public CatalogSearchSettings(RuleCatalogConnection connection, Guid?currentRuleApp)
 {
     CatalogServiceUrl = connection.ServiceUri;
     CatalogUsername   = connection.User?.Name;
     CatalogPassword   = connection.User?.Password;
     CurrentRuleApp    = currentRuleApp;
 }
        public static RuleApplicationDef GetRuleApplicationDef(RuleCatalogConnection conn, string ruleAppName, string labelName)
        {
            RuleAppRef appRef = conn.GetRuleAppRef(ruleAppName, labelName);

            return(conn.GetSpecificRuleAppRevision(appRef.Guid, appRef.PublicRevision));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
                }
            }
        }