Ejemplo n.º 1
0
        public static string Serialize(TimerPreferences prefs)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(TimerPreferences));

            StringWriter writer = new StringWriter();

            formatter.Serialize(writer, prefs);

            return(writer.ToString());
        }
Ejemplo n.º 2
0
        public static TimerPreferences Deserialize(string xml)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(TimerPreferences));

            TextReader reader = new StringReader(xml);

            TimerPreferences prefs = (TimerPreferences)formatter.Deserialize(reader);

            return(prefs);
        }
Ejemplo n.º 3
0
        public void Launch(TimerPreferences preferences)
        {
            _timerPreferences = preferences;

            DateTime now = DateTime.Now;

            _finishingTime = now + new TimeSpan(preferences.DurationHours, preferences.DurationMinutes,
                                                preferences.DurationSeconds);

            MainCounter.Start();
        }
Ejemplo n.º 4
0
        private bool ReadUi(out TimerPreferences prefs)
        {
            prefs = new TimerPreferences();

            // Reading action
            if (NoActionRadbut.Checked)
            {
                prefs.Action = TimerPreferences.FinalAction.None;
            }
            else if (HibernationRadbut.Checked)
            {
                prefs.Action = TimerPreferences.FinalAction.Hibernation;
            }
            else
            {
                prefs.Action = TimerPreferences.FinalAction.ShutDown;
            }

            bool parsingOk = true;

            parsingOk &= Int32.TryParse(HoursBox.Text, out prefs.DurationHours);
            parsingOk &= Int32.TryParse(MinutesBox.Text, out prefs.DurationMinutes);
            parsingOk &= Int32.TryParse(SecondsBox.Text, out prefs.DurationSeconds);

            prefs.MakeWarning = WarningBox.Checked;
            if (prefs.MakeWarning)
            {
                parsingOk &= Int32.TryParse(WarningTimeBox.Text, out prefs.WarningSecondsBeforeEnd);
            }
            else
            {
                prefs.WarningSecondsBeforeEnd = 0;
            }

            prefs.MakeSoundSignal = SignalBox.Checked;

            prefs.HiddenLaunchEnabled = HiddenLaunchBox.Checked;

            return(parsingOk);
        }