public DataNode Read(XmlReader reader)
        {
            DataItem item = new DataItem ();
            reader.MoveToContent ();
            string name = reader.LocalName;
            item.Name = name;

            while (reader.MoveToNextAttribute ()) {
                DataNode data = ReadAttribute (reader.LocalName, reader.Value);
                if (data != null) 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;
        }
        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);
        }
 public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem item)
 {
     ICustomDataItem citem = obj as ICustomDataItem;
     if (citem != null) {
         ClassTypeHandler handler = new ClassTypeHandler (serCtx, this);
         citem.Deserialize (handler, item.ItemData);
     }
     else
         Deserialize (serCtx, obj, item.ItemData);
 }
        public override DataNode Serialize(SerializationContext serCtx, object mapData, object obj)
        {
            if (obj.GetType () != ValueType) {
                DataType subtype = Context.GetConfigurationDataType (obj.GetType ());
                DataItem it = (DataItem) subtype.Serialize (serCtx, mapData, obj);
                it.ItemData.Add (new DataValue ("ctype", subtype.Name));
                it.Name = Name;
                return it;
            }

            DataItem item = new DataItem ();
            item.Name = Name;

            ICustomDataItem citem = obj as ICustomDataItem;
            if (citem != null) {
                ClassTypeHandler handler = new ClassTypeHandler (serCtx, this);
                item.ItemData = citem.Serialize (handler);
            }
            else
                item.ItemData = Serialize (serCtx, obj);
            return item;
        }
 public void Deserialize(object obj, DataItem data)
 {
     dataContext.SetConfigurationItemData (serializationContext, obj, data);
 }
Exemplo n.º 6
0
 public void SetTypeInfo(DataItem item, Type type)
 {
     item.ItemData.Add (new DataValue ("ctype", GetConfigurationDataType (type).Name));
 }
Exemplo n.º 7
0
 public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem data)
 {
     ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ());
     dataType.SetConfigurationItemData (serCtx, obj, data);
 }
        protected override void WriteChildren(XmlWriter writer, DataItem item)
        {
            base.WriteChildren (writer, item);

            writer.WriteStartElement ("Entries");
            foreach (CombineEntry entry in combine.Entries) {
                writer.WriteStartElement ("Entry");
                writer.WriteAttributeString ("filename", entry.RelativeFileName);
                writer.WriteEndElement ();
                Runtime.ProjectService.WriteFile (entry.FileName, entry, monitor);
            }
            writer.WriteEndElement ();
        }
        protected override DataNode ReadChild(XmlReader reader, DataItem parent)
        {
            if (reader.LocalName == "Entries") {
                if (reader.IsEmptyElement) { reader.Skip(); return null; }
                string basePath = Path.GetDirectoryName (combine.FileName);
                reader.ReadStartElement ();

                ArrayList files = new ArrayList ();
                while (MoveToNextElement (reader)) {
                    string nodefile = reader.GetAttribute ("filename");
                    nodefile = Runtime.FileUtilityService.RelativeToAbsolutePath (basePath, nodefile);
                    files.Add (nodefile);
                    reader.Skip ();
                }

                monitor.BeginTask (string.Format (GettextCatalog.GetString("Loading combine: {0}"), combine.FileName), files.Count);
                try {
                    foreach (string nodefile in files) {
                        combine.Entries.Add ((CombineEntry) Runtime.ProjectService.ReadFile (nodefile, monitor));
                        monitor.Step (1);
                    }
                } finally {
                    monitor.EndTask ();
                }

                reader.ReadEndElement ();
                return null;
            }

            return base.ReadChild (reader, parent);
        }
        protected override DataNode ReadChild(XmlReader reader, DataItem parent)
        {
            if (reader.LocalName == "Entries") {
                if (reader.IsEmptyElement) { reader.Skip(); return null; }
                string basePath = Path.GetDirectoryName (file);
                reader.ReadStartElement ();
                monitor.BeginTask (string.Format (GettextCatalog.GetString("Loading combine: {0}"), combine.FileName), 1);
                while (MoveToNextElement (reader)) {
                    string nodefile = reader.GetAttribute ("filename");
                    nodefile = Runtime.FileUtilityService.RelativeToAbsolutePath (basePath, nodefile);
                    combine.Entries.Add ((CombineEntry) Runtime.ProjectService.ReadFile (nodefile, monitor));
                    reader.Skip ();
                }
                monitor.EndTask ();
                reader.ReadEndElement ();
                return null;
            } else if (reader.LocalName == "Configurations") {
                DataItem item = base.ReadChild (reader, parent) as DataItem;
                foreach (DataNode data in item.ItemData) {
                    DataItem conf = data as DataItem;
                    if (conf == null) continue;
                    Runtime.ProjectService.DataContext.SetTypeInfo (conf, typeof(CombineConfiguration));
                }
                return item;
            }

            return base.ReadChild (reader, parent);
        }
 void Transform(DataItem conf)
 {
     for (int n=0; n<changes.Length; n+=3) {
         DataNode data = conf.ItemData.Extract (changes[n]);
         if (data != null) {
             data.Name = changes [n+2];
             conf.ItemData.Add (data, changes[n+1]);
         }
     }
 }
        protected override DataNode ReadChild(XmlReader reader, DataItem parent)
        {
            if (reader.LocalName == "Configurations")
            {
                ILanguageBinding binding = Runtime.Languages.GetBindingPerLanguageName (project.LanguageName);
                object confObj = binding.CreateCompilationParameters (null);
                Type confType = confObj.GetType ();
                DataContext prjContext = Runtime.ProjectService.DataContext;

                DataItem item = base.ReadChild (reader, parent) as DataItem;
                foreach (DataNode data in item.ItemData) {
                    DataItem conf = data as DataItem;
                    if (conf == null) continue;
                    prjContext.SetTypeInfo (conf, typeof(DotNetProjectConfiguration));
                    DataItem codeGeneration = conf ["CodeGeneration"] as DataItem;
                    if (codeGeneration != null)
                        prjContext.SetTypeInfo (codeGeneration, confType);
                    Transform (conf);
                }
                return item;
            }
            return base.ReadChild (reader, parent);
        }
 public override DataNode Serialize(SerializationContext serCtx, object mdata, object collection)
 {
     MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData ();
     DataItem item = new DataItem ();
     item.Name = Name;
     item.UniqueNames = false;
     object pos = handler.GetInitialPosition (collection);
     while (handler.MoveNextItem (collection, ref pos)) {
         object val = handler.GetCurrentItem (collection, pos);
         if (val == null) continue;
         DataNode data = mapData.ItemType.Serialize (serCtx, mapData.ItemMapData, val);
         data.Name = mapData.ItemName;
         item.ItemData.Add (data);
     }
     return item;
 }
 protected virtual void WriteChildren(XmlWriter writer, DataItem item)
 {
     if (item.UniqueNames) {
         foreach (DataNode data in item.ItemData) {
             if (!(data is DataValue))
                 WriteChild (writer, data);
         }
     } else {
         foreach (DataNode data in item.ItemData)
             WriteChild (writer, data);
     }
 }
 protected virtual void WriteAttributes(XmlWriter writer, DataItem item)
 {
     if (item.UniqueNames) {
         foreach (DataNode data in item.ItemData) {
             DataValue val = data as DataValue;
             if (val != null)
                 WriteAttribute (writer, val.Name, val.Value);
         }
     }
 }
 protected virtual DataNode ReadChild(XmlReader reader, DataItem parent)
 {
     return DefaultReader.Read (reader);
 }