Exemple #1
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("正在登陆用户");
                }
            }
Exemple #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));
        }
Exemple #3
0
 public bool EstablishUserEndpoint(UserEndpoint userEndpoint)
 {
     if (_isPlatformStarted == false)
     {
         userEndpoint.Platform.BeginStartup(EndPlatformStartup, userEndpoint.Platform);
         _platformStartupCompleted.WaitOne();
         _isPlatformStarted = true;
     }
     userEndpoint.BeginEstablish(EndEndpointEstablish, userEndpoint);
     _endpointInitCompletedEvent.WaitOne();
     return(true);
 }
Exemple #4
0
        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;
        }
Exemple #5
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."));
                }
            });
        }
Exemple #6
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));
        }
        // Method to establish an already created UserEndpoint.
        // This method returns an established UserEndpoint object. If you do not want to monitor LocalOwnerPresence, you may
        // want to call the CreateEstablishedUserEndpoint method directly. Otherwise, you may call ReadUserSettings
        // followed by CreateUserEndpoint, followed by EstablishUserEndpoint methods.
        public bool EstablishUserEndpoint(UserEndpoint userEndpoint)
        {
            // Startup the platform, if not already
            if (_isPlatformStarted == false)
            {
                userEndpoint.Platform.BeginStartup(EndPlatformStartup, userEndpoint.Platform);

                // Sync; wait for the platform startup to complete.
                _platformStartupCompleted.WaitOne();
                NonBlockingConsole.WriteLine("Platform started...");
                _isPlatformStarted = true;
            }
            // Establish the user endpoint
            userEndpoint.BeginEstablish(EndEndpointEstablish, userEndpoint);

            // Sync; wait for the registration to complete.
            _endpointInitCompletedEvent.WaitOne();
            NonBlockingConsole.WriteLine("Endpoint established...");
            return(true);
        }
Exemple #8
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));
            }
Exemple #9
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);
            }
        }
        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);
        }
        // Method to establish an already created UserEndpoint.
        // This method returns an established UserEndpoint object. If you do not want to monitor LocalOwnerPresence, you may 
        // want to call the CreateEstablishedUserEndpoint method directly. Otherwise, you may call ReadUserSettings
        // followed by CreateUserEndpoint, followed by EstablishUserEndpoint methods.
        public bool EstablishUserEndpoint(UserEndpoint userEndpoint)
        {
            // Startup the platform, if not already
            if (_isPlatformStarted == false)
            {
                userEndpoint.Platform.BeginStartup(EndPlatformStartup, userEndpoint.Platform);

                // Sync; wait for the platform startup to complete.
                _platformStartupCompleted.WaitOne();
                NonBlockingConsole.WriteLine("Platform started...");
                _isPlatformStarted = true;
            }
            // Establish the user endpoint
            userEndpoint.BeginEstablish(EndEndpointEstablish, userEndpoint);

            // Sync; wait for the registration to complete.
            _endpointInitCompletedEvent.WaitOne();
            NonBlockingConsole.WriteLine("Endpoint established...");
            return true;
        }
Exemple #12
0
        public UserEndpoint CreateUserEndpointWithServerPlatform(string endpointFriendlyName)
        {
            string prompt = string.Empty;

            if (string.IsNullOrEmpty(endpointFriendlyName))
            {
                endpointFriendlyName = "Default User";
            }

            try
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine("Creating User Endpoint for {0}...", endpointFriendlyName);
                Console.WriteLine();

                if (ConfigurationManager.AppSettings[_serverFQDNPrompt + _userCount] != null)
                {
                    if (ReadGenericApplicationContactConfiguration())
                    {
                        Console.WriteLine("Using {0} as Microsoft Lync Server", _serverFqdn);
                    }
                    else
                    {
                        Console.WriteLine("Error. Could not read AppSettings");
                    }
                }
                else
                {
                    Console.WriteLine("Please fill in the App.config file.");
                }

                // Prompt user for user name
                prompt = String.Concat(
                    "Please enter the User Name for ",
                    endpointFriendlyName,
                    " (or hit the ENTER key to use current credentials)\r\n" +
                    "Please enter the User Name => ");
                _userName = PromptUser(prompt, _userNamePrompt + _userCount);

                // If user name is empty, use current credentials
                if (string.IsNullOrEmpty(_userName))
                {
                    Console.WriteLine("Username was empty - using current credentials...");
                    _useSuppliedCredentials = true;
                }
                else
                {
                    // Prompt for password
                    prompt        = String.Concat("Enter the User Password for ", endpointFriendlyName, " => ");
                    _userPassword = PromptUser(prompt, null);

                    prompt      = String.Concat("Please enter the User Domain for ", endpointFriendlyName, " => ");
                    _userDomain = PromptUser(prompt, _userDomainPrompt + _userCount);
                }

                // Prompt user for user URI
                prompt   = String.Concat("Please enter the User URI for ", endpointFriendlyName, " in the User@Host format => ");
                _userURI = PromptUser(prompt, _userURIPrompt + _userCount);
                if (!(_userURI.ToLower().StartsWith("sip:") || _userURI.ToLower().StartsWith("tel:")))
                {
                    _userURI = "sip:" + _userURI;
                }

                // Reuse platform instance so that all endpoints share the same platform.
                if (_serverCollabPlatform == null)
                {
                    CreateAndStartServerPlatform();
                }

                // Increment the last user number
                _userCount++;

                // Initalize and register the endpoint, using the credentials of the user the application will be acting as.
                // NOTE: the _userURI should always be of the form "sip:user@host"
                UserEndpointSettings userEndpointSettings = new UserEndpointSettings(_userURI, _serverFqdn);
                if (!_useSuppliedCredentials)
                {
                    _credential = new System.Net.NetworkCredential(_userName, _userPassword, _userDomain);
                    userEndpointSettings.Credential = _credential;
                }
                else
                {
                    userEndpointSettings.Credential = System.Net.CredentialCache.DefaultNetworkCredentials;
                }

                _userEndpoint = new UserEndpoint(_serverCollabPlatform, userEndpointSettings);
                _endpointInitCompletedEvent.Reset();
                _userEndpoint.BeginEstablish(EndEndpointEstablish, _userEndpoint);

                // Sync; wait for the registration to complete.
                _endpointInitCompletedEvent.WaitOne();
                Console.WriteLine("{0} endpoint established...", endpointFriendlyName);
            }
            catch (InvalidOperationException iOpEx)
            {
                // Invalid Operation Exception should only be thrown on poorly-entered input.
                Console.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }

            return(_userEndpoint);
        }
Exemple #13
0
        public void Run()
        {
            //Initalize and startup the platform.
            ClientPlatformSettings clientPlatformSettings = new ClientPlatformSettings(_applicationName, _transportType);

            _collabPlatform = new CollaborationPlatform(clientPlatformSettings);
            _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);

            // Get port range
            NetworkPortRange portRange = CollaborationPlatform.AudioVideoSettings.GetPortRange();

            Console.WriteLine("Port range is from " + portRange.LocalNetworkPortMin + " to " + portRange.LocalNetworkPortMax);

            // Modifying port range
            portRange.SetRange(1500, 2000);
            CollaborationPlatform.AudioVideoSettings.SetPortRange(portRange);
            Console.WriteLine("Port range now is from " + portRange.LocalNetworkPortMin + " to " + portRange.LocalNetworkPortMax);

            //Sync; wait for the startup to complete.
            _autoResetEvent.WaitOne();


            //Initalize and register the endpoint, using the credentials of the user the application will be acting as.
            UserEndpointSettings userEndpointSettings = new UserEndpointSettings(_userURI, _userServer);

            userEndpointSettings.Credential = _credential;
            _userEndpoint = new UserEndpoint(_collabPlatform, userEndpointSettings);
            _userEndpoint.BeginEstablish(EndEndpointEstablish, _userEndpoint);

            //Sync; wait for the registration to complete.
            _autoResetEvent.WaitOne();


            //Setup the conversation and place the call.
            ConversationSettings convSettings = new ConversationSettings();

            convSettings.Priority = _conversationPriority;
            convSettings.Subject  = _conversationSubject;
            //Conversation represents a collection of modalities in the context of a dialog with one or multiple callees.
            Conversation conversation = new Conversation(_userEndpoint, convSettings);

            _audioVideoCall = new AudioVideoCall(conversation);

            //Call: StateChanged: Only hooked up for logging.
            _audioVideoCall.StateChanged += new EventHandler <CallStateChangedEventArgs>(audioVideoCall_StateChanged);

            //Subscribe for the flow configuration requested event; the flow will be used to send the media.
            //Ultimately, as a part of the callback, the media will be sent/recieved.
            _audioVideoCall.AudioVideoFlowConfigurationRequested += this.audioVideoCall_FlowConfigurationRequested;


            //Place the call to the remote party;
            _audioVideoCall.BeginEstablish(_calledParty, null, EndCallEstablish, _audioVideoCall);

            //Sync; wait for the call to complete.
            _autoResetEvent.WaitOne();

            // Shutdown the platform
            _collabPlatform.BeginShutdown(EndPlatformShutdown, _collabPlatform);

            //Wait for shutdown to occur.
            _autoResetShutdownEvent.WaitOne();
        }