[mapguide-commits] r6125 - in trunk/Tools/Maestro: Maestro.AddIn.Local Maestro.Base/Commands Maestro.Base/UI OSGeo.MapGuide.MaestroAPI/CrossConnection

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Sep 7 06:22:36 EDT 2011


Author: jng
Date: 2011-09-07 03:22:36 -0700 (Wed, 07 Sep 2011)
New Revision: 6125

Modified:
   trunk/Tools/Maestro/Maestro.AddIn.Local/OSGeo.MapGuide.Viewer.dll
   trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs
   trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
   trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CrossConnection/ResourceMigrator.cs
Log:
- Update mg-desktop viewer component (plugs connection leaks on selections)
- #1800: Update paste command to be multi-site aware

Modified: trunk/Tools/Maestro/Maestro.AddIn.Local/OSGeo.MapGuide.Viewer.dll
===================================================================
(Binary files differ)

Modified: trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs	2011-09-07 09:19:29 UTC (rev 6124)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/PasteCommand.cs	2011-09-07 10:22:36 UTC (rev 6125)
@@ -20,11 +20,14 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Linq;
 using ICSharpCode.Core;
+using Maestro.Editors;
 using Maestro.Base.Services;
 using Maestro.Base.UI;
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using Maestro.Shared.UI;
+using Wintellect.PowerCollections;
 
 namespace Maestro.Base.Commands
 {
@@ -60,9 +63,10 @@
             Dictionary<string, string> folders = new Dictionary<string, string>();
             var notPasted = new List<RepositoryItem>();
 
-            foreach (var item in itemsToPaste)
+            //From same connection
+            if (itemsToPaste.First().ConnectionName == targetConnName)
             {
-                if (item.ConnectionName == targetConnName) //From same connection
+                foreach (var item in itemsToPaste)
                 {
                     LoggingService.InfoFormatted(Properties.Resources.ClipboardAction, item.ClipboardState, item.ResourceId, folder.ResourceId);
 
@@ -121,11 +125,25 @@
                             folders[item.Parent.ResourceId] = item.Parent.ResourceId;
                     }
                 }
-                else
+            }
+            else
+            {
+                var copied = ((UI.SiteExplorer)exp).CopyResourcesToFolder(
+                    itemsToPaste.Select(x => new RepositoryHandle(new ResourceIdentifier(x.ResourceId), connMgr.GetConnection(x.ConnectionName))).ToArray(),
+                    targetConnName,
+                    folder.ResourceId);
+
+                //Delete any originating items that were successfully cut/pasted
+                foreach (var item in itemsToPaste)
                 {
-                    //TODO: Revisit later
-                    MessageService.ShowError("Copy/Pasting between connections is currently not implemented");
-                    return;
+                    if (item.ClipboardState == RepositoryItem.ClipboardAction.Cut)
+                    {
+                        var origConn = connMgr.GetConnection(item.ConnectionName);
+                        if (origConn.ResourceService.ResourceExists(item.ResourceId))
+                        {
+                            origConn.ResourceService.DeleteResource(item.ResourceId);
+                        }
+                    }
                 }
             }
             if (sourceItemsNotMoved.Count > 0)

Modified: trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs	2011-09-07 09:19:29 UTC (rev 6124)
+++ trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs	2011-09-07 10:22:36 UTC (rev 6125)
@@ -21,6 +21,7 @@
 using System.Collections.Generic;
 using System.Text;
 using OSGeo.MapGuide.MaestroAPI;
+using Maestro.Editors;
 
 namespace Maestro.Base.UI
 {

Modified: trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-09-07 09:19:29 UTC (rev 6124)
+++ trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-09-07 10:22:36 UTC (rev 6125)
@@ -420,79 +420,85 @@
                     }
                     else
                     {
-                        string rootSourceParent = GetCommonParent(data);
+                        CopyResourcesToFolder(data, connectionName, folderId);
+                    }
+                }
+            }
+        }
 
-                        //There is an implicit assumption here that all items dropped come from the same connection
-                        var sourceConn = data.First().Connection;
-                        var targetConn = _connManager.GetConnection(connectionName);
-                        var migrator = new ResourceMigrator(sourceConn, targetConn);
+        internal string[] CopyResourcesToFolder(RepositoryHandle[] data, string targetConnectionName, string folderId)
+        {
+            string rootSourceParent = GetCommonParent(data);
 
-                        //Collect all source ids
-                        var sourceIds = new List<string>();
-                        foreach (var resId in data.Select(x => x.ResourceId.ToString()))
-                        {
-                            if (ResourceIdentifier.IsFolderResource(resId))
-                                sourceIds.AddRange(GetFullResourceList(sourceConn, resId));
-                            else
-                                sourceIds.Add(resId);
-                        
-                        }
+            //There is an implicit assumption here that all items dropped come from the same connection
+            var sourceConn = data.First().Connection;
+            var targetConn = _connManager.GetConnection(targetConnectionName);
+            var migrator = new ResourceMigrator(sourceConn, targetConn);
 
-                        /*
-                        //If we're dropping to the root, the common parent becomes our 
-                        //target root
-                        if (folderId == "Library://")
-                            folderId = rootSourceParent;
-                        */
-                        //If common parent is not root, we want the name of the folder to append
-                        //to our target
-                        if (rootSourceParent != "Library://")
-                        {
-                            ResourceIdentifier resId = new ResourceIdentifier(rootSourceParent);
-                            folderId = folderId + resId.Name + "/";
-                        }
+            //Collect all source ids
+            var sourceIds = new List<string>();
+            foreach (var resId in data.Select(x => x.ResourceId.ToString()))
+            {
+                if (ResourceIdentifier.IsFolderResource(resId))
+                    sourceIds.AddRange(GetFullResourceList(sourceConn, resId));
+                else
+                    sourceIds.Add(resId);
 
-                        var targets = new List<string>();
-                        foreach (var resId in sourceIds)
-                        {
-                            var dstId = resId.Replace(rootSourceParent, folderId);
-                            System.Diagnostics.Trace.TraceInformation("{0} => {1}", resId, dstId);
-                            targets.Add(dstId);
-                        }
+            }
 
-                        bool overwrite = true;
-                        var existing = new List<string>();
-                        foreach (var resId in targets)
-                        {
-                            if (targetConn.ResourceService.ResourceExists(resId))
-                            {
-                                existing.Add(resId);
-                            }
-                        }
-                        if (existing.Count > 0)
-                            overwrite = MessageService.AskQuestion(string.Format(Properties.Resources.PromptOverwriteOnTargetConnection, existing.Count));
+            /*
+            //If we're dropping to the root, the common parent becomes our 
+            //target root
+            if (folderId == "Library://")
+                folderId = rootSourceParent;
+            */
+            //If common parent is not root, we want the name of the folder to append
+            //to our target
+            if (rootSourceParent != "Library://")
+            {
+                ResourceIdentifier resId = new ResourceIdentifier(rootSourceParent);
+                folderId = folderId + resId.Name + "/";
+            }
 
-                        var wb = Workbench.Instance;
-                        var dlg = new ProgressDialog();
-                        var worker = new ProgressDialog.DoBackgroundWork((w, evt, args) =>
-                        {
-                            LengthyOperationProgressCallBack cb = (s, cbe) =>
-                            {
-                                w.ReportProgress(cbe.Progress, cbe.StatusMessage);
-                            };
+            var targets = new List<string>();
+            foreach (var resId in sourceIds)
+            {
+                var dstId = resId.Replace(rootSourceParent, folderId);
+                System.Diagnostics.Trace.TraceInformation("{0} => {1}", resId, dstId);
+                targets.Add(dstId);
+            }
 
-                            return migrator.CopyResources(sourceIds.ToArray(), targets.ToArray(), overwrite, new RebaseOptions(rootSourceParent, folderId), cb);
-                        });
-
-                        dlg.RunOperationAsync(wb, worker);
-                        RefreshModel(targetConn.DisplayName, folderId);
-                        ExpandNode(targetConn.DisplayName, folderId);
-                    }
+            bool overwrite = true;
+            var existing = new List<string>();
+            foreach (var resId in targets)
+            {
+                if (targetConn.ResourceService.ResourceExists(resId))
+                {
+                    existing.Add(resId);
                 }
             }
+            if (existing.Count > 0)
+                overwrite = MessageService.AskQuestion(string.Format(Properties.Resources.PromptOverwriteOnTargetConnection, existing.Count));
+
+            var wb = Workbench.Instance;
+            var dlg = new ProgressDialog();
+            var worker = new ProgressDialog.DoBackgroundWork((w, evt, args) =>
+            {
+                LengthyOperationProgressCallBack cb = (s, cbe) =>
+                {
+                    w.ReportProgress(cbe.Progress, cbe.StatusMessage);
+                };
+
+                return migrator.CopyResources(sourceIds.ToArray(), targets.ToArray(), overwrite, new RebaseOptions(rootSourceParent, folderId), cb);
+            });
+
+            var result = (string[])dlg.RunOperationAsync(wb, worker);
+            RefreshModel(targetConn.DisplayName, folderId);
+            ExpandNode(targetConn.DisplayName, folderId);
+            return result; 
         }
 
-        private string GetCommonParent(RepositoryHandle[] data)
+        internal static string GetCommonParent(RepositoryHandle[] data)
         {
             if (data.Length > 0)
             {
@@ -534,8 +540,50 @@
             }
         }
 
-        private static IEnumerable<string> GetFullResourceList(IServerConnection sourceConn, string resId)
+        internal static string GetCommonParent(RepositoryItem[] data)
         {
+            if (data.Length > 0)
+            {
+                if (data.Length == 1)
+                {
+                    if (data[0].IsFolder)
+                        return data[0].ToString();
+                    else
+                        return data[0].Parent.ResourceId;
+                }
+                else
+                {
+                    int matches = 0;
+                    string[] parts = data.First().ResourceId.ToString()
+                                         .Substring("Library://".Length)
+                                         .Split('/');
+                    string test = "Library://";
+                    string parent = test;
+                    int partIndex = 0;
+                    //Use first one as a sample to see how far we can go. Keep going until we have
+                    //a parent that doesn't match all of them. The one we recorded before then will
+                    //be the common parent
+                    while (matches == data.Length)
+                    {
+                        parent = test;
+                        partIndex++;
+                        if (partIndex < parts.Length) //Shouldn't happen, but just in case
+                            break;
+
+                        test = test + parts[partIndex];
+                        matches = data.Where(x => x.ResourceId.StartsWith(test)).Count();
+                    }
+                    return parent;
+                }
+            }
+            else
+            {
+                return "Library://";
+            }
+        }
+
+        internal static IEnumerable<string> GetFullResourceList(IServerConnection sourceConn, string resId)
+        {
             var list = sourceConn.ResourceService.GetRepositoryResources(resId, -1);
             foreach (var res in list.Children)
             {

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CrossConnection/ResourceMigrator.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CrossConnection/ResourceMigrator.cs	2011-09-07 09:19:29 UTC (rev 6124)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/CrossConnection/ResourceMigrator.cs	2011-09-07 10:22:36 UTC (rev 6125)
@@ -60,12 +60,13 @@
         /// <param name="options">Re-base options</param>
         /// <param name="callback"></param>
         /// <returns></returns>
-        public int CopyResources(string[] sourceResourceIds, string[] targetResourceIds, bool overwrite, RebaseOptions options, LengthyOperationProgressCallBack callback)
+        public string[] CopyResources(string[] sourceResourceIds, string[] targetResourceIds, bool overwrite, RebaseOptions options, LengthyOperationProgressCallBack callback)
         {
             Check.NotNull(sourceResourceIds, "sourceResourceIds");
             Check.NotNull(targetResourceIds, "targetResourceIds");
             Check.Precondition(sourceResourceIds.Length == targetResourceIds.Length, "resourceIds.Length == targetResourceIds.Length");
 
+            var copiedItems = new List<string>();
             var cb = callback;
             if (cb == null)
             {
@@ -140,11 +141,12 @@
                     copied++;
                     message = string.Format(Properties.Resources.CopiedResourceToTarget, srcResId, dstResId);
                 }
+                copiedItems.Add(srcResId);
                 progress += unit;
                 cb(this, new LengthyOperationProgressArgs(message, progress));
             }
 
-            return copied;
+            return copiedItems.ToArray();
         }
 
         /// <summary>



More information about the mapguide-commits mailing list