public static RuleElementDef GetLanguageRuleElementDef(RuleElementDef ruleDef)
 {
     if (ruleDef is LanguageRuleDef)
     {
         return(((LanguageRuleDef)ruleDef).RuleElement);
     }
     return(null);
 }
        public CatalogSearchResultViewModel(DefInfo ruleAppDef, RuleSetDef ruleSetDef, string matchedValue, CatalogSearchSettings settings, RuleElementDef ruleDef = null)
        {
            RuleAppName  = ruleAppDef.Name + " v" + ruleAppDef.PublicRevision;
            RuleSetName  = ruleSetDef.AuthoringElementPath;
            MatchedValue = matchedValue;
            //TODO: The way we're navigating to the item does not work properly - add this back in once that works
            IsInCurrentRuleApp = false;// settings.CurrentRuleApp != null && ruleAppDef.Key.Guid == settings.CurrentRuleApp.Value;

            RuleSetDef = ruleSetDef;

            if (ruleDef != null)
            {
                RuleElementName = ruleDef.AuthoringElementPath;
                RuleDef         = ruleDef;
            }
        }
        public static RuleElementDefCollection GetRuleElementDefCollection(RuleElementDef parentDef)
        {
            RuleElementDefCollection ruleDefs = null;

            if (parentDef is RuleSetDef)
            {
                ruleDefs = ((RuleSetDef)parentDef).Rules;
            }
            else if (parentDef is SimpleRuleDef)
            {
                ruleDefs = ((SimpleRuleDef)parentDef).SubRules;
            }
            else if (parentDef is ExclusiveRuleDef)
            {
                ruleDefs = ((ExclusiveRuleDef)parentDef).Conditions;
            }

            return(ruleDefs);
        }
        public static RuleElementDef GetRuleElementDef(string ruleElementName, RuleElementDef parentDef)
        {
            RuleElementDef ruleDef = null;

            if (parentDef is LanguageRuleDef)
            {
                if (((LanguageRuleDef)parentDef).RuleElement.Name == ruleElementName)
                {
                    ruleDef = ((LanguageRuleDef)parentDef).RuleElement;
                }
            }
            else
            {
                RuleElementDefCollection ruleDefs = GetRuleElementDefCollection(parentDef);
                ruleDef = (RuleElementDef)ruleDefs[ruleElementName];
            }

            return(ruleDef);
        }
        public static void AppendToExecutionFlowXml(RuleElementDef def, XmlTextWriter xw)
        {
            if (def != null && def.IsActive)
            {
                if (def is ExecuteActionDef)
                {
                    AppendExecuteRuleSetTarget(def as ExecuteActionDef, xw);
                }
                else if (def is ExecuteMemberRuleSetActionDef)
                {
                    AppendExecuteMemberRuleSetTarget(def as ExecuteMemberRuleSetActionDef, xw);
                }
                else if (def is ExclusiveRuleDef)
                {
                    foreach (SimpleRuleDef simpleRuleDef in ((ExclusiveRuleDef)def).Conditions)
                    {
                        //xw.WriteRaw("<Collection4>");
                        AppendToExecutionFlowXml(simpleRuleDef, xw);
                        //xw.WriteRaw("</Collection4>");
                    }
                    foreach (RuleElementDef ruleDef in ((ExclusiveRuleDef)def).DefaultSubRules)
                    {
                        //xw.WriteRaw("<Collection6>");
                        AppendToExecutionFlowXml(ruleDef, xw);
                        //xw.WriteRaw("</Collection6>");
                    }
                }
                else if (def is DecisionTableDef)
                {
                    DecisionTableDef dtDef = def as DecisionTableDef;
                    //xw.WriteStartElement(dtDef.Name);
                    foreach (ActionDimensionDef aDef in dtDef.Actions)
                    {
                        //xw.WriteRaw("<" + aDef.DisplayName + ">");
                        foreach (ActionValueDef actionDef in aDef.ActionValues)
                        {
                            //xw.WriteRaw("<Collection>");
                            AppendToExecutionFlowXml(actionDef.RuleElement as RuleElementDef, xw);
                            //xw.WriteRaw("</Collection>");
                        }
                        //xw.WriteRaw("</" + aDef.DisplayName + ">");
                    }
                    //xw.WriteEndElement();
                }
                else if (def is IContainsRuleElements)
                {
                    foreach (RuleElementDef ruleElementDef in ((IContainsRuleElements)def).RuleElements)
                    {
                        //xw.WriteRaw("<Collection2>");
                        AppendToExecutionFlowXml(ruleElementDef, xw);
                        //xw.WriteRaw("</Collection2>");
                    }
                }
                else if (def is LanguageRuleDef)
                {
                    AppendToExecutionFlowXml(((LanguageRuleDef)def).RuleElement, xw);
                }
                //else if (def is FireNotificationActionDef)
                //{
                //    if (((FireNotificationActionDef)def).Name.Length > 0)
                //    {
                //        xw.WriteStartElement(((FireNotificationActionDef)def).Name);
                //        xw.WriteEndElement();
                //    }
                //    //AppendToExecutionFlowXml(((FireNotificationActionDef)def)., xw);

                //}
                //else if (def is AddCollectionMemberActionDef)
                //{
                //    if (((AddCollectionMemberActionDef)def).Name.Length > 0)
                //    {
                //        xw.WriteStartElement(((AddCollectionMemberActionDef)def).Name);
                //        xw.WriteEndElement();
                //    }
                //    //AppendToExecutionFlowXml(((FireNotificationActionDef)def)., xw);

                //}
                //else if (def is SetValueActionDef)
                //{
                //    if (((SetValueActionDef)def).Name.Length > 0)
                //    {
                //        xw.WriteStartElement(((SetValueActionDef)def).Name);
                //        xw.WriteEndElement();
                //    }
                //    //AppendToExecutionFlowXml(((FireNotificationActionDef)def)., xw);

                //}
                else
                {
                    //Console.WriteLine(def.ToString());
                }
            }
        }