Beispiel #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("正在登陆用户");
                }
            }
Beispiel #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));
        }
        /// <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 #4
0
        /// <summary>
        /// Retrieves the application configuration and begins running the
        /// sample.
        /// </summary>
        void Run()
        {
            _appID = null;
            try
            {
                // Attempt to retrieve the application ID of the provisioned
                // application from the config file.
                _appID = System.Configuration.ConfigurationManager.AppSettings["ApplicationID"];
                if (string.IsNullOrEmpty(_appID))
                {
                    // The application ID wasn't retrieved from the config file
                    // so prompt for the application ID for the application that
                    // has been provisioned.
                    string prompt = "Please enter the unique ID of the application that is provisioned in "
                                    + "the topology => ";
                    _appID = UCMASampleHelper.PromptUser(prompt, null);
                }
                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);

                    // Wire up a handler for the
                    // ApplicationEndpointOwnerDiscovered event.
                    _collabPlatform.RegisterForApplicationEndpointSettings(
                        this.Platform_ApplicationEndpointOwnerDiscovered);

                    // Initialize and startup the platform.
                    _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);
                }
                else
                {
                    Console.WriteLine("No application ID was specified by the user.");
                }
                UCMASampleHelper.PauseBeforeContinuing("Press ENTER to shutdown and exit.");
            }
            catch (InvalidOperationException iOpEx)
            {
                // Invalid Operation Exception may be thrown if the data
                // provided to the BeginXXX methods was
                // invalid/malformed.
                // TODO (Left to the reader): Write actual handling code for the
                // occurrence.
                Console.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }
            finally
            {
                // Terminate the platform which would in turn terminate any
                // endpoints.
                Console.WriteLine("Shutting down the platform.");
                ShutdownPlatform();
            }
        }
Beispiel #5
0
        private void CreateAndStartServerPlatform()
        {
            var certToUse = GetLocalCertificate(_certificateFriendlyName);

            ServerPlatformSettings serverPlatformSettings = new ServerPlatformSettings(_applicationName, _applicationHostFQDN, _applicationPort, _applicationGruu, certToUse);

            _serverCollabPlatform = new CollaborationPlatform(serverPlatformSettings);

            // Startup the platform.
            _serverCollabPlatform.BeginStartup(EndPlatformStartup, _serverCollabPlatform);

            // Sync; wait for the startup to complete.
            _platformStartupCompleted.WaitOne();
            Console.WriteLine("Platform started...");
        }
Beispiel #6
0
        void Run()
        {
            _AppID = System.Configuration.ConfigurationManager.AppSettings["ApplicationID"];
            ProvisionedApplicationPlatformSettings settings = new ProvisionedApplicationPlatformSettings("My UCMA Application", _AppID);

            _CollabPlatform = new CollaborationPlatform(settings);
            _CollabPlatform.RegisterForApplicationEndpointSettings(Platform_ApplicationEndpointOwnerDiscovered);
            
            Console.WriteLine("Starting collaboration platform");
            _CollabPlatform.BeginStartup(PlatformStartupComplete, _CollabPlatform);

            //PauseBeforeContinuing("Press enter to shutdown and exit");

            Console.WriteLine("Shutting down the platform.");
            //ShutdownPlatform();
        }
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
        public static void Main(string[] args)
        {
            try
            {
                string appId = ConfigurationManager.AppSettings["ApplicationID"];

                Console.WriteLine("Creating CollaborationPlatform for the provisioned application with "
                                  + "ID \'{0}\' using ProvisionedApplicationPlatformSettings.", appId);
                ProvisionedApplicationPlatformSettings settings
                    = new ProvisionedApplicationPlatformSettings("UCMASampleApp", appId);

                settings.DefaultAudioVideoProviderEnabled = true;

                _collabPlatform = new CollaborationPlatform(settings);

                _collabPlatform.InstantMessagingSettings.SupportedFormats = InstantMessagingFormat.All;

                // Wire up a handler for the
                // ApplicationEndpointOwnerDiscovered event.
                _collabPlatform.RegisterForApplicationEndpointSettings(
                    Platform_ApplicationEndpointOwnerDiscovered);

                // Initalize and startup the platform.
                _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);

                Console.WriteLine("Please hit Esc key to end the sample.");

                ConsoleKeyInfo info = Console.ReadKey();
                while (info.Key != ConsoleKey.Escape)
                {
                    info = Console.ReadKey();
                }
            }
            catch (InvalidOperationException iOpEx)
            {
                Console.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }
            finally
            {
                Console.WriteLine("Shutting down the platform.");
                ShutdownPlatform();
            }
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            try
            {
                string appId = ConfigurationManager.AppSettings["ApplicationID"];

                Console.WriteLine("Creating CollaborationPlatform for the provisioned application with "
                    + "ID \'{0}\' using ProvisionedApplicationPlatformSettings.", appId);
                ProvisionedApplicationPlatformSettings settings
                    = new ProvisionedApplicationPlatformSettings("UCMASampleApp", appId);

                settings.DefaultAudioVideoProviderEnabled = true;

                _collabPlatform = new CollaborationPlatform(settings);

                _collabPlatform.InstantMessagingSettings.SupportedFormats = InstantMessagingFormat.All;

                // Wire up a handler for the
                // ApplicationEndpointOwnerDiscovered event.
                _collabPlatform.RegisterForApplicationEndpointSettings(
                    Platform_ApplicationEndpointOwnerDiscovered);

                // Initalize and startup the platform.
                _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);

                Console.WriteLine("Please hit Esc key to end the sample.");

                ConsoleKeyInfo info = Console.ReadKey();
                while (info.Key != ConsoleKey.Escape)
                {
                    info = Console.ReadKey();
                }
            }
            catch (InvalidOperationException iOpEx)
            {
                Console.WriteLine("Invalid Operation Exception: " + iOpEx.ToString());
            }
            finally
            {
                Console.WriteLine("Shutting down the platform.");
                ShutdownPlatform();
            }
        }
        public void Start()
        {
            // Get the application ID from App.config.
            string applicationUserAgent = "maximillian";
            string applicationId = ConfigurationManager.AppSettings["applicationId"];

            // Create a settings object.
            ProvisionedApplicationPlatformSettings settings =
                new ProvisionedApplicationPlatformSettings(applicationUserAgent, applicationId);

            // Create a new collaboration platform with the settings.
            _collaborationPlatform = new CollaborationPlatform(settings);
            _collaborationPlatform.RegisterForApplicationEndpointSettings(OnApplicationEndpointSettingsDiscovered);

            _logger.Log("Starting collaboration platform...");

            // Start the platform as an asynchronous operation.
            _collaborationPlatform.BeginStartup(OnPlatformStartupCompleted, null);
        }
        public void Start()
        {
            // Get the trusted application settings from App.config
            string appUserAgent = "MyUCMAApp";
            string applicationId = "urn:application:myucmaapp";
            string localhost = System.Net.Dns.GetHostEntry("localhost").HostName;
            int listeningPort = int.Parse("10600");

            _recipientSipUri = "sip:[email protected]";

            // Create a settings object that will hold all the previous information
            var settings = new ProvisionedApplicationPlatformSettings(appUserAgent, applicationId);
            //ServerPlatformSettings settings = new ServerPlatformSettings(applicationName, localhost, listeningPort, gruu, CertificateHelper.GetLocalCertificate());

            // Create a new collaboration platform with the settings
            _collaborationPlatform = new CollaborationPlatform(settings);

            // Start the platform as an asynchronous operation
            _collaborationPlatform.BeginStartup(OnPlatformStartupCompleted, null);
        }
        public void Start()
        {
            // Get the trusted application settings from App.config
            string appUserAgent = "MyUCMAApp";
            string applicationId = ConfigurationManager.AppSettings["applicationId"];
            string applicationName = ConfigurationManager.AppSettings["applicationName"];
            string localhost = System.Net.Dns.GetHostEntry("localhost").HostName;
            int listeningPort = int.Parse(ConfigurationManager.AppSettings["listeningPort"]);
            string gruu = ConfigurationManager.AppSettings["gruu"];

            // Create a settings object that will hold all the previous information
            var settings = new ProvisionedApplicationPlatformSettings(appUserAgent, applicationId);
            //ServerPlatformSettings settings = new ServerPlatformSettings(applicationName, localhost, listeningPort, gruu, CertificateHelper.GetLocalCertificate());

            // Create a new collaboration platform with the settings
            _collaborationPlatform = new CollaborationPlatform(settings);

            // Start the platform as an asynchronous operation
            _collaborationPlatform.BeginStartup(OnPlatformStartupCompleted, null);
        }
            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 #14
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 #15
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);
            }
        }
Beispiel #16
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 #18
0
        /// <summary>
        /// Returns an application endpoint that is provisioned on a platform
        /// as specified by the ApplicationID which could be provided by config
        /// file or be prompted to the user; if the platform discovers multiple
        /// application endpoints the first one discovered and established will be
        /// returned. If no application endpoints are discovered this method
        /// returns null.
        /// </summary>
        /// <returns></returns>
        public ApplicationEndpoint CreateAutoProvisionedApplicationEndpoint()
        {
            _applicationId = null;
            try
            {
                // Attempt to retrieve the application ID of the provisioned
                // application from the config file.
                _applicationId = System.Configuration.ConfigurationManager.AppSettings["ApplicationID"];
                if (string.IsNullOrEmpty(_applicationId))
                {
                    // The application ID wasn't retrieved from the config file
                    // so prompt for the application ID for the application that
                    // has been provisioned.
                    string prompt = "Please enter the unique ID of the application that is provisioned in "
                                    + "the topology => ";
                    _applicationId = UCMASampleHelper.PromptUser(prompt, null);
                }
                if (!string.IsNullOrEmpty(_applicationId))
                {
                    UCMASampleHelper.WriteLine("Creating CollaborationPlatform for the provisioned application"
                                               + " with ID \'" + _applicationId + "\' using ProvisionedApplicationPlatformSettings.");
                    ProvisionedApplicationPlatformSettings settings
                        = new ProvisionedApplicationPlatformSettings("UCMASampleApp", _applicationId);
                    // Reuse platform instance so that all endpoints share the
                    // same platform.
                    if (_collabPlatform == null)
                    {
                        // Initalize and startup the platform.
                        _collabPlatform = new CollaborationPlatform(settings);

                        // Wire up a handler for the
                        // ApplicationEndpointOwnerDiscovered event.
                        _collabPlatform.RegisterForApplicationEndpointSettings(
                            this.Platform_ApplicationEndpointOwnerDiscovered);
                        // Initalize and startup the platform.
                        _collabPlatform.BeginStartup(EndPlatformStartup, _collabPlatform);

                        if (_endpointInitCompletedEvent.WaitOne())
                        {
                            UCMASampleHelper.WriteLine("Found an application EP the Owner Uri is: "
                                                       + _applicationEndpoint.OwnerUri);
                        }
                        else
                        {
                            Console.WriteLine("Application endpoint was not established within the given time,"
                                              + " ending Sample.");
                            UCMASampleHelper.FinishSample();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Collaboration platform already exists, ending Sample.");
                        UCMASampleHelper.FinishSample();
                    }
                }
                else
                {
                    Console.WriteLine("No application ID was specified by the user. Unable to create an"
                                      + " ApplicationEndpoint to use in the sample.");
                    UCMASampleHelper.FinishSample();
                }

                return(_applicationEndpoint);
            }
            catch (InvalidOperationException iOpEx)
            {
                // Invalid Operation Exception may be thrown if the data provided
                // to the BeginStartUp is called when the platform has already been
                // started or terminated.
                // TODO (Left to the reader): Error handling code.
                UCMASampleHelper.WriteException(iOpEx);
                return(_applicationEndpoint);
            }
        }
Beispiel #19
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();
        }
Beispiel #20
0
        /// <summary>
        /// Retrieves the application configuration and begins starting up the
        /// platform.
        /// </summary>
        private void Run()
        {
            // Prompt for the settings necessary to initialize the
            // CollaborationPlatform and the ApplicationEndpoint if they are
            // not declared in App.config.
            // TODO (Left to the reader): Input sanitization on the
            // collected parameters.
            _applicationHostFQDN = UCMASampleHelper.PromptUser(
                "Please enter the FQDN assigned to this computer in the trusted application pool => ",
                "TrustedAppComputerFQDN");
            if (string.IsNullOrEmpty(_applicationHostFQDN))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No FQDN was found in App.config or input by the user.");
            }
            string inputPort = UCMASampleHelper.PromptUser(
                "Please enter the port assigned to this trusted application => ",
                "TrustedAppPort");

            if (!int.TryParse(inputPort, out _applicationHostPort))
            {
                UCMASampleHelper.WriteErrorLine(
                    "Port could not be parsed from App.config or from input by the user.");
            }
            _computerGRUU = UCMASampleHelper.PromptUser(
                "Please enter the GRUU assigned to this computer for this trusted application => ",
                "TrustedAppComputerGRUU");
            if (string.IsNullOrEmpty(_computerGRUU))
            {
                UCMASampleHelper.WriteErrorLine("No GRUU was found in App.config or input by the user.");
            }
            _certificateFriendlyName = UCMASampleHelper.PromptUser(
                "Please enter the friendly name of the certificate identifying this computer => ",
                "CertificateFriendlyName");
            if (string.IsNullOrEmpty(_certificateFriendlyName))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No certificate friendly name was found in App.config or input by the user.");
            }
            _certificate = UCMASampleHelper.GetLocalCertificate(_certificateFriendlyName);
            if (_certificate == null)
            {
                UCMASampleHelper.WriteErrorLine("Certificate with friendly name '" + _certificateFriendlyName
                                                + "' could not be found in computer account Personal certificate store.");
            }
            _endpointOwnerURI = UCMASampleHelper.PromptUser(
                "Please enter the SIP URI assigned to this trusted application endpoint => ",
                "TrustedAppEpOwnerURI");
            if (string.IsNullOrEmpty(_endpointOwnerURI))
            {
                UCMASampleHelper.WriteErrorLine("No SIP URI was found in App.config or input by the user.");
            }
            _registrarFQDN = UCMASampleHelper.PromptUser(
                "Please enter the FQDN of the registrar pool  to which this endpoint is assigned => ",
                "RegistrarFQDN");
            if (string.IsNullOrEmpty(_registrarFQDN))
            {
                UCMASampleHelper.WriteErrorLine(
                    "No registrar pool FQDN was found in App.config or input by the user.");
            }
            string inputRegistrarPort = UCMASampleHelper.PromptUser(
                "Please enter the port used by the registrar pool to which this endpoint is assigned => ",
                "RegistrarPort");

            if (!int.TryParse(inputRegistrarPort, out _registrarPort))
            {
                UCMASampleHelper.WriteErrorLine(
                    "Registrar port could not be parsed from App.config or from input by the user.");
            }

            try
            {
                // Create the CollaborationPlatform using the
                // ServerPlatformSettings.
                _platformSettings = new ServerPlatformSettings(_applicationUserAgent,
                                                               _applicationHostFQDN,
                                                               _applicationHostPort,
                                                               _computerGRUU,
                                                               _certificate);
                _platform = new CollaborationPlatform(_platformSettings);

                // Initialize and startup the platform. EndPlatformStartup()
                // will be called when the platform finishes starting up.
                UCMASampleHelper.WriteLine("Starting platform...");
                _platform.BeginStartup(PlatformStartupCompleted, _platform);
            }
            catch (ArgumentNullException argumentNullException)
            {
                // ArgumentNullException will be thrown if the parameters used
                // to construct ServerPlatformSettings or CollaborationPlatform
                // are null.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with non-null parameters, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentNullException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentOutOfRangeException argumentOutOfRangeException)
            {
                // ArgumentOutOfRangeException will be thrown if the port
                // parameter used to construct ServerPlatformSettings is greater
                // than 65536 or less than 0.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid port, log the error
                // for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentOutOfRangeException);
                UCMASampleHelper.FinishSample();
            }
            catch (ArgumentException argumentException)
            {
                // ArgumentException will be thrown if the parameters used to
                // construct ServerPlatformSettings or CollaborationPlatform are
                // invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with corrected parameters, log
                // the error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(argumentException);
                UCMASampleHelper.FinishSample();
            }
            catch (TlsFailureException tlsFailureException)
            {
                // TlsFailureException will be thrown if the certificate used to
                // construct CollaborationPlatform is invalid or otherwise
                // unusable.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid certificate, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(tlsFailureException);
                UCMASampleHelper.FinishSample();
            }
            catch (CryptographicException cryptographicException)
            {
                // CryptographicException will be thrown if the certificate used
                // to construct ServerPlatformSettings is invalid.
                // TODO (Left to the reader): Error handling code to either
                // retry creating the platform with a valid certificate, log the
                // error for debugging or gracefully exit the program.
                UCMASampleHelper.WriteException(cryptographicException);
                UCMASampleHelper.FinishSample();
            }
            catch (InvalidOperationException invalidOperationException)
            {
                // InvalidOperationException will be thrown if the platform has
                // already been started or shutdown.
                // TODO (Left to the reader): Error handling code to log the
                // error for debugging.
                UCMASampleHelper.WriteException(invalidOperationException);
                UCMASampleHelper.FinishSample();
            }
            finally
            {
                // Wait for the sample to finish before shutting down the
                // platform and returning from the main thread.
                UCMASampleHelper.WaitForSampleFinish();

                // It is possible the platform was never created due to issues
                // collecting configuration parameters.
                if (_platform != null)
                {
                    // Shutdown the platform, thereby terminating any attached
                    // endpoints.
                    UCMASampleHelper.WriteLine("Shutting down the platform...");
                    _platform.BeginShutdown(PlatformShutdownCompleted, _platform);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Method to start platform and endpoint initialization.
        /// </summary>
        public void Start()
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("Please restart");
            }

            string applicationId = Configuration.ApplicationId;

            if (!String.IsNullOrEmpty(applicationId))
            {
                ProvisionedApplicationPlatformSettings settings
                    = new ProvisionedApplicationPlatformSettings(UcmaHelper.ApplicationName, applicationId);

                //Create the platform.
                m_collabPlatform = new CollaborationPlatform(settings);


                //Populate im flow template.
                InstantMessagingFlowTemplate imFlowTemplate = new InstantMessagingFlowTemplate();
                imFlowTemplate.ComposingTimeoutValue      = 10; //seconds
                imFlowTemplate.SupportedFormats           = InstantMessagingFormat.PlainText | InstantMessagingFormat.HtmlText;
                imFlowTemplate.MessageConsumptionMode     = InstantMessageConsumptionMode.ProxiedToRemoteEntity;
                imFlowTemplate.ToastFormatSupport         = CapabilitySupport.UnSupported;
                m_collabPlatform.InstantMessagingSettings = imFlowTemplate;

                // Wire up a handler for the ApplicationEndpointOwnerDiscovered event.
                m_collabPlatform.RegisterForApplicationEndpointSettings(this.Platform_ApplicationEndpointOwnerDiscovered);

                bool needCleanup = true;
                try
                {
                    m_collabPlatform.BeginStartup(this.PlatformStartupCompleted, m_collabPlatform);
                    needCleanup = false;
                }
                catch (InvalidOperationException ioe)
                {
                    Helper.Logger.Error("Exception caught during startup {0}", EventLogger.ToString(ioe));
                }
                finally
                {
                    if (needCleanup)
                    {
                        this.Cleanup();
                    }
                }
                //Wait for all operations to complete.
                var allDone = m_allDone;
                if (allDone != null)
                {
                    bool succeeded = m_allDone.WaitOne(UcmaHelper.MaxTimeoutInMillis, false /*exitContext*/);
                    if (!succeeded)
                    {
                        Helper.Logger.Error("Initialization did not complete in expected time.");
                    }
                }
            }
            else
            {
                Helper.Logger.Error("Invalid application id. Please provide a valid value for application id in the web.config file.");
            }
        }