public override void ReadSlnData (DataItem item)
		{
			// Remove the default configuration, since new ones will be loaded
			CompiledAssemblyProject project = (CompiledAssemblyProject) EntityItem;
			project.Configurations.Clear ();
			
			DataSerializer ser = new DataSerializer (MSBuildProjectService.DataContext);
			ser.SerializationContext.BaseFile = EntityItem.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';
			ser.Deserialize (project, item);
		}
Beispiel #2
0
 public void Deserialize(ITypeSerializer handler, DataCollection data)
 {
     handler.Deserialize((object)this, data);
     foreach (DataNode dataNode in data)
     {
         MonoDevelop.Core.Serialization.DataItem dataItem = dataNode as MonoDevelop.Core.Serialization.DataItem;
         if (dataItem != null)
         {
             this.Frames.Add(handler.SerializationContext.Serializer.DataContext.GetConfigurationDataType(dataNode.Name).Deserialize(handler.SerializationContext, (object)null, (DataNode)dataItem) as FrameData);
         }
     }
     this.ExtendedProperties.Clear();
 }
Beispiel #3
0
 public void Deserialize(ITypeSerializer handler, DataCollection data)
 {
     handler.Deserialize(this, data);
     foreach (DataNode dataNode in data)
     {
         MonoDevelop.Core.Serialization.DataItem dataItem = dataNode as MonoDevelop.Core.Serialization.DataItem;
         if (dataItem != null)
         {
             DataType  configurationDataType = handler.SerializationContext.Serializer.DataContext.GetConfigurationDataType(dataNode.Name);
             FrameData item = configurationDataType.Deserialize(handler.SerializationContext, null, dataItem) as FrameData;
             this.Frames.Add(item);
         }
     }
     base.ExtendedProperties.Clear();
 }
Beispiel #4
0
		internal void UpdateFromItem (DataItem item, HashSet<DataItem> removedItems)
		{
			var counter = new Dictionary<string, int> ();
			foreach (var d in item.ItemData) {
				DataNode current = null;
				DataCollection col;
				if (!counter.ContainsKey (d.Name))
					counter [d.Name] = 0;
				var index = ItemData.FindData (d.Name, out col, false, counter[d.Name]);
				counter [d.Name]++;
				if (index != -1) {
					current = col [index];
				}
				if (current != null) {
					if (d.IsDefaultValue || d is DataDeletedNode) {
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
						ItemData.Remove (current);
					} else if (current.GetType () != d.GetType () || current is DataValue) {
						var i = ItemData.IndexOf (current);
						ItemData [i] = d;
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
					} else if (current is DataItem) {
						((DataItem)current).UpdateFromItem ((DataItem)d, removedItems);
					}
				} else if (!d.IsDefaultValue && !(d is DataDeletedNode)) {
					var dataItem = d as DataItem;
					if (dataItem != null) {
						var newDataItem = new DataItem () {
							Name = d.Name,
							UniqueNames = dataItem.UniqueNames
						};
						newDataItem.UpdateFromItem (dataItem, removedItems);
						ItemData.Add (newDataItem);
					} else {
						ItemData.Add (d);
					}
				}
			}
		}
		internal void UpdateFromItem (DataItem item, HashSet<DataItem> removedItems)
		{
			foreach (var d in item.ItemData) {
				var current = ItemData[d.Name];
				if (current != null) {
					if (d.IsDefaultValue || d is DataDeletedNode) {
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
						ItemData.Remove (current);
					}
					else if (current.GetType () != d.GetType () || current is DataValue) {
						var i = ItemData.IndexOf (current);
						ItemData [i] = d;
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
					} else if (current is DataItem) {
						((DataItem)current).UpdateFromItem ((DataItem)d, removedItems);
					}
				} else if (!d.IsDefaultValue && !(d is DataDeletedNode)) {
					ItemData.Add (d);
				}
			}
		}
Beispiel #6
0
		void WriteDataItem (StreamWriter sw, DataItem item)
		{
			int id = 0;
			foreach (DataNode val in item.ItemData)
				WriteDataNode (sw, "", val, ref id);
		}
		protected virtual DataNode ReadChild (XmlElement elem, DataItem parent)
		{
			return GetChildReader (parent).Read (elem);
		}
		protected virtual XmlConfigurationReader GetChildReader (DataItem parent)
		{
			return this;
		}
Beispiel #9
0
 public void Deserialize(object obj, DataItem data)
 {
     dataContext.SetConfigurationItemData(serializationContext, obj, data);
 }
		public DataNode Read (XmlReader reader)
		{
			DataItem item = new DataItem (); 
			item.UniqueNames = false;
			reader.MoveToContent ();
			string name = reader.LocalName;
			item.Name = name;
			
			while (reader.MoveToNextAttribute ()) {
				if (reader.LocalName == "xmlns")
					continue;
				DataNode data = ReadAttribute (reader.LocalName, reader.Value);
				if (data != null) {
					DataValue val = data as DataValue;
					if (val != null)
						val.StoreAsAttribute = true;
					item.ItemData.Add (data);
				}
			}
			
			reader.MoveToElement ();
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return item;
			}
			
			reader.ReadStartElement ();
			reader.MoveToContent ();
			
			string text = "";
			while (reader.NodeType != XmlNodeType.EndElement) {
				if (reader.NodeType == XmlNodeType.Element) {
					DataNode data = ReadChild (reader, item);
					if (data != null) item.ItemData.Add (data);
				} else if (reader.NodeType == XmlNodeType.Text) {
					text += reader.Value;
					reader.Skip ();
				} else {
					reader.Skip ();
				}
			}
			
			reader.ReadEndElement ();
			
			if (!item.HasItemData && text != "")
				return new DataValue (name, text); 

			return item;
		}
		public void SetConfigurationItemData (SerializationContext serCtx, object obj, DataItem data)
		{
			ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ());
			dataType.Deserialize (serCtx, null, data, obj);
		}
Beispiel #12
0
 protected virtual DataNode ReadChild(XmlReader reader, DataItem parent)
 {
     return(GetChildReader(parent).Read(reader));
 }
Beispiel #13
0
        public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem data)
        {
            ClassDataType dataType = (ClassDataType)GetConfigurationDataType(obj.GetType());

            dataType.Deserialize(serCtx, null, data, obj);
        }
Beispiel #14
0
		public void Deserialize (object obj, DataItem data)
		{
			dataContext.SetConfigurationItemData (serializationContext, obj, data);
		}
        void Deserialize(SerializationContext serCtx, object obj, DataCollection itemData, DataItem ukwnDataRoot, string baseName)
        {
            Hashtable expandedCollections = null;

            foreach (DataNode value in itemData)
            {
                ItemProperty prop = (ItemProperty)properties [baseName + value.Name];
                if (prop == null)
                {
                    if (value is DataItem)
                    {
                        DataItem root = new DataItem();
                        root.Name        = value.Name;
                        root.UniqueNames = ((DataItem)value).UniqueNames;
                        if (ukwnDataRoot != null)
                        {
                            ukwnDataRoot.ItemData.Add(root);
                        }
                        Deserialize(serCtx, obj, ((DataItem)value).ItemData, root, baseName + value.Name + "/");

                        // If no unknown data has been added, there is no need to keep this
                        // in the unknown items list.
                        if (ukwnDataRoot != null && !root.HasItemData)
                        {
                            ukwnDataRoot.ItemData.Remove(root);
                        }
                    }
                    else if (obj is IExtendedDataItem && (value.Name != "ctype" || baseName.Length > 0))
                    {
                        // store unreadable raw data to a special property so it can be
                        // serialized back an the original format is kept
                        // The ctype attribute don't need to be stored for the root object, since
                        // it is generated by the serializer
                        ukwnDataRoot.ItemData.Add(value);
                    }
                    continue;
                }
                if (prop.WriteOnly || !prop.CanDeserialize(serCtx, obj))
                {
                    continue;
                }

                try {
                    if (prop.ExpandedCollection)
                    {
                        ICollectionHandler handler = prop.ExpandedCollectionHandler;
                        if (expandedCollections == null)
                        {
                            expandedCollections = new Hashtable();
                        }

                        object pos, col;
                        if (!expandedCollections.ContainsKey(prop))
                        {
                            col = handler.CreateCollection(out pos, -1);
                        }
                        else
                        {
                            pos = expandedCollections [prop];
                            col = prop.GetValue(obj);
                        }
                        handler.AddItem(ref col, ref pos, prop.Deserialize(serCtx, obj, value));
                        expandedCollections [prop] = pos;
                        prop.SetValue(obj, col);
                    }
                    else
                    {
                        if (prop.HasSetter && prop.DataType.CanCreateInstance)
                        {
                            prop.SetValue(obj, prop.Deserialize(serCtx, obj, value));
                        }
                        else if (prop.DataType.CanReuseInstance)
                        {
                            object pval = prop.GetValue(obj);
                            if (pval == null)
                            {
                                if (prop.HasSetter)
                                {
                                    throw new InvalidOperationException("The property '" + prop.Name + "' is null and a new instance of '" + prop.PropertyType + "' can't be created.");
                                }
                                else
                                {
                                    throw new InvalidOperationException("The property '" + prop.Name + "' is null and it does not have a setter.");
                                }
                            }
                            prop.Deserialize(serCtx, obj, value, pval);
                        }
                        else
                        {
                            throw new InvalidOperationException("The property does not have a setter.");
                        }
                    }
                }
                catch (Exception ex) {
                    throw new InvalidOperationException("Could not set property '" + prop.Name + "' in type '" + Name + "'", ex);
                }
            }
        }
Beispiel #16
0
 protected virtual XmlConfigurationReader GetChildReader(DataItem parent)
 {
     return(this);
 }
        internal protected override object OnDeserialize(SerializationContext serCtx, object mapData, DataNode data)
        {
            DataItem item = data as DataItem;

            if (item == null)
            {
                throw new InvalidOperationException("Invalid value found for type '" + Name + "' " + data);
            }

            DataValue ctype = item ["ctype"] as DataValue;

            if (ctype != null && ctype.Value != Name)
            {
                bool     isFallbackType;
                DataType stype = FindDerivedType(ctype.Value, mapData, out isFallbackType);

                if (isFallbackType)
                {
                    // Remove the ctype attribute, to make sure it is not checked again
                    // by the fallback type
                    item.ItemData.Remove(ctype);
                }

                if (stype != null)
                {
                    DataNode desData = data;
                    if (stype.IsSimpleType)
                    {
                        desData = item.ItemData ["Value"];
                        if (desData == null)
                        {
                            throw new InvalidOperationException("Value node not found");
                        }
                    }
                    object sobj = stype.Deserialize(serCtx, mapData, desData);

                    // Store the original data type, so it can be serialized back
                    if (isFallbackType && sobj is IExtendedDataItem)
                    {
                        ((IExtendedDataItem)sobj).ExtendedProperties ["__raw_ctype"] = ctype.Value;
                    }

                    return(sobj);
                }
                else
                {
                    throw new InvalidOperationException("Type not found: " + ctype.Value);
                }
            }

            ConstructorInfo ctor = ValueType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);

            if (ctor == null)
            {
                throw new InvalidOperationException("Default constructor not found for type '" + ValueType + "'");
            }

            object obj = ctor.Invoke(null);

            Deserialize(serCtx, null, item, obj);
            return(obj);
        }
        internal DataCollection Serialize(SerializationContext serCtx, object obj)
        {
            DataCollection itemCol = new DataCollection();

            foreach (ItemProperty prop in Properties)
            {
                if (prop.ReadOnly || !prop.CanSerialize(serCtx, obj))
                {
                    continue;
                }
                object val = prop.GetValue(obj);
                if (val == null)
                {
                    continue;
                }
                if (!serCtx.IsDefaultValueSerializationForced(prop) && val.Equals(prop.DefaultValue))
                {
                    continue;
                }

                DataCollection col = itemCol;
                if (prop.IsNested)
                {
                    col = GetNestedCollection(col, prop.NameList, 0);
                }

                if (prop.ExpandedCollection)
                {
                    ICollectionHandler handler = prop.ExpandedCollectionHandler;
                    object             pos     = handler.GetInitialPosition(val);
                    while (handler.MoveNextItem(val, ref pos))
                    {
                        object item = handler.GetCurrentItem(val, pos);
                        if (item == null)
                        {
                            continue;
                        }
                        DataNode data = prop.Serialize(serCtx, obj, item);
                        data.Name = prop.SingleName;
                        col.Add(data);
                    }
                }
                else
                {
                    DataNode data = prop.Serialize(serCtx, obj, val);
                    if (data == null)
                    {
                        continue;
                    }
                    col.Add(data);
                }
            }

            if (obj is IExtendedDataItem)
            {
                // Serialize raw data which could not be deserialized
                DataItem uknData = (DataItem)((IExtendedDataItem)obj).ExtendedProperties ["__raw_data"];
                if (uknData != null)
                {
                    itemCol.Merge(uknData.ItemData);
                }
            }

            return(itemCol);
        }
Beispiel #19
0
 public object CreateInstance(Type type, DataItem data)
 {
     return(dataContext.CreateConfigurationData(serializationContext, type, data));
 }
Beispiel #20
0
		bool ReadDataNode (DataItem item, List<string> lines, int lastLine, string prefix, ref int lineNum)
		{
			string s = lines [lineNum].Trim (' ','\t');
			
			if (s.Length == 0) {
				lineNum++;
				return true;
			}
			
			// Check if the line belongs to the current item
			if (prefix.Length > 0) {
				if (!s.StartsWith (prefix + "."))
					return false;
				s = s.Substring (prefix.Length + 1);
			} else {
				if (s.StartsWith ("$"))
					return false;
			}
			
			int i = s.IndexOf ('=');
			if (i == -1) {
				lineNum++;
				return true;
			}

			string name = s.Substring (0, i).Trim (' ','\t');
			if (name.Length == 0) {
				lineNum++;
				return true;
			}
			
			string value = s.Substring (i+1).Trim (' ','\t');
			if (value.StartsWith ("$")) {
				// New item
				DataItem child = new DataItem ();
				child.Name = name;
				lineNum++;
				while (lineNum <= lastLine) {
					if (!ReadDataNode (child, lines, lastLine, value, ref lineNum))
						break;
				}
				item.ItemData.Add (child);
			}
			else {
				value = DecodeString (value);
				DataValue val = new DataValue (name, value);
				item.ItemData.Add (val);
				lineNum++;
			}
			return true;
		}
		void ReadItems (ITypeSerializer handler, SolutionEntityItem item, DataItem items)
		{
			foreach (DataNode node in items.ItemData) {
				DataType dtype = handler.SerializationContext.Serializer.DataContext.GetConfigurationDataType (node.Name);
				if (dtype != null && typeof(ProjectItem).IsAssignableFrom (dtype.ValueType)) {
					ProjectItem it = (ProjectItem) handler.SerializationContext.Serializer.Deserialize (dtype.ValueType, node);
					item.Items.Add (it);
				}
			}
		}
Beispiel #22
0
 protected virtual DataNode ReadChild(XmlElement elem, DataItem parent)
 {
     return(GetChildReader(parent).Read(elem));
 }
		internal protected override DataNode OnSerialize (SerializationContext serCtx, object mdata, object collection)
		{
			MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData ();
			DataItem colItem = new DataItem ();
			colItem.Name = Name;
			colItem.UniqueNames = false;
			IDictionary dict = (IDictionary) collection;
			
			foreach (DictionaryEntry e in dict) {
				DataItem item = new DataItem ();
				item.Name = mapData.ItemName;
				item.UniqueNames = true;
				
				DataNode key = mapData.KeyType.Serialize (serCtx, null, e.Key);
				key.Name = mapData.KeyName;
				DataNode value = mapData.ValueType.Serialize (serCtx, null, e.Value);
				value.Name = mapData.ValueName;
				item.ItemData.Add (key);
				item.ItemData.Add (value);
				
				colItem.ItemData.Add (item);
			}
			return colItem;
		}
		public void SetTypeInfo (DataItem item, Type type)
		{
			item.ItemData.Add (new DataValue ("ctype", GetConfigurationDataType (type).Name));
		}
		protected virtual void WriteAttributes (XmlWriter writer, DataItem item)
		{
			foreach (DataNode data in item.ItemData) {
				DataValue val = data as DataValue;
				if (val != null && (item.UniqueNames || val.StoreAsAttribute) && StoreAsAttribute (val))
					WriteAttribute (writer, val.Name, val.Value);
			}
		}
Beispiel #26
0
 public void SetTypeInfo(DataItem item, Type type)
 {
     item.ItemData.Add(new DataValue("ctype", GetConfigurationDataType(type).Name));
 }
Beispiel #27
0
        internal int FindData(string name, out DataCollection colec, bool buildTree, int skipCount)
        {
            if (name.IndexOf('/') == -1)
            {
                for (int n = 0; n < Items.Count; n++)
                {
                    DataNode data = Items [n];
                    if (data.Name == name)
                    {
                        if (skipCount > 0)
                        {
                            skipCount--;
                            continue;
                        }
                        colec = this;
                        return(n);
                    }
                }
                colec = this;
                return(-1);
            }
            else
            {
                string[] names = name.Split('/');
                int      pos   = -1;
                colec = this;
                DataNode data = null;

                for (int p = 0; p < names.Length; p++)
                {
                    if (p > 0)
                    {
                        DataItem item = data as DataItem;
                        if (item != null)
                        {
                            colec = item.ItemData;
                        }
                        else if (buildTree)
                        {
                            item      = new DataItem();
                            item.Name = names [p - 1];
                            colec.Add(item);
                            colec = item.ItemData;
                        }
                        else
                        {
                            colec = null;
                            return(-1);
                        }
                    }

                    pos = -1;
                    for (int n = 0; n < colec.Count; n++)
                    {
                        data = colec [n];
                        if (data.Name == names [p])
                        {
                            pos = n; break;
                        }
                    }
                }
                return(pos);
            }
        }
Beispiel #28
0
		public object CreateInstance (Type type, DataItem data)
		{
			return dataContext.CreateConfigurationData (serializationContext, type, data);
		}
 protected override XmlConfigurationReader GetChildReader(MonoDevelop.Core.Serialization.DataItem parent)
 {
     // Don't reuse this serializer for children, since it has solution-specific serialization code
     return(XmlConfigurationReader.DefaultReader);
 }
		void WriteItems (ITypeSerializer handler, SolutionEntityItem item, DataCollection data)
		{
			DataItem items = new DataItem ();
			items.Name = "Items";
			foreach (object it in item.Items) {
				if (it is ProjectFile || it is ProjectReference)
					continue; // Already handled by serializer
				DataNode node = handler.SerializationContext.Serializer.Serialize (it, it.GetType ());
				items.ItemData.Add (node);
			}
			if (items.HasItemData)
				data.Add (items);
		}
		static void WriteDataItem (SlnSection pset, DataItem item)
		{
			HashSet<DataItem> removedItems = new HashSet<DataItem> ();
			Dictionary<DataNode,int> ids = new Dictionary<DataNode, int> ();

			// First of all read the existing data item, since we want to keep data that has not been modified
			// The ids collection is filled with a map of items and their ids
			var currentItem = ReadDataItem (pset, ids);

			// UpdateFromItem will add new data to the item, it will remove the data that has been removed, and
			// will ignore unknown data that has not been set or removed
			currentItem.UpdateFromItem (item, removedItems);

			// List of IDs that are not used anymore and can be reused when writing the item
			var unusedIds = new Queue<int> (removedItems.Select (it => ids[it]).OrderBy (i => i));

			// Calculate the next free id, to be used when adding new items
			var usedIds = ids.Where (p => !removedItems.Contains (p.Key)).Select (p => p.Value).ToArray ();
			int nextId = usedIds.Length > 0 ? usedIds.Max () + 1 : 0;

			var newSet = new List<KeyValuePair<string, string>> ();

			foreach (DataNode val in currentItem.ItemData)
				WriteDataNode (newSet, "", val, ids, unusedIds, ref nextId);
			
			pset.SetContent (newSet);
		}
		protected virtual void WriteAttributes (XmlElement elem, DataItem item)
		{
			if (StoreAllInElements)
				return;
			foreach (DataNode data in item.ItemData) {
				DataValue val = data as DataValue;
				if (val != null && (item.UniqueNames || val.StoreAsAttribute))
					WriteAttribute (elem, val.Name, val.Value);
			}
		}
		static DataItem ReadDataItem (SlnSection pset, Dictionary<DataNode,int> ids)
		{
			DataItem it = new DataItem ();

			var lines = pset.GetContent ().ToArray ();

			int lineNum = 0;
			int lastLine = lines.Length - 1;
			while (lineNum <= lastLine) {
				if (!ReadDataNode (it, lines, lastLine, "", ids, ref lineNum))
					lineNum++;
			}
			return it;
		}
		protected virtual void WriteChildren (XmlElement elem, DataItem item)
		{
			if (item.UniqueNames) {
				foreach (DataNode data in item.ItemData) {
					if (!(data is DataValue) || !StoreAsAttribute ((DataValue)data))
						WriteChild (elem, data);
				}
			} else {
				foreach (DataNode data in item.ItemData) {
					DataValue dval = data as DataValue;
					if (dval == null || !dval.StoreAsAttribute || !StoreAsAttribute (dval))
						WriteChild (elem, data);
				}
			}
		}
		static bool ReadDataNode (DataItem item, KeyValuePair<string,string>[] lines, int lastLine, string prefix, Dictionary<DataNode,int> ids, ref int lineNum)
		{
			var s = lines [lineNum];

			string name = s.Key;
			if (name.Length == 0) {
				lineNum++;
				return true;
			}

			// Check if the line belongs to the current item
			if (prefix.Length > 0) {
				if (!s.Key.StartsWith (prefix + ".", StringComparison.Ordinal))
					return false;
				name = s.Key.Substring (prefix.Length + 1);
			} else {
				if (s.Key.StartsWith ("$", StringComparison.Ordinal))
					return false;
			}

			string value = s.Value;
			if (value.StartsWith ("$", StringComparison.Ordinal)) {
				// New item
				DataItem child = new DataItem ();
				child.Name = name;
				int id;
				if (ids != null && int.TryParse (value.Substring (1), out id))
					ids [child] = id;
				lineNum++;
				while (lineNum <= lastLine) {
					if (!ReadDataNode (child, lines, lastLine, value, ids, ref lineNum))
						break;
				}
				item.ItemData.Add (child);
			} else {
				value = DecodeString (value);
				DataValue val = new DataValue (name, value);
				item.ItemData.Add (val);
				lineNum++;
			}
			return true;
		}
		public DataNode Read (XmlElement elem)
		{
			DataItem item = new DataItem (); 
			item.UniqueNames = false;

			item.Name = elem.LocalName;
			
			foreach (XmlAttribute att in elem.Attributes) {
				if (att.LocalName == "xmlns")
					continue;
				DataNode data = ReadAttribute (att.LocalName, att.Value);
				if (data != null) {
					DataValue val = data as DataValue;
					if (val != null)
						val.StoreAsAttribute = true;
					item.ItemData.Add (data);
				}
			}

			string text = "";
			
			foreach (XmlNode node in elem.ChildNodes) {
				if (node.NodeType == XmlNodeType.Element) {
					DataNode data = ReadChild ((XmlElement)node, item);
					if (data != null) item.ItemData.Add (data);
				} else if (node.NodeType == XmlNodeType.Text) {
					text += ((XmlText)node).Value;
				}
			}
			
			if (!item.HasItemData && text != "")
				return new DataValue (item.Name, text); 

			return item;
		}
		DataCollection GetNestedCollection (DataCollection col, string[] nameList, int pos, bool isDefault)
		{
			if (pos == nameList.Length - 1) return col;

			DataItem item = col [nameList[pos]] as DataItem;
			if (item == null) {
				item = new DataItem ();
				item.Name = nameList[pos];
				col.Add (item);
				item.IsDefaultValue = isDefault;
			}
			if (item.IsDefaultValue && !isDefault)
				item.IsDefaultValue = false;
			return GetNestedCollection (item.ItemData, nameList, pos + 1, isDefault);
		}
		protected virtual DataNode ReadChild (XmlReader reader, DataItem parent)
		{
			return GetChildReader (parent).Read (reader);
		}
		internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object obj)
		{
			string ctype = null;
			
			if (obj.GetType () != ValueType) {
				if (obj is IExtendedDataItem) {
					// This is set by fallback types, to make sure the original type name is serialized back
					ctype = (string) ((IExtendedDataItem)obj).ExtendedProperties ["__raw_ctype"];
				}
				if (ctype == null) {
					DataType subtype = Context.GetConfigurationDataType (obj.GetType ());
					DataNode n = subtype.Serialize (serCtx, mapData, obj);
					DataItem it = n as DataItem;
					if (it == null) {
						it = new DataItem ();
						n.Name = "Value";
						it.ItemData.Add (n);
					}
					it.ItemData.Add (new DataValue ("ctype", subtype.Name));
					it.Name = Name;
					return it;
				}
			} 
			
			DataItem item = new DataItem ();
			item.Name = Name;
			
			ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem (obj);
			if (citem != null) {
				ClassTypeHandler handler = new ClassTypeHandler (serCtx, this);
				item.ItemData = citem.Serialize (handler);
			}
			else
				item.ItemData = Serialize (serCtx, obj);
				
			if (ctype != null)
				item.ItemData.Add (new DataValue ("ctype", ctype));

			return item;
		}
		public void Deserialize (ITypeSerializer handler, DataCollection data)
		{
			DataItem item = new DataItem ();
			item.Name = "SolutionConfiguration";
			DataCollection col = item.ItemData;
			
			foreach (DataNode val in data) {
				if (val.Name != "name" && val.Name != "ctype" && val.Name != "Entry")
					col.Add (val);
			}
			
			handler.Deserialize (this, data);
			
			if (data.Count > 0) {
				solutionConfiguration = new SolutionConfiguration (name);
				handler.SerializationContext.Serializer.Deserialize (solutionConfiguration, item);
			}
		}
		DataCollection GetNestedCollection (DataCollection col, string[] nameList, int pos)
		{
			if (pos == nameList.Length - 1) return col;

			DataItem item = col [nameList[pos]] as DataItem;
			if (item == null) {
				item = new DataItem ();
				item.Name = nameList[pos];
				col.Add (item);
			}
			return GetNestedCollection (item.ItemData, nameList, pos + 1);
		}
Beispiel #42
0
		DataItem ReadDataItem (int start, int count, List<string> lines)
		{
			DataItem it = new DataItem ();
			int lineNum = start + 1;
			int lastLine = start + count - 2;
			while (lineNum <= lastLine) {
				if (!ReadDataNode (it, lines, lastLine, "", ref lineNum))
					lineNum++;
			}
			return it;
		}
		void Deserialize (SerializationContext serCtx, object obj, DataCollection itemData, DataItem ukwnDataRoot, string baseName)
		{
			Hashtable expandedCollections = null;
			
			foreach (DataNode value in itemData) {
				ItemProperty prop = (ItemProperty) properties [baseName + value.Name];
				if (prop == null) {
					if (value is DataItem) {
						DataItem root = new DataItem ();
						root.Name = value.Name;
						root.UniqueNames = ((DataItem)value).UniqueNames;
						if (ukwnDataRoot != null)
							ukwnDataRoot.ItemData.Add (root);
						Deserialize (serCtx, obj, ((DataItem)value).ItemData, root, baseName + value.Name + "/");

						// If no unknown data has been added, there is no need to keep this
						// in the unknown items list.
						if (ukwnDataRoot != null && !root.HasItemData)
							ukwnDataRoot.ItemData.Remove (root);
					}
					else if (obj is IExtendedDataItem && (value.Name != "ctype" || baseName.Length > 0)) {
						// store unreadable raw data to a special property so it can be 
						// serialized back an the original format is kept
						// The ctype attribute don't need to be stored for the root object, since
						// it is generated by the serializer
						ukwnDataRoot.ItemData.Add (value);
					}
					continue;
				}
				if (prop.WriteOnly || !prop.CanDeserialize (serCtx, obj))
					continue;
				
				try {
					if (prop.ExpandedCollection) {
						ICollectionHandler handler = prop.ExpandedCollectionHandler;
						if (expandedCollections == null) expandedCollections = new Hashtable ();
						
						object pos, col;
						if (!expandedCollections.ContainsKey (prop)) {
							col = handler.CreateCollection (out pos, -1);
						} else {
							pos = expandedCollections [prop];
							col = prop.GetValue (obj);
						}
						handler.AddItem (ref col, ref pos, prop.Deserialize (serCtx, obj, value));
						expandedCollections [prop] = pos;
						prop.SetValue (obj, col);
					}
					else {
						if (prop.HasSetter && prop.DataType.CanCreateInstance)
							prop.SetValue (obj, prop.Deserialize (serCtx, obj, value));
						else if (prop.DataType.CanReuseInstance) {
							object pval = prop.GetValue (obj);
							if (pval == null) {
								if (prop.HasSetter)
									throw new InvalidOperationException ("The property '" + prop.Name + "' is null and a new instance of '" + prop.PropertyType + "' can't be created.");
								else
									throw new InvalidOperationException ("The property '" + prop.Name + "' is null and it does not have a setter.");
							}
							prop.Deserialize (serCtx, obj, value, pval);
						} else {
							throw new InvalidOperationException ("The property does not have a setter.");
						}
					}
				}
				catch (Exception ex) {
					throw new InvalidOperationException ("Could not set property '" + prop.Name + "' in type '" + Name + "'", ex);
				}
			}
		}
Beispiel #44
0
		public virtual void ReadSlnData (DataItem item)
		{
			customSlnData = item;
		}
Beispiel #45
0
        public DataNode Read(XmlReader reader)
        {
            DataItem item = new DataItem();

            item.UniqueNames = false;
            reader.MoveToContent();
            string name = reader.LocalName;

            item.Name = name;

            while (reader.MoveToNextAttribute())
            {
                if (reader.LocalName == "xmlns")
                {
                    continue;
                }
                DataNode data = ReadAttribute(reader.LocalName, reader.Value);
                if (data != null)
                {
                    DataValue val = data as DataValue;
                    if (val != null)
                    {
                        val.StoreAsAttribute = true;
                    }
                    item.ItemData.Add(data);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return(item);
            }

            reader.ReadStartElement();

            string text = "";

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    DataNode data = ReadChild(reader, item);
                    if (data != null)
                    {
                        item.ItemData.Add(data);
                    }
                }
                else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.Whitespace)
                {
                    text += reader.Value;
                    reader.Skip();
                }
                else
                {
                    reader.Skip();
                }
            }

            reader.ReadEndElement();

            if (!item.HasItemData && text != "")
            {
                return(new DataValue(name, text));
            }

            return(item);
        }