/// <summary> /// Starts the server and loads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <param name="runStates">State information to start the instance with.</param> /// <exception cref="Exception">Thrown when an error occurs, caller should call <see cref="Stop"/> in this cass.</exception> public void Start(ComponentRunState[] runStates) { bool setDllDirectorySuccess = SetDllDirectory(assemblyPath); if (setDllDirectorySuccess) { if (log.IsInfoEnabled) { log.InfoFormat("Set DllDirectory to {0}. Unmanaged dlls will be imported from this folder.", assemblyPath); } } else { if (log.IsErrorEnabled) { log.ErrorFormat("Failed to set DllDirectory to {0}. Components that rely on unmanaged DLLs will not work.", assemblyPath); } } if (log.IsInfoEnabled) { log.Info("Getting new node."); } //enable this manually after the server is up an running because on server startup //code that modifies the directory will cause the domain to reload. AssemblyLoader.Instance.EnableRaisingEvents = false; relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); if (relayNode != null) { if (log.IsInfoEnabled) { log.Info("New node created."); log.Info("Initializing Relay Node Instance"); } relayNode.Initialize(runStates); if (log.IsInfoEnabled) { log.Info("Relay Node Initialized, Starting"); } relayNode.Start(); if (log.IsInfoEnabled) { log.Info("Relay Node Started"); } AssemblyLoader.Instance.EnableRaisingEvents = true; } else { if (log.IsErrorEnabled) { log.Error("Error starting Relay Server: No Relay Node implemenation found!"); } } }
/// <summary> /// Stops the server, reloads the assembly and restarts the server. /// </summary> public void AssemblyChanged() //should rename to ReloadAssembly { try { //preserve state information between assembly reloads ComponentRunState[] runStates = GetRunState(); Stop(); Start(runStates); } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Exception recycling Relay Node Domain: " + ex.ToString() + Environment.NewLine + "Trying again with no runstate."); } relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); relayNode.Initialize(null); relayNode.Start(); } }
/// <summary> /// Starts the server and loads the <see cref="IRelayNode"/> instance's assembly. /// </summary> /// <param name="runStates">State information to start the instance with.</param> /// <exception cref="Exception">Thrown when an error occurs, caller should call <see cref="Stop"/> in this cass.</exception> public void Start(ComponentRunState[] runStates) { bool setDllDirectorySuccess = SetDllDirectory(assemblyPath); if (setDllDirectorySuccess) { if (log.IsInfoEnabled) log.InfoFormat("Set DllDirectory to {0}. Unmanaged dlls will be imported from this folder.", assemblyPath); } else { if (log.IsErrorEnabled) log.ErrorFormat("Failed to set DllDirectory to {0}. Components that rely on unmanaged DLLs will not work.", assemblyPath); } if (log.IsInfoEnabled) log.Info("Getting new node."); //enable this manually after the server is up an running because on server startup //code that modifies the directory will cause the domain to reload. AssemblyLoader.Instance.EnableRaisingEvents = false; relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); if (relayNode != null) { if (log.IsInfoEnabled) { log.Info("New node created."); log.Info("Initializing Relay Node Instance"); } relayNode.Initialize(runStates); if (log.IsInfoEnabled) log.Info("Relay Node Initialized, Starting"); relayNode.Start(); if (log.IsInfoEnabled) log.Info("Relay Node Started"); AssemblyLoader.Instance.EnableRaisingEvents = true; } else { if (log.IsErrorEnabled) log.Error("Error starting Relay Server: No Relay Node implemenation found!"); } }
/// <summary> /// Stops the server, reloads the assembly and restarts the server. /// </summary> public void AssemblyChanged() //should rename to ReloadAssembly { try { //preserve state information between assembly reloads ComponentRunState[] runStates = GetRunState(); Stop(); Start(runStates); } catch (Exception ex) { if (log.IsErrorEnabled) log.Error("Exception recycling Relay Node Domain: " + ex.ToString() + Environment.NewLine + "Trying again with no runstate."); relayNode = AssemblyLoader.Instance.GetRelayNode(nodeChangedDelegate); relayNode.Initialize(null); relayNode.Start(); } }