Beispiel #1
0
 public Version(string name, int iteration, AddElementDelegate addAttribute)
 {
     this.name         = name;
     this.iteration    = iteration;
     this.addAttribute = addAttribute;
 }
Beispiel #2
0
        public static void IHasContainersTemplateDealer(ElementBase container, IEnumerable <ElementBase> containerElements, IEnumerable <ElementBase> elementsCollection, JObject template, AddElementDelegate addElementFunc, Func <ElementBase, string, IEnumerable <string> > nameListFunc)
        {
            //Searching elements that fixed the template
            List <string> nameList = nameListFunc(container, template.Value <string> ("ElementName")).ToList();
            //Searching elements that contains the definitions
            var elementsDefinitionCollection = SearchingElementsDefinitionByPath(elementsCollection, (container as ISupportDefinitionRefElement).DefinitionRef);

            ElementBase elementDefinition = elementsDefinitionCollection.Where(ele => Regex.IsMatch(ele.Path + "\\" + ele.ElementName, template.Value <string> ("DEFINITION"), RegexOptions.Multiline)).FirstOrDefault();
            string      elementType       = elementDefinition.ElementType;

            foreach (var subJToken in ElementTypeJDict)
            {
                if ((subJToken.Value as JArray).Contains(elementType))
                {
                    elementType = subJToken.Key;
                    break;
                }
            }
            foreach (var name in nameList)
            {
                var containerElement = containerElements.Where(ele => ele.ElementName.Equals(name)).FirstOrDefault();
                if (containerElement == null)
                {
                    //try to add an element

                    var ele         = container.NewElement(elementType);
                    var elementBase = new ElementBase()
                    {
                        ArxmlElement = ele
                    };
                    (elementBase as ISupportDefinitionRefElement).DefinitionRef  = elementDefinition.Path + "\\" + elementDefinition.ElementName;
                    (elementBase as ISupportDefinitionRefElement).DefinitionType = elementDefinition.ElementType;
                    addElementFunc(elementBase);
                    containerElement = containerElements.Where(ele => ele.ElementName.Equals(name)).FirstOrDefault();
                }
                else
                {
                    (containerElement as ISupportDefinitionRefElement).DefinitionRef  = elementDefinition.Path + "\\" + elementDefinition.ElementName;
                    (containerElement as ISupportDefinitionRefElement).DefinitionType = elementDefinition.ElementType;
                }
            }
        }