private IDataService LoadFile(string path, bool IgnoreExceptions) { string jsonString = ""; var settings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, PreserveReferencesHandling = PreserveReferencesHandling.All, TypeNameHandling = TypeNameHandling.All }; IDataService dataService = new InvalidDataService(); try { jsonString = File.ReadAllText(path); dataService = JsonConvert.DeserializeObject <DataService>(jsonString, settings); SS.LastUsedPath = path; } catch { SS.LastUsedPath = ""; dataService = new InvalidDataService(); if (!IgnoreExceptions) { throw; } } return(dataService); }
public IDataService LoadLastFile() { string path = SS.LastUsedPath; IDataService LoadResult = new InvalidDataService(); //if a previous file exists if (!string.IsNullOrEmpty(path)) { TargetDirectory = Path.GetDirectoryName(path); LoadResult = LoadFile(path, true); } return(LoadResult); }
public IDataService LoadWithDialog() { IDataService Load_Success = new InvalidDataService(); string filepath = ""; OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Character Manager File (*.cmv1) |*.cmv1", InitialDirectory = TargetDirectory }; if (openFileDialog.ShowDialog() == true) { filepath = openFileDialog.FileName; Load_Success = LoadFile(filepath); } return(Load_Success); }