/// <summary> /// Zapisuje grupy jako pliki json /// </summary> /// <param name="group">Grupa do zapisania</param> /// <param name="pathToFIle">ścieżka zapisu, Jeśli nie zostanie po dana to plik zostanie zutomatycznie zapisany w domyślnej ścieżce</param> public void StoreGroup(Group group, string pathToFIle = null) { var serializer = new Serializer(); bool isNewFile = false; FileViewModel fileViewModel = new FileViewModel(); if (pathToFIle == null) { isNewFile = true; pathToFIle = SavedFilesPath + Guid.NewGuid() + ".json"; if (SavedDtmcData == null) { SavedDtmcData = new FilesListViewModel(); } if (SavedResultsData == null) { SavedResultsData = new FilesListViewModel(); } fileViewModel = new FileViewModel { FilePath = pathToFIle, DisplayDataFrame = MainScreenContent.DataContext as PresentationScreenViewModel }; } if (group.GetType() == typeof(TestedGroup)) { var tsGroup = group as TestedGroup; fileViewModel.WasEvaluated = tsGroup.Sessions.Exists(x => x.WasClassified); fileViewModel.FileName = group.GivenName; fileViewModel.Parent = SavedResultsData; fileViewModel.Represents = FileControlRepresents.SavedResults; if (isNewFile) { SavedResultsData.List.Add(fileViewModel); } serializer.WriteToJsonFile(pathToFIle, group as TestedGroup); } else if (group.GetType() == typeof(DtmcGroup)) { fileViewModel.FileName = group.GivenName; fileViewModel.Parent = SavedDtmcData; fileViewModel.Represents = FileControlRepresents.DTMC; if (isNewFile) { SavedDtmcData.List.Add(fileViewModel); } serializer.WriteToJsonFile(pathToFIle, group as DtmcGroup); } }
private void LoadSavedFile(string path) { Directory.CreateDirectory(path); var serializer = new Serializer(); if (SavedDtmcData == null) { SavedDtmcData = new FilesListViewModel(); } if (SavedResultsData == null) { SavedResultsData = new FilesListViewModel(); } foreach (var filename in Directory.EnumerateFiles(path)) { var loadedGroup = serializer.ReadFromJsonFile <Group>(filename); var viewModel = new FileViewModel { IsSelected = false, FilePath = filename, FileName = loadedGroup.GivenName, DisplayDataFrame = (PresentationScreenViewModel)MainScreenContent.DataContext, }; if (loadedGroup.GetType() == typeof(TestedGroup)) { var tsGroup = loadedGroup as TestedGroup; viewModel.Parent = SavedResultsData; viewModel.WasEvaluated = tsGroup.Sessions.Exists(x => x.WasClassified); viewModel.Parent = SavedResultsData; SavedResultsData.List.Add(viewModel); viewModel.Represents = FileControlRepresents.SavedResults; } else if (loadedGroup.GetType() == typeof(DtmcGroup)) { viewModel.Parent = SavedDtmcData; SavedDtmcData.List.Add(viewModel); viewModel.Represents = FileControlRepresents.DTMC; } } }