internal void ValidateImport(RuleApplicationDef dest) { if (dest.Validate().Count != 0) { throw new InvalidImportException("The import you just attempted is not valid."); } }
public void TestImportDefByCategory() { Helper h = new Helper(); string sourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_SourceRuleApplication_Import_By_Category.ruleappx"); string destPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_DestRuleApplication_Import_By_Category.ruleappx"); RuleApplicationDef source = RuleApplicationDef.Load(sourcePath); RuleApplicationDef dest = RuleApplicationDef.Load(destPath); h.ImportRuleApp(source, dest, "Category1"); RuleRepositoryDefBase retval = h.FindDefDeep(dest, "FireNotification1"); Assert.NotNull(retval); RuleApplicationValidationErrorCollection err = dest.Validate(); string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", Guid.NewGuid() + "TempRuleApplication.ruleappx"); dest.SaveToFile(tempPath); }
public void Execute() { try { _ruleAppDef = RuleApplicationService.RuleApplicationDef; _excelFilePath = Utility.BrowseForPath(); _sheetName = Utility.GetSheetName(); if (_excelFilePath.Length == 0) { return; } var spreadsheet = new Spreadsheet(); var rows = spreadsheet.ExtractExcelValues(_excelFilePath, _sheetName); var decisionTableDef = new DecisionTableDef(); decisionTableDef.Name = GetDTName(_excelFilePath); RuleApplicationService.Controller.AddDef(decisionTableDef, SelectedItem); // create a wait window that will run on background thread var window = new BackgroundWorkerWaitWindow("Decision Table Import", "Importing..."); // use delegate to load decision table with data window.DoWork += delegate(object sender, DoWorkEventArgs e) { ExecuteImport(decisionTableDef, rows, spreadsheet); }; // use delegate to report errors and close window window.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MessageBoxFactory.Show("The following error occurred while attempting to import the spreadsheet:\n\n" + e.Error.ToString(), "Import", MessageBoxFactoryImage.Error); } window.Close(); var validations = _ruleAppDef.Validate(); var s = new StringBuilder(); foreach (var validation in validations) { s.AppendLine(validation.ToString()); } if (s.Length > 0) { MessageBoxFactory.Show(s.ToString(), ""); } }; // show the window window.ShowDialog(); } catch (Exception e) { MessageBoxFactory.Show("The following error occurred while attempting to import the spreadsheet:\n\n" + e, "Regimen Import", MessageBoxFactoryImage.Error); } }