/// <summary> /// /// </summary> /// <param name="key"></param> /// <returns></returns> private IEnumerable <Simple> ParseSimple(string key, Color color) { foreach (var way in Xdoc.Descendants("way")) { var id = way.Attribute("id").Value; if (way.Attribute("visible").Value != "true") { continue; } if (ways.Contains(id)) { continue; } var isKey = (from tag in way.Descendants("tag") where tag.Attribute("k").Value == key && tag.Attribute("v").Value != "no" select tag).Any(); if (isKey) { ways.Add(id); yield return(new Simple(id, way, CreateFootprint(way), color)); } } }
public void ImportFile(string importFile) { if (ColorCount == 0) { InitializeColorPalette(); } Log($"Importing theme from {importFile}."); var foundFile = false; //make sure file exists var myFileInfo = new FileInfo(importFile); if (myFileInfo.Exists) { foundFile = true; AddNewPalette(importFile); Xdoc.Save(_configFile); } else { //lets see if we can find the file name in the local directory var localFile = Path.Combine(_localPath, importFile); var myLocalFileInfo = new FileInfo(localFile); if (myLocalFileInfo.Exists) { foundFile = true; AddNewPalette(localFile); Xdoc.Save(_configFile); } } if (!foundFile) { Log($"We were unable to find the file specified: {importFile}"); } }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerable <BuildingPart> Buildings() { ways.Clear(); var compounds = ParseCompounds(); // Build first multipolygon building parts of complex buildings foreach (var building in Compounds(compounds, CompoundType.MultipolygonBuildingPart)) { yield return(building); } // Second are remaining multipolygon of complex buildings foreach (var building in Compounds(compounds, CompoundType.MultipolygonBuilding)) { yield return(building); } // Third are remaining simpler parts of complex buildings foreach (var building in Compounds(compounds, CompoundType.Building)) { yield return(building); } // Fourth remaining parts of simple buildings foreach (var building in ParseSimples()) { yield return(new BuildingPart(building.Id, building.Polygon, ParsePart(building.Data), ParseRoof(building.Data), building.Color)); } #if DEBUG Console.Clear(); var count = 0; foreach (var way in Xdoc.Descendants("way")) { var id = way.Attribute("id").Value; if (way.Attribute("visible").Value != "true") { continue; } if (ways.Contains(id)) { continue; } var build = from tag in way.Descendants("tag") where tag.Attribute("k").Value == "building" || tag.Attribute("k").Value == "building:part" select tag; if (build.Any()) { yield return(new BuildingPart(id, CreateFootprint(way), ParsePart(way), ParseRoof(way), Color.Red)); count++; Console.WriteLine("Way {0}: {1} = {2}", id, build.First().Attribute("k").Value, build.First().Attribute("v").Value); } } Console.WriteLine("{0}\nTotal remaining building structures = {1}", new String('-', 40), count); #endif }
public List <XElement> SearchEmployeeNode(string pEmployeeBeforeEditName, string pCompanyValue, string pDepartmentValue) { var employee = Xdoc.Elements("Ramais").Elements("Empresa").Where(i => i.Attribute("id").Value.Equals(pCompanyValue)).FirstOrDefault() .Elements("Funcionario").Where(e => e.Element("Nome").Value == pEmployeeBeforeEditName && e.Element("Departamento").Value == pDepartmentValue); return(employee.ToList()); }
public List <XElement> SearchEmployeeNode(string pEmployeeBeforeEditName, string pCompany) { var employee = Xdoc.Elements("Telefones").Elements("Empresa").Where(i => i.Attribute("id").Value == pCompany).FirstOrDefault() .Elements("Funcionario").Where(e => e.Element("Nome").Value == pEmployeeBeforeEditName); return(employee.ToList()); }
public void ImportFolder(string importFolder) { if (ColorCount == 0) { InitializeColorPalette(); } var path = (string.IsNullOrWhiteSpace(importFolder)) ? _localPath : importFolder; Log($"Looking for any themes in the folder: {path} "); var palettes = GetPalettes(path); if (palettes.Any()) { Log($"Found {palettes.Count()} files to import"); foreach (var palette in palettes) { AddNewPalette(palette); } Xdoc.Save(_configFile); } else { Log("No valid files found."); } }
protected virtual List <int> ParseXmlPattern() { var lastRowIndexes = new List <int>(); foreach (var worksheet in Xdoc.Element("document").Element("worksheets").Elements("worksheet")) { var worksheetName = worksheet.Attribute("name")?.Value; var wsheet = Excel.Workbook.Worksheets.Add(worksheetName); var rowIndex = 1; foreach (var row in worksheet.Element("rows").Elements("row")) { var columnIndex = 1; foreach (var header in row.Element("headers").Elements("header")) { var span = header.Attribute("span") == null ? 1 : int.Parse(header.Attribute("span").Value); wsheet.Cells[rowIndex, columnIndex, rowIndex, columnIndex + (span - 1)].Merge = true; wsheet.Cells[rowIndex, columnIndex].Value = header.Value; columnIndex += span; } rowIndex += 1; } lastRowIndexes.Add(rowIndex); } return(lastRowIndexes); }
public void Load(string path) { Initialize(); if (File.Exists(path) && Path.GetExtension(path) == Ext) { Xdoc.Load(path); } Xroot = Xdoc.SelectSingleNode("/" + EStruct); RootStruct = (GffRootStruct)CreateComponent(Xroot); }
// public IEnumerable<Building> Buildings() private void Buildings() { var ways = (from e in Xdoc.Descendants("way") where !Cache.Exist((string)e.Attribute("id")) where (string)e.Attribute("visible") == "true" from t in e.Descendants("tag") // warning: some nodes could contain both k,v pairs, use Distinct() since we don't want key duplicates where (string)t.Attribute("k") == "building" || (string)t.Attribute("k") == "building:part" select new { Key = (string)e.Attribute("id"), Value = e }).Distinct().ToDictionary(pair => pair.Key, pair => pair.Value); var relations = from e in Xdoc.Descendants("relation") where (string)e.Attribute("visible") == "true" from t in e.Descendants("tag") where (string)t.Attribute("k") == "type" && (string)t.Attribute("v") == "building" select new { Name = Name(e), Element = e }; // Process building parts from relations foreach (var rel in relations) { var building = new Building(rel.Name); XElement way; foreach (var m in rel.Element.Descendants("member")) { if ((string)m.Attribute("type") == "way") { string id = (string)m.Attribute("ref"); if (ways.TryGetValue(id, out way)) { var part = BuildPart(way, (string)m.Attribute("role") == "part" ? true : false); building.Parts.Add(part); ways.Remove(id); Cache.AddOrUpdate(id, part); } } } // yield return building; } // Process remaining standalone building foreach (var way in ways) { var part = BuildPart(way.Value); Cache.AddOrUpdate(way.Key, part); // yield return new Building(Name(way.Value), part); } }
private void WriteField(XmlElement n, GffComponent c) { var fld = (GffField)c; n.SetAttribute(AType, Enum.GetName(typeof(GffType), fld.Type)); var data = fld.Value; if (data != string.Empty) { n.AppendChild(Xdoc.CreateTextNode(data)); } }
public string Save() { if (IsFile) { Xdoc.Save(Xml); } else { Xml = Xdoc.ToString(); } return(IsFile ? "" : Xml); }
public bool BBox(double left, double bottom, double right, double top) { var mapRequest = OsmMapUrl + "bbox=" + left.ToString() + "," + bottom.ToString() + "," + right.ToString() + "," + top.ToString(); Xdoc = MakeRequest(mapRequest); if (!Xdoc.Equals(null)) { Tile = new TileBound(Mercator.ToMeters(top, left), Mercator.ToMeters(bottom, right)); Buildings(); return(true); } return(false); }
/// <summary> /// Load reads map information from a xml file /// </summary> /// <param name="filename"></param> /// <returns></returns> public bool Load(string filename) { Xdoc = XDocument.Load(filename); if (!Xdoc.Equals(null)) { double left = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("minlon").Value); double top = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("maxlat").Value); double right = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("maxlon").Value); double bottom = Convert.ToDouble(Xdoc.Root.Element("bounds").Attribute("minlat").Value); Tile = new TileBound(MercatorHelper.ToMeters(top, left), MercatorHelper.ToMeters(bottom, right)); return(true); } return(false); }
public List <Employee> LoadEmployee(string pRootNode, string pFirstNodeName, string pFirstNodeValue) { List <Employee> listEmployees = new List <Employee>(); var employees = Xdoc.Elements(pRootNode).Elements(pFirstNodeName).Where(i => i.Attribute("id").Value.Equals(pFirstNodeValue)).FirstOrDefault(); if (employees != null) { employees.Elements().ToList().ForEach(i => listEmployees.Add(new Employee { Name = i.Element("Nome").Value, MobilePhone = i.Element("Tel1").Value, TelePhone = i.Element("Tel2").Value })); } return(listEmployees.OrderBy(i => i.Name).ToList()); }
public void SaveXMLFIle(string pAction, Employee pEmployee, string pCompanyName) { Xdoc.Save(Path); Util utl = new Util(); utl.SendMail(String.Format("{0} {1} o telefone {2}, {3}, {4}, {5}", UserLogged, pAction, HttpUtility.HtmlDecode(pEmployee.Name), pEmployee.MobilePhone, pEmployee.TelePhone, pCompanyName), ConfigurationManager.AppSettings["emailDestinatarioLog"]); }
public void AddNewEmployee(Employee pEmployee, string company) { var employeeXElement = new List <XElement>(); employeeXElement.Add(new XElement("Nome", pEmployee.Name)); employeeXElement.Add(new XElement("Tel1", pEmployee.MobilePhone)); employeeXElement.Add(new XElement("Tel2", pEmployee.TelePhone)); var companyNode = Xdoc.Elements("Telefones").Elements("Empresa").Where(i => i.Attribute("id").Value == company).First(); companyNode.Add(new XElement("Funcionario")); companyNode.Elements("Funcionario").Last().Add(employeeXElement); SaveXMLFIle("adicionou", pEmployee, company); }
/// <summary> /// /// </summary> /// <returns></returns> private Dictionary <string, Compound> ParseCompounds() { var compounds = new Dictionary <string, Compound>(); foreach (var relation in Xdoc.Descendants("relation")) { if (relation.Attribute("visible").Value != "true") { continue; } var id = relation.Attribute("id").Value; var type = (from tag in relation.Descendants("tag") where tag.Attribute("k").Value == "type" select tag.Attribute("v").Value).FirstOrDefault(); switch (type) { case "building": compounds.Add(id, new Compound(CompoundType.Building, relation)); break; case "multipolygon": { var subtype = (from tag in relation.Descendants("tag") where tag.Attribute("k").Value == "building" || tag.Attribute("k").Value == "building:part" select tag.Attribute("k").Value).FirstOrDefault(); switch (subtype) { case "building": compounds.Add(id, new Compound(CompoundType.MultipolygonBuilding, relation)); break; case "building:part": compounds.Add(id, new Compound(CompoundType.MultipolygonBuildingPart, relation)); break; } } break; default: break; } } return(compounds); }
public void SaveXMLFIle(string pAction, Employee pEmployee, string pCompanyName, string pDepartament) { Xdoc.Save(Path); Util utl = new Util(); utl.SendMail(String.Format("{0} {1} o ramal {2}, {3}, {4}, {5} , {6}", UserLogged, pAction, HttpUtility.HtmlDecode(pEmployee.Name), HttpUtility.HtmlDecode(pEmployee.Initials), HttpUtility.HtmlDecode(pEmployee.Local), pEmployee.ExtentionLine, pDepartament, pCompanyName ), ConfigurationManager.AppSettings["emailDestinatarioLog"]); }
private void Write(XmlNode xRoot, GffComponent vChild) { XmlElement xChild; if (vChild is GffStruct) { xChild = Xdoc.CreateElement(EStruct); } else if (vChild is GffList) { xChild = Xdoc.CreateElement(EList); } else if (vChild is GffField) { xChild = Xdoc.CreateElement(EField); } else { throw new ComponentException("Type de composant inconnu."); } WriteLabel(xChild, vChild); var child = vChild as GffStruct; if (child != null) { WriteStruct(xChild, child); } else if (vChild is GffField) { WriteField(xChild, vChild); } xRoot.AppendChild(xChild); var composite = vChild as GffComposite; if (composite == null) { return; } var cvChild = composite; foreach (var vChild2 in cvChild) { Write(xChild, vChild2); } }
public void AddNewEmployee(Employee pEmployee, string company, string pDepartment) { var employeeXElement = new List <XElement>(); employeeXElement.Add(new XElement("Nome", pEmployee.Name)); employeeXElement.Add(new XElement("Sigla", pEmployee.Initials)); employeeXElement.Add(new XElement("Local", pEmployee.Local)); employeeXElement.Add(new XElement("Ramal", pEmployee.ExtentionLine)); employeeXElement.Add(new XElement("Departamento", pDepartment)); var companyNode = Xdoc.Elements("Ramais").Elements("Empresa").Where(i => i.Attribute("id").Value == company).First(); companyNode.Add(new XElement("Funcionario")); companyNode.Elements("Funcionario").Last().Add(employeeXElement); SaveXMLFIle("adicionou", pEmployee, company, pDepartment); }
public IEnumerable <YahooStat> LoadStats( string playerId, string season, string week) { return(Xdoc.Element("stat-list") .Elements("stat") .Where(e => e.Attribute("id").Value == playerId && e.Attribute("season").Value == season && e.Attribute("week").Value == week) .Select(r => new YahooStat { Id = ( string )r.Attribute("id"), Season = ( string )r.Attribute("season"), Week = ( string )r.Attribute("week"), Qty = ( decimal )r.Attribute("qty") } )); }
public BuildingPart BuildPart(XElement way, bool volume = true) { var tags = way.Descendants("tag") .ToDictionary( tag => tag.Attribute("k").Value, // add key tag => tag.Attribute("v").Value); // add value // Building creation var buildingPart = new BuildingPart( tags.ContainsKey("name") ? tags["name"] : "", Convert.ToInt64(way.Attribute("id").Value)); // Outline construction // TODO check if closed? foreach (var elt in way.Descendants("nd")) { // find node that matches ways' node ref var query = (from node in Xdoc.Descendants("node") where (string)node.Attribute("id") == (string)elt.Attribute("ref") select node).First(); var pos = Mercator.ToMeters(Convert.ToDouble(query.Attribute("lat").Value), Convert.ToDouble(query.Attribute("lon").Value)); var x = pos.X - Tile.Center.X; var y = pos.Y - Tile.Center.Y; buildingPart.Outline.Add(new Vector2(x, y)); } // Part data PartData part; part.volume = volume; part.height = float.Parse(tags.ContainsKey("height") ? Regex.Match(tags["height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture); part.min_height = float.Parse(tags.ContainsKey("min_height") ? Regex.Match(tags["min_height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture); part.levels = Convert.ToInt16(tags.ContainsKey("building:levels") ? tags["building:levels"] : "-1"); part.min_level = Convert.ToInt16(tags.ContainsKey("building:min_level") ? tags["building:min_level"] : "-1"); buildingPart.Data = part; Surface surf; surf.colour = tags.ContainsKey("building:colour") ? tags["building:colour"] : ""; surf.material = tags.ContainsKey("building:material") ? tags["building:material"] : ""; buildingPart.PartSurface = surf; return(buildingPart); }
/// <summary> /// NATURAL /// Support for Natural like map elements /// TODO: /// - Trees: rows, woods. /// - other naturals /// </summary> /// <returns></returns> public IEnumerable <Natural> Natural() { var nodes = (from e in Xdoc.Descendants("node") where e.Attribute("visible").Value == "true" from t in e.Descendants("tag") where t.Attribute("k").Value == "natural" && t.Attribute("v").Value == "tree" select new { Id = e.Attribute("id").Value, Name = t.Attribute("v").Value, Lat = Convert.ToDouble(e.Attribute("lat").Value), Long = Convert.ToDouble(e.Attribute("lon").Value), Element = e }); foreach (var node in nodes) { NaturalData data = default(NaturalData); data.circumference = DefaultTreeCircumference; data.height = DefaultTreeHeight; foreach (var tag in node.Element.Descendants("tag")) { switch (tag.Attribute("k").Value.ToLower()) { case "genus": data.genus = tag.Attribute("v").Value; break; case "leaf_type": data.leaf_type = tag.Attribute("v").Value; break; case "circumference": MatchFloat(tag.Attribute("v").Value, out data.circumference); break; case "height": MatchFloat(tag.Attribute("v").Value, out data.height); break; } } var pos = MercatorHelper.ToMeters(node.Lat, node.Long); yield return(new Natural(node.Id, new Vector2(pos.X - Tile.Center.X, pos.Y - Tile.Center.Y), data)); } }
public void Save(GffRootStruct root, string path) { Initialize(); _rootStruct = root; FileStream fs; if (File.Exists(path)) { fs = new FileStream(path, FileMode.Truncate); } else { fs = new FileStream(path, FileMode.Create); } Xdoc.AppendChild(Xdoc.CreateXmlDeclaration("1.0", LatinEncoding.Name, "yes")); Write(Xdoc, _rootStruct); Xdoc.Save(fs); fs.Close(); }
private void button4_Click(object sender, EventArgs e) { ServiceReference3.WebService1SoapClient soap = new ServiceReference3.WebService1SoapClient(); //string xml = dataSet.GetXml(); try { XDocument Xdoc = new XDocument(new XElement("Users")); if (System.IO.File.Exists("D:\\LessonManagerApp.xml")) { Xdoc = XDocument.Load("D:\\LessonManagerApp.xml"); } else { Xdoc = new XDocument(); XElement xmlstart = new XElement("Users"); Xdoc.Add(xmlstart); } XElement xml1 = /*new XElement("Users",*/ new XElement("User", new XElement("StartTime", textBox1.Text), new XElement("Duration", customControl11.Text), new XElement("Notes", textBox3.Text), new XElement("Instructor_ID", comboBox1.Text)); if (Xdoc.Descendants().Count() > 0) { Xdoc.Descendants().First().Add(xml1); } else { Xdoc.Add(xml1); } Xdoc.Element("Users").Save("D:\\LessonManagerApp.xml"); soap.UploadNotes("xml1"); MessageBox.Show("Uploaded Successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public List <Employee> LoadEmployee(string pRootNode, string pFirstNodeName, string pFirstNodeValue, string pFirstNodeAttributeName, string pFirstNodeAttributeValue) { List <Employee> listEmployees = new List <Employee>(); var employees = Xdoc.Elements(pRootNode).Elements(pFirstNodeName).Where(i => i.Attribute("id").Value == pFirstNodeValue).FirstOrDefault(); if (employees != null) { employees.Elements().Where(i => i.Element(pFirstNodeAttributeName).Value.Equals(pFirstNodeAttributeValue)).ToList() .ForEach(i => listEmployees.Add(new Employee { Name = i.Element("Nome").Value, Initials = i.Element("Sigla").Value, Local = i.Element("Local").Value, ExtentionLine = i.Element("Ramal").Value, Department = i.Element("Departamento").Value })); } return(listEmployees.OrderBy(i => i.Name).ToList()); }
public ColorPalette(ConfigOptions config) { var configFolder = config.ConfigurationFolder; _configFile = Path.Combine(configFolder, FileName); _localPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); SchemaSet = SetXmlSchema(config.XmlValidation); Xdoc = XDocument.Load(_configFile); Vanilla = Xdoc.Descendants().First(key => (string)key.Attribute("name") == ".Vanilla"); Build = Vanilla.AttributeOrEmpty("build").Value; if (config.BackupConfiguration) { BackupConfiguration(configFolder, _configFile); } ColorCount = Vanilla.Descendants().Count(key => (string)key.Attribute("name") == "Colors"); InstalledThemes = ColorCount == 0 ? new List <string>() : GetInstalledPalettes(); }
/// <summary> /// Candidate for memoization? /// </summary> /// <param name="id"></param> /// <returns></returns> private XElement FindWayById(string id) { return((from node in Xdoc.Descendants("way") where node.Attribute("id").Value == id select node).FirstOrDefault()); }
public XElement Element(XName xname) { return(Xdoc.Element(xname)); }
public IEnumerable <XElement> Elements(XName xname) { return(Xdoc.Elements(xname)); }