Esempio n. 1
0
        private void CreateAndPopulateElementAssertionString(StringBuilder sb)
        {
            //generate the element assertion
            var elementAssert = _element.GetAssertionStringIdentifier();

            if (!string.IsNullOrEmpty(elementAssert))
            {
                elementAssert = this.GetFormattedPrefix() + elementAssert;
            }
            else if (string.IsNullOrEmpty(elementAssert) && this.containedTemplates.Count > 0)
            {
                elementAssert = "*";
            }

            List <string> containedTemplateContexts = new List <string>();

            foreach (var containedTemplate in this.containedTemplates)
            {
                TemplateContextBuilder tcb      = new TemplateContextBuilder(this._tdb, this._igType, this._igTypeSchema, this._prefix);
                string containedTemplateContext = tcb.BuildContextString(containedTemplate.Key);
                containedTemplateContexts.Add(containedTemplateContext);
            }

            if (containedTemplateContexts.Count == 1)
            {
                elementAssert += "[" + containedTemplateContexts[0] + "]";
            }
            else if (containedTemplateContexts.Count > 1)
            {
                elementAssert += "[(" + string.Join(") or (", containedTemplateContexts) + ")]";
            }

            sb.Replace(Sentinels.ELEMENT_TOKEN, elementAssert);
        }
        private void CreateAndPopulateElementAssertionString(StringBuilder sb)
        {
            //generate the element assertion
            var elementAssert = _element.GetAssertionStringIdentifier();

            if (!string.IsNullOrEmpty(elementAssert))
            {
                elementAssert = this.GetFormattedPrefix() + elementAssert;
            }
            else if (string.IsNullOrEmpty(elementAssert) && !string.IsNullOrEmpty(this._containedTemplateOid))
            {
                elementAssert = "*";
            }

            //do we have a template id?
            if (!string.IsNullOrEmpty(_containedTemplateOid))
            {
                string oid;
                string root;
                string extension;
                string urn;

                if (IdentifierHelper.GetIdentifierOID(_containedTemplateOid, out oid))
                {
                    string format = "[" + this._templateIdentifierXpath + "]";
                    elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), oid);
                }
                else if (IdentifierHelper.GetIdentifierII(_containedTemplateOid, out root, out extension))
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        string format = "[" + this._templateIdentifierXpath + "]";
                        elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), root);
                    }
                    else
                    {
                        string format = "[" + this._templateVersionIdentifierXpath + "]";
                        elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), root, extension);
                    }
                }
                else if (IdentifierHelper.GetIdentifierURL(_containedTemplateOid, out urn))
                {
                    string format = "[" + this._templateIdentifierXpath + "]";
                    elementAssert = elementAssert + string.Format(format, this.GetFormattedPrefix(), urn);
                }
                else
                {
                    throw new Exception("Unexpected/invalid identifier for template found when processing contained template reference");
                }
            }

            sb.Replace(Sentinels.ELEMENT_TOKEN, elementAssert);
        }