Beispiel #1
0
        public void Run(IBrowser browser, ManualResetEvent manualResetEvent, PersonDetails personDetails)
        {
            browser.ClickElementWithCss($"[for='Sections_1_Questions_INC7_Answers_{personDetails.HasLivedInAfricaInLast2Years.ToYesNo()}']");
            browser.ClickElementWithCss($"[for='Sections_1_Questions_INC8_Answers_{personDetails.IntendToLiveOutsideOfUkInNext2Years.ToYesNo()}']");
            browser.ClickElementWithCss("#nextPageButton");

            if (personDetails.IntendToLiveOutsideOfUkInNext2Years)
            {
                browser.ClickElementWithCss($"[for='Sections_1_Questions_INC8_1_Answers_{personDetails.TravelInfo.KnowsWhichCountryTheyWillTravelTo.ToYesNo()}']");
                browser.ClickElementWithCss("#nextPageButton");

                if (personDetails.TravelInfo.KnowsWhichCountryTheyWillTravelTo)
                {
                    browser.ClickElementWithCss("[type='text']");
                    browser.FindElements(".option").Skip(TravelInfo.GetIndexOfCountry(personDetails.TravelInfo.Country)).First().Click();
                    browser.ClickElementWithCss("#INC8_1-answer");
                    browser.ClickElementWithCss("#nextPageButton");

                    browser.ClickElementWithCss($"[for='Sections_0_Questions_Grp1_1_Answers_{personDetails.TravelInfo.IntendToLiveInCountrySelected.ToYesNo()}']");
                    browser.ClickElementWithCss("#nextPageButton");
                }
            }

            manualResetEvent.WaitOne(Timeout.Infinite);
        }
Beispiel #2
0
        public List <Row> GetTravelRoutes(string startAddress, string endAddress)
        {
            List <Row> travelRoutes = new List <Row>();
            TravelInfo travelInfo   = JsonConvert.DeserializeObject <TravelInfo>(GetTravelInfo(startAddress, endAddress).Result);

            foreach (Row row in travelInfo.rows)
            {
                travelRoutes.Add(row);
            }
            return(travelRoutes);
        }
Beispiel #3
0
        public void SaveTravelInfo(TempUserModel travelObj, string userId)
        {
            var info = new TravelInfo()
            {
                Comment = travelObj.Comment,
                UserId  = userId,
                CityId  = _context.Cities.First(o => o.CityName == travelObj.CityName).Id,
            };

            _context.TravelInfos.Add(info);
            _context.SaveChanges();
        }
 public void SetDirectionsInfo(TravelInfo travelInfo, Customer customer)
 {
     customer.duration       = travelInfo.routes[0].legs[0].duration_in_traffic.value;
     customer.duration       = customer.duration / 60;
     customer.distance       = travelInfo.routes[0].legs[0].distance.value;
     customer.endLatitude    = travelInfo.routes[0].legs[0].end_location.lat;
     customer.endLongitude   = travelInfo.routes[0].legs[0].end_location.lng;
     customer.startLatitude  = travelInfo.routes[0].legs[0].start_location.lat;
     customer.startLongitude = travelInfo.routes[0].legs[0].start_location.lng;
     _repo.Customer.EditCustomer(customer);
     _context.SaveChangesAsync();
 }
        public void SelectPurposeForCollectingTravelInfo(TravelInfo travelinfo)
        {
            switch (travelinfo)
            {
                case TravelInfo.PurposeArrive:
                    UIUtil.DefaultProvider.WaitForDisplayAndClick("ctl00_cph_radPurposeArrive", LocateBy.Id);
                    break;

                case TravelInfo.PurposeBooking:
                    UIUtil.DefaultProvider.WaitForDisplayAndClick("ctl00_cph_radPurposeBooking", LocateBy.Id);
                    break;
            }
        }
Beispiel #6
0
        public int GetValuesFromAPIs(TravelInfoVM travelInfoVM, string json)
        {
            var travelInfo = new TravelInfo();

            travelInfo.FromAddress = travelInfoVM.FromAddress;
            travelInfo.ToAddress   = travelInfoVM.ToAddress;
            travelInfo.Transport   = travelInfoVM.Transport;

            JObject o = JObject.Parse(json);

            string tempDist = (string)o.SelectToken("emissions[1].routedDistance");

            travelInfo.Distance = Convert.ToSingle(tempDist);

            switch (travelInfo.Transport)
            {
            case "BICYCLE":
                GetCo2(o, 0, travelInfo);
                break;

            case "WALKING":
                GetCo2(o, 1, travelInfo);
                break;

            case "TRAIN":
                GetCo2(o, 2, travelInfo);
                break;

            case "BUS":
                GetCo2(o, 3, travelInfo);
                break;

            case "MOTORCYCLE":
                GetCo2(o, 4, travelInfo);
                break;

            case "DRIVING":
                GetCo2(o, 7, travelInfo);
                break;
            }
            return /*AddNewTravel(travelInfo)*/ (1);
        }
Beispiel #7
0
        public void Edit(EditModel edit, string user)
        {
            if (edit.Id == 0)
            {
                var tempTravel = new TravelInfo()
                {
                    Comment = edit.Comment,
                    CityId  = _context.Cities.First(o => o.CityName == edit.CityName).Id,
                    UserId  = user,
                };
                _context.TravelInfos.Add(tempTravel);
            }
            var dbEntry = _context.TravelInfos.Find(edit.Id);

            if (dbEntry != null)
            {
                dbEntry.VisitedCity = _context.Cities.First(o => o.CityName == edit.CityName);
                dbEntry.Comment     = edit.Comment;
            }
            _context.SaveChanges();
        }
Beispiel #8
0
        private void GetCo2(JObject o, int i, TravelInfo travelInfo)
        {
            float Co2;
            var   distance = (int)o.SelectToken($"emissions[{i}].routedDistance");

            if (i == 7 && distance > 2000000)
            {
                Co2            = Convert.ToSingle(distance / 5.556f);
                travelInfo.Co2 = Co2;
            }
            else
            {
                string tempCo2 = (string)o.SelectToken($"emissions[{i}].totalCo2");
                if (tempCo2.StartsWith("-"))
                {
                    tempCo2 = tempCo2.Substring(1);
                }
                Co2            = Convert.ToSingle(tempCo2);
                travelInfo.Co2 = Co2;
            }
        }
        public async Task <TravelInfo> GetDirections(Customer customer, FlightInfo flight)
        {
            string              url      = $"https://maps.googleapis.com/maps/api/directions/json?origin={customer.StreetAddress}&={customer.ZipCode}&destination={flight.Airport}&traffic_model=best_guess&departure_time=now&key={APIKeys.GoogleAPI}";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(url);

            TravelInfo travelInfo = null;

            if (response.IsSuccessStatusCode)
            {
                string data = await response.Content.ReadAsStringAsync();

                travelInfo = JsonConvert.DeserializeObject <TravelInfo>(data);
                return(travelInfo);


                //customer.Latitude = (double)location["lat"];
                //customer.Longitude = (double)location["lng"];
                // customer.Latitude = (double)location[];
            }
            return(null);
        }
        public async Task <IActionResult> FlightInfo(TimeSpan?time, int flightId)
        {
            CustomerFlightInfoViewModel customerFlight = new CustomerFlightInfoViewModel();
            var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var customer = _repo.Customer.GetCustomer(userId);

            if (flightId != 0)
            {
                customer.flightId = flightId;
            }
            var flight = _repo.Flight.GetFlight(customer.flightId);

            if (time != null)
            {
                flight.SelectedArrivalTime = time;
            }
            _repo.Customer.EditCustomer(customer);
            _repo.Flight.EditFlight(flight);
            await _context.SaveChangesAsync();

            customerFlight.Customer   = customer;
            customerFlight.FlightInfo = flight;
            Airport airport = await _tsaWaitTimesService.GetWaitTimes(flight.AirportCode);

            string firstTimeSlot = airport.estimated_hourly_times[0].timeslot;
            char   firstChar     = firstTimeSlot[0];
            int    firstTime     = Convert.ToInt32(Char.GetNumericValue(firstChar));
            double?transitMins;
            bool   withinTime;

            if (flight.SelectedArrivalTime.HasValue || time.HasValue)
            {
                if (flight.SelectedArrivalTime.Value.Hours < firstTime || flight.SelectedArrivalTime.Value.Hours > airport.estimated_hourly_times.Length)
                {
                    withinTime        = true;
                    ViewBag.TimeCheck = withinTime;
                    return(View(customerFlight));
                }
                for (int i = firstTime; i < airport.estimated_hourly_times.Length; i++)
                {
                    TimeSpan start = new TimeSpan(i, 0, 0);
                    TimeSpan end   = new TimeSpan((i + 1), 0, 0);
                    if ((flight.SelectedArrivalTime >= start) && (flight.SelectedArrivalTime <= end))
                    {
                        flight.TSAWaitTimeOnArrival = airport.estimated_hourly_times[i].waittime;
                        break;
                    }
                }
                _repo.Flight.EditFlight(flight);
                await _context.SaveChangesAsync();

                EpochTimeConverter(flight);
                TravelInfo travelInfo = await _directions.GetDirections(customer, flight);

                SetDirectionsInfo(travelInfo, customer);
                transitMins         = customer.duration + flight.TSAWaitTimeOnArrival;
                ViewBag.TransitTime = transitMins;
                DateTime leaveTime = ConvertTime(transitMins, flight);
                ViewBag.LeaveTimeData = leaveTime;
                string dateToDisplay = leaveTime.ToShortDateString();
                string timeToDisplay = leaveTime.ToString("hh:mm:ss tt");
                ViewBag.LeaveTime = $"{dateToDisplay} {timeToDisplay}";
            }
            return(View(customerFlight));
        }
Beispiel #11
0
 public int AddNewTravel(TravelInfo travelInfo)
 {
     _context.TravelInfo.Add(travelInfo);
     _context.SaveChanges();
     return(travelInfo.Id);
 }
Beispiel #12
0
        public JsonResult Estimate(TravelInfo travelInfo)
        {
            Random rnd         = new Random(DateTime.Now.TimeOfDay.Milliseconds);
            var    travelsList = new List <TravelResult>();

            string configPath = @"C:\Multiride\config.json";

            if (System.IO.File.Exists(configPath))
            {
                System.IO.File.Delete(configPath);
            }

            Newtonsoft.Json.Linq.JObject config = new Newtonsoft.Json.Linq.JObject();
            config["PickupLat"]  = travelInfo.PickupLat;
            config["PickupLng"]  = travelInfo.PickupLng;
            config["DropoffLat"] = travelInfo.DropoffLat;
            config["DropoffLng"] = travelInfo.DropoffLng;

            System.IO.File.WriteAllText(configPath, Newtonsoft.Json.JsonConvert.SerializeObject(config));

            string resultPath = @"C:\Multiride\result.json";
            string appPath    = @"C:\Multiride\EstimateRequestApp.jar";

            if (System.IO.File.Exists(resultPath))
            {
                System.IO.File.Delete(resultPath);
            }

            var myProcess = new System.Diagnostics.Process();

            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.FileName        = "java";
            myProcess.StartInfo.Arguments       = @"-jar " + appPath;
            myProcess.Start();

            int iLoops = 0;

            while (!System.IO.File.Exists(resultPath))
            {
                Thread.Sleep(250);
                iLoops += 1;
                if (iLoops >= 500)
                {
                    throw new TimeoutException("Exceção o tempo limite de buscar dados de viagem");
                }
            }

            Newtonsoft.Json.Linq.JArray results = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JArray>(System.IO.File.ReadAllText(resultPath));

            foreach (var item in results)
            {
                travelsList.Add(new TravelResult()
                {
                    Imagem     = Convert.ToString(item["Imagem"]),
                    MenorValor = Convert.ToDouble(item["MenorValor"]),
                    MaiorValor = Convert.ToDouble(item["MaiorValor"]),
                    MenorTempo = 0,
                    MaiorTempo = 0,
                    Tipo       = Convert.ToString(item["Tipo"])
                });
            }

            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Response.Headers.Add("Access-Control-Allow-Headers", "*");
            Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            Response.Headers.Add("Access-Control-Allow-Credentials", "true");

            return(Json(travelsList, JsonRequestBehavior.AllowGet));
        }
        internal LocationStatus(EliteDangerousAPI api)
        {
            api.TravelEvents.Location += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    StarSystem.Security      = e.SystemSecurityType;
                    StarSystem.Government    = e.SystemGovernmentType;
                    StarSystem.Economy       = e.SystemEconomyType;
                    StarSystem.SecondEconomy = e.SystemSecondEconomyType;
                    StarSystem.Faction       = e.SystemFaction ?? StarSystem.Faction;
                    StarSystem.Population    = e.Population;

                    Body = new SpaceBodyInfo(e.BodyType ?? BodyType.Null, e.Body);

                    if (Body.Type == BodyType.Station)
                    {
                        if (Station == null || !string.Equals(Station?.Name, e.StationName,
                                                              StringComparison.OrdinalIgnoreCase))
                        {
                            Station = new StationInfo(e.StationName ?? e.Body, e.StationType);
                        }
                        Station.Faction    = e.StationFaction ?? Station.Faction;
                        Station.Economy    = e.StationEconomyType;
                        Station.Government = e.StationGovernmentType;
                        Station.Allegiance = e.StationAllegiance ?? Station.Allegiance;
                        Station.MarketId   = e.MarketId ?? Station.MarketId;
                    }
                    else
                    {
                        Station = null;
                    }

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.ApproachBody += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    Body    = new SpaceBodyInfo(BodyType.Planet, e.Body ?? "Planet");
                    Station = null;

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.ApproachSettlement += (s, e) =>
            {
                lock (_lock)
                {
                    Body    = new SpaceBodyInfo(BodyType.Planet, e.BodyName);
                    Station = new StationInfo(e.NameLocalised ?? e.Name, "PlanetaryOutpost")
                    {
                        MarketId = e.MarketId
                    };

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.LeaveBody += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    Body    = new SpaceBodyInfo(BodyType.Planet, e.Body ?? "Planet");
                    Station = null;

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.Docked += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    Body = new SpaceBodyInfo(BodyType.Station, e.StationName ?? "Station");

                    if (Station == null ||
                        !string.Equals(Station?.Name, e.StationName, StringComparison.OrdinalIgnoreCase))
                    {
                        Station = new StationInfo(e.StationName, e.StationType);
                    }

                    Station.Economy    = e.StationEconomyType;
                    Station.Government = e.StationGovernmentType;
                    Station.Faction    = e.StationFaction ?? Station.Faction;
                    Station.Allegiance = e.StationAllegiance ?? Station.Allegiance;
                    Station.MarketId   = e.MarketId;

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.DockingRequested += (s, e) =>
            {
                lock (_lock)
                {
                    if (Station == null ||
                        !string.Equals(Station?.Name, e.StationName, StringComparison.OrdinalIgnoreCase))
                    {
                        Station = new StationInfo(e.StationName, e.StationType);
                    }
                    Station.MarketId = e.MarketId;

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.FsdJump += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    if (Route != null && string.Equals(Route.DestinationSystem, StarSystem.Name))
                    {
                        Route = null;
                    }

                    StarSystem.Security      = e.SystemSecurityType;
                    StarSystem.Government    = e.SystemGovernmentType;
                    StarSystem.Economy       = e.SystemEconomyType;
                    StarSystem.SecondEconomy = e.SystemSecondEconomyType;
                    StarSystem.Faction       = e.SystemFaction ?? StarSystem.Faction;
                    StarSystem.Population    = e.Population;

                    Body = new SpaceBodyInfo(e.BodyType, e.Body);

                    Station = null;

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.SupercruiseExit += (s, e) =>
            {
                lock (_lock)
                {
                    if (StarSystem == null ||
                        !string.Equals(StarSystem?.Name, e.StarSystem, StringComparison.OrdinalIgnoreCase))
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem);
                    }

                    Body = new SpaceBodyInfo(e.BodyType ?? BodyType.Null, e.Body);

                    api.InvokeLocationStatusChanged(this);
                }
            };

            api.TravelEvents.StartJump += (s, e) =>
            {
                lock (_lock)
                {
                    if (e.JumpType == JumpType.Hyperspace)
                    {
                        StarSystem = new StarSystemInfo(e.StarSystem)
                        {
                            StarClass = e.StarClass
                        };
                        Body    = null;
                        Station = null;

                        api.InvokeLocationStatusChanged(this);
                    }
                }
            };

            api.TravelEvents.FsdTarget += (s, e) =>
            {
                lock (_lock)
                {
                    Route = new TravelInfo(e.Name, e.RemainingJumpsInRoute);

                    api.InvokeLocationStatusChanged(this);
                }
            };
        }