private static void CollectAllDefs(this RuleRepositoryDefBase parentDef, HashSet <RuleRepositoryDefBase> items)
        {
            if (items.Add(parentDef))
            {
                foreach (RuleRepositoryDefBase def in parentDef.GetAllRootItems())
                {
                    def.CollectAllDefs(items);
                }

                IContainsVocabulary containsVocabulary = parentDef as IContainsVocabulary;
                VocabularyDef       vocab = containsVocabulary?.Vocabulary;
                if (vocab != null)
                {
                    items.Add(vocab);
                }

                var languageRuleDef = parentDef as LanguageRuleDef;
                if (languageRuleDef?.RuleElement != null)
                {
                    languageRuleDef.RuleElement.CollectAllDefs(items);
                }

                foreach (RuleRepositoryDefCollection defs in parentDef.GetAllChildCollections())
                {
                    foreach (RuleRepositoryDefBase def in defs)
                    {
                        def.CollectAllDefs(items);
                    }
                }
            }
        }
Пример #2
0
 private string _importHash = ""; //prevents duplicate import
 internal void ProcessChildren(RuleRepositoryDefBase child, ObservableCollection <Artifact> list, string key)
 {
     if (_importHash.Contains(child.Name) == false)
     {
         _importHash = _importHash + child.Name;  //update the hash
         //Console.WriteLine(child.Name);
         if (String.IsNullOrEmpty(key) == false)
         {
             if (IsSafeTemplateDef(child)) //some vocab definitions are not safe to stamp with an attribute
             {
                 StampAttribute(child, key);
             }
         }
         Artifact a = new Artifact();
         a.DefBase = child;
         list?.Add(a);
         var collquery = from childcollections in child.GetAllChildCollections()
                         select childcollections;
         foreach (RuleRepositoryDefCollection defcollection in collquery)
         {
             var defquery = from RuleRepositoryDefBase items in defcollection select items;
             foreach (var def in defquery)
             {
                 ProcessChildren(def, list, key);
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Deep search of a ruleapp for a specific def.  This code may not be suitable for proper looping and stamping
        /// of defs because the AsEnumerable misses some artifacts.  This will remain standalone for specific artifacts
        /// until it's decided that the ProcessChildren and this code can be refactored safely.  This code has the
        /// advantage of not requireing the member variable to hash duplicate hits and remove them from the
        /// collection.
        /// </summary>
        public RuleRepositoryDefBase FindDefDeep(RuleApplicationDef ruleapp, string guid)
        {
            RuleRepositoryDefBase found = null;

            if ((ruleapp != null) && (String.IsNullOrEmpty(guid) == false))
            {
                foreach (RuleRepositoryDefBase def in ruleapp.AsEnumerable())
                {
                    if (def.Guid.ToString().Equals(guid))
                    {
                        //Console.WriteLine("Found....");
                        found = def;
                        break;
                    }
                }
                //If we did not get a hit, let's look at category
                if (found == null)
                {
                    foreach (RuleRepositoryDefBase def in ruleapp.Categories)
                    {
                        if (def.Guid.ToString().Equals(guid))
                        {
                            //Console.WriteLine("Found....");
                            found = def;
                            break;
                        }
                    }
                }
            }
            return(found);
        }
        public static IEnumerable <string> AppendDefDescriptions(this RuleRepositoryDefBase def)
        {
            var className = def.GetType().GetDefTypeFullName();

            yield return(className);

            if (def is FieldDef && !(def is FieldDefInfo))
            {
                var typed = (FieldDef)def;
                if (typed.IsCollection)
                {
                    className += " (Collection)";
                }

                className += $" ({typed.DataType})";

                if (typed.IsAnEntityDataType)
                {
                    if (typed.IsMarkedAsParentContext())
                    {
                        className += $" ({"Parent Context"})";
                    }
                }
                yield return(className);
            }
            if (def is TemplateValueDef)
            {
                var templateValueDef = (TemplateValueDef)def;
                var compiledTypeName = templateValueDef.CompiledTypeName;
                var justClassName    = compiledTypeName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
                var trailingName     = justClassName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                yield return($"{className}.{trailingName}");
            }
        }
        public static List <RuleRepositoryDefBase> GetAllDefs(this RuleRepositoryDefBase parentDef)
        {
            var items = new HashSet <RuleRepositoryDefBase>();

            parentDef.CollectAllDefs(items);
            return(items.ToList());
        }
Пример #6
0
        /// <summary>
        /// This enforces the policy of importing only times that are tagged with a category.  It will include parents
        /// even if they are not tagged with a category.  This expects that parents do not exist in the existing
        /// Rule Application so it's not a true "merge" capability.
        /// </summary>
        internal void RemoveNonCategoryDefsFromChildren(RuleRepositoryDefBase child, string cat)
        {
            if (_importHash.Contains(child.Name) == false)
            {
                _importHash = _importHash + child.Name;  //update the hash

                if ((child.HasChildCollectionChildren == false) && (child.AssignedCategories.Contains(cat) == false))
                {
                    //only remove if it's the lowest node
                    child.ThisRuleSet.Rules.Remove(child);
                }
                else if (child.HasChildCollectionChildren == true)
                {
                    var collquery = from childcollections in child.GetAllChildCollections()
                                    select childcollections;
                    foreach (RuleRepositoryDefCollection defcollection in collquery)
                    {
                        var defquery = from RuleRepositoryDefBase items in defcollection select items;
                        foreach (var def in defquery.ToList <RuleRepositoryDefBase>())
                        {
                            RemoveNonCategoryDefsFromChildren(def, cat);
                        }
                    }
                }
            }
        }
Пример #7
0
 internal void StampAttribute(RuleRepositoryDefBase def, string key)
 {
     Debug.WriteLine(def.Name);
     //if for whatever reason it's already been stamped
     if (IsToolkitMatch(def, key) == false)
     {
         def.Attributes.Default.Add("Toolkit", key);
     }
 }
Пример #8
0
        public void TestDeepFindDef()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            RuleRepositoryDefBase found = h.FindDefDeep(dest, "ece7c19a-f8c1-4212-9cc2-90f6dcf837cf");

            Assert.NotNull(found);
        }
 public static RuleSetDef GetParentRulesetDef(this RuleRepositoryDefBase ruleDef)
 {
     if (ruleDef is RuleSetDef)
     {
         return((RuleSetDef)ruleDef);
     }
     if (ruleDef.Parent == null)
     {
         return(null);
     }
     return(GetParentRulesetDef(ruleDef.Parent));
 }
Пример #10
0
        /// <summary>
        /// Check if a specific ruleapp matches a key hash (Name,Revision,GUID).
        /// </summary>
        public bool IsToolkitMatch(RuleRepositoryDefBase def, string key)
        {
            var isMatch    = false;
            var attributes =
                from XmlSerializableStringDictionary.XmlSerializableStringDictionaryItem att in def.Attributes.Default
                where att.Value == key
                select att;

            if (attributes.Any())
            {
                isMatch = true;
            }
            return(isMatch);
        }
Пример #11
0
        public bool IsToolkit(RuleRepositoryDefBase def)
        {
            bool   result = false;
            Helper h      = new Helper();

            foreach (ToolkitContents toolkit in _toolkits)
            {
                if (h.IsToolkitMatch(def, toolkit.GetKey()))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Пример #12
0
        /// <summary>
        /// It's ok to add attributes to TemplateDefs but not their children.
        /// </summary>
        internal bool IsSafeTemplateDef(RuleRepositoryDefBase child)
        {
            bool isSafe = true;

            if (child.GetType().ToString().Contains("InRule.Repository.Vocabulary"))
            {
                string prefix    = "InRule.Repository.Vocabulary.";
                string longname  = child.GetType().ToString();
                string shortname = longname.Substring(prefix.Length, longname.Length - prefix.Length);
                if (child.GetType() != typeof(TemplateDef))
                {
                    isSafe = false;
                }
            }
            return(isSafe);
        }
Пример #13
0
        private UndoHistoryItem PopulateUndoHistoryItem(RuleRepositoryDefBase x, Action <UndoHistoryItem> undoAction)
        {
            var idx = -1;

            if (x.ParentCollection != null)
            {
                idx = x.ParentCollection.IndexOf(x.Guid);
            }

            return(new UndoHistoryItem
            {
                DefToUndo = x.CopyWithSameGuids(),
                ParentGuid = x.Parent.Guid,
                OriginalIndex = idx,
                UndoAction = undoAction
            });
        }
Пример #14
0
        internal void IgnoreExistingDef(RuleRepositoryDefBase child, string cat, RuleApplicationDef dest)
        {
            //does this def exist in the destination, keep going deep
            if ((this.FindDefDeep(dest, child.Guid.ToString()) != null))
            {
                if (child.HasChildCollectionChildren == false)
                {
                    Debug.WriteLine("The child exists in the ruleapp and has no children -- Do nothing.");
                }
                else
                {
                    //traverse the children and add only those that don't exist
                    var collquery = from childcollections in child.GetAllChildCollections()
                                    select childcollections;
                    foreach (RuleRepositoryDefCollection defcollection in collquery)
                    {
                        var defquery = from RuleRepositoryDefBase items in defcollection select items;
                        foreach (var def in defquery.ToList <RuleRepositoryDefBase>())
                        {
                            IgnoreExistingDef(def, cat, dest);
                        }
                    }
                }
            }
            else
            {
                if (child.AssignedCategories.Contains(cat))
                {
                    RuleRepositoryDefBase destParent = this.FindDefDeep(dest, child.Parent.Guid.ToString());
                    RuleRepositoryDefBase copy       = child.CopyWithSameGuids();
                    child.SetParent(null);
                    if (destParent.AuthoringElementTypeName != "Rule Set")
                    {
                        SimpleRuleDef simpleParent = (SimpleRuleDef)destParent;
                        simpleParent.SubRules.Add(child);
                    }
                    else
                    {
                        destParent.ThisRuleSet.Rules.Add(child);
                    }

                    //Debug.WriteLine("----Just add it --- " + child.Name + " Parent in dest: " + destParent.Name);
                }
            }
        }
        public static string GetDefTypeCountSummary(this RuleRepositoryDefBase parentDef)
        {
            var defItems = parentDef.GetAllDefs();
            var items    = new List <string>();

            defItems.ForEach(r => items.AddRange(r.AppendDefDescriptions()));

            var results = from p in items
                          group p by p into g
                          select new { TypeDescription = g.Key, Count = g.Count() };



            var ordered = results.OrderBy(g => g.TypeDescription);

            return(string.Join(Environment.NewLine,
                               ordered.Select(t => t.TypeDescription.PadRight(50) + t.Count.ToString("#,##0").PadLeft(15))));
        }
Пример #16
0
        public void TestGetDef()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);
            EntityDef          entity = new EntityDef();

            entity.Name = "HelloWorld";
            source.Entities.Add(entity);
            h.ImportToolkit(source, dest);
            ToolkitsContainer tc = new ToolkitsContainer();

            tc.Toolkits = h.GetToolkits(dest);
            RuleRepositoryDefBase def = tc.GetDef(entity.Guid);

            Assert.IsNotNull(def);
            def = tc.GetDef(Guid.NewGuid());
            Assert.IsNull(def); //should return null becuase it's not there
        }
Пример #17
0
        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);
        }
Пример #18
0
        internal void AddArtifactToCount(RuleRepositoryDefBase def, ObservableCollection <ArtifactCount> summary)
        {
            //Console.WriteLine(def.AuthoringElementTypeName);
            bool found = false;

            foreach (ArtifactCount item in summary)
            {
                if (item.ArtifcatType == def.AuthoringElementTypeName)
                {
                    item.Count++;
                    found = true;
                    break;
                }
            }
            if (found == false)
            {
                ArtifactCount count = new ArtifactCount();
                count.ArtifcatType = def.AuthoringElementTypeName;
                count.Count++;
                summary.Add(count);
            }
        }
Пример #19
0
 public UnusedFieldReference(RuleRepositoryDefBase innerDef)
 {
     this.InnerDef = innerDef;
 }
Пример #20
0
        public ErrorForm(Exception ex, RuleRepositoryDefBase def)
        {
            InitializeComponent();

            errorTextBox.Text = String.Format("ERROR for def: {0} ({1}){2}{2}{3}", def.Name, def.GetType().ToString(), Environment.NewLine, ex.ToString());
        }