Example #1
0
        public XmlDocument GetCurrentConfiguration()
        {
            ConfStorage storage = null;

            if (Application["m_ConfStorage"] != null)
            {
                storage = (ConfStorage)Application["m_ConfStorage"];
            }
            else
            {
                storage = new ConfStorage();
                Application["m_ConfStorage"] = storage;
            }

            MemoryStream ms = new MemoryStream();
            SerializableConfiguration config = storage.GetSerializableConfiguration();

            System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(SerializableConfiguration));
            ser.Serialize(ms, config);
            ms.Seek(0, SeekOrigin.Begin);

            XmlDocument doc = new XmlDocument();

            doc.Load(ms);
            return(doc);
        }
Example #2
0
 /// <summary>
 /// Storage load if this is not done yet
 /// </summary>
 public void ConfStorageLoad()
 {
     if (Application[AppVars.CONFSTORAGE] != null)
     {
         m_ConfStorage = (ConfStorage)Application[AppVars.CONFSTORAGE];
     }
     else
     {
         m_ConfStorage = new ConfStorage();
         Application[AppVars.CONFSTORAGE] = m_ConfStorage;
     }
 }
        /***************************************************************************************/

        #region General

        /// <summary>
        /// Storage load if this is not done yet
        /// </summary>
        public void ConfStorageLoad()
        {
            if (Application["m_ConfStorage"] != null)
            {
                m_ConfStorage = (ConfStorage)Application["m_ConfStorage"];
            }
            else
            {
                m_ConfStorage = new ConfStorage();
                Application["m_ConfStorage"] = m_ConfStorage;
            }
        }
Example #4
0
        public void LoadConfiguration(XmlDocument configuration)
        {
            XmlReader reader = new XmlNodeReader(configuration.DocumentElement);

            System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(SerializableConfiguration));
            SerializableConfiguration config           = (SerializableConfiguration)ser.Deserialize(reader);



            ConfStorage storage = ConfStorage.Load(config);

            Application["m_ConfStorage"] = storage;
        }
        protected void btnConfigure_Click(object sender, EventArgs e)
        {
            try
            {
                lblError.Text = string.Empty;

                Stream stream = fileSelector.FileContent;

                System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(SerializableConfiguration));
                SerializableConfiguration config           = (SerializableConfiguration)ser.Deserialize(stream);

                ConfStorage storage = ConfStorage.Load(config);
                Application["m_ConfStorage"] = storage;
            }
            catch (Exception exc)
            {
                lblError.Text = "Error: " + exc.Message;
            }
        }
Example #6
0
        public void ProcessModeChanging(string doorToken,
                                        DoorMode mode,
                                        ConfStorage storage,
                                        EventServer eventServer,
                                        ExternalLogging.StateReportingService stateReporter)
        {
            if (_eventServer != eventServer || _stateReporter != stateReporter)
            {
                _eventServer   = eventServer;
                _stateReporter = stateReporter;
                InitUpdateActions();
            }

            TriggerSettings[] settings =
                storage.TriggerConfiguration.Settings.Where(S => S.DoorToken == doorToken).ToArray();

            DoorState state = storage.DoorStateList[doorToken];

            if (settings != null)
            {
                List <TriggerSettings> triggers = new List <TriggerSettings>();

                TriggerSettings doorMonitorSettings =
                    settings.Where(S => S.Sensor == Sensor.DoorMonitor && S.DoorMode == mode).FirstOrDefault();
                if (doorMonitorSettings != null)
                {
                    triggers.Add(doorMonitorSettings);
                }

                TriggerSettings doorLockMonitorSettings =
                    settings.Where(S => S.Sensor == Sensor.DoorLockMonitor && S.DoorMode == mode).FirstOrDefault();
                if (doorLockMonitorSettings != null)
                {
                    triggers.Add(doorLockMonitorSettings);
                }

                TriggerSettings doorDoubleLockMonitorSettings =
                    settings.Where(S => S.Sensor == Sensor.DoorDoubleLockMonitor && S.DoorMode == mode).FirstOrDefault();
                if (doorDoubleLockMonitorSettings != null)
                {
                    triggers.Add(doorDoubleLockMonitorSettings);
                }

                List <TriggerSettings> orderedTriggers = triggers.OrderBy(TS => TS.Timeout).ToList();

                if (orderedTriggers.Count > 0)
                {
                    Dictionary <Sensor, object> values = new Dictionary <Sensor, object>();

                    values.Add(Sensor.DoorMonitor, _doorMonitorValues[mode]);
                    values.Add(Sensor.DoorLockMonitor, _doorLockMonitorValues[mode]);
                    values.Add(Sensor.DoorDoubleLockMonitor, _doorDoubleLockMonitorValues[mode]);

                    int timeout = 0;

                    List <Action> update = new List <Action>();

                    for (int i = 0; i < orderedTriggers.Count; i++)
                    {
                        TriggerSettings ts    = orderedTriggers[i];
                        int             delay = ts.Timeout - timeout;
                        if (delay > 0)
                        {
                            Action del = () => { Thread.Sleep(delay); };
                            update.Add(del);
                        }
                        Action nextAction = () => _updates[ts.Sensor](state, doorToken, values[ts.Sensor]);

                        System.Diagnostics.Debug.WriteLine(string.Format("{0}: {1} => {2}", ts.Timeout, ts.Sensor, values[ts.Sensor]));

                        update.Add(nextAction);
                        timeout = ts.Timeout;
                    }

                    Action updateAll = new Action(
                        () =>
                    {
                        foreach (Action del in update)
                        {
                            del.Invoke();
                        }
                    });
                    updateAll.BeginInvoke(null, null);
                }
            }
        }