private void LoadFromFile() { foreach (var config in _watchInfos) { var mananger = new CarpetManager(config); mananger.StartWatch(); _managers.Add(mananger); } }
private void Save_OnClick(object sender, RoutedEventArgs e) { var segments = CodeEditor.GetDeletableSegments().ToArray(); if (segments.Length != 3) { MessageBox.Show("GetFilePath, GetDirPath and at least one watch directory is required.", "Error", MessageBoxButton.OK); return; } var watchDirs = segments[0].Split('\n').Select(_ => _.Trim()).Where(_ => _.Length > 0); var error = AreDirectoriesValid(_viewModel.DestBaseDir, watchDirs); if (error != null) { MessageBox.Show(error, "Error", MessageBoxButton.OK); return; } error = IsNameValid(_viewModel.Name); if (error != null) { MessageBox.Show(error, "Error", MessageBoxButton.OK); return; } try { var f = new CustomFunction <CarpetFileInfo>("GetFilePath", PredefinedCustomFunctionParameter.File, segments[1]).Test(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Compilation error: GetFilePath", MessageBoxButton.OK); return; } try { var f = new CustomFunction <CarpetFileInfo>("GetDirPath", PredefinedCustomFunctionParameter.Dir, segments[2]).Test(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Compilation error:GetDirPath", MessageBoxButton.OK); return; } var existing = _managers.FirstOrDefault(_ => _.Info.Name == _viewModel.Name); if (existing != null) { Remove(_viewModel.Name); } //TODO: add automapper _model.Name = _viewModel.Name; _model.DestBaseDir = _viewModel.DestBaseDir; _model.Dirs = watchDirs.ToList(); _model.FileDest = segments[1]; _model.DirDest = segments[2]; _model.IncludeSubdirectories = _viewModel.IncludeSubdirectories; var mananger = new CarpetManager(_model); _watchInfos.Add(_model); mananger.StartWatch(); mananger.InitialScan(); _managers.Add(mananger); var comboItem = new ComboBoxItem { Content = _model.Name, DataContext = _model }; watchInfoList.Add(comboItem); WatchInfoCombo.SelectedItem = comboItem; _configManager.Save(_watchInfos); }