public SimpleWizardInRuleControl()
 {
     // Required to initialize variables
     InitializeComponent();
     m_rulePriority.Text = DEFAULT_RULE_PRIORITY.ToString();
     DialCommandSB.Begin();
     HideErrorSB.Begin();
     SpecificTimeStoryboard.Begin();
     m_initialised = true;
 }
        private void CloseErrroMessage(object sender, System.Windows.RoutedEventArgs e)
        {
            ////m_ruleToAccount.IsEnabled = true;
            ////m_ruleType.IsEnabled = true;
            //m_rulePattern.IsEnabled = true;
            ////m_ruleCommandString.IsEnabled = true;
            //m_ruleDescription.IsEnabled = true;
            //m_rulePriority.IsEnabled = true;
            //m_ruleSaveButton.IsEnabled = true;
            //m_ruleCancelButton.IsEnabled = true;

            //m_errorCanvas.Visibility = System.Windows.Visibility.Collapsed;

            //m_descriptionText.Text = (m_ruleToUpdate != null) ? UPDATE_TEXT : ADD_TEXT;

            HideErrorSB.Begin();
        }
        public void SetRuleToUpdate(SimpleWizardRule rule)
        {
            if (rule != null)
            {
                m_ruleToUpdate = rule;
                SetStatusMessage(UPDATE_TEXT, false);

                SetUIToMatchFields(rule);

                m_rulePattern.Text = rule.Pattern;
                m_ruleCommandType.SelectedIndex = m_ruleCommandType.Items.IndexOf(m_ruleCommandType.Items.Single(x => ((TextBlock)x).Text == rule.Command));
                m_ruleDescription.Text          = rule.Description;
                m_rulePriority.Text             = rule.Priority.ToString();
                m_ruleIsDisabled.IsChecked      = rule.IsDisabled;

                if (rule.TimePattern != null)
                {
                    m_ruleWhenSpecificTimes.IsChecked = true;
                    var matchedDays = rule.MatchedDays();
                    m_monCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Monday);
                    m_tueCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Tuesday);
                    m_wedCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Wednesday);
                    m_thuCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Thursday);
                    m_friCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Friday);
                    m_satCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Saturday);
                    m_sunCheckbox.IsChecked = matchedDays.Contains(DayOfWeek.Sunday);
                    m_startTimeHour.Text    = rule.GetStartHour().ToString();
                    m_startTimeMin.Text     = rule.GetStartMinute().ToString();
                    m_endTimeHour.Text      = rule.GetEndHour().ToString();
                    m_endTimeMin.Text       = rule.GetEndMinute().ToString();
                }
                else
                {
                    m_ruleWhenAnytime.IsChecked = true;
                }

                SetUICommandFieldsForRule(rule);
            }
            else
            {
                m_ruleToUpdate = null;
                SetStatusMessage(ADD_TEXT, false);

                //m_ruleToSIPAccount.IsChecked = false;
                //m_ruleToChoiceAny.IsChecked = true;
                m_ruleIsDisabled.IsChecked         = false;
                m_toMatchType.SelectedIndex        = 0;
                m_ruleToAccount.SelectedIndex      = 0;
                m_ruleToProvider.SelectedIndex     = 0;
                m_ruleToRegexText.Text             = String.Empty;
                m_rulePattern.Text                 = String.Empty;
                m_ruleCommandType.SelectedIndex    = 0;
                m_ruleCommandString.Text           = DEFAULT_DIAL_DESTINATION;
                m_ruleProvider.SelectedIndex       = 0;
                m_ruleDescription.Text             = String.Empty;
                m_rulePriority.Text                = DEFAULT_RULE_PRIORITY.ToString();
                m_ruleAdvancedDialString.Text      = String.Empty;
                m_ruleRingDuration.Text            = String.Empty;
                m_ruleAnswerDuration.Text          = String.Empty;
                m_rejectResponseCode.SelectedIndex = DEFAULT_REJECT_RESPONSE_INDEX;
                m_rejectReason.Text                = String.Empty;
                m_highriseURL.Text                 = String.Empty;
                m_highriseToken.Text               = String.Empty;

                m_ruleCommandString.Text = "${EXTEN}";

                m_ruleWhenAnytime.IsChecked       = true;
                m_ruleWhenSpecificTimes.IsChecked = false;
                m_monCheckbox.IsChecked           = true;
                m_tueCheckbox.IsChecked           = true;
                m_wedCheckbox.IsChecked           = true;
                m_thuCheckbox.IsChecked           = true;
                m_friCheckbox.IsChecked           = true;
                m_satCheckbox.IsChecked           = true;
                m_sunCheckbox.IsChecked           = true;
                m_startTimeHour.Text = "00";
                m_startTimeMin.Text  = "00";
                m_endTimeHour.Text   = "23";
                m_endTimeMin.Text    = "59";

                HideErrorSB.Begin();
            }
        }
        private void Submit(object sender, System.Windows.RoutedEventArgs e)
        {
            decimal priority = DEFAULT_RULE_PRIORITY;

            Decimal.TryParse(m_rulePriority.Text, out priority);

            if (m_ruleToUpdate == null)
            {
                SimpleWizardRule rule = new SimpleWizardRule()
                {
                    ID         = Guid.Empty.ToString(),     // Will be set in the manager.
                    Owner      = "None",                    // Will be set in the manager.
                    DialPlanID = Guid.Empty.ToString(),     // Will be set in the manager.
                    Direction  = SIPCallDirection.In.ToString(),
                    //ToSIPAccount = (m_ruleToSIPAccount.IsChecked.GetValueOrDefault()) ? m_ruleToAccount.SelectedValue as string : null,
                    //RuleTypeID = Enum.Parse(typeof(SimpleWizardRuleTypes), ((TextBlock)m_ruleType.SelectedValue).Text, true).GetHashCode(),
                    Pattern     = m_rulePattern.Text,
                    Command     = ((TextBlock)m_ruleCommandType.SelectedValue).Text,
                    Description = m_ruleDescription.Text,
                    Priority    = priority,
                    IsDisabled  = m_ruleIsDisabled.IsChecked.GetValueOrDefault()
                };

                string toFieldsError = SetRuleToMatchFields(rule);
                if (toFieldsError != null)
                {
                    SetErrorMessage(toFieldsError);
                    return;
                }

                string commandParameterError = SetRuleCommandFields(rule);
                if (commandParameterError != null)
                {
                    SetErrorMessage(commandParameterError);
                    return;
                }

                string timePatternError = GetTimePattern(rule);
                if (timePatternError != null)
                {
                    SetErrorMessage(timePatternError);
                    return;
                }

                string validationError = Validate(rule);
                if (validationError != null)
                {
                    SetErrorMessage(validationError);
                }
                else
                {
                    HideErrorSB.Begin();
                    Add(rule);
                }
            }
            else
            {
                //m_ruleToUpdate.ToSIPAccount = (m_ruleToSIPAccount.IsChecked.GetValueOrDefault()) ? m_ruleToAccount.SelectedValue as string : null;
                //m_ruleToUpdate.RuleTypeID = Enum.Parse(typeof(SimpleWizardRuleTypes), ((TextBlock)m_ruleType.SelectedValue).Text, true).GetHashCode();
                m_ruleToUpdate.Pattern     = m_rulePattern.Text;
                m_ruleToUpdate.Command     = ((TextBlock)m_ruleCommandType.SelectedValue).Text;
                m_ruleToUpdate.Description = m_ruleDescription.Text;
                m_ruleToUpdate.Priority    = priority;
                m_ruleToUpdate.IsDisabled  = m_ruleIsDisabled.IsChecked.GetValueOrDefault();

                string toFieldsError = SetRuleToMatchFields(m_ruleToUpdate);
                if (toFieldsError != null)
                {
                    SetErrorMessage(toFieldsError);
                    return;
                }

                string commandParameterError = SetRuleCommandFields(m_ruleToUpdate);
                if (commandParameterError != null)
                {
                    SetErrorMessage(commandParameterError);
                    return;
                }

                string timePatternError = GetTimePattern(m_ruleToUpdate);
                if (timePatternError != null)
                {
                    SetErrorMessage(timePatternError);
                    return;
                }

                string validationError = Validate(m_ruleToUpdate);
                if (validationError != null)
                {
                    SetErrorMessage(validationError);
                }
                else
                {
                    HideErrorSB.Begin();
                    Update(m_ruleToUpdate);
                }
            }
        }