/// <summary>
        /// Creates the P2PEndpoint for sending the Notify. A P2P endpoint enjoys
        /// auto-provisioning of the necessary application endpoint settings
        /// if it is obtained from an established ApplicationEndpoint created with
        /// ProvisionedApplicationPlatformSettings.
        /// </summary>
        void CreateP2PEndpoint()
        {
            Console.WriteLine("Creating P2P Endpoint...for {0}", _appID);
            try
            {
                if (!string.IsNullOrEmpty(_appID))
                {
                    Console.WriteLine("Creating CollaborationPlatform for the provisioned application with "
                                      + "ID \'{0}\' using ProvisionedApplicationPlatformSettings.", _appID);

                    ProvisionedApplicationPlatformSettings settings
                                    = new ProvisionedApplicationPlatformSettings("UCMASampleApp", _appID);
                    _collabPlatform = new CollaborationPlatform(settings);
                    // Receive applicationEndpoint settings via auto-provisioning
                    _collabPlatform.RegisterForApplicationEndpointSettings(ApplicationEndpointSettingsDiscovered);
                    _collabPlatform.EndStartup(_collabPlatform.BeginStartup(null, null));

                    Console.WriteLine("platform started.");
                }
                else
                {
                    Console.WriteLine("Error: Application ID not provided.");
                }
            }
            catch (Exception iOpEx)
            {
                Console.WriteLine(iOpEx.ToString());
            }
        }
Beispiel #2
0
        // Callback for CollaborationPlatform's BeginStartup().
        static void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                // The CollaborationPlatform should now be started.
                collabPlatform.EndStartup(ar);
                Console.WriteLine("Collaboration platform associated with the provisioned application has been started");
            }
            catch (ProvisioningFailureException pfEx)
            {
                Console.WriteLine("ProvisioningFailure Exception: " + pfEx.ToString());
                Console.WriteLine("The FailureReason for the ProvisioningFailure Exception: "
                                  + pfEx.FailureReason.ToString());
            }
            catch (OperationFailureException opFailEx)
            {
                Console.WriteLine("OperationFailure Exception: " + opFailEx.ToString());
            }
            catch (ConnectionFailureException connFailEx)
            {
                Console.WriteLine("ConnectionFailure Exception: " + connFailEx.ToString());
            }
            catch (RealTimeException realTimeEx)
            {
                Console.WriteLine("RealTimeException : " + realTimeEx.ToString());
            }
        }
Beispiel #3
0
            public void Start(List <Uri> chatRoomsToJoin)
            {
                Console.WriteLine("正在登陆用户");
                Console.ReadKey();

                try
                {
                    chatRooms = chatRoomsToJoin;

                    // Connect to Lync Server
                    ClientPlatformSettings platformSettings = new ClientPlatformSettings("PersistentChat.Test", SipTransportType.Tls);
                    CollaborationPlatform  collabPlatform   = new CollaborationPlatform(platformSettings);
                    collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null));
                    UserEndpointSettings userEndpointSettings = new UserEndpointSettings(UserUri.AbsoluteUri, SampleCommon.LyncServer);
                    userEndpointSettings.Credential = new NetworkCredential(UserName, Password);
                    userEndpoint = new UserEndpoint(collabPlatform, userEndpointSettings);
                    Console.WriteLine("正在登陆用户----------->");
                    // Login to Lync Server
                    currentOperation.Begin("Connect to Lync Server",
                                           () => userEndpoint.BeginEstablish(ar => LyncServerBeginEstablishFinished(ar), null));
                }
                catch (Exception e) {
                    Console.WriteLine("正在登陆用户");
                }
            }
Beispiel #4
0
        private void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                collabPlatform.EndStartup(ar);
            }
            catch (OperationFailureException opFailEx)
            {
                log(opFailEx.Message);
                throw;
            }
            catch (ConnectionFailureException connFailEx)
            {
                log(connFailEx.Message);
                throw;
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown as a result of any UCMA operation.
                log(realTimeEx.Message);
                throw;
            }
            finally
            {
                // Again, just for sync. reasons.
                _platformStartupCompleted.Set();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sets up the OCS objects using the credentials provided
        /// </summary>
        /// <remarks>
        /// In this sample this is invoked when the user presses the "Apply Server Settings" button
        /// </remarks>
        /// <param name="applicationUri">SIP Uri of the OCS account</param>
        /// <param name="serverName">SIP server URI</param>
        /// <param name="serverPort">Port (usually 443)</param>
        /// <param name="credential">Credentials for establishing the user endpoint</param>
        private void InitializeMCSConnection(string applicationUri, string serverName, int serverPort, NetworkCredential credential)
        {
            //Initialize new client platform.
            //Note that this sample only supports TLS, and additionally that it uses ClientPlatform rather than ServerPlatform.
            //In a production application, ServerPlatform should be used; ClientPlatform is preferred here to demonstrate the platform without
            //requiring application provisioning. This is out of the scope of this sample, however.
            ClientPlatformSettings clientPlatformSettings;

            clientPlatformSettings = new ClientPlatformSettings("VoiceXMLTestApp", SipTransportType.Tls);

            collaborationPlatform = new CollaborationPlatform(clientPlatformSettings);
            collaborationPlatform.EndStartup(collaborationPlatform.BeginStartup(null, null));

            //Create a new UserEndpoint based on the information provided through the UI.
            //As with Server/Client platform above, in production, this should be replaced with provisioned ApplicationEndpoint in most circumstances.
            UserEndpointSettings endpointSettings;

            endpointSettings = new UserEndpointSettings(applicationUri, serverName, serverPort);

            endpoint = new UserEndpoint(collaborationPlatform, endpointSettings);

            endpoint.Credential = credential;

            //Bind the event handler to handle incoming calls. Use of the strongly-typed AVCall dictates that calls not matching this type will not be raised.
            endpoint.RegisterForIncomingCall <AudioVideoCall>(AudioVideoCallReceived);

            endpoint.EndEstablish(endpoint.BeginEstablish(null, endpoint));
        }
Beispiel #6
0
        // Callback for CollaborationPlatform's BeginStartup().
        private void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                // The CollaborationPlatform should now be started.
                collabPlatform.EndStartup(ar);
                Console.WriteLine("Collaboration platform associated with the provisioned application with "
                                  + "ID {0} has been started", _appID);
            }
            catch (ProvisioningFailureException pfEx)
            {
                // ProvisioningFailureException may be thrown during
                // EndStartup() for many reasons such as inaccessible
                // configuration data, unable to find a matching application,
                // and invalid configuration data. The FailureReason property
                // exposes these issues via a value of the
                // ProvisioningFailureReason enumerated type, which can have
                // values of ConfigurationDataInaccessible, ApplicationNotFound,
                // and InvalidConfiguration.
                // TODO (Left to the reader): Write actual handling code for the
                // occurrence.
                Console.WriteLine("ProvisioningFailure Exception: " + pfEx.ToString());
                Console.WriteLine("The FailureReason for the ProvisioningFailure Exception: "
                                  + pfEx.FailureReason.ToString());
            }
            catch (OperationFailureException opFailEx)
            {
                // OperationFailureException will be thrown when the platform
                // cannot establish, usually due to invalid data.
                // TODO (Left to the reader): Write actual handling code for the
                // occurrence.
                Console.WriteLine("OperationFailure Exception: " + opFailEx.ToString());
            }
            catch (ConnectionFailureException connFailEx)
            {
                // ConnectionFailureException will be thrown when the platform
                // cannot connect.
                // TODO (Left to the reader): Write actual handling code for the
                // occurrence.
                Console.WriteLine("ConnectionFailure Exception: " + connFailEx.ToString());
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown as a result of any UCMA
                // operation.
                // TODO (Left to the reader): Write actual handling code for the
                // occurrence.
                Console.WriteLine("RealTimeException : " + realTimeEx.ToString());
            }
        }
Beispiel #7
0
        public void StartupPlatform()
        {
            try
            {
                ProvisionedApplicationPlatformSettings settings = new ProvisionedApplicationPlatformSettings(LumtGlobals.ApplicationUserAgent, LumtGlobals.TrustedApplicationID);
                collabPlatform = new CollaborationPlatform(settings);

                Log.WriteLogEntry("INFO", String.Format("Starting {0} platform...", LumtGlobals.ApplicationShortName));
                collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null));
                Log.WriteLogEntry("INFO", String.Format("{0} platform started.", LumtGlobals.ApplicationShortName));
            }
            catch (Exception ex)
            {
                Log.WriteLogEntry("ERROR", String.Format("{0} platform NOT started: {1}. Inner Exception: {2}", LumtGlobals.ApplicationShortName, ex.Message, (ex.InnerException == null ? "N/A" : ex.InnerException.Message)), String.Format("{0} platform NOT started.", LumtGlobals.ApplicationShortName));
                Program.CloseApplicationOnError();
            }
        }
Beispiel #8
0
        private void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                collabPlatform.EndStartup(ar);
                Console.WriteLine("The platform is now started.");
            }
            catch (ConnectionFailureException connFailEx)
            {
                //ConnectionFailureException will be thrown when the platform cannot connect.
                Console.WriteLine(connFailEx.ToString());
            }

            //Again, just for sync. reasons.
            _autoResetEvent.Set();
        }
            private static ApplicationEndpoint CreateEndPoint(ServerPlatformSettings settings)
            {
                CollaborationPlatform collaborationPlatform = new CollaborationPlatform(settings);

                collaborationPlatform.EndStartup(collaborationPlatform.BeginStartup(null, null));
                ApplicationEndpoint result;

                try
                {
                    ApplicationEndpoint applicationEndpoint = new ApplicationEndpoint(collaborationPlatform, new ApplicationEndpointSettings(BaseUMconnectivityTester.SipPlatformConnectionManager.OwnerUri));
                    applicationEndpoint.EndEstablish(applicationEndpoint.BeginEstablish(null, null));
                    result = applicationEndpoint;
                }
                catch (Exception)
                {
                    collaborationPlatform.EndShutdown(collaborationPlatform.BeginShutdown(null, null));
                    throw;
                }
                return(result);
            }
Beispiel #10
0
            public void Start(List <Uri> chatRoomsToJoin)
            {
                chatRooms = chatRoomsToJoin;
                Log(string.Format("Start Client: chatRooms.Count={0}", chatRooms.Count));

                currentOperation.Reset();

                // Connect to OCS
                ClientPlatformSettings platformSettings = new ClientPlatformSettings("PersistentChat.Test", SipTransportType.Tls);
                CollaborationPlatform  collabPlatform   = new CollaborationPlatform(platformSettings);

                collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null));
                UserEndpointSettings userEndpointSettings = new UserEndpointSettings(UserUri.AbsoluteUri, SampleCommon.OcsServer);

                userEndpointSettings.Credential = new NetworkCredential(UserName, Password);
                userEndpoint = new UserEndpoint(collabPlatform, userEndpointSettings);

                // Login to OCS
                currentOperation.Begin("Connect to OCS",
                                       () => userEndpoint.BeginEstablish(OcsBeginEstablishFinished, null));
            }
Beispiel #11
0
        public static void Start()
        {
            try
            {
                var host       = Plugin.LyncPlugin.Configuration.GetString("host");
                var thumbprint = Plugin.LyncPlugin.Configuration.GetString("thumbprint");
                var gruu       = Plugin.LyncPlugin.Configuration.GetString("gruu");
                var trustPort  = Plugin.LyncPlugin.Configuration.GetInt("trustedPort");
                var appPort    = Plugin.LyncPlugin.Configuration.GetInt("appPort");
                var sip        = Plugin.LyncPlugin.Configuration.GetString("accountSip");

                var platformSettings = new ServerPlatformSettings(UserAgent, host, trustPort, gruu, CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, thumbprint));

                Platform    = new CollaborationPlatform(platformSettings);
                AppEndpoint = new ApplicationEndpoint(Platform, new ApplicationEndpointSettings(sip, host, appPort)
                {
                    UseRegistration = true
                });

                Log("Starting Lync platform.");
                Platform.EndStartup(Platform.BeginStartup(null, null));
                Log("Lync platform started.");

                AppEndpoint.EndEstablish(AppEndpoint.BeginEstablish(null, null));

                UserEndpoint = new UserEndpoint(Platform, new UserEndpointSettings(sip, host, appPort)
                {
                    AutomaticPresencePublicationEnabled = true
                });
                UserEndpoint.EndEstablish(UserEndpoint.BeginEstablish(null, null));

                RemotePresence = new RemotePresenceView(UserEndpoint, new RemotePresenceViewSettings());
                RemotePresence.PresenceNotificationReceived += PresenceNotificationReceived;
            }
            catch (Exception ex)
            {
                Error(ex.Message);
            }
        }
        private void EndPlatformStartup(IAsyncResult ar)
        {
            CollaborationPlatform collabPlatform = ar.AsyncState as CollaborationPlatform;

            try
            {
                // The platform should now be started.
                collabPlatform.EndStartup(ar);
                // It should be noted that all the re-thrown exceptions will crash the application. This is intentional.
                // Ideal exception handling would report the error and shut down nicely. In production code, consider using
                // an IAsyncResult implementation to report the error instead of throwing or put the implementation
                // in this try block.
            }
            catch (OperationFailureException opFailEx)
            {
                // OperationFailureException will be thrown when the platform cannot establish, here, usually due to invalid data.
                NonBlockingConsole.WriteLine(opFailEx.Message);
                throw;
            }
            catch (ConnectionFailureException connFailEx)
            {
                // ConnectionFailureException will be thrown when the platform cannot connect.
                // ClientPlatforms will not throw this exception on startup.
                NonBlockingConsole.WriteLine(connFailEx.Message);
                throw;
            }
            catch (RealTimeException realTimeEx)
            {
                // RealTimeException may be thrown as a result of any UCMA operation.
                NonBlockingConsole.WriteLine(realTimeEx.Message);
                throw;
            }
            finally
            {
                // Again, just for sync. reasons.
                _platformStartupCompleted.Set();
            }
        }
Beispiel #13
0
        /// <summary>
        /// Callback method for platform startup. This method will initiate endpoint establishment.
        /// </summary>
        /// <param name="result">Async result</param>
        private void PlatformStartupCompleted(IAsyncResult result)
        {
            CollaborationPlatform collabPlatform = result.AsyncState as CollaborationPlatform;
            bool needCleanup = true;

            try
            {
                collabPlatform.EndStartup(result);
                Helper.Logger.Info("The platform is now started.");
                needCleanup = false;
            }
            catch (RealTimeException rte)
            {
                Helper.Logger.Error("Platform End startup threw an exception {0}", EventLogger.ToString(rte));
            }
            finally
            {
                if (needCleanup)
                {
                    this.Cleanup();
                }
            }
        }
Beispiel #14
0
        //Commented the functions used to start and stop workflow runtime service as workflows are not to be used

        /*
         * private void StartWorkflowRuntime(AsyncTask task, object state)
         * {
         *  m_workflowRuntime = new WorkflowRuntime();
         *  m_workflowRuntime.AddService(new CommunicationsWorkflowRuntimeService());
         *  m_workflowRuntime.AddService(new TrackingDataWorkflowRuntimeService());
         *
         *  task.DoFinalStep(
         *      delegate()
         *      {
         *          m_workflowRuntime.StartRuntime();
         *          this.Logger.Log(Logger.LogLevel.Info, "Workflow started.");
         *      });
         * }
         *
         * private void ShutdownWorkflowRuntime(AsyncTask task, object state)
         * {
         *  if (m_workflowRuntime == null)
         *  {
         *      task.Complete(null);
         *      return;
         *  }
         *  task.DoFinalStep(
         *      delegate()
         *      {
         *          m_workflowRuntime.StopRuntime();
         *          this.Logger.Log(Logger.LogLevel.Info, "Workflow shutdown.");
         *      });
         * }
         */
        private void StartupPlatform(AsyncTask task, object state)
        {
            task.DoOneStep(
                delegate()
            {
                var settings = new ProvisionedApplicationPlatformSettings(m_userAgent, m_applicationId);
                m_platform   = new CollaborationPlatform(settings);
                m_platform.RegisterForApplicationEndpointSettings(this.ApplicationEndpointOwnerDiscovered);

                //this.Logger.Log(Logger.LogLevel.Info, "Starting the Collaboration Platform.");
                m_platform.BeginStartup(
                    delegate(IAsyncResult ar)
                {
                    task.DoFinalStep(
                        delegate()
                    {
                        m_platform.EndStartup(ar);
                        //this.Logger.Log(Logger.LogLevel.Info, "Collaboration Platform started.");
                    });
                },
                    null);
            });
        }
        public static UserEndpoint ConnectLyncServer(string userSipUri, string lyncServer, bool usingSso, string username, string password)
        {
            // Create the Lync Server UserEndpoint and attempt to connect to Lync Server
            Console.WriteLine("{0} Connecting to Lync Server... [{1}]", username, lyncServer);

            // Use the appropriate SipTransportType depending on current Lync Server deployment
            ClientPlatformSettings platformSettings = new ClientPlatformSettings("PersistentChat.Test", SipTransportType.Tls);
            CollaborationPlatform  collabPlatform   = new CollaborationPlatform(platformSettings);

            collabPlatform.AllowedAuthenticationProtocol = SipAuthenticationProtocols.Ntlm;

            // Initialize the platform
            collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null));

            // You can also pass in the server's port # here.
            UserEndpointSettings userEndpointSettings = new UserEndpointSettings(userSipUri, lyncServer);

            // When usingSso is true use the current users credentials, otherwise use username and password
            userEndpointSettings.Credential = usingSso ? SipCredentialCache.DefaultCredential : new NetworkCredential(username, password);

            UserEndpoint userEndpoint = new UserEndpoint(collabPlatform, userEndpointSettings);

            // Login to Lync Server.
            userEndpoint.EndEstablish(userEndpoint.BeginEstablish(null, null));

            if (PersistentChatServerUri == null)
            {
                // Extract default Persistent Chat pool uri from inband
                ProvisioningData provisioningData =
                    userEndpoint.EndGetProvisioningData(userEndpoint.BeginGetProvisioningData(null, null));
                PersistentChatServerUri = new Uri(provisioningData.PersistentChatConfiguration.DefaultPersistentChatUri);
                Console.WriteLine("\t-- {0}PersistentChatServerUri:{1}", username, PersistentChatServerUri);
            }

            Console.WriteLine("\t{0} Connecting>>>>Success", username);
            return(userEndpoint);
        }
Beispiel #16
0
        /// <summary>
        /// Callback from <code>BeginStartup</code> method on platform.
        /// </summary>
        /// <param name="result">
        /// Status of the platform startup operation.
        /// </param>
        private void PlatformStartupCompleted(IAsyncResult result)
        {
            // Extract the platform that was passed in as the state argument to
            // the BeginStartup() method.
            CollaborationPlatform platform = result.AsyncState as CollaborationPlatform;

            if (platform == null)
            {
                UCMASampleHelper.WriteErrorLine("CollaborationPlatform not passed into BeginStartup() method.");
                UCMASampleHelper.FinishSample();
                return;
            }

            try
            {
                // Determine whether the startup operation completed
                // successfully.
                platform.EndStartup(result);

                UCMASampleHelper.WriteLine("Platform has been started.");
            }
            catch (TlsFailureException tlsFailureException)
            {
                // TlsFailureException will be thrown if the certificate used to
                // startup the platform is invalid or otherwise unusable.
                // TODO (Left to the reader): Error handling code to either
                // retry the platform startup operation with a different
                // certificate, log the error for debugging, or gracefully exit
                // the program.
                UCMASampleHelper.WriteException(tlsFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (ConnectionFailureException connectionFailureException)
            {
                // ConnectionFailureException will be thrown when the platform
                // could not listen on any of the configured IP/port
                // combinations.
                // TODO (Left to the reader): Error handling code to notify user
                // the configured IP address cannot be used or some other
                // process is already using the port, log the error for
                // debugging, or gracefully exit the program.
                UCMASampleHelper.WriteException(connectionFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (RealTimeException realTimeException)
            {
                // RealTimeException will be thrown when the platform startup
                // operation failed for some other reason.
                // TODO (Left to the reader): Error handling code to notify user
                // the configured IP address cannot be used or some other
                // process is already using the port, log the error for
                // debugging, or gracefully exit the program.
                UCMASampleHelper.WriteException(realTimeException);
                UCMASampleHelper.FinishSample();
            }
            try
            {
                // Create the ApplicationEndpointSettings.
                _endpointSettings = new ApplicationEndpointSettings(_endpointOwnerURI,
                                                                    _registrarFQDN,
                                                                    _registrarPort);

                // Create the ApplicationEndpoint from the
                // ApplicationEndpointSettings and bind it to the platform.
                _endpoint = new ApplicationEndpoint(platform, _endpointSettings);

                // Bind an event handler to notify when the endpoint changes
                // state.
                _endpoint.StateChanged += new EventHandler <LocalEndpointStateChangedEventArgs>(
                    _endpoint_StateChanged);

                // Establish the endpoint so that it can receive incoming calls
                // and conference invitations. EndEndpointEstablish()  will be
                // called when the endpoint finishes establishment.
                _endpoint.BeginEstablish(EndpointEstablishmentCompleted, _endpoint);

                UCMASampleHelper.WriteLine("Endpoint has been established.");
            }
            catch (ArgumentNullException argumentNullException)
            {
                // ArgumentNullException will be thrown if the parameters used to
                // construct ApplicationEndpointSettings or ApplicationEndpoint
                // are null.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the endpoint with non-null parameters, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentNullException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentException argumentException)
            {
                // ArgumentException will be thrown if the parameters used to
                // construct ApplicationEndpointSettings or ApplicationEndpoint
                // are invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the endpoint with corrected parameters, log
                // the error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentException);
                UCMASampleHelper.FinishSample();
            }
            catch (InvalidOperationException invalidOperationException)
            {
                // InvalidOperationException will be thrown if the platform is
                // already shutdown, an endpoint with the same SIP URI already
                // exists, or the endpoint has already been established or
                // terminated.
                // TODO (Left to the reader): Error handling code to log the
                // error for debugging.
                UCMASampleHelper.WriteException(invalidOperationException);
                UCMASampleHelper.FinishSample();
            }
        }