Esempio n. 1
0
 /// <summary>
 /// Executes the command for the current sequence.
 /// </summary>
 private static void ExecuteCommand()
 {
     AlertBox.Close();
     System.Diagnostics.Process          process   = new System.Diagnostics.Process();
     System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
     startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     startInfo.FileName    = "cmd.exe";
     startInfo.Arguments   = " /C " + Command(currentSequence);
     process.StartInfo     = startInfo;
     process.Start();
 }
Esempio n. 2
0
        /// <summary>
        /// Set the sequence to the specified sequence and type to Fast.
        /// </summary>
        /// <param name="seq">The sequence to be set.</param>
        internal static void Set(SequenceList seq)
        {
            Log.Write("Trying to change sequence.");

            if (currentSequence == seq)
            {
                OnErrorEvent(seq == SequenceList.NoShutdown ? "Already unset any sequence." :
                             "There is a sequence already set.");
                return;
            }

            if (currentSequence > SequenceList.NoShutdown && seq > SequenceList.NoShutdown)
            {
                OnErrorEvent("There is a sequence already set.");
                return;
            }

            if (seq < SequenceList.NoShutdown || seq > SequenceList.LockUser)
            {
                OnErrorEvent("Setting to an invalid sequence.");
                return;
            }

            Stop();
            if (seq == SequenceList.NoShutdown)
            {
                currentType = SequenceType.None;
                Log.Write("Successfully unset current sequence.");
            }
            else
            {
                alarm         = new Alarm(2000);
                alarm.Expire += () =>
                {
                    ExecuteCommand();
                    Reset();
                };
                alarm.Start();
                currentType = SequenceType.Fast;
                if (Config.Equals("alert", "1"))
                {
                    AlertBox.Show("Sequence Changed!",
                                  "Will " + seq + " in a moment.",
                                  1800);
                }
                Log.Write("Set sequence to " + currentType + " " + seq + ".");
            }

            currentSequence = seq;
            OnSequenceChangeEvent(new SequenceChangeEventArgs(CurrentSequence, CurrentType));
        }
Esempio n. 3
0
 /// <summary>
 /// Invokes the message event with the specified error message.
 /// </summary>
 /// <param name="message">The error message of the event.</param>
 private static void OnErrorEvent(string message)
 {
     Log.Write(message);
     if (Config.Equals("alert", "1"))
     {
         AlertBox.Show("Sequence Change Error!", message);
     }
     if (Requested)
     {
         Server.Send(new Data("sequence", "-1").Add(message));
         Requested = false;
     }
     Error?.Invoke(message);
 }
Esempio n. 4
0
        /// <summary>
        /// Set the sequence to the specified sequence and its type to Scheduled.
        /// Will execute on the date provided.
        /// </summary>
        /// <param name="seq">The sequence to be set.</param>
        /// <param name="date">DateTime instance of the date when will execute.</param>
        internal static void Set(SequenceList seq, MyDate date)
        {
            Log.Write("Trying to change sequence.");
            if (currentSequence > SequenceList.NoShutdown && seq > SequenceList.NoShutdown)
            {
                OnErrorEvent("There is a sequence already set.");
                return;
            }

            if (seq < SequenceList.Shutdown || seq > SequenceList.LockUser)
            {
                OnErrorEvent("Setting to an invalid timed sequence.");
                return;
            }

            if (date.Millis < new MyDate().Millis + 5000)
            {
                OnErrorEvent("Setting scheduled sequence time five seconds or less in the future.");
                return;
            }

            Stop();

            alarm         = new Alarm(date);
            alarm.Expire += () =>
            {
                ExecuteCommand();
                Reset();
            };
            alarm.AddTimeoutThreshold(60000);
            alarm.AddTimeoutThreshold(600000);
            alarm.AddTimeoutThreshold(3600000);

            alarm.TimeoutRemaining += (int remain) =>
            {
                if (Config.Equals("alert", "1"))
                {
                    string alert = "Will " + CurrentSequence + " in less than ";
                    switch (remain)
                    {
                    case 60000:
                        alert += "a minute.";
                        break;

                    case 600000:
                        alert += "ten minutes.";
                        break;

                    case 3600000:
                        alert += "an hour.";
                        break;
                    }
                    AlertBox.Show("Sequence Reminder!", alert, 15000);
                }
            };
            Console.WriteLine(alarm.Timeout);
            alarm.Start();

            currentType     = SequenceType.Scheduled;
            currentSequence = seq;

            if (Config.Equals("alert", "1"))
            {
                AlertBox.Show("Sequence Changed!",
                              "Will " + seq + " on " + date.GetString() + ".",
                              15000);
            }
            Log.Write("Set sequence to " + currentType + " " + seq + " that will execute on " + date.GetString() + ".");

            OnSequenceChangeEvent(new SequenceChangeEventArgs(CurrentSequence, date));
        }
Esempio n. 5
0
        /// <summary>
        /// Set the sequence to the specified sequence and its type to Timed.
        /// Will execute after the specified timeout in milliseconds.
        /// </summary>
        /// <param name="seq">The sequence to be set.</param>
        /// <param name="timeout">The number of milliseconds before it executes.</param>
        internal static void Set(SequenceList seq, int timeout)
        {
            Log.Write("Trying to change sequence.");
            if (currentSequence > SequenceList.NoShutdown && seq > SequenceList.NoShutdown)
            {
                OnErrorEvent("There is a sequence already set.");
                return;
            }

            if (seq < SequenceList.Shutdown || seq > SequenceList.LockUser)
            {
                OnErrorEvent("Setting to an invalid timed sequence.");
                return;
            }

            if (timeout < 5000)
            {
                OnErrorEvent("Setting timed sequence with timeout less than 5 seconds.");
                return;
            }

            Stop();

            alarm         = new Alarm(timeout);
            alarm.Expire += () =>
            {
                ExecuteCommand();
                Reset();
            };
            alarm.AddTimeoutThreshold(60000);
            alarm.AddTimeoutThreshold(600000);
            alarm.AddTimeoutThreshold(3600000);

            alarm.TimeoutRemaining += (int remain) =>
            {
                if (Config.Equals("alert", "1"))
                {
                    string alert = "Will " + CurrentSequence + " in less than ";
                    switch (remain)
                    {
                    case 60000:
                        alert += "a minute.";
                        break;

                    case 600000:
                        alert += "ten minutes.";
                        break;

                    case 3600000:
                        alert += "an hour.";
                        break;
                    }
                    AlertBox.Show("Sequence Reminder!", alert, 15000);
                }
            };

            alarm.Start();

            currentType     = SequenceType.Timed;
            currentSequence = seq;

            int hr  = timeout / 3600000;
            int min = (timeout % 3600000) / 60000;
            int sec = ((timeout % 3600000) % 60000) / 1000;

            string show = "";

            if (hr > 0)
            {
                show += hr + " hour" + (hr > 0 ? "s" : "") + (min > 0 || sec > 0 ? ", " : "");
            }

            if (min > 0)
            {
                show += min + " minute" + (min > 0 ? "s" : "") + (sec > 0 ? ", " : "");
            }

            if (sec > 0)
            {
                show += sec + " second" + (sec > 0 ? "s" : "") + "";
            }

            if (Config.Equals("alert", "1"))
            {
                AlertBox.Show("Sequence Changed!",
                              "Will " + seq + " in " + show + ".",
                              15000);
            }
            Log.Write("Set sequence to " + currentType + " " + seq + " that will execute after " + show + ".");

            OnSequenceChangeEvent(new SequenceChangeEventArgs(CurrentSequence, timeout));
        }