Exemple #1
0
            private void FindAgentCompleted(IAsyncResult result)
            {
                AcdAgentMatchMaker matchMaker = result.AsyncState as AcdAgentMatchMaker;

                try
                {
                    if (_tentativeAgent != null &&
                        _tentativeAgent.Owner == _session &&
                        _tentativeAgent.IsAllocated)
                    {
                        _tentativeAgent.Deallocate(_session);
                        _agentHunter._logger.Log("AcdAgentHunter failed to deallocate the previous agent of the hunt");
                    }
                    _tentativeAgent = matchMaker.EndFindAgent(result);

                    _session.AddAgentToExclusionList(_tentativeAgent);

                    if (_session.State != CustomerSessionState.Terminating &&
                        _session.State != CustomerSessionState.Terminated)
                    {
                        this.BeginTryCommitAgent(_tentativeAgent,
                                                 this.TryCommitAgentCompleted,
                                                 null);
                    }
                    else
                    {
                        _tentativeAgent.Deallocate(_session);
                        _agentHunter.Matchmaker.HandleNewAvailableAgent(_tentativeAgent);
                        _session.Anchor.DisallowParticipant(_tentativeAgent.SignInAddress);
                        this.SetAsCompleted(new TimeoutException("AcdAgentHunter realized that the customer session ended"), false);
                        return;
                    }
                }
                catch (TimeoutException toex)
                {
                    // We are re-evaluating the average queue time by taking into account this time out.
                    _agentHunter.AverageQueueTime.ReEvaluate(new TimeSpan(0, 0, 0, _agentHunter.Matchmaker.Configuration.MaxWaitTimeOut));

                    this.SetAsCompleted(toex, false);
                }
                catch (OperationFailureException ofex)
                {
                    this.SetAsCompleted(ofex, false);
                }
            }
Exemple #2
0
            private void TryCommitAgentCompleted(IAsyncResult result)
            {
                try
                {
                    _imCall = this.EndTryCommitAgent(result);
                    if (null != _imCall)
                    {
                        _huntingConversation = _imCall.Conversation;
                        bool success = true;

                        try
                        {
                            _session.Anchor.AuthorizeParticipant(_tentativeAgent.SignInAddress);

                            _tentativeAgent.AllocationStatus = AgentAllocationStatus.EscalatingTheAgent;
                            _tentativeAgent.AsyncResult      = this as AsyncResult <AgentHuntResult>;

                            _huntingConversation.ConferenceSession.BeginJoin(_session.Anchor.ConferenceUri,
                                                                             null,
                                                                             this.JoinCompleted,
                                                                             null);
                        }
                        catch (InvalidOperationException ivoex)
                        {
                            success = false;
                            this.SetAsCompleted(new OperationFailureException("AcdAgentHunter failed to join the conference", ivoex), false);
                        }
                        finally
                        {
                            if (!success)
                            {
                                //First Deallocate/Disallow the agent
                                _tentativeAgent.Deallocate(_session);
                                _agentHunter.Matchmaker.HandleNewAvailableAgent(_tentativeAgent);
                                _session.Anchor.DisallowParticipant(_tentativeAgent.SignInAddress);

                                try
                                {
                                    _imCall.Flow.BeginSendInstantMessage(
                                        _agentHunter.Matchmaker.Configuration.FinalMessageToAgent,
                                        sm =>
                                    {
                                        try
                                        {
                                            _imCall.Flow.EndSendInstantMessage(sm);
                                            _huntingConversation.BeginTerminate(ter => { _huntingConversation.EndTerminate(ter); }, null);
                                        }
                                        catch (RealTimeException rtex)
                                        {
                                            _agentHunter._logger.Log("AcdAgenHunter failed to end send the final message to Agent", rtex);
                                        }
                                    },
                                        null);
                                }
                                catch (InvalidOperationException ivoex)
                                {
                                    _agentHunter._logger.Log("AcdAgenHunter failed to end send the final message to Agent", ivoex);
                                }
                            }
                        }
                    }
                    else
                    {
                        _tentativeAgent.Deallocate(_session);
                        _agentHunter.Matchmaker.HandleNewAvailableAgent(_tentativeAgent);
                        _session.Anchor.DisallowParticipant(_tentativeAgent.SignInAddress);
                        ThreadPool.QueueUserWorkItem((waitState) =>
                        {
                            var tempAr = waitState as HuntForAgentAsyncResult;
                            tempAr.Process(false);
                        }, this);
                    }
                }
                catch (Exception ex)
                {
                    this.SetAsCompleted(ex, false);
                    _tentativeAgent.Deallocate(_session);
                    _agentHunter.Matchmaker.HandleNewAvailableAgent(_tentativeAgent);
                    _session.Anchor.DisallowParticipant(_tentativeAgent.SignInAddress);
                }
            }