コード例 #1
0
        public void ResolveVehicleLocationProviderType_Cabs_Passes()
        {
            using (IDbContext idtoFakeContext = new IDTOFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(idtoFakeContext))
                {
                    Step stepEntity = new Step();
                    stepEntity.StepNumber     = 1;
                    stepEntity.StartDate      = DateTime.Parse("1/1/2014 10:02");
                    stepEntity.EndDate        = DateTime.Parse("1/1/2014 10:40");
                    stepEntity.FromName       = "Quartz Street";
                    stepEntity.FromProviderId = (int)Providers.CABS;
                    stepEntity.FromStopCode   = "1001";
                    stepEntity.ModeId         = (int)Modes.Bus;
                    stepEntity.RouteNumber    = "039";
                    stepEntity.Distance       = (decimal)12.2;
                    stepEntity.ToName         = "Slate Run Road";
                    stepEntity.ToProviderId   = (int)Providers.CABS;
                    stepEntity.ToStopCode     = "2002";

                    unitOfWork.Repository <Step>().Insert(stepEntity);
                    unitOfWork.Save();

                    TConnect tconn = new TConnect();
                    tconn.InboundStepId = stepEntity.Id;

                    unitOfWork.Repository <TConnect>().Insert(tconn);
                    unitOfWork.Save();

                    IVehicleLocation iv = VehicleLocationMonitorWorker.ResolveVehicleLocationProviderType(tconn, unitOfWork, scheduleFakes);
                    Assert.AreEqual(iv.ProviderName, Providers.CABS);
                }
        }
コード例 #2
0
        /// <summary>
        /// Based on the TConnect's Inbound Step Provider, determine if the appropriate
        /// type of vehicle location provider to use
        /// Uses TOprovider
        /// </summary>
        /// <param name="mt"></param>
        /// <returns></returns>
        public static IVehicleLocation ResolveVehicleLocationProviderType(TConnect mt, IUnitOfWork Uow, List <IBusSchedule> busScheduleAPIs)
        {
            IVehicleLocation vehLoc      = null;
            Step             inboundStep = Uow.Repository <Step>().Query().Get()
                                           .Where(s => s.Id.Equals(mt.InboundStepId)).First();

            if (inboundStep.ToProviderId == (int)Providers.CapTrans)
            {
                vehLoc = new CapTransVehicleLocation();
            }
            else
            {
                foreach (IBusSchedule busSchedule in busScheduleAPIs)
                {
                    if (inboundStep.ToProviderId == (int)busSchedule.GetProviderId())
                    {
                        vehLoc = new CabsVehicleLocation(busSchedule);
                    }
                }
            }

            if (vehLoc == null)
            {
                throw new NotImplementedException("Tconnects only handled from CapTrans and CABS currently. ");
            }
            return(vehLoc);
        }
コード例 #3
0
        public void ResolveVehicleLocationProviderType_Other_Fails()
        {
            using (IDbContext idtoFakeContext = new IDTOFakeContext())
                using (IUnitOfWork unitOfWork = new UnitOfWork(idtoFakeContext))
                {
                    Step stepEntity = new Step();
                    stepEntity.StepNumber     = 1;
                    stepEntity.StartDate      = DateTime.Parse("1/1/2014 10:02");
                    stepEntity.EndDate        = DateTime.Parse("1/1/2014 10:40");
                    stepEntity.FromName       = "Quartz Street";
                    stepEntity.FromProviderId = (int)Providers.COTA;
                    stepEntity.FromStopCode   = "1001";
                    stepEntity.ModeId         = (int)Modes.Bus;
                    stepEntity.RouteNumber    = "039";
                    stepEntity.Distance       = (decimal)12.2;
                    stepEntity.ToName         = "Slate Run Road";
                    stepEntity.ToProviderId   = (int)Providers.COTA;
                    stepEntity.ToStopCode     = "2002";

                    unitOfWork.Repository <Step>().Insert(stepEntity);
                    unitOfWork.Save();

                    TConnect tconn = new TConnect();
                    tconn.InboundStepId = stepEntity.Id;

                    unitOfWork.Repository <TConnect>().Insert(tconn);
                    unitOfWork.Save();
                    try
                    {
                        IVehicleLocation iv = VehicleLocationMonitorWorker.ResolveVehicleLocationProviderType(tconn, unitOfWork, scheduleFakes);
                        Assert.AreEqual(true, false, "Test should have thrown an exception and not executed this line.");
                    }
                    catch (Exception ex)
                    {
                        //unhandled type
                    }
                }
        }
コード例 #4
0
        /// <summary>
        /// For each newly added TConnect added via the Trip Service, resolve the inbound vehicle name
        /// and update the status for the record.
        /// </summary>
        /// <param name="Uow"></param>
        async public void SetupNewTConnects(IUnitOfWork Uow)
        {
            List <TConnect> monitoredTConnects = Uow.Repository <TConnect>().Query().Include(s => s.InboundStep.Trip).Include(s => s.OutboundStep).Get()
                                                 .Where(m => m.TConnectStatusId == (int)TConnectStatuses.New).ToList();

            foreach (TConnect mt in monitoredTConnects)
            {
                try
                {
                    //T-Connect Monitor should not start monitoring the T-Connect until 1 minute before the start of the Trip
                    if (DateTime.UtcNow >= mt.InboundStep.Trip.TripStartDate.AddMinutes(-1))
                    {
                        //Update Tconnect created with Status New.
                        //InboundVehicle,StartWindow,EndWindow all need updated.
                        IVehicleLocation veh = VehicleLocationMonitorWorker.ResolveVehicleLocationProviderType(mt, Uow, busSchedulerAPIs);
                        mt.InboundVehicle = veh.GetInboundVehicleName(mt, Uow);

                        //Step step = Uow.Repository<Step>().Query().Get()
                        //     .Where(s => s.Id.Equals(mt.OutboundStepId)).First();
                        //Provider prov = step.FromProvider;

                        mt.ModifiedDate = DateTime.UtcNow;
                        mt.ModifiedBy   = ModifiedBy;
                        //Update status to monitored now that it has been setup
                        mt.TConnectStatusId = (int)TConnectStatuses.Monitored;
                        Uow.Repository <TConnect>().Update(mt);
                        Uow.Repository <TripEvent>().Insert(new TripEvent(mt.InboundStep.TripId, "Identified Inbound Vehicle for T-Connect"));
                        Uow.Repository <TripEvent>().Insert(new TripEvent(mt.InboundStep.TripId, "T-Connect status changed to Monitored"));
                        Uow.Save();
                    }
                }
                catch (Exception ex)
                {
                    Diagnostics.WriteMainDiagnosticInfo(TraceEventType.Error, TraceEventId.TraceGeneral, " Error in SetupNewTConnects for TConnect: " + mt.Id + ".  " + ex.Message);
                }
            }
        }