private string GetReminderDetails(OutlookReminder reminder)
        {
            string scheduleDetails = "You have an appointment at " + reminder.ScheduledDateTime.ToShortTimeString() + ".";

            if (reminder.Subject.Length > 0)
            {
                scheduleDetails += "The subject of this appointment is " + reminder.Subject + ". ";
            }

            if (reminder.Location.Length > 0)
            {
                scheduleDetails += "The location of this appointment is " + reminder.Location + ". ";
            }

            return(scheduleDetails);
        }
        protected override void OnExternalCommand(string command, string commandData, string eventToken, TelecomScriptInterface tsInterface, CallButler.Telecom.TelecomProviderBase telecomProvider, WOSI.CallButler.Data.DataProviders.CallButlerDataProviderBase dataProvider)
        {
            // Parse out our external event action
            if (Enum.IsDefined(typeof(ScheduleReminderExternalCommands), command))
            {
                ScheduleReminderExternalCommands externalCommand = WOSI.Utilities.EnumUtils <ScheduleReminderExternalCommands> .Parse(command);

                switch (externalCommand)
                {
                case ScheduleReminderExternalCommands.CALLBUTLERINTERNAL_GetNextNumber:
                {
                    // If we have a previous call, end it
                    if (telecomProvider.IsLineInUse(tsInterface.LineNumber))
                    {
                        telecomProvider.EndCall(tsInterface.LineNumber);
                    }

                    extensionNumberIndex++;

                    // Get our extension contact numbers
                    WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[] contactNumbers = (WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow[])dataProvider.GetExtensionContactNumbers(extension.ExtensionID).Select("", "Priority ASC");

                    while (extensionNumberIndex < contactNumbers.Length)
                    {
                        WOSI.CallButler.Data.CallButlerDataset.ExtensionContactNumbersRow contactNumber = contactNumbers[extensionNumberIndex];

                        // Is the number online?
                        if (contactNumber.Online)
                        {
                            // Does the number have hours?
                            if (!contactNumber.HasHoursOfOperation || (contactNumber.HasHoursOfOperation && ScriptUtils.IsInHoursOfOperation(contactNumber.HoursOfOperation, contactNumber.HoursOfOperationUTCOffset)))
                            {
                                // If we get here, try the number
                                tsInterface.IMLInterpreter.SetLocalVariable("NumberToCall", contactNumber.ContactNumber);

                                tsInterface.IMLInterpreter.SetLocalVariable("ExtensionTimeout", contactNumber.Timeout.ToString());

                                string introDetails = "You have " + reminders.Length + " upcoming appointment";

                                if (reminders.Length > 1)
                                {
                                    introDetails += "s";
                                }

                                introDetails += ".";

                                tsInterface.IMLInterpreter.SetLocalVariable("IntroDetails", introDetails);

                                tsInterface.IMLInterpreter.SignalEventCallback(eventToken);

                                return;
                            }
                        }

                        extensionNumberIndex++;
                    }

                    if (telecomProvider.IsLineInUse(tsInterface.LineNumber))
                    {
                        telecomProvider.EndCall(tsInterface.LineNumber);
                    }

                    tsInterface.IMLInterpreter.StopScript();
                    break;
                }

                case ScheduleReminderExternalCommands.CALLBUTLERINTERNAL_FetchNextReminder:
                {
                    reminderIndex++;

                    if (reminderIndex < reminders.Length)
                    {
                        OutlookReminder reminder = reminders[reminderIndex];

                        tsInterface.IMLInterpreter.SetLocalVariable("ScheduleDetails", GetReminderDetails(reminder));

                        if (reminderIndex == reminders.Length - 1)
                        {
                            tsInterface.IMLInterpreter.SignalExternalEvent(ScheduleReminderExternalEvents.CALLBUTLERINTERNAL_LastReminder.ToString());
                        }
                        else
                        {
                            tsInterface.IMLInterpreter.SignalEventCallback(eventToken);
                        }
                    }
                    else
                    {
                        tsInterface.IMLInterpreter.SignalExternalEvent(ScheduleReminderExternalEvents.CALLBUTLERINTERNAL_EndOfReminders.ToString());
                    }


                    break;
                }
                }
            }
        }