[mapguide-commits] r4806 - in trunk/Tools/Maestro: Maestro/ResourceEditors/LoadProcedureEditors MaestroAPI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Apr 20 02:01:21 EDT 2010


Author: jng
Date: 2010-04-20 02:01:20 -0400 (Tue, 20 Apr 2010)
New Revision: 4806

Modified:
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/LoadProcedureCtrl.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.Designer.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.resx
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.Designer.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.cs
   trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.resx
   trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs
   trunk/Tools/Maestro/MaestroAPI/ServerConnectionI.cs
Log:
#579: More load procedure updates

- Add some warning labels to the Load Procedure editors so that users know what Maestro can't do (as opposed to Studio)
- Updated ServerConnectionBase.ExecuteLoadProcedure(), it will now check if it has been executed before (if it doesn't have a list of generated resource ids, it is assumed to be the first execution). If it is the first execution, the load procedure resource will update this resource with the list of created resource ids. Subsequent executions of this load procedure will only update this specified list of resource ids.

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/LoadProcedureCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/LoadProcedureCtrl.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/LoadProcedureCtrl.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -187,6 +187,10 @@
 
         private void btnLoadResources_Click(object sender, EventArgs e)
         {
+            //Save the current resource before executing it
+            Save("");
+            _ed.CurrentConnection.SaveResourceAs(this.Resource, _resourceID);
+
             WaitForOperation dlg = new WaitForOperation();
             dlg.CancelAbortsThread = true;
 
@@ -214,6 +218,31 @@
             string lpID = (string)args[1];
             conn.ExecuteLoadProcedure(lpID, true, cb);
 
+            //These would be equal if we're executing an unsaved load procedure
+            if (lpID != _ed.ResourceId)
+            {
+                //Copy current copy to the library version
+                conn.CopyResource(lpID, _ed.ResourceId, true);
+            }
+
+            //If the load procedure was executed for the first time, it would have been
+            //updated with the list of resources generated, so replace the current resource
+            //with the updated one.
+            this.Resource = conn.GetResource(lpID);
+
+            //Update the load procedure editor
+            if (this.InvokeRequired)
+            {
+                this.Invoke(new MethodInvoker(delegate
+                {
+                    UpdateDisplay();
+                }));
+            }
+            else
+            {
+                UpdateDisplay();
+            }
+
             return true;
         }
 

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.Designer.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.Designer.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -31,6 +31,7 @@
             this.groupBox1 = new System.Windows.Forms.GroupBox();
             this.sourceFilesCtrl1 = new OSGeo.MapGuide.Maestro.ResourceEditors.LoadProcedureEditors.SourceFilesCtrl();
             this.groupBox2 = new System.Windows.Forms.GroupBox();
+            this.lblNote = new System.Windows.Forms.Label();
             this.cmbSdfDuplicateStrategy = new System.Windows.Forms.ComboBox();
             this.label3 = new System.Windows.Forms.Label();
             this.numGeneralize = new System.Windows.Forms.NumericUpDown();
@@ -40,6 +41,7 @@
             this.label1 = new System.Windows.Forms.Label();
             this.groupBox3 = new System.Windows.Forms.GroupBox();
             this.loadSettingsCtrl1 = new OSGeo.MapGuide.Maestro.ResourceEditors.LoadProcedureEditors.LoadSettingsCtrl();
+            this.lblNote2 = new System.Windows.Forms.Label();
             this.groupBox1.SuspendLayout();
             this.groupBox2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.numGeneralize)).BeginInit();
@@ -73,6 +75,8 @@
             this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Left)
                         | System.Windows.Forms.AnchorStyles.Right)));
+            this.groupBox2.Controls.Add(this.lblNote2);
+            this.groupBox2.Controls.Add(this.lblNote);
             this.groupBox2.Controls.Add(this.cmbSdfDuplicateStrategy);
             this.groupBox2.Controls.Add(this.label3);
             this.groupBox2.Controls.Add(this.numGeneralize);
@@ -87,6 +91,16 @@
             this.groupBox2.TabStop = false;
             this.groupBox2.Text = "Transformation";
             // 
+            // lblNote
+            // 
+            this.lblNote.AutoSize = true;
+            this.lblNote.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.lblNote.Location = new System.Drawing.Point(6, 98);
+            this.lblNote.Name = "lblNote";
+            this.lblNote.Size = new System.Drawing.Size(311, 13);
+            this.lblNote.TabIndex = 27;
+            this.lblNote.Text = "Note: Disabled features are not supported by Maestro";
+            // 
             // cmbSdfDuplicateStrategy
             // 
             this.cmbSdfDuplicateStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@@ -185,6 +199,17 @@
             this.loadSettingsCtrl1.Size = new System.Drawing.Size(586, 102);
             this.loadSettingsCtrl1.TabIndex = 0;
             // 
+            // lblNote2
+            // 
+            this.lblNote2.AutoSize = true;
+            this.lblNote2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.lblNote2.Location = new System.Drawing.Point(6, 117);
+            this.lblNote2.Name = "lblNote2";
+            this.lblNote2.Size = new System.Drawing.Size(497, 13);
+            this.lblNote2.TabIndex = 28;
+            this.lblNote2.Text = "Note: Do not use SDF2 files. Maestro does not support conversion from SDF2 to SDF" +
+                "3";
+            // 
             // SdfLoadProcedureCtrl
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -217,5 +242,7 @@
         private System.Windows.Forms.NumericUpDown numGeneralize;
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.ComboBox cmbSdfDuplicateStrategy;
+        private System.Windows.Forms.Label lblNote;
+        private System.Windows.Forms.Label lblNote2;
     }
 }

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -128,14 +128,27 @@
         public override string[] GetAffectedResourceIds()
         {
             List<string> affected = new List<string>();
-            foreach (string f in sourceFilesCtrl1.SourceFiles)
+            LoadProcedure lp = this.Resource as LoadProcedure;
+            if (lp != null)
             {
-                string name = System.IO.Path.GetFileNameWithoutExtension(f);
+                SdfLoadProcedureType sdfl = lp.Item as SdfLoadProcedureType;
+                if (sdfl != null && sdfl.ResourceId != null)
+                {
+                    affected.AddRange(sdfl.ResourceId);
+                }
+            }
 
-                if (loadSettingsCtrl1.LoadFeatureSources)
-                    affected.Add(loadSettingsCtrl1.FeatureSourceRootPath + loadSettingsCtrl1.FeatureSourceFolderName + "/" + name + ".FeatureSource");
-                if (loadSettingsCtrl1.LoadLayers)
-                    affected.Add(loadSettingsCtrl1.LayerRootPath + loadSettingsCtrl1.LayerFolderName + "/" + name + ".LayerDefinition");
+            if (affected.Count == 0)
+            {
+                foreach (string f in sourceFilesCtrl1.SourceFiles)
+                {
+                    string name = System.IO.Path.GetFileNameWithoutExtension(f);
+
+                    if (loadSettingsCtrl1.LoadFeatureSources)
+                        affected.Add(loadSettingsCtrl1.FeatureSourceRootPath + loadSettingsCtrl1.FeatureSourceFolderName + "/" + name + ".FeatureSource");
+                    if (loadSettingsCtrl1.LoadLayers)
+                        affected.Add(loadSettingsCtrl1.LayerRootPath + loadSettingsCtrl1.LayerFolderName + "/" + name + ".LayerDefinition");
+                }
             }
             return affected.ToArray();
         }

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.resx
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.resx	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/SdfLoadProcedureCtrl.resx	2010-04-20 06:01:20 UTC (rev 4806)
@@ -117,4 +117,4 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-</root>
+</root>
\ No newline at end of file

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.Designer.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.Designer.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -39,6 +39,7 @@
             this.label1 = new System.Windows.Forms.Label();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
             this.sourceFilesCtrl1 = new OSGeo.MapGuide.Maestro.ResourceEditors.LoadProcedureEditors.SourceFilesCtrl();
+            this.lblNote = new System.Windows.Forms.Label();
             this.groupBox3.SuspendLayout();
             this.groupBox2.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.numGeneralize)).BeginInit();
@@ -78,6 +79,7 @@
             this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Left)
                         | System.Windows.Forms.AnchorStyles.Right)));
+            this.groupBox2.Controls.Add(this.lblNote);
             this.groupBox2.Controls.Add(this.chkConvertSdf);
             this.groupBox2.Controls.Add(this.btnBrowseCS);
             this.groupBox2.Controls.Add(this.numGeneralize);
@@ -172,6 +174,16 @@
             this.sourceFilesCtrl1.SourceFiles = new string[0];
             this.sourceFilesCtrl1.TabIndex = 0;
             // 
+            // lblNote
+            // 
+            this.lblNote.AutoSize = true;
+            this.lblNote.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.lblNote.Location = new System.Drawing.Point(6, 72);
+            this.lblNote.Name = "lblNote";
+            this.lblNote.Size = new System.Drawing.Size(311, 13);
+            this.lblNote.TabIndex = 31;
+            this.lblNote.Text = "Note: Disabled features are not supported by Maestro";
+            // 
             // ShpLoadProcedureCtrl
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -203,5 +215,6 @@
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.CheckBox chkConvertSdf;
         protected System.Windows.Forms.Button btnBrowseCS;
+        private System.Windows.Forms.Label lblNote;
     }
 }

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -125,14 +125,27 @@
         public override string[] GetAffectedResourceIds()
         {
             List<string> affected = new List<string>();
-            foreach (string f in sourceFilesCtrl1.SourceFiles)
+            LoadProcedure lp = this.Resource as LoadProcedure;
+            if (lp != null)
             {
-                string name = System.IO.Path.GetFileNameWithoutExtension(f);
+                ShpLoadProcedureType shpl = lp.Item as ShpLoadProcedureType;
+                if (shpl != null && shpl.ResourceId != null)
+                {
+                    affected.AddRange(shpl.ResourceId);
+                }
+            }
 
-                if (loadSettingsCtrl1.LoadFeatureSources)
-                    affected.Add(loadSettingsCtrl1.FeatureSourceRootPath + loadSettingsCtrl1.FeatureSourceFolderName + "/" + name + ".FeatureSource");
-                if (loadSettingsCtrl1.LoadLayers)
-                    affected.Add(loadSettingsCtrl1.LayerRootPath + loadSettingsCtrl1.LayerFolderName + "/" + name + ".LayerDefinition");
+            if (affected.Count == 0)
+            {
+                foreach (string f in sourceFilesCtrl1.SourceFiles)
+                {
+                    string name = System.IO.Path.GetFileNameWithoutExtension(f);
+
+                    if (loadSettingsCtrl1.LoadFeatureSources)
+                        affected.Add(loadSettingsCtrl1.FeatureSourceRootPath + loadSettingsCtrl1.FeatureSourceFolderName + "/" + name + ".FeatureSource");
+                    if (loadSettingsCtrl1.LoadLayers)
+                        affected.Add(loadSettingsCtrl1.LayerRootPath + loadSettingsCtrl1.LayerFolderName + "/" + name + ".LayerDefinition");
+                }
             }
             return affected.ToArray();
         }

Modified: trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.resx
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.resx	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/Maestro/ResourceEditors/LoadProcedureEditors/ShpLoadProcedureCtrl.resx	2010-04-20 06:01:20 UTC (rev 4806)
@@ -117,4 +117,4 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-</root>
+</root>
\ No newline at end of file

Modified: trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -2192,6 +2192,7 @@
             SdfLoadProcedureType sdfl = proc.Item as SdfLoadProcedureType;
             ShpLoadProcedureType shpl = proc.Item as ShpLoadProcedureType;
 
+            bool firstExecute = true;
             if (sdfl != null)
             {
                 if (!ignoreUnsupportedFeatures)
@@ -2203,7 +2204,7 @@
                     }
                 }
 
-                resourcesCreatedOrUpdated = ExecuteSdfLoadProcedure(cb, sdfl);
+                resourcesCreatedOrUpdated = ExecuteSdfLoadProcedure(cb, sdfl, ref firstExecute);
             }
             else if (shpl != null)
             {
@@ -2220,20 +2221,23 @@
                         throw new NotSupportedException("Conversion of SHP files to SDF files is not supported");
                     }
                 }
-                resourcesCreatedOrUpdated = ExecuteShpLoadProcedure(cb, shpl);
+                resourcesCreatedOrUpdated = ExecuteShpLoadProcedure(cb, shpl, ref firstExecute);
             }
             else //We don't support anything else (and probably never will)
             {
                 throw new NotSupportedException("Unsupported load procedure type");
             }
 
-            proc.Item.ResourceId = resourcesCreatedOrUpdated;
-            this.SaveResourceAs(proc, resourceID);
-
+            //Update the generated resources list if this is the first execution
+            if (firstExecute)
+            {
+                proc.Item.ResourceId = resourcesCreatedOrUpdated;
+                this.SaveResourceAs(proc, resourceID);
+            }
             return resourcesCreatedOrUpdated;
         }
 
-        private string[] ExecuteShpLoadProcedure(LengthyOperationProgressCallBack cb, ShpLoadProcedureType shpl)
+        private string[] ExecuteShpLoadProcedure(LengthyOperationProgressCallBack cb, ShpLoadProcedureType shpl, ref bool firstExecution)
         {
             List<string> resCreatedOrUpdated = new List<string>();
 
@@ -2241,14 +2245,44 @@
             int pcPerFile = (int)(100 / shpFiles.Length);
             int current = 0;
 
-            string fsRoot = shpl.SpatialDataSourcesPath + shpl.SpatialDataSourcesFolder;
-            string layerRoot = shpl.LayersPath + shpl.LayersFolder;
+            string root = shpl.RootPath;
+            if (!root.EndsWith("/"))
+                root += "/";
 
+            string sdp = shpl.SpatialDataSourcesPath;
+            string lp = shpl.LayersPath;
+
+            if (!string.IsNullOrEmpty(sdp))
+            {
+                if (!sdp.EndsWith("/"))
+                    sdp += "/";
+            }
+
+            if (!string.IsNullOrEmpty(lp))
+            {
+                if (!lp.EndsWith("/"))
+                    lp += "/";
+            }
+
+            string fsRoot = (string.IsNullOrEmpty(sdp) ? root : sdp) + shpl.SpatialDataSourcesFolder;
+            string layerRoot = (string.IsNullOrEmpty(lp) ? root : lp) + shpl.LayersFolder;
+
             if (!fsRoot.EndsWith("/"))
                 fsRoot += "/";
             if (!layerRoot.EndsWith("/"))
                 layerRoot += "/";
 
+            List<string> resToUpdate = new List<string>();
+            if (shpl.ResourceId != null)
+            {
+                resToUpdate.AddRange(shpl.ResourceId);
+                firstExecution = false;
+            }
+            else
+            {
+                firstExecution = true;
+            }
+
             Dictionary<string, List<string>> extraFiles = new Dictionary<string, List<string>>();
             //Unlike SDF, a SHP file actually consists of multiple files
             foreach (string shp in shpFiles)
@@ -2279,131 +2313,140 @@
 
                     if (shpl.GenerateSpatialDataSources)
                     {
-                        //Process is as follows:
-                        //
-                        // 1. Create and save feature source document.
-                        // 2. Upload sdf file as resource data for this document.
-                        // 3. Test the connection, it should check out.
-                        // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.
+                        //Skip only if we have an update list and this resource id is not in it
+                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(fsId));
+                        if (!skip)
+                        {
+                            //Process is as follows:
+                            //
+                            // 1. Create and save feature source document.
+                            // 2. Upload sdf file as resource data for this document.
+                            // 3. Test the connection, it should check out.
+                            // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.
 
-                        //Step 1: Create feature source document
-                        FeatureSource fs = new FeatureSource();
-                        fs.ResourceId = fsId;
-                        fs.Provider = "OSGeo.SHP";
-                        fs.Parameter = new NameValuePairTypeCollection();
-                        fs.Parameter.Add(new NameValuePairType() { Name = "DefaultFileLocation", Value = "%MG_DATA_FILE_PATH%" + dataName });
+                            //Step 1: Create feature source document
+                            FeatureSource fs = new FeatureSource();
+                            fs.ResourceId = fsId;
+                            fs.Provider = "OSGeo.SHP";
+                            fs.Parameter = new NameValuePairTypeCollection();
+                            fs.Parameter.Add(new NameValuePairType() { Name = "DefaultFileLocation", Value = "%MG_DATA_FILE_PATH%" + dataName });
 
-                        this.SaveResource(fs);
-                        resCreatedOrUpdated.Add(fsId);
-                        cb(this, new LengthyOperationProgressArgs("Created: " + fsId, current));
+                            this.SaveResource(fs);
+                            resCreatedOrUpdated.Add(fsId);
+                            cb(this, new LengthyOperationProgressArgs("Created: " + fsId, current));
 
-                        //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
-                        //Maybe then we can actually implement the generalization and conversion properties. Until then, we skip
-                        //these options
+                            //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
+                            //Maybe then we can actually implement the generalization and conversion properties. Until then, we skip
+                            //these options
 
-                        //Step 2: Load resource data for document
-                        this.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));
+                            //Step 2: Load resource data for document
+                            this.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));
 
-                        cb(this, new LengthyOperationProgressArgs("Loaded: " + file, current));
+                            cb(this, new LengthyOperationProgressArgs("Loaded: " + file, current));
 
-                        //Load supplementary files
-                        foreach (string extraFile in extraFiles[file])
-                        {
-                            string dn = System.IO.Path.GetFileName(extraFile);
-                            if (System.IO.File.Exists(extraFile))
+                            //Load supplementary files
+                            foreach (string extraFile in extraFiles[file])
                             {
-                                this.SetResourceData(fsId, dn, ResourceDataType.File, System.IO.File.OpenRead(extraFile));
-                                cb(this, new LengthyOperationProgressArgs("Loaded: " + extraFile, current));
+                                string dn = System.IO.Path.GetFileName(extraFile);
+                                if (System.IO.File.Exists(extraFile))
+                                {
+                                    this.SetResourceData(fsId, dn, ResourceDataType.File, System.IO.File.OpenRead(extraFile));
+                                    cb(this, new LengthyOperationProgressArgs("Loaded: " + extraFile, current));
+                                }
                             }
-                        }
 
-                        //Step 3: Test to make sure we're all good so far
-                        string result = this.TestConnection(fsId);
+                            //Step 3: Test to make sure we're all good so far
+                            string result = this.TestConnection(fsId);
 
-                        //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
-                        if (result == "No errors")
-                        {
-                            //Step 4: Test to see if default cs needs to be specified
-                            FdoSpatialContextList spatialContexts = this.GetSpatialContextInfo(fsId, false);
-                            if (spatialContexts.SpatialContext.Count == 0 && !string.IsNullOrEmpty(shpl.CoordinateSystem))
+                            //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
+                            if (result == "No errors")
                             {
-                                //Register the default CS from the load procedure
-                                fs.SupplementalSpatialContextInfo = new SpatialContextTypeCollection();
-                                fs.SupplementalSpatialContextInfo.Add(new SpatialContextType()
+                                //Step 4: Test to see if default cs needs to be specified
+                                FdoSpatialContextList spatialContexts = this.GetSpatialContextInfo(fsId, false);
+                                if (spatialContexts.SpatialContext.Count == 0 && !string.IsNullOrEmpty(shpl.CoordinateSystem))
                                 {
-                                    Name = "Default",
-                                    CoordinateSystem = shpl.CoordinateSystem
-                                });
+                                    //Register the default CS from the load procedure
+                                    fs.SupplementalSpatialContextInfo = new SpatialContextTypeCollection();
+                                    fs.SupplementalSpatialContextInfo.Add(new SpatialContextType()
+                                    {
+                                        Name = "Default",
+                                        CoordinateSystem = shpl.CoordinateSystem
+                                    });
 
-                                //Update this feature source
-                                this.SaveResource(fs);
+                                    //Update this feature source
+                                    this.SaveResource(fs);
 
-                                cb(this, new LengthyOperationProgressArgs("Set default spatial context for: " + fsId, current));
+                                    cb(this, new LengthyOperationProgressArgs("Set default spatial context for: " + fsId, current));
+                                }
                             }
                         }
                     }
 
                     if (shpl.GenerateLayers)
                     {
-                        //Process is as follows
-                        //
-                        // 1. Describe the schema of the feature source
-                        // 2. If it contains at least one feature class, create a layer definition
-                        // 3. Set the following layer definition properties:
-                        //    - Feature Source: the feature source id
-                        //    - Feature Class: the first feature class in the schema
-                        //    - Geometry: the first geometry property in the first feature class
-                        // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.
-
-                        //Step 1: Describe the schema
-                        FeatureSourceDescription desc = DescribeFeatureSource(fsId);
-
-                        if (desc.Schemas.Length > 0)
+                        //Skip only if we have an update list and this resource id is not in it
+                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(lyrId));
+                        if (!skip)
                         {
-                            //Step 2: Find the first feature class with a geometry property
-                            FeatureSourceDescription.FeatureSourceSchema clsDef = null;
-                            FeatureSetColumn geom = null;
+                            //Process is as follows
+                            //
+                            // 1. Describe the schema of the feature source
+                            // 2. If it contains at least one feature class, create a layer definition
+                            // 3. Set the following layer definition properties:
+                            //    - Feature Source: the feature source id
+                            //    - Feature Class: the first feature class in the schema
+                            //    - Geometry: the first geometry property in the first feature class
+                            // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.
 
-                            bool done = false;
+                            //Step 1: Describe the schema
+                            FeatureSourceDescription desc = DescribeFeatureSource(fsId);
 
-                            foreach (FeatureSourceDescription.FeatureSourceSchema cls in desc.Schemas)
+                            if (desc.Schemas.Length > 0)
                             {
-                                if (done) break;
+                                //Step 2: Find the first feature class with a geometry property
+                                FeatureSourceDescription.FeatureSourceSchema clsDef = null;
+                                FeatureSetColumn geom = null;
 
-                                foreach (FeatureSetColumn prop in cls.Columns)
+                                bool done = false;
+
+                                foreach (FeatureSourceDescription.FeatureSourceSchema cls in desc.Schemas)
                                 {
                                     if (done) break;
 
-                                    if (typeof(Topology.Geometries.IGeometry).IsAssignableFrom(prop.Type))
+                                    foreach (FeatureSetColumn prop in cls.Columns)
                                     {
-                                        clsDef = cls;
-                                        geom = prop;
-                                        done = true;
+                                        if (done) break;
+
+                                        if (typeof(Topology.Geometries.IGeometry).IsAssignableFrom(prop.Type))
+                                        {
+                                            clsDef = cls;
+                                            geom = prop;
+                                            done = true;
+                                        }
                                     }
                                 }
-                            }
 
-                            if (clsDef != null && geom != null)
-                            {
-                                LayerDefinition ld = CreateResourceObject<LayerDefinition>();
+                                if (clsDef != null && geom != null)
+                                {
+                                    LayerDefinition ld = CreateResourceObject<LayerDefinition>();
 
-                                //Step 3: Assign default properties
-                                ld.ResourceId = lyrId;
-                                VectorLayerDefinitionType vld = ld.Item as VectorLayerDefinitionType;
-                                vld.ResourceId = fsId;
-                                vld.FeatureName = clsDef.Fullname;
-                                vld.Geometry = geom.Name;
+                                    //Step 3: Assign default properties
+                                    ld.ResourceId = lyrId;
+                                    VectorLayerDefinitionType vld = ld.Item as VectorLayerDefinitionType;
+                                    vld.ResourceId = fsId;
+                                    vld.FeatureName = clsDef.Fullname;
+                                    vld.Geometry = geom.Name;
 
-                                this.SaveResource(ld);
-                                resCreatedOrUpdated.Add(lyrId);
-                                cb(this, new LengthyOperationProgressArgs("Created: " + lyrId, current));
+                                    this.SaveResource(ld);
+                                    resCreatedOrUpdated.Add(lyrId);
+                                    cb(this, new LengthyOperationProgressArgs("Created: " + lyrId, current));
 
-                                //Step 4: Infer geometry storage support and remove unsupported styles
-                                //TODO: There doesn't seem to be a MaestroAPI way to figure out geometry storage types atm
+                                    //Step 4: Infer geometry storage support and remove unsupported styles
+                                    //TODO: There doesn't seem to be a MaestroAPI way to figure out geometry storage types atm
+                                }
                             }
                         }
                     }
-
                     success = true;
                 }
                 else
@@ -2423,7 +2466,7 @@
             return resCreatedOrUpdated.ToArray();
         }
 
-        private string[] ExecuteSdfLoadProcedure(LengthyOperationProgressCallBack cb, SdfLoadProcedureType sdfl)
+        private string[] ExecuteSdfLoadProcedure(LengthyOperationProgressCallBack cb, SdfLoadProcedureType sdfl, ref bool firstExecution)
         {
             List<string> resCreatedOrUpdated = new List<string>();
 
@@ -2431,14 +2474,44 @@
             int pcPerFile = (int)(100 / files.Length);
             int current = 0;
 
-            string fsRoot = sdfl.SpatialDataSourcesPath + sdfl.SpatialDataSourcesFolder;
-            string layerRoot = sdfl.LayersPath + sdfl.LayersFolder;
+            string root = sdfl.RootPath;
+            if (!root.EndsWith("/"))
+                root += "/";
 
+            string sdp = sdfl.SpatialDataSourcesPath;
+            string lp = sdfl.LayersPath;
+
+            if (!string.IsNullOrEmpty(sdp))
+            {
+                if (!sdp.EndsWith("/"))
+                    sdp += "/";
+            }
+
+            if (!string.IsNullOrEmpty(lp))
+            {
+                if (!lp.EndsWith("/"))
+                    lp += "/";
+            }
+
+            string fsRoot = (string.IsNullOrEmpty(sdp) ? root : sdp) + sdfl.SpatialDataSourcesFolder;
+            string layerRoot = (string.IsNullOrEmpty(lp) ? root : lp) + sdfl.LayersFolder;
+
             if (!fsRoot.EndsWith("/"))
                 fsRoot += "/";
             if (!layerRoot.EndsWith("/"))
                 layerRoot += "/";
 
+            List<string> resToUpdate = new List<string>();
+            if (sdfl.ResourceId != null)
+            {
+                resToUpdate.AddRange(sdfl.ResourceId);
+                firstExecution = false;
+            }
+            else
+            {
+                firstExecution = true;
+            }
+
             foreach (string file in files)
             {
                 bool success = false;
@@ -2454,120 +2527,129 @@
 
                     if (sdfl.GenerateSpatialDataSources)
                     {
-                        //Process is as follows:
-                        //
-                        // 1. Create and save feature source document.
-                        // 2. Upload sdf file as resource data for this document.
-                        // 3. Test the connection, it should check out.
-                        // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.
+                        //Skip only if we have an update list and this resource id is not in it
+                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(fsId));
+                        if (!skip)
+                        {
+                            //Process is as follows:
+                            //
+                            // 1. Create and save feature source document.
+                            // 2. Upload sdf file as resource data for this document.
+                            // 3. Test the connection, it should check out.
+                            // 4. If no spatial contexts are detected, assign a default one from the load procedure and save the modified feature source.
 
-                        //Step 1: Create feature source document
-                        FeatureSource fs = new FeatureSource();
-                        fs.ResourceId = fsId;
-                        fs.Provider = "OSGeo.SDF";
-                        fs.Parameter = new NameValuePairTypeCollection();
-                        fs.Parameter.Add(new NameValuePairType() { Name = "File", Value = "%MG_DATA_FILE_PATH%" + dataName });
+                            //Step 1: Create feature source document
+                            FeatureSource fs = new FeatureSource();
+                            fs.ResourceId = fsId;
+                            fs.Provider = "OSGeo.SDF";
+                            fs.Parameter = new NameValuePairTypeCollection();
+                            fs.Parameter.Add(new NameValuePairType() { Name = "File", Value = "%MG_DATA_FILE_PATH%" + dataName });
 
-                        this.SaveResource(fs);
-                        resCreatedOrUpdated.Add(fsId);
-                        cb(this, new LengthyOperationProgressArgs("Created: " + fsId, current));
+                            this.SaveResource(fs);
+                            resCreatedOrUpdated.Add(fsId);
+                            cb(this, new LengthyOperationProgressArgs("Created: " + fsId, current));
 
-                        //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
-                        //Maybe then we can actually implement the generalization and duplicate record handling properties. Until then, we skip
-                        //these options
+                            //TODO: When the infrastructure is available to us (ie. A portable .net FDO/MG Feature Service API wrapper)
+                            //Maybe then we can actually implement the generalization and duplicate record handling properties. Until then, we skip
+                            //these options
 
-                        //Step 2: Load resource data for document
-                        this.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));
+                            //Step 2: Load resource data for document
+                            this.SetResourceData(fsId, dataName, ResourceDataType.File, System.IO.File.OpenRead(file));
 
-                        cb(this, new LengthyOperationProgressArgs("Loaded: " + file, current));
+                            cb(this, new LengthyOperationProgressArgs("Loaded: " + file, current));
 
-                        //Step 3: Test to make sure we're all good so far
-                        string result = this.TestConnection(fsId);
+                            //Step 3: Test to make sure we're all good so far
+                            string result = this.TestConnection(fsId);
 
-                        //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
-                        if (result == "No errors")
-                        {
-                            //Step 4: Test to see if default cs needs to be specified
-                            FdoSpatialContextList spatialContexts = this.GetSpatialContextInfo(fsId, false);
-                            if (spatialContexts.SpatialContext.Count == 0 && !string.IsNullOrEmpty(sdfl.CoordinateSystem))
+                            //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
+                            if (result == "No errors")
                             {
-                                //Register the default CS from the load procedure
-                                fs.SupplementalSpatialContextInfo = new SpatialContextTypeCollection();
-                                fs.SupplementalSpatialContextInfo.Add(new SpatialContextType()
+                                //Step 4: Test to see if default cs needs to be specified
+                                FdoSpatialContextList spatialContexts = this.GetSpatialContextInfo(fsId, false);
+                                if (spatialContexts.SpatialContext.Count == 0 && !string.IsNullOrEmpty(sdfl.CoordinateSystem))
                                 {
-                                    Name = "Default",
-                                    CoordinateSystem = sdfl.CoordinateSystem
-                                });
+                                    //Register the default CS from the load procedure
+                                    fs.SupplementalSpatialContextInfo = new SpatialContextTypeCollection();
+                                    fs.SupplementalSpatialContextInfo.Add(new SpatialContextType()
+                                    {
+                                        Name = "Default",
+                                        CoordinateSystem = sdfl.CoordinateSystem
+                                    });
 
-                                //Update this feature source
-                                this.SaveResource(fs);
+                                    //Update this feature source
+                                    this.SaveResource(fs);
 
-                                cb(this, new LengthyOperationProgressArgs("Set default spatial context for: " + fsId, current));
+                                    cb(this, new LengthyOperationProgressArgs("Set default spatial context for: " + fsId, current));
+                                }
                             }
                         }
                     }
 
                     if (sdfl.GenerateLayers)
                     {
-                        //Process is as follows
-                        //
-                        // 1. Describe the schema of the feature source
-                        // 2. If it contains at least one feature class, create a layer definition
-                        // 3. Set the following layer definition properties:
-                        //    - Feature Source: the feature source id
-                        //    - Feature Class: the first feature class in the schema
-                        //    - Geometry: the first geometry property in the first feature class
-                        // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.
-
-                        //Step 1: Describe the schema
-                        FeatureSourceDescription desc = DescribeFeatureSource(fsId);
-
-                        if (desc.Schemas.Length > 0)
+                        //Skip only if we have an update list and this resource id is not in it
+                        bool skip = (resToUpdate.Count > 0 && !resToUpdate.Contains(lyrId));
+                        if (!skip)
                         {
-                            //Step 2: Find the first feature class with a geometry property
-                            FeatureSourceDescription.FeatureSourceSchema clsDef = null;
-                            FeatureSetColumn geom = null;
+                            //Process is as follows
+                            //
+                            // 1. Describe the schema of the feature source
+                            // 2. If it contains at least one feature class, create a layer definition
+                            // 3. Set the following layer definition properties:
+                            //    - Feature Source: the feature source id
+                            //    - Feature Class: the first feature class in the schema
+                            //    - Geometry: the first geometry property in the first feature class
+                            // 4. Infer the supported geometry types for this feature class. Toggle supported styles accordingly.
 
-                            bool done = false;
+                            //Step 1: Describe the schema
+                            FeatureSourceDescription desc = DescribeFeatureSource(fsId);
 
-                            foreach (FeatureSourceDescription.FeatureSourceSchema cls in desc.Schemas)
+                            if (desc.Schemas.Length > 0)
                             {
-                                if (done) break;
+                                //Step 2: Find the first feature class with a geometry property
+                                FeatureSourceDescription.FeatureSourceSchema clsDef = null;
+                                FeatureSetColumn geom = null;
 
-                                foreach (FeatureSetColumn prop in cls.Columns)
+                                bool done = false;
+
+                                foreach (FeatureSourceDescription.FeatureSourceSchema cls in desc.Schemas)
                                 {
                                     if (done) break;
 
-                                    if (typeof(Topology.Geometries.IGeometry).IsAssignableFrom(prop.Type))
+                                    foreach (FeatureSetColumn prop in cls.Columns)
                                     {
-                                        clsDef = cls;
-                                        geom = prop;
-                                        done = true;
+                                        if (done) break;
+
+                                        if (typeof(Topology.Geometries.IGeometry).IsAssignableFrom(prop.Type))
+                                        {
+                                            clsDef = cls;
+                                            geom = prop;
+                                            done = true;
+                                        }
                                     }
                                 }
-                            }
 
-                            if (clsDef != null && geom != null)
-                            {
-                                LayerDefinition ld = CreateResourceObject<LayerDefinition>();
+                                if (clsDef != null && geom != null)
+                                {
+                                    LayerDefinition ld = CreateResourceObject<LayerDefinition>();
 
-                                //Step 3: Assign default properties
-                                ld.ResourceId = lyrId;
-                                VectorLayerDefinitionType vld = ld.Item as VectorLayerDefinitionType;
-                                vld.ResourceId = fsId;
-                                vld.FeatureName = clsDef.Fullname;
-                                vld.Geometry = geom.Name;
+                                    //Step 3: Assign default properties
+                                    ld.ResourceId = lyrId;
+                                    VectorLayerDefinitionType vld = ld.Item as VectorLayerDefinitionType;
+                                    vld.ResourceId = fsId;
+                                    vld.FeatureName = clsDef.Fullname;
+                                    vld.Geometry = geom.Name;
 
-                                this.SaveResource(ld);
-                                resCreatedOrUpdated.Add(lyrId);
-                                cb(this, new LengthyOperationProgressArgs("Created: " + lyrId, current));
+                                    this.SaveResource(ld);
+                                    resCreatedOrUpdated.Add(lyrId);
+                                    cb(this, new LengthyOperationProgressArgs("Created: " + lyrId, current));
 
-                                //Step 4: Infer geometry storage support and remove unsupported styles
-                                //TODO: There doesn't seem to be a MaestroAPI way to figure out geometry storage types atm
+                                    //Step 4: Infer geometry storage support and remove unsupported styles
+                                    //TODO: There doesn't seem to be a MaestroAPI way to figure out geometry storage types atm
+                                }
                             }
                         }
                     }
-
                     success = true;
                 }
                 else

Modified: trunk/Tools/Maestro/MaestroAPI/ServerConnectionI.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/ServerConnectionI.cs	2010-04-20 03:24:08 UTC (rev 4805)
+++ trunk/Tools/Maestro/MaestroAPI/ServerConnectionI.cs	2010-04-20 06:01:20 UTC (rev 4806)
@@ -409,12 +409,14 @@
         T CreateResourceObject<T>();
 
         /// <summary>
-        /// Executes the specified load procedure
+        /// Executes the specified load procedure. If this load procedure has not been executed before,
+        /// it will update the load procedure resource with the list of resource ids created. On subsequent
+        /// executions, it will only create or update resources from this list.
         /// </summary>
         /// <param name="resourceID"></param>
         /// <param name="ignoreUnsupportedFeatures"></param>
         /// <param name="callback"></param>
-        /// <returns>A list of resource IDs that were created from the execution of this load procedure</returns>
+        /// <returns>A list of resource IDs that were created or updated from the execution of this load procedure</returns>
         string[] ExecuteLoadProcedure(string resourceID, bool ignoreUnsupportedFeatures, LengthyOperationProgressCallBack callback);
     }
 }



More information about the mapguide-commits mailing list