public void SaveModifiedSymbol(Symbol symbol) { RemoveObsoleteSymbolFiles(symbol); SymbolJson symbolJson = new SymbolJson(); using (var sw = new StreamWriter(GetFilePathForSymbol(symbol))) using (var writer = new JsonTextWriter(sw)) { symbolJson.Writer = writer; symbolJson.Writer.Formatting = Formatting.Indented; symbolJson.WriteSymbol(symbol); } if (!string.IsNullOrEmpty(symbol.PendingSource)) { WriteSymbolSourceToFile(symbol); } }
public Symbol ReadSymbolFromFile(string symbolFile) { Log.Info($"file: {symbolFile}"); using (var sr = new StreamReader(symbolFile)) using (var jsonReader = new JsonTextReader(sr)) { SymbolJson symbolJson = new SymbolJson { Reader = jsonReader }; var symbol = symbolJson.ReadSymbol(this); if (symbol != null) { symbol.SourcePath = OperatorTypesFolder + symbol.Name + SourceExtension; SymbolRegistry.Entries.Add(symbol.Id, symbol); } return(symbol); } }
public virtual void SaveAll() { ResourceManager.Instance().DisableOperatorFileWatcher(); // don't update ops if file is written during save // remove all old t3 files before storing to get rid off invalid ones DirectoryInfo di = new DirectoryInfo(OperatorTypesFolder); FileInfo[] files = di.GetFiles("*" + SymbolExtension).ToArray(); foreach (FileInfo file in files) { try { File.Delete(file.FullName); } catch (Exception e) { Log.Warning("Failed to deleted file '" + file + "': " + e); } } SymbolJson symbolJson = new SymbolJson(); // store all symbols in corresponding files foreach (var(_, symbol) in SymbolRegistry.Entries) { using (var sw = new StreamWriter(OperatorTypesFolder + symbol.Name + "_" + symbol.Id + SymbolExtension)) using (var writer = new JsonTextWriter(sw)) { symbolJson.Writer = writer; symbolJson.Writer.Formatting = Formatting.Indented; symbolJson.WriteSymbol(symbol); } if (!string.IsNullOrEmpty(symbol.PendingSource)) { WriteSymbolSourceToFile(symbol); } } ResourceManager.Instance().EnableOperatorFileWatcher(); }