Exemple #1
0
        /// <summary>
        /// Creates the XML open tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>The XML open tag. In case of an element without value, the tag is self-closing.</returns>
        internal static string CreateXmlOpenTag(System.Xml.Linq.XElement element)
        {
            var builder = new System.Text.StringBuilder();
            builder.Append("<");
            var name = element.Name.LocalName;
            builder.Append(Settings.Default.Formatting_CommentXmlTagsToLowerCase ? name.ToLowerInvariant() : name);

            if (element.HasAttributes)
            {
                foreach (var attr in element.Attributes())
                {
                    builder.Append(Spacer);
                    builder.Append(attr);
                }
            }

            if (element.IsEmpty)
            {
                if (Settings.Default.Formatting_CommentXmlSpaceSingleTags)
                {
                    builder.Append(Spacer);
                }

                builder.Append("/");
            }

            builder.Append(">");

            var result = builder.ToString();

            return Settings.Default.Formatting_CommentXmlKeepTagsTogether ? SpaceToFake(result) : result;
        }
        /// <summary>
        /// Creates the XML open tag string for an XElement.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="options">The comment options used to contruct the tag.</param>
        /// <param name="allowSelfClosing">Whether to allow a self-closing tag or not.</param>
        /// <returns>The XML open tag. In case of an element without value, the tag is self-closing.</returns>
        internal static string CreateXmlOpenTag(System.Xml.Linq.XElement element, CodeCommentOptions options, bool allowSelfClosing = true)
        {
            var builder = new System.Text.StringBuilder();
            builder.Append("<");
            var name = element.Name.LocalName;
            builder.Append(options.XmlTagsToLowerCase ? name.ToLowerInvariant() : name);

            if (element.HasAttributes)
            {
                foreach (var attr in element.Attributes())
                {
                    builder.Append(CodeCommentHelper.Spacer);
                    builder.Append(attr.ToString());
                }
            }

            if (element.IsEmpty && allowSelfClosing)
            {
                if (options.XmlSpaceSingleTags)
                {
                    builder.Append(CodeCommentHelper.Spacer);
                }

                builder.Append("/");
            }

            builder.Append(">");

            var result = builder.ToString();

            return options.XmlKeepTagsTogether ? SpaceToFake(result) : result;
        }
 public static System.Xml.Linq.XElement RemoveAllNamespaces(System.Xml.Linq.XElement rootElement)
 {
     System.Xml.Linq.XElement xElement = new System.Xml.Linq.XElement(rootElement.Name.LocalName);
     if (rootElement.HasAttributes)
     {
         foreach (System.Xml.Linq.XAttribute attribute in rootElement.Attributes())
         {
             if (!attribute.IsNamespaceDeclaration)
             {
                 if (rootElement.Name.LocalName == "Category")
                 {
                     xElement.Add(attribute);
                 }
                 else
                 {
                     if (attribute.Name.ToString() == "{http://www.w3.org/2001/XMLSchema-instance}type"
                         || attribute.Name.ToString() == "{http://www.w3.org/2001/XMLSchema-instance}nil")
                     {
                         //  We dont want xsi: attribute
                         //  except for certain types where we will inject our own value
                         if (rootElement.Name.LocalName == "Activity"
                             && attribute.Name.ToString() == "{http://www.w3.org/2001/XMLSchema-instance}type"
                             && attribute.Value.EndsWith("RepairAndMaintenanceActivity"))
                         {
                             attribute.Value = "RepairAndMaintenanceActivity";
                             xElement.Add(attribute);
                         }
                         if (rootElement.Name.LocalName == "Activity"
                             && attribute.Name.ToString() == "{http://www.w3.org/2001/XMLSchema-instance}type"
                             && attribute.Value.EndsWith("CustomerActivity"))
                         {
                             attribute.Value = "CustomerActivity";
                             xElement.Add(attribute);
                         }
                     }
                     else
                     {
                         xElement.Add(attribute);
                     }
                 }
             }
         }
     }
     if (rootElement.HasElements)
     {
         //  Recurse the structure
         foreach (System.Xml.Linq.XElement childElement in rootElement.Elements())
         {
             xElement.Add(RemoveAllNamespaces(childElement));
         }
     }
     else
     {
         //  Take the current value across
         xElement.Value = rootElement.Value;
     }
     return xElement;
 }
        /// <summary>
        /// Maps an XML element to a settings dictionary.
        /// </summary>
        /// <param name="element">The XML element to be mapped.</param>
        /// <returns>The settings dictionary.</returns>
        public Models.SettingsDictionary Map(System.Xml.Linq.XElement element)
        {
            if (element == null)
            {
                return new SettingsDictionary();
            }

            return new SettingsDictionary(
                element.Attributes()
                    .ToDictionary(attr => XmlConvert.DecodeName(attr.Name.LocalName), attr => attr.Value));
        }
Exemple #5
0
        public static GISServer Create(System.Xml.Linq.XElement sERVERSERVER)
        {
            GISServer srv = new GISServer();

            foreach (XAttribute attr in sERVERSERVER.Attributes())
            {
                switch (attr.Name.LocalName)
                {
                    case "display":
                        srv._display = attr.Value;
                        break;
                    case "host":
                        srv._host = attr.Value;
                        break;
                    case "servlet":
                        srv._servlet = attr.Value;
                        break;
                    case "location":
                        srv._servlet = attr.Value;
                        break;
                    case "version":
                        srv._version = attr.Value;
                        break;
                    case "type":
                        srv.Type = attr.Value;
                        break;
                    case "credentials":
                        srv.Credentials = attr.Value;
                        break;
                }
            }

            srv._Controller = GISControllerFactory.Create(srv);
            return srv;
        }
        private static void RemoveSCCElementsAttributes(System.Xml.Linq.XElement el)
        {
            try
            {
                el.Elements().ToList().RemoveAll(x => x.Name.LocalName.StartsWith("Scc"));

                el.Attributes().ToList().RemoveAll(x => x.Name.LocalName.StartsWith("Scc"));

                foreach (var child in el.Elements())
                {
                    RemoveSCCElementsAttributes(child);
                }
            }
            catch (Exception ex)
            {
                Log.CaptureException(ex);
            }
        }
        private void Transit(System.Xml.Linq.XElement expression)
        {
            if (expression == null)
            {
                return;
            }

            if (expression.Elements().Any())
            {
                foreach (var element in expression.Elements())
                {
                    Transit(element);
                }
            }
            var attirbs = from attirb in expression.Attributes()
                          where attirb.Value == typeof(DTO).FullName
                          select attirb;
            foreach (var attrib in attirbs)
            {
                attrib.Value = typeof(Entity).FullName;
                //expression.ReplaceAttributes(new XAttribute("Name", typeof(Entity).FullName));
            }
        }
        /// <summary>
        /// Uses XML to initialize the object.
        /// </summary>
        /// <param name="element">The element used for loading.</param>
        public override void LoadFromXml(System.Xml.Linq.XElement element)
        {
            //Attributes
            foreach (var attribute in element.Attributes())
            {
                if (attribute.Name.LocalName.Equals("walkspeed", StringComparison.OrdinalIgnoreCase))
                {
                    float value;

                    if (float.TryParse(attribute.Value, out value))
                    {
                        WalkSpeed = value;
                    }

                    continue;
                }

                if (attribute.Name.LocalName.Equals("runspeed", StringComparison.OrdinalIgnoreCase))
                {
                    float value;

                    if (float.TryParse(attribute.Value, out value))
                    {
                        RunSpeed = value;
                    }

                    continue;
                }
            }

            //Grid size.
            XElement originelement = element.Element("gridsize");

            if (originelement != null)
            {
                int x = 0;
                int y = 0;

                foreach (var attribute in originelement.Attributes())
                {
                    if (attribute.Name.LocalName.Equals("x", StringComparison.OrdinalIgnoreCase))
                    {
                        int.TryParse(attribute.Value, out x);

                        continue;
                    }

                    if (attribute.Name.LocalName.Equals("y", StringComparison.OrdinalIgnoreCase))
                    {
                        int.TryParse(attribute.Value, out y);

                        continue;
                    }
                }

                GridSize = new Vector(x, y);
            }
        }
        /// <summary>
        /// Uses XML to initialize the object.
        /// </summary>
        /// <param name="element">The element used for loading.</param>
        public override void LoadFromXml(System.Xml.Linq.XElement element)
        {
            //Attributes
            foreach (var attribute in element.Attributes())
            {
                if (attribute.Name.LocalName.Equals("targetid", StringComparison.OrdinalIgnoreCase))
                {
                    TargetID = attribute.Value;
                    continue;
                }

                if (attribute.Name.LocalName.Equals("distance", StringComparison.OrdinalIgnoreCase))
                {
                    float value;

                    if (float.TryParse(attribute.Value, out value))
                    {
                        Distance = value;
                    }

                    continue;
                }

                if (attribute.Name.LocalName.Equals("rundistance", StringComparison.OrdinalIgnoreCase))
                {
                    float value;

                    if (float.TryParse(attribute.Value, out value))
                    {
                        RunDistance = value;
                    }

                    continue;
                }
            }

            //Safe zone.
            XElement safezoneelement = element.Element("safezone");

            if (safezoneelement != null)
            {
                int x = 0;
                int y = 0;

                foreach (var attribute in safezoneelement.Attributes())
                {
                    if (attribute.Name.LocalName.Equals("x", StringComparison.OrdinalIgnoreCase))
                    {
                        int.TryParse(attribute.Value, out x);

                        continue;
                    }

                    if (attribute.Name.LocalName.Equals("y", StringComparison.OrdinalIgnoreCase))
                    {
                        int.TryParse(attribute.Value, out y);

                        continue;
                    }
                }

                Safezone = new Vector(x, y);
            }

            #endregion
        }
        private static void RemoveSCCElementsAttributes(System.Xml.Linq.XElement el)
        {
            el.Elements().Where( x => x.Name.LocalName.StartsWith( "Scc" ) ).Remove();
            el.Attributes().Where( x => x.Name.LocalName.StartsWith( "Scc" ) ).Remove();

            foreach( var child in el.Elements() )
            {
                RemoveSCCElementsAttributes(child);
            }
        }