[mapguide-commits] r5680 - in trunk/Tools/Maestro/Maestro.Base: . Commands/SiteExplorer Properties

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Apr 5 08:23:45 EDT 2011


Author: jng
Date: 2011-04-05 05:23:45 -0700 (Tue, 05 Apr 2011)
New Revision: 5680

Added:
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DuplicateResourceCommand.cs
Modified:
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
Log:
#1649: Add missing duplicate resource command from Maestro 2.0


Added: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DuplicateResourceCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DuplicateResourceCommand.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/DuplicateResourceCommand.cs	2011-04-05 12:23:45 UTC (rev 5680)
@@ -0,0 +1,85 @@
+#region Disclaimer / License
+// Copyright (C) 2011, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ICSharpCode.Core;
+using Maestro.Base.Services;
+using Maestro.Base.UI;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+
+namespace Maestro.Base.Commands.SiteExplorer
+{
+    internal class DuplicateResourceCommand : AbstractMenuCommand
+    {
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            var exp = wb.ActiveSiteExplorer;
+            var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+            var conn = connMgr.GetConnection(exp.ConnectionName);
+
+            if (exp.SelectedItems.Length > 0)
+            {
+                List<RepositoryItem> toDuplicate = new List<RepositoryItem>();
+                foreach (var item in exp.SelectedItems)
+                {
+                    if (!item.IsFolder)
+                        toDuplicate.Add(item);
+                }
+
+                //They all have the same parent
+                var folder = exp.SelectedItems[0].Parent;
+
+                foreach (var item in toDuplicate)
+                {
+                    //Keep testing until we find a target resource identifier that 
+                    //doesn't already exists. Note this would automatically guard against any resources in this folder
+                    //that may already be open in an editor
+                    var rid = new ResourceIdentifier(item.ResourceId);
+                    var name = rid.IsFolder ? (rid.Name + "/") : (rid.Name + "." + rid.ResourceType.ToString());
+                    var resId = folder.ResourceId + name;
+                    int counter = 0;
+                    while (conn.ResourceService.ResourceExists(resId))
+                    {
+                        counter++;
+
+                        if (rid.IsFolder)
+                        {
+                            resId = folder.ResourceId + rid.Name + " (" + counter + ")/";
+                        }
+                        else
+                        {
+                            var rname = name.Substring(0, name.IndexOf("."));
+                            var type = name.Substring(name.IndexOf("."));
+                            rname += " (" + counter + ")";
+                            resId = folder.ResourceId + rname + type;
+                        }
+                    }
+
+                    conn.ResourceService.CopyResource(item.ResourceId, resId, false);
+                    LoggingService.Info(string.Format(Properties.Resources.ResourceDuplicated, item.ResourceId, resId));
+                }
+
+                exp.RefreshModel(folder.ResourceId);
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2011-04-05 11:53:18 UTC (rev 5679)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2011-04-05 12:23:45 UTC (rev 5680)
@@ -492,6 +492,10 @@
                       icon="cross_script"
                       label="${res:SiteExplorer_SelectedItem_Delete}"
                       class="Maestro.Base.Commands.SiteExplorer.DeleteSelectedItemsCommand" />
+            <MenuItem id="Duplicate"
+                      icon="document_copy"
+                      label="${res:SiteExplorer_DuplicateResources}"
+                      class="Maestro.Base.Commands.SiteExplorer.DuplicateResourceCommand" />
             <MenuItem type="Separator" />
             <Condition action="Disable" name="ResourceType" types="FeatureSource,LayerDefinition">
                 <MenuItem id="PurgeFsCache"
@@ -551,6 +555,10 @@
                       icon="cross_script"
                       label="${res:SiteExplorer_SelectedItem_Delete}"
                       class="Maestro.Base.Commands.SiteExplorer.DeleteSelectedItemsCommand" />
+            <MenuItem id="Duplicate"
+                      icon="document_copy"
+                      label="${res:SiteExplorer_DuplicateResources}"
+                      class="Maestro.Base.Commands.SiteExplorer.DuplicateResourceCommand" />
             <MenuItem type="Separator" />
             <Condition action="Disable" name="CanCutOrCopy">
                 <MenuItem id="Copy"

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-04-05 11:53:18 UTC (rev 5679)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-04-05 12:23:45 UTC (rev 5680)
@@ -101,6 +101,7 @@
     <Compile Include="Commands\SaveAllCommand.cs" />
     <Compile Include="Commands\SaveResourceAsCommand.cs" />
     <Compile Include="Commands\SaveResourceCommand.cs" />
+    <Compile Include="Commands\SiteExplorer\DuplicateResourceCommand.cs" />
     <Compile Include="Commands\SiteExplorer\PurgeFeatureSourceCacheCommand.cs" />
     <Compile Include="Commands\SiteExplorer\SaveResourceContentToDiskCommand.cs" />
     <Compile Include="Commands\ServerMonitorCommand.cs" />

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2011-04-05 11:53:18 UTC (rev 5679)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2011-04-05 12:23:45 UTC (rev 5680)
@@ -1299,6 +1299,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Resource Duplicated: {0} ( =&gt; {1}).
+        /// </summary>
+        internal static string ResourceDuplicated {
+            get {
+                return ResourceManager.GetString("ResourceDuplicated", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Resource Migrated: {0}.
         /// </summary>
         internal static string ResourceMigrated {
@@ -1612,6 +1621,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Duplicate Resources.
+        /// </summary>
+        internal static string SiteExplorer_DuplicateResources {
+            get {
+                return ResourceManager.GetString("SiteExplorer_DuplicateResources", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Migrate.
         /// </summary>
         internal static string SiteExplorer_Migrate {

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2011-04-05 11:53:18 UTC (rev 5679)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2011-04-05 12:23:45 UTC (rev 5680)
@@ -901,4 +901,10 @@
   <data name="SchemaInformationPurged" xml:space="preserve">
     <value>Schema information for {0} purged</value>
   </data>
+  <data name="ResourceDuplicated" xml:space="preserve">
+    <value>Resource Duplicated: {0} ( =&gt; {1})</value>
+  </data>
+  <data name="SiteExplorer_DuplicateResources" xml:space="preserve">
+    <value>Duplicate Resources</value>
+  </data>
 </root>
\ No newline at end of file



More information about the mapguide-commits mailing list