public void LoadExternalRuleCollections() { ExternalRuleCollections = new List <BestPracticeCollection>(); if (_model != null) { var externalRuleCollectionsJson = _model.GetAnnotation(BPAAnnotationExternalRules); if (externalRuleCollectionsJson != null) { try { var externalRuleFilePaths = JsonConvert.DeserializeObject <List <string> >(externalRuleCollectionsJson); Environment.CurrentDirectory = FileSystemHelper.DirectoryFromPath(UIController.Current.File_Current) ?? Environment.CurrentDirectory; foreach (var filePath in externalRuleFilePaths) { try { if (filePath.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromUrl(filePath)); } else { ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(filePath)); } } catch { } } } catch { } } } }
public void LoadExternalRuleCollections() { ExternalRuleCollections = new List <BestPracticeCollection>(); if (_model != null) { var externalRuleCollectionsJson = _model.GetAnnotation(BPAAnnotationExternalRules); if (externalRuleCollectionsJson != null) { try { var externalRuleFilePaths = JsonConvert.DeserializeObject <List <string> >(externalRuleCollectionsJson); foreach (var filePath in externalRuleFilePaths) { try { if (filePath.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromUrl(filePath)); } else { ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(BasePath, filePath)); } } catch { } } } catch { } } } }
public bool LocalFile() { var startDir = FileSystemHelper.DirectoryFromPath(UIController.Current.File_Current) ?? Environment.CurrentDirectory; var sfd = new CommonOpenFileDialog("Open Rule File"); sfd.EnsureFileExists = true; sfd.InitialDirectory = startDir; sfd.DefaultExtension = "json"; sfd.Filters.Add(new CommonFileDialogFilter("JSON file", "*.json")); sfd.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); var localPathCheckBox = new CommonFileDialogCheckBox("Use relative path", true) { Visible = false }; if (UIController.Current.File_Current != null) { sfd.Controls.Add(localPathCheckBox); localPathCheckBox.Visible = true; sfd.FolderChanging += (s, e) => { var relativePath = FileSystemHelper.GetRelativePath(startDir, e.Folder); if (relativePath.Length >= 2 && relativePath[1] == ':') { localPathCheckBox.Visible = false; } else { localPathCheckBox.Visible = true; } }; } parent.Enabled = false; if (sfd.ShowDialog() == CommonFileDialogResult.Ok) { parent.Enabled = true; var fileName = localPathCheckBox.Visible && localPathCheckBox.IsChecked ? FileSystemHelper.GetRelativePath(startDir, sfd.FileName) : sfd.FileName; if (!analyzer.ExternalRuleCollections.Any( rc => rc.FilePath != null && FileSystemHelper.GetAbsolutePath(analyzer.BasePath, rc.FilePath).EqualsI(sfd.FileName) )) { analyzer.ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(analyzer.BasePath, fileName)); } return(true); } parent.Enabled = true; return(false); }
public bool NewFile() { var sfd = new CommonSaveFileDialog("New Rule File"); sfd.EnsurePathExists = true; sfd.InitialDirectory = analyzer.BasePath; sfd.DefaultFileName = "BPARules.json"; sfd.DefaultExtension = "json"; sfd.Filters.Add(new CommonFileDialogFilter("JSON file", "*.json")); sfd.Filters.Add(new CommonFileDialogFilter("All files", "*.*")); var localPathCheckBox = new CommonFileDialogCheckBox("Use relative path", true) { Visible = false }; if (UIController.Current.File_Current != null) { sfd.Controls.Add(localPathCheckBox); localPathCheckBox.Visible = true; sfd.FolderChanging += (s, e) => { var relativePath = FileSystemHelper.GetRelativePath(analyzer.BasePath, e.Folder); if (relativePath.Length >= 2 && relativePath[1] == ':') { localPathCheckBox.Visible = false; } else { localPathCheckBox.Visible = true; } }; } parent.Enabled = false; if (sfd.ShowDialog() == CommonFileDialogResult.Ok) { parent.Enabled = true; try { File.WriteAllText(sfd.FileName, "[]"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unable to create rule file", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } var fileName = localPathCheckBox.Visible && localPathCheckBox.IsChecked ? FileSystemHelper.GetRelativePath(analyzer.BasePath, sfd.FileName) : sfd.FileName; if (!analyzer.ExternalRuleCollections.Any( rc => rc.FilePath != null && FileSystemHelper.GetAbsolutePath(analyzer.BasePath, rc.FilePath).EqualsI(sfd.FileName) )) { analyzer.ExternalRuleCollections.Add(BestPracticeCollection.GetCollectionFromFile(analyzer.BasePath, fileName)); } return(true); } parent.Enabled = true; return(false); }