/// <summary> /// Load and compile the application manifest, and try /// to connect to the Live Communications Server. /// </summary> /// <exception cref="System.Exception">If unable to /// connect. The exception string contains the details /// </exception> /// <param name="manifestFile">file name of the SPL manifest. /// This file must be present in the working directory of the /// executable /// </param> /// <param name="applicationName">A friendly name for use while /// registering with WMI. Use a null value if you dont want /// the function to do registration /// </param> /// <param name="appGuid">Guid for use during WMI registration. /// If a null guid is specified but applicationName is not /// null, a new guid will be generated, used, and returned. /// </param> /// <seealso cref="Microsoft.Rtc.Sip.CompilerErrorException"/> /// <seealso cref="Microsoft.Rtc.Sip.ServerAgent"/> public void ConnectToServer(string manifestFile, string applicationName, ref string appGuid) { ///load and compile the application manifest applicationManifest = ApplicationManifest.CreateFromFile(manifestFile); if (applicationManifest == null) { throw new Exception( String.Format("The manifest file {0} was not found", manifestFile)); } try { applicationManifest.Compile(); ///try to connect to server serverAgent = new ServerAgent(this, applicationManifest); } catch (CompilerErrorException cee) { ///collapse all compiler errors into one, and return it StringBuilder sb = new StringBuilder(1024, 1024); foreach (string errorMessage in cee.ErrorMessages) { if (errorMessage.Length + sb.Length + 2 < sb.MaxCapacity) { sb.Append(errorMessage); sb.Append("\r\n"); } else { ///compiler returns really large error message ///so just return what we can accomodate sb.Append(errorMessage.Substring(0, sb.MaxCapacity - sb.Length - 1)); break; } } throw new Exception(sb.ToString()); } catch (Exception e) { if (applicationManifest != null) { applicationManifest = null; } //ServerNotFoundException || UnauthorizedException throw e; } ///hook the connection dropped event handler serverAgent.ConnectionDropped += new ConnectionDroppedEventHandler(this.ConnectionDroppedHandler); //ConnectionDroppedEventHandler ///start the eventManager thread after making sure one is ///not already running eventManagerQuit.Reset(); eventManagerThread = new Thread(new ThreadStart(EventManagerHandler)); eventManagerThread.Start(); return; }
static ServerAgent ConnectToServer(object app, string amFile) { try { ServerAgent.WaitForServerAvailable(3); // 3 Attempts } catch (Exception e1) { Console.WriteLine("ERROR: Server unavailable - {0}", e1.Message); if (e1 is UnauthorizedException) { Console.WriteLine("must be running under an account that is a member of the \"RTC Server Applications\" local group"); } return(null); } ApplicationManifest am = ApplicationManifest.CreateFromFile(amFile); if (am == null) { Console.WriteLine("ERROR: {0} application manifest file not found.", amFile); return(null); } try { am.Compile(); } catch (CompilerErrorException e2) { Console.WriteLine("ERROR: {0} application manifest file contained errors:", amFile); foreach (string message in e2.ErrorMessages) { Console.WriteLine(message); } return(null); } try { ServerAgent agent = new ServerAgent(app, am); Console.WriteLine("ServerAgent instantiated successfully with Role={0}", agent.Role.ToString()); return(agent); } catch (Exception e3) { Console.WriteLine("ERROR: Unable insnatiate ServerAgent and to connect to server - {0}", e3.Message); Console.WriteLine("ERROR: type - {0}", e3.GetType().ToString()); Console.WriteLine("ERROR: stacktrace: {0}", e3.StackTrace); if (e3.InnerException != null) { Console.WriteLine("ERROR: inner exception: {0} ", e3.InnerException.Message); } return(null); } }
// // Static function to connect to Server // public static ServerAgent ConnectToServer(object app, string amFile) { try { ServerAgent.WaitForServerAvailable(3); // 3 Attempts } catch (Exception e1) { Console.WriteLine("ERROR: Server unavailable - {0}", e1.Message); if (e1 is UnauthorizedException) { Console.WriteLine("must be running under an account that is a member of the \"RTC Server Applications\" local group"); } return(null); } ApplicationManifest am = ApplicationManifest.CreateFromFile(amFile); if (am == null) { Console.WriteLine("ERROR: {0} application manifest file not found.", amFile); return(null); } try { am.Compile(); } catch (CompilerErrorException e2) { Console.WriteLine("ERROR: {0} application manifest file contained errors:", amFile); foreach (string message in e2.ErrorMessages) { Console.WriteLine(message); } return(null); } try { ServerAgent agent = new ServerAgent(app, am); return(agent); } catch (Exception e3) { Console.WriteLine("ERROR: Unable to connect to server - {0}", e3.Message); return(null); } }
/// <summary> /// Load and compile the application manifest, and try /// to connect to the Live Communications Server. /// </summary> /// <exception cref="System.Exception">If unable to /// connect. The exception string contains the details /// </exception> /// <param name="manifestFile">file name of the SPL manifest. /// This file must be present in the working directory of the /// executable /// </param> /// <param name="applicationName">A friendly name for use while /// registering with WMI. Use a null value if you dont want /// the function to do registration /// </param> /// <param name="appGuid">Guid for use during WMI registration. /// If a null guid is specified but applicationName is not /// null, a new guid will be generated, used, and returned. /// </param> /// <seealso cref="Microsoft.Rtc.Sip.CompilerErrorException"/> /// <seealso cref="Microsoft.Rtc.Sip.ServerAgent"/> public virtual void ConnectToServer( string manifestFile, string applicationName, ref string appGuid ) { CheckDisposed(); // // Load and compile the application manifest. // applicationManifest = ApplicationManifest.CreateFromFile(manifestFile); if (applicationManifest == null) { throw new Exception( String.Format("The manifest file {0} was not found", manifestFile)); } try { // // Compile the manifest. // applicationManifest.Compile(); // // Connect to server. // serverAgent = new ServerAgent(this, applicationManifest); } catch (CompilerErrorException cee) { // // Collapse all compiler errors into one, and return it // StringBuilder sb = new StringBuilder(1024, 1024); foreach (string errorMessage in cee.ErrorMessages) { if (errorMessage.Length + sb.Length + 2 < sb.MaxCapacity) { sb.Append(errorMessage); sb.Append("\r\n"); } else { sb.Append(errorMessage.Substring(0, sb.MaxCapacity - sb.Length - 1)); break; } } throw new Exception(sb.ToString()); } catch (Exception e) { if (applicationManifest != null) { applicationManifest = null; } // ServerNotFoundException || UnauthorizedException throw e; } // // Install the connection dropped event handler. // serverAgent.ConnectionDropped += new ConnectionDroppedEventHandler(this.ConnectionDroppedHandler); // // Start the event manager. // quitHandle = new AutoResetEvent(false); eventManager = new Thread(new ThreadStart(EventManager)); eventManager.Start(); return; }