/// <summary> /// Finishes the endpoint termination. This will indirectly take care of cleaning the Presence subscription resource as well. /// </summary> private void HandleEndpointTermination(IAsyncResult result) { ApplicationEndpoint endpoint = result.AsyncState as ApplicationEndpoint; endpoint.EndTerminate(result); _matchMaker.UpdateState(MatchMakerState.Terminated); _matchMaker._listOfShutdownAsyncResults.ForEach(ar => ar.SetAsCompleted(null, false)); //Terminate operation never throws this.SetAsCompleted(null, false); }
/// <summary> /// Starts subscribing to the Presence of agents upon successful registration of the endpoint /// </summary> private void OnEstablishComplete(IAsyncResult result) { try { _matchMaker._endpoint.EndEstablish(result); //create a SubscriptionTarget for each agent RemotePresentitySubscriptionTarget[] contacts = new RemotePresentitySubscriptionTarget[_matchMaker._configuration.Agents.Count]; for (int i = 0; i < _matchMaker.Configuration.Agents.Count; i++) { contacts[i] = new RemotePresentitySubscriptionTarget(_matchMaker._configuration.Agents[i].SignInAddress); } RemotePresenceView MatchMakerPresence = new RemotePresenceView(_matchMaker._endpoint); //Initiate the persistent batch subscription to the list of agents //Only interested in subscribing to the Agents Availability. We should not expect more than one category instance //per Remote Presentity notification change. Always register the event handler before starting the subscription. MatchMakerPresence.PresenceNotificationReceived += _matchMaker.HandleAgentAvailabilityChanged; MatchMakerPresence.StartSubscribingToPresentities(contacts); try { _matchMaker._mohServer = new AcdMusicOnHoldServer(_matchMaker, _matchMaker.Configuration.MusicOnHoldFilePath, _matchMaker._logger); _matchMaker._mohServer.BeginStartUp(ar => { AcdMusicOnHoldServer mohServer = ar.AsyncState as AcdMusicOnHoldServer; mohServer.EndStartUp(ar); lock (_matchMaker._syncRoot) { _matchMaker.UpdateState(MatchMakerState.Started); } this.SetAsCompleted(null, false); }, _matchMaker._mohServer); } catch (RealTimeException ex) { _matchMaker._logger.Log("AcdAgentMatchMaker failed to subscribe to the Presence of its Agents", ex); _matchMaker.BeginShutdown((asyncResult) => { _matchMaker.EndShutdown(asyncResult); this.SetAsCompleted(ex, false); }, ex); } } catch (RealTimeException ex) { _matchMaker._logger.Log("AcdAgentMatchMaker failed to subscribe to the Presence of its Agents; verify your agent configuration.", ex); this.SetAsCompleted(ex, false); _matchMaker.BeginShutdown((asyncResult) => { _matchMaker.EndShutdown(asyncResult); this.SetAsCompleted(ex, false); }, ex); } }