Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void SendNewHumidityMeasurement(MyHumidityMeasurement measurement)
        {
            //string str = "Received";

            IPublisherCallback callback = m_MeasurementPublishers[measurement.MyLocationName];

            if (callback != null)
            {
                callback.OnHumidityMeasurementSent(measurement);
                AddNewHumidityMeasuremenToDb(measurement);
            }

            foreach (var item in m_HumidityCallbacks[measurement.MyLocationName].Values)
            {
                WorkerClass work = new WorkerClass();
                work.MyHumidity = measurement;
                work.MyCallback = item;
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolSendHumidityCallback), work);
            }
        }
Beispiel #3
0
        public void Subscribe(string location)
        {
            string message = "";
            string uuid    = "";
            RMUnit unit    = null;

            IPublisherCallback publisher = OperationContext.Current.GetCallbackChannel <IPublisherCallback>();

            if (m_MeasurementPublishers.Keys.Contains(location))
            {
                IPublisherCallback publishers = m_MeasurementPublishers[location];

                if (publishers == null)
                {
                    m_MeasurementPublishers[location] = publisher;
                    message = "Measurement unit initialised";
                    unit    = GetRMUnitForLocation(location);
                    m_TemperatureCallbacks[location] = new Dictionary <string, IMeasurementUserCallback>();
                    m_HumidityCallbacks[location]    = new Dictionary <string, IMeasurementUserCallback>();
                    if (unit == null)
                    {
                        unit = GenerateNewRMUnit();
                        AddNewRMUnitToDBEntities(location, unit);
                    }

                    uuid = unit.Name;
                }
                else
                {
                    message = "Publisher allready running";
                }
            }
            else
            {
                message = "Invalid location";
            }

            MyRMUnit myUnit = FromDbEntityToMyClass(unit);

            publisher.OnSubcribe(myUnit, message);
        }
Beispiel #4
0
        public void Unsubscribe(string uuid)
        {
            IPublisherCallback callback = OperationContext.Current.GetCallbackChannel <IPublisherCallback>();
            string             message  = "";
            RMUnit             rmu;

            rmu = MyDbContext.RMUnits.ToList().FirstOrDefault(r => r.Name.Equals(uuid));

            if (rmu == null)
            {
                message = "Your unsubscriber UUId now valid!!";
            }
            else
            {
                m_MeasurementPublishers.Remove(rmu.LocationName);
                m_MeasurementPublishers[rmu.LocationName] = null;
                //m_MyDbContext.SaveChanges();
                message = "Unsubscribed!";
            }

            callback.OnUnsubcribe(message);
        }