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); } } } }
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); } } } }
/// <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); } } } } }
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); } } }