public async void Should_Fill_Alerts_Table()
        {
            var msgL = await _mtaFeedService.GetCurrentRealtimeFeedMessage(SubwayLines.L);
            var msgIrt = await _mtaFeedService.GetCurrentRealtimeFeedMessage(SubwayLines.RED_GREEN_S);

            var alertFactory = new AlertFactory();
            var alertsIrt = alertFactory.CreateItemsFromFeedMessage(msgIrt);
            var alertsL = alertFactory.CreateItemsFromFeedMessage(msgL);

            // Clear Tables
            using (var alertRepos = new AlertRepository() { Connection = _connection })
            {
                alertRepos.ClearAll();

                // Load Tables
                alertRepos.AddRange(alertsIrt);
                alertRepos.AddRange(alertsL);
            }
        }
        public async void Should_Fill_All_Tables()
        {
            var msgL = await _mtaFeedService.GetCurrentRealtimeFeedMessage(SubwayLines.L);
            var msgIrt = await _mtaFeedService.GetCurrentRealtimeFeedMessage(SubwayLines.RED_GREEN_S);

            var alertFactory = new AlertFactory();
            var stopTimeFactory = new StopTimeUpdateFactory();
            var tripFactory = new TripFactory();
            var vehicleFactory = new VehiclePositionFactory();

            var alertsIrt = alertFactory.CreateItemsFromFeedMessage(msgIrt);
            var alertsL = alertFactory.CreateItemsFromFeedMessage(msgL);

            using (var alertRepos = new AlertRepository() { Connection = _connection })
            {
                // Clear Tables
                alertRepos.ClearAll();

                // Load Tables
                alertRepos.AddRange(alertsIrt);
                alertRepos.AddRange(alertsL);
            }

            var stopsIrt = stopTimeFactory.CreateItemsFromFeedMessage(msgIrt);
            var stopsL = stopTimeFactory.CreateItemsFromFeedMessage(msgL);

            using (var stopsRepos = new StopTimeUpdateRepository() { Connection = _connection })
            {
                // Clear Tables
                stopsRepos.ClearAll();

                // Load Tables
                stopsRepos.AddRange(stopsIrt);
                stopsRepos.AddRange(stopsL);
            }

            var tripsIrt = tripFactory.CreateItemsFromFeedMessage(msgIrt);
            var tripsL = tripFactory.CreateItemsFromFeedMessage(msgL);

            using (var tripsRepos = new TripRepository() { Connection = _connection })
            {
                // Clear Tables
                tripsRepos.ClearAll();

                // Load Tables
                tripsRepos.AddRange(tripsIrt);
                tripsRepos.AddRange(tripsL);
            }

            var vehiclesIrt = vehicleFactory.CreateItemsFromFeedMessage(msgIrt);
            var vehiclesL = vehicleFactory.CreateItemsFromFeedMessage(msgL);

            using (var vehiclesRepos = new VehiclePositionRepository() { Connection = _connection }) {
                // Clear Tables
                vehiclesRepos.ClearAll();

                // Load Tables
                vehiclesRepos.AddRange(vehiclesIrt);
                vehiclesRepos.AddRange(vehiclesL);
            }
        }
Beispiel #3
0
        private static async Task AsyncMain()
        {
            // Load Feed Message
            var dbConnStr = ConfigurationManager.ConnectionStrings["DbConnStr"].ConnectionString;

            var combinedUrl = string.Format(Url, ApiKey);
            var service = new FeedMessageService(combinedUrl);
            var msgIrt = await service.GetCurrentRealtimeFeedMessage(SubwayLines.RED_GREEN_S);
            var msgL = await service.GetCurrentRealtimeFeedMessage(SubwayLines.L);

            var alertFactory = new AlertFactory();
            var stopTimeFactory = new StopTimeUpdateFactory();
            var tripFactory = new TripFactory();
            var vehicleFactory = new VehiclePositionFactory();

            var alertsIrt = alertFactory.CreateItemsFromFeedMessage(msgIrt);
            var alertsL = alertFactory.CreateItemsFromFeedMessage(msgL);

            using (SqlConnection conn = new SqlConnection(dbConnStr))
            {

                using (var alertRepos = new AlertRepository() {Connection = conn})
                {
                    // Clear Tables
                    alertRepos.ClearAll();

                    // Load Tables
                    alertRepos.AddRange(alertsIrt);
                    alertRepos.AddRange(alertsL);
                }

                var stopsIrt = stopTimeFactory.CreateItemsFromFeedMessage(msgIrt);
                var stopsL = stopTimeFactory.CreateItemsFromFeedMessage(msgL);

                using (var stopsRepos = new StopTimeUpdateRepository() { Connection = conn })
                {
                    // Clear Tables
                    stopsRepos.ClearAll();

                    // Load Tables
                    stopsRepos.AddRange(stopsIrt);
                    stopsRepos.AddRange(stopsL);
                }

                var tripsIrt = tripFactory.CreateItemsFromFeedMessage(msgIrt);
                var tripsL = tripFactory.CreateItemsFromFeedMessage(msgL);

                using (var tripsRepos = new TripRepository() { Connection = conn })
                {
                    // Clear Tables
                    tripsRepos.ClearAll();

                    // Load Tables
                    tripsRepos.AddRange(tripsIrt);
                    tripsRepos.AddRange(tripsL);
                }

                var vehiclesIrt = vehicleFactory.CreateItemsFromFeedMessage(msgIrt);
                var vehiclesL = vehicleFactory.CreateItemsFromFeedMessage(msgL);

                using (var vehiclesRepos = new VehiclePositionRepository() { Connection = conn })
                {
                    // Clear Tables
                    vehiclesRepos.ClearAll();

                    // Load Tables
                    vehiclesRepos.AddRange(vehiclesIrt);
                    vehiclesRepos.AddRange(vehiclesL);
                }
            }
        }
        /// <summary>
        /// When implemented in a derived class, executes the scheduled job asynchronously. Implementations that want to know whether
        ///             the scheduled job is being cancelled can get a <see cref="P:Microsoft.WindowsAzure.Mobile.Service.ScheduledJob.CancellationToken"/> from the <see cref="M:CancellationToken"/> property.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Threading.Tasks.Task"/> representing the asynchronous operation.
        /// </returns>
        public override async Task ExecuteAsync()
        {
            // Load Feed Message
            var dbConnStr = ConfigurationManager.ConnectionStrings["MTA_DB"].ConnectionString;

            var combinedUrl = string.Format(Url, ApiKey);
            var service = new FeedMessageService(combinedUrl);
            var msgIrt = await service.GetCurrentRealtimeFeedMessage(SubwayLines.RED_GREEN_S);
            var msgL = await service.GetCurrentRealtimeFeedMessage(SubwayLines.L);

            var alertFactory = new AlertFactory();
            var stopTimeFactory = new StopTimeUpdateFactory();
            var tripFactory = new TripFactory();
            var vehicleFactory = new VehiclePositionFactory();

            var alertsIrt = alertFactory.CreateItemsFromFeedMessage(msgIrt);
            var alertsL = alertFactory.CreateItemsFromFeedMessage(msgL);

            using (SqlConnection conn = new SqlConnection(dbConnStr))
            {

                    conn.Open();

                using (var alertRepos = new AlertRepository() {Connection = conn})
                {
                    // Clear Tables
                    alertRepos.ClearAll(); 

                    // Load Tables
                    alertRepos.AddRange(alertsIrt);
                    alertRepos.AddRange(alertsL);
                }

                var stopsIrt = stopTimeFactory.CreateItemsFromFeedMessage(msgIrt);
                var stopsL = stopTimeFactory.CreateItemsFromFeedMessage(msgL);

                using (var stopsRepos = new StopTimeUpdateRepository() { Connection = conn })
                {
                    // Clear Tables
                    stopsRepos.ClearAll();

                    // Load Tables
                    stopsRepos.AddRange(stopsIrt);
                    stopsRepos.AddRange(stopsL);
                }

                var tripsIrt = tripFactory.CreateItemsFromFeedMessage(msgIrt);
                var tripsL = tripFactory.CreateItemsFromFeedMessage(msgL);

                using (var tripsRepos = new TripRepository() { Connection = conn })
                {
                    // Clear Tables
                    tripsRepos.ClearAll();

                    // Load Tables
                    tripsRepos.AddRange(tripsIrt);
                    tripsRepos.AddRange(tripsL);
                }

                var vehiclesIrt = vehicleFactory.CreateItemsFromFeedMessage(msgIrt);
                var vehiclesL = vehicleFactory.CreateItemsFromFeedMessage(msgL);

                using (var vehiclesRepos = new VehiclePositionRepository() { Connection = conn })
                {
                    // Clear Tables
                    vehiclesRepos.ClearAll();

                    // Load Tables
                    vehiclesRepos.AddRange(vehiclesIrt);
                    vehiclesRepos.AddRange(vehiclesL);
                }

                using (var cmd = new SqlCommand("sp_CreateRealtimeSchedule", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.ExecuteNonQuery();
                }
            }

            //return Task.FromResult(true);
        }