Example #1
0
        public void LoadCustomConfiguration(System.Xml.XmlNodeList nodeList)
        {
            if (nodeList == null || nodeList.Count == 0)
            {
                throw new ConfigurationErrorsException("No configuration provided.");
            }

            var node = nodeList.Cast <XmlNode>().FirstOrDefault(x => x.LocalName == "file");

            if (node == null)
            {
                throw new ConfigurationErrorsException("Expected 'file' element.");
            }

            var elem = node as XmlElement;

            var path = elem.Attributes["path"];

            if (path == null || String.IsNullOrWhiteSpace(path.Value))
            {
                throw new ConfigurationErrorsException("Expected 'path' attribute.");
            }

            this.filename = path.Value;
        }
Example #2
0
        static public System.Xml.XmlDocument set_todoc(System.Data.DataTable dt)
        {
            // salvo xml
            System.Xml.XmlDocument docSet       = new System.Xml.XmlDocument();
            System.IO.StringWriter stringWriter = new System.IO.StringWriter();
            DataSet ds = new DataSet(); ds.Tables.Add(dt);

            ds.WriteXml(new System.Xml.XmlTextWriter(stringWriter), System.Data.XmlWriteMode.WriteSchema);
            docSet.LoadXml(stringWriter.ToString());

            System.Xml.XmlNamespaceManager nm = new System.Xml.XmlNamespaceManager(docSet.NameTable);
            nm.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            System.Xml.XmlNodeList fields = docSet.SelectNodes("/" + ds.DataSetName + "/xs:schema//xs:element[@name='" + ds.Tables[0].TableName
                                                               + "']/xs:complexType/xs:sequence/xs:element", nm);
            if (fields == null || fields.Count == 0)
            {
                return(null);
            }

            // costruzione xsl
            System.Xml.Xsl.XslCompiledTransform xslDoc = new System.Xml.Xsl.XslCompiledTransform();
            string strXsl = "<?xml version='1.0'?>"
                            + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
                            + "<xsl:template match=\"/\">"
                            + " <rows schema='xmlschema.datatable'>"
                            + "  <xsl:for-each select=\"/" + ds.DataSetName + "/" + ds.Tables[0].TableName + "\"><row>"
                            + string.Concat(fields.Cast <XmlNode>().Select(x =>
                                                                           string.Format("  <{0}><xsl:value-of select=\"{0}\"/></{0}>", x.Attributes["name"].Value)))
                            + "  </row></xsl:for-each>"
                            + " </rows></xsl:template></xsl:stylesheet>";

            System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(strXsl));
            xslDoc.Load(reader);

            // trasformazione xml
            System.Xml.XmlDocument docResult = new System.Xml.XmlDocument();
            System.IO.StringWriter xmlText   = new System.IO.StringWriter();
            xslDoc.Transform(docSet, System.Xml.XmlWriter.Create(xmlText));
            //System.Text.Encoding e = xslDoc.OutputSettings.Encoding;

            docResult.LoadXml(xmlText.ToString());

            return(docResult);
        }
        public override void LoadCustomConfiguration(XmlNodeList nodeList)
        {
            if (nodeList == null || nodeList.Count == 0)
            {
                throw new ConfigurationErrorsException("No configuration provided.");
            }

            var node = nodeList.Cast<XmlNode>().FirstOrDefault(x => x.LocalName == "trustedIssuerMetadata");
            if (node == null)
            {
                throw new ConfigurationErrorsException("Expected 'trustedIssuerMetadata' element.");
            }

            var elem = node as XmlElement;

            var name = elem.Attributes["issuerName"];
            if (name == null || String.IsNullOrWhiteSpace(name.Value))
            {
                throw new ConfigurationErrorsException("Expected 'issuerName' attribute.");
            }

            var address = elem.Attributes["metadataAddress"];
            if (address == null || String.IsNullOrWhiteSpace(address.Value))
            {
                throw new ConfigurationErrorsException("Expected 'metadataAddress' attribute.");
            }

            this.metadataAddress = new Uri(address.Value);
            this.issuerName = name.Value;
        }
 private static IEnumerable<XElement> ToXElementList(XmlNodeList xmlNodeList) {
     return xmlNodeList.Cast<XmlNode>().Select(GetXElement);
 }
 private static IEnumerable<IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
 {
     return xmlNodes.Cast<XmlNode>()
         .Select(xmlNode => PublishedContentModelFactory.CreateModel(new XmlPublishedContent(xmlNode, isPreviewing)));
 }
        public override void LoadCustomConfiguration(XmlNodeList nodeList)
        {
            base.LoadCustomConfiguration(nodeList);
            
            if (nodeList == null || nodeList.Count == 0)
            {
                throw new ConfigurationErrorsException("No configuration provided.");
            }

            var node = nodeList.Cast<XmlNode>().FirstOrDefault(x => x.LocalName == "metadataCache");
            if (node == null)
            {
                throw new ConfigurationErrorsException("Expected 'metadataCache' element.");
            }

            var elem = node as XmlElement;

            var protect = elem.Attributes["protect"];
            if (protect != null)
            {
                if (protect.Value != "true" && protect.Value != "false")
                {
                    throw new ConfigurationErrorsException("Expected 'protect' to be 'true' or 'false'.");
                }
                this.protect = protect.Value == "true";
            }
            
            var cacheType = elem.Attributes["cacheType"];
            if (cacheType == null || String.IsNullOrWhiteSpace(cacheType.Value))
            {
                throw new ConfigurationErrorsException("Expected 'cacheType' attribute.");
            }

            var cacheDuration = elem.Attributes["cacheDuration"];
            if (cacheDuration == null || String.IsNullOrWhiteSpace(cacheDuration.Value))
            {
                this.cacheDuration = DefaultCacheDuration;
            }
            else
            {
                if (!Int32.TryParse(cacheDuration.Value, out this.cacheDuration))
                {
                    throw new ConfigurationErrorsException("Attribute 'cacheType' not a valid Int32.");
                }
            }
            
            var cacheInstance = (IMetadataCache)Activator.CreateInstance(Type.GetType(cacheType.Value));
            var config = cacheInstance as ICustomIdentityConfiguration;
            if (config != null)
            {
                config.LoadCustomConfiguration(elem.ChildNodes);
            }
            SetCache(cacheInstance);

            try
            {
                this.LoadMetadata();
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(ex.ToString());
            }
        }
        void LoadCustomConfiguration(XmlNodeList nodeList)
        {
            if (nodeList == null || nodeList.Count == 0)
            {
                throw new ConfigurationErrorsException("No configuration provided.");
            }

            var node = nodeList.Cast<XmlNode>().FirstOrDefault(x => x.LocalName == "metadataCache");
            if (node == null)
            {
                throw new ConfigurationErrorsException("Expected 'metadataCache' element.");
            }

            var elem = node as XmlElement;

            var protect = elem.Attributes["protect"];
            if (protect != null)
            {
                if (protect.Value != "true" && protect.Value != "false")
                {
                    throw new ConfigurationErrorsException("Expected 'protect' to be 'true' or 'false'.");
                }
                this.protect = protect.Value == "true";
            }
            
            var cacheType = elem.Attributes["cacheType"];
            if (cacheType == null || String.IsNullOrWhiteSpace(cacheType.Value))
            {
                throw new ConfigurationErrorsException("Expected 'cacheType' attribute.");
            }

            var cacheDuration = elem.Attributes["cacheDuration"];
            if (cacheDuration == null || String.IsNullOrWhiteSpace(cacheDuration.Value))
            {
                this.cacheDuration = DefaultCacheDuration;
            }
            else
            {
                if (!Int32.TryParse(cacheDuration.Value, out this.cacheDuration))
                {
                    throw new ConfigurationErrorsException("Attribute 'cacheType' not a valid Int32.");
                }
            }

            var type = Type.GetType(cacheType.Value);
            var xmlCtor = type.GetConstructor(new Type[]{typeof(XmlNodeList)});
            IMetadataCache cacheInstance = null;
            if (xmlCtor != null)
            {
                cacheInstance = (IMetadataCache)Activator.CreateInstance(type, elem.ChildNodes);
            }
            else
            {
                cacheInstance = (IMetadataCache)Activator.CreateInstance(type);
            }
            SetCache(cacheInstance);
        }
 private static IEnumerable<IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes)
 {
     return xmlNodes.Cast<XmlNode>().Select(xmlNode => new Models.XmlPublishedContent(xmlNode));
 }
Example #9
0
 private static IEnumerable<string> GetNames(XmlNodeList elements)
 {
     return elements.Cast<XmlElement>()
         .Select(x => x.GetAttributeValue("name"));
 }
        private SqlGeography ExtractGeography(XmlNamespaceManager ns, XmlNodeList points, out DateTime? minDate)
        {
            minDate = null;
              SqlGeography result = null;

              if (points.Count < 2) return null;

              string goodString = GetValidCoordinateString(points.Cast<XmlElement>().Select(f => GetCoordinate(ns, f)).ToList());

              // Check for multiple points in the line
              if (goodString.IndexOf(',') >= 0)
              {
            result = SqlGeography.STLineFromText(new SqlChars("LINESTRING(" + goodString + ")"), GeographyServices.SRID);
              }

              return result;
        }
Example #11
0
 private string[] ParseCategories(XmlNodeList xmlCategories)
 {
     return xmlCategories.Cast<XmlNode>().Select(n => GetAttributeStringValue(n, "slug")).ToArray();
 }
Example #12
0
        private string GetDidYouMeans(XmlNodeList xmlNodeList)
        {
            var nodes = new List<XmlNode>(xmlNodeList.Cast<XmlNode>());
            if (nodes.Count == 0)
                return null;

            nodes.OrderByDescending(node => double.Parse(node.Attributes["score"].Value, CultureInfo.InvariantCulture));
            var didyoumeans = nodes.Select(node =>
                $"\"{node.InnerText}\" (score: {Math.Round(double.Parse(node.Attributes["score"].Value, CultureInfo.InvariantCulture) * 100)}%)");

            var firstItems = string.Join(", ", didyoumeans.Take(didyoumeans.Count() - 1));

            string result;
            if (didyoumeans.Count() > 1)
            {
                result = firstItems + " or " + didyoumeans.Last();
            }
            else
            {
                result = firstItems;
            }
            return result;
        }