예제 #1
0
 public void DeleteAlarmRang(Alarm alarm)
 {
     if (alarm == fastestCameAlarm)
     {
         fastestCameAlarm = null;
         measuringAlarms.Remove(alarm);
     }
 }
예제 #2
0
        private void StartAlarmButton_Click(object sender, RoutedEventArgs e)
        {
            Func<TextBox, int> GetIntFromTextBox = (tb) =>
            {
                if (tb.Text == "")
                {
                    return 0;
                }

                int i;
                if (int.TryParse(tb.Text, out i))
                {
                    return i;
                }
                else
                {
                    return -1;
                }
            };

            int hours = GetIntFromTextBox(AlarmHours);
            int minutes = GetIntFromTextBox(AlarmMinutes);
            int seconds = GetIntFromTextBox(AlarmSeconds);
            if ((hours >= 0 && minutes >= 0 && seconds >= 0) &&
                (hours + minutes + seconds) > 0)
            {
                Alarm alarm = new Alarm(hours, minutes, seconds, DateTime.Now, AlarmRemarks.Text);
                measuringAlarms.AddAlarm(alarm);

                TabClock.IsSelected = true;
            }
            else
            {
                MessageBox.Show("時間には半角数字の0かそれ以上の整数を入力してください。\n空欄は0と認識します。");
            }

            //終了処理
            AlarmHours.Text = "";
            AlarmMinutes.Text = "";
            AlarmSeconds.Text = "";
            AlarmRemarks.Text = "";
        }
예제 #3
0
        private void measuringAlarms_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            fastestCameAlarm = null;

            if (measuringAlarms.Count() == 0)
            {
                SetTimerMonitorPattern("0");
                return;
            }

            foreach (Alarm alarm in measuringAlarms)
            {
                if (fastestCameAlarm == null)
                {
                    fastestCameAlarm = alarm;
                }
                else if (alarm.AlarmMeasuring < fastestCameAlarm.AlarmMeasuring)
                {
                    fastestCameAlarm = alarm;
                }
            }
        }
예제 #4
0
        private void LoadAlarmLog()
        {
            String logFilePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                @"Yu",
                @"BreakAlarm",
                @"log.txt");
            if (!File.Exists(logFilePath))
            {
                return;
            }

            using (StreamReader reader = new StreamReader(logFilePath))
            {
                String patternTimeSpan = "\\((?<span_hour>\\d\\d):(?<span_minute>\\d\\d):(?<span_second>\\d\\d)\\)";
                String patternExecutionDate = "\\((?<exec_year>\\d\\d\\d\\d)/(?<exec_month>\\d\\d)/(?<exec_day>\\d\\d)\\s+(?<exec_hour>\\d\\d):(?<exec_minute>\\d\\d):(?<exec_second>\\d\\d)\\)";
                String patternRemarks = "(?<remarks>.*)\n?";
                String line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    Match match = Regex.Match(line, String.Format(
                        "{0}\\s+{1}:\\s+{2}",
                        patternTimeSpan,
                        patternExecutionDate,
                        patternRemarks
                        ));

                    Func<Match, String, int> GetIntFromGroup = (m, key) =>
                    {
                        return int.Parse(m.Groups[key].Value);
                    };

                    int hour = GetIntFromGroup(match, "span_hour");
                    int minute = GetIntFromGroup(match, "span_minute");
                    int second = GetIntFromGroup(match, "span_second");
                    DateTime executionDate = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(
                        GetIntFromGroup(match, "exec_year"),
                        GetIntFromGroup(match, "exec_month"),
                        GetIntFromGroup(match, "exec_day"),
                        GetIntFromGroup(match, "exec_hour"),
                        GetIntFromGroup(match, "exec_minute"),
                        GetIntFromGroup(match, "exec_second")
                    ), TimeZoneInfo.Local);
                    String remarks = match.Groups["remarks"].Value;
                    Alarm alarm = new Alarm(hour, minute, second, executionDate, remarks);
                    logAlarms.Add(alarm);
                }
            }
        }
예제 #5
0
 public void UpdateMainWindowInfo(Alarm alarm)
 {
     SetTimerMonitorPattern("0");
     LatestAlarmInfo.Text += String.Format("{0}: Alarm({1} \"{2}\") came.\n",
         alarm.AlarmMeasuring,
         alarm.AlarmSetting,
         alarm.Remarks);
     logAlarms.Insert(0, alarm);
 }
예제 #6
0
        public void NoticeActionCenter(Alarm alarm)
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText03;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastImageElements = toastXml.GetElementsByTagName("image");
            ((XmlElement)toastImageElements[0]).SetAttribute("src",
                "file://" + System.IO.Path.GetFullPath("NotifyIcon.png"));

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].InnerText = "BreakAlarm: " + alarm.AlarmSetting.ToString();
            toastTextElements[1].InnerText = alarm.Remarks;

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            ((XmlElement)toastNode).SetAttribute("duration", "long");

            ToastNotification toast = new ToastNotification(toastXml);
            toast.Activated += toast_Activated;
            toast.Dismissed += toast_Dismissed;
            toast.Failed += toast_Failed;

            ToastNotificationManager.CreateToastNotifier(Properties.Resources.ApplicationId).Show(toast);
        }