public override Specification VisitReference(ReferenceSpecification rf)
        {
            this.XmlWriter.WriteStartElement(Consts.Ref, this.NameSpace);
            this.WriteKey(rf.Key);

            this.XmlWriter.WriteEndElement();
            return(rf);
        }
        public void ResolveSpecRefGenericError()
        {
            ReferenceSpecification referenceSpecification = new ReferenceSpecification("qwe");
            AndSpecification       and = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                referenceSpecification);

            Dictionary <string, object> values = new Dictionary <string, object> {
                { "qwe", 1 }
            };

            AndSpecification result = and.ResolveSpecificationRefs(
                values,
                new ReferenceResolutionSettings {
                ThrowReferenceErrors = false
            });

            Assert.Same(referenceSpecification, result.Specifications.Last());
        }
        public void ResolveSpecReference()
        {
            ReferenceSpecification referenceSpecification = new ReferenceSpecification("qwe");

            LessOrEqualSpecification    specification = new LessOrEqualSpecification("qwe", SpecificationValue.Single(1));
            Dictionary <string, object> values        =
                new Dictionary <string, object>
            {
                {
                    "qwe",
                    specification
                }
            };

            Specification resolved = referenceSpecification.ResolveSpecificationRefs(values);

            var kv = Assert.IsType <LessOrEqualSpecification>(resolved);

            Assert.Same(specification, kv);
        }
        public void Evaluate(string key, bool expectedResult, string expectedDetails, bool allowError)
        {
            SpecificationEvaluationSettings settings =
                new SpecificationEvaluationSettings {
                ThrowReferenceErrors = allowError
            };

            var values = new Dictionary <string, object>
            {
                { "v1", 1 },
                { "null", null },
                { "c1", new ReferenceSpecification("c2") },
                { "c2", new ReferenceSpecification("c1") },
                { "rv", new ReferenceSpecification("v1") },
                { "rnull", new ReferenceSpecification("null") },
                { "rt", ConstantSpecification.True },
                { "rf", ConstantSpecification.False },
            };

            ReferenceSpecification reference = new ReferenceSpecification(key);

            if (allowError)
            {
                var exc = Assert.Throws <InvalidOperationException>(() => reference.Evaluate(values, settings));
                Assert.Contains(expectedDetails, exc.Message);
            }
            else
            {
                var result = reference.Evaluate(values, settings);
                Assert.Equal(expectedResult, result.IsSatisfied);

                if (expectedDetails == null)
                {
                    Assert.Null(result.Details);
                }
                else
                {
                    Assert.Contains(expectedDetails, result.Details);
                }
            }
        }
        public void ResolveSpecPartial()
        {
            ReferenceSpecification referenceSpecification = new ReferenceSpecification("qwe");

            ReferenceSpecification      refSpec = new ReferenceSpecification("qwe2");
            Dictionary <string, object> values  =
                new Dictionary <string, object>
            {
                {
                    "qwe",
                    refSpec
                }
            };

            ReferenceResolutionSettings settings = new ReferenceResolutionSettings();

            settings.AllowedUnresolvedSpecificationReferenceKeys.Add("qwe2");
            Specification resolved = referenceSpecification.ResolveSpecificationRefs(values, settings);

            Assert.Same(refSpec, resolved);
        }
        public override Specification VisitReference(ReferenceSpecification rf)
        {
            var r = rf.TryResolve(out var result, this.Values, out string error, true);

            if (r)
            {
                return(result);
            }

            if (result != null && result is ReferenceSpecification refSpec && this.Settings.AllowedUnresolvedSpecificationReferenceKeys.Contains(refSpec.Key))
            {
                return(result);
            }

            if (this.Settings.ThrowReferenceErrors)
            {
                throw new InvalidOperationException(
                          string.Format(SpecAbsRes.MissingSpecReference, rf, error));
            }

            return(base.VisitReference(rf));
        }
 public override bool VisitReference(ReferenceSpecification reference)
 {
     return(true);
 }
Exemple #8
0
 public virtual Specification VisitReference(ReferenceSpecification rf)
 {
     return(rf);
 }
Exemple #9
0
 public virtual bool VisitReference(ReferenceSpecification rf)
 {
     return(false);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="mgr"></param>
        /// <returns></returns>
        public override IFeature FromXml(XmlNode node, XmlNamespaceManager mgr)
        {
            if (node != null && node.HasChildNodes)
            {
                if (node.FirstChild.Attributes.Count > 0)
                {
                    Id = node.FirstChild.Attributes["gml:id"].InnerText;
                }
            }

            var periodicDateRangeNodes = node.FirstChild.SelectNodes("periodicDateRange", mgr);

            if (periodicDateRangeNodes != null && periodicDateRangeNodes.Count > 0)
            {
                var dateRanges = new List <DateRange>();
                foreach (XmlNode periodicDateRangeNode in periodicDateRangeNodes)
                {
                    var newDateRange = new DateRange();
                    newDateRange.FromXml(periodicDateRangeNode, mgr);
                    dateRanges.Add(newDateRange);
                }
                PeriodicDateRange = dateRanges.ToArray();
            }

            var fixedDateRangeNode = node.FirstChild.SelectSingleNode("fixedDateRange", mgr);

            if (fixedDateRangeNode != null && fixedDateRangeNode.HasChildNodes)
            {
                FixedDateRange = new DateRange();
                FixedDateRange.FromXml(fixedDateRangeNode, mgr);
            }

            var featureNameNodes = node.FirstChild.SelectNodes("featureName", mgr);

            if (featureNameNodes != null && featureNameNodes.Count > 0)
            {
                var featureNames = new List <FeatureName>();
                foreach (XmlNode featureNameNode in featureNameNodes)
                {
                    var newFeatureName = new FeatureName();
                    newFeatureName.FromXml(featureNameNode, mgr);
                    featureNames.Add(newFeatureName);
                }
                FeatureName = featureNames.ToArray();
            }

            var sourceIndication = node.FirstChild.SelectSingleNode("sourceIndication", mgr);

            if (sourceIndication != null && sourceIndication.HasChildNodes)
            {
                SourceIndication = new SourceIndication();
                SourceIndication.FromXml(sourceIndication, mgr);
            }

            var textContentNodes = node.FirstChild.SelectNodes("textContent", mgr);

            if (textContentNodes != null && textContentNodes.Count > 0)
            {
                var textContents = new List <TextContent>();
                foreach (XmlNode textContentNode in textContentNodes)
                {
                    if (textContentNode != null && textContentNode.HasChildNodes)
                    {
                        var content = new TextContent();
                        content.FromXml(textContentNode, mgr);
                        textContents.Add(content);
                    }
                }
                TextContent = textContents.ToArray();
            }

            var classificationNode = node.FirstChild.SelectSingleNode("classification", mgr);

            if (classificationNode != null && classificationNode.HasChildNodes)
            {
                Classification = classificationNode.FirstChild.InnerText;
            }

            var copyrightNode = node.FirstChild.SelectSingleNode("copyright", mgr);

            if (copyrightNode != null && copyrightNode.HasChildNodes)
            {
                Copyright = copyrightNode.FirstChild.InnerText;
            }

            var maximumDisplayScaleNode = node.FirstChild.SelectSingleNode("maximumDisplayScale", mgr);

            if (maximumDisplayScaleNode != null && maximumDisplayScaleNode.HasChildNodes)
            {
                MaximumDisplayScale = maximumDisplayScaleNode.FirstChild.InnerText;
            }

            var horizontalDatumReferenceNode = node.FirstChild.SelectSingleNode("horizontalDatumReference", mgr);

            if (horizontalDatumReferenceNode != null && horizontalDatumReferenceNode.HasChildNodes)
            {
                HorizontalDatumReference = horizontalDatumReferenceNode.FirstChild.InnerText;
            }

            var horizontalDatumValueNode = node.FirstChild.SelectSingleNode("horizontalDatumValue", mgr);

            if (horizontalDatumValueNode != null && horizontalDatumValueNode.HasChildNodes)
            {
                HorizontalDatumValue = horizontalDatumValueNode.FirstChild.InnerText;
            }

            var verticalDatumNode = node.FirstChild.SelectSingleNode("verticalDatum", mgr);

            if (verticalDatumNode != null && verticalDatumNode.HasChildNodes)
            {
                VerticalDatum = verticalDatumNode.FirstChild.InnerText;
            }

            var soundingDatumNode = node.FirstChild.SelectSingleNode("soundingDatum", mgr);

            if (soundingDatumNode != null && soundingDatumNode.HasChildNodes)
            {
                SoundingDatum = soundingDatumNode.FirstChild.InnerText;
            }

            var productTypeNode = node.FirstChild.SelectSingleNode("productType", mgr);

            if (productTypeNode != null && productTypeNode.HasChildNodes)
            {
                ProductType = productTypeNode.FirstChild.InnerText;
            }

            var minimumDisplayScaleNode = node.FirstChild.SelectSingleNode("minimumDisplayScale", mgr);

            if (minimumDisplayScaleNode != null && minimumDisplayScaleNode.HasChildNodes)
            {
                MinimumDisplayScale = minimumDisplayScaleNode.FirstChild.InnerText;
            }

            var issueDateNode = node.FirstChild.SelectSingleNode("issueDate", mgr);

            if (issueDateNode != null && issueDateNode.HasChildNodes)
            {
                IssueDate = issueDateNode.FirstChild.InnerText;
            }

            var purposeNode = node.FirstChild.SelectSingleNode("purpose", mgr);

            if (purposeNode != null && purposeNode.HasChildNodes)
            {
                Purpose = purposeNode.FirstChild.InnerText;
            }

            var informationNodes = node.FirstChild.SelectNodes("information", mgr);

            if (informationNodes != null && informationNodes.Count > 0)
            {
                var informations = new List <Information>();
                foreach (XmlNode informationNode in informationNodes)
                {
                    if (informationNode != null && informationNode.HasChildNodes)
                    {
                        var newInformation = new Information();
                        newInformation.FromXml(informationNode, mgr);
                        informations.Add(newInformation);
                    }
                }
                Information = informations.ToArray();
            }

            var priceNodes = node.FirstChild.SelectNodes("price", mgr);

            if (priceNodes != null && priceNodes.Count > 0)
            {
                var prices = new List <Price>();
                foreach (XmlNode priceNode in priceNodes)
                {
                    if (priceNode != null && priceNode.HasChildNodes)
                    {
                        var newPrice = new Price();
                        newPrice.FromXml(priceNode, mgr);
                        prices.Add(newPrice);
                    }
                }
                Price = prices.ToArray();
            }

            var producingAgencyNode = node.FirstChild.SelectSingleNode("producingAgency", mgr);

            if (producingAgencyNode != null && producingAgencyNode.HasChildNodes)
            {
                ProducingAgency = new ProducingAgency();
                ProducingAgency.FromXml(producingAgencyNode, mgr);
            }

            var publicationNumberNode = node.FirstChild.SelectSingleNode("publicationNumber", mgr);

            if (publicationNumberNode != null && publicationNumberNode.HasChildNodes)
            {
                PublicationNumber = publicationNumberNode.FirstChild.InnerText;
            }

            var dataSetNameNode = node.FirstChild.SelectSingleNode("dataSetName", mgr);

            if (dataSetNameNode != null && dataSetNameNode.HasChildNodes)
            {
                DataSetName = dataSetNameNode.FirstChild.InnerText;
            }

            var versionNode = node.FirstChild.SelectSingleNode("version", mgr);

            if (versionNode != null && versionNode.HasChildNodes)
            {
                Version = versionNode.FirstChild.InnerText;
            }

            var serviceStatusNode = node.FirstChild.SelectSingleNode("serviceStatus", mgr);

            if (serviceStatusNode != null && serviceStatusNode.HasChildNodes)
            {
                ServiceStatus = serviceStatusNode.FirstChild.InnerText;
            }

            var keywordsNode = node.FirstChild.SelectSingleNode("keywords", mgr);

            if (keywordsNode != null && keywordsNode.HasChildNodes)
            {
                Keywords = keywordsNode.FirstChild.InnerText;
            }

            var productSpecificationNode = node.FirstChild.SelectSingleNode("productSpecification", mgr);

            if (productSpecificationNode != null && productSpecificationNode.HasChildNodes)
            {
                ProductSpecification = new ReferenceSpecification();
                ProductSpecification.FromXml(productSpecificationNode, mgr);
            }

            var onlineResourceNode = node.FirstChild.SelectSingleNode("onlineResource", mgr);

            if (onlineResourceNode != null && onlineResourceNode.HasChildNodes)
            {
                OnlineResource = new OnlineResource();
                OnlineResource.FromXml(onlineResourceNode, mgr);
            }

            var serviceSpecificationNode = node.FirstChild.SelectSingleNode("serviceSpecification", mgr);

            if (serviceSpecificationNode != null && serviceSpecificationNode.HasChildNodes)
            {
                ServiceSpecification = new ReferenceSpecification();
                ServiceSpecification.FromXml(serviceSpecificationNode, mgr);
            }

            var serviceDesignNode = node.FirstChild.SelectSingleNode("serviceDesign", mgr);

            if (serviceDesignNode != null && serviceDesignNode.HasChildNodes)
            {
                ServiceDesign = new ReferenceSpecification();
                ServiceDesign.FromXml(serviceDesignNode, mgr);
            }

            var linkNodes = node.FirstChild.SelectNodes("*[boolean(@xlink:href)]", mgr);

            if (linkNodes != null && linkNodes.Count > 0)
            {
                var links = new List <Link>();
                foreach (XmlNode linkNode in linkNodes)
                {
                    var newLink = new Link();
                    newLink.FromXml(linkNode, mgr);
                    links.Add(newLink);
                }
                Links = links.ToArray();
            }

            return(this);
        }