DataCollection ICustomDataItem.Serialize (ITypeSerializer handler) { if (policies == null) return null; DataCollection dc = new DataCollection (); foreach (KeyValuePair<PolicyKey,object> p in policies) dc.Add (PolicyService.DiffSerialize (p.Key.PolicyType, p.Value, p.Key.Scope)); return dc; }
int FindData (string name, out DataCollection colec, bool buildTree) { if (list == null) { colec = null; return -1; } if (name.IndexOf ('/') == -1) { for (int n=0; n<list.Count; n++) { DataNode data = list [n]; if (data.Name == name) { 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.List.Count; n++) { data = colec.List [n]; if (data.Name == names [p]) { pos = n; break; } } } return pos; } }
void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data) { handler.Deserialize (this, data); if (data["Url"] == null) { string dir = ((DataValue)data ["Dir"]).Value; string user = ((DataValue)data ["User"]).Value; string server = ((DataValue)data ["Server"]).Value; string method = ((DataValue)data ["Method"]).Value; int port = int.Parse (((DataValue)data ["Port"]).Value); UriBuilder ub = new UriBuilder (method, server, port, dir); url = ub.ToString (); } CreateUri (); }
void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data) { if (data.Count == 0) return; policies = new PolicyDictionary (); foreach (DataNode node in data) { try { if (!(node is DataItem)) continue; ScopedPolicy val = PolicyService.DiffDeserialize ((DataItem)node); policies.Add (val); } catch (Exception ex) { if (handler.SerializationContext.ProgressMonitor != null) handler.SerializationContext.ProgressMonitor.ReportError (ex.Message, ex); else LoggingService.LogError (ex.Message, ex); } } }
public override void Deserialize (object obj, ITypeSerializer handler, DataCollection data) { //deserialise as normal base.Deserialize (obj, handler, data); AspNetAppProject proj = obj as AspNetAppProject; if (proj == null) return; //find files that are web content and have been deserialised from the obsolete "FileCopy" BuildAction foreach (MonoDevelop.Projects.ProjectFile pf in proj.Files) { if (pf.BuildAction != MonoDevelop.Projects.BuildAction.Content || pf.CopyToOutputDirectory != MonoDevelop.Projects.FileCopyMode.Always) continue; WebSubtype type = proj.DetermineWebSubtype (pf); if (type != WebSubtype.None && type != WebSubtype.Code) { //and mark them to not copy, since we don't actually want this; // the obsolete behaviour was a hack pf.CopyToOutputDirectory = MonoDevelop.Projects.FileCopyMode.None; } } }
public void Deserialize(ITypeSerializer handler, DataCollection data) { handler.Deserialize (this, data); foreach (var p in tempIncludes) LocalIncludeCache.ParsedDirectories.Add (ProjectBuilder.EnsureCorrectPathSeparators (p)); }
public virtual void Deserialize (object obj, ITypeSerializer handler, DataCollection data) { if (obj is ProjectFile) { ProjectFile pf = (ProjectFile) obj; //Map the old FileCopy action to the Content BuildAction with CopyToOutputDirectory set to "always" //BuildActionDataType handles mapping the BuildAction to "Content" DataValue value = data ["buildaction"] as DataValue; bool isFileCopy = value != null && value.Value == "FileCopy"; DataValue resourceId = data.Extract ("resource_id") as DataValue; handler.Deserialize (obj, data); if (isFileCopy) pf.CopyToOutputDirectory = FileCopyMode.Always; if (resourceId != null) pf.ResourceId = resourceId.Value; } else if (obj is SolutionEntityItem) { DataValue ac = null; DataItem confItem = data ["Configurations"] as DataItem; if (confItem != null) ac = (DataValue) confItem.ItemData.Extract ("active"); DataItem items = data.Extract ("Items") as DataItem; if (items != null) ReadItems (handler, (SolutionEntityItem)obj, items); handler.Deserialize (obj, data); if (ac != null) { SolutionEntityItem item = (SolutionEntityItem) obj; item.DefaultConfigurationId = ac.Value; } DotNetProject np = obj as DotNetProject; if (np != null) { // Import the framework version TargetFrameworkMoniker fx = null; DataValue vfx = data["targetFramework"] as DataValue; if (vfx != null) fx = TargetFrameworkMoniker.Parse (vfx.Value); else { vfx = data ["clr-version"] as DataValue; if (vfx != null && vfx.Value == "Net_2_0") fx = TargetFrameworkMoniker.NET_2_0; else if (vfx != null && vfx.Value == "Net_1_1") fx = TargetFrameworkMoniker.NET_1_1; } if (fx != null) np.TargetFramework = Runtime.SystemAssemblyService.GetTargetFramework (fx); // Get the compile target from one of the configurations if (np.Configurations.Count > 0) np.CompileTarget = (CompileTarget) Enum.Parse (typeof(CompileTarget), (string) np.Configurations [0].ExtendedProperties ["Build/target"]); } } else if (obj is ProjectReference) { ProjectReference pref = (ProjectReference) obj; DataValue refto = data.Extract ("refto") as DataValue; handler.Deserialize (obj, data); if (refto != null) { pref.Reference = refto.Value; if (pref.ReferenceType == ReferenceType.Assembly) { string basePath = Path.GetDirectoryName (handler.SerializationContext.BaseFile); pref.Reference = FileService.RelativeToAbsolutePath (basePath, pref.Reference); } } } else handler.Deserialize (obj, data); }
public void Deserialize (object obj, ITypeSerializer handler, DataCollection data) { subHandler.Deserialize (obj, new ChainedTypeSerializer (mainHandler, handler), data); }
internal void DeserializeNoCustom (SerializationContext serCtx, object obj, DataCollection itemData) { foreach (ItemProperty prop in Properties) if (!prop.CanDeserialize (serCtx, obj) && prop.DefaultValue != null) prop.SetValue (obj, prop.DefaultValue); // ukwnDataRoot is where to store values for which a property cannot be found. DataItem ukwnDataRoot = (obj is IExtendedDataItem) ? new DataItem () : null; Deserialize (serCtx, obj, itemData, ukwnDataRoot, ""); // store unreadable raw data to a special property so it can be // serialized back an the original format is kept if (ukwnDataRoot != null && ukwnDataRoot.HasItemData) ((IExtendedDataItem)obj).ExtendedProperties ["__raw_data"] = ukwnDataRoot; }
int FindData(string name, out DataCollection colec, bool buildTree) { if (list == null) { colec = null; return(-1); } if (name.IndexOf('/') == -1) { for (int n = 0; n < list.Count; n++) { DataNode data = list [n]; if (data.Name == name) { 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.List.Count; n++) { data = colec.List [n]; if (data.Name == names [p]) { pos = n; break; } } } return(pos); } }
public void AddRange (DataCollection col) { foreach (DataNode node in col) Add (node); }
public void Merge (DataCollection col) { ArrayList toAdd = new ArrayList (); foreach (DataNode node in col) { DataNode current = this [node.Name]; if (current == null) toAdd.Add (node); else if (node is DataItem && current is DataItem) { ((DataItem)current).ItemData.Merge (((DataItem)node).ItemData); } } foreach (DataNode node in toAdd) Add (node); }
public void Deserialize (object obj, ITypeSerializer handler, DataCollection data) { handler.Deserialize (obj, data); }
public void Deserialize (object obj, ITypeSerializer handler, DataCollection data) { //find whether is was marked as FileCopy DataValue value = data ["buildaction"] as DataValue; bool isFileCopy = value != null && value.Value == "FileCopy"; handler.Deserialize (obj, data); ProjectFile file = (ProjectFile) obj; //if it wasn't, no fancy migrations to do if (!isFileCopy) return; //if there were any deploy settings remaining in the project file, then the file isn't "copy to output" //but instead should be marked to deploy foreach (string key in keys) { if (file.ExtendedProperties.Contains (key)) { file.CopyToOutputDirectory = FileCopyMode.None; file.ExtendedProperties ["DeployService.Deploy"] = true; return; } } }
public void Deserialize(ITypeSerializer handler, DataCollection data) { handler.Deserialize(this, data); }
void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data) { DataItem items = (DataItem) data.Extract ("Items"); handler.Deserialize (this, data); ProgressMonitor monitor = handler.SerializationContext.ProgressMonitor; if (monitor == null) monitor = new ProgressMonitor (); if (items != null) { string baseDir = Path.GetDirectoryName (handler.SerializationContext.BaseFile); monitor.BeginTask (null, items.ItemData.Count); try { foreach (DataValue item in items.ItemData) { string file = Path.Combine (baseDir, item.Value); WorkspaceItem it = Services.ProjectService.ReadWorkspaceItem (monitor, file).Result; if (it != null) Items.Add (it); monitor.Step (1); } } finally { monitor.EndTask (); } } }
public void Deserialize (object instance, DataCollection data) { cdt.DeserializeNoCustom (ctx, instance, data); }
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 Deserialize(ITypeSerializer handler, DataCollection data) { handler.Deserialize(this, data); foreach (var p in tempIncludes) LocalIncludeCache.Add(p); // Parse local includes DCompilerConfiguration.UpdateParseCacheAsync(LocalIncludeCache); }
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); } } }
public void Deserialize(ITypeSerializer handler, DataCollection data) { itemHandler.Deserialize(ob, handler, data); }
public void Deserialize (ITypeSerializer handler, DataCollection data) { itemHandler.Deserialize (ob, handler, data); }
public void Deserialize(object obj, ITypeSerializer handler, DataCollection data) { subHandler.Deserialize(obj, new ChainedTypeSerializer(mainHandler, handler), data); }
public void Deserialize (object instance, DataCollection data) { handler.Deserialize (instance, serializer, data); }
public void Deserialize(object instance, DataCollection data) { handler.Deserialize(instance, serializer, data); }
public void Deserialize(ITypeSerializer handler, DataCollection data) { handler.Deserialize (this, data); referenceCollection.InitRefCollection (tempProjectDependencies, tempIncludes); }
internal DataCollection Serialize(SerializationContext serCtx, object obj) { DataCollection itemCol = new DataCollection(); foreach (ItemProperty prop in Properties) { if (prop.ReadOnly || !prop.CanSerialize(serCtx, obj)) { continue; } DataCollection col = itemCol; object val = prop.GetValue(obj); if (val == null) { if (serCtx.IncludeDeletedValues) { if (prop.IsNested) { col = GetNestedCollection(col, prop.NameList, 0, true); } col.Add(new DataDeletedNode(prop.SingleName)); } continue; } var isDefault = val.Equals(prop.DefaultValue); if (isDefault && !serCtx.IsDefaultValueSerializationForced(prop)) { continue; } if (prop.IsNested) { col = GetNestedCollection(col, prop.NameList, 0, isDefault); } 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) { if (serCtx.IncludeDeletedValues) { col.Add(new DataDeletedNode(prop.SingleName)); } continue; } data.IsDefaultValue = isDefault; 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); }
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); }
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); } } }
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); } }
public void Deserialize(object instance, DataCollection data) { cdt.DeserializeNoCustom(ctx, instance, data); }
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); }
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.Serializer.IncludeDefaultValues && 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; }
// if MtouchDebug element is not present, this handler migrates args // and sets default values for the new Mtouch* properties public void Deserialize (ITypeSerializer handler, DataCollection data) { var argsToMigrate = data.Extract ("ExtraMtouchArgs") as DataValue; var mtouchDebugData = data.Extract ("MtouchDebug") as DataValue; handler.Deserialize (this, data); if (mtouchDebugData == null || string.IsNullOrEmpty (mtouchDebugData.Value)) { if (Name == "Debug") { MtouchDebug = true; if (Platform == IPhoneProject.PLAT_SIM) MtouchLink = MtouchLinkMode.None; } if (argsToMigrate != null && string.IsNullOrEmpty (argsToMigrate.Value)) { if (argsToMigrate.Value.Contains ("-debug")) MtouchDebug = true; if (argsToMigrate.Value.Contains ("-nolink")) MtouchLink = MtouchLinkMode.None; MtouchExtraArgs = new StringBuilder (argsToMigrate.Value) .Replace ("-nolink", "").Replace ("-linksdkonly", "").Replace ("-debug", "").Replace (" ", " ") .ToString (); } } else { MtouchDebug = mtouchDebugData.Value.Equals ("true", StringComparison.OrdinalIgnoreCase); } }
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); }