コード例 #1
0
ファイル: PortRange.cs プロジェクト: mujiansu/Lync
        private void EndEndpointEstablish(IAsyncResult ar)
        {
            UserEndpoint userEndpoint = ar.AsyncState as UserEndpoint;

            try
            {
                userEndpoint.EndEstablish(ar);
                Console.WriteLine("The User Endpoint owned by URI: ");
                Console.WriteLine(userEndpoint.OwnerUri);
                Console.WriteLine(" is now established and registered.");
            }
            catch (ConnectionFailureException connFailEx)
            {
                // ConnectionFailureException will be thrown when the endpoint cannot connect to the server, or the credentials are invalid.
                // It is left to the developer to write real error handling code.
                Console.WriteLine(connFailEx.ToString());
            }
            catch (InvalidOperationException iOpEx)
            {
                // InvalidOperationException will be thrown when the endpoint is not in a valid state to connect. To connect, the platform must be started and the Endpoint Idle.
                // It is left to the developer to write real error handling code.
                Console.WriteLine(iOpEx.ToString());
            }
            catch (RegisterException regEx)
            {
                // RegisterException will be thrown when the endpoint cannot be registered (usually due to bad credentials).
                // It is left to the developer to write real error handling code (here, the appropriate action is likely reprompting for user/password/domain strings).
                Console.WriteLine(regEx.ToString());
            }

            //Again, just for sync. reasons.
            _autoResetEvent.Set();
        }
コード例 #2
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));
        }
コード例 #3
0
            private void OcsBeginEstablishFinished(IAsyncResult ar)
            {
                currentOperation.End("OcsBeginEstablishFinished", () => userEndpoint.EndEstablish(ar));

                currentOperation.Begin(string.Format("Connect to GC={0}", SampleCommon.PersistentChatServerUri),
                                       () =>
                {
                    // Connect to Persistent Chat Server
                    persistentChatEndpoint = new PersistentChatEndpoint(SampleCommon.PersistentChatServerUri, userEndpoint);
                    persistentChatEndpoint.BeginEstablish(ar1 => PersistentChatBeginEstablishFinished(ar1), null);
                });
            }
コード例 #4
0
        public static Task EstablishAsync(this
                                          UserEndpoint endpoint)
        {
            Action <IAsyncResult> action = (result) =>
            {
                endpoint.EndEstablish(result);
            };

            return(Task.Factory.FromAsync(
                       endpoint.BeginEstablish,
                       action,
                       null));
        }
コード例 #5
0
ファイル: Endpoint.cs プロジェクト: StefanPlizga/lumt
        public void CreateUserEndpoint(string userURI)
        {
            UserEndpointSettings settings = new UserEndpointSettings(userURI);

            user = new UserEndpoint(collabPlatform, settings);
            user.EndEstablish(user.BeginEstablish(null, null));
            if (user.State != LocalEndpointState.Established)
            {
                throw new Exception("Local endpoint state is not established");
            }

            alertNotification = null;
        }
コード例 #6
0
ファイル: AppFrontEnd.cs プロジェクト: mujiansu/Lync
        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
        public void SetPresence(User user, PreferredUserStatus status)
        {
            if (!LyncCollaboration.HasStarted)
            {
                LyncCollaboration.Start();
            }

            var state = PresenceState.UserAway;

            switch (status)
            {
            case PreferredUserStatus.BeRightBack:
                state = PresenceState.UserBeRightBack;
                break;

            case PreferredUserStatus.Busy:
                state = PresenceState.UserBusy;
                break;

            case PreferredUserStatus.DoNotDisturb:
                state = PresenceState.UserDoNotDisturb;
                break;

            case PreferredUserStatus.Offwork:
                state = PresenceState.UserOffWork;
                break;

            case PreferredUserStatus.Online:
                state = PresenceState.UserAvailable;
                break;
            }

            user.ClearPresence();

            var host     = Plugin.LyncPlugin.Configuration.GetString("host");
            var appPort  = Plugin.LyncPlugin.Configuration.GetInt("appPort");
            var sip      = "sip:" + user.SipUri();
            var endpoint = new UserEndpoint(LyncCollaboration.Platform, new UserEndpointSettings(sip, host, appPort));

            endpoint.EndEstablish(endpoint.BeginEstablish(null, null));
            endpoint.LocalOwnerPresence.EndSubscribe(endpoint.LocalOwnerPresence.BeginSubscribe(null, null));
            endpoint.LocalOwnerPresence.EndPublishPresence(endpoint.LocalOwnerPresence.BeginPublishPresence(new PresenceCategory[] { state }, null, null));
            endpoint.EndTerminate(endpoint.BeginTerminate(null, null));
        }
コード例 #8
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);
            }
        }
コード例 #9
0
        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);
        }