public async void LoadPresets() { ExceptionDispatchInfo jsonException = null; try { using (var SR = new StreamReader(Environment.CurrentDirectory + @"\presets.txt")) using (var jsonReader = new JsonTextReader(SR)) { var jsonData = (JArray)JToken.ReadFrom(jsonReader); foreach (var arrayObj in jsonData) { var title = arrayObj.SelectToken("Title").ToString(); var start = variableReturn(arrayObj.SelectToken("Source").ToString(), "username"); var stop = variableReturn(arrayObj.SelectToken("Destination").ToString(), "destination"); var filter = arrayObj.SelectToken("File_Ext").ToString(); var listObject = new BackupDataView(title, start, stop, filter); presets.Add(listObject); } } } catch (FileNotFoundException) { var msgBox = new MessageDialogBox(); msgBox.AcknowledgeBoxAsync("Missing Presets", "Looks like we are missing presets. Please create and save a preset."); } catch (JsonReaderException ex) { jsonException = ExceptionDispatchInfo.Capture(ex); } if (jsonException == null) return; var msgDialog = new MessageDialogBox(); var result = await msgDialog.ChoicesBox("Preset File Error", "The preset file formatting seems to be incorrect. Delete?"); if (result != MessageDialogResult.Affirmative) return; if (File.Exists(Environment.CurrentDirectory + @"\presets.txt")) File.Delete(Environment.CurrentDirectory + @"\presets.txt"); }
private void ScanAll(object sender, RoutedEventArgs e) { if (NullOrIncorrectFields()) { var msgDialog = new MessageDialogBox(); msgDialog.AcknowledgeBoxAsync("Missing Fields", "Some required fields are missing entries."); return; } try { var checkSubDirectory = Convert.ToInt16(Directory.GetDirectories(SourceDestination).Count().ToString()); var tempList = new List<BackupFileProp>(); if (checkSubDirectory == 0) { foreach (var item in ScanForFiles()) { sharedList.Add(item); } } if (Directory.GetFiles(SourceDestination).Any() && checkSubDirectory > 0) { ScanForFileWithSubDirectory(SourceDestination, tempList); foreach (var item in tempList) { sharedList.Add(item); } foreach (var item in ScanForFiles()) { sharedList.Add(item); } } BackupDataGrid.ItemsSource = sharedList.Where(x => x.scannedFileName != null); } catch (DirectoryNotFoundException) { var msgDialog = new MessageDialogBox(); msgDialog.AcknowledgeBoxAsync("Directory Not Found", SourceDestination); } }
public void CreatePreset() { if (PresetTitle == null || NullOrIncorrectFields()) { var msgDialog = new MessageDialogBox(); msgDialog.AcknowledgeBoxAsync("Missing Fields", "Please Check Fields"); }; presets.Add(new BackupDataView() { PresetTitle = PresetTitle, SourceDestination = SourceDestination, SaveDestination = SaveDestination, DesiredExtension = DesiredExtension }); SourceDestination = null; SaveDestination = null; DesiredExtension = null; PresetTitle = null; }