public static CatalogRuleApplicationReference GetCatalogRuleAppReference(RuleExecutionInfo ruleExecutionInfo) { var ruleapp = new CatalogRuleApplicationReference(ruleExecutionInfo.CatalogUri, ruleExecutionInfo.RuleAppName, ruleExecutionInfo.Username, ruleExecutionInfo.Password); ruleapp.SetRefresh(ruleExecutionInfo.CatalogRefreshInterval); ruleapp.ConnectionTimeout = ruleExecutionInfo.CatalogRuleAppTimeoutInterval; return(ruleapp); }
private static void Main() { // Load rule application from catalog var ruleappref = new CatalogRuleApplicationReference("http://localhost/InRuleCatalogService/Service.svc", "InvoiceLineItem"); ruleappref.Credentials = new CatalogCredentials("admin", "password"); using (var session = new RuleSession(ruleappref)) { // Create Invoice entity var invoiceEntity = session.CreateEntity("Invoice"); // Read the state file into the entity invoiceEntity.LoadXml(@"InvoiceLineItem.xml"); // Apply rules session.ApplyRules(); // Get the value of the Total calculation var total = invoiceEntity.Fields["Total"].Value; Console.WriteLine("Total is: " + total); Console.ReadLine(); } }
static async Task <int> Main(string[] args) { //Required Parameters bool showHelp = false; string irDistributionKey = null; string OutputFilePath = null; //Option 1 string RuleAppFilePath = null; //Option 2 string CatalogUri = null; string CatalogUsername = null; string CatalogPassword = null; string CatalogRuleAppName = null; string CatalogRuleAppLabel = "LIVE"; var clParams = new OptionSet { { "h|help", "Display Help.", k => showHelp = true }, { "k|DistributionKey=", "The irDistributionKey for your account.", k => irDistributionKey = k }, { "o|OutputPath=", "Desired Path for the compiled output library.", p => OutputFilePath = p }, //Option 1 { "r|RuleAppPath=", "Path to the Rule Application to be compiled.", p => RuleAppFilePath = p }, //Option 2 { "c|CatUri=", "Web URI for the IrCatalog Service endpoint.", p => CatalogUri = p }, { "u|CatUsername="******"IrCatalog Username for authentication.", p => CatalogUsername = p }, { "p|CatPassword="******"IrCatalog Password for authentication.", p => CatalogPassword = p }, { "n|CatRuleAppName=", "Name of the Rule Application.", p => CatalogRuleAppName = p }, { "l|CatLabel=", "Label of the Rule Application to retrieve (LIVE).", p => CatalogRuleAppLabel = p }, }; try { clParams.Parse(args); } catch (OptionException e) { Console.Write("Failed parsing execution parameters: " + e.Message); showHelp = true; } RuleApplicationReference ruleApp = null; if (showHelp) { ShowHelp(clParams); return(1); } else if (string.IsNullOrEmpty(irDistributionKey)) { Console.WriteLine("Error: Missing required parameter DistributionKey."); return(1); } else if (string.IsNullOrEmpty(OutputFilePath)) { Console.WriteLine("Error: Missing required parameter OutputPath."); return(1); } if (!string.IsNullOrEmpty(RuleAppFilePath)) { try { ruleApp = new FileSystemRuleApplicationReference(RuleAppFilePath); } catch (IntegrationException ie) { Console.WriteLine("Error creating reference to file-based Rule App: " + ie.Message); //Rule App file not found } } if (!string.IsNullOrEmpty(CatalogUri) && !string.IsNullOrEmpty(CatalogUsername) && !string.IsNullOrEmpty(CatalogPassword) && !string.IsNullOrEmpty(CatalogRuleAppName)) { if (ruleApp != null) { Console.WriteLine("Error: Parameters were provided for both File- and Catalog-based Rule App; only one may be specified."); return(1); } else { ruleApp = new CatalogRuleApplicationReference(CatalogUri, CatalogRuleAppName, CatalogUsername, CatalogPassword, CatalogRuleAppLabel); } } if (ruleApp == null) { Console.WriteLine("You must provide either RuleAppPath or all of CatUri, CatUsername, CatPassword, and CatRuleAppName (with optional CatLabel)"); return(1); } else { var success = await RetrieveAndWriteIrJSFromDistributionService(ruleApp, irDistributionKey, OutputFilePath); if (success) { return(0); } else { return(1); } } }
public List <CatalogSearchResultViewModel> SearchCatalogForDescription(SearchField field, string searchQuery, Dispatcher dispatcher) { List <CatalogSearchResultViewModel> results = new List <CatalogSearchResultViewModel>(); try { Debug.WriteLine($"Searching for '{searchQuery}' in the {field} from catalog located at {Settings.CatalogServiceUrl}"); using (var catCon = new RuleCatalogConnection(new Uri(Settings.CatalogServiceUrl), TimeSpan.FromSeconds(60), Settings.CatalogUsername, Settings.CatalogPassword)) { var ruleApps = catCon.GetAllRuleApps().Where(ra => ra.Key.IsLatest); int processedRuleApps = 0; foreach (var ruleApp in ruleApps) { var ruleAppDefInfo = ruleApp.Key; var ruleAppInfo = ruleApp.Value; Debug.WriteLine($"Searching Rule App {ruleAppDefInfo.Name} v{ruleAppDefInfo.PublicRevision} {ruleAppInfo.LastLabelName}"); var ruleAppRef = new CatalogRuleApplicationReference(Settings.CatalogServiceUrl, ruleAppDefInfo.Name, Settings.CatalogUsername, Settings.CatalogPassword, ruleAppDefInfo.PublicRevision); var ruleAppDef = ruleAppRef.GetRuleApplicationDef(); var entities = ((IEnumerable <EntityDef>)ruleAppDef.Entities); foreach (var entity in entities) { foreach (var ruleSet in entity.GetAllRuleSets()) { switch (field) { case SearchField.Description: if (ruleSet.Comments.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, ruleSet.Comments, Settings)); })); } break; case SearchField.Name: if (ruleSet.Name.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, ruleSet.Name, Settings)); })); } break; case SearchField.Note: var matchingNote = ruleSet.Notes.FirstOrDefault(n => n.Text.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)); if (matchingNote != null) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, matchingNote.Text, Settings)); })); } break; } foreach (RuleElementDef rule in ruleSet.GetAllRuleElements()) { switch (field) { case SearchField.Description: if (rule.Comments.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, rule.Comments, Settings, rule)); })); } break; case SearchField.Name: if (rule.Name.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, rule.Name, Settings, rule)); })); } break; case SearchField.Note: var matchingNote = rule.Notes.FirstOrDefault(n => n.Text.Contains(searchQuery, StringComparison.InvariantCultureIgnoreCase)); if (matchingNote != null) { dispatcher.BeginInvoke(new Action(() => { Results.Add(new CatalogSearchResultViewModel(ruleAppDefInfo, ruleSet, matchingNote.Text, Settings, rule)); })); } break; } } } } dispatcher.BeginInvoke(new Action(() => { Progress = (int)(++processedRuleApps / (double)ruleApps.Count() * 100); })); } } } catch (Exception ex) { Debug.WriteLine("Error occurred: " + ex.ToString()); } return(results); }
static int Main(string[] args) { bool showHelp = false; string ruleAppName = null; string label = "LIVE"; string comment = ""; string sourceCatalogUrl = null; string sourceCatalogUsername = null; string sourceCatalogPassword = null; string destCatalogUrl = null; string destCatalogUsername = null; string destCatalogPassword = null; var clParams = new OptionSet { { "h|help", "Display Help.", k => showHelp = true }, { "n|RuleAppName=", "The name of the Rule App to promote.", n => ruleAppName = n }, { "l|Label=", "Label assigned to the desired version of the Rule App.", l => label = l }, { "m|Comment=", "Comment to be associated with the promotion commit.", c => comment = c }, //Source { "a|SrcCatUri=", "Web URI for the source IrCatalog Service endpoint.", c => sourceCatalogUrl = c }, { "b|SrcCatUser="******"IrCatalog Username for authentication .", u => sourceCatalogUsername = u }, { "c|SrcCatPass="******"IrCatalog Password for authentication.", p => sourceCatalogPassword = p }, //Dest { "d|DestCatUri=", "Web URI for the target IrCatalog Service endpoint.", c => destCatalogUrl = c }, { "e|DestCatUser="******"IrCatalog Username for authentication.", u => destCatalogUsername = u }, { "f|DestCatPass="******"IrCatalog Password for authentication.", p => destCatalogPassword = p }, }; try { clParams.Parse(args); } catch (OptionException e) { Console.Write("Failed parsing execution parameters: " + e.Message); showHelp = true; } if (showHelp) { ShowHelp(clParams); return(1); } else if (string.IsNullOrEmpty(ruleAppName) || string.IsNullOrEmpty(sourceCatalogUrl) || string.IsNullOrEmpty(sourceCatalogUsername) || string.IsNullOrEmpty(sourceCatalogPassword) || string.IsNullOrEmpty(destCatalogUrl) || string.IsNullOrEmpty(destCatalogUsername) || string.IsNullOrEmpty(destCatalogPassword)) { Console.WriteLine("Parameters must be specified for the Rule App name as well as the URI, username, and password for both the source and destination irCatalog instances."); return(1); } else { RuleApplicationDef sourceRuleAppDef = null; try { CatalogRuleApplicationReference sourceRuleApp; if (string.IsNullOrEmpty(label)) { sourceRuleApp = new CatalogRuleApplicationReference(sourceCatalogUrl, ruleAppName, sourceCatalogUsername, sourceCatalogPassword); } else { sourceRuleApp = new CatalogRuleApplicationReference(sourceCatalogUrl, ruleAppName, sourceCatalogUsername, sourceCatalogPassword, label); } sourceRuleAppDef = sourceRuleApp.GetRuleApplicationDef(); } catch (Exception ex) { Console.WriteLine("Error retrieving source Rule App: " + ex.Message); return(1); } try { if (sourceRuleAppDef != null) { var destCatCon = new RuleCatalogConnection(new Uri(destCatalogUrl), TimeSpan.FromSeconds(60), destCatalogUsername, destCatalogPassword); var promotedDef = destCatCon.PromoteRuleApplication(sourceRuleAppDef, comment); Console.WriteLine("Success!"); return(0); } else { Console.WriteLine("Source Rule App was unable to be retrieved."); return(1); } } catch (Exception ex) { Console.WriteLine("Error promoting Rule App: " + ex.Message); return(1); } } }
static int Main(string[] args) { bool showHelp = false; string TestSuiteFilePath = null; //Option 1 string RuleAppFilePath = null; //Option 2 string CatalogUri = null; string CatalogUsername = null; string CatalogPassword = null; string CatalogRuleAppName = null; string CatalogRuleAppLabel = null; string CatalogRuleAppRevision = null; var clParams = new OptionSet { { "h|help", "Display Help.", k => showHelp = true }, { "t|TestSuitePath=", "The path to the .testsuite file to run.", p => TestSuiteFilePath = p }, //Option 1 { "r|RuleAppPath=", "Path to the Rule Application to be compiled.", p => RuleAppFilePath = p }, //Option 2 { "c|CatUri=", "Web URI for the IrCatalog Service endpoint.", p => CatalogUri = p }, { "u|CatUsername="******"IrCatalog Username for authentication.", p => CatalogUsername = p }, { "p|CatPassword="******"IrCatalog Password for authentication.", p => CatalogPassword = p }, { "n|CatRuleAppName=", "Name of the Rule Application.", p => CatalogRuleAppName = p }, { "l|CatLabel=", "Label of the Rule Application to retrieve.", p => CatalogRuleAppLabel = p }, { "v|CatRevision=", "Revision of the Rule Application to retrieve.", p => CatalogRuleAppRevision = p }, }; try { clParams.Parse(args); } catch (OptionException e) { Console.Write("Failed parsing execution parameters: " + e.Message); showHelp = true; } if (showHelp) { ShowHelp(clParams); return(2); } else if (string.IsNullOrEmpty(TestSuiteFilePath)) { Console.WriteLine("Parameter must be specified for the TestSuitePath."); return(2); } else if (!string.IsNullOrEmpty(RuleAppFilePath)) { try { if (File.Exists(RuleAppFilePath)) { Console.WriteLine("Using Rule App " + RuleAppFilePath); } else { Console.WriteLine("ERROR: Rule App file not found at " + RuleAppFilePath); return(2); } var result = RunTestSuite(new FileSystemRuleApplicationReference(RuleAppFilePath), TestSuiteFilePath); return(result); } catch (IntegrationException ie) { Console.WriteLine("Error creating reference to file-based Rule App: " + ie.Message); //Rule App file not found return(2); } } else if (!string.IsNullOrEmpty(CatalogUri) && !string.IsNullOrEmpty(CatalogUsername) && !string.IsNullOrEmpty(CatalogPassword) && !string.IsNullOrEmpty(CatalogRuleAppName)) { try { RuleApplicationReference ruleApp; int ruleAppRevision; if (!string.IsNullOrEmpty(CatalogRuleAppLabel)) { ruleApp = new CatalogRuleApplicationReference(CatalogUri, CatalogRuleAppName, CatalogUsername, CatalogPassword, CatalogRuleAppLabel); Console.WriteLine($"Loading Rule App {CatalogRuleAppName} with Label {CatalogRuleAppLabel} from {CatalogUri}"); } else if (!string.IsNullOrEmpty(CatalogRuleAppRevision) && int.TryParse(CatalogRuleAppRevision, out ruleAppRevision)) { ruleApp = new CatalogRuleApplicationReference(CatalogUri, CatalogRuleAppName, CatalogUsername, CatalogPassword, ruleAppRevision); Console.WriteLine($"Loading Rule App {CatalogRuleAppName} with Revision {ruleAppRevision} from {CatalogUri}"); } else { ruleApp = new CatalogRuleApplicationReference(CatalogUri, CatalogRuleAppName, CatalogUsername, CatalogPassword); Console.WriteLine($"Loading Rule App {CatalogRuleAppName} from {CatalogUri}"); } var result = RunTestSuite(ruleApp, TestSuiteFilePath); return(result); } catch (Exception ex) { Console.WriteLine("Error creating reference to Catalog-based Rule App: " + ex.Message); return(2); } } else { Console.WriteLine("You must provide either RuleAppPath or all of CatUri, CatUsername, CatPassword, and CatRuleAppName (with optional CatLabel or CatRevision)"); return(2); } }