public override void Populate(XContainer root) { root = root.Element("result"); base.Populate(root); Url = root.Element("url").Value; }
private static IAccount GetAccount(XContainer accountContainer) { if (accountContainer == null) return null; return new Account { Number = accountContainer.Element("Number").GetTextValue(), CountryCode = accountContainer.Element("CountryCode").GetTextValue() }; }
/// <summary> /// Updates the property element. /// </summary> /// <param name="property">The property.</param> /// <param name="elementPosition">The element position.</param> /// <param name="fileId">The file id.</param> private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId) { property.Add(new XElement("FileRef", new XAttribute("uid", fileId))); var seqpnt = new XElement( "SequencePoint", new XAttribute("vc", property.Element("MethodPoint").Attribute("vc").Value), new XAttribute("sl", elementPosition.Start)); property.Element("SequencePoints").Add(seqpnt); }
private static UserInfo BuildUserInfo(XContainer user) { // ReSharper disable PossibleNullReferenceException return new UserInfo { Name = user.Element("screen_name").Value, Location = user.Element("location").Value, FriendCount = int.Parse(user.Element("friends_count").Value), FollowerCount = int.Parse(user.Element("followers_count").Value) }; // ReSharper restore PossibleNullReferenceException }
/// <summary> /// Constructor for user data /// </summary> /// <param name="xml">XContainer containing user data</param> /// <param name="adminUser">Admin username</param> public WufooData(XContainer xml, string adminUser) { // set user properties AdminUserName = adminUser; Hash = xml.Element("Hash").ElementValueNull(); Title = xml.Element("User").ElementValueNull(); ApiKey = xml.Element("ApiKey").ElementValueNull(); FormsUrl = xml.Element("LinkForms").ElementValueNull(); CreateForms = xml.Element("CreateForms").ElementValueNull().Equals("1"); Created = DateTime.MinValue; Modified = DateTime.MinValue; IsForm = false; }
public Station(XContainer xc) { name = xc.Element("name").Value; id = Convert.ToInt32(xc.Element("id").Value); lat = Convert.ToDouble(xc.Element("lat").Value); lng = Convert.ToDouble(xc.Element("long").Value); installed = Convert.ToBoolean(xc.Element("installed").Value); locked = Convert.ToBoolean(xc.Element("locked").Value); locked = Convert.ToBoolean(xc.Element("temporary").Value); bikeCount = Convert.ToInt32(xc.Element("nbBikes").Value); dockCount = Convert.ToInt32(xc.Element("nbEmptyDocks").Value); }
internal static List<string> GetGuids(XContainer owningElement, string propertyName) { var propElement = owningElement.Element(propertyName); return (propElement == null) ? new List<string>() : (from osEl in propElement.Elements(SharedConstants.Objsur) select osEl.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant()).ToList(); }
private static string GetField(XContainer el, string fieldName) { var fld = el.Element(fieldName); return fld != null ? fld.Value : "<Missing>"; }
public void UpdateGeocodes(XContainer result, Org org) { if (result == null) throw new ArgumentNullException("result"); var element = result.Element("geometry"); if (element == null) return; var locationElement = element.Element("location"); if (locationElement == null) return; var lat = locationElement.Element("lat"); if (lat != null) { org.Lat = lat.Value.ToNullableDouble(); org.Modified = DateTime.Now; } var lng = locationElement.Element("lng"); if (lng != null) { org.Lon = lng.Value.ToNullableDouble(); org.Modified = DateTime.Now; } }
private static string GetValue(XContainer container, string elementName) { var typeElemment = container.Element(elementName); if (typeElemment == null) throw new ArgumentException("找不到元素 MsgType。"); return typeElemment.Value; }
/// <summary> /// Updates the property element. /// </summary> /// <param name="property">The property.</param> /// <param name="elementPosition">The element position.</param> /// <param name="fileId">The file id.</param> private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId) { foreach (var pt in property.Element("code").Elements().Take(1)) { pt.Add(new XAttribute("sl", elementPosition.Start)); pt.Add(new XAttribute("fid", fileId)); } }
private void FillProperties(XContainer xml) { if (xml == null) return; var title = xml.Element("title"); var subTitle = xml.Element("subtitle"); var location = xml.Element("location"); var phone = xml.Element("phone"); var url = xml.Element("url"); var urlText = xml.Element("urlText"); if (title != null) Title = string.IsNullOrEmpty(title.Value) ? null : title.Value; if (subTitle != null) SubTitle = string.IsNullOrEmpty(subTitle.Value) ? null : subTitle.Value; if (location != null) Location = string.IsNullOrEmpty(location.Value) ? null : location.Value; if (phone != null) Phone = string.IsNullOrEmpty(phone.Value) ? null : phone.Value; if (url != null) Url = string.IsNullOrEmpty(url.Value) ? null : url.Value; if (urlText != null) UrlText = string.IsNullOrEmpty(urlText.Value) ? null : urlText.Value; var keyValueList = xml.Element("departmentOrDayOfWeekToTimeList"); if (keyValueList == null) return; var items = keyValueList.Descendants("item"); foreach (var item in items) { var key = item.Attribute("key"); if (key == null) continue; var value = item.Element("value"); if (value != null) LocationOrDayOfWeekToTime.Add(key.Value, value.Value ?? string.Empty); } }
private void RegisterExecutionTypes(XContainer root, OpcodeLookup lookup) { foreach (XElement element in root.Element("scriptTypes").Descendants("type")) { var opcode = (ushort) XMLUtil.GetNumericAttribute(element, "opcode"); string name = XMLUtil.GetStringAttribute(element, "name"); lookup.RegisterScriptType(name, opcode); } }
public void FillProperties(XContainer xml) { if (xml == null) return; var title = xml.Element("title"); var phone = xml.Element("phone"); var fax = xml.Element("fax"); var email = xml.Element("email"); var visitingAddress = xml.Element("visitingaddress"); var address = xml.Element("address"); if (title != null) Title = string.IsNullOrEmpty(title.Value) ? null : title.Value; if (phone != null) Phone = string.IsNullOrEmpty(phone.Value) ? null : phone.Value; if (fax != null) Fax = string.IsNullOrEmpty(fax.Value) ? null : fax.Value; if (email != null) Email = string.IsNullOrEmpty(email.Value) ? null : email.Value; if (visitingAddress != null) VisitingAddress = string.IsNullOrEmpty(visitingAddress.Value) ? null : visitingAddress.Value; if (address != null) Address = string.IsNullOrEmpty(address.Value) ? null : address.Value; var contactPersons = xml.Element("contact-persons"); if (contactPersons != null) { ContactPersons = new List<ContactPerson>(); foreach (var person in contactPersons.Descendants("person")) { var name = person.Element("name"); if (name == null) continue; if (string.IsNullOrEmpty(name.Value)) continue; var cp = new ContactPerson {Name = name.Value}; var positionAsElement = person.Element("position"); var emailAsElement = person.Element("email"); var phoneAsElement = person.Element("phone"); if (positionAsElement != null && !string.IsNullOrEmpty(positionAsElement.Value)) cp.Position = positionAsElement.Value; if (emailAsElement != null && !string.IsNullOrEmpty(emailAsElement.Value)) cp.Email = emailAsElement.Value; if (phoneAsElement != null && !string.IsNullOrEmpty(phoneAsElement.Value)) cp.Phone = phoneAsElement.Value; ContactPersons.Add(cp); } } var genericFields = xml.Element("generic-fields"); if (genericFields == null) return; GenericFields = new List<string>(); var fields = genericFields.Descendants("field"); foreach (var field in fields.Where(field => field != null && !string.IsNullOrEmpty(field.Value))){ GenericFields.Add(field.Value); } }
private static Customer CreateCustomer(XContainer customerElement) { Customer newCustomer = new Customer(); XName customerID = XName.Get("CustomerID", "http://tempuri.org/NWindDataSet.xsd"); XName companyName = XName.Get("CompanyName", "http://tempuri.org/NWindDataSet.xsd"); XName country = XName.Get("Country", "http://tempuri.org/NWindDataSet.xsd"); XName city = XName.Get("City", "http://tempuri.org/NWindDataSet.xsd"); XName contactName = XName.Get("ContactName", "http://tempuri.org/NWindDataSet.xsd"); XName boolean = XName.Get("Bool", "http://tempuri.org/NWindDataSet.xsd"); newCustomer.CustomerID = customerElement.Element(customerID).Value; newCustomer.CompanyName = customerElement.Element(companyName).Value; newCustomer.Country = customerElement.Element(country).Value; newCustomer.City = customerElement.Element(city).Value; newCustomer.ContactName = customerElement.Element(contactName).Value; newCustomer.Bool = bool.Parse(customerElement.Element(boolean).Value); return newCustomer; }
private static ICountry GetCountry(XContainer countryContainer) { if (countryContainer == null) return null; return new Country { Code = countryContainer.Element("CountryCode").GetTextValue(), Name = countryContainer.Element("CountryName").GetTextValue() }; }
public static bool AddPullData(XContainer xc, List<Station> stationList) { try { string LastUpdate = xc.Element("stations").Attribute("lastUpdate").Value; CaBiDataContext dc = new CaBiDataContext(); if ((from p in dc.Pulls where p.DateSignature == LastUpdate select p).Count<Pull>() == 0) { Pull p = new Pull(); p.DateSignature = LastUpdate; p.PullDate = DateTime.Now; dc.Pulls.InsertOnSubmit(p); dc.SubmitChanges(); int pullID = (from pid in dc.Pulls where pid.DateSignature == LastUpdate select pid.PullID).First<int>(); foreach (Station s in stationList) { if ((from ps in dc.PulledStations where ps.StationID == s.id select ps).Count<PulledStation>() == 0) { CaBiDataContext dcsub = new CaBiDataContext(); PulledStation ps = new PulledStation(); ps.StationID = s.id; ps.StationName = s.name; ps.Latitude = s.lat; ps.Longitude = s.lng; ps.Installed = s.installed; ps.Locked = s.locked; ps.Temporary = s.temporary; dcsub.PulledStations.InsertOnSubmit(ps); dcsub.SubmitChanges(); } PullResult pr = new PullResult(); pr.PullID = pullID; pr.StationID = s.id; pr.Docked = s.bikeCount; pr.Empty = s.dockCount; pr.Installed = s.installed; pr.Locked = s.locked; pr.Temporary = s.temporary; dc.PullResults.InsertOnSubmit(pr); } dc.SubmitChanges(); } return true; } catch { return false; } }
/// <summary> /// Loads stringID set definitions from an XML container. /// </summary> /// <param name="container">The XML container to load set definitions from.</param> /// <param name="resolver">The StringIDSetResolver to store sets to.</param> public static void LoadAllStringIDSets(XContainer container, StringIDSetResolver resolver) { // Make sure there is a root <layouts> tag XContainer stringIDContainer = container.Element("stringIDs"); if (stringIDContainer == null) throw new ArgumentException("Invalid stringID definition document"); // Process <set> elements foreach (XElement element in stringIDContainer.Elements("set")) ProcessSetElement(element, resolver); }
private static IEnumerable<string> GetAvailableServices(XContainer xml, XNamespace azureNamespace) { var availableServicesElement = xml.Element(azureNamespace + "AvailableServices"); if (availableServicesElement == null) { return Enumerable.Empty<string>(); } return availableServicesElement.Elements(azureNamespace + "AvailableService") .Select(e => e.Value) .ToList(); }
/// <summary> /// Constructor for form data /// </summary> /// <param name="xml">XContainer containing form data</param> /// <param name="user">User the form belongs to</param> /// <param name="adminUser">Admin username</param> public WufooData(XContainer xml, string user, string adminUser) { // set form properties AdminUserName = adminUser; User = user; IsForm = true; Hash = xml.Element("Hash").ElementValueNull(); Title = xml.Element("Name").ElementValueNull(); Name = xml.Element("Url").ElementValueNull(); Created = xml.Element("DateCreated").ElementValueNull().UniversalDateTime(); Modified = xml.Element("DateUpdated").ElementValueNull().UniversalDateTime(); Description = xml.Element("Description").ElementValueNull(); Language = xml.Element("Language").ElementValueNull(); IsPublic = xml.Element("IsPublic").ElementValueNull(); StartDate = xml.Element("StartDate").ElementValueNull().UniversalDateTime(); EndDate = xml.Element("EndDate").ElementValueNull().UniversalDateTime(); RedirectMessage = xml.Element("RedirectMessage").ElementValueNull(); Email = xml.Element("Email").ElementValueNull(); EntryLimit = xml.Element("EntryLimit").ElementValueNull(); LinkFields = xml.Element("LinkFields").ElementValueNull(); LinkEntries = xml.Element("LinkEntries").ElementValueNull(); // we can use the friendly url or the hash (let's use the friendly url for now) Url = string.Format(WufooWrapper.FormUrl, adminUser, Name); EditUrl = string.Format(WufooWrapper.FormEditUrl, adminUser, Name); }
public Literal(XContainer literal) { if (literal == null) { throw new ArgumentNullException("literal"); } var xElement = literal.Element("ID"); if (xElement != null) { Id = "$" + xElement.Value + "$"; } var xElement2 = literal.Element("ToolTip"); if (xElement2 != null) { ToolTip = xElement2.Value; } var xElement3 = literal.Element("Default"); if (xElement3 != null) { Default = xElement3.Value; } }
private void RegisterValueTypes(XContainer root, OpcodeLookup lookup) { foreach (XElement element in root.Element("valueTypes").Descendants("type")) { string name = XMLUtil.GetStringAttribute(element, "name"); var opcode = (ushort) XMLUtil.GetNumericAttribute(element, "opcode"); int size = XMLUtil.GetNumericAttribute(element, "size"); bool quoted = XMLUtil.GetBoolAttribute(element, "quoted", false); string tag = XMLUtil.GetStringAttribute(element, "tag", null); var valueType = new ScriptValueType(name, opcode, size, quoted, tag); lookup.RegisterValueType(valueType); } }
private static IEnumerable<string> GetRoleSizes( XContainer computeCapabilitiesElement, XNamespace azureNamespace, string subElementName) { var capabilitiesElement = computeCapabilitiesElement.Element(azureNamespace + subElementName); if (capabilitiesElement == null) { return Enumerable.Empty<string>(); } return capabilitiesElement.Elements(azureNamespace + "RoleSize") .Select(e => e.Value); }
public IMessageBase Deserialize(XContainer container) { var eventType = GetValue(container, "Event").ToLower(); switch (eventType) { case "subscribe": if (container.Element("Ticket") == null) return SubscribeEventMessageFormatter.Deserialize(container); return QrSubscribeEventKeyMessageFormatter.Deserialize(container); } if (!Mappings.ContainsKey(eventType)) throw new NotSupportedException(string.Format("不支持的事件类型:{0}。", eventType)); return Mappings[eventType].Deserialize(container); }
public object Deserialize(XContainer source, object modelOrType) { if (modelOrType == null) { throw new ArgumentNullException("modelOrType"); } Type t = modelOrType is Type ? (Type)modelOrType : modelOrType.GetType(); PropertyInfo[] props = t.GetProperties(); object model = modelOrType; if (modelOrType is Type) { ConstructorInfo ctor = t.GetConstructor(ObjectUtil.EMPTY_TYPES); model = ctor.Invoke(ObjectUtil.EMPTY_OBJECTS); } foreach (PropertyInfo p in props) { if (!p.IsTransient()) { XElement elt = source.Element(p.Name); if (elt != null) { Type pt = p.PropertyType; string s = elt.Value; object val = null; if ("{null}".Equals(s, StringComparison.InvariantCultureIgnoreCase)) { val = null; } else if (p.IsObject()) { val = p.GetValue(model, null); val = Deserialize(elt, (val != null) ? val : pt); } else if (pt.IsEnum) { try { val = Enum.Parse(pt, s, true); } catch (Exception) { val = Enum.ToObject(pt, 0); } } else { val = Convert.ChangeType(s, pt); } if (p.CanWrite) { p.SetValue(model, val, ObjectUtil.EMPTY_OBJECTS); } } } } return model; }
private void RegisterFunctions(XContainer root, OpcodeLookup lookup) { foreach (XElement element in root.Element("functions").Descendants("function")) { string name = XMLUtil.GetStringAttribute(element, "name"); if (name == "") continue; var opcode = (ushort) XMLUtil.GetNumericAttribute(element, "opcode"); string returnType = XMLUtil.GetStringAttribute(element, "returnType", "void"); var flags = (uint) XMLUtil.GetNumericAttribute(element, "flags", 0); string[] parameterTypes = element.Descendants("arg").Select(e => XMLUtil.GetStringAttribute(e, "type")).ToArray(); var info = new ScriptFunctionInfo(name, opcode, returnType, flags, parameterTypes); lookup.RegisterFunction(info); } }
/// <summary> /// Initializes a new instance of the <see cref="ConfigPolicyProvider"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <exception cref="System.ArgumentException"> /// All policies must specify a unique 'key'. /// or /// All policies must specify an IPolicy policy type 'value'. /// or /// All policies must implement 'Decision.IPolicy'. /// </exception> public ConfigPolicyProvider(XContainer settings) { var policies = settings.Element("policies"); foreach (var item in policies.Elements("item")) { // Validate that a key is present var key = item.Attribute("key"); if (key == null || string.IsNullOrWhiteSpace((string)key)) { throw new ArgumentException("All policies must specify a unique 'key'.", item.ToString()); } // Validate that a value is present var value = item.Attribute("value"); if (value == null || string.IsNullOrWhiteSpace((string)value)) { throw new ArgumentException("All policies must specify an IPolicy policy type 'value'.", key.ToString()); } // Extract type and assembly information specified by the value var typeName = (string)value; string assembly = null; if (typeName.Contains(",")) { var typeSplit = typeName.Split(','); assembly = typeSplit[1].Trim(); typeName = typeSplit[0].Trim(); } // Validate the type is correct var type = assembly == null ? Type.GetType(typeName, false) : Assembly.Load(assembly).GetType(typeName, false); if (type == null || type.GetInterface(typeof(IPolicy).FullName) == null) { throw new ArgumentException("All policies must implement 'Decisions.Contracts.IPolicy'.", typeName); } container.Register(Component.For(type).Forward<IPolicy>().Named(key.Value).DependsOn(Dependencies(type, item).ToArray())); } }
private void ParseNodePrices(XContainer xEle) { var i = 0; var resourceId = _context.HhResources.Single(s => s.ResourceName == xEle.Element(_sdNs + "NodeName").Value) .ResourceID; var hhPdDetail = new HhShadowDetail[24]; foreach ( var ele in xEle.Elements(_sdNs + "HourlyPrices")) { hhPdDetail[i] = new HhShadowDetail { ResourceID = resourceId, ScheHour = Convert.ToInt32(ele.Element(_sdNs + "DeliveryHour").Value), ScheMW = Convert.ToDecimal(ele.Elements(_sdNs + "Prices").First(p => p.Element(_sdNs + "PriceType").Value.Equals("Energy")) .Element(_sdNs + "MCP").Value) }; _hhSdMain.HhShadowDetails.Add(hhPdDetail[i]); i++; } }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { YellowstonePathology.UI.Common.OrderDialog openWindow = null; foreach (Window window in Application.Current.Windows) { if (window.GetType().ToString() == "YellowstonePathology.UI.Common.OrderDialog") { openWindow = window as YellowstonePathology.UI.Common.OrderDialog; break; } } if (item != null) { System.Xml.Linq.XContainer xContainer = item as System.Xml.Linq.XContainer; XElement templateNameElement = xContainer.Element("TemplateName"); if (templateNameElement != null) { return(((System.Windows.Controls.Grid)openWindow.Content).FindResource(templateNameElement.Value) as DataTemplate); } return(((System.Windows.Controls.Grid)openWindow.Content).FindResource("StandardCheckBoxTemplate") as DataTemplate); } return(((YellowstonePathology.UI.Common.OrderDialog)openWindow.Content).FindResource("StandardCheckBoxTemplate") as DataTemplate); }
public Address(XContainer e) { if (e == null) return; var element = e.Element("formatted_address"); if (element != null) FormattedAddress = element.Value; foreach (var el in e.Elements("address_component")) { var type = el.Element("type"); if (type != null) { XElement xElement; switch (type.Value) { case "street_number": xElement = el.Element("long_name"); if (xElement != null) StreetNumber = xElement.Value; break; case "route": xElement = el.Element("long_name"); if (xElement != null) Route = xElement.Value; break; case "locality": xElement = el.Element("long_name"); if (xElement != null) Locality = xElement.Value; break; case "postal_code": xElement = el.Element("long_name"); if (xElement != null) PostalCode = xElement.Value; break; case "country": xElement = el.Element("long_name"); if (xElement != null) Country = xElement.Value; break; } } Console.WriteLine(el); } }
private static void TraverseCategories( ICollection<DefaultCategory> list, XContainer parent, string elementName, CategoryType type) { var element = parent.Element(elementName); if (element == null) { return; } foreach (var category in element.Elements("category") .Select(e => TraverseCategory(e, type)) .Where(category => category != null)) { list.Add(category); } }