[mapguide-commits] r4344 - in trunk/Tools/Maestro/MaestroAPI: .
RuntimeClasses
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Sun Nov 15 18:10:34 EST 2009
Author: ksgeograf
Date: 2009-11-15 18:10:34 -0500 (Sun, 15 Nov 2009)
New Revision: 4344
Added:
trunk/Tools/Maestro/MaestroAPI/Selection.cs
Modified:
trunk/Tools/Maestro/MaestroAPI/HttpServerConnection.cs
trunk/Tools/Maestro/MaestroAPI/LocalNativeConnection.cs
trunk/Tools/Maestro/MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
trunk/Tools/Maestro/MaestroAPI/RuntimeClasses/RuntimeMap.cs
Log:
Maestro:
Fixed issue #858, selection support in MaestroAPI (no more Xml required).
Modified: trunk/Tools/Maestro/MaestroAPI/HttpServerConnection.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/HttpServerConnection.cs 2009-11-11 22:06:46 UTC (rev 4343)
+++ trunk/Tools/Maestro/MaestroAPI/HttpServerConnection.cs 2009-11-15 23:10:34 UTC (rev 4344)
@@ -619,7 +619,10 @@
SetResourceData(resourceID, "RuntimeData", ResourceDataType.Stream, ms);
if (ms2 != null)
SetResourceData(resourceID, "LayerGroupData", ResourceDataType.Stream, ms2);
- }
+
+ if (map.HasLoadedSelectionXml)
+ SetSelectionXml(resourceID, map.Selection.ToXml());
+ }
finally
{
map.Name = r;
Modified: trunk/Tools/Maestro/MaestroAPI/LocalNativeConnection.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/LocalNativeConnection.cs 2009-11-11 22:06:46 UTC (rev 4343)
+++ trunk/Tools/Maestro/MaestroAPI/LocalNativeConnection.cs 2009-11-15 23:10:34 UTC (rev 4344)
@@ -342,6 +342,9 @@
SetResourceData(resourceID, "RuntimeData", ResourceDataType.Stream, ms);
if (ms2 != null)
SetResourceData(resourceID, "LayerGroupData", ResourceDataType.Stream, ms2);
+
+ if (map.HasLoadedSelectionXml)
+ SetSelectionXml(resourceID, map.Selection.ToXml());
}
finally
{
Modified: trunk/Tools/Maestro/MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj 2009-11-11 22:06:46 UTC (rev 4343)
+++ trunk/Tools/Maestro/MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj 2009-11-15 23:10:34 UTC (rev 4344)
@@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<ProjectType>Local</ProjectType>
- <ProductVersion>9.0.21022</ProductVersion>
+ <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{290B027E-3649-4A60-A9BF-0544831435E2}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -294,6 +294,7 @@
<Compile Include="RuntimeClasses\Selection.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Selection.cs" />
<Compile Include="ServerConnectionBase.cs">
<SubType>Code</SubType>
</Compile>
Modified: trunk/Tools/Maestro/MaestroAPI/RuntimeClasses/RuntimeMap.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/RuntimeClasses/RuntimeMap.cs 2009-11-11 22:06:46 UTC (rev 4343)
+++ trunk/Tools/Maestro/MaestroAPI/RuntimeClasses/RuntimeMap.cs 2009-11-15 23:10:34 UTC (rev 4344)
@@ -19,6 +19,7 @@
#endregion
using System;
using System.Collections;
+using System.Collections.Generic;
namespace OSGeo.MapGuide.MaestroAPI.RuntimeClasses
{
@@ -28,7 +29,6 @@
/// </summary>
public class RuntimeMap : OSGeo.MapGuide.MaestroAPI.MapDefinition
{
-
protected string m_objid;
protected const int MgBinaryVersion = 262144; //1;
protected const int ClassId = 11500; //30500;
@@ -38,6 +38,7 @@
protected new RuntimeMapLayerCollection m_mapLayer;
protected new RuntimeMapGroupCollection m_mapLayerGroup;
+ protected MaestroAPI.Selection m_selection = null;
Box2DType m_dataExtent = new Box2DType();
int m_displaydpi;
@@ -180,6 +181,21 @@
set { m_mapLayerGroup = value; }
}
+ public bool HasLoadedSelectionXml
+ {
+ get { return m_selection != null; }
+ }
+
+ public MaestroAPI.Selection Selection
+ {
+ get
+ {
+ if (m_selection == null)
+ m_selection = new OSGeo.MapGuide.MaestroAPI.Selection(this, m_serverConnection.GetSelectionXml(m_resourceID));
+ return m_selection;
+ }
+ }
+
internal void Serialize(BinarySerializer.MgBinarySerializer s)
{
if (s.SiteVersion >= SiteVersions.GetVersion(KnownSiteVersions.MapGuideOS1_2))
@@ -631,7 +647,7 @@
{
protected double[] m_scaleRanges;
protected int m_type;
- protected ArrayList m_ids;
+ protected List<KeyValuePair<string, Type>> m_ids;
protected bool m_needRefresh;
protected double m_displayOrder;
protected string m_featureSourceId;
@@ -660,7 +676,7 @@
{
m_scaleRanges = new double[] {0.0, InfinityScale};
m_type = OSGeo.MapGuide.MgLayerType.Dynamic;
- m_ids = new ArrayList();
+ m_ids = new List<KeyValuePair<string, Type>>();
m_schemaName = "";
m_featureName = "";
@@ -743,7 +759,7 @@
}
if (m_ids == null)
- m_ids = new ArrayList();
+ m_ids = new List<KeyValuePair<string,Type>>();
}
@@ -763,7 +779,7 @@
if (fs.Provider.StartsWith("OSGeo.Gdal") || fs.Provider.StartsWith("OSGeo.WMS") || fs.Provider.StartsWith("Autodesk.Raster"))
{
if (m_ids == null)
- m_ids = new ArrayList();
+ m_ids = new List<KeyValuePair<string,Type>>();
return;
}
@@ -772,12 +788,12 @@
if (scm != null)
{
- m_ids = new ArrayList();
+ m_ids = new List<KeyValuePair<string, Type>>();
foreach(string id in ids)
foreach(OSGeo.MapGuide.MaestroAPI.FeatureSetColumn fsc in scm.Columns)
if (fsc.Name == id)
{
- m_ids.Add(new object[] {(short)Utility.ConvertNetTypeToMgType(fsc.Type), id});
+ m_ids.Add(new KeyValuePair<string, Type> (id, fsc.Type));
break;
}
}
@@ -832,14 +848,14 @@
m_featureName = d.ReadString();
m_geometry = d.ReadString();
- ArrayList ids = new ArrayList();
+ List<KeyValuePair<string, Type>> ids = new List<KeyValuePair<string, Type>>();
int idCount = d.ReadInt32();
while(idCount-- > 0)
{
short idType = d.ReadInt16();
string idName = d.ReadString();
- ids.Add(new object[] { idType, idName } );
+ ids.Add(new KeyValuePair<string, Type>(idName, Utility.ConvertMgTypeToNetType(idType)));
}
m_ids = ids;
@@ -873,14 +889,14 @@
m_schemaName = d.ReadInternalString();
m_geometry = d.ReadInternalString();
- ArrayList ids = new ArrayList();
+ List<KeyValuePair<string, Type>> ids = new List<KeyValuePair<string, Type>>();
int idCount = BitConverter.ToInt32(d.ReadStreamRepeat(4), 0);
while(idCount-- > 0)
{
short idType = BitConverter.ToInt16(d.ReadStreamRepeat(2), 0);
string idName = d.ReadInternalString();
- ids.Add(new object[] { idType, idName } );
+ ids.Add(new KeyValuePair<string, Type>(idName, Utility.ConvertMgTypeToNetType(idType)));
}
m_ids = ids;
@@ -923,10 +939,10 @@
s.Write(m_geometry);
s.Write(m_ids.Count);
- foreach(object[] x in m_ids)
+ foreach(KeyValuePair<string, Type> x in m_ids)
{
- s.Write((short)x[0]);
- s.Write((string)x[1]);
+ s.Write((short)Utility.ConvertNetTypeToMgType(x.Value));
+ s.Write(x.Key);
}
}
else
@@ -956,13 +972,11 @@
s.WriteStringInternal(m_geometry);
s.WriteRaw(BitConverter.GetBytes(m_ids.Count));
- foreach(object[] x in m_ids)
+ foreach(KeyValuePair<string, Type> x in m_ids)
{
- s.WriteRaw(BitConverter.GetBytes((short)x[0]));
- s.WriteStringInternal((string)x[1]);
+ s.WriteRaw(BitConverter.GetBytes((short)Utility.ConvertNetTypeToMgType(x.Value)));
+ s.WriteStringInternal(x.Key);
}
-
-
}
}
@@ -1112,15 +1126,17 @@
set { m_type = value; }
}
- public ArrayList IDs
+ /// <summary>
+ /// Returns the list of columns that comprise the primary key for the layer
+ /// </summary>
+ public IList<KeyValuePair<string, Type>> IDs
{
get
{
if (m_ids == null || m_ids.Count == 0)
FindResourceIDs();
- return m_ids;
+ return new System.Collections.ObjectModel.ReadOnlyCollection<KeyValuePair<string, Type>>(m_ids);
}
- set { m_ids = value; }
}
}
@@ -1202,6 +1218,15 @@
{
base.InnerList.Insert(index, layer);
}
+
+ public RuntimeClasses.RuntimeMapLayer FindByGuid(string guid)
+ {
+ foreach (RuntimeMapLayer l in base.InnerList)
+ if (l.Guid == guid)
+ return l;
+
+ return null;
+ }
}
Added: trunk/Tools/Maestro/MaestroAPI/Selection.cs
===================================================================
--- trunk/Tools/Maestro/MaestroAPI/Selection.cs (rev 0)
+++ trunk/Tools/Maestro/MaestroAPI/Selection.cs 2009-11-15 23:10:34 UTC (rev 4344)
@@ -0,0 +1,629 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI
+{
+ /// <summary>
+ /// A wrapper class to help deal with the selection xml format
+ /// </summary>
+ public class Selection : IList<Selection.LayerSelection>
+ {
+ private RuntimeClasses.RuntimeMap m_map;
+ private List<LayerSelection> m_layers;
+
+ /// <summary>
+ /// Constructs a new selection helper
+ /// </summary>
+ /// <param name="map">The map that the selection belongs to</param>
+ public Selection(RuntimeClasses.RuntimeMap map)
+ {
+ m_layers = new List<LayerSelection>();
+ m_map = map;
+ }
+
+ /// <summary>
+ /// Constructs a new selection helper
+ /// </summary>
+ /// <param name="map">The map that the selection belongs to</param>
+ /// <param name="xml">A selection xml to initialize the selection with</param>
+ public Selection(RuntimeClasses.RuntimeMap map, string xml)
+ : this(map)
+ {
+ }
+
+ /// <summary>
+ /// Resets the selectionhelper to match the provided xml
+ /// </summary>
+ /// <param name="xml">The selection xml</param>
+ public void FromXml(string xml)
+ {
+ m_layers.Clear();
+
+ System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
+ if (!string.IsNullOrEmpty(xml))
+ doc.LoadXml(xml);
+
+ //There are two variations
+ System.Xml.XmlNodeList lst = doc.SelectNodes("FeatureSet/Layer");
+ if (lst.Count == 0)
+ lst = doc.SelectNodes("FeatureInformation/FeatureSet/Layer");
+
+ foreach (System.Xml.XmlNode n in lst)
+ {
+ if (n.Attributes["id"] != null)
+ {
+ string guid = n.Attributes["id"].Value;
+ RuntimeClasses.RuntimeMapLayer l = m_map.Layers.FindByGuid(guid);
+ if (l != null)
+ {
+ foreach (System.Xml.XmlNode c in n.SelectNodes("Class"))
+ {
+ if (c.Attributes["id"] != null)
+ if (c.Attributes["id"].Value == l.SchemaName + ":" + l.FeatureName)
+ m_layers.Add(new LayerSelection(l, c.SelectNodes("ID")));
+ }
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Returns an xml document that represents the current map selection
+ /// </summary>
+ /// <returns>An xml document that represents the current map selection</returns>
+ public string ToXml()
+ {
+ System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
+ System.Xml.XmlNode root = doc.AppendChild(doc.CreateElement("FeatureSet"));
+
+ foreach (LayerSelection layer in m_layers)
+ {
+ System.Xml.XmlNode ln = root.AppendChild(doc.CreateElement("Layer"));
+ ln.Attributes.Append(doc.CreateAttribute("id")).Value = layer.Layer.Guid;
+
+ System.Xml.XmlNode cn = ln.AppendChild(doc.CreateElement("Class"));
+ cn.Attributes.Append(doc.CreateAttribute("id")).Value = layer.Layer.SchemaName + ":" + layer.Layer.FeatureName;
+
+ for (int i = 0; i < layer.Count; i++)
+ cn.AppendChild(doc.CreateElement("ID")).InnerText = layer.EncodeIDString(layer[i]);
+ }
+
+ return doc.OuterXml;
+ }
+
+ /// <summary>
+ /// Helper class to represent a layer with selected objects
+ /// </summary>
+ public class LayerSelection : IList<object[]>
+ {
+ private RuntimeClasses.RuntimeMapLayer m_layer;
+ private List<object[]> m_list = new List<object[]>();
+
+ /// <summary>
+ /// Gets the layer that contains the selected objects
+ /// </summary>
+ public RuntimeClasses.RuntimeMapLayer Layer { get { return m_layer; } }
+
+ /// <summary>
+ /// Internal helper to construct a LayerSelection
+ /// </summary>
+ /// <param name="layer">The layer that the selection belongs to</param>
+ /// <param name="ids">A list of xml <ID> nodes</param>
+ internal LayerSelection(RuntimeClasses.RuntimeMapLayer layer, System.Xml.XmlNodeList ids)
+ : this(layer)
+ {
+ foreach (System.Xml.XmlNode n in ids)
+ Add(ParseIDString(n.InnerXml));
+ }
+
+ /// <summary>
+ /// Encodes the given combined keyset into an ID string for use in the Xml
+ /// </summary>
+ /// <param name="values">The combined key</param>
+ /// <returns>A base64 encoded ID string</returns>
+ public string EncodeIDString(object[] values)
+ {
+ object[] tmp = NormalizeAndValidate(values);
+
+ using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
+ {
+ for (int i = 0; i < m_layer.IDs.Count; i++)
+ {
+ Type type = m_layer.IDs[i].Value;
+
+ if (type == typeof(short))
+ {
+ byte[] x = BitConverter.GetBytes((short)tmp[i]);
+ ms.Write(x, 0, x.Length);
+ }
+ else if (type == typeof(int))
+ {
+ byte[] x = BitConverter.GetBytes((int)tmp[i]);
+ ms.Write(x, 0, x.Length);
+ }
+ else if (type == typeof(long))
+ {
+ byte[] x = BitConverter.GetBytes((long)tmp[i]);
+ ms.Write(x, 0, x.Length);
+ }
+ else if (type == typeof(string))
+ {
+ byte[] x = System.Text.Encoding.UTF8.GetBytes((string)tmp[i]);
+ ms.Write(x, 0, x.Length);
+ ms.WriteByte(0);
+ }
+ else
+ throw new Exception(string.Format("The type {0} is not supported for primary keys", type.ToString()));
+ }
+
+ return Convert.ToBase64String(ms.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Parses a base64 encoded string with key values
+ /// </summary>
+ /// <param name="id">The base64 encoded ID string</param>
+ /// <returns>The composite value key</returns>
+ public object[] ParseIDString(string id)
+ {
+ int index = 0;
+ byte[] data = Convert.FromBase64String(id);
+ object[] tmp = new object[m_layer.IDs.Count];
+ for (int i = 0; i < m_layer.IDs.Count; i++)
+ {
+ Type type = m_layer.IDs[i].Value;
+
+ if (type == typeof(short))
+ {
+ tmp[i] = BitConverter.ToInt16(data, index);
+ index += BinarySerializer.MgBinarySerializer.UInt16Len;
+ }
+ else if (type == typeof(int))
+ {
+ tmp[i] = BitConverter.ToInt32(data, index);
+ index += BinarySerializer.MgBinarySerializer.UInt32Len;
+ }
+ else if (type == typeof(long))
+ {
+ tmp[i] = BitConverter.ToInt64(data, index);
+ index += BinarySerializer.MgBinarySerializer.UInt64Len;
+ }
+ else if (type == typeof(string))
+ {
+ int pos = index;
+ while (pos < data.Length && data[pos] != 0)
+ pos++;
+
+ if (pos >= data.Length)
+ throw new Exception("Bad null encoded string");
+
+ tmp[i] = System.Text.Encoding.UTF8.GetString(data, index, pos - index);
+ index = pos + 1;
+ }
+ else
+ throw new Exception(string.Format("The type {0} is not supported for primary keys", type.ToString()));
+ }
+
+ return tmp;
+ }
+
+ /// <summary>
+ /// Constructs a new LayerSelection with a number of selected featured
+ /// </summary>
+ /// <param name="layer">The layer to represent</param>
+ /// <param name="ids">The list of composite IDs that the layer supports</param>
+ public LayerSelection(RuntimeClasses.RuntimeMapLayer layer, IEnumerable<object[]> ids)
+ : this(layer)
+ {
+ AddRange(ids);
+ }
+
+ /// <summary>
+ /// Constructs a new LayerSelection with a number of selected featured
+ /// </summary>
+ /// <param name="layer">The layer to represent</param>
+ public LayerSelection(RuntimeClasses.RuntimeMapLayer layer)
+ {
+ if (layer == null)
+ throw new ArgumentNullException("layer");
+
+ if (layer.IDs == null || layer.IDs.Count == 0)
+ throw new Exception("The layer does not have a primary key, and cannot be used for selection");
+
+ m_layer = layer;
+ }
+
+ /// <summary>
+ /// Adds a composite key to the selection
+ /// </summary>
+ /// <param name="values">The composite key</param>
+ public void Add(object[] values)
+ {
+ object[] tmp = NormalizeAndValidate(values);
+
+ if (!this.Contains(tmp))
+ m_list.Add(tmp);
+ }
+
+ /// <summary>
+ /// Ensures that the composite key types match the layers ID column types.
+ /// The returned array is a copy of the one passed in
+ /// </summary>
+ /// <param name="values">The composite key</param>
+ /// <returns>A copy of the composite key</returns>
+ private object[] NormalizeAndValidate(object[] values)
+ {
+ if (values == null)
+ throw new ArgumentNullException("values");
+
+ if (values.Length != m_layer.IDs.Count)
+ throw new Exception(string.Format("The layers key consists of {0} columns, but only {1} columns were given", m_layer.IDs.Count, values.Length));
+
+ object[] tmp = new object[values.Length];
+
+ for (int i = 0; i < values.Length; i++)
+ {
+ if (values[i] == null)
+ throw new Exception(string.Format("The value for {0} is null, which is not supported as a key", m_layer.IDs[i].Key));
+ if (values[i].GetType() != m_layer.IDs[i].Value)
+ try { tmp[i] = Convert.ChangeType(values[i], m_layer.IDs[i].Value); }
+ catch (Exception ex) { throw new Exception(string.Format("Failed to convert value for {0} from {1} to {2}", m_layer.IDs[i].Key, values[i].GetType(), m_layer.IDs[i].Value), ex); }
+ else
+ tmp[i] = values[i];
+ }
+
+ return tmp;
+ }
+
+ /// <summary>
+ /// Adds a number of composite keys
+ /// </summary>
+ /// <param name="lst">A list of composite keys</param>
+ public void AddRange(IEnumerable<object[]> lst)
+ {
+ foreach (object[] x in lst)
+ Add(x);
+ }
+
+ #region IList<object[]> Members
+
+ /// <summary>
+ /// Returns the index of the given composite key
+ /// </summary>
+ /// <param name="item">The composite key to look for</param>
+ /// <returns>The index of the composite key or -1 if the key is not found</returns>
+ public int IndexOf(object[] item)
+ {
+ object[] tmp = NormalizeAndValidate(item);
+
+ for (int i = 0; i < m_list.Count; i++)
+ {
+ object[] tmpx = m_list[i];
+
+ bool matches = true;
+ for (int j = 0; j < tmpx.Length; j++)
+ if (tmpx[j] != item[j])
+ {
+ matches = false;
+ break;
+ }
+
+ if (matches)
+ return i;
+ }
+
+ return -1;
+ }
+
+ /// <summary>
+ /// Inserts a key at the specified location
+ /// </summary>
+ /// <param name="index">The index to insert the key at</param>
+ /// <param name="item">The key to insert</param>
+ public void Insert(int index, object[] item)
+ {
+ object[] tmp = NormalizeAndValidate(item);
+
+ int ix = IndexOf(tmp);
+
+ if (ix >= 0)
+ RemoveAt(ix);
+
+ Insert(index, item);
+ }
+
+ /// <summary>
+ /// Removes the element at the specified location
+ /// </summary>
+ /// <param name="index">The index of the item to remove</param>
+ public void RemoveAt(int index)
+ {
+ m_list.RemoveAt(index);
+ }
+
+ /// <summary>
+ /// Gets or sets the composite key for the specified index
+ /// </summary>
+ /// <param name="index">The index for the composite key</param>
+ /// <returns>The composite key</returns>
+ public object[] this[int index]
+ {
+ get
+ {
+ object[] tmp = new object[m_layer.IDs.Count];
+ Array.Copy(m_list[index], tmp, tmp.Length);
+ return tmp;
+ }
+ set
+ {
+ m_list[index] = NormalizeAndValidate(value);
+ }
+ }
+
+ #endregion
+
+ #region ICollection<object[]> Members
+
+ /// <summary>
+ /// Removes all composite keys from the collection
+ /// </summary>
+ public void Clear()
+ {
+ m_list.Clear();
+ }
+
+ /// <summary>
+ /// Returns a value indicating if the composite key is contained in the collection
+ /// </summary>
+ /// <param name="item">The composite key to look for</param>
+ /// <returns>True if the collection contains the composite key, false otherwise</returns>
+ public bool Contains(object[] item)
+ {
+ return IndexOf(item) >= 0;
+ }
+
+ /// <summary>
+ /// Not implemented
+ /// </summary>
+ /// <param name="array"></param>
+ /// <param name="arrayIndex"></param>
+ public void CopyTo(object[][] array, int arrayIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Returns the number of composite keys (and thus selected objects)
+ /// </summary>
+ public int Count
+ {
+ get { return m_list.Count; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating if the collection is read-only
+ /// </summary>
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ /// Removes the given composite key from the collection
+ /// </summary>
+ /// <param name="item">The composite key to remove</param>
+ /// <returns>True if the composite key was found and removed, false otherwise</returns>
+ public bool Remove(object[] item)
+ {
+ int ix = IndexOf(item);
+ if (ix < 0)
+ return false;
+
+ m_list.RemoveAt(ix);
+ return true;
+ }
+
+ #endregion
+
+ #region IEnumerable<object[]> Members
+
+ /// <summary>
+ /// Returns an enumerator for the collection
+ /// </summary>
+ /// <returns>An enumerator for the collection</returns>
+ public IEnumerator<object[]> GetEnumerator()
+ {
+ return m_list.GetEnumerator();
+ }
+
+ #endregion
+
+ #region IEnumerable Members
+
+ /// <summary>
+ /// Returns an enumerator for the collection
+ /// </summary>
+ /// <returns>An enumerator for the collection</returns>
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return ((System.Collections.IEnumerable)m_list).GetEnumerator();
+ }
+
+ #endregion
+ }
+
+
+ #region IList<LayerSelection> Members
+
+ /// <summary>
+ /// Returns the index of the given layer
+ /// </summary>
+ /// <param name="item">The layer to look for</param>
+ /// <returns>The index of the layer, or -1 if the layer is not in the collection</returns>
+ public int IndexOf(Selection.LayerSelection item)
+ {
+ return IndexOf(item.Layer);
+ }
+
+ /// <summary>
+ /// Returns the index of the given layer
+ /// </summary>
+ /// <param name="item">The layer to look for</param>
+ /// <returns>The index of the layer, or -1 if the layer is not in the collection</returns>
+ public int IndexOf(RuntimeClasses.RuntimeMapLayer layer)
+ {
+ for (int i = 0; i < m_layers.Count; i++)
+ if (m_layers[i].Layer.Guid == layer.Guid)
+ return i;
+
+ return 1;
+ }
+
+ /// <summary>
+ /// Inserts a selection layer into the collection
+ /// </summary>
+ /// <param name="index">The index to place the item at</param>
+ /// <param name="item">The item to insert</param>
+ public void Insert(int index, Selection.LayerSelection item)
+ {
+ m_layers.Insert(index, item);
+ }
+
+ /// <summary>
+ /// Inserts a selection layer into the collection
+ /// </summary>
+ /// <param name="index">The index to place the item at</param>
+ /// <param name="item">The item to insert</param>
+ public void Insert(int index, RuntimeClasses.RuntimeMapLayer layer)
+ {
+ m_layers.Insert(index, new LayerSelection(layer));
+ }
+
+ /// <summary>
+ /// Removes the item at the given index
+ /// </summary>
+ /// <param name="index">The index to remove the item at</param>
+ public void RemoveAt(int index)
+ {
+ m_layers.RemoveAt(index);
+ }
+
+ /// <summary>
+ /// Gets or sets the selection layer at a given index
+ /// </summary>
+ /// <param name="index">The index to get or set the item for</param>
+ /// <returns>The item at the given index</returns>
+ public Selection.LayerSelection this[int index]
+ {
+ get
+ {
+ return m_layers[index];
+ }
+ set
+ {
+ if (value == null)
+ throw new ArgumentNullException();
+ m_layers[index] = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the selection layer at a given index
+ /// </summary>
+ /// <param name="index">The index to get or set the item for</param>
+ /// <returns>The item at the given index</returns>
+ public Selection.LayerSelection this[RuntimeClasses.RuntimeMapLayer index]
+ {
+ get
+ {
+ return m_layers[IndexOf(index)];
+ }
+ set
+ {
+ if (value == null)
+ throw new ArgumentNullException();
+ m_layers[IndexOf(index)] = value;
+ }
+ }
+
+ #endregion
+
+ #region ICollection<LayerSelection> Members
+
+ public void Add(Selection.LayerSelection item)
+ {
+ if (item == null)
+ throw new ArgumentNullException();
+
+ m_layers.Add(item);
+ }
+
+ public void Add(RuntimeClasses.RuntimeMapLayer layer)
+ {
+ if (!Contains(layer))
+ Add(new LayerSelection(layer));
+ }
+
+ public void Clear()
+ {
+ m_layers.Clear();
+ }
+
+ public bool Contains(RuntimeClasses.RuntimeMapLayer item)
+ {
+ return IndexOf(item) >= 0;
+ }
+
+ public bool Contains(Selection.LayerSelection item)
+ {
+ return IndexOf(item) >= 0;
+ }
+
+ public void CopyTo(Selection.LayerSelection[] array, int arrayIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int Count
+ {
+ get { return m_layers.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return false; }
+ }
+
+ public bool Remove(Selection.LayerSelection item)
+ {
+ int ix = IndexOf(item);
+ if (ix < 0)
+ return false;
+
+ m_layers.RemoveAt(ix);
+ return true;
+ }
+
+ #endregion
+
+ #region IEnumerable<LayerSelection> Members
+
+ public IEnumerator<Selection.LayerSelection> GetEnumerator()
+ {
+ return m_layers.GetEnumerator();
+ }
+
+ #endregion
+
+ #region IEnumerable Members
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ return ((System.Collections.IEnumerable)m_layers).GetEnumerator();
+ }
+
+ #endregion
+ }
+}
More information about the mapguide-commits
mailing list