Inheritance: IFeedMessageService
Exemplo n.º 1
0
        public void SetupTestFixture()
        {
            _combinedUrl = string.Format(Url, ApiKey);
            _mtaFeedService = new FeedMessageService(_combinedUrl);

            _connection = new SqlConnection(DbConnStr);    
        }
Exemplo n.º 2
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);
                }
            }
        }
 public void SetupFixture()
 {
     CombinedUrl = string.Format(Url, ApiKey);
     MtaFeedService = new FeedMessageService(CombinedUrl);
 }
Exemplo n.º 4
0
        /// <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);
        }