/// <summary> /// Initializes a new instance of the <see cref="AreaDefinition"/> class. /// </summary> /// <param name="element">The element.</param> public AreaDefinition(XElement element) : this() { this.AreaString.String = element.TryGetAttributeValue("Text", null); this.MapToPropertyExpression = element.TryGetAttributeValue("MapTo", null); this.Separator = element.TryGetAttributeValue("Separator", ":"); }
/// <summary> /// Initializes a new instance of the <see cref="AreaDefinition"/> class. /// </summary> /// <param name="element">The element.</param> public AreaDefinition(XElement element) : this() { this.AreaString.String = element.TryGetAttributeValue("Text", null); this.AreaString.IsContained = element.TryGetAttributeValue("Text-IsContained", true); this.MapToPropertyName = element.TryGetAttributeValue("MapTo", null); this.Separator = element.TryGetAttributeValue("Separator", ":"); }
public CreatorInfo(XElement node) { string value; if (node.TryGetAttributeValue("id", out value)) _id = value; XElement n = node.Element("name"); if (n != null && n.TryGetValue(out value)) _name = value; n = node.Element("email"); if (n != null && n.TryGetValue(out value)) { _email = value; if (n.TryGetAttributeValue("display", out value)) _displayEmail = bool.Parse(value); } n = node.Element("bio"); if (n != null && n.TryGetValue(out value)) _bio = value; n = node.Element("url"); if (n != null && n.TryGetValue(out value)) _url = value; }
/// <summary> /// Initializes a new instance of the <see cref="SectionDefinition"/> class. /// </summary> /// <param name="element">The XML-element to read the data from.</param> public SectionDefinition(XElement element) : this() { this.SectionString.String = element.TryGetAttributeValue("Text", null); // Parse the aspects... foreach (XElement aspectE in element.Elements("Aspect")) { SectionParserDefinition spDefinition = new SectionParserDefinition(aspectE); if (string.IsNullOrWhiteSpace(spDefinition.Type)) { // TODO: Log warning continue; } this.Parsers.Add(spDefinition); } // Parse the areas... foreach (XElement areaE in element.Elements("Area")) { AreaDefinition areaDefinition = new AreaDefinition(areaE); if (!areaDefinition.IsValidDefinition()) { // TODO: Log warning continue; } this.Areas.Add(areaDefinition); } }
object IAddressProvider.ParseXElement(XElement element) { string address = element.Value; string receiptType = element.TryGetAttributeValue("Type", MailingEntryObject.ReceiptType.To.ToString()); return MailingEntryObject.FromAddress(address, receiptType); }
/// <summary> /// Initializes a new instance of the <see cref="SectionDefinition"/> class. /// </summary> /// <param name="element">The XML-element to read the data from.</param> public SectionDefinition(XElement element) : this() { this.SectionString.String = element.TryGetAttributeValue("Text", null); this.SectionString.IsContained = element.TryGetAttributeValue("Text-IsContained", true); // Parse the areas... foreach (XElement areaE in element.Elements("Area")) { AreaDefinition areaDefinition = new AreaDefinition(areaE); if (!areaDefinition.IsValidDefinition()) { // TODO: Log warning continue; } this.Areas.Add(areaDefinition); } }
object IAddressProvider.Convert(XElement element) { string consumer = element.TryGetAttributeValue("Consumer", null); string recApiKey = element.Value; PushEntryObject geo = new PushEntryObject(); geo.Consumer = consumer; geo.RecipientApiKey = recApiKey; return geo; }
/// <summary> /// Initializes a new instance of the <see cref="SectionParserDefinition"/> class. /// </summary> /// <param name="element">The element.</param> public SectionParserDefinition(XElement element) : this() { this.Type = element.TryGetAttributeValue("Type", null); foreach (var item in element.Attributes()) { if (item.Name == "Type") { continue; } Options[item.Name.LocalName] = item.Value; } }
public MessageInfo(XElement node) { string value; if (node.TryGetAttributeValue("id", out value)) _id = int.Parse(value); XElement n = node.Element("title"); if (n != null && n.TryGetValue(out value)) _title = value; n = node.Element("text"); if (n != null && n.TryGetValue(out value)) _text = value; }
internal static KernelTypeInfo Deserialize(XElement xe, string directory = null) { string name = xe.GetAttributeValue(csNAME); bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY); string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR); string typeName = xe.Element(csTYPE).Value; string assemblyFullName = xe.Element(csASSEMBLY).Value; string assemblyName = xe.Element(csASSEMBLYNAME).Value; string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH); long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value); eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr); Type type = null; KernelTypeInfo kti = new KernelTypeInfo(null); if (!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName)) { Assembly assembly = null; try { assembly = Assembly.Load(assemblyFullName); } catch (FileNotFoundException) { directory = directory != null ? directory : string.Empty; assemblyName = directory + Path.DirectorySeparatorChar + assemblyName; if (File.Exists(assemblyName + ".dll")) { assembly = Assembly.LoadFrom(assemblyName + ".dll"); } else if (File.Exists(assemblyName + ".exe")) { assembly = Assembly.LoadFrom(assemblyName + ".exe"); } else if (!string.IsNullOrEmpty(assemblyPath)) { assembly = Assembly.LoadFrom(assemblyPath); } else throw; } if (assembly == null) throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName); type = assembly.GetType(typeName); kti = new KernelTypeInfo(type, isDummy == true ? true : false, behaviour); } kti.DeserializedChecksum = checksum; return kti; }
public CategoryInfo(CatalogInfo catalog, XElement node) { _catalog = catalog; string value; if (node.TryGetAttributeValue("id", out value)) _id = int.Parse(value); XElement n = node.Element("name"); if (n != null && n.TryGetValue(out value)) _name = value; n = node.Element("description"); if (n != null && n.TryGetValue(out value)) _description = value; }
public CatalogInfo(XElement node) { string value; if (node.TryGetAttributeValue("id", out value)) _id = int.Parse(value); XElement n = node.Element("name"); if (n != null && n.TryGetValue(out value)) _name = value; n = node.Element("description"); if (n != null && n.TryGetValue(out value)) _description = value; n = node.Element("type"); if (n != null && n.TryGetValue(out value)) _type = (CatalogType)System.Enum.Parse(typeof(CatalogType), value); }
public ItemInfo(CatalogInfo catalog, XElement node) { _catalog = catalog; string value; if (node.TryGetAttributeValue("id", out value)) _id = int.Parse(value); if (node.TryGetAttributeValue("categoryId", out value)) _categoryId = int.Parse(value); if (node.TryGetAttributeValue("creatorId", out value)) _creatorId = value; XElement n = node.Element("name"); if (n != null && n.TryGetValue(out value)) _name = value; n = node.Element("description"); if (n != null && n.TryGetValue(out value)) _description = value; n = node.Element("version"); if (n != null && n.TryGetValue(out value)) _version = value; n = node.Element("downloadUrl"); if (n != null && n.TryGetValue(out value)) _downloadUrl = value; n = node.Element("fileName"); if (n != null && n.TryGetValue(out value)) _fileName = value; n = node.Element("screenshotUrl"); if (n != null && n.TryGetValue(out value)) _screenshotUrl = value; n = node.Element("iconUrl"); if (n != null && n.TryGetValue(out value)) _iconUrl = value; n = node.Element("worksWithMajorVersion"); if (n != null && n.TryGetValue(out value)) _worksWithMajorVersion = int.Parse(value); n = node.Element("worksWithMinorVersion"); if (n != null && n.TryGetValue(out value)) _worksWithMinorVersion = int.Parse(value); n = node.Element("requiresManualIntervention"); if (n != null && n.TryGetValue(out value)) _requiresManualIntervention = bool.Parse(value); n = node.Element("dateAdded"); if (n != null && n.TryGetValue(out value)) _dateAdded = DateTime.Parse(value); n = node.Element("statisticsInfo"); if (n != null) _statistics = new StatisticsInfo(n); n = node.Element("purchaseInfo"); if (n != null) _purchase = new PurchaseInfo(n); n = node.Element("tags"); if (n != null) { foreach (XElement e in n.Elements("tag")) { string tag; if (e.TryGetValue(out tag)) _tags.Add(tag); } } }
internal static KernelMethodInfo Deserialize(XElement xe, CudafyModule parentModule, string directory = null) { string methodName = xe.GetAttributeValue(csNAME); string methodTypeName = xe.GetAttributeValue(csTYPE); eKernelMethodType methodType = (eKernelMethodType)Enum.Parse(typeof(eKernelMethodType), methodTypeName); bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY); string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR); string typeName = xe.Element(csTYPE).Value; string assemblyFullName = xe.Element(csASSEMBLY).Value; string assemblyName = xe.Element(csASSEMBLYNAME).Value; string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH); long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value); eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr); MethodInfo mi = null; KernelMethodInfo kmi = null; if(!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName)) { Assembly assembly = null; try { assembly = Assembly.Load(assemblyFullName); } catch (FileNotFoundException) { directory = directory != null ? directory : string.Empty; assemblyName = directory + Path.DirectorySeparatorChar + assemblyName; if (File.Exists(assemblyName + ".dll")) { assembly = Assembly.LoadFrom(assemblyName + ".dll"); } else if (File.Exists(assemblyName + ".exe")) { assembly = Assembly.LoadFrom(assemblyName + ".exe"); } else if (!string.IsNullOrEmpty(assemblyPath)) { assembly = Assembly.LoadFrom(assemblyPath); } else throw; } if (assembly == null) throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName); Type type = assembly.GetType(typeName); if (type == null) throw new CudafyException(CudafyException.csCOULD_NOT_FIND_TYPE_X_IN_ASSEMBLY_X, typeName, assemblyFullName); mi = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (mi == null) throw new CudafyException(CudafyException.csCOULD_NOT_FIND_METHOD_X_IN_TYPE_X_IN_ASSEMBLY_X, methodName, typeName, assemblyFullName); kmi = new KernelMethodInfo(type, mi, methodType, isDummy == true ? true : false, behaviour, parentModule); } kmi.DeserializedChecksum = checksum; return kmi; }
private static SettingsConfigurationFile ParseVersion1(XElement rootE) { string identifier = rootE.TryGetAttributeValue("Identifier", null); if (string.IsNullOrWhiteSpace(identifier)) { return null; } int iSetting = 0; List<SettingItem> settings = new List<SettingItem>(); foreach (XElement settingE in rootE.Elements("Setting")) { // Dissect the element and retrieve all attributes string name = settingE.TryGetAttributeValue("Name", null); if (string.IsNullOrWhiteSpace(name)) { Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemInvalidName, iSetting + 1); continue; } string typeName = settingE.TryGetAttributeValue("Type", null); if (string.IsNullOrWhiteSpace(typeName)) { Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemEmptyType, name); continue; } if (!SupportedSettingTypes.Contains(typeName)) { Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemInvalidType, typeName, string.Join(",", SupportedSettingTypes)); continue; } bool isNull = settingE.TryGetAttributeValue("IsNull", false); // Read the setting value. If it contains a CDATA, then we need to process that first. string valueString = null; XNode valueNode = settingE.DescendantNodes().FirstOrDefault(); if (valueNode != null) { switch (valueNode.NodeType) { case System.Xml.XmlNodeType.CDATA: case System.Xml.XmlNodeType.Text: valueString = ((XText)valueNode).Value; break; default: Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFile), Properties.Resources.SettingsConfigurationEmbResInvalidValueContent, valueNode.NodeType, name); break; } } // TODO: This will work only with primitive types (String, Boolean etc.). This could be made extensible to allow storing other types as well. Type type = Type.GetType(typeName); object defaultValue = Convert.ChangeType(valueString, type, CultureInfo.InvariantCulture); SettingItem settingItem = new SettingItem(name, defaultValue, defaultValue, type); settings.Add(settingItem); iSetting++; } return new SettingsConfigurationFile(identifier, settings); }
private static Enumeration ParseEnumeration(XElement enumNode) { var group = enumNode.TryGetAttributeValue("group"); var ns = enumNode.TryGetAttributeValue("namespace"); var vendor = enumNode.TryGetAttributeValue("vendor"); var enApi = enumNode.TryGetAttributeValue("api"); var type = enumNode.TryGetAttributeValue("type"); var elements = from member in enumNode.Nodes().OfType<XElement>() where member.Name == "enum" let name = member.TryGetAttributeValue("name") let value = member.TryGetAttributeValue("value") let api = member.TryGetAttributeValue("api") let intValue = value.StartsWith("0x") ? ulong.Parse(value.Substring(2), NumberStyles.HexNumber) : unchecked((ulong) long.Parse(value)) select new {Name = name, Api = api, Value = intValue}; return new Enumeration( group, ns, vendor, enApi, type == "bitmask" ? EnumerationType.Bitmask : EnumerationType.None, elements.Select(x => new Enumeration.EnumerationField(x.Name, x.Value, x.Api))); }
private static DataType ParseDataType(XElement element) { var nodes = element.Nodes().ToArray(); var ptype = element.Nodes().OfType<XElement>().FirstOrDefault(n => n.Name == "ptype"); string group = element.TryGetAttributeValue("group"); string type; int ptypeIndex; if (ptype == null) { type = "void"; ptypeIndex = int.MaxValue; } else { type = ptype.Value; ptypeIndex = Array.IndexOf(nodes, ptype); } bool isConst = false; bool isPointerConst = false; int pointerIndirection = 0; string name = element.Nodes().OfType<XElement>().Single(n => n.Name == "name").Value; for (int i = 0; i < nodes.Length; i++) { var textnode = nodes[i] as XText; if (textnode != null) { string text = textnode.Value.Trim(); if (textnode.Value.Trim() == "const") { if (i < ptypeIndex) isConst = true; } else if (text.Contains("*")) pointerIndirection = text.Count(c => c == '*'); } } return new DataType(name, group, pointerIndirection, type, isConst, isPointerConst); }
internal static KernelConstantInfo Deserialize(XElement xe, string directory = null) { string constantName = xe.GetAttributeValue(csNAME); string fieldName = xe.GetAttributeValue(csFIELDNAME); bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY); string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR); string typeName = xe.Element(csTYPE).Value; string assemblyFullName = xe.Element(csASSEMBLY).Value; string assemblyName = xe.Element(csASSEMBLYNAME).Value; string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH); long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value); FieldInfo fi = null; KernelConstantInfo kci = null; if (!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName)) { Assembly assembly = null; try { assembly = Assembly.Load(assemblyFullName); } catch (FileNotFoundException) { directory = directory != null ? directory : string.Empty; assemblyName = directory + Path.DirectorySeparatorChar + assemblyName; if (File.Exists(assemblyName + ".dll")) { assembly = Assembly.LoadFrom(assemblyName + ".dll"); } else if (File.Exists(assemblyName + ".exe")) { assembly = Assembly.LoadFrom(assemblyName + ".exe"); } else if (!string.IsNullOrEmpty(assemblyPath)) { assembly = Assembly.LoadFrom(assemblyPath); } else throw; } if (assembly == null) throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName); Type type = assembly.GetType(typeName); fi = type.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); kci = new KernelConstantInfo(fieldName, fi, isDummy == true ? true : false); } kci.DeserializedChecksum = checksum; return kci; }
private static bool IsEnabled(XElement customElementE) { return customElementE.TryGetAttributeValue("IsEnabled", true); }