Пример #1
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            DateTime timeStamp = DateTime.UtcNow;
            //double randomPowerScouts = 0;

            int divisor = 1;

            Console.WriteLine("Going to enter time entry: " + timeStamp.ToString());
            for (int building = 0; building < GetPowerGridView.BuildingName.Length; building++)
            {
                Building         buildingInfo  = new Building(GetPowerGridView.BuildingName[building]);
                GetPowerGridView powerGridView = new GetPowerGridView();
                if (k % 60 == 0)
                {
                    divisor = k / 60;
                    powerGridView.AddPowerGridView(buildingInfo, timeStamp, true, divisor);
                }
                powerGridView.AddPowerGridView(buildingInfo, timeStamp, false, divisor);
            }
            GetSensorData sensorData = new GetSensorData();

            sensorData.AddSensorData(timeStamp);
            GetWeather weatherData = new GetWeather();

            weatherData.AddWeatherData(timeStamp);
            Console.WriteLine("Complete time entry: " + timeStamp.ToString());
            k++;
        }
Пример #2
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                DateTime timeStamp = DateTime.UtcNow;
                DateTime startDate = timeStamp;

                ///Get Previous Data///////////////
                if (!IsBacklogFinished)
                {
                    using (SqlConnection sqlConnection = new SqlConnection(ConfigurationSetting.ConnectionString))
                    {
                        DateTime dbLastDate = DateTime.MinValue;
                        sqlConnection.Open();
                        string getMaxTimeStampQuery = "select MAX(TimeStamp) from PowergridView";
                        using (SqlCommand cmd = new SqlCommand(getMaxTimeStampQuery, sqlConnection))
                        {
                            DateTime.TryParse(cmd.ExecuteScalar().ToString(), out dbLastDate);
                        }
                        string getMaxIdQuery = "select MAX(Id) from PowergridView";
                        using (SqlCommand cmd = new SqlCommand(getMaxIdQuery, sqlConnection))
                        {
                            object maxId = cmd.ExecuteScalar();
                            Id = maxId != DBNull.Value ? Convert.ToInt32(maxId) : 0;
                        }

                        //Date Handling
                        if (!(dbLastDate == null || dbLastDate == DateTime.MinValue || dbLastDate == default(DateTime)))
                        {
                            startDate = dbLastDate;
                        }
                        AddPreviousData(timeStamp, startDate);
                        IsBacklogFinished = true;
                    }
                }
                else //real time data population
                {
                    Console.WriteLine("Going to enter time entry: " + timeStamp.ToString());
                    for (int building = 0; building < GetPowerGridView.BuildingName.Length; building++)
                    {
                        Building         buildingInfo  = new Building(GetPowerGridView.BuildingName[building]);
                        GetPowerGridView powerGridView = new GetPowerGridView();
                        powerGridView.AddPowerGridView(buildingInfo, timeStamp);
                    }
                    GetWeather weatherData = new GetWeather();
                    weatherData.AddWeatherData(timeStamp);

                    GetSensorData sensorData = new GetSensorData();
                    for (int i = 0; i < RuntimeSensors.Count; i++)
                    {
                        sensorData.AddSensorData(timeStamp, RuntimeSensors.ElementAt(i));
                    }
                }
                Console.WriteLine("Complete time entry: " + timeStamp.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occured " + ex.Message);
            }
        }
Пример #3
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            GetPowerGridView powerGridView = new GetPowerGridView();

            powerGridView.AddPowerGridView();
            GetSensorData sensorData = new GetSensorData();

            sensorData.AddSensorData();
            GetWeather weatherData = new GetWeather();

            weatherData.AddWeatherData();
        }
Пример #4
0
        static void Main(string[] args)
        {
            GetPowerGridView powerGridView = new GetPowerGridView();

            powerGridView.AddPowerGridView();
            GetSensorData sensorData = new GetSensorData();

            sensorData.AddSensorData();
            GetWeather weatherData = new GetWeather();

            weatherData.AddWeatherData();
            //ThreadStart t1 = new ThreadStart(repeatProcess);
            //Thread childMeterThread = new Thread(t1);
            //childMeterThread.Start();
        }
Пример #5
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            DateTime timeStamp = DateTime.UtcNow;

            Console.WriteLine("Going to enter time entry: " + timeStamp.ToString());
            for (int building = 0; building < GetPowerGridView.BuildingName.Length; building++)
            {
                Building         buildingInfo  = new Building(GetPowerGridView.BuildingName[building]);
                GetPowerGridView powerGridView = new GetPowerGridView();
                powerGridView.AddPowerGridView(buildingInfo, timeStamp);
            }
            GetSensorData sensorData = new GetSensorData();

            sensorData.AddSensorData(timeStamp);
            GetWeather weatherData = new GetWeather();

            weatherData.AddWeatherData(timeStamp);
            Console.WriteLine("Complete time entry: " + timeStamp.ToString());
        }
Пример #6
0
        private static void repeatProcess()
        {
            try
            {
                CreateTableIfNotExist();
                DateTime timeStamp = DateTime.UtcNow;
                DateTime startDate = timeStamp;

                startDate = timeStamp.AddDays(-previousPendingDays);
                using (SqlConnection sqlConnection = new SqlConnection(ConfigurationSetting.ConnectionString))
                {
                    DateTime dbLastDate = DateTime.MinValue;
                    sqlConnection.Open();
                    string getMaxTimeStampQuery = "select MAX(TimeStamp) from PowergridView";
                    using (SqlCommand cmd = new SqlCommand(getMaxTimeStampQuery, sqlConnection))
                    {
                        DateTime.TryParse(cmd.ExecuteScalar().ToString(), out dbLastDate);
                    }
                    string getMaxIdQuery = "select MAX(Id) from PowergridView";
                    using (SqlCommand cmd = new SqlCommand(getMaxIdQuery, sqlConnection))
                    {
                        object maxId = cmd.ExecuteScalar();
                        Id = maxId != DBNull.Value ? Convert.ToInt32(maxId) : 0;
                    }

                    //Date Handling
                    if (!(dbLastDate == null || dbLastDate == DateTime.MinValue || dbLastDate == default(DateTime)))
                    {
                        startDate = dbLastDate;
                    }
                    AddPreviousData(timeStamp, startDate);
                }
                previousPendingDays = 0;
                //Get Existing sensor names from db
                UpdateSensorsList();//Runtimesensors list updated
                int maxDbSensorCount = RuntimeSensors.Count;
                //


                //Insert Sensor Data for the first time with ramdom name generated at runtime
                GetSensorData sensorData = new GetSensorData();
                for (int i = maxDbSensorCount + 1; i <= maxDbSensorCount + sensorCount; i++)
                {
                    Random rnd        = new Random();
                    int    index      = rnd.Next(0, sensorData.wirelessTagTemplate.Length);
                    string sensorName = sensorData.wirelessTagTemplate[index] + " " + i;
                    RuntimeSensors.Add(sensorName);
                    sensorData.AddSensorData(timeStamp, sensorName);
                    Console.WriteLine("Inserted Sensor : " + sensorName);
                }

                processTimer          = new System.Timers.Timer(60000);
                processTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimerElapsed);
                processTimer.Start();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("repeatProcess exception occured: ", e.Message);
            }
        }