public async void GetRouteInfo() { string response = string.Empty; try { await Task.Run(() => { URL url = new URL(string.Format("https://maps.googleapis.com/maps/api/directions/json?" + "origin={0},{1}&destination={2},{3}&key={4}", 47.636372, -122.126888, 47.639466, -122.130665, "AIzaSyCn2XMz_4-GjsAu2Ge1M6h8mFBVpResBYs")); HttpsURLConnection urlConnection = (HttpsURLConnection)url.OpenConnection(); urlConnection.Connect(); var stream = urlConnection.InputStream; using (var streamReader = new StreamReader(stream)) { response = streamReader.ReadToEnd(); } }); } catch (Exception e) { var x = e.Message; } if (Routes != null) { Routes.Remove(); } RouteLine = GetPolylines(response); RouteLine.InvokeColor(-65536); RouteLine.InvokeWidth(5); Routes = googleMap.AddPolyline(RouteLine); }
//Drawing line on panel private void drawLine(RouteLine line) { Graphics G = drawingPanel.CreateGraphics(); G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; G.DrawLine(line.pen, line.firstPoint, line.lastPoint); }
private void InitGui() { InitSetting(); CalculateRate(); // InitPlayerItemList(); // InitMarkItemList(); _safeCircle = new BaneCircle(safeDuquanRoot, false, true); _duquanCircle = new BaneCircle(curDuquanRoot, true, true); _bombArea = new BombArea(curBombAreaRoot); _safeMiniDis = new SafeMiniDis(miniDisRoot); if (!MapLevel.Min.Equals(adapter.MapLevel)) { // _mapGird = new MapGird(lineRoot); // _mapGird1 = new MapGird1(girdRoot); } _mapGird1 = new MapGird1(girdRoot); InitMapBg(); _airPlane = new AirPlane(kTouRoot, Loader); _routeLine = new RouteLine(routeRoot); _mapLabel = new MapLabel(labelRoot); _mapPlayer = new MapPlayer(playItemRoot); _mapMark = new MapMark(markRoot); _bioMark = new BioMark(bioMarkRoot); PreparedSprite(); }
public async void OnMapReady(GoogleMap googleMap) { this.googleMap = googleMap; googleMap.MyLocationEnabled = true; this.googleMap.UiSettings.MyLocationButtonEnabled = true; googleMap.UiSettings.ScrollGesturesEnabled = true; MarkerOptions mrkerBagLocation = new MarkerOptions(); mrkerBagLocation.SetPosition(new LatLng(Double.Parse(ViewModel.BagLatitude), Double.Parse(ViewModel.BagLongitude))); mrkerBagLocation.SetTitle("Bag Location"); MarkerOptions mrkerUserLocation = new MarkerOptions(); mrkerUserLocation.SetPosition(new LatLng(47.639466, -122.130665)); mrkerUserLocation.SetTitle("Your Location"); googleMap.AddMarker(mrkerUserLocation); googleMap.AddMarker(mrkerBagLocation); googleMap.MoveCamera(CameraUpdateFactory.NewLatLng(new LatLng(47.639466, -122.130665))); var x = await GetRouteInfo(); RouteLine = GetPolylines(x); RouteLine.InvokeColor(-65536); RouteLine.InvokeWidth(5); Routes = googleMap.AddPolyline(RouteLine); }
public ActionResult Create(RouteLineViewModel svm, string Command) { RouteLine s = Mapper.Map <RouteLineViewModel, RouteLine>(svm); Route temp = new RouteService(_unitOfWork).Find(s.RouteId); if (ModelState.IsValid) { if (s.CityId == 0) { PrepareViewBag(svm); return(View(svm).Danger("Please fill City")); } s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; _RouteLineService.Create(s); _unitOfWork.Save(); return(RedirectToAction("Create").Success("Data saved successfully")); } PrepareViewBag(svm); return(View(svm)); }
public ActionResult _Edit(int id) { RouteLine temp = _RouteLineService.GetRouteLine(id); RouteLineViewModel s = Mapper.Map <RouteLine, RouteLineViewModel>(temp); PrepareViewBag(s); if (temp == null) { return(HttpNotFound()); } return(PartialView("_Create", s)); }
public ActionResult Delete(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RouteLine RouteLine = _RouteLineService.GetRouteLine(id); if (RouteLine == null) { return(HttpNotFound()); } return(View(RouteLine)); }
private async Task ProcessNewMessage(Station station, Message message) { try { RouteDirection direction = Enum.Parse <RouteDirection>(message.Label, true); DateTime expiration = DateTime.UtcNow.AddMinutes(2); try { expiration = message.ExpiresAtUtc.AddMinutes(2); // Add two minutes as a buffer. } catch (Exception) { /* Ignore. */ } ServiceBusMessage messageBody = JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body)); Tuple <Station, RouteDirection> key = this.MakeKey(station, direction); List <RealtimeData> newData = (await Task.WhenAll(messageBody.Messages.Select(async realtimeMessage => { var realtimeData = new RealtimeData() { ExpectedArrival = realtimeMessage.LastUpdated.AddSeconds(realtimeMessage.SecondsToArrival), ArrivalTimeMessage = realtimeMessage.ArrivalTimeMessage, Headsign = realtimeMessage.Headsign, LastUpdated = realtimeMessage.LastUpdated, LineColors = realtimeMessage.LineColor.Split(',').Where(color => !string.IsNullOrWhiteSpace(color)).ToList(), DataExpiration = expiration }; RouteLine route = null; try { route = await this.pathDataRepository.GetRouteFromTrainHeadsign(realtimeData.Headsign, realtimeData.LineColors); } catch (Exception ex) { Log.Logger.Here().Warning(ex, "Failed to lookup route during realtime message update."); } realtimeData.Route = route; return(realtimeData); }))).ToList(); this.realtimeData.AddOrUpdate(key, newData, (ignored, oldData) => newData[0].LastUpdated > oldData[0].LastUpdated ? newData : oldData); } catch (Exception ex) { Log.Logger.Here().Error(ex, $"Unexpected error reading a service bus message for {station}."); } }
public static OLocation CreateDeco(RouteLine routeLine) { var entity = LookupEntity(routeLine.GetAccNumber()); if (entity == null || entity.Decos.Count == 0) { return(new OLocation() { Id = null, Reference = null }); } var decoId = entity.Decos.Select(x => x.DecoId).FirstOrDefault(); var deco = _api.ExecuteRequest(new LoadLocation(_api.Context, decoId)).Data; deco.Id = ReplaceId(deco.Id); deco.ClientId = "382"; return(deco); }
public ActionResult DeletePost(RouteLineViewModel vm) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); RouteLine RouteLine = _RouteLineService.GetRouteLine(vm.RouteLineId); LogList.Add(new LogTypeViewModel { ExObj = RouteLine, }); _RouteLineService.Delete(vm.RouteLineId); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("EditSize", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Route).DocumentTypeId, DocId = RouteLine.RouteId, DocLineId = RouteLine.RouteLineId, ActivityType = (int)ActivityTypeContants.Deleted, xEModifications = Modifications, })); return(Json(new { success = true })); }
private static void GetLines(XmlNode linesNode, int currentIDNumeric, List <RouteLine> lines, List <RouteStop> stops) { foreach (XmlElement line in linesNode) { int lineID = int.Parse(line.Attributes["id"].Value); string lineName = line.Attributes["publicName"].Value; RouteLine currentLine = new RouteLine(lineID, lineName, currentIDNumeric); lines.Add(currentLine); foreach (XmlElement route in line) { int currentRouteID = int.Parse(route.Attributes["route_id"].Value); string currentRouteName = route.Attributes["publicName"].Value; Route currentRoute = new Route(currentRouteID, currentRouteName); var currentChildNode = route.ChildNodes[0]; int currentChildID = int.Parse(currentChildNode.Attributes["id"].Value); RouteStop currentStop = null; try { var tempStop = stops.Where(x => x.PublicID == currentChildID).First(); currentStop = tempStop.Clone() as RouteStop; } catch (InvalidOperationException) { currentStop = new RouteStop(currentChildID, "MISSING!"); } for (int i = 1; i < route.ChildNodes.Count; i++) { if (route.ChildNodes[i].Name == "stopRef") { currentRoute.Stops.Add(currentStop); currentChildNode = route.ChildNodes[i]; currentChildID = int.Parse(currentChildNode.Attributes["id"].Value); try { var tempStop = stops.Where(x => x.PublicID == currentChildID).First(); currentStop = tempStop.Clone() as RouteStop; } catch (InvalidOperationException) { currentStop = new RouteStop(currentChildID, "MISSING!"); } } else { string lat = route.ChildNodes[i].Attributes["lat"].Value; string lon = route.ChildNodes[i].Attributes["lon"].Value; StopLocation currentStopLocation = new StopLocation(lat, lon); currentStop.StopLocations.Add(currentStopLocation); } } currentRoute.Stops.Add(currentStop); currentLine.LineRoute.Add(currentRoute); } } }
static void Main() { XmlDocument routes = new XmlDocument(); string fullPath = @"C:\Users\Kickass\Desktop\Ceco\DEMO_routes_aaa.xml"; routes.Load(@"C:\Users\Kickass\Desktop\Ceco\DEMO_routes_aaa.xml"); var nodes = routes.DocumentElement.SelectNodes("/transportationNetwork/vehicleType"); List <RouteStop> stops = new List <RouteStop>(); List <RouteLine> lines = new List <RouteLine>(); foreach (XmlElement vehicleTypeNode in nodes) { var currentId = vehicleTypeNode.Attributes["id"]; int currentIDNumeric = int.Parse(currentId.Value); var stopsNode = vehicleTypeNode.FirstChild; var linesNode = vehicleTypeNode.LastChild; GetStops(stopsNode, stops); GetLines(linesNode, currentIDNumeric, lines, stops); } string dirPath = Path.GetDirectoryName(fullPath); Directory.CreateDirectory(dirPath + "\\Processed Routes"); #region XmlWriterSettings XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; #endregion WriteProcessedRoutes(lines, dirPath, settings); XmlDocument timetables = new XmlDocument(); string fullTimetablesPath = @"C:\Users\Kickass\Desktop\Ceco\timetables_aaa.xml"; timetables.Load(fullTimetablesPath); var mainNodes = timetables.DocumentElement.SelectNodes("/schedules/vehicleType"); List <int> timetableLineOrder = new List <int>(); List <RouteStop> timetableStops = new List <RouteStop>(); ExtractTimetableTimes(mainNodes, stops, timetableLineOrder, timetableStops); foreach (var line in timetableLineOrder) { List <RouteStop> currentStops = new List <RouteStop>(); foreach (var stop in timetableStops) { foreach (var schedule in stop.LineToStopSchedule) { if (schedule.LineID == line) { currentStops.Add(stop); break; } } } RouteStop[] orderedStops = null; try { orderedStops = currentStops.OrderBy(x => x.LineToStopSchedule.Where(y => y.LineID == line).First().TimeAtStop[0]).ToArray(); } catch (Exception ex) { MessageBox.Show(ex.Message); } RouteLine currentLine = null; try { currentLine = lines.Where(x => x.LineID == line).First(); } catch (NullReferenceException) { MessageBox.Show("Invalid TimeTable data"); } catch (Exception ex) { MessageBox.Show(ex.Message); } Directory.CreateDirectory(String.Format("{0}\\Processed Routes\\{1}\\Timetables", dirPath, currentLine.Name)); int tripCounter = 1; int indexCounter = 0; bool loopAlive = true; while (loopAlive) { string currentFileName = String.Format("{0}\\Processed Routes\\{1}\\Timetables\\{2}.xml", dirPath, currentLine.Name, tripCounter); using (XmlWriter writer = XmlWriter.Create(currentFileName, settings)) { writer.WriteStartElement("schedules"); writer.WriteStartElement("vehicleType"); writer.WriteAttributeString("id", currentLine.VehicleType.ToString()); foreach (var stop in orderedStops) { var currentLineToStopSchedule = stop.LineToStopSchedule.Where(x => x.LineID == line).First(); writer.WriteStartElement("stopRef"); writer.WriteAttributeString("id", stop.PublicID.ToString()); try { writer.WriteStartElement("lineRef"); writer.WriteAttributeString("id", line.ToString()); writer.WriteValue(currentLineToStopSchedule.TimeAtStop[indexCounter].TimeOfDay.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); } catch (ArgumentOutOfRangeException) { if (tripCounter < currentStops.Max(x => x.LineToStopSchedule[line].TimeAtStop.Count)) { MessageBox.Show(String.Format("There are missing times in Stop ID: {0}, Line ID: {1} at Trip: {2}", stop.PublicID, currentLine.LineID, tripCounter)); writer.WriteElementString("lineRef", line.ToString()); } else { MessageBox.Show("Writing Timetables finished succesfully"); writer.Flush(); return; } } } } tripCounter++; indexCounter++; } } }
public void Update(RouteLine s) { s.ObjectState = ObjectState.Modified; _unitOfWork.Repository <RouteLine>().Update(s); }
public void Delete(RouteLine s) { _unitOfWork.Repository <RouteLine>().Delete(s); }
public RouteLine Create(RouteLine S) { S.ObjectState = ObjectState.Added; _unitOfWork.Repository <RouteLine>().Insert(S); return(S); }
//Routing Methods public void receivePacket(PacketClass packet) { int btnSizeMargin = 30; Point firstPoint = new Point(packet.originAddress.x + btnSizeMargin, packet.originAddress.y + btnSizeMargin); Point secondPoint = new Point(this.nodeAddress.x + btnSizeMargin, this.nodeAddress.y + btnSizeMargin); Point destinationPoint = new Point(packet.destinationAddress.x + btnSizeMargin, packet.destinationAddress.y + btnSizeMargin); if (packet.packetType == PacketClass.PacketType.Acknowledgement_Type) { //Line between two pens with custom pen: color + Dashed/Solid RouteLine line = new RouteLine(firstPoint, secondPoint, DrawingPen.Pen.redDashedPen); drawLine(line); if (GlobalVariable.IsBeelineEnabled) { RouteLine beeline = new RouteLine(firstPoint, destinationPoint, DrawingPen.Pen.blackDashedPen); drawLine(beeline); } } else { RouteLine line = new RouteLine(firstPoint, secondPoint, DrawingPen.Pen.orangeDashedPen); drawLine(line); if (GlobalVariable.IsBeelineEnabled) { RouteLine beeline = new RouteLine(firstPoint, destinationPoint, DrawingPen.Pen.blueSolidPen); drawLine(beeline); } } Console.WriteLine("Receiving packet at Node " + this.nodeID + " From OriginAddress x:" + packet.originAddress.x); packet.originAddress = this.nodeAddress; if (GlobalVariable.IsManual) { //Manual Routing if (packet.destinationAddress != this.nodeAddress) { //Step by step route until reaches destination OnManualStep(this, packet); } else { OnPacketReachingDestination(this, packet); if (packet.packetType == PacketClass.PacketType.Message_Type) { packet = new PacketClass(packet.sourceAddress, packet.destinationAddress, this.nodeAddress, GlobalVariable.KVAcknowledgment, PacketClass.PacketType.Acknowledgement_Type); OnManualStep(this, packet); //Resend packet to route acknowledgement } } } else { //Automatic Routing if (packet.destinationAddress != this.nodeAddress) { //Route until reaches destination sendPacket(packet); } else { OnPacketReachingDestination(this, packet); if (packet.packetType == PacketClass.PacketType.Message_Type) { packet = new PacketClass(packet.sourceAddress, packet.destinationAddress, this.nodeAddress, GlobalVariable.KVAcknowledgment, PacketClass.PacketType.Acknowledgement_Type); this.sendPacket(packet); //Resend packet to route acknowledgement } } } }
public ActionResult _CreatePost(RouteLineViewModel svm) { RouteLine s = Mapper.Map <RouteLineViewModel, RouteLine>(svm); Route temp = new RouteService(_unitOfWork).Find(s.RouteId); //if (Command == "Submit" && (s.ProductId == 0)) // return RedirectToAction("Submit", "Route", new { id = s.RouteId }).Success("Data saved successfully"); if (s.CityId == 0) { PrepareViewBag(svm); return(View(svm).Danger("Please fill City")); } if (ModelState.IsValid) { if (svm.RouteLineId == 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; _RouteLineService.Create(s); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("_Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Route).DocumentTypeId, DocId = s.RouteId, DocLineId = s.RouteLineId, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("_Create", new { id = s.RouteId })); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); Route header = new RouteService(_unitOfWork).Find(svm.RouteId); StringBuilder logstring = new StringBuilder(); RouteLine temp1 = _RouteLineService.Find(svm.RouteLineId); RouteLine ExRec = Mapper.Map <RouteLine>(temp1); temp1.CityId = svm.CityId; temp1.ModifiedDate = DateTime.Now; temp1.ModifiedBy = User.Identity.Name; _RouteLineService.Update(temp1); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp1, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(PartialView("_Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Route).DocumentTypeId, DocId = temp.RouteId, DocLineId = temp1.RouteLineId, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); return(Json(new { success = true })); } } PrepareViewBag(svm); return(PartialView("_Create", svm)); }