Inheritance: ObservableClass
Esempio n. 1
0
        public Account()
        {
            _server = FieldValue.GetByName(values, "server");
            _server.PropertyChanged += (s, e) => RaisePropertyChanged("server");
            _username = FieldValue.GetByName(values, "username");
            _username.PropertyChanged += (s, e) => RaisePropertyChanged("username");
            _name = FieldValue.GetByName(values, "name");
            _name.PropertyChanged += (s, e) => RaisePropertyChanged("name");
            _guid = FieldValue.GetByName(values, "guid");
            _guid.PropertyChanged += (s, e) => {

                if (!guid_ok(this, _guid.value) || String.IsNullOrEmpty(_guid.value)) {
                    for (int i = 1; i <= 10; i++) {
                        int val = i == 10 ? 0 : i; // want 0 checked last.
                        if (guid_ok(this, val.ToString())) {
                            _guid.value = val.ToString();
                            return;
                        }
                    }
                }
                RaisePropertyChanged("guid");
                RaisePropertyChanged("gateway_id");
            };
            _caller_id_name = FieldValue.GetByName(values, "caller_id_name");
            _caller_id_name.PropertyChanged += (s, e) => RaisePropertyChanged("caller_id_name");
            _caller_id_number = FieldValue.GetByName(values, "caller_id_number");
            _caller_id_number.PropertyChanged += (s, e) => RaisePropertyChanged("caller_id_number");
            _guid.value = "1";
            PropertyChanged += Account_PropertyChanged;
            state = "NOREG";
        }
Esempio n. 2
0
        public void gen_config(XmlNode config_node)
        {
            XmlNode global_settings = XmlUtils.AddNodeNode(config_node, "global_settings");

            Utils.add_xml_param(global_settings, "auto-restart", "true");
            Utils.add_xml_param(global_settings, "log-level", "0");
            XmlNode profiles = XmlUtils.AddNodeNode(config_node, "profiles");
            XmlNode profile  = XmlUtils.AddNodeNode(profiles, "profile");

            XmlUtils.AddNodeAttrib(profile, "name", "softphone");
            XmlNode gateways = XmlUtils.AddNodeNode(profile, "gateways");

            Account.create_gateway_nodes(gateways, FieldValue.GetByName(values, "tls").value == "true", FieldValue.GetByName(values, "tls-only").value == "true");
            XmlNode settings = XmlUtils.AddNodeNode(profile, "settings");

            Utils.add_xml_param(settings, "context", "public");
            Utils.add_xml_param(settings, "dialplan", "xml");
            Utils.add_xml_param(settings, "disable-register", "true");
            bool tls_cert_check_already = false;

            foreach (FieldValue value in values)
            {
                if (String.IsNullOrEmpty(value.field.xml_name))
                {
                    continue;
                }
                if (String.IsNullOrWhiteSpace(value.value) && !AllowedEmptyFields.Contains(value.field.name))
                {
                    continue;
                }
                String param_value = value.value;
                if ((value.field.name == "tls-only" || value.field.name == "tls") && value.value == "true" && !tls_cert_check_already)
                {
                    if (!tls_cert_exist_check())
                    {
                        param_value = "false";
                    }
                    else
                    {
                        tls_cert_check_already = true;
                    }
                }

                Utils.add_xml_param(settings, value.field.xml_name, param_value);
                if (value.field.xml_name == "codec-prefs")
                {
                    Utils.add_xml_param(settings, "inbound-codec-prefs", param_value);
                    Utils.add_xml_param(settings, "outbound-codec-prefs", param_value);
                }
            }

            DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 1000);
        }
Esempio n. 3
0
        private bool sofia_actual_profile_check(bool is_last_try)
        {
            String res = Utils.api_exec("sofia", "xmlstatus profile softphone").ToLower().Trim();

            if (res == "invalid command!")
            {
                if (!is_last_try)
                {
                    return(false);
                }
                MessageBox.Show("Warning mod_sofia module does not seem to be loaded please make sure it exists");
                master_profile_ok = false;
                return(false);
            }
            if (res == "invalid profile!")
            {
                if (!is_last_try)
                {
                    return(false);
                }
                String tls_port_msg = "";
                if (FieldValue.GetByName(values, "tls").value == "true")
                {
                    tls_port_msg += " and tls bind port (" + FieldValue.GetByName(values, "tls-sip-port").value + ")";
                }
                var message_res = MessageBox.Show("Warning the master sofia profile was not able to load and the phone will most likely _not_ work, make sure the local bind port (" + FieldValue.GetByName(values, "sip-port").value + ")" + tls_port_msg + " is free(set under the Advanced tab of in the sofia settings) and FSClient is allowed through your firewall, otherwise check the freeswitch.log for more details. This can sometimes happen when you lose network connection. You can try reloading the sofia profile by editing the sofia settings and clicking save to see if fixed.   Do you want to try and reload sofia now?", "Sofia Profile Not Loaded", MessageBoxButton.YesNo);
                master_profile_ok = false;
                if (message_res == MessageBoxResult.Yes)
                {
                    reload_config(RELOAD_CONFIG_MODE.MODULE);
                }
                return(false);
            }
            if (res.Contains("<context>public</context>") == false)
            {
                if (!is_last_try)
                {
                    return(false);
                }
                master_profile_ok = false;
                MessageBox.Show("I believe there may be a problem with sofia, but I do not know what");
                return(false);
            }
            master_profile_ok = true;
            return(true);
        }
Esempio n. 4
0
        private UIElement CreateElementValuer(FieldValue value)
        {
            Control ret = null;

            switch (value.field.type)
            {
            case Field.FIELD_TYPE.Int:
                TextBox ibox = new TextBox();
                ibox.Text  = value.value;
                ibox.Width = 50;
                ret        = ibox;
                break;

            case Field.FIELD_TYPE.MultiItem:
            case Field.FIELD_TYPE.MultiItemSort:
                ListBox listBox = new ListBox();
                listBox.SelectionMode = SelectionMode.Multiple;
                if (value.field.type == Field.FIELD_TYPE.MultiItemSort)
                {
                    CreateSortableContextMenu(listBox);
                }
                listBox.Height = 100;
                listBox.Width  = 190;
                String[] vals = value.value.Split(',');
                foreach (String val in vals)
                {
                    Field.FieldOption opt = Field.FieldOption.GetByValue(value.field.options, val);
                    if (opt != null)
                    {
                        listBox.Items.Add(opt);
                        listBox.SelectedItems.Add(opt);
                    }
                }
                foreach (Field.FieldOption option in value.field.options)
                {
                    if (value.field.Validator != null && !String.IsNullOrEmpty(value.field.Validator(option.value)))
                    {
                        continue;
                    }
                    if (listBox.Items.Contains(option))
                    {
                        continue;
                    }
                    listBox.Items.Add(option);
                }
                ret = listBox;
                break;

            case Field.FIELD_TYPE.String:
                TextBox box = new TextBox();
                box.Text  = value.value;
                box.Width = 200;
                ret       = box;
                break;

            case Field.FIELD_TYPE.Password:
                PasswordBox pbox = new PasswordBox();
                pbox.Password = value.value;
                pbox.Width    = 200;
                ret           = pbox;
                break;

            case Field.FIELD_TYPE.Bool:
                CheckBox cbox = new CheckBox();
                cbox.IsChecked = (value.value == "true");
                ret            = cbox;
                break;

            case Field.FIELD_TYPE.Combo:
                ComboBox comboBox = new ComboBox();
                foreach (Field.FieldOption option in value.field.options)
                {
                    if (value.field.Validator == null || String.IsNullOrEmpty(value.field.Validator(option.value)))
                    {
                        comboBox.Items.Add(option);
                    }
                }
                comboBox.SelectedItem = Field.FieldOption.GetByValue(value.field.options, value.value);
                if (comboBox.SelectedIndex == -1)
                {
                    comboBox.SelectedIndex = 0;
                }
                ret = comboBox;
                break;
            }
            AutomationProperties.SetName(ret, value.field.display_name);
            return(ret);
        }
Esempio n. 5
0
 public SettingsField(FieldValue fv)
 {
     name = fv.field.name;
     value = fv.value;
 }
Esempio n. 6
0
 public static void SetValues(FieldValue[] values, params string[] name_value_pairs)
 {
     for (int i = 0; i < name_value_pairs.Length; i += 2)
         GetByName(values, name_value_pairs[i]).value = name_value_pairs[i + 1];
 }
Esempio n. 7
0
 public static FieldValue GetByName(FieldValue[] values, string name)
 {
     return (from v in values where v.field.name == name select v).SingleOrDefault();
 }
Esempio n. 8
0
 private String GetValueFromUI(FieldValue value, UIElement elem)
 {
     String val = null;
     switch (value.field.type) {
         case Field.FIELD_TYPE.MultiItem:
         case Field.FIELD_TYPE.MultiItemSort:
             ListBox listBox = (elem as ListBox);
             val = "";
             foreach (Object obj in listBox.Items) {
                 if (listBox.SelectedItems.Contains(obj) == false)
                     continue;
                 Field.FieldOption opt2 = obj as Field.FieldOption;
                 if (opt2 != null) {
                     if (!String.IsNullOrEmpty(val))
                         val += ",";
                     val += opt2.value;
                 }
             }
             break;
         case Field.FIELD_TYPE.Int:
         case Field.FIELD_TYPE.String:
             val = ((TextBox) elem).Text;
             break;
         case Field.FIELD_TYPE.Password:
             val = ((PasswordBox) elem).Password;
             break;
         case Field.FIELD_TYPE.Bool:
             val = (((CheckBox) elem).IsChecked == true) ? "true" : "false";
             break;
         case Field.FIELD_TYPE.Combo:
             Field.FieldOption opt = ((ComboBox) elem).SelectedItem as Field.FieldOption;
             if (opt != null)
                 val = opt.value;
             break;
     }
     return val;
 }
Esempio n. 9
0
 private UIElement CreateElementValuer(FieldValue value)
 {
     Control ret = null;
     switch (value.field.type) {
         case Field.FIELD_TYPE.Int:
             TextBox ibox = new TextBox();
             ibox.Text = value.value;
             ibox.Width = 50;
             ret = ibox;
             break;
         case Field.FIELD_TYPE.MultiItem:
         case Field.FIELD_TYPE.MultiItemSort:
             ListBox listBox = new ListBox();
             listBox.SelectionMode = SelectionMode.Multiple;
             if (value.field.type == Field.FIELD_TYPE.MultiItemSort)
                 CreateSortableContextMenu(listBox);
             listBox.Height = 100;
             listBox.Width = 190;
             String[] vals = value.value.Split(',');
             foreach (String val in vals) {
                 Field.FieldOption opt = Field.FieldOption.GetByValue(value.field.options, val);
                 if (opt != null){
                     listBox.Items.Add(opt);
                     listBox.SelectedItems.Add(opt);
                 }
             }
             foreach (Field.FieldOption option in value.field.options) {
                 if (value.field.Validator != null && !String.IsNullOrEmpty(value.field.Validator(option.value)))
                     continue;
                 if (listBox.Items.Contains(option))
                     continue;
                 listBox.Items.Add(option);
             }
             ret = listBox;
             break;
         case Field.FIELD_TYPE.String:
             TextBox box = new TextBox();
             box.Text = value.value;
             box.Width = 200;
             ret = box;
             break;
         case Field.FIELD_TYPE.Password:
             PasswordBox pbox = new PasswordBox();
             pbox.Password = value.value;
             pbox.Width = 200;
             ret = pbox;
             break;
         case Field.FIELD_TYPE.Bool:
             CheckBox cbox = new CheckBox();
             cbox.IsChecked = (value.value == "true");
             ret = cbox;
             break;
         case Field.FIELD_TYPE.Combo:
             ComboBox comboBox = new ComboBox();
             foreach (Field.FieldOption option in value.field.options) {
                 if (value.field.Validator == null || String.IsNullOrEmpty(value.field.Validator(option.value)))
                     comboBox.Items.Add(option);
             }
             comboBox.SelectedItem = Field.FieldOption.GetByValue(value.field.options, value.value);
             if (comboBox.SelectedIndex == -1)
                 comboBox.SelectedIndex = 0;
             ret = comboBox;
             break;
     }
     AutomationProperties.SetName(ret, value.field.display_name);
     return ret;
 }
Esempio n. 10
0
 public string getSendVoicemailURL()
 {
     if (send_voicemail_val == null)
         send_voicemail_val = FieldValue.GetByName(values, "sip_send_voicemail_url");
     return send_voicemail_val.value;
 }
Esempio n. 11
0
 public string getCheckVoicemailURL()
 {
     if (check_voicemail_val == null)
         check_voicemail_val = FieldValue.GetByName(values, "sip_check_voicemail_url");
     return check_voicemail_val.value;
 }
Esempio n. 12
0
 public SettingsField(FieldValue fv)
 {
     name  = fv.field.name;
     value = fv.value;
 }