[mapguide-commits] r4430 - in trunk/Tools/Maestro: Maestro MaestroAPI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Dec 12 19:16:45 EST 2009


Author: ksgeograf
Date: 2009-12-12 19:16:45 -0500 (Sat, 12 Dec 2009)
New Revision: 4430

Modified:
   trunk/Tools/Maestro/Maestro/ResourceProperties.cs
   trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs
Log:
Maestro:
Fixed issue #1183.

Modified: trunk/Tools/Maestro/Maestro/ResourceProperties.cs
===================================================================
--- trunk/Tools/Maestro/Maestro/ResourceProperties.cs	2009-12-12 23:29:28 UTC (rev 4429)
+++ trunk/Tools/Maestro/Maestro/ResourceProperties.cs	2009-12-13 00:16:45 UTC (rev 4430)
@@ -854,8 +854,12 @@
                     m_backgroundThread = System.Threading.Thread.CurrentThread;
 
                 string resourceId = (ResourceIdentifier)e.Argument;
-                ResourceReferenceList lst = m_connection.EnumerateResourceReferences(resourceId);
 
+                List<string> lst = new List<string>();
+                foreach (string s in  m_connection.EnumerateResourceReferences(resourceId).ResourceId)
+                    if (!lst.Contains(s))
+                        lst.Add(s);
+
                 System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                 using(System.IO.MemoryStream ms = new System.IO.MemoryStream(m_connection.GetResourceXmlData(resourceId)))
                     doc.Load(ms);
@@ -863,7 +867,8 @@
                 List<KeyValuePair<System.Xml.XmlNode, string>> refs = Utility.GetResourceIdPointers(doc);
                 List<string> r = new List<string>();
                 foreach (KeyValuePair<System.Xml.XmlNode, string> s in refs)
-                    r.Add(s.Value);
+                    if (!r.Contains(s.Value))
+                        r.Add(s.Value);
                 e.Result = new object[] { lst, r };
             }
             catch(System.Threading.ThreadAbortException)
@@ -904,13 +909,13 @@
 
             OutReferences.Enabled = InReferences.Enabled = true;
 
-            ResourceReferenceList l1 = ((object[])e.Result)[0] as ResourceReferenceList;
+            List<string> l1 = ((object[])e.Result)[0] as List<string>;
             List<string> l2 = ((object[])e.Result)[1] as List<string>;
 
             foreach (string s in l2)
                 OutReferenceList.Items.Add(s, m_editor.GetImageIndexFromResourceID(s));
 
-            foreach (string s in l1.ResourceId)
+            foreach (string s in l1)
                 InReferenceList.Items.Add(s, m_editor.GetImageIndexFromResourceID(s));
 
             m_hasLoadedRefs = true;

Modified: trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs	2009-12-12 23:29:28 UTC (rev 4429)
+++ trunk/Tools/Maestro/MaestroAPI/ServerConnectionBase.cs	2009-12-13 00:16:45 UTC (rev 4430)
@@ -718,39 +718,62 @@
 				if (!pi.CanRead || !pi.CanWrite || pi.GetIndexParameters().Length != 0 || pi.GetValue(o, null) == null)
 					continue;
 
+                object v = pi.GetValue(o, null);
+                if (v == null)
+                    continue;
+
+                if (v is string)
+
                 //If we are at a ResourceId property, update it as needed
-				if (pi.Name == "ResourceId")
-				{
-					object v = pi.GetValue(o, null);
-					string current = v as string;
+                    if (v is string)
+                    {
+                        bool isResId = pi.Name == "ResourceId";
+                        if (!isResId)
+                        {
+                            //Search for attributes
+                            object[] xmlAttrs = pi.GetCustomAttributes(typeof(System.Xml.Serialization.XmlElementAttribute), false);
+                            if (xmlAttrs != null)
+                                foreach (System.Xml.Serialization.XmlElementAttribute attr in xmlAttrs)
+                                    if (attr.Type == typeof(string) && attr.ElementName == "ResourceId")
+                                        if (pi.Name == "ResourceId")
+                                        {
+                                            isResId = true;
+                                            break;
+                                        }
+                        }
 
-					if (current != null)
-					{
-						if (folderupdates && current.StartsWith(oldresourcepath))
-							pi.SetValue(o, newresourcepath + current.Substring(oldresourcepath.Length), null);
-						else if (current == oldresourcepath)
-							pi.SetValue(o, newresourcepath, null); 
-					}
-				}
-				else if (pi.GetValue(o, null).GetType().GetInterface(typeof(System.Collections.ICollection).FullName) != null)
-				{
-                    //Handle collections
-					System.Collections.ICollection srcList = (System.Collections.ICollection)pi.GetValue(o, null);
-					foreach(object ox in srcList)
-						UpdateResourceReferences(ox, oldresourcepath, newresourcepath, folderupdates, visited);
-				}
-				else if (pi.GetValue(o, null).GetType().IsArray)
-				{
-                    //Handle arrays
-					System.Array sourceArr = (System.Array)pi.GetValue(o, null);
-					for(int i = 0; i < sourceArr.Length; i++)
-						UpdateResourceReferences(sourceArr.GetValue(i), oldresourcepath, newresourcepath, folderupdates, visited);
-				}
-                else if (pi.PropertyType.IsClass)
-                {
-                    //Handle subobjects
-                    UpdateResourceReferences(pi.GetValue(o, null), oldresourcepath, newresourcepath, folderupdates, visited);
-                }
+                        if (isResId)
+                        {
+                            string current = v as string;
+
+                            if (current != null)
+                            {
+                                if (folderupdates && current.StartsWith(oldresourcepath))
+                                    pi.SetValue(o, newresourcepath + current.Substring(oldresourcepath.Length), null);
+                                else if (current == oldresourcepath)
+                                    pi.SetValue(o, newresourcepath, null);
+                            }
+                        }
+                    }
+                    else if (v is IEnumerable)
+                    {
+                        //Handle collections
+                        System.Collections.IEnumerable srcList = (System.Collections.IEnumerable)v;
+                        foreach (object ox in srcList)
+                            UpdateResourceReferences(ox, oldresourcepath, newresourcepath, folderupdates, visited);
+                    }
+                    else if (v.GetType().IsArray)
+                    {
+                        //Handle arrays
+                        System.Array sourceArr = (System.Array)v;
+                        for (int i = 0; i < sourceArr.Length; i++)
+                            UpdateResourceReferences(sourceArr.GetValue(i), oldresourcepath, newresourcepath, folderupdates, visited);
+                    }
+                    else if (v.GetType().IsClass)
+                    {
+                        //Handle subobjects
+                        UpdateResourceReferences(v, oldresourcepath, newresourcepath, folderupdates, visited);
+                    }
 			}
 
 		}
@@ -831,11 +854,18 @@
 
 				try
 				{
-					object o = GetResource(item.Itempath);
+                    System.Xml.XmlDocument d = new System.Xml.XmlDocument();
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream(GetResourceXmlData(item.Itempath)))
+                        d.Load(ms);
 
-					UpdateResourceReferences(o, oldpath, newpath, false);
+                    UpdateResourceReferences(d, oldpath, newpath, false);
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
+                    {
+                        d.Save(ms);
+                        ms.Position = 0;
 
-					SaveResourceAs(o, item.Itempath);
+                        SetResourceXmlData(item.Itempath, ms);
+                    }
 					item.Status = LengthyOperationCallbackArgs.LengthyOperationItem.OperationStatus.Success;
 				}
 				catch (Exception ex)
@@ -953,13 +983,20 @@
 
 				try
 				{
-					object o = GetResource(item.Itempath);
+                    System.Xml.XmlDocument d = new System.Xml.XmlDocument();
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream(GetResourceXmlData(item.Itempath)))
+                        d.Load(ms);
 
-					UpdateResourceReferences(o, oldpath, newpath, true);
+                    UpdateResourceReferences(d, oldpath, newpath, true);
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
+                    {
+                        d.Save(ms);
+                        ms.Position = 0;
 
-					SaveResourceAs(o, item.Itempath);
-					item.Status = LengthyOperationCallbackArgs.LengthyOperationItem.OperationStatus.Success;
-				}
+                        SetResourceXmlData(item.Itempath, ms);
+                    }
+                    item.Status = LengthyOperationCallbackArgs.LengthyOperationItem.OperationStatus.Success;
+                }
 				catch (Exception ex)
 				{
 					string s = ex.Message;
@@ -1073,13 +1110,20 @@
 
 				try
 				{
-					object o = GetResource(item.Itempath);
+                    System.Xml.XmlDocument d = new System.Xml.XmlDocument();
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream(GetResourceXmlData(item.Itempath)))
+                        d.Load(ms);
 
-					UpdateResourceReferences(o, oldpath, newpath, true);
+                    UpdateResourceReferences(d, oldpath, newpath, true);
+                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
+                    {
+                        d.Save(ms);
+                        ms.Position = 0;
 
-					SaveResourceAs(o, item.Itempath);
-					item.Status = LengthyOperationCallbackArgs.LengthyOperationItem.OperationStatus.Success;
-				}
+                        SetResourceXmlData(item.Itempath, ms);
+                    }
+                    item.Status = LengthyOperationCallbackArgs.LengthyOperationItem.OperationStatus.Success;
+                }
 				catch (Exception ex)
 				{
 					string s = ex.Message;



More information about the mapguide-commits mailing list