Exemplo n.º 1
0
        /// <summary>
        /// Requests the Data Overview View
        /// </summary>
        /// <returns>Partial View</returns>
        public ActionResult DataOverview()
        {
            IParkadesModel      parkadesModel      = this.ParkingFinderFacade.RequestParkades <ParkadesModel>();
            ITrainStationsModel trainstationsModel = this.ParkingFinderFacade.RequestTrainStations <TrainStationsModel>();
            IOccupanciesModel   occupanciesModel   = this.ParkingFinderFacade.RequestParkadeOccupancies <OccupanciesModel>();

            return(PartialView("Partial/DataOverview", new Tuple <IParkadesModel, ITrainStationsModel, IOccupanciesModel>(parkadesModel, trainstationsModel, occupanciesModel)));
        }
        /// <summary>
        /// The Loop which gets the Price every x minutes
        /// x can be adjusted via web.config entry "DelayWhileDataCollection"
        /// TODO Raus hier
        /// </summary>
        /// <param name="threadGuid">the guid of the current thread</param>
        private void DataCollectionLoop(Guid threadGuid)
        {
            // Check if the shut down should be forced
            while (!this.PredefinedServiceFacade.ThreadService.ShutDownForced(threadGuid))
            {
                // Get the station data from json dynamically based on the ids of the input
                IOccupanciesModel            occupancies    = this.ParkingFnderFacade.RequestParkadeOccupancies <OccupanciesModel>();
                IParkingFinderAnalyticsModel analyticsModel = (IParkingFinderAnalyticsModel)this.PredefinedServiceFacade.CachingService.GetModel <ParkingFinderAnalyticsModel>();

                foreach (OccupancyModel occupancy in occupancies.Occupancies)
                {
                    IParkingFinderAnalyticsData specificAnalyticsData = new ParkingFinderAnalyticsData()
                    {
                        OccupancyModel = occupancy,
                        TimeStamp      = DateTime.Now
                    };

                    IList <IParkingFinderAnalyticsData> analyticsData;
                    if (analyticsModel.AnalyticsData.TryGetValue(occupancy.Site.Id, out analyticsData))
                    {
                        analyticsData.Add(specificAnalyticsData);
                    }
                    else
                    {
                        analyticsData = new List <IParkingFinderAnalyticsData>()
                        {
                            specificAnalyticsData
                        };

                        analyticsModel.AnalyticsData.Add(occupancy.Site.Id, analyticsData);
                    }
                }

                // Serialize and save the Result
                this.PredefinedServiceFacade.CachingService.SetModel <ParkingFinderAnalyticsModel>(analyticsModel);
                this.PredefinedServiceFacade.SerializationService.Serialize(analyticsModel, Settings.AnaylticsSerializationPath);

                // Sleep in Web.config
                // Sleep again
                System.Threading.Thread.Sleep(600000);
            }
            // Remove this thread from the static list
            Logger.Info("DataCollectionLoop: shutdown triggered");
            this.PredefinedServiceFacade.ThreadService.RemoveDataCollectionThread(threadGuid);
        }