示例#1
0
        public bool ExecuteTrigger(string triggerName, bool useDefaultMessage, string message, string source)
        {
            Log.Add(LogLevel.Info, "Trigger", String.Format("Executing trigger {0}/{1} requested by {2}", triggerName, message, source));

            try
            {
                TriggerInfo triggerInfo = GetTriggerInfo(triggerName);

                if (triggerInfo.Id < 0)
                {
                    Log.Add(LogLevel.Warning, "Trigger", String.Format("Trigger {0} not found.", triggerName));
                    return false;
                }

                Log.Add(LogLevel.Debug, "Trigger", "Trigger " + triggerInfo.Name + " exists, running...");

                TriggerSlotInfo currentSlot = GetCurrentTriggerSlot(triggerInfo, DateTime.Now);

                if (currentSlot.SlotId < 0)
                {
                    Log.Add(LogLevel.Warning, "Trigger", "Not valid trigger slot found. Check Database for consistency.");
                    return false;
                }

                Log.Add(LogLevel.Debug, "Trigger", String.Format("Found Slot {0}, DOW {1}, Text: {2}", currentSlot.SlotId, currentSlot.DayOfWeek, currentSlot.Text));

                PersonInfo[] persons = GetSlotPersons(currentSlot);

                Log.Add(LogLevel.Debug, "Trigger", String.Format("Found {0} persons", persons.Length));

                string alarmtext = currentSlot.Text;

                if (message != String.Empty && !useDefaultMessage)
                {
                    alarmtext = message;
                }

                DateTime date = DateTime.Now;

                StringBuilder builder = new StringBuilder();
                builder.AppendLine(String.Format("{3:00}:{4:00} / {0:00}.{1:00}.{2:0000}", date.Day, date.Month, date.Year, date.Hour, date.Minute));
                builder.AppendLine();
                builder.Append("Auslöser: ");
                builder.AppendLine(triggerInfo.Name);
                builder.Append("Text: ");
                builder.AppendLine(alarmtext);
                builder.Append("Quelle: ");
                builder.AppendLine(source);
                builder.AppendLine();
                builder.AppendLine("Alarmiere " + persons.Length + " Personen:");
                builder.AppendLine();

                foreach (PersonInfo person in persons)
                {
                    Log.Add(LogLevel.Verbose, "Trigger", String.Format("({2}) {0}: {1} {3}", person.Name, person.Number, person.PersonId, person.Flash ? "(f)" : String.Empty));
                    builder.AppendLine(String.Format("- {0} / {1} {2}", person.Name, person.Number, person.Flash ? "(f)" : String.Empty));
                }

                if (OnFreetextMessage != null)
                {
                    OnFreetextMessage(this, "Alarmierung", builder.ToString());
                }

                if (OnTriggerMessage != null)
                {
                    foreach (PersonInfo person in persons)
                    {
                        TriggerMessage msg = new TriggerMessage();
                        msg.Destination = person.Number;
                        msg.Text = alarmtext;
                        msg.FlashMessage = person.Flash;
                        Log.Add(LogLevel.Debug, PluginName, string.Format("Throwing TriggerMessage for {0} Flash: {1}", msg.Destination, msg.FlashMessage));
                        OnTriggerMessage(this, msg);
                    }
                }

                Log.Add(LogLevel.Info, "Trigger", String.Format("Processed {0} persons.", persons.Length));
                return true;
            }
            catch (Exception ex)
            {
                Log.AddException("Trigger", ex);
                return false;
            }
        }
示例#2
0
 public void HandleTriggerMessage(object sender, TriggerMessage message)
 {
     Log.Add(LogLevel.Debug, "SMS", string.Format("Enqueing Message to {0}", message.Destination));
     _messagesToSend.Enqueue(message);
 }