private XElement LocationFromService(string urn) { XElement reply = new XElement("root", null); reply = null; if (Locations.Elements().Any()) { reply = ( from x in Locations.Elements("Location") where x.Element("Epc").Value.ToString().Equals(urn) select new XElement(x) ).FirstOrDefault(); } if (reply == null) { ServiceReference1.NamingServiceClient client = new ServiceReference1.NamingServiceClient(); reply = client.GetLocation(urn); client.Close(); reply = (XElement)reply.Element("Location"); Locations.Add(reply); } return(reply); }
private XElement VehicleFromService(string urn) { XElement reply = new XElement("root", null); reply = null; if (Vehicles.Elements().Any()) { reply = ( from x in Vehicles.Elements("Fordon") where x.Element("EPC").Value.Equals(urn) select new XElement(x) ).FirstOrDefault(); } if (reply == null) { ServiceReference1.NamingServiceClient client = new ServiceReference1.NamingServiceClient(); reply = client.GetVehicle(urn); client.Close(); XElement reply2; if (reply.Elements("Fordonsindivider").Any()) { reply2 = new XElement ( "Fordon", new XElement("EPC", urn), (reply.Element("Fordonsindivider").Element("FordonsIndivid").Elements("Fordonsnummer").Any()) ? new XElement("EVN", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Fordonsnummer").Value) : null, (reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Fordonsinnehavare").Elements("Foretag").Any()) ? new XElement("Fordonsinnehavare", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Fordonsinnehavare").Element("Foretag").Value) : null, (reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("UnderhallsansvarigtForetag").Elements("Foretag").Any()) ? new XElement("UnderhallsansvarigtForetag", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("UnderhallsansvarigtForetag").Element("Foretag").Value) : null, (reply.Element("FordonsTyp").Elements("FordonskategoriKodFullVardeSE").Any()) ? new XElement("FordonsTyp", reply.Element("FordonsTyp").Element("FordonskategoriKodFullVardeSE").Value) : null, (reply.Element("FordonsTyp").Elements("FordonsunderkategoriKodFullVardeSE").Any()) ? new XElement("FordonsunderkategoriKodFullVardeSE", reply.Element("FordonsTyp").Element("FordonsunderkategoriKodFullVardeSE").Value) : null, (reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Elements("FordonsgodkannandeFullVardeSE").Any()) ? new XElement("FordonsgodkannandeFullVardeSE", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Element("FordonsgodkannandeFullVardeSE").Value): null, (reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Elements("GiltigtTom").Any()) ? new XElement("GiltigtTom", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Element("GiltigtTom").Value): null, (reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Elements("GiltigtFrom").Any()) ? new XElement("GiltigtFrom", reply.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Element("GiltigtFrom").Value): null ); } else { reply2 = new XElement ( "Fordon", new XElement("EPC", urn) ); } Vehicles.Add(reply2); return(reply2); } return(reply); }