예제 #1
0
        public static CIMObject Clone(this CIMObject cimObject)
        {
            var clone        = System.Activator.CreateInstance("ArcGIS.Core", cimObject.GetType().ToString()).Unwrap() as CIMObject;
            var stringReader = new StringReader(cimObject.ToXml());
            var xmlReader    = new XmlTextReader(stringReader);

            //xmlReader.MoveToContent();
            clone.ReadXml(xmlReader);
            xmlReader.Dispose();
            return(clone);
        }
예제 #2
0
 public void StartDocument(string filePath)
 {
     currentElement   = null;
     currentAttribute = null;
     if (model == null)
     {
         model            = new CIMModel();
         model.SourcePath = filePath;
     }
     inLevel = Level.Root;
 }
예제 #3
0
 public override void StartDocument()
 {
     currentElement   = null;
     currentAttribute = null;
     embeddedElement  = null;
     if (model == null)
     {
         model            = new CIMModel();
         model.SourcePath = this.filePath;
     }
     childrenOf = new Dictionary <string, Stack <CIMObject> >();
     inLevel    = Level.Root;
 }
예제 #4
0
        public void StartElement(string localName, string qName, SortedList <string, string> atts)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(qName, rdfRootQ, true) == 0)
            {
                //// rdf:RDF element - extract attributes
                if ((atts != null) && (atts.Count > 0))
                {
                    for (int i = 0; i < atts.Count; i++)
                    {
                        model.AddRDFAttribute(atts.ElementAt(i).Key, atts.ElementAt(i).Value);
                    }
                }
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                //// start of new main element
                if (currentElement == null)
                {
                    inLevel        = Level.Element;
                    currentElement = new CIMObject(model.ModelContext, type);
                    string id = TryReadRDFIdAttribute(atts);
                    if (id != null)
                    {
                        currentElement.ID = id;
                    }
                    currentElement.CIMType         = type;
                    currentElement.NamespaceString = namespaceName;
                }
                //// new attribute
                else
                {
                    inLevel          = Level.Property;
                    currentAttribute = new ObjectAttribute(model.ModelContext, type);

                    currentAttribute.FullName        = type;
                    currentAttribute.NamespaceString = namespaceName;

                    ReadAndProcessAttributeValue(currentAttribute, atts);
                }
            }
        }
예제 #5
0
        //// If some object in model references the unexisting parent object by some
        //// of it's properties, the "ReferenceToUnexistingElement" validation message is reported.
        private void AddValidationMessageAboutReferenceToUnexistingElement(CIMObject childObject, ObjectAttribute invalidProperty, string unexistingParentId)
        {
            //if (model.ValidationDataFromParsing == null)
            //{
            //    model.ValidationDataFromParsing = new ValidationData(model);
            //    model.ValidationDataFromParsing.StartTime = DateTime.Now;
            //}

            //if (childObject != null)
            //{
            //    //// add validation message to model and attache it to the problematic attribute
            //    invalidProperty.AddValidationMessage((model.ValidationDataFromParsing.AddOrUpdateMessage(ValidationMessageType.ReferenceToUnexistingElement, this.FilePath,
            //                                            childObject.CIMType, invalidProperty.FullName, unexistingParentId, childObject.ID)).ID);
            //}
            //model.ValidationDataFromParsing.EndTime = DateTime.Now;
        }
예제 #6
0
        public static void LoadCIMObject(ref CIMObject cimObject, CIMModelContext cimModelContext, string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                bool     success;
                TimeSpan durationOfParsing;

                CIMRDFObjectXMLHandler handler = new CIMRDFObjectXMLHandler();
                handler.CimModelContext = cimModelContext;
                //// call parsing:
                handler = (CIMRDFObjectXMLHandler)XMLParsingManager.DoParseText(handler, XMLParsingManager.ParsingFileTypes.CIMModelFile, text, out success, out durationOfParsing);

                if (success)
                {
                    cimObject = handler.Object;
                }
            }
        }
예제 #7
0
        public void EndElement(string localName, string qName)
        {
            string type = localName;

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                //// end of main element
                if (inLevel == Level.Element)
                {
                    inLevel = Level.Root;
                    if (currentElement != null)
                    {
                        if (model.GetObjectByID(currentElement.ID) == null)
                        {
                            model.InsertObjectInModelMap(currentElement);
                        }

                        currentElement = null;
                    }
                }
                //// end of an attribute (property)
                else if (inLevel == Level.Property)
                {
                    inLevel = Level.Element;
                    content = content.Trim();
                    if (!string.IsNullOrEmpty(content))
                    {
                        if (currentAttribute != null)
                        {
                            //// if attribute value wasn't set as the reference, we read the text content and set it in value
                            if (string.IsNullOrEmpty(currentAttribute.Value))
                            {
                                currentAttribute.Value = content;
                            }
                        }
                        content = string.Empty;
                    }

                    AddAttributeToCurrentElement();
                }
            }
        }
        public override void StartElement(string localName, string qName, SortedList <string, string> attributes, int lineNumber = 0, int columnNumber = 0)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                string id = TryReadRDFIdAttribute(attributes);
                //// start of new main element
                if (currentElement == null)
                {
                    if (id != null)
                    {
                        inLevel           = Level.Element;
                        currentElement    = new CIMObject(cimModelContext, type);
                        currentElement.ID = id;
                        currentElement.NamespaceString   = namespaceName;
                        currentElement.SourceStartLine   = lineNumber;
                        currentElement.SourceStartColumn = columnNumber;
                    }
                }
                //// start of new subelement (attribute or embedded element)
                else
                {
                    //// new attribute
                    inLevel          = Level.Property;
                    currentAttribute = new ObjectAttribute(cimModelContext, type);
                    currentAttribute.NamespaceString = namespaceName;

                    ReadAndProcessAttributeValue(currentAttribute, attributes);
                }
            }
        }
예제 #9
0
        public override void StartElement(string localName, string qName, SortedList <string, string> attributes, int lineNumber = 0, int columnNumber = 0)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(qName, rdfRootQ, true) == 0)
            {
                //// rdf:RDF element - extract attributes
                if ((attributes != null) && (attributes.Count > 0))
                {
                    foreach (string attrName in attributes.Keys)
                    {
                        if (!attrName.StartsWith(xmlnsPrefix, true, null))
                        {
                            model.AddRDFAttribute(attrName, attributes[attrName]);
                        }
                    }
                }
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                string id = TryReadRDFIdAttribute(attributes);
                //// start of new main element
                if (currentElement == null)
                {
                    if (id != null)
                    {
                        inLevel           = Level.Element;
                        currentElement    = new CIMObject(model.ModelContext, type);
                        currentElement.ID = id;
                        currentElement.NamespaceString   = namespaceName;
                        currentElement.SourceStartLine   = lineNumber;
                        currentElement.SourceStartColumn = columnNumber;
                    }
                }
                //// start of new subelement (attribute or embedded element)
                else
                {
                    //// if rdf:ID is defined -> it is new embedded element
                    if (id != null)
                    {
                        inLevel            = Level.EmbeddedElement;
                        embeddedElement    = new CIMObject(model.ModelContext, type);
                        embeddedElement.ID = id;
                        embeddedElement.NamespaceString     = namespaceName;
                        embeddedElement.SourceStartLine     = lineNumber;
                        embeddedElement.SourceStartColumn   = columnNumber;
                        embeddedElement.IsDefinedAsEmbedded = true;

                        if (string.IsNullOrEmpty(embeddedListName))
                        {
                            embeddedListName = currentAttribute.FullName;
                            if (!string.IsNullOrEmpty(currentAttribute.NamespaceString))
                            {
                                embeddedListName = currentAttribute.NamespacePrintString + embeddedListName;
                            }
                        }
                        currentAttribute = null;
                        AddEmbeddedChildToCurrentElement();
                    }
                    //// new attribute
                    else
                    {
                        inLevel          = Level.Property;
                        currentAttribute = new ObjectAttribute(model.ModelContext, type);
                        currentAttribute.NamespaceString = namespaceName;

                        ReadAndProcessAttributeValue(currentAttribute, attributes);
                    }
                }
            }
        }
예제 #10
0
        public override void EndElement(string localName, string qName, int lineNumber = 0, int columnNumber = 0)
        {
            string type = localName;

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                //// end of main element
                if (inLevel == Level.Element)
                {
                    inLevel = Level.Root;
                    if (currentElement != null)
                    {
                        currentElement.SourceEndLine   = lineNumber;
                        currentElement.SourceEndColumn = columnNumber + qName.Length + 3;
                        if (model.GetObjectByID(currentElement.ID) == null)
                        {
                            model.InsertObjectInModelMap(currentElement);
                        }
                        else
                        {
                            AddValidationMessageAboutDuplicateRdfId();
                        }
                        currentElement = null;
                    }
                }
                //// end of embededList of elements
                else if (inLevel == Level.EmbeddedList)
                {
                    inLevel          = Level.Element;
                    embeddedListName = string.Empty;
                }
                //// end of embeded element
                else if (inLevel == Level.EmbeddedElement)
                {
                    inLevel = Level.EmbeddedList;
                    if (embeddedElement != null)
                    {
                        embeddedElement.SourceEndLine   = lineNumber;
                        embeddedElement.SourceEndColumn = columnNumber + qName.Length + 3;
                        if (model.GetObjectByID(embeddedElement.ID) == null)
                        {
                            model.InsertObjectInModelMap(embeddedElement);
                        }
                        else
                        {
                            AddValidationMessageAboutDuplicateRdfId();
                        }
                        embeddedElement = null;
                    }
                }
                //// end of an attribute (property)
                else if (inLevel == Level.Property)
                {
                    if (embeddedElement == null)
                    {
                        inLevel = Level.Element;
                    }
                    else
                    {
                        inLevel = Level.EmbeddedElement;
                    }

                    content = content.Trim();
                    if (!string.IsNullOrEmpty(content))
                    {
                        if (currentAttribute != null)
                        {
                            //// if attribute value wasn't set as the reference, we read the text content as set it in value
                            if (string.IsNullOrEmpty(currentAttribute.Value))
                            {
                                currentAttribute.Value = content;
                                if (string.IsNullOrEmpty(currentAttribute.Value))
                                {
                                    AddValidationMessageAboutEmptyValueOfProperty();
                                }
                            }
                        }
                        content = string.Empty;
                    }

                    AddAttributeToCurrentElement();
                }
            }
        }
 public override void StartDocument()
 {
     currentElement   = null;
     currentAttribute = null;
     inLevel          = Level.Root;
 }
예제 #12
0
        private void FindAttributeDifferences()
        {
            modified = new List <CIMEntityDifference>();
            if (updated != null)
            {
                CIMModelContext context = new CIMModelContext();
                foreach (KeyValuePair <CIMEntity, CIMEntity> pair in updated)
                {
                    CIMObject oldVersion = null;
                    CIMModelLoader.LoadCIMObject(ref oldVersion, context, string.Format("{0}{1}\n</rdf:RDF>", beforeModel.Header, pair.Key.Source));
                    CIMObject newVersion = null;
                    CIMModelLoader.LoadCIMObject(ref newVersion, context, string.Format("{0}{1}\n</rdf:RDF>", afterModel.Header, pair.Value.Source));

                    if ((oldVersion != null) && (newVersion != null))
                    {
                        CIMEntityDifference diff = new CIMEntityDifference();
                        diff.RdfId = oldVersion.ID;
                        //// TODO uporediti atribute u oba objekta i spakovati ih u CIMEntityDifference instancu
                        //PROVERA ZA OLD
                        if (oldVersion.HasAttributes)
                        {
                            foreach (ObjectAttribute oldAtt in oldVersion.MyAttributesAsList)
                            {
                                if (string.Compare(oldAtt.FullName, CIMConstants.AttributeNameIdentifiedObjectMRID) == 0)
                                {
                                    //postavi mrid
                                    diff.MRID = oldAtt.Value;
                                }

                                //uzmem sve sa istim imenom - ako nema dodajem ako ima proveravam
                                if (newVersion.GetAttributeList(oldAtt.FullName) != null)
                                {
                                    if (newVersion.GetAttributeList(oldAtt.FullName).Count == 0)
                                    {
                                        //dodajem
                                        diff.AddAttribute(oldAtt, null);
                                    }
                                    else
                                    {
                                        bool found = false;
                                        if (newVersion.HasAttributes)
                                        {
                                            foreach (ObjectAttribute newAtt in newVersion.GetAttributeList(oldAtt.FullName))
                                            {
                                                //proveravam da li se javlja ista vrednost
                                                if (string.Compare(oldAtt.Value, newAtt.Value) == 0)
                                                {
                                                    //ako se javlja dodajem ga kao nadjen i ne treba da se pojavi
                                                    found = true;
                                                    break;
                                                }
                                            }
                                        }
                                        //ako je found false, znaci da je dodat
                                        if (!found)
                                        {
                                            diff.AddAttribute(oldAtt, null);
                                        }
                                    }
                                }
                                else
                                {
                                    diff.AddAttribute(oldAtt, null);
                                }
                            }
                        }
                        //PROVERA ZA NEW
                        if (newVersion.HasAttributes)
                        {
                            if (newVersion.MyAttributesAsList != null)
                            {
                                foreach (ObjectAttribute newAtt in newVersion.MyAttributesAsList)
                                {
                                    if (string.Compare(newAtt.FullName, CIMConstants.AttributeNameIdentifiedObjectMRID) == 0)
                                    {
                                        //postavi mrid
                                        if (string.IsNullOrEmpty(diff.MRID))
                                        {
                                            diff.MRID = newAtt.Value;
                                        }
                                    }

                                    //uzmem sve sa istim imenom - ako nema dodajem ako ima proveravam
                                    if (oldVersion.GetAttributeList(newAtt.FullName) != null)
                                    {
                                        if (oldVersion.GetAttributeList(newAtt.FullName).Count == 0)
                                        {
                                            //dodajem
                                            diff.AddAttribute(newAtt, null);
                                        }
                                        else
                                        {
                                            bool found = false;
                                            if (oldVersion.HasAttributes)
                                            {
                                                foreach (ObjectAttribute oldAtt in oldVersion.GetAttributeList(newAtt.FullName))
                                                {
                                                    //proveravam da li se javlja ista vrednost
                                                    if (string.Compare(newAtt.Value, oldAtt.Value) == 0)
                                                    {
                                                        //ako se javlja i isti je obelezavam ga kao nadjen
                                                        found = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            //ako je found false, znaci da je dodat
                                            if (!found)
                                            {
                                                diff.AddAttribute(null, newAtt);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        diff.AddAttribute(null, newAtt);
                                    }
                                }
                            }
                        }
                        if (diff.Attributes.Count > 0)
                        {
                            this.modified.Add(diff);
                        }
                    }
                }
            }
        }