/// <summary> /// Endpoint to get all locations /// </summary> /// <param name="xml"></param> /// <returns></returns> public XElement GetAllLocations() { NamingServiceClient namingClient = new NamingServiceClient(); XElement result = namingClient.GetAllLocations(); namingClient.Close(); XElement response = GetResponseInfo(new XElement("Response"), "OK", "OK"); response.Add(new XElement("Platser", result.Element("Locations").Elements("Location").Select(x => new XElement("Plats", new XElement("PlatsEPC", x.Element("Epc").Value), new XElement("PlatsNamn", x.Element("Name").Value) )) )); return response; }
// GET: Vehicle public ActionResult Index() { NamingServiceClient namingService = new NamingServiceClient(); // VehicleServiceClient vehicleService = new VehicleServiceClient(); XElement xmlResponse = namingService.GetAllLocations(); List <string> locationList = (from location in xmlResponse.Descendants("Location") select location.Element("Name").Value).ToList(); List <SelectListItem> listOfLocations = new List <SelectListItem>(); foreach (var a in xmlResponse.Descendants("Location")) { listOfLocations.Add(new SelectListItem { Text = a.Element("Name").Value.ToString(), Value = a.Element("Name").Value.ToString() + "*" + a.Element("Epc").Value.ToString() }); } ViewBag.ListOfLocations = listOfLocations; // (DateTime start, DateTime end, String locationEPC, string location, string user) DateTime start = new DateTime(2011, 03, 25); DateTime end = new DateTime(2011, 03, 28); String locationEPC = "urn:epc:id:sgln:735999271.000.12"; string locationn = "Göteborg"; string user = "******"; // XElement xmlTest = vehicleService.XmlAnswer(start, end, locationEPC, locationn, user); return(View()); }
/// <summary> /// End point to get FordonPasssage /// </summary> /// <param name="request">XElement containing Start, End and location EPC</param> /// <returns>Fordonspassage Element</returns> public XElement GetFordonPassage(XElement request) { //Instansiera klinter för services EpcisEventServiceClient eventClient = new EpcisEventServiceClient(); NamingServiceClient namingClient = new NamingServiceClient(); //Kolla så att requestens element är valida XElement response = GetResponseInfoAndCheckRequest(request); if(response.Element("Svarsinformation").Element("Svarskod").Value != "OK") { return response; } //Inputvariabler definieras DateTime start = (DateTime)request.Element("Start"); DateTime end = (DateTime)request.Element("End"); string epc = (string)request.Element("EPC"); int sida; int resultatPerSida; if(request.Elements("Sida").Any()) { sida = (int)request.Element("Sida"); } else { sida = 1; } if(request.Elements("ResultatPerSida").Any()) { resultatPerSida = (int)request.Element("ResultatPerSida"); } else { resultatPerSida = 10; } //Hämta events XNamespace ns = "urn:epcglobal:epcis:xsd:1"; IEnumerable<XElement> result = eventClient.GetEvents(start, end, epc); eventClient.Close(); List<XElement> objEvents = new List<XElement>(); //Hämta ut OjbectEventelement foreach (XElement epcisdoc in result) { objEvents.AddRange(epcisdoc.Elements("EPCISBody").Elements("EventList").Elements("ObjectEvent")); } //Hämta antalet träffar int hits = objEvents.Count(); //Skip och take för pagination int skip = (sida - 1) * resultatPerSida; objEvents = objEvents.Skip(skip).Take(resultatPerSida).ToList(); XElement fordonsPassager = new XElement("FordonsPassager"); //int antalSidor = (int)Math.Ceiling((decimal)((int)hits / resultatPerSida)); int antalSidor; if(hits % resultatPerSida == 0) { antalSidor = hits / resultatPerSida; } else { antalSidor = (int)Math.Floor((double)hits / (double)resultatPerSida) + 1; } //Hämta alla locations, går snabbare än att hämta varje // XElement locations = namingClient.GetAllLocations().Element("Locations"); XElement location = GetLocationFromEpc(epc); namingClient.Close(); //Iterera igenom events för att populera resposne foreach(XElement objEvent in objEvents) { //Hämta location data //XElement location = locations.Elements("Location").Where(l => l.Element("Epc").Value == (objEvent.Element("readPoint").Element("id").Value)).First(); //Skapa fordonspassageelementet fordonsPassager.Add(new XElement("FordonsPassage", GetVehicleFromEpc(objEvent.Element("epcList").Element("epc").Value), location, new XElement("Tid", objEvent.Element("eventTime").Value) )); } //Lägg till fordonspassage i responseobjektet response.Add(fordonsPassager); response.Element("Svarsinformation").Add( new XElement("Sida", sida), new XElement("Träffar", hits), new XElement("AntalSidor", antalSidor), new XElement("ResultatPerSida", resultatPerSida) ); return response; }
/// <summary> /// Endpoint to search vehicles on EPC /// </summary> /// <param name="epc"></param> /// <returns>An XElement containing vehicle information formatted to fit the Fordon class</returns> public XElement GetVehicleFromEpc(string epc) { NamingServiceClient namingClient = new NamingServiceClient(); XElement specificVehicle = namingClient.GetVehicle(epc); namingClient.Close(); if (specificVehicle.Element("ResponseData").Elements("ResponseMessage").Any()) { return new XElement("Fordon", new XElement("FordonsEPC", epc)); } XElement godkännande; //Skapa godkännandeelement try { godkännande = new XElement("Godkännande", new XElement("GiltigtFrom", specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Element("GiltigtFrom").Value) ); } catch(NullReferenceException) { godkännande = new XElement("Godkännande", new XElement("GiltigtFrom", "NoVehicleException") ); } //Kontrollera om giltigt godkännande if (specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Elements("Godkannanade").Elements("GiltigtTom").Any()) { godkännande.Add( new XElement("GiltigtTom", specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Element("Godkannande").Element("GiltigtTom").Value), new XElement("Godkänd", "Ej godkänd") ); } else { godkännande.Add(new XElement("Godkänd", "Godkänd")); } XElement specificVehicleRelevantData = new XElement("Fordon", new XElement("FordonsEPC", epc), new XElement("FordonsEVN", (string)specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Element("Fordonsnummer")), new XElement("Fordonsinnehavare", (string)specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Element("Fordonsinnehavare").Element("Foretag")), new XElement("Underhållsansvarig", (string)specificVehicle.Element("Fordonsindivider").Element("FordonsIndivid").Element("UnderhallsansvarigtForetag").Element("Foretag")), new XElement("Fordonstyp", (string)specificVehicle.Element("FordonsTyp").Element("FordonskategoriKodFullVardeSE")), godkännande ); return specificVehicleRelevantData; }
public XElement GetLocationFromEpc(string epc) { NamingServiceClient namingClient = new NamingServiceClient(); XElement specificLocation = namingClient.GetLocation(epc); XElement specificLocationRelevantData = new XElement("Plats", new XElement("PlatsEPC", (string)specificLocation.Element("Location").Element("Epc")), new XElement("PlatsNamn", (string)specificLocation.Element("Location").Element("Name")) ); return specificLocationRelevantData; }
public NamingServiceConnection(string url) { target = url; channel = ChannelPool.Instance.ForUrl(target); client = new NamingServiceClient(channel); }