private static void ApplyDir(XElement dirElement, String path) { path = Path.Combine(path, dirElement.Attribute("name").Value); if (!Directory.Exists(path)) Directory.CreateDirectory(path); foreach (var file in dirElement.XPathSelectElements("file")) File.Create(Path.Combine(path, file.Attribute("name").Value)).Close(); foreach (var dir in dirElement.XPathSelectElements("directory")) ApplyDir(dir, path); }
public void LoadFromXml(XElement xml){ AddRules(ControllerRule.FromXml(xml .XPathSelectElements("on"))); xml.XPathSelectElements("map[@role]") .Select(n => new{From = n.attr("role").ToUpper(), To = n.attr("as").ToUpper()}) .map(i => RoleMap.Add(i.From, i.To)); xml.XPathSelectElements("map[@user]") .Select(n => new{From = n.attr("user").ToUpper(), To = n.attr("as").ToUpper()}) .map(i => UserMap.Add(i.From, i.To)); var def = xml.First("default"); if (def.yes()){ DefaultResult = def.Value; } }
public void AddToPackage(string xPath, XElement document, string package, string formName) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes) { if (node.HasAttributes || node.Attribute("Name") == null ||node.Attribute("Name").Value != package) { continue; } foreach (var child in node.Elements()) { if (child.Name != "OutputForms") { continue; } var newNode = new XElement("Form"); newNode.SetAttributeValue("Name", formName); //node.Parent.AddAfterSelf(newNode); child.Add(newNode); } } }
public virtual void Load(PengWorld world, XElement xWorld) { Contract.Requires(world != null); Contract.Requires(xWorld != null); foreach (XElement xObj in xWorld.XPathSelectElements(TA.XPathObjects)) { List<ObjectArgumentInfo> args = new List<ObjectArgumentInfo>(); args.Add(new ObjectArgumentInfo(typeof(string), xObj.Attribute(TA.ObjectID).Value)); Type objectType; if (xObj.Attribute(TA.ObjectType) != null) { objectType = Type.GetType(xObj.Attribute(TA.ObjectType).Value); foreach (XElement xArg in xWorld.XPathSelectElements(TA.XPathObjectArgs)) { if (xArg.Attribute(TA.ArgumentType) != null) args.Add(GetObjectArgFromXml(xArg)); } } else objectType = typeof(PengObject); var ctor = objectType.GetConstructor(args.ConvertAll(x => x.Type).ToArray()); PengObject obj = (PengObject)ctor.Invoke(args.ConvertAll(x => x.Value).ToArray()); obj.LoadFromXml(xObj); } }
protected override IEnumerable<UserRoleMap> internalListAllUserRoleMaps(XElement lastx) { var elements = lastx.XPathSelectElements("//map[@user and @as]"); foreach (var element in elements) { var rm = new UserRoleMap {User = element.attr("user"), Role = element.attr("as")}; yield return rm; } }
public XElement Transform(XElement element) { // <p class="combat"> var combats = element.XPathSelectElements("p[@class='combat']").ToArray(); if (combats.Count() == 1) { var combat = combats.ElementAt(0); // <button type="button" class="combat" onclick="Section.fight();"> combat.Name = "button"; combat.RemoveAttributes(); combat.Add(new XAttribute("type", "button")); combat.Add(new XAttribute("class", "combat")); combat.Add(new XAttribute("onclick", "Section.fight();")); } else { for (var index = 0; index < combats.Count(); index++) { var combat = combats.ElementAt(index); // <button type="button" class="combat" onclick="Section.fight(X);"> combat.Name = "button"; combat.RemoveAttributes(); combat.Add(new XAttribute("type", "button")); combat.Add(new XAttribute("class", "combat")); combat.Add(new XAttribute("onclick", string.Format("Section.fight({0});", index))); } } return element; }
public NavigationLinkBuilder(string dimensionsPath) { dimensions = XElement.Load(dimensionsPath); //Create context items for dimension name/value pairs foreach(var node in dimensions.XPathSelectElements("//DIMENSION")) { string name = node.Attribute("NAME").Value; string id = node.Descendants("DIMENSION_ID").First().Attribute("ID").Value; var item = new ContextItem() { Name = name, ID = id }; var count = 0; foreach (var descendant in node.Descendants("DIMENSION_NODE")) { // Skip first if (count != 0) { // get id var a = descendant.Descendants("DVAL_ID").First().Attribute("ID").Value; // get name from syn var b = descendant.Descendants("SYN").First().Value; item.Values.Add(b, new ContextItem() { Name = b, ID = a }); idToDimensions.Add(a, id); } count++; } contextItems.Add(name, item); } }
/// <summary> /// Parse a XElement type parameter to a ComplexTypeElement instance. /// </summary> /// <param name="complexTypeElement">A ComplexType element.</param> /// <returns>Returns a ComplexTypeElement instance.</returns> public static ComplexTypeElement Parse(XElement complexTypeElement) { if (null == complexTypeElement) { return null; } string name = null != complexTypeElement.Attribute("Name") ? complexTypeElement.Attribute("Name").Value : null; var props = new List<PropertyElement>(); string xPath = "./*[local-name()='Property']"; var propertyElements = complexTypeElement.XPathSelectElements(xPath, ODataNamespaceManager.Instance); foreach (var propEle in propertyElements) { if (null != propEle.Attribute("Name") && null != propEle.Attribute("Type")) { AnnotationDVsManager accessor = AnnotationDVsManager.Instance(); string propertyName = string.Format("{0}_{1}", name, propEle.GetAttributeValue("Name")); object defaultValue = accessor.GetDefaultValue(propertyName); bool nullable = null != propEle.Attribute("Nullable") ? Convert.ToBoolean(propEle.Attribute("Nullable").Value) : true; props.Add(new PropertyElement(propEle.Attribute("Name").Value.ToString(), propEle.Attribute("Type").Value.ToString(), defaultValue, nullable)); } } return new ComplexTypeElement(name, props); }
public void ReplaceInForms(string xPath, XElement document, Element previousParam, Element param) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes) { if (node.HasElements) { continue; } if (!node.HasAttributes || node.Attribute("Name").Value != previousParam.FormName || node.Attribute("Pdf").Value != previousParam.PdfName) { continue; } AttributeHelper.AttributeInNode("Name", previousParam.FormName, param.FormName, node); AttributeHelper.AttributeInNode("Pdf", previousParam.PdfName, param.PdfName, node); AttributeHelper.AttributeInNode("Doctype", previousParam.Doctype, param.Doctype, node); AttributeHelper.AttributeInNode("DataNamePrefix", previousParam.DataNamePrefix, param.DataNamePrefix, node); AttributeHelper.AttributeInNode("Docdesc", previousParam.Docdesc, param.Docdesc, node); AttributeHelper.AttributeInNode("MergeID", previousParam.MergeId, param.MergeId, node); AttributeHelper.AttributeInNode("Attachment", previousParam.Attachment, param.Attachment, node); } }
/// <summary> /// Adds the frame XML. /// </summary> /// <param name="ui">The UI.</param> public void AddFrameXml(XElement ui) { if (ui == null) throw new ArgumentNullException("ui"); // Select all elements in the FrameXML that has a name ui.XPathSelectElements("/descendant::*[@name]").ForEach(element => this.AddFrameXmlElement(element)); }
public static LinkedInLikesSummary Parse(XElement xLikes) { return new LinkedInLikesSummary { Total = xLikes.GetAttributeValueOrDefault<int>("total"), Persons = ( from xPerson in xLikes.XPathSelectElements("like/person") select LinkedInPersonSummary.Parse(xPerson) ).ToArray() }; }
public void AddToForms(string xPath, XElement document, Element element) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes) { node.Add(AttributeHelper.AddNodeToForm(element)); } }
public void RemoveFromPackages(string xPath, XElement document, Element param) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes.Where(node => node.Name == "Form" && node.Attribute("Name") != null && node.Attribute("Name").Value == param.FormName)) { node.Remove(); } }
public void RemoveFromPackage(string xPath, XElement document, string package, string formName) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes.Where(node => node.HasAttributes && node.Attribute("Name") != null && node.Attribute("Name").Value == formName && node.Parent.Parent.Attribute("Name").Value == package)) { node.Remove(); } }
public void ReplaceInPdfs(string xPath, XElement document, Element previousParam, Element param) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes.Where(node => node.HasAttributes && node.Attribute("Name").Value == previousParam.PdfName && node.Attribute("File").Value == previousParam.PdfFilePath)) { node.Attribute("Name").Value = param.PdfName; node.Attribute("File").Value = param.PdfFilePath; } }
public void ReplaceFormNameInPackage(string xPath, XElement document, string package, string prevFormName, string formName) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes.Where(node => node.Name == "Form" && node.Parent.Parent.Attribute("Name").Value == package && node.Attribute("Name") != null && node.Attribute("Name").Value == prevFormName)) { node.Attribute("Name").Value = formName; } }
public void RemoveFromPdfs(string xPath, XElement document, Element param) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes.Where(node => node.HasElements == false && node.HasAttributes && node.Attribute("Name") != null && node.Attribute("Name").Value == param.PdfName && node.Attribute("File") != null && node.Attribute("File").Value == param.PdfFilePath)) { node.Remove(); } }
protected override IEnumerable<UserRoleMap> internalListAllUserRoleMaps(XElement lastx) { var elements = lastx.XPathSelectElements("//map"); foreach (var element in elements) { if (element.attr("code") == element.attr("code").ToLower()) { var rm = new UserRoleMap {User = element.attr("code").Replace("/","\\"), Role = element.attr("name").ToUpper()}; yield return rm; } } }
//public static void DetermineSelected(this XmlTreeNode node) //{ //} /// <summary> /// Determines if the node should be clickable based on the xpath given /// </summary> /// <param name="node">The node.</param> /// <param name="xpath">The xpath.</param> /// <param name="type">The type.</param> /// <param name="xml">The XML.</param> public static void DetermineClickable(this XmlTreeNode node, string xpath, XPathFilterType type, XElement xml) { if (!string.IsNullOrEmpty(xpath)) { try { var matched = xml.XPathSelectElements(xpath); if (matched.Count() > 0) { if (type == XPathFilterType.Disable) { //add the non-clickable color to the node node.Style.AddCustom("uc-treenode-noclick"); } else { //add the non-clickable color to the node node.Style.AddCustom("uc-treenode-click"); } } else { if (type == XPathFilterType.Disable) { //ensure the individual node is the correct color node.Style.AddCustom("uc-treenode-click"); } else { //ensure the individual node is the correct color node.Style.AddCustom("uc-treenode-noclick"); } } } catch (XPathException) { node.Text = "umbraco.editorControls: MNTP: XPath Error!"; } } else { if (type == XPathFilterType.Disable) { //ensure the individual node is the correct color node.Style.AddCustom("uc-treenode-click"); } else { //ensure the individual node is the correct color node.Style.AddCustom("uc-treenode-noclick"); } } }
public OlsonMapper(XElement xml) { var values = from m in xml.XPathSelectElements("*/mapTimezones/mapZone") where m.Attribute("territory").Value == "001" select new { TimeZoneId = m.Attribute("other").Value, OlsonId = m.Attribute("type").Value }; _mapping = values.ToDictionary(v => v.TimeZoneId, v => v.OlsonId); }
public static IEnumerable<Entity> GetEntities(XElement xml, DacpacExtractor extractor) { const string xpath = "/DataSchemaModel/Model/Element[@Type='SqlTable']"; var elements = xml.XPathSelectElements(xpath); foreach (var e in elements) { var entity = new Entity {TableName = e.GetAttributeString("Name"), IncludeForeignKey = extractor.IncludeForeignKey}; foreach (var pe in e.XPathSelectElements("Relationship[@Name='Columns']/Entry/Element[@Type='SqlSimpleColumn']")) { var nullableNode = pe.XPathSelectElement("Property[@Name='IsNullable']"); var identityNode = pe.XPathSelectElement("Property[@Name='IsIdentity']"); var p = new EntityProperty() { Nullable = nullableNode == null || nullableNode.GetAttributeBool("Value"), Identity = identityNode != null && identityNode.GetAttributeBool("Value"), Name = pe.GetAttributeString("Name"), Type = pe.XPathSelectElement("Relationship[@Name='TypeSpecifier']/Entry/Element[@Type='SqlTypeSpecifier' or @Type='SqlXmlTypeSpecifier']/Relationship[@Name='Type']/Entry/References").GetAttributeString("Name"), }; var over = extractor.ColumnOverrides.EmptyIfNull().FirstOrDefault(o => o.Name == p.Name); if (over != null) { p.Type = over.Type ?? p.Type; p.Nullable = over.Nullable ?? p.Nullable; p.Attributes = over.Attributes; over.Name = null; } if (p.Type.ToLower() != "[timestamp]" && p.Type.ToLower() != "[rowversion]" && !extractor.ObjectsToIgnore.EmptyIfNull().Contains(p.Name)) { entity.Properties.Add(p); } } foreach (var c in extractor.ColumnOverrides.EmptyIfNull()) { if (c.Name != null && c.Type != null && c.Name.StartsWith(entity.TableName)) { entity.Properties.Add(c); } } var an = extractor.EntityOverrides.EmptyIfNull().FirstOrDefault(ae => ae.TableName == entity.TableName); if (an != null) { entity.Annotations = an.Annotations; entity.Name = an.Name; entity.IncludeForeignKey = an.IncludeForeignKey; } if (!extractor.ObjectsToIgnore.EmptyIfNull().Contains(entity.TableName)) { yield return entity; } } }
public XElement Merge(XElement masterElement, XNode sourceElement) { var masterElementsWithIds = masterElement.XPathSelectElements("//*[@id]"); foreach (var masterElementWithId in masterElementsWithIds) { // ReSharper disable PossibleNullReferenceException var childElementWithSameId = sourceElement.XPathSelectElement("//*[@id='" + masterElementWithId.Attribute("id").Value + "']"); // ReSharper restore PossibleNullReferenceException if (childElementWithSameId != null) masterElementWithId.ReplaceWith(childElementWithSameId); } return masterElement; }
private static IQueryable<River> BuildRiversQuery( GeographyEntities context, XElement queryElement) { IQueryable<River> riversQuery = context.Rivers.AsQueryable(); foreach (var countryElement in queryElement.XPathSelectElements("country")) { var countryName = countryElement.Value; riversQuery = riversQuery.Where( r => r.Countries.Any(c => c.CountryName == countryName)); } riversQuery = riversQuery.OrderBy(r => r.RiverName); return riversQuery; }
public void AddToPdfs(string xPath, XElement document, Element element) { var nodes = document.XPathSelectElements(xPath); foreach (var node in nodes) { var newNode = new XElement("Pdf"); newNode.SetAttributeValue("Name", element.PdfName); newNode.SetAttributeValue("File", element.PdfFilePath); node.Add(newNode); } }
public static DayTypeConfiguration FromXml(XElement root) { lock (m_syncRoot) { Collection<DayType> dayTypes = new Collection<DayType>(); foreach (XElement type in root.XPathSelectElements("./configuration/dayTypes/type")) { string name = type.XPathSelectElement("name").Value; string description = type.XPathSelectElement("description").Value; dayTypes.Add(new DayType(name, description)); } return new DayTypeConfiguration(dayTypes); } }
public IEnumerable<string> ExtractPackages(string xPath, XElement document) { var nodes = document.XPathSelectElements(xPath); //var result = new List<string>(); foreach (var atttribute in nodes.Where(node => node.HasAttributes).Attributes()) { //result.Add(atttribute.Value); yield return atttribute.Value; } //return result; }
public static RatesConfiguration FromXml(XElement root) { lock (m_syncRoot) { Collection<Rate> rates = new Collection<Rate>(); foreach (XElement type in root.XPathSelectElements("./configuration/rates/rate")) { DateTime effectiveDate = Convert.ToDateTime(type.Attribute("effectiveDate").Value); decimal rate = Convert.ToDecimal(type.Attribute("amount").Value); rates.Add(new Rate(rate, effectiveDate)); } return new RatesConfiguration(rates); } }
//Если попадаются members у которых включающий их класс не был объявлен в XML документации, то создается класс, но у него не будет заполнено RawNode static TypeDoc[] ParseMembers(XElement members) { Dictionary<string, TypeDoc> types = members .XPathSelectElements("member[starts-with(@name,\"T:\")]") .Select(TypeDoc.Parse) .Where(t => !t.FullName.Contains("XamlGeneratedNamespace")) .ToDictionary(_ => _.FullName); foreach (var node in members.XPathSelectElements("member[not(starts-with(@name,\"T:\"))]")) { var member = MemberDoc.ParseMember(node); if (member != null) { TypeDoc type; if (types.TryGetValue(member.Name.FullClassName, out type)) { type.Members.Add(member); } else { type = new TypeDoc { FullName = member.Name.FullClassName }; type.Members.Add(member); if (!type.FullName.Contains("XamlGeneratedNamespace")) types.Add(type.FullName, type); } } else { //ToDo: сделать обработку типов(редкие,неиспользуемые) 'N'-namespace, '!' - error } } return types .Select(_ => _.Value) .ToArray(); }
public XElement Transform(XElement element) { // <a href="action.htm">Action Chart</a> foreach (var action in element.XPathSelectElements("//a[@href='action.htm']")) { // <button type="button" class="action-chart" onclick="Section.inventory();"> action.Name = "button"; action.RemoveAttributes(); action.Add(new XAttribute("type", "button")); action.Add(new XAttribute("class", "action-chart")); action.Add(new XAttribute("onclick", "Section.inventory();")); } return element; }
private static void AddGround(XElement root) { foreach (var elem in root.XPathSelectElements("//Ground")) { var type = (short)Utils.FromString(elem.Attribute("type").Value); var id = elem.Attribute("id").Value; ObjectTypeToId[type] = id; TypeToIdGround[type] = id; IdToObjectType[id] = type; TypeToElement[type] = elem; Tiles[type] = new TileDesc(elem); } }
/// <summary> /// Создание задачи из XML-определения /// </summary> /// <param name="declaration">XML-определение</param> /// <returns></returns> public ITask Parse(System.Xml.Linq.XElement declaration) { if (declaration == null) { throw new ArgumentNullException("Отсутствует определение задачи"); } _expression = declaration.Attribute("expression").Value; _tasks = new List <ITask>(); var taskNodes = declaration.XPathSelectElements(@"Task"); foreach (var taskNode in taskNodes) { _tasks.Add(Tasks.TaskFactory.Create(taskNode)); } return(this); }