[mapguide-commits] r5034 - in sandbox/maestro-3.0: Maestro.Base/Editor Maestro.Editors Maestro.Editors/Common Maestro.Editors/FeatureSource/Providers Maestro.Editors/FeatureSource/Providers/Sdf Maestro.Editors/FeatureSource/Providers/Shp MaestroAPITests OSGeo.MapGuide.MaestroAPI/ObjectModels OSGeo.MapGuide.MaestroAPI/Properties OSGeo.MapGuide.MaestroAPI/Resource

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jul 16 08:50:46 EDT 2010


Author: jng
Date: 2010-07-16 12:50:46 +0000 (Fri, 16 Jul 2010)
New Revision: 5034

Modified:
   sandbox/maestro-3.0/Maestro.Base/Editor/ResourceEditorService.cs
   sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs
   sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/FileBasedCtrl.cs
   sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Sdf/SdfFileCtrl.cs
   sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs
   sandbox/maestro-3.0/Maestro.Editors/IEditorService.cs
   sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/IResource.cs
Log:
This submission includes the following changes:
 - Simplify the resource data API by making List/Add/Edit/Delete resource data methods as extension methods of IResource, thus giving all resource classes these methods automatically.
 - Add extra APIs to FeatureSourceType to extract alias names and embedded file names.
 - Add missing dirty state notification when a resource's data files have been modified.

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/ResourceEditorService.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/ResourceEditorService.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/ResourceEditorService.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -180,23 +180,28 @@
             }
         }
 
+        /*
         public void AddResourceData(string dataName, OSGeo.MapGuide.ObjectModels.Common.ResourceDataType type, System.IO.Stream stream)
         {
-            _conn.ResourceService.SetResourceData(_editCopy.ResourceID, dataName, type, stream);
+            //_conn.ResourceService.SetResourceData(_editCopy.ResourceID, dataName, type, stream);
+            _editCopy.SetResourceData(dataName, type, stream);
             this.IsDirty = true;
             OnDirtyStateChanged();
         }
 
         public System.IO.MemoryStream GetResourceData(string dataName)
         {
-            return _conn.ResourceService.GetResourceData(_editCopy.ResourceID, dataName);
+            //return _conn.ResourceService.GetResourceData(_editCopy.ResourceID, dataName);
+            _editCopy.GetResourceData(dataName);
         }
 
         public void RemoveResourceData(string dataName)
         {
-            _conn.ResourceService.DeleteResourceData(_editCopy.ResourceID, dataName);
+            //_conn.ResourceService.DeleteResourceData(_editCopy.ResourceID, dataName);
+            _editCopy.DeleteResourceData(dataName);
             OnDirtyStateChanged();
         }
+         */
 
         public string EditedResourceID
         {

Modified: sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -29,6 +29,7 @@
 using System.IO;
 using Maestro.Shared.UI;
 using OSGeo.MapGuide.MaestroAPI.Exceptions;
+using OSGeo.MapGuide.MaestroAPI.Resource;
 
 namespace Maestro.Editors.Common
 {
@@ -102,16 +103,7 @@
             }
             set
             {
-                ListViewItem it = null;
-                foreach (ListViewItem item in lstDataFiles.Items)
-                {
-                    if (item.Name == value)
-                        it = item;
-                }
-                if (it != null)
-                {
-                    MarkItem(it);
-                }
+                MarkResourceDataAsSelected(value);
             }
         }
 
@@ -120,18 +112,7 @@
             var list = _edSvc.ResourceService.EnumerateResourceData(_edSvc.EditedResourceID);
             _data = list.ResourceData;
 
-            foreach (var f in _data)
-            {
-                var item = new ListViewItem();
-                item.Tag = f;
-                item.Text = f.Name;
-                item.Name = f.Name;
-
-                if (_defaultFont == null)
-                    _defaultFont = item.Font;
-
-                lstDataFiles.Items.Add(item);
-            }
+            BindResourceList();
         }
 
         private void btnAdd_Click(object sender, EventArgs e)
@@ -146,7 +127,9 @@
                         {
                             using (var fs = new FileStream(open.FileName, FileMode.Open))
                             {
-                                _edSvc.AddResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
+                                //_edSvc.AddResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
+                                IResource res = _edSvc.GetEditedResource();
+                                res.SetResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
                                 LoadResourceData();
                                 OnDataListChanged();
                             }
@@ -176,8 +159,11 @@
                 {
                     using (new WaitCursor(this))
                     {
-                        _edSvc.RemoveResourceData(item.Name);
+                        //_edSvc.RemoveResourceData(item.Name);
+                        IResource res = _edSvc.GetEditedResource();
+                        res.DeleteResourceData(item.Name);
                         _data.Remove(item);
+                        BindResourceList();
                         OnDataListChanged();
                     }
                 }
@@ -203,7 +189,9 @@
                         {
                             using (new WaitCursor(this))
                             {
-                                var stream = _edSvc.GetResourceData(item.Name);
+                                //var stream = _edSvc.GetResourceData(item.Name);
+                                IResource res = _edSvc.GetEditedResource();
+                                var stream = res.GetResourceData(item.Name);
                                 File.WriteAllBytes(save.FileName, stream.GetBuffer());
                             }
                             MessageBox.Show(Properties.Resources.FileDownloaded);
@@ -221,26 +209,70 @@
         {
             if (lstDataFiles.SelectedItems.Count == 1)
             {
-                MarkItem(lstDataFiles.SelectedItems[0]);
+                MarkResourceDataAsSelected(lstDataFiles.SelectedItems[0].Name);
             }
         }
 
-        private void MarkItem(ListViewItem item)
+        private void MarkResourceDataAsSelected(string name)
         {
-            //Restore original font
+            ListViewItem item = null; 
+
+            //Find matching item
             foreach (ListViewItem it in lstDataFiles.Items)
             {
-                it.Font = new Font(_defaultFont, _defaultFont.Style);
+                if (it.Name == name)
+                {
+                    item = it;
+                    break;
+                }
             }
 
-            //Bold the selected item
-            var f = item.Font;
-            item.Font = new Font(f, f.Style | FontStyle.Bold);
+            if (item != null)
+            {
+                //Restore original font
+                foreach (ListViewItem it in lstDataFiles.Items)
+                {
+                    it.Font = new Font(_defaultFont, _defaultFont.Style);
+                }
+
+                //Bold the selected item
+                var f = item.Font;
+                item.Font = new Font(f, f.Style | FontStyle.Bold);
+            }
         }
 
+        private void BindResourceList()
+        {
+            lstDataFiles.Items.Clear();
+            foreach (var f in _data)
+            {
+                var item = new ListViewItem();
+                item.Tag = f;
+                item.Text = f.Name;
+                item.Name = f.Name;
+
+                if (_defaultFont == null)
+                    _defaultFont = item.Font;
+
+                lstDataFiles.Items.Add(item);
+            }
+        }
+
+
         private void lstDataFiles_SelectedIndexChanged(object sender, EventArgs e)
         {
             EvaluateCommands();
         }
+
+        public event ResourceDataSelectionEventHandler ResourceDataMarked;
+
+        private void OnResourceDataMarked(string name)
+        {
+            var handler = this.ResourceDataMarked;
+            if (handler != null)
+                handler(this, name);
+        }
     }
+
+    public delegate void ResourceDataSelectionEventHandler(object sender, string dataName);
 }

Modified: sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/FileBasedCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/FileBasedCtrl.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/FileBasedCtrl.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -49,9 +49,18 @@
 
         public virtual void Bind(IEditorService service)
         {
+            service.RegisterCustomNotifier(this);
             resDataCtrl.Init(service);
+            resDataCtrl.DataListChanged += (sender, e) => { OnResourceChanged(); };
         }
 
+        protected virtual void OnResourceChanged()
+        {
+            var handler = this.ResourceChanged;
+            if (handler != null)
+                handler(this, EventArgs.Empty);
+        }
+
         public event EventHandler ResourceChanged;
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Sdf/SdfFileCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Sdf/SdfFileCtrl.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Sdf/SdfFileCtrl.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -44,16 +44,21 @@
             _fs = service.GetEditedResource() as FeatureSourceType;
             Debug.Assert(_fs != null);
 
+            MarkSelected();
+        }
+
+        private void MarkSelected()
+        {
             var file = _fs.GetConnectionProperty("File");
             if (!string.IsNullOrEmpty(file))
             {
-                if (file.Contains("%MG_DATA_FILE_PATH%"))
+                if (_fs.UsesEmbeddedDataFiles)
                 {
                     rdManaged.Checked = true;
-                    var df = file.Substring("%MG_DATA_FILE_PATH%".Length);
+                    var df = _fs.GetEmbeddedDataName();
                     resDataCtrl.MarkedFile = df;
                 }
-                else
+                else if (_fs.UsesAliasedDataFiles)
                 {
                     rdUnmanaged.Checked = true;
                     txtAlias.Text = file;
@@ -61,6 +66,12 @@
             }
         }
 
+        protected override void OnResourceChanged()
+        {
+            base.OnResourceChanged();
+            MarkSelected();
+        }
+
         private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
         {
             _fs.SetConnectionProperty("ReadOnly", chkReadOnly.Checked.ToString().ToUpper());

Modified: sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -24,6 +24,8 @@
 using System.Data;
 using System.Text;
 using System.Windows.Forms;
+using OSGeo.MapGuide.ObjectModels.FeatureSource;
+using System.Diagnostics;
 
 namespace Maestro.Editors.FeatureSource.Providers.Shp
 {
@@ -33,5 +35,41 @@
         {
             InitializeComponent();
         }
+
+        private FeatureSourceType _fs;
+
+        public override void Bind(IEditorService service)
+        {
+            base.Bind(service);
+            _fs = service.GetEditedResource() as FeatureSourceType;
+            Debug.Assert(_fs != null);
+
+            MarkSelected();
+        }
+
+        private void MarkSelected()
+        {
+            var file = _fs.GetConnectionProperty("DefaultFileLocation");
+            if (!string.IsNullOrEmpty(file))
+            {
+                if (_fs.UsesEmbeddedDataFiles)
+                {
+                    rdManaged.Checked = true;
+                    var df = _fs.GetEmbeddedDataName();
+                    resDataCtrl.MarkedFile = df;
+                }
+                else if (_fs.UsesAliasedDataFiles)
+                {
+                    rdUnmanaged.Checked = true;
+                    txtAlias.Text = file;
+                }
+            }
+        }
+
+        protected override void OnResourceChanged()
+        {
+            base.OnResourceChanged();
+            MarkSelected();
+        }
     }
 }

Modified: sandbox/maestro-3.0/Maestro.Editors/IEditorService.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/IEditorService.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/Maestro.Editors/IEditorService.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -47,6 +47,7 @@
         /// Gets the associated drawing service
         /// </summary>
         IDrawingService DrawingService { get; }
+        /*
         /// <summary>
         /// Adds the specified resource data. Do not use the identical method exposed by the
         /// <see cref="ResourceService"/> property as this one has dirty state notification hooks
@@ -67,6 +68,7 @@
         /// </summary>
         /// <param name="dataName"></param>
         void RemoveResourceData(string dataName);
+         */
         /// <summary>
         /// Registers a custom notifier
         /// </summary>

Modified: sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/MaestroAPITests/ResourceTests.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -611,20 +611,60 @@
 
             Assert.IsTrue(fs.UsesEmbeddedDataFiles);
             Assert.IsFalse(fs.UsesAliasedDataFiles);
+            Assert.AreEqual(fs.GetEmbeddedDataName(), "Foo.sdf");
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasedFileName());
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasName());
 
             fs = new FeatureSourceType();
+            fs.Provider = "OSGeo.SDF";
+            fs.ConnectionString = "File=%MG_DATA_FILE_PATH%Bar.sdf;ReadOnly=TRUE";
+
+            Assert.IsTrue(fs.UsesEmbeddedDataFiles);
+            Assert.IsFalse(fs.UsesAliasedDataFiles);
+            Assert.AreEqual(fs.GetEmbeddedDataName(), "Bar.sdf");
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasedFileName());
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasName());
+
+            fs = new FeatureSourceType();
             fs.Provider = "OSGeo.SHP";
             fs.ConnectionString = "DefaultFileLocation=%MG_DATA_PATH_ALIAS[foobar]%";
 
             Assert.IsTrue(fs.UsesAliasedDataFiles);
             Assert.IsFalse(fs.UsesEmbeddedDataFiles);
+            Assert.AreEqual(fs.GetAliasName(), "foobar");
+            Assert.IsEmpty(fs.GetAliasedFileName());
+            Assert.Catch<InvalidOperationException>(() => fs.GetEmbeddedDataName());
 
             fs = new FeatureSourceType();
+            fs.Provider = "OSGeo.SDF";
+            fs.ConnectionString = "DefaultFileLocation=%MG_DATA_PATH_ALIAS[foobar]%Test.sdf";
+
+            Assert.IsTrue(fs.UsesAliasedDataFiles);
+            Assert.IsFalse(fs.UsesEmbeddedDataFiles);
+            Assert.AreEqual(fs.GetAliasName(), "foobar");
+            Assert.AreEqual(fs.GetAliasedFileName(), "Test.sdf");
+            Assert.Catch<InvalidOperationException>(() => fs.GetEmbeddedDataName());
+
+            fs = new FeatureSourceType();
+            fs.Provider = "OSGeo.SDF";
+            fs.ConnectionString = "DefaultFileLocation=%MG_DATA_PATH_ALIAS[foobar]%Test.sdf;ReadOnly=TRUE";
+
+            Assert.IsTrue(fs.UsesAliasedDataFiles);
+            Assert.IsFalse(fs.UsesEmbeddedDataFiles);
+            Assert.AreEqual(fs.GetAliasName(), "foobar");
+            Assert.AreEqual(fs.GetAliasedFileName(), "Test.sdf");
+            Assert.Catch<InvalidOperationException>(() => fs.GetEmbeddedDataName());
+
+            fs = new FeatureSourceType();
             fs.Provider = "OSGeo.SQLServerSpatial";
             fs.ConnectionString = "Service=(local)\\SQLEXPRESS;DataStore=TEST";
 
             Assert.IsFalse(fs.UsesEmbeddedDataFiles);
             Assert.IsFalse(fs.UsesAliasedDataFiles);
+
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasedFileName());
+            Assert.Catch<InvalidOperationException>(() => fs.GetAliasName());
+            Assert.Catch<InvalidOperationException>(() => fs.GetEmbeddedDataName());
         }
     }
 }

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ObjectModels/FeatureSource.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -167,12 +167,80 @@
             }
         }
 
+        const string DATA_TAG = "%MG_DATA_FILE_PATH%";
+
+        /// <summary>
+        /// Gets the name of the embedded data resource. Can only be called if <see cref="UsesEmbeddedDataFiles"/> returns true.
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="InvalidOperationException">If <see cref="UsesEmbeddedDataFiles"/> is false</exception>
+        public string GetEmbeddedDataName()
+        {
+            if (!this.UsesEmbeddedDataFiles)
+                throw new InvalidOperationException(OSGeo.MapGuide.MaestroAPI.Properties.Resources.ERR_FS_NO_EMBEDDED_DATA);
+
+            string connStr = this.ConnectionString;
+            int tagIndex = connStr.IndexOf(DATA_TAG);
+
+            int end = connStr.IndexOf(";", tagIndex + DATA_TAG.Length);
+            //The "File" parameter was the last parameter
+            if (end < 0)
+                return connStr.Substring(tagIndex + DATA_TAG.Length);
+            else
+                return connStr.Substring(tagIndex + DATA_TAG.Length, end - (tagIndex + DATA_TAG.Length));
+        }
+
+        const string ALIAS_PREFIX = "%MG_DATA_PATH_ALIAS[";
+
+        /// <summary>
+        /// Gets the name of the alias. Can only be called if <see cref="UsesAliasedDataFiles"/> returns true
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="InvalidOperationException">If <see cref="UsesAliasedDataFiles"/> is false </exception>
+        public string GetAliasName()
+        {
+            if (!this.UsesAliasedDataFiles)
+                throw new InvalidOperationException(OSGeo.MapGuide.MaestroAPI.Properties.Resources.ERR_FS_NO_ALIAS);
+
+            string connStr = this.ConnectionString;
+
+            int braceStart = connStr.IndexOf(ALIAS_PREFIX) + ALIAS_PREFIX.Length;
+            int braceEnd = connStr.IndexOf(']', braceStart + 1);
+            int length = braceEnd - braceStart;
+
+            return connStr.Substring(braceStart, length);
+        }
+
+        /// <summary>
+        /// Gets the name of the aliased file. Can only be called if <see cref="UsesAliasedDataFiles"/> returns true. An
+        /// empty string is returned if it is a directory (ie. no file name was found)
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="InvalidOperationException">If <see cref="UsesAliasedDataFiles"/> is false</exception>
+        public string GetAliasedFileName()
+        {
+            if (!this.UsesAliasedDataFiles)
+                throw new InvalidOperationException(OSGeo.MapGuide.MaestroAPI.Properties.Resources.ERR_FS_NO_ALIAS);
+
+            string connStr = this.ConnectionString;
+            int braceStart = connStr.IndexOf(ALIAS_PREFIX) + ALIAS_PREFIX.Length;
+            int braceEnd = connStr.IndexOf(']', braceStart + 1);
+            int aliasEnd = braceEnd + 2;
+
+            int end = connStr.IndexOf(";", aliasEnd);
+            //The "File" parameter was the last parameter
+            if (end < 0)
+                return connStr.Substring(aliasEnd);
+            else
+                return connStr.Substring(aliasEnd, end - aliasEnd);
+        }
+
         [XmlIgnore]
         public bool UsesEmbeddedDataFiles
         {
             get
             {
-                return this.ConnectionString.Contains("%MG_DATA_FILE_PATH%");
+                return this.ConnectionString.Contains(DATA_TAG);
             }
         }
 
@@ -181,7 +249,7 @@
         {
             get
             {
-                return this.ConnectionString.Contains("%MG_DATA_PATH_ALIAS[");
+                return this.ConnectionString.Contains(ALIAS_PREFIX);
             }
         }
     }

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.Designer.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -88,6 +88,24 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to This feature source does not connect an externally aliased file.
+        /// </summary>
+        internal static string ERR_FS_NO_ALIAS {
+            get {
+                return ResourceManager.GetString("ERR_FS_NO_ALIAS", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to This feature source does not connect to an embedded data file.
+        /// </summary>
+        internal static string ERR_FS_NO_EMBEDDED_DATA {
+            get {
+                return ResourceManager.GetString("ERR_FS_NO_EMBEDDED_DATA", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to There is no downgrade path to the desired resource version.
         /// </summary>
         internal static string ERR_NO_DOWNGRADE_PATH {

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Properties/Resources.resx	2010-07-16 12:50:46 UTC (rev 5034)
@@ -126,6 +126,12 @@
   <data name="ERR_CONVERTER_ALREADY_REGISTERED" xml:space="preserve">
     <value>A resource converter for {0} is already registered</value>
   </data>
+  <data name="ERR_FS_NO_ALIAS" xml:space="preserve">
+    <value>This feature source does not connect an externally aliased file</value>
+  </data>
+  <data name="ERR_FS_NO_EMBEDDED_DATA" xml:space="preserve">
+    <value>This feature source does not connect to an embedded data file</value>
+  </data>
   <data name="ERR_NO_DOWNGRADE_PATH" xml:space="preserve">
     <value>There is no downgrade path to the desired resource version</value>
   </data>

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/IResource.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/IResource.cs	2010-07-16 10:03:44 UTC (rev 5033)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Resource/IResource.cs	2010-07-16 12:50:46 UTC (rev 5034)
@@ -23,6 +23,7 @@
 using System.Xml.Serialization;
 using System.IO;
 using System.ComponentModel;
+using OSGeo.MapGuide.ObjectModels.Common;
 
 namespace OSGeo.MapGuide.MaestroAPI.Resource
 {
@@ -58,5 +59,48 @@
         {
             return new ResourceTypeDescriptor(res.ResourceType, res.ResourceVersion.ToString());
         }
+
+        /// <summary>
+        /// Convenience method for enumerating resource data of this resource
+        /// </summary>
+        /// <param name="res"></param>
+        /// <returns></returns>
+        public static ResourceDataListResourceData[] EnumerateResourceData(this IResource res)
+        {
+            return res.CurrentConnection.ResourceService.EnumerateResourceData(res.ResourceID).ResourceData.ToArray();
+        }
+
+        /// <summary>
+        /// Convenience method for getting an associated resource data stream of this resource
+        /// </summary>
+        /// <param name="res"></param>
+        /// <param name="dataName"></param>
+        /// <returns></returns>
+        public static MemoryStream GetResourceData(this IResource res, string dataName)
+        {
+            return res.CurrentConnection.ResourceService.GetResourceData(res.ResourceID, dataName);
+        }
+
+        /// <summary>
+        /// Convenience method for setting an associated resource data stream of this resource
+        /// </summary>
+        /// <param name="res"></param>
+        /// <param name="dataName"></param>
+        /// <param name="dataType"></param>
+        /// <param name="inputStream"></param>
+        public static void SetResourceData(this IResource res, string dataName, ResourceDataType dataType, Stream inputStream)
+        {
+            res.CurrentConnection.ResourceService.SetResourceData(res.ResourceID, dataName, dataType, inputStream);
+        }
+
+        /// <summary>
+        /// Convenience method for deleting an associated resource data stream of this resource
+        /// </summary>
+        /// <param name="res"></param>
+        /// <param name="dataName"></param>
+        public static void DeleteResourceData(this IResource res, string dataName)
+        {
+            res.CurrentConnection.ResourceService.DeleteResourceData(res.ResourceID, dataName);
+        }
     }
 }



More information about the mapguide-commits mailing list