示例#1
0
        private void ShutdownContactSubscription(AsyncTask task, object state)
        {
            if (m_contactGroupServices.CurrentState != CollaborationSubscriptionState.Subscribed)
            {
                task.Complete(null);
                return;
            }
            m_contactGroupServices.NotificationReceived -= this.ContactGroupServices_NotificationReceived;

            task.DoOneStep(
                delegate()
            {
                Logger.Log(Logger.LogLevel.Info, "Starting contact unsubscription.");
                m_contactGroupServices.BeginUnsubscribe(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        m_contactGroupServices.EndUnsubscribe(ar);
                        Logger.Log(Logger.LogLevel.Info, "Started contact unsubscription.");
                    });
                },
                    null);
            });
        }
示例#2
0
        private void ShutdownUserEndpoint(AsyncTask task, object state)
        {
            UserEndpoint userEndpoint = state as UserEndpoint;

            if (userEndpoint == null)
            {
                task.Complete(null);
                return;
            }
            task.DoOneStep(
                delegate()
            {
                Logger.Log(Logger.LogLevel.Info, "Terminating UserEndpoint." + userEndpoint.OwnerUri);
                userEndpoint.BeginTerminate(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        userEndpoint.EndTerminate(ar);
                        Logger.Log(Logger.LogLevel.Info, "Terminated UserEndpoint." + userEndpoint.OwnerUri);
                    });
                },
                    null);
            });
        }
示例#3
0
        private void ShutdownReverseLookup(AsyncTask task, object state)
        {
            ReverseNumberLookup rnl = m_reverseNumberLookup;

            if (rnl == null)
            {
                task.Complete(null);
                return;
            }
            task.DoOneStep(
                delegate()
            {
                this.Logger.Log(Logger.LogLevel.Info, "Shuttong down Reverse Number Lookup.");
                rnl.BeginShutdown(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        rnl.EndShutdown(ar);
                        this.Logger.Log(Logger.LogLevel.Info, "Reverse Number Lookup shutdown.");
                    });
                },
                    null);
            });
        }
示例#4
0
        private void ShutdownCollaborationPlatform(AsyncTask task, object state)
        {
            CollaborationPlatform platform = m_platform;

            if (platform == null)
            {
                task.Complete(null);
                return;
            }
            task.DoOneStep(
                delegate()
            {
                m_platform.BeginShutdown(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        m_platform.EndShutdown(ar);
                        this.Logger.Log(Logger.LogLevel.Info, "Platform shutdown completed.");
                    });
                },
                    null);
            });
        }
示例#5
0
        private void ShutdownPresenceView(AsyncTask task, object state)
        {
            RemotePresenceView presenceView = m_remotePresenceView;

            if (presenceView == null)
            {
                task.Complete(null);
                return;
            }
            m_remotePresenceView.PresenceNotificationReceived -= this.PresenceView_NotificationReceived;
            task.DoOneStep(
                delegate()
            {
                presenceView.BeginTerminate(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        presenceView.EndTerminate(ar);
                    });
                },
                    null);
            });
        }
示例#6
0
        private void StartupUserEndpoint(AsyncTask task, object state)
        {
            UserEndpoint userEndpoint = state as UserEndpoint;

            task.DoOneStep(
                delegate()
            {
                if (userEndpoint == null)
                {
                    task.Complete(new InvalidOperationException("UserEndpoint is needed to establish."));
                    return;
                }
                else if (userEndpoint.State == LocalEndpointState.Established)
                {
                    task.Complete(null);     // Already established.
                }
                else if (userEndpoint.State == LocalEndpointState.Idle)
                {
                    Logger.Log(Logger.LogLevel.Info, "Establishing UserEndpoint." + userEndpoint.OwnerUri);
                    userEndpoint.BeginEstablish(
                        delegate(IAsyncResult ar)
                    {
                        task.DoOneStep(
                            delegate()
                        {
                            userEndpoint.EndEstablish(ar);
                            Logger.Log(Logger.LogLevel.Info, "Established UserEndpoint." + userEndpoint.OwnerUri);
                            userEndpoint.LocalOwnerPresence.BeginSubscribe(
                                delegate(IAsyncResult ar2)
                            {
                                task.DoFinalStep(
                                    delegate()
                                {
                                    userEndpoint.LocalOwnerPresence.EndSubscribe(ar2);
                                });
                            },
                                null);
                        });
                    },
                        null);
                }
                else
                {
                    task.Complete(new InvalidOperationException("UserEndpoint should be in Idle state to establish."));
                }
            });
        }
示例#7
0
 private void StartPresenceView(AsyncTask task, object state)
 {
     m_remotePresenceView = new RemotePresenceView(this.UserEndpoint, new RemotePresenceViewSettings());
     m_remotePresenceView.PresenceNotificationReceived += this.PresenceView_NotificationReceived;
     m_remotePresenceView.SubscriptionStateChanged     += RemoteSubscriptionStateChanged;
     this.SubscribeToRemotePresentities();
     task.Complete(null);
 }
示例#8
0
        private void ShutdownUserEndpoint(AsyncTask task, object state)
        {
            AsyncTask proxyTask = new AsyncTask(m_customerSession.AppFrontEnd.RelaseUserEndpoint, m_myUserEndpoint);

            proxyTask.TaskCompleted +=
                delegate(object sender, AsyncTaskCompletedEventArgs e)
            {
                task.Complete(e.ActionResult.Exception);
            };
            proxyTask.StartTask();
        }
示例#9
0
        /// <summary>
        /// Starts a sequence represented by the task given.
        /// </summary>
        /// <param name="task">The task that contains the sequence.</param>
        /// <remarks>This method expects one argument that should be a sequence. Else, it will complete with failure.</remarks>
        /// <remarks>Note: If actionsequence is null, there will be no logging for this task.</remarks>
        public static void SequenceStartingMethod(AsyncTask task, object state)
        {
            AsyncTaskSequence actionSequence = state as AsyncTaskSequence;

            if (actionSequence == null)
            {
                task.Complete(new InvalidOperationException("Invalid use of AsyncTask.SequenceStartingMethod method. Expecting actionsequence as state."));
                return;
            }
            actionSequence.Start(); // Task will complete when the sequence completes. The report delegate for the sequence should be Complete methods in this task so that this task can complete.
        }
示例#10
0
        private void ShutdownUserEndpoint(AsyncTask task, object state)
        {
            CallbackRequest callbackRequest = (CallbackRequest)state;
            AsyncTask       proxyTask       = new AsyncTask(m_appFrontEnd.RelaseUserEndpoint, callbackRequest.MyUserEndpoint);

            proxyTask.TaskCompleted +=
                delegate(object sender, AsyncTaskCompletedEventArgs e)
            {
                task.Complete(e.ActionResult.Exception);
            };
            proxyTask.StartTask();
        }
示例#11
0
        /// <summary>
        /// Terminates the service channel.
        /// </summary>
        /// <param name="task">The task for this operation.</param>
        private void TerminateServiceChannelCall(AsyncTask task, object state)
        {
            Exception exception = null;

            try
            {
                Logger.Log(Logger.LogLevel.Info, "Terminating service channel call.");
                m_serviceChannelCall.BeginTerminate(
                    ar =>
                {
                    Exception ex = null;
                    try
                    {
                        m_serviceChannelCall.EndTerminate(ar);
                        Logger.Log(Logger.LogLevel.Info, "Terminated service channel call.");
                    }
                    catch (RealTimeException rte)
                    {
                        ex = rte;
                    }
                    finally
                    {
                        task.Complete(ex);
                    }
                }, null);
            }
            catch (InvalidOperationException ioe)
            {
                exception = ioe;
            }
            finally
            {
                if (exception != null)
                {
                    task.Complete(exception);
                }
            }
        }
示例#12
0
 private void StartWaitForPresence(AsyncTask task, object state)
 {
     lock (m_syncRoot)
     {
         if (m_subCount == m_contacts.Count)
         {
             task.Complete(null);
         }
         else
         {
             m_presenceWaitAction = task;
         }
     }
 }
示例#13
0
        /// <summary>
        /// Releases the user endpoint from usage from a component.
        /// </summary>
        /// <param name="task">The task to be done.</param>
        /// <param name="state">The user endpoint to release.</param>
        /// <remarks>If ref count is reduced to 0, the userendpoint will be terminated.</remarks>
        public void RelaseUserEndpoint(AsyncTask task, object state)
        {
            MyUserEndpoint  myUserEndpoint = state as MyUserEndpoint;
            RealTimeAddress ownerAddress   = new RealTimeAddress(myUserEndpoint.UserEndpoint.OwnerUri);
            bool            completeNeeded = true;

            lock (this.SyncRoot)
            {
                if (m_userEndpoints.ContainsKey(ownerAddress))
                {
                    MyUserEndpoint storedEndpoint = m_userEndpoints[ownerAddress];
                    if (storedEndpoint == myUserEndpoint) // What we have matches the released endpoint. Reduce ref count.
                    {
                        int count = m_userEndpointReferenceCounts[ownerAddress];
                        count--;
                        m_userEndpointReferenceCounts[ownerAddress] = count;
                        if (count == 0)
                        {
                            // Terminate the endpoint.
                            AsyncTask terminateEndpointTask = new AsyncTask(this.ShutdownUserEndpoint, myUserEndpoint.UserEndpoint);
                            terminateEndpointTask.TaskCompleted +=
                                delegate(object sender, AsyncTaskCompletedEventArgs e)
                            {
                                task.Complete(e.ActionResult.Exception);
                            };
                            terminateEndpointTask.StartTask();
                            completeNeeded = false;
                        }
                    }
                }
            }
            if (completeNeeded)
            {
                task.Complete(null);
            }
        }
示例#14
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();
        }
示例#15
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();
        }
示例#16
0
        protected void StartupJoinConference(AsyncTask task, object state)
        {
            task.DoOneStep(
                delegate()
            {
                Conference conference = null;
                AsyncTaskResult conferenceActionResult = task.PreviousActionResult;
                // Normally, the previous task should be the one that scheduled the conference. But, play safe to allow other actions in between.
                while (conferenceActionResult != null)
                {
                    ConferenceActionResult conferenceResult = conferenceActionResult as ConferenceActionResult;
                    if (conferenceResult != null)
                    {
                        conference = conferenceResult.Conference;
                        break;
                    }
                    conferenceActionResult = conferenceActionResult.PreviousActionResult;
                }
                if (conference == null)
                {
                    task.Complete(new InvalidOperationException("StartupConferenceJoin: Conference must be scheduled before conference join operation."));
                    return;
                }
                ConferenceJoinOptions options = new ConferenceJoinOptions();
                options.JoinMode = JoinMode.TrustedParticipant;

                m_tcuConversation.ConferenceSession.BeginJoin(
                    conference.ConferenceUri,
                    options,
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        m_tcuConversation.ConferenceSession.EndJoin(ar);
                        this.Logger.Log(Logger.LogLevel.Verbose,
                                        String.Format("ServiceHub {0} joined TCU conference {1}.",
                                                      this.CustomerSession.Customer.UserUri,
                                                      m_tcuConversation.ConferenceSession.ConferenceUri));
                    });
                },
                    null);
            });
        }
示例#17
0
        void RemoteSubscriptionStateChanged(object sender, RemoteSubscriptionStateChangedEventArgs e)
        {
            bool completeAction = false;

            lock (m_syncRoot)
            {
                foreach (KeyValuePair <RealTimeAddress, RemotePresentityStateChange> pair in e.SubscriptionStateChanges)
                {
                    if (pair.Value.PreviousState == RemotePresentitySubscriptionState.Subscribing)
                    {
                        m_subCount++; // Went from subscribing to some other state. Could be Terminating or Subscribed or WaitingForRetry etc.
                    }
                }
                if (m_subCount == m_contacts.Count)
                {
                    completeAction = true;
                }
                if (completeAction && m_presenceWaitAction != null)
                {
                    m_presenceWaitAction.Complete(null);
                }
            }
        }
示例#18
0
 private void ShutdownEndpoint(AsyncTask task, object state)
 {
     if (m_endpoint == null)
     {
         task.Complete(null);
         return;
     }
     task.DoOneStep(
         delegate()
     {
         Logger.Log(Logger.LogLevel.Info, "Terminating Application Endpoint.");
         m_endpoint.BeginTerminate(
             delegate(IAsyncResult ar)
         {
             task.DoFinalStep(
                 delegate()
             {
                 m_endpoint.EndTerminate(ar);
                 Logger.Log(Logger.LogLevel.Info, "Terminated Application Endpoint.");
             });
         },
             null);
     });
 }
示例#19
0
 private void ShutdownCallbackManager(AsyncTask task, object state)
 {
     if (m_callbackManager == null)
     {
         task.Complete(null);
         return;
     }
     task.DoOneStep(
         delegate()
     {
         CallbackManager callbackManager = m_callbackManager;
         callbackManager.BeginShutdown(
             delegate(IAsyncResult ar)
         {
             task.DoFinalStep(
                 delegate()
             {
                 callbackManager.EndShutdown(ar);
                 this.Logger.Log(Logger.LogLevel.Verbose, "Callback Manager shutdown.");
             });
         },
             null);
     });
 }
示例#20
0
 private void ShutdownMusicProvider(AsyncTask task, object state)
 {
     if (m_mohProvider == null)
     {
         task.Complete(null);
         return;
     }
     task.DoOneStep(
         delegate()
     {
         MusicProvider musicProvider = m_mohProvider;
         musicProvider.BeginShutdown(
             delegate(IAsyncResult ar)
         {
             task.DoFinalStep(
                 delegate()
             {
                 musicProvider.EndShutdown(ar);
                 this.Logger.Log(Logger.LogLevel.Verbose, "Music provider shutdown.");
             });
         },
             null);
     });
 }
示例#21
0
 /// <summary>
 /// Clean up a request given as argument in the task.
 /// </summary>
 /// <param name="task">The task for this operation.</param>
 private void CleanupRequest(AsyncTask task, object state)
 {
     task.DoOneStep(
         delegate()
     {
         CallbackRequest callbackRequest = (CallbackRequest)state;
         // We need to terminate view and then endppoint. Endpoint termiantion alone is enough. We will do both here for sample usage.
         AsyncTaskSequenceSerial sequence = new AsyncTaskSequenceSerial(this);
         sequence.Name = "CleanupCallbackRequest";
         sequence.FailureCompletionReportHandlerDelegate = delegate(Exception exception) { task.Complete(null); };
         sequence.SuccessCompletionReportHandlerDelegate = delegate(Exception exception) { task.Complete(exception); };
         AsyncTask viewShutdownAction = new AsyncTask(this.ShutdownPresenceView, callbackRequest);
         sequence.AddTask(viewShutdownAction);
         AsyncTask endpointShutdownAction = new AsyncTask(this.ShutdownUserEndpoint, callbackRequest);
         sequence.AddTask(endpointShutdownAction);
         sequence.Start();
     });
 }
示例#22
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();
                }
            }
        }