예제 #1
0
        private void AddUserPhoneNumbersToRnl(object state)
        {
            string userUri = state as string;

            if (!userUri.StartsWith("sip"))
            {
                userUri = "sip:" + userUri;
            }
            AsyncTask getUserEndpointTask = new AsyncTask(this.CreateOrGetUserEndpoint, userUri);

            getUserEndpointTask.TaskCompleted +=
                delegate(object sender, AsyncTaskCompletedEventArgs e)
            {
                UserEndpointCreationActionResult res = e.ActionResult as UserEndpointCreationActionResult;
                Debug.Assert(res != null);

                if (res.MyUserEndpoint.ContactCard != null)
                {
                    foreach (Presence.PhoneNumber p in res.MyUserEndpoint.ContactCard.PhoneNumbers)
                    {
                        this.AppPlatform.ReverseNumberLookUp.AddEntry(p.Uri, res.MyUserEndpoint.UserEndpoint.OwnerUri);
                    }
                }
            };
            getUserEndpointTask.StartTask();
        }
예제 #2
0
        private void StartupUserEndpoint(AsyncTask task, object state)
        {
            AsyncTask proxyTask = new AsyncTask(m_customerSession.AppFrontEnd.CreateOrGetUserEndpoint, m_customerSession.Customer.UserUri);

            proxyTask.TaskCompleted +=
                delegate(object sender, AsyncTaskCompletedEventArgs e)
            {
                UserEndpointCreationActionResult result = proxyTask.TaskResult as UserEndpointCreationActionResult;
                if (result != null)
                {
                    m_myUserEndpoint       = result.MyUserEndpoint;
                    m_contactGroupServices = m_myUserEndpoint.UserEndpoint.ContactGroupServices;
                }
                task.Complete(e.ActionResult.Exception);
            };
            proxyTask.StartTask();
        }
예제 #3
0
        private void StartupUserEndpoint(AsyncTask task, object state)
        {
            CallbackRequest callbackRequest = (CallbackRequest)state;
            AsyncTask       proxyTask       = new AsyncTask(m_appFrontEnd.CreateOrGetUserEndpoint, callbackRequest.Customer.UserUri);

            proxyTask.TaskCompleted +=
                delegate(object sender, AsyncTaskCompletedEventArgs e)
            {
                UserEndpointCreationActionResult result = proxyTask.TaskResult as UserEndpointCreationActionResult;
                if (result != null)
                {
                    callbackRequest.MyUserEndpoint = result.MyUserEndpoint;
                }
                task.Complete(e.ActionResult.Exception);
            };
            proxyTask.StartTask();
        }
예제 #4
0
        public void CreateOrGetUserEndpoint(AsyncTask task, object state)
        {
            string ownerUri = state as string;

            if (String.IsNullOrEmpty(ownerUri))
            {
                task.Complete(new InvalidOperationException("OwnerUri is needed to request a user endpoint."));
                return;
            }
            RealTimeAddress ownerAddress = null;

            try
            {
                ownerAddress = new RealTimeAddress(ownerUri);
            }
            catch (ArgumentException exception)
            {
                task.Complete(exception);
                return;
            }
            MyUserEndpoint myUserEndpoint = null;

            lock (this.SyncRoot)
            {
                if (m_userEndpoints.ContainsKey(ownerAddress))
                {
                    myUserEndpoint = m_userEndpoints[ownerAddress];
                    if (myUserEndpoint.UserEndpoint.State == LocalEndpointState.Terminating || myUserEndpoint.UserEndpoint.State == LocalEndpointState.Terminated)
                    {
                        myUserEndpoint = null; // Loose it since it is going away.
                        m_userEndpoints.Remove(ownerAddress);
                        m_userEndpointReferenceCounts.Remove(ownerAddress);
                    }
                    else
                    {
                        int count = m_userEndpointReferenceCounts[ownerAddress];
                        count++;
                        m_userEndpointReferenceCounts[ownerAddress] = count;
                    }
                }
                if (myUserEndpoint == null)
                {
                    // Create and add user endpoint into dictionary.
                    // One could use the platform discover server from uri if the topology has DNS srv records for server auto discovery.
                    // Normally, this would point to a director. Here, we will use the proxy of the application endpoint.
                    UserEndpointSettings userEndpointSettings = new UserEndpointSettings(ownerUri, m_settings.ProxyHost, m_settings.ProxyPort);
                    UserEndpoint         userEndpoint         = new UserEndpoint(m_parent.Platform, userEndpointSettings);
                    myUserEndpoint = new MyUserEndpoint(userEndpoint);
                    m_userEndpoints.Add(ownerAddress, myUserEndpoint);
                    m_userEndpointReferenceCounts.Add(ownerAddress, 1);
                    myUserEndpoint.UserEndpoint.StateChanged += UserEndpointStateChanged; // Ensures that only one registration per endpoint.
                }
                UserEndpointCreationActionResult result = new UserEndpointCreationActionResult(myUserEndpoint, null);
                task.TaskResult = result; // Store it for now.
                if (myUserEndpoint.UserEndpoint.State == LocalEndpointState.Established)
                {
                    task.Complete(null, result);
                }
                else if (myUserEndpoint.UserEndpoint.State == LocalEndpointState.Establishing)
                {
                    // Wait till the endpoint establish completes.
                    lock (this.SyncRoot)
                    {
                        m_pendingUserEndpointCreationTasks.Add(task);
                    }
                }
                else if (myUserEndpoint.UserEndpoint.State == LocalEndpointState.Idle)
                {
                    AsyncTask establishTask = new AsyncTask(this.StartupUserEndpoint, myUserEndpoint.UserEndpoint);
                    establishTask.TaskCompleted +=
                        delegate(object sender, AsyncTaskCompletedEventArgs e)
                    {
                        task.TaskResult.Exception = e.ActionResult.Exception;     // Transfer
                        task.Complete(e.ActionResult.Exception, task.TaskResult);
                        lock (this.SyncRoot)
                        {
                            // Complete pending tasks
                            foreach (AsyncTask pendingTask in m_pendingUserEndpointCreationTasks)
                            {
                                pendingTask.TaskResult.Exception = e.ActionResult.Exception;
                                pendingTask.Complete(e.ActionResult.Exception, pendingTask.TaskResult);
                            }
                            m_pendingUserEndpointCreationTasks.Clear();
                        }
                    };
                    establishTask.StartTask();
                }
            }
        }