예제 #1
0
        void ActivateNextLineWrapper()
        {
            MainFormPhoneLineControl nextLineControl = null;
            long lastPartTime = -1, lastPartId = -1;

            foreach (var lineWrapper in _mainFormPhoneLineControls)
            {
                if (lineWrapper?.Call != null && !lineWrapper.Active)
                {
                    if (nextLineControl == null)
                    {
                        nextLineControl = lineWrapper;
                    }

                    // We will try to compare unique ids of call and found call with minimal number.
                    // This is because if call is in queue it can leave queue and enter queue again
                    // and it is better to pick it up as soon as possible.
                    var unid = lineWrapper.Call.Headers["x-unid"];
                    if (unid != null)
                    {
                        // Asterisk unique id. Example: 1349177069.455
                        var uniqueId = unid.Value;

                        var uniqueIdParts = uniqueId.Split('.');

                        if (uniqueIdParts.Length == 2)
                        {
                            long partTime, partId;

                            if (long.TryParse(uniqueIdParts[0], out partTime) && long.TryParse(uniqueIdParts[1], out partId))
                            {
                                if (partTime < lastPartTime || (partTime == lastPartTime && partId < lastPartId))
                                {
                                    nextLineControl = lineWrapper;

                                    lastPartTime = partTime;
                                    lastPartId   = partId;
                                }
                                else if (nextLineControl == lineWrapper)
                                {
                                    lastPartTime = partTime;
                                    lastPartId   = partId;
                                }
                            }
                        }
                    }
                }
            }

            if (nextLineControl != null)
            {
                ChangeLineWrapper(nextLineControl);
            }
        }
예제 #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (_core == null)
            {
                throw new NullReferenceException("Core is not initialized");
            }

            Ui.SetCurrent(this);

            Header = string.Format(_baseTitle, CaptionStrings.CaptionStrings.StateInitializing);

            _mainFormPhoneLineControls[0] = new MainFormPhoneLineControl(Core, 0, btnLine1, labelCallerIDName, txtNumber, lblDuration, labelCallState, btnHold);
            _mainFormPhoneLineControls[1] = new MainFormPhoneLineControl(Core, 1, btnLine2, labelCallerIDName, txtNumber, lblDuration, labelCallState, btnHold);
            _mainFormPhoneLineControls[2] = new MainFormPhoneLineControl(Core, 2, btnLine3, labelCallerIDName, txtNumber, lblDuration, labelCallState, btnHold);
            _mainFormPhoneLineControls[3] = new MainFormPhoneLineControl(Core, 3, btnLine4, labelCallerIDName, txtNumber, lblDuration, labelCallState, btnHold);
            _mainFormPhoneLineControls[4] = new MainFormPhoneLineControl(Core, 4, btnLine5, labelCallerIDName, txtNumber, lblDuration, labelCallState, btnHold);

            _mainFormPhoneLineControls[0].Active = true;
            _lastMainFormPhoneLineControl        = _mainFormPhoneLineControls[0];

            // Bind to audio subsystem
            LoadAudioValues();

            // UI features
            TopMost = _core.SettingsManager.GetValueOrSetDefault("mainFormTopMost", false);
            toolStripMenuItemTopAll.Checked = TopMost;
            Location = _core.SettingsManager.GetValueOrSetDefault("MainFormLocation", Location);

            // Load plugins ui elements
            ReloadUIElementsFromPlugins();

            AutoAnswerService.Create(_core);

            // Check if first run - run settings
            if (string.IsNullOrEmpty(_core.Sip.Account.UserName))
            {
                if (!DisableSettingsFormAutoStartup)
                {
                    kryptonCommandSettings.PerformExecute();
                }
            }
            else
            {
                // Connect
                _core.Sip.Account.Register();
            }

            labelCallState.Visible = false;
#if DEBUG
            labelCallState.Visible = true;
#endif

            _messageTransport.MessageReceived += OnRemoteMessageReceived;
        }
예제 #3
0
        private void btnHold_Click(object sender, EventArgs e)
        {
            MainFormPhoneLineControl lineControl = GetActiveUILineWrapper();

            if (lineControl != null)
            {
                if (lineControl.Call != null)
                {
                    lineControl.Call.ToggleHold();
                }
            }
        }
예제 #4
0
        private void AddCharacterToNumber(string c)
        {
            MainFormPhoneLineControl lineControl = GetActiveUILineWrapper();

            if (lineControl != null && lineControl.Call != null && lineControl.Call.State == CallState.ACTIVE)
            {
                lineControl.Call.SendDTMF(c);
            }

            if (txtNumber.Text.Length < 15)
            {
                txtNumber.Text += c;
            }
        }
예제 #5
0
        private void btnDrop_Click(object sender, EventArgs e)
        {
            MainFormPhoneLineControl lineControl = GetActiveUILineWrapper();

            Logger.LogNotice("Trying to drop");

            if (lineControl.Call != null)
            {
                lineControl.Call.Drop();
            }
            else
            {
                Logger.LogWarn("Drop failed - not found");
            }
        }
예제 #6
0
        private void ChangeLineWrapper(MainFormPhoneLineControl targetLineControl)
        {
            if (_lastMainFormPhoneLineControl != null && _lastMainFormPhoneLineControl != targetLineControl && TransferMode)
            {
                if (targetLineControl.Call != null &&
                    targetLineControl.Call.State == CallState.HOLDING &&
                    _lastMainFormPhoneLineControl.Call != null &&
                    (new QuestionForm(string.Format("Do you want to transfer '{0}' to '{1}'", _lastMainFormPhoneLineControl.Call.Number, targetLineControl.Call.Number))).ShowDialog() == DialogResult.OK)
                {
                    if (targetLineControl.Call.State == CallState.HOLDING)
                    {
                        targetLineControl.Call.UnHold();
                    }

                    if (_lastMainFormPhoneLineControl.Call.State == CallState.HOLDING)
                    {
                        _lastMainFormPhoneLineControl.Call.UnHold();
                    }

                    targetLineControl.Call.TransferAttended(_lastMainFormPhoneLineControl.Call);
                }

                TransferMode = false;
            }

            if (_lastMainFormPhoneLineControl != null)
            {
                _lastMainFormPhoneLineControl.Active = false;
            }

            if (targetLineControl != null)
            {
                _lastMainFormPhoneLineControl = targetLineControl;
                targetLineControl.Active      = true;
            }
        }