[mapguide-commits] r5303 - in sandbox/maestro-3.0: Maestro.Base
Maestro.Base/Properties Maestro.Base/Services
Maestro.Base/Services/DragDropHandlers Maestro.Base/UI
MaestroAPITests OSGeo.MapGuide.MaestroAPI
OSGeo.MapGuide.MaestroAPI/ObjectModels
OSGeo.MapGuide.MaestroAPI/Resource
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Oct 20 08:14:34 EDT 2010
Author: jng
Date: 2010-10-20 05:14:34 -0700 (Wed, 20 Oct 2010)
New Revision: 5303
Added:
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlerService.cs
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs
sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs
sandbox/maestro-3.0/Maestro.Base/Services/IDragDropHandler.cs
sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorerDragDropHandler.cs
Modified:
sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorer.cs
sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceContentVersionChecker.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceTypeDescriptor.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs
Log:
3.0 sandbox changes:
- Port the Object Explorer drag handler functionality from FDO Toolbox.
- Tweak the xml content version inspection to use the xsi:noNamespaceSchemaLocation attribute as this has all the required information needed to construct a ResourceTypeDescriptor instance.
Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.addin 2010-10-20 12:14:34 UTC (rev 5303)
@@ -28,6 +28,14 @@
<Class id="GeneralPrefs" class="Maestro.Base.UI.Preferences.GeneralPreferencesCtrl" />
</Path>
+ <!-- Registered drop handlers -->
+ <Path name="/Maestro/DragDropHandlers">
+ <Class id="SdfHandler" class="Maestro.Base.Services.DragDropHandlers.SdfFileHandler" />
+ <Class id="ShpHandler" class="Maestro.Base.Services.DragDropHandlers.ShpFileHandler" />
+ <Class id="SltHandler" class="Maestro.Base.Services.DragDropHandlers.SltFileHandler" />
+ <Class id="XmlResHandler" class="Maestro.Base.Services.DragDropHandlers.XmlResFileHandler" />
+ </Path>
+
<!-- Registered editors -->
<Path name="/Maestro/Editors">
<Class id="DrawingSourceEditor100" class="Maestro.Base.Editor.DrawingSourceEditorFactory" />
@@ -169,6 +177,7 @@
<!-- Application-level services -->
<Path name="/Maestro/ApplicationServices">
+ <Class id="DragDropHandlerService" class="Maestro.Base.Services.DragDropHandlerService" />
<Class id="ClipboardService" class="Maestro.Base.Services.ClipboardService" />
<Class id="ServerConnectionManager" class="Maestro.Base.Services.ServerConnectionManager" />
<Class id="UrlLauncher" class="Maestro.Base.Services.UrlLauncherService" />
Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj 2010-10-20 12:14:34 UTC (rev 5303)
@@ -171,6 +171,12 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Services\ClipboardService.cs" />
+ <Compile Include="Services\DragDropHandlerService.cs" />
+ <Compile Include="Services\DragDropHandlers\SltFileHandler.cs" />
+ <Compile Include="Services\DragDropHandlers\SdfFileHandler.cs" />
+ <Compile Include="Services\DragDropHandlers\ShpFileHandler.cs" />
+ <Compile Include="Services\DragDropHandlers\XmlResFileHandler.cs" />
+ <Compile Include="Services\IDragDropHandler.cs" />
<Compile Include="Services\NewItemTemplateService.cs" />
<Compile Include="Services\OpenResourceManager.cs" />
<Compile Include="Services\ServerConnectionManager.cs" />
@@ -275,6 +281,7 @@
<DependentUpon>SiteExplorer.cs</DependentUpon>
</Compile>
<Compile Include="TabFactory.cs" />
+ <Compile Include="UI\SiteExplorerDragDropHandler.cs" />
<Compile Include="UI\ValidationResultsDialog.cs">
<SubType>Form</SubType>
</Compile>
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.Designer.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -1100,6 +1100,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Create a SDF Feature Source.
+ /// </summary>
+ internal static string SdfHandlerAction {
+ get {
+ return ResourceManager.GetString("SdfHandlerAction", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Select FDO Provider.
/// </summary>
internal static string SelectFdoProvider {
@@ -1161,6 +1170,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Create a SHP Feature Source.
+ /// </summary>
+ internal static string ShpHandlerAction {
+ get {
+ return ResourceManager.GetString("ShpHandlerAction", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Resource Name: {1}{0}Resource Type: {2}{0}Created: {3}{0}Last Modified: {4}{0}Owner: {5}.
/// </summary>
internal static string SITE_EXPLORER_TOOLTIP_TEMPLATE {
@@ -1286,6 +1304,15 @@
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Create a SQLite Feature Source.
+ /// </summary>
+ internal static string SltHandlerAction {
+ get {
+ return ResourceManager.GetString("SltHandlerAction", resourceCulture);
+ }
+ }
+
internal static System.Drawing.Bitmap tick {
get {
object obj = ResourceManager.GetObject("tick", resourceCulture);
@@ -1634,5 +1661,14 @@
return ResourceManager.GetString("ValidationValidating", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to Load this resource into the Site Repository.
+ /// </summary>
+ internal static string XmlResHandlerAction {
+ get {
+ return ResourceManager.GetString("XmlResHandlerAction", resourceCulture);
+ }
+ }
}
}
Modified: sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/Maestro.Base/Properties/Resources.resx 2010-10-20 12:14:34 UTC (rev 5303)
@@ -712,4 +712,16 @@
<data name="ConfirmMove" xml:space="preserve">
<value>Are you sure you want to move the following resources?</value>
</data>
+ <data name="SdfHandlerAction" xml:space="preserve">
+ <value>Create a SDF Feature Source</value>
+ </data>
+ <data name="ShpHandlerAction" xml:space="preserve">
+ <value>Create a SHP Feature Source</value>
+ </data>
+ <data name="SltHandlerAction" xml:space="preserve">
+ <value>Create a SQLite Feature Source</value>
+ </data>
+ <data name="XmlResHandlerAction" xml:space="preserve">
+ <value>Load this resource into the Site Repository</value>
+ </data>
</root>
\ No newline at end of file
Added: sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlerService.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlerService.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlerService.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,87 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 System.IO;
+using ICSharpCode.Core;
+
+namespace Maestro.Base.Services
+{
+ public class DragDropHandlerService : ServiceBase
+ {
+ public override void Initialize()
+ {
+ base.Initialize();
+ _handlers = new Dictionary<string, List<IDragDropHandler>>();
+
+ //Find and register drag and drop handlers
+ List<IDragDropHandler> handlers = AddInTree.BuildItems<IDragDropHandler>("/Maestro/DragDropHandlers", this);
+ if (handlers != null)
+ {
+ foreach (IDragDropHandler h in handlers)
+ {
+ RegisterHandler(h);
+ }
+ }
+ }
+
+ private Dictionary<string, List<IDragDropHandler>> _handlers;
+
+ /// <summary>
+ /// Registers a drag and drop handler.
+ /// </summary>
+ /// <param name="handler">The handler.</param>
+ public void RegisterHandler(IDragDropHandler handler)
+ {
+ foreach (string fileExt in handler.FileExtensions)
+ {
+ string ext = fileExt.ToUpper();
+ if (!_handlers.ContainsKey(ext))
+ _handlers[ext] = new List<IDragDropHandler>();
+
+ _handlers[ext].Add(handler);
+ }
+ }
+
+ /// <summary>
+ /// Gets the registered handlers for this particular file type
+ /// </summary>
+ /// <param name="file">The file being dropped</param>
+ /// <returns>A list of registered handlers</returns>
+ public IList<IDragDropHandler> GetHandlersForFile(string file)
+ {
+ string ext = Path.GetExtension(file).ToUpper();
+ if (_handlers.ContainsKey(ext))
+ return _handlers[ext];
+
+ return new List<IDragDropHandler>();
+ }
+
+ /// <summary>
+ /// Gets the list of file extensions being handled
+ /// </summary>
+ /// <returns></returns>
+ public ICollection<string> GetHandledExtensions()
+ {
+ return _handlers.Keys;
+ }
+ }
+}
Added: sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,81 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 OSGeo.MapGuide.MaestroAPI.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using System.IO;
+using ICSharpCode.Core;
+
+namespace Maestro.Base.Services.DragDropHandlers
+{
+ public class SdfFileHandler : IDragDropHandler
+ {
+ public string HandlerAction
+ {
+ get { return Properties.Resources.SdfHandlerAction; }
+ }
+
+ string[] extensions = { ".sdf" };
+
+ public string[] FileExtensions
+ {
+ get { return extensions; }
+ }
+
+ public bool HandleDrop(string file, string folderId)
+ {
+ try
+ {
+ var wb = Workbench.Instance;
+ var exp = wb.ActiveSiteExplorer;
+ var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ var conn = mgr.GetConnection(exp.ConnectionName);
+ var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SDF");
+
+ string fileName = Path.GetFileName(file);
+ string resName = Path.GetFileNameWithoutExtension(file);
+ int counter = 0;
+ string resId = folderId + resName + ".FeatureSource";
+ while (conn.ResourceService.ResourceExists(resId))
+ {
+ counter++;
+ resId = folderId + resName + " (" + counter + ").FeatureSource";
+ }
+ fs.ResourceID = resId;
+ fs.SetConnectionProperty("File", "%MG_DATA_FILE_PATH%" + fileName);
+ conn.ResourceService.SaveResource(fs);
+
+ using (var stream = File.Open(file, FileMode.Open))
+ {
+ fs.SetResourceData(fileName, OSGeo.MapGuide.ObjectModels.Common.ResourceDataType.File, stream);
+ }
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageService.ShowError(ex);
+ return false;
+ }
+ }
+ }
+}
Added: sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,99 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 OSGeo.MapGuide.MaestroAPI.ObjectModels;
+using System.IO;
+using ICSharpCode.Core;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+
+namespace Maestro.Base.Services.DragDropHandlers
+{
+ public class ShpFileHandler : IDragDropHandler
+ {
+ public string HandlerAction
+ {
+ get { return Properties.Resources.ShpHandlerAction; }
+ }
+
+ private string[] extensions = { ".shp" };
+
+ public string[] FileExtensions
+ {
+ get { return extensions; }
+ }
+
+ public bool HandleDrop(string file, string folderId)
+ {
+ try
+ {
+ var wb = Workbench.Instance;
+ var exp = wb.ActiveSiteExplorer;
+ var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ var conn = mgr.GetConnection(exp.ConnectionName);
+ var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SHP");
+
+ string fileName = Path.GetFileName(file);
+ string resName = Path.GetFileNameWithoutExtension(file);
+ int counter = 0;
+ string resId = folderId + resName + ".FeatureSource";
+ while (conn.ResourceService.ResourceExists(resId))
+ {
+ counter++;
+ resId = folderId + resName + " (" + counter + ").FeatureSource";
+ }
+ fs.ResourceID = resId;
+ fs.SetConnectionProperty("DefaultFileLocation", "%MG_DATA_FILE_PATH%" + fileName);
+ conn.ResourceService.SaveResource(fs);
+
+ //As we all know, the term shape file is deceptive...
+ string[] files = new string[]
+ {
+ file,
+ file.Substring(0, file.LastIndexOf(".")) + ".shx",
+ file.Substring(0, file.LastIndexOf(".")) + ".dbf",
+ file.Substring(0, file.LastIndexOf(".")) + ".idx",
+ file.Substring(0, file.LastIndexOf(".")) + ".prj",
+ file.Substring(0, file.LastIndexOf(".")) + ".cpg"
+ };
+
+ foreach (string fn in files)
+ {
+ if (File.Exists(fn))
+ {
+ using (var stream = File.Open(fn, FileMode.Open))
+ {
+ string dataName = Path.GetFileName(fn);
+ fs.SetResourceData(dataName, OSGeo.MapGuide.ObjectModels.Common.ResourceDataType.File, stream);
+ }
+ }
+ }
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageService.ShowError(ex);
+ return false;
+ }
+ }
+ }
+}
Added: sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,81 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 OSGeo.MapGuide.MaestroAPI.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using System.IO;
+using ICSharpCode.Core;
+
+namespace Maestro.Base.Services.DragDropHandlers
+{
+ public class SltFileHandler : IDragDropHandler
+ {
+ public string HandlerAction
+ {
+ get { return Properties.Resources.SdfHandlerAction; }
+ }
+
+ string[] extensions = { ".sqlite", ".db", ".slt" };
+
+ public string[] FileExtensions
+ {
+ get { return extensions; }
+ }
+
+ public bool HandleDrop(string file, string folderId)
+ {
+ try
+ {
+ var wb = Workbench.Instance;
+ var exp = wb.ActiveSiteExplorer;
+ var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ var conn = mgr.GetConnection(exp.ConnectionName);
+ var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SQLite");
+
+ string fileName = Path.GetFileName(file);
+ string resName = Path.GetFileNameWithoutExtension(file);
+ int counter = 0;
+ string resId = folderId + resName + ".FeatureSource";
+ while (conn.ResourceService.ResourceExists(resId))
+ {
+ counter++;
+ resId = folderId + resName + " (" + counter + ").FeatureSource";
+ }
+ fs.ResourceID = resId;
+ fs.SetConnectionProperty("File", "%MG_DATA_FILE_PATH%" + fileName);
+ conn.ResourceService.SaveResource(fs);
+
+ using (var stream = File.Open(file, FileMode.Open))
+ {
+ fs.SetResourceData(fileName, OSGeo.MapGuide.ObjectModels.Common.ResourceDataType.File, stream);
+ }
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageService.ShowError(ex);
+ return false;
+ }
+ }
+ }
+}
Added: sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,87 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 OSGeo.MapGuide.MaestroAPI.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using System.IO;
+using ICSharpCode.Core;
+using OSGeo.MapGuide.MaestroAPI;
+
+namespace Maestro.Base.Services.DragDropHandlers
+{
+ public class XmlResFileHandler : IDragDropHandler
+ {
+ public string HandlerAction
+ {
+ get { return Properties.Resources.XmlResHandlerAction; }
+ }
+
+ private string[] extensions = { ".xml",
+ ".FeatureSource",
+ ".LayerDefinition",
+ ".MapDefinition",
+ ".WebLayout",
+ ".SymbolDefinition",
+ ".ApplicationDefinition",
+ ".PrintLayout",
+ };
+
+ public string[] FileExtensions
+ {
+ get { return extensions; }
+ }
+
+ public bool HandleDrop(string file, string folderId)
+ {
+ try
+ {
+ var wb = Workbench.Instance;
+ var exp = wb.ActiveSiteExplorer;
+ var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+ var conn = mgr.GetConnection(exp.ConnectionName);
+
+ //The easiest way to tell if this XML file is legit
+ var res = ResourceTypeRegistry.Deserialize(File.ReadAllText(file));
+
+ int counter = 0;
+ string name = Path.GetFileNameWithoutExtension(file);
+ string resId = folderId + name + "." + res.ResourceType.ToString();
+
+ while (conn.ResourceService.ResourceExists(resId))
+ {
+ counter++;
+ resId = folderId + name + " (" + counter + ")." + res.ResourceType.ToString();
+ }
+
+ res.ResourceID = resId;
+ conn.ResourceService.SaveResource(res);
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageService.ShowError(ex);
+ return false;
+ }
+ }
+ }
+}
Added: sandbox/maestro-3.0/Maestro.Base/Services/IDragDropHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Services/IDragDropHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/Services/IDragDropHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,49 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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;
+
+namespace Maestro.Base.Services
+{
+ /// <summary>
+ /// Drag and Drop handler interface
+ /// </summary>
+ public interface IDragDropHandler
+ {
+ /// <summary>
+ /// Gets a description of the action this handler will take
+ /// </summary>
+ string HandlerAction { get; }
+
+ /// <summary>
+ /// Gets the file extensions this handler can handle
+ /// </summary>
+ string[] FileExtensions { get; }
+
+ /// <summary>
+ /// Handles the file drop
+ /// </summary>
+ /// <param name="file">The file being dropped</param>
+ /// <param name="folderId">The site explorer folder this drop was performed</param>
+ /// <returns>true if the drop was successfully handled</returns>
+ bool HandleDrop(string file, string folderId);
+ }
+}
Modified: sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorer.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorer.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -336,38 +336,44 @@
private void trvResources_DragDrop(object sender, DragEventArgs e)
{
var data = e.Data.GetData(typeof(ResourceIdentifier[])) as ResourceIdentifier[];
- if (data == null || data.Length == 0)
- return;
-
- //See if the mouse is currently over a node
- var node = trvResources.GetNodeAt(trvResources.PointToClient(new Point(e.X, e.Y)));
- if (node == null)
- return;
-
- //Can only drop in a folder
- var item = node.Tag as RepositoryItem;
- if (item != null && item.IsFolder)
+ if (data == null)
{
- string folderId = item.ResourceId;
- List<string> resIds = new List<string>();
- foreach (var n in data)
- {
- resIds.Add(n.ToString());
- }
+ //See if the mouse is currently over a node
+ var node = trvResources.GetNodeAt(trvResources.PointToClient(new Point(e.X, e.Y)));
+ SiteExplorerDragDropHandler.OnDragDrop(this, e, node);
+ }
+ else
+ {
+ //See if the mouse is currently over a node
+ var node = trvResources.GetNodeAt(trvResources.PointToClient(new Point(e.X, e.Y)));
+ if (node == null)
+ return;
- //I think it's nice to ask for confirmation
- if (resIds.Count > 0)
+ //Can only drop in a folder
+ var item = node.Tag as RepositoryItem;
+ if (item != null && item.IsFolder)
{
- if (!MessageService.AskQuestion(Properties.Resources.ConfirmMove))
- return;
- }
+ string folderId = item.ResourceId;
+ List<string> resIds = new List<string>();
+ foreach (var n in data)
+ {
+ resIds.Add(n.ToString());
+ }
- string [] folders = MoveResources(resIds, folderId);
+ //I think it's nice to ask for confirmation
+ if (resIds.Count > 0)
+ {
+ if (!MessageService.AskQuestion(Properties.Resources.ConfirmMove))
+ return;
+ }
- foreach (var fid in folders)
- {
- LoggingService.Info("Refreshing: " + fid);
- RefreshModel(fid);
+ string[] folders = MoveResources(resIds, folderId);
+
+ foreach (var fid in folders)
+ {
+ LoggingService.Info("Refreshing: " + fid);
+ RefreshModel(fid);
+ }
}
}
}
@@ -375,30 +381,31 @@
private void trvResources_DragOver(object sender, DragEventArgs e)
{
var data = e.Data.GetData(typeof(ResourceIdentifier[])) as ResourceIdentifier[];
- if (data == null || data.Length == 0)
+ if (data == null)
{
- e.Effect = DragDropEffects.None;
- return;
+ SiteExplorerDragDropHandler.OnDragEnter(this, e);
}
-
- //See if the mouse is currently over a node
- var node = trvResources.GetNodeAt(trvResources.PointToClient(new Point(e.X, e.Y)));
- if (node == null)
+ else
{
- e.Effect = DragDropEffects.None;
- return;
- }
+ //See if the mouse is currently over a node
+ var node = trvResources.GetNodeAt(trvResources.PointToClient(new Point(e.X, e.Y)));
+ if (node == null)
+ {
+ e.Effect = DragDropEffects.None;
+ return;
+ }
- //Is it a folder?
- var item = node.Tag as RepositoryItem;
- if (item != null && item.IsFolder)
- {
- e.Effect = DragDropEffects.Move;
+ //Is it a folder?
+ var item = node.Tag as RepositoryItem;
+ if (item != null && item.IsFolder)
+ {
+ e.Effect = DragDropEffects.Move;
+ }
+ else
+ {
+ e.Effect = DragDropEffects.None;
+ }
}
- else
- {
- e.Effect = DragDropEffects.None;
- }
}
private void trvResources_DragEnter(object sender, DragEventArgs e)
Added: sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorerDragDropHandler.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorerDragDropHandler.cs (rev 0)
+++ sandbox/maestro-3.0/Maestro.Base/UI/SiteExplorerDragDropHandler.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -0,0 +1,97 @@
+#region Disclaimer / License
+// Copyright (C) 2010, 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 System.Windows.Forms;
+using Maestro.Base.Services;
+using Maestro.Shared.UI;
+using Aga.Controls.Tree;
+
+namespace Maestro.Base.UI
+{
+ internal sealed class SiteExplorerDragDropHandler
+ {
+ internal static void OnDragEnter(ISiteExplorer sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
+ {
+ Array a = e.Data.GetData(DataFormats.FileDrop) as Array;
+ if (a != null && a.Length > 0)
+ {
+ e.Effect = DragDropEffects.Copy;
+ }
+ else
+ e.Effect = DragDropEffects.None;
+ }
+ else
+ e.Effect = DragDropEffects.None;
+ }
+
+ internal static void OnDragDrop(ISiteExplorer sender, DragEventArgs e, TreeNodeAdv droppedNode)
+ {
+ //If drop node specified, extract relevant folder, otherwise default to root (Library://)
+ string folderId = "Library://";
+ if (droppedNode != null)
+ {
+ var ri = droppedNode.Tag as RepositoryItem;
+ if (ri != null)
+ {
+ if (ri.IsFolder)
+ folderId = ri.ResourceId;
+ else
+ folderId = ri.Parent != null ? ri.Parent.ResourceId : "Library://";
+ }
+ }
+
+ Array a = e.Data.GetData(DataFormats.FileDrop) as Array;
+ bool refresh = false;
+ if (a != null && a.Length > 0)
+ {
+ DragDropHandlerService handlerSvc = ServiceRegistry.GetService<DragDropHandlerService>();
+ for (int i = 0; i < a.Length; i++)
+ {
+ string file = a.GetValue(i).ToString();
+
+ IList<IDragDropHandler> handlers = handlerSvc.GetHandlersForFile(file);
+
+ if (handlers.Count == 0)
+ continue;
+
+ if (handlers.Count == 1)
+ {
+ using (new WaitCursor(Workbench.Instance))
+ {
+ if (handlers[0].HandleDrop(file, folderId))
+ refresh = true;
+ }
+ }
+
+ if (handlers.Count > 1)
+ {
+ //Resolve which handler to use
+ }
+ }
+ }
+ if (refresh)
+ sender.RefreshModel(folderId);
+ }
+ }
+}
Modified: sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -735,5 +735,45 @@
Assert.Catch<InvalidOperationException>(() => fs.GetAliasName());
Assert.Catch<InvalidOperationException>(() => fs.GetEmbeddedDataName());
}
+
+ [Test]
+ public void TestResourceTypeDescriptor()
+ {
+ var rtd = new ResourceTypeDescriptor(ResourceTypes.ApplicationDefinition, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "ApplicationDefinition-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.DrawingSource, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "DrawingSource-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.FeatureSource, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "FeatureSource-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.LayerDefinition, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "LayerDefinition-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.LayerDefinition, "1.1.0");
+ Assert.AreEqual(rtd.XsdName, "LayerDefinition-1.1.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.LoadProcedure, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "LoadProcedure-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.MapDefinition, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "MapDefinition-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.DrawingSource, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "DrawingSource-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.PrintLayout, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "PrintLayout-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.SymbolDefinition, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "SymbolDefinition-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.SymbolLibrary, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "SymbolLibrary-1.0.0.xsd");
+
+ rtd = new ResourceTypeDescriptor(ResourceTypes.WebLayout, "1.0.0");
+ Assert.AreEqual(rtd.XsdName, "WebLayout-1.0.0.xsd");
+ }
}
}
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/ObjectFactory.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -157,7 +157,8 @@
return new FeatureSourceType()
{
CurrentConnection = owner,
- Provider = provider
+ Provider = provider,
+ Parameter = new System.ComponentModel.BindingList<NameValuePairType>()
};
}
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceContentVersionChecker.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceContentVersionChecker.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceContentVersionChecker.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -22,6 +22,7 @@
using System.Text;
using System.IO;
using System.Xml;
+using OSGeo.MapGuide.MaestroAPI.Exceptions;
namespace OSGeo.MapGuide.MaestroAPI.Resource
{
@@ -33,7 +34,7 @@
public sealed class ResourceContentVersionChecker : IDisposable
{
private XmlReader _reader;
- private MemoryStream _stream;
+ private Stream _stream;
/// <summary>
/// Constructor
@@ -41,8 +42,10 @@
/// <param name="stream">The resource content stream. Inspection is done on a copy of this stream</param>
public ResourceContentVersionChecker(Stream stream)
{
- _stream = new MemoryStream();
- Utility.CopyStream(stream, _stream);
+ var ms = new MemoryStream();
+ Utility.CopyStream(stream, ms);
+ ms.Position = 0L; //Rewind
+ _stream = ms;
_reader = new XmlTextReader(_stream);
}
@@ -52,7 +55,7 @@
/// <param name="xmlContent"></param>
public ResourceContentVersionChecker(string xmlContent)
{
- _reader = new XmlTextReader(new StringReader(xmlContent));
+ _stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent));
}
private ResourceTypeDescriptor _rtd;
@@ -65,17 +68,37 @@
{
if (_rtd == null)
{
- _reader.Read();
+ _rtd = GetVersionFromXmlStream(_stream);
+ }
+ return _rtd;
+ }
- if (!_reader.HasAttributes)
- throw new XmlException(Properties.Resources.ERR_BAD_DOCUMENT_NO_ROOT_ATTRIBUTES);
+ public static ResourceTypeDescriptor GetVersionFromXmlStream(Stream ms)
+ {
+ string version = "1.0.0";
+ using (var xr = XmlReader.Create(ms))
+ {
+ xr.MoveToContent();
+ if (!xr.HasAttributes)
+ throw new SerializationException();
- ResourceTypes rt = (ResourceTypes)Enum.Parse(typeof(ResourceTypes), _reader.Name);
- string version = _reader.GetAttribute("version");
+ try
+ {
+ //Parse version number from ResourceType-x.y.z.xsd
+ string xsd = xr.GetAttribute("xsi:noNamespaceSchemaLocation");
+ int start = (xsd.LastIndexOf("-"));
+ int end = xsd.IndexOf(".xsd") - 1;
+ version = xsd.Substring(start + 1, xsd.Length - end);
+ string typeStr = xsd.Substring(0, start);
- _rtd = new ResourceTypeDescriptor(rt, version);
+ return new ResourceTypeDescriptor((ResourceTypes)Enum.Parse(typeof(ResourceTypes), typeStr), version);
+
+ }
+ finally
+ {
+ xr.Close();
+ }
}
- return _rtd;
}
/// <summary>
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceTypeDescriptor.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceTypeDescriptor.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/ResourceTypeDescriptor.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -38,6 +38,14 @@
this.Version = ver;
}
+ public string XsdName
+ {
+ get
+ {
+ return ResourceType + "-" + Version + ".xsd";
+ }
+ }
+
public string ResourceType { get; set; }
public string Version { get; set; }
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs 2010-10-20 08:55:48 UTC (rev 5302)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ResourceTypeRegistry.cs 2010-10-20 12:14:34 UTC (rev 5303)
@@ -37,6 +37,7 @@
using OSGeo.MapGuide.ObjectModels.FeatureSource;
using OSGeo.MapGuide.ObjectModels.MapDefinition;
using OSGeo.MapGuide.ObjectModels.DrawingSource;
+using System.Diagnostics;
namespace OSGeo.MapGuide.MaestroAPI
{
@@ -188,101 +189,31 @@
public static IResource Deserialize(ResourceTypes resourceType, Stream stream)
{
//UGLY: We have to peek inside the stream to determine the version number
- //DOUBLE UGLY: WebLayout documents don't have the version attribute so we have to peek at the xsd schema name
- if (resourceType == ResourceTypes.WebLayout)
+
+ //House the stream inside a rewindable memory stream
+ using (var ms = new MemoryStream())
{
- //House the stream inside a rewindable memory stream
- using (var ms = new MemoryStream())
- {
- string version = "1.0.0";
- Utility.CopyStream(stream, ms);
- ms.Position = 0L; //Rewind
- using (var xr = XmlReader.Create(ms))
- {
- xr.MoveToContent();
- if (!xr.HasAttributes)
- throw new SerializationException();
-
- try
- {
- //Parse version number from WebLayout-x.y.z.xsd
- string xsd = xr.GetAttribute("xsi:noNamespaceSchemaLocation");
- int start = ("WebLayout-".Length);
- int end = xsd.IndexOf(".xsd") - 1;
- version = xsd.Substring(start, xsd.Length - end);
+ Utility.CopyStream(stream, ms);
+ ms.Position = 0L; //Rewind
- }
- catch
- {
- version = "1.0.0";
- }
- finally
- {
- if (string.IsNullOrEmpty(version))
- version = "1.0.0";
- }
- xr.Close();
- }
+ var rd = ResourceContentVersionChecker.GetVersionFromXmlStream(ms);
+ Debug.Assert(rd.ResourceType.Equals(resourceType.ToString()));
- ms.Position = 0L; //Rewind
+ ms.Position = 0L; //Rewind
- var rd = new ResourceTypeDescriptor(resourceType, version);
- using (var reader = new StreamReader(ms))
- {
- var xml = reader.ReadToEnd();
- if (_serializers.ContainsKey(rd))
- return _serializers[rd].Deserialize(xml);
- else
- return new UntypedResource(xml, resourceType, version);
- }
- }
- }
- else
- {
- //House the stream inside a rewindable memory stream
- using (var ms = new MemoryStream())
+ using (var reader = new StreamReader(ms))
{
- Utility.CopyStream(stream, ms);
- string version = "1.0.0";
- ms.Position = 0L; //Rewind
- using (var xr = XmlReader.Create(ms))
- {
- xr.MoveToContent();
- if (!xr.HasAttributes)
- throw new SerializationException();
-
- //Resources post-1.0.0 have a version attribute, those without are assumed to be 1.0.0 version
- try
- {
- version = xr.GetAttribute("version");
- }
- catch
- {
- version = "1.0.0";
- }
- finally
- {
- if (string.IsNullOrEmpty(version))
- version = "1.0.0";
- }
- xr.Close();
- }
-
- ms.Position = 0L; //Rewind
-
- var rd = new ResourceTypeDescriptor(resourceType, version);
- using (var reader = new StreamReader(ms))
- {
- var xml = reader.ReadToEnd();
- if (_serializers.ContainsKey(rd))
- return _serializers[rd].Deserialize(xml);
- else
- return new UntypedResource(xml, resourceType, version);
- }
+ var xml = reader.ReadToEnd();
+ if (_serializers.ContainsKey(rd))
+ return _serializers[rd].Deserialize(xml);
+ else
+ return new UntypedResource(xml, resourceType, rd.Version);
}
}
}
+
+
public static Stream Serialize(IResource res)
{
var rd = res.GetResourceTypeDescriptor();
More information about the mapguide-commits
mailing list