//public C_Variable this[String name] //{ // get // { // return from v in ContextCollection // where v.Name == name // select v; // } // set // { // collection.Add(name, value); // } //} #endregion // Indexer public void AddOrUpdate(C_Struct cs, C_VariableListContexts context) { var structs = (from v in _collection where v is ITypeDef && (v as ITypeDef).TypeDefName == cs.TypeDefName select v).ToList(); foreach (C_Struct csItem in structs) { _collection.Remove(csItem); } UpdateStructInCollection(cs, _collection); UpdateStructInCollection(cs, context.ContextCollection); _collection.Add(cs); UpdateCollectionChanged(CollectionChangeAction.Add, "Name"); UpdateCollectionChanged(CollectionChangeAction.Add, "Size"); }
public void AddOrUpdate(C_Enum ce, C_VariableListContexts context) { var enums = (from v in _collection where v is ITypeDef && (v as ITypeDef).TypeDefName == ce.TypeDefName select v).ToList(); foreach (C_Enum ceItem in enums) { _collection.Remove(ceItem); } UpdateEnumInCollection(ce, _collection); UpdateEnumInCollection(ce, context.ContextCollection); _collection.Add(ce); UpdateCollectionChanged(CollectionChangeAction.Add, "Name"); UpdateCollectionChanged(CollectionChangeAction.Add, "Size"); }
public static bool SaveToXml(C_VariableListContexts context, String path) { String backupPath = String.Format("{0}.bak", path); bool saveResult = false; try { if (!FileHelper.IsFilePathLegal(path)) { return(false); } XmlSerializer writer = new XmlSerializer(typeof(C_VariableListContexts), IncludedTypes); if (!FileHelper.CheckPath(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); File.Create(path).Close(); } File.Copy(path, backupPath, true); using (StreamWriter file = new StreamWriter(path)) { writer.Serialize(file, context); } saveResult = true; } catch (Exception ex) { try { File.Copy(path, String.Format("{0}.err", path), true); File.Copy(backupPath, path, true); } catch (Exception ex1) { LogWriter.Instance.WriteToLog(ex1, "Error restoring backup: {0}", backupPath); } LogWriter.Instance.WriteToLog(ex, "Error saving {0}", path); } return(saveResult); }
public static bool LoadFromXml(C_VariableListContexts context, String path) { bool loadResult = false; try { if (!FileHelper.IsFilePathLegal(path)) { return(false); } if (FileHelper.CheckPath(path)) { var eventHandlers = context.CollectionChanged; XmlSerializer reader = new XmlSerializer(typeof(C_VariableListContexts), IncludedTypes); using (StreamReader file = new StreamReader(path)) { context = (C_VariableListContexts)reader.Deserialize(file); } context.CollectionChanged = eventHandlers; loadResult = true; context.UpdateCollectionChanged(CollectionChangeAction.Refresh, "All"); foreach (C_Variable cvItem in context.ContextCollection) { cvItem.SetParent(); } foreach (C_Variable cvItem in context.ContextCollection) { cvItem.SetParent(); } } } catch (Exception ex) { LogWriter.Instance.WriteToLog(ex, "Error loading C_VariableList.xml"); } return(loadResult); }