Пример #1
0
        public MyMeasurements GetAllMeasurementsFromLocationDateToDate(DateTime from, DateTime todate, params string[] pars)
        {
            MyMeasurements m = new MyMeasurements();
            List <TemperatureMeasurement> tlist = new List <TemperatureMeasurement>();
            List <HumidityMeasurement>    hlist = new List <HumidityMeasurement>();
            string location    = pars[0];
            string measurement = pars[1];

            if (pars[0].Equals("all"))
            {
                hlist = MyDbContext.HumidityMeasurements.ToList();
                tlist = MyDbContext.TemperatureMeasurements.ToList();
            }
            else
            {
                hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.LocationName.Equals(location)).ToList();
                tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.LocationName.Equals(location)).ToList();
            }

            if (pars[1].Equals("humid") || pars[1].Equals("both"))
            {
                hlist = hlist.Where(r => r.DateTime > from).ToList();
                hlist = hlist.Where(r => r.DateTime < todate).ToList();

                Action <HumidityMeasurement> toSendList = (item) =>
                {
                    var item2 = new MyHumidityMeasurement();
                    item2.MyDateTime     = item.DateTime;
                    item2.MyRMUnitName   = item.RMUnit.Name;
                    item2.MyLocationName = item.LocationName;
                    item2.MyValue        = (float)item.Value;
                    m.MyHumMeasurements.Add(item2);
                };

                hlist.ForEach(toSendList);
            }

            if (pars[1].Equals("temp") || pars[1].Equals("both"))
            {
                tlist = tlist.Where(r => r.DateTime > from).ToList();
                tlist = tlist.Where(r => r.DateTime < todate).ToList();

                Action <TemperatureMeasurement> toSendList = (item) =>
                {
                    var item2 = new MyTemperatureMeasurement();
                    item2.MyDateTime     = item.DateTime;
                    item2.MyRMUnitName   = item.RMUnit.Name;
                    item2.MyLocationName = item.LocationName;
                    item2.MyValue        = (float)item.Value;
                    m.MyTempMeasurements.Add(item2);
                };

                tlist.ForEach(toSendList);
            }

            return(m);
        }
Пример #2
0
        public MyMeasurements GetAllMeasuremensWithLimit(float limit, params string[] pars)
        {
            MyMeasurements m = new MyMeasurements();
            List <TemperatureMeasurement> tlist = new List <TemperatureMeasurement>();
            List <HumidityMeasurement>    hlist = new List <HumidityMeasurement>();

            if (pars[1].Equals("humid") || pars[1].Equals("both"))
            {
                if (pars[0].Equals("above"))
                {
                    hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.Value > limit).ToList();
                }
                else if (pars[0].Equals("under"))
                {
                    hlist = MyDbContext.HumidityMeasurements.ToList().Where(r => r.Value < limit).ToList();
                }


                Action <HumidityMeasurement> toSendList = (item) =>
                {
                    var item2 = new MyHumidityMeasurement();
                    item2.MyDateTime     = item.DateTime;
                    item2.MyRMUnitName   = item.RMUnit.Name;
                    item2.MyValue        = (float)item.Value;
                    item2.MyLocationName = item.LocationName;
                    m.MyHumMeasurements.Add(item2);
                };

                hlist.ForEach(toSendList);
            }
            if (pars[1].Equals("temp") || pars[1].Equals("both"))
            {
                if (pars[0].Equals("above"))
                {
                    tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.Value > limit).ToList();
                }
                else if (pars[0].Equals("under"))
                {
                    tlist = MyDbContext.TemperatureMeasurements.ToList().Where(r => r.Value < limit).ToList();
                }

                Action <TemperatureMeasurement> toSendList = (item) =>
                {
                    var item2 = new MyTemperatureMeasurement();
                    item2.MyDateTime     = item.DateTime;
                    item2.MyRMUnitName   = item.RMUnit.Name;
                    item2.MyLocationName = item.LocationName;
                    item2.MyValue        = (float)item.Value;
                    m.MyTempMeasurements.Add(item2);
                };

                tlist.ForEach(toSendList);
            }


            return(m);
        }
Пример #3
0
        public void AddNewTemperatureMeasuremenToDb(MyTemperatureMeasurement measurement)
        {
            //tm.Add(measurement);
            TemperatureMeasurement m = new TemperatureMeasurement();

            m.Value        = measurement.MyValue;
            m.LocationName = measurement.MyLocationName;
            m.DateTime     = measurement.MyDateTime;
            MyDbContext.TemperatureMeasurements.Add(m);

            if (MyDbContext.Entry(m).State == System.Data.EntityState.Added)
            {
                MyDbContext.SaveChanges();
            }
        }
Пример #4
0
        public void SendNewTemperatureMeasurement(MyTemperatureMeasurement measurement)
        {
            //var my = (MyMeasurement)measurement;
            IPublisherCallback callback = m_MeasurementPublishers[measurement.MyLocationName];

            if (callback != null)
            {
                AddNewTemperatureMeasuremenToDb(measurement);
                callback.OnTemperatureMeasurementSent(measurement);
            }

            foreach (var item in m_TemperatureCallbacks[measurement.MyLocationName].Values)
            {
                WorkerClass work = new WorkerClass();
                work.MyTemperature = measurement;
                work.MyCallback    = item;
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolSendTemperatureCallback), work);
            }
        }