コード例 #1
0
        public void CheckForNewAlarms(InstallNewAlarms installer)
        {
            HttpWebRequest request = WebRequest.Create("http://dstutzman.vail.lan.flt/schedule_xml.php") as HttpWebRequest;
            request.IfModifiedSince = this.scheduleLastModified;
            request.BeginGetResponse(delegate(IAsyncResult result) {
                WebResponse response = null;
                try {
                    response = request.EndGetResponse(result);
                    string xml = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    log.Debug(xml);
                    String lastModifiedString = response.Headers.Get("Last-Modified");
                    log.Debug("Last-Modified: " + lastModifiedString);

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);

                    List<AlarmModel> newAlarms = new List<AlarmModel>();
                    XmlNode scheduleNode = doc.SelectSingleNode("schedule");
                    lastModifiedString = scheduleNode.Attributes.GetNamedItem("lastModified").Value;
                    this.scheduleLastModified = DateTime.Parse(lastModifiedString);
                    foreach (XmlNode alarmNode in scheduleNode.ChildNodes) {
                        String alarmWhenString = alarmNode.Attributes.GetNamedItem("datetime").Value;
                        DateTime alarmWhen = DateTime.ParseExact(alarmWhenString, "yyyy-MM-dd HH:mm:ss",
                            CultureInfo.InvariantCulture);

                        String id = alarmNode.Attributes.GetNamedItem("id").Value;
                        String name = alarmNode.Attributes.GetNamedItem("name").Value;
                        bool isArmed = alarmNode.Attributes.GetNamedItem("armed").Value.Equals("true");
                        AlarmModel alarm = new AlarmModel(id, name, alarmWhen, isArmed);

                        alarm.FiringChange += this.OnAlarmFiringChange;

                        newAlarms.Add(alarm);
                    }

                    installer(newAlarms);
                }
                catch (WebException e) {
                    HttpWebResponse response2 = e.Response as HttpWebResponse;
                    if (response2.StatusCode == HttpStatusCode.NotModified)
                        log.Debug("Got 304");
                    else
                        throw e;
                }
                finally {
                    if (response != null)
                        response.Close();
                }
            }, null);
        }
コード例 #2
0
        public AlarmController(AlarmModel model, AlarmView view)
        {
            this.model = model;
            this.view = view;

            this.view.timeTextBox.Text = this.model.When.ToString("HH:mm");
            this.view.nameTextBox.Text = this.model.Name;
            this.view.offButton.Enabled = this.model.IsArmed;

            this.view.offButton.Click += OnClickOffButton;

            this.model.FiringChange += OnFiringChange;

            this.flashTimer = new Timer();
            this.flashTimer.Interval = 200;
            this.flashTimer.Tick += ToggleBackground;
        }
コード例 #3
0
ファイル: TopModel.cs プロジェクト: danielstutzman/Wasp
 public AlarmEventArgs(AlarmModel alarm)
 {
     this.alarm = alarm;
 }
コード例 #4
0
ファイル: TopModel.cs プロジェクト: danielstutzman/Wasp
 private void FireAlarm(AlarmModel alarm)
 {
     alarm.Fire();
 }