public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data)
 {
     string file = ((DataValue)data).Value;
     if (file == "") return "";
     string basePath = Path.GetDirectoryName (serCtx.BaseFile);
     return Runtime.FileUtilityService.RelativeToAbsolutePath (basePath, file);
 }
 public override DataNode Serialize(SerializationContext serCtx, object mapData, object value)
 {
     if (value == null || ((string)value).Length == 0) return null;
     string basePath = Path.GetDirectoryName (serCtx.BaseFile);
     string file = Runtime.FileUtilityService.AbsoluteToRelativePath (basePath, value.ToString ());
     return new DataValue (Name, file);
 }
コード例 #3
0
 public override object Deserialize(SerializationContext serCtx, object mdata, DataNode data)
 {
     DataCollection items = ((DataItem) data).ItemData;
     object position;
     object collectionInstance = handler.CreateCollection (out position, items.Count);
     Deserialize (serCtx, mdata, items, collectionInstance, position);
     return collectionInstance;
 }
コード例 #4
0
 internal DataNode Serialize(SerializationContext serCtx, object value)
 {
     DataNode data = dataType.Serialize (serCtx, mapData, value);
     if (data != null) data.Name = SingleName;
     return data;
 }
コード例 #5
0
        void Deserialize(SerializationContext serCtx, object obj, DataCollection itemData, string baseName)
        {
            Hashtable expandedCollections = null;

            foreach (DataNode value in itemData) {
                ItemProperty prop = (ItemProperty) properties [baseName + value.Name];
                if (prop == null) {
                    if (value is DataItem)
                        Deserialize (serCtx, obj, ((DataItem)value).ItemData, baseName + value.Name + "/");
                    continue;
                }
                if (prop.WriteOnly)
                    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 = GetPropValue (prop, obj);
                        }
                        handler.AddItem (ref col, ref pos, prop.Deserialize (serCtx, value));
                        expandedCollections [prop] = pos;
                        SetPropValue (prop, obj, col);
                    }
                    else {
                        if (prop.HasSetter && prop.DataType.CanCreateInstance)
                            SetPropValue (prop, obj, prop.Deserialize (serCtx, value));
                        else if (prop.DataType.CanReuseInstance) {
                            object pval = GetPropValue (prop, 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, 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);
                }
            }
        }
コード例 #6
0
        internal void Deserialize(SerializationContext serCtx, object obj, DataCollection itemData)
        {
            foreach (ItemProperty prop in Properties)
                if (prop.DefaultValue != null)
                    SetPropValue (prop, obj, prop.DefaultValue);

            Deserialize (serCtx, obj, itemData, "");
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 public DataSerializer(DataContext ctx, string baseFile)
 {
     dataContext = ctx;
     serializationContext = ctx.CreateSerializationContext ();
     serializationContext.BaseFile = baseFile;
 }
コード例 #9
0
 public override DataNode Serialize(SerializationContext serCtx, object mapData, object value)
 {
     return new DataValue (Name, value.ToString ());
 }
コード例 #10
0
 public virtual void Deserialize(SerializationContext serCtx, object mapData, DataNode data, object valueInstance)
 {
     throw new InvalidOperationException ("Could not create instance for type '" + ValueType + "'");
 }
コード例 #11
0
 public abstract object Deserialize(SerializationContext serCtx, object mapData, DataNode data);
コード例 #12
0
 public abstract DataNode Serialize(SerializationContext serCtx, object mapData, object value);
コード例 #13
0
 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;
 }
コード例 #14
0
 public override void Deserialize(SerializationContext serCtx, object mdata, DataNode data, object collectionInstance)
 {
     DataCollection items = ((DataItem) data).ItemData;
     object position;
     handler.ResetCollection (collectionInstance, out position, items.Count);
     Deserialize (serCtx, mdata, items, collectionInstance, position);
 }
コード例 #15
0
 public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data)
 {
     return Enum.Parse (ValueType, ((DataValue)data).Value, false);
 }
コード例 #16
0
 public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data)
 {
     return Convert.ChangeType (((DataValue)data).Value, ValueType);
 }
コード例 #17
0
 public object LoadConfigurationData(SerializationContext serCtx, Type type, DataNode data)
 {
     DataType dataType = GetConfigurationDataType (type);
     return dataType.Deserialize (serCtx, null, data);
 }
コード例 #18
0
 public DataSerializer(DataContext ctx)
 {
     dataContext = ctx;
     serializationContext = ctx.CreateSerializationContext ();
 }
コード例 #19
0
 public DataNode SaveConfigurationData(SerializationContext serCtx, object obj, Type type)
 {
     if (type == null) type = obj.GetType ();
     DataType dataType = GetConfigurationDataType (type);
     return dataType.Serialize (serCtx, null, obj);
 }
コード例 #20
0
        public override object Deserialize(SerializationContext serCtx, object mapData, DataNode data)
        {
            DataItem item = data as DataItem;
            if (item == null)
                throw new InvalidOperationException ("Invalid value found for type '" + Name + "'");

            DataValue ctype = item ["ctype"] as DataValue;
            if (ctype != null && ctype.Value != Name) {
                DataType stype = FindDerivedType (ctype.Value);
                if (stype != null) return stype.Deserialize (serCtx, mapData, data);
                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);
            SetConfigurationItemData (serCtx, obj, item);
            return obj;
        }
コード例 #21
0
 public void SetConfigurationItemData(SerializationContext serCtx, object obj, DataItem data)
 {
     ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ());
     dataType.SetConfigurationItemData (serCtx, obj, data);
 }
コード例 #22
0
 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);
 }
コード例 #23
0
 internal object Deserialize(SerializationContext serCtx, DataNode data)
 {
     return dataType.Deserialize (serCtx, mapData, data);
 }
コード例 #24
0
        internal DataCollection Serialize(SerializationContext serCtx, object obj)
        {
            DataCollection itemCol = new DataCollection ();

            foreach (ItemProperty prop in Properties) {
                if (prop.ReadOnly) continue;
                object val = GetPropValue (prop, obj);
                if (val == null) continue;
                if (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, item);
                        data.Name = prop.SingleName;
                        col.Add (data);
                    }
                }
                else {
                    DataNode data = prop.Serialize (serCtx, val);
                    if (data == null) continue;
                    col.Add (data);
                }
            }
            return itemCol;
        }
コード例 #25
0
 internal void Deserialize(SerializationContext serCtx, DataNode data, object valueInstance)
 {
     dataType.Deserialize (serCtx, mapData, data, valueInstance);
 }
コード例 #26
0
 internal ClassTypeHandler(SerializationContext ctx, ClassDataType cdt)
 {
     this.ctx = ctx;
     this.cdt = cdt;
 }
コード例 #27
0
        void Deserialize(SerializationContext serCtx, object mdata, DataCollection items, object collectionInstance, object position)
        {
            MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData ();

            foreach (DataNode val in items) {
                handler.AddItem (ref collectionInstance, ref position, mapData.ItemType.Deserialize (serCtx, mapData.ItemMapData, val));
            }
            handler.FinishCreation (ref collectionInstance, position);
        }