Example #1
0
 public static string GetAttr(this XElement el, string name)
 {
     if (el.Attribute(name) == null)
         return null;
     else
         return el.Attribute(name).Value;
 }
Example #2
0
        public static BsonDocument ToBsonDocument(this XElement xElement)
        {
            var bsonDocument = new BsonDocument();

            var type = xElement.Name.ToString();
            bsonDocument.Add(Constants._TYPE, type);
            var mainId = xElement.Attribute(Constants._ID) != null ? xElement.Attribute(Constants._ID).Value : null;

            foreach (XAttribute attribure in xElement.Attributes())
            {
                var key = attribure.Name.ToString();
                var value = attribure.Value;
                if (bsonDocument.Contains(key))
                    bsonDocument.Set(key, value);
                else
                    bsonDocument.Add(key, value);
            }
            foreach (XElement kid in xElement.Descendants())
            {
                var id = kid.Attribute(Constants._ID);
                if (id == null || mainId == null)
                {
                    bsonDocument.Add(kid.Name.ToString(), kid.ToBsonDocument());
                }
                else
                {
                    kid.SetAttributeValue(Constants.PARENT_ID, mainId);
                    DBFactory.GetData().Save(kid);
                }
            }
            return bsonDocument;
        }
 internal static void UpdateXElement(this XElement element, SettingsInfo settings, XNamespace ns)
 {
     element.Attribute("ID").Value = settings.Id.ToString();
     element.Attribute("processorRef").Value = settings.Processor.Id.ToString();
     element.Element(ns + "name").Value = settings.Name;
     element.Element(ns + "serialPortSettings").UpdateXElement(settings.SerialPortSettings, ns);
 }
 static SeatGroup ParseSeatGroup(this XElement cell)
 {
     return new HtmlSeatGroup(
         (string)cell.Attribute("data-person"),
         (int)cell.Attribute("data-count")
     );
 }
Example #5
0
 public static Color GetColor(this XElement element, string name, string defaultColor) {
     return
         ColorReflector.ToColorFromHex(element.Attribute(name) != null
             ? element.Attribute(name).Value
             : element.Attribute(defaultColor).Value);
     //return (Color) ColorConverter.ConvertFromString(element.Attribute(name).Value);
 }
Example #6
0
 public static Color? GetNullColor(this XElement element, string name)
 {
     return element.Attribute(name) != null
         ? ColorReflector.ToColorFromHex(element.Attribute(name).Value)
         : new Color?();
     //return (Color) ColorConverter.ConvertFromString(element.Attribute(name).Value);
 }
 public static string GetAttribute(this XElement element, string attributeName)
 {
     if (!element.HasAttributes ||
         element.Attribute(attributeName) == null ||
         string.IsNullOrEmpty(element.Attribute(attributeName).Value))
         return string.Empty;
     return element.Attribute(attributeName).Value;
 }
 public static PortalSettings GetPortalSetting(this XElement element, string id)
 {
     var portalItem = new PortalSettings();
     portalItem.AlwaysShowEditButton = Convert.ToBoolean(element.Attribute("AlwaysShowEditButton").Value);
     portalItem.PortalName = element.Attribute("PortalName").Value;
     portalItem.PortalId = id;
     return portalItem;
 }
Example #9
0
        public static string GenerateXPathFromXElement(this XElement xUi)
        {
            var original = xUi.GetAttributeValue("XPath");
            if (!String.IsNullOrEmpty(original))
                return original;
            var tag = "//*";
            var xTag = xUi.Attribute("tag");
            var xType = xUi.Attribute("type");
            if (xType != null)
            {
                if (xType.Value.Equals("a"))
                {
                    tag = "//a";
                    xType.Remove();
                }
                if(xType.Value.Equals("table")||xType.Value.Equals("div"))
                {
                    var textAttr = xUi.Attribute("text");
                    if(textAttr!=null) textAttr.Remove();
                }

            }
            if (xTag != null)
            {
                tag = "//" + xTag.Value;
                xTag.Remove();
            }
            var xpath = tag;
            if (xUi.Attributes().Any())
            {
                xpath = xpath + "[";
                var count = 0;
                foreach (XAttribute xa in xUi.Attributes())
                {
                    var key = xa.Name.ToString();
                    if (key.StartsWith("_"))
                        continue;
                    var value = xa.Value;
                    if (count > 0)
                        xpath = xpath + " and ";
                    if (key.Equals("text"))
                    {
                        if (value.Length < 32)
                            xpath = xpath + key + "()='" + value + "' ";
                        else
                        {
                            xpath = xpath + "contains(text(),'" + value.Substring(0, 16) + "') ";
                        }
                    }

                    else
                        xpath = xpath + "@" + key + "='" + value + "' ";
                    count++;
                }
                xpath = xpath + "]";
            }
            return xpath;
        }
Example #10
0
 internal static Processor ToProcessor(this XElement element, XNamespace ns)
 {
     return new Processor(Convert.ToInt32(element.Attribute("ID").Value, 10),
         element.Attribute("Name").Value,
         Convert.ToInt32(element.Element(ns + "eepromSize").Value, 16),
         Convert.ToInt32(element.Element(ns + "flashSize").Value, 16),
         Convert.ToInt32(element.Element(ns + "bootStartAddress").Value, 16),
         Convert.ToInt32(element.Element(ns + "bootEndAddress").Value, 16));
 }
        public static Field ToField(this XElement f)
        {
            if (f.Name != Constants.Field)
            {
                throw new ArgumentException("Invalid argument.", "f");
            }

            return new Field(f.Attribute(Constants.Name).Value, f.Attribute(Constants.Required).Value == Constants.True);
        }
Example #12
0
 public static Vector3 ParseXYZ(this XElement element, Vector3 defaultValue)
 {
     return new Vector3
     (
         element.Attribute("x").ToFloat(defaultValue.x),
         element.Attribute("y").ToFloat(defaultValue.y),
         element.Attribute("z").ToFloat(defaultValue.z)
     );
 }
        /// <summary>
        /// Returns true if this XElement is null, or an obix:Null contract.
        /// </summary>
        /// <returns>true if this XElement is null or a null contract, false otherwise.</returns>
        public static bool IsNullOrNullContract(this XElement element) {
            if (element == null) {
                return true;
            }

            return element.HasAttributes 
                && element.Attribute("null") != null 
                && element.Attribute("null").Value == "true";
        }
Example #14
0
        public static string GetValue(this XElement self, string attributeName, bool toLower = true)
        {
            if (self.Attribute(attributeName) == null)
                return null;

            return toLower ?
                self.Attribute(attributeName).Value.ToLowerInvariant() :
                self.Attribute(attributeName).Value;
        }
 internal static bool IsAttributeSetToValue(this XElement element, string attributeName, string expectedValue)
 {
     return element.Attribute(attributeName) != null
         ? string.Equals(
             element.Attribute(attributeName).Value,
             expectedValue,
             StringComparison.InvariantCultureIgnoreCase)
         : false;
 }
Example #16
0
 internal static void UpdateXElement(this XElement element, Processor processor, XNamespace ns)
 {
     element.Attribute("ID").Value = processor.Id.ToString();
     element.Attribute("Name").Value = processor.Name;
     element.Element(ns + "eepromSize").Value = "0x" + processor.EepromSize.ToString("X");
     element.Element(ns + "flashSize").Value = "0x" + processor.FlashSize.ToString("X");
     element.Element(ns + "bootStartAddress").Value = "0x" + processor.BootStartAddress.ToString("X");
     element.Element(ns + "bootEndAddress").Value = "0x" + processor.BootEndAddress.ToString("X");
 }
        public static Fields.Field ToField2(this XElement f)
        {
            if (f.Name != Constants.Field)
            {
                throw new ArgumentException("Invalid argument.", "f");
            }

            return new Fields.Field(int.Parse(f.Attribute(Constants.Number).Value), f.Attribute(Constants.Name).Value, f.Attribute(Constants.Type).Value, f.Elements(Constants.Value).Select(v => v.ToValue()));
        }
        private static string GetAttributeValueOrNullByExactName(this XElement source, string attributeName)
        {
            if (source.Attribute(attributeName) != null)
            {
                return source.Attribute(attributeName).Value;
            }

            return null;
        }
Example #19
0
        public static string GetAttribute(this XElement element, string name, string defaultValue)
        {
            string value = null;
            if (element.Attribute(name) != null)
            {
                value = element.Attribute(name).Value;
            }

            return value ?? defaultValue;
        }
        /// <summary>
        /// Gets the attribute value with the given attributeName.
        /// </summary>
        /// <returns>The attribute value if found, String.Empty otherwise.</returns>
        /// <param name="element">Element.</param>
        /// <param name="attributeName">Attribute name.</param>
        public static string GetSafeAttributeValue(this XElement element, XName attributeName)
        {
            string result = String.Empty;

            if (element != null && element.Attribute(attributeName) != null)
            {
                result = element.Attribute(attributeName).Value;
            }

            return result;
        }
Example #21
0
 public static string Stringize(this XElement e)
 {
     return
         e.Attribute("Severity") + " " +
         e.Attribute("Code") + ": " +
         (e.Element("Message") != null ? e.Element("Message").Value + " " : string.Empty) +
         (e.Element("Span") != null
             ? string.Format("[{0},{1}) Length: {2}", e.Element("Span").Attribute("Start"),
                                                      e.Element("Span").Attribute("End"),
                                                      e.Element("Span").Attribute("Length")) : string.Empty);
 }
Example #22
0
 public static string GetOptionalAttributeValue(this XElement element, string localName, string namespaceName = null)
 {
     XAttribute attr = null;
     if (String.IsNullOrEmpty(namespaceName)) {
         attr = element.Attribute(localName);
     }
     else {
         attr = element.Attribute(XName.Get(localName, namespaceName));
     }
     return attr != null ? attr.Value : null;
 }
Example #23
0
 public static FieldRef GetCamlFieldRef(this XElement xmlNode)
 {
     FieldRef fieldRef = new FieldRef();
     fieldRef.Name = xmlNode.Attribute("Name").Value;
     fieldRef.DisplayName = xmlNode.Attribute("DisplayName") == null ?
         null : xmlNode.Attribute("DisplayName").Value;
     fieldRef.IsHidden = xmlNode.AttributeBoolOrFalse("Hidden");
     fieldRef.IsReadOnly = xmlNode.AttributeBoolOrFalse("ReadOnly");
     fieldRef.IsRequired = xmlNode.AttributeBoolOrFalse("Required");
     return fieldRef;
 }
Example #24
0
 /// <summary>
 /// Creates a single instruction out of an <instruction /> element
 /// </summary>
 /// <param name="xelm">The instruction as XElement</param>
 /// <returns>The new instruction.</returns>
 public static Instruction ToInstruction(this XElement xelm)
 {
     return new Instruction()
         {
             State = Convert.ToInt32(xelm.Attribute("state").Value),
             Read = xelm.Attribute("read").Value[0],
             Write = xelm.Attribute("write").Value[0],
             Direction = (Direction)Convert.ToInt32(xelm.Attribute("direction").Value),
             NewState = Convert.ToInt32(xelm.Attribute("newstate").Value)
         };
 }
        public static Group ToGroup(this XElement g)
        {
            if (g.Name != Constants.Group)
            {
                throw new ArgumentException("Invalid argument.", "g");
            }

            return new Group(
                g.Attribute(Constants.Name).Value,
                g.Attribute(Constants.Required).Value == Constants.True,
                g.Elements(Constants.Field).Select(f => f.ToField()));
        }
Example #26
0
        /// <summary>
        ///     Gets the attribute value for a given element.
        /// </summary>
        /// <param name="element">the element that possesses the attribute</param>
        /// <param name="attribute">the attribute to find</param>
        /// <returns>the string value of the element. Returns null if the element or attribute does not exist.</returns>
        internal static string GetAttribute(this XElement element, XName attribute) {
            if (element == null || attribute == null || string.IsNullOrWhiteSpace(attribute.ToString())) {
                return null;
            }

            var a = element.Attribute(attribute);
            if (a == null) {
                if (attribute.Namespace == element.Name.Namespace) {
                    a = element.Attribute(attribute.LocalName);
                }
            }
            return a == null ? null : a.Value;
        }
        public static TabSettings GetTabSetting(this XElement element, string id)
        {
            var tabItem = new TabSettings();

            tabItem.TabName = element.Attribute("TabName").Value;
            tabItem.TabId = id;
            tabItem.AccessRoles =
                    (from item in element.Attribute("AccessRoles").Value.Split(';')
                     where item.Length > 0
                     select item).ToList();

            return tabItem;
        }
Example #28
0
 public static Field GetCamlField(this XElement xmlNode)
 {
     Field field = new Field();
     field.Name = xmlNode.Attribute("Name").Value;
     field.IsRequired  = xmlNode.AttributeBoolOrFalse("Required");
     field.IsReadOnly = xmlNode.AttributeBoolOrFalse("ReadOnly");
     field.IsHidden = xmlNode.AttributeBoolOrFalse("Hidden");
     field.FieldType   = xmlNode.Attribute("Type").Value;
     field.DisplayName = xmlNode.Attribute("DisplayName").Value;
     field.IsIndexed = xmlNode.AttributeBoolOrFalse("Indexed");
     field.List = xmlNode.AttributeValueOrDefault("List");
     field.IsPrimaryKey = xmlNode.AttributeBoolOrFalse("PrimaryKey");
     return field;
 }
		public static NuGetReference AsPackage(this XElement element)
		{
			if (element == null)
				throw new ArgumentNullException(nameof(element));

			var id = element.Attribute("id");
			if (id == null)
				throw new InvalidOperationException("Cannot find attribute 'id' in <package> element.");

			var version = element.Attribute("version");
			if (version == null)
				throw new InvalidOperationException("Cannot find attribute 'version' in <package> element.");

			return new NuGetReference(id.Value, version.Value);
		}
Example #30
0
 public static string GetAttribute(this XElement el, XName name, string defaultValue = "")
 {
     var attr = el.Attribute(name);
     if (attr != null)
         return attr.Value;
     return defaultValue;
 }