[mapguide-commits] r5081 - in sandbox/maestro-3.0/Maestro.Base: . Commands Editor

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Aug 11 00:35:54 EDT 2010


Author: jng
Date: 2010-08-11 04:35:54 +0000 (Wed, 11 Aug 2010)
New Revision: 5081

Modified:
   sandbox/maestro-3.0/Maestro.Base/Commands/ValidateResourceCommand.cs
   sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs
   sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
   sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
Log:
This submission includes the following changes:
 - Enable validate resource command on toolbar
 - Enable profilable state for MapDefinition editor (command is still not implemented)


Modified: sandbox/maestro-3.0/Maestro.Base/Commands/ValidateResourceCommand.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Commands/ValidateResourceCommand.cs	2010-08-11 02:56:23 UTC (rev 5080)
+++ sandbox/maestro-3.0/Maestro.Base/Commands/ValidateResourceCommand.cs	2010-08-11 04:35:54 UTC (rev 5081)
@@ -20,10 +20,128 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using ICSharpCode.Core;
+using Maestro.Base.Services;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using OSGeo.MapGuide.ObjectModels.Common;
+using System.ComponentModel;
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Exceptions;
 
 namespace Maestro.Base.Commands
 {
-    internal class ValidateResourceCommand : NotImplementedCommand
+    internal class ValidateResourceCommand : AbstractMenuCommand
     {
+        private IServerConnection _conn;
+
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            var ed = wb.ActiveEditor;
+            var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+
+            //TODO: Will need to look at this again, when we decide to support
+            //multiple connections to different sites from the same session. Right
+            //now this is fine as we can only connect to one site at any time.
+            _conn = connMgr.GetConnection(wb.ActiveSiteExplorer.ConnectionName);
+
+            if (ed != null)
+            {
+                var pdlg = new ProgressDialog();
+                pdlg.CancelAbortsThread = true;
+
+                var issues = (ValidationIssue[])pdlg.RunOperationAsync(wb, new ProgressDialog.DoBackgroundWork(BackgroundValidate), ed.Resource.ResourceID);
+
+                if (issues != null)
+                {
+                    if (issues.Length > 0)
+                    {
+                        //Sigh! LINQ would've made this code so simple...
+
+                        var sort = new Dictionary<string, List<ValidationIssue>>();
+                        foreach (var issue in issues)
+                        {
+                            string resId = issue.Resource.ResourceID;
+                            if (!sort.ContainsKey(resId))
+                                sort[resId] = new List<ValidationIssue>();
+
+                            sort[resId].Add(issue);
+                        }
+
+                        var groupedIssues = new List<KeyValuePair<string, ValidationIssue[]>>();
+                        foreach (var kvp in sort)
+                        {
+                            groupedIssues.Add(
+                                new KeyValuePair<string, ValidationIssue[]>(
+                                    kvp.Key,
+                                    kvp.Value.ToArray()));
+                        }
+
+                        var resDlg = new ValidationResultsDialog(groupedIssues);
+                        resDlg.ShowDialog(wb);
+                    }
+                    else
+                    {
+                        MessageService.ShowMessage(Properties.Resources.ValidationNoIssues);
+                    }
+                }
+            }
+        }
+
+        private object BackgroundValidate(BackgroundWorker worker, DoWorkEventArgs e, params object[] args)
+        {
+            //Collect all documents to be validated. Some of these selected items
+            //may be folders.
+            var documents = new List<string>();
+            foreach (object a in args)
+            {
+                string rid = a.ToString();
+                if (ResourceIdentifier.Validate(rid))
+                {
+                    var resId = new ResourceIdentifier(rid);
+                    if (resId.IsFolder)
+                    {
+                        foreach (IRepositoryItem o in _conn.ResourceService.GetRepositoryResources((string)args[0]).Children)
+                        {
+                            if (!o.IsFolder)
+                            {
+                                documents.Add(o.ResourceId);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        documents.Add(rid);
+                    }
+                }
+            }
+
+            worker.ReportProgress(0);
+
+            var issues = new List<ValidationIssue>();
+            int i = 0;
+            foreach (string s in documents)
+            {
+                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
+                IResource item = null;
+                try
+                {
+                    //TODO: This will validate resources multiple times, if they are referenced by
+                    //resources inside the folder
+                    item = _conn.ResourceService.GetResource(s);
+                    issues.AddRange(ResourceValidatorSet.Validate(item, true));
+                }
+                catch (Exception ex)
+                {
+                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
+                    issues.Add(new ValidationIssue(item, ValidationStatus.Error, string.Format(Properties.Resources.ValidationResourceLoadFailed, msg)));
+                }
+                i++;
+                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
+            }
+
+            return issues.ToArray();
+        }
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs	2010-08-11 02:56:23 UTC (rev 5080)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/EditorContentBase.cs	2010-08-11 04:35:54 UTC (rev 5081)
@@ -111,7 +111,7 @@
 
         public virtual bool CanBeValidated
         {
-            get { return false; }
+            get { return true; }
         }
 
         public virtual bool CanEditAsXml

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs	2010-08-11 02:56:23 UTC (rev 5080)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/MapDefinitionEditor.cs	2010-08-11 04:35:54 UTC (rev 5081)
@@ -64,5 +64,13 @@
                 e.Cancel = true;
             }
         }
+
+        public override bool CanProfile
+        {
+            get
+            {
+                return true;
+            }
+        }
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin	2010-08-11 02:56:23 UTC (rev 5080)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin	2010-08-11 04:35:54 UTC (rev 5081)
@@ -205,10 +205,12 @@
                          tooltip="${res:Menu_File_PreviewResource}"
                          class="Maestro.Base.Commands.NotImplementedCommand" />
         </Condition>
-        <ToolbarItem id="XmlEdit"
-                     icon="document_code"
-                     tooltip="${res:Menu_File_EditResourceWithXml}"
-                     class="Maestro.Base.Commands.NotImplementedCommand" />
+        <Condition action="Disable" name="EditorFunction" property="CanEditAsXml">
+            <ToolbarItem id="XmlEdit"
+                         icon="document_code"
+                         tooltip="${res:Menu_File_EditResourceWithXml}"
+                         class="Maestro.Base.Commands.NotImplementedCommand" />
+        </Condition>
         <Condition action="Disable" name="EditorFunction" property="CanProfile">
             <ToolbarItem id="Profile"
                          icon="clock"
@@ -219,7 +221,7 @@
             <ToolbarItem id="Validate"
                          icon="tick"
                          tooltip="${res:Menu_File_ValidateResource}"
-                         class="Maestro.Base.Commands.NotImplementedCommand" />
+                         class="Maestro.Base.Commands.ValidateResourceCommand" />
         </Condition>
         <!-- 
         Only needed if our custom drawn close buttons don't appear on document
@@ -227,6 +229,7 @@
         
         This command is a fallback in case there are problems.
         -->
+        <!--
         <ToolbarItem type="Separator" />
         <Condition action="Disable" name="CanClose">
             <ToolbarItem id="CloseDocument"



More information about the mapguide-commits mailing list