/// <summary> /// Starts and onlines an instance located at <paramref name="config"/> /// </summary> /// <param name="config">The <see cref="IInstanceConfig"/> for the <see cref="Instance"/></param> /// <returns><see langword="null"/> on success, error message on failure</returns> string SetupOneInstance(IInstanceConfig config) { if (!config.Enabled) { return(null); } try { var host = SetupInstance(config); if (host != null) { host.Open(); } else { lock (this) Config.InstancePaths.Remove(config.Directory); } return(null); } catch (Exception e) { return("Instance set up but an error occurred while starting it: " + e.ToString()); } }
/// <summary> /// Constructs and a <see cref="Instance"/> /// </summary> public Instance(IInstanceConfig config, byte logID) { LoggingID = logID; Config = config; InitAdministration(); InitEventHandlers(); InitChat(); InitRepo(); InitByond(); InitDreamDaemon(); InitCompiler(); }
/// <summary> /// Constructs and a <see cref="Instance"/> /// </summary> public Instance(IInstanceConfig config, byte logID) { LoggingID = logID; Config = config; FindTheDroidsWereLookingFor(); InitEventHandlers(); InitChat(); InitRepo(); InitByond(); InitDreamDaemon(); InitCompiler(); }
/// <summary> /// Creates and starts a <see cref="ServiceHost"/> for a <see cref="Instance"/> at <paramref name="config"/> /// </summary> /// <param name="config">The <see cref="IInstanceConfig"/> for the <see cref="Instance"/></param> /// <returns>The inactive <see cref="ServiceHost"/> on success, <see langword="null"/> on failure</returns> ServiceHost SetupInstance(IInstanceConfig config) { Instance instance; string instanceName; try { if (hosts.ContainsKey(config.Directory)) { var datInstance = ((Instance)hosts[config.Directory].SingletonInstance); Logger.WriteError(String.Format("Unable to start instance at path {0}. Has the same name as instance at path {1}. Detaching...", config.Directory, datInstance.ServerDirectory()), EventID.InstanceInitializationFailure, LoggingID); return(null); } if (!config.Enabled) { return(null); } var ID = LockLoggingID(); Logger.WriteInfo(String.Format("Instance {0} ({1}) assigned logging ID {2}", config.Name, config.Directory, ID), EventID.InstanceIDAssigned, ID); instanceName = config.Name; instance = new Instance(config, ID); } catch (Exception e) { Logger.WriteError(String.Format("Unable to start instance at path {0}. Detaching... Error: {1}", config.Directory, e.ToString()), EventID.InstanceInitializationFailure, LoggingID); return(null); } var host = CreateHost(instance, String.Format("{0}/{1}", Definitions.InstanceInterfaceName, instanceName)); hosts.Add(instanceName, host); AddEndpoint(host, typeof(ITGConnectivity)); AddEndpoint(host, typeof(ITGAdministration)); AddEndpoint(host, typeof(ITGByond)); AddEndpoint(host, typeof(ITGChat)); AddEndpoint(host, typeof(ITGCompiler)); AddEndpoint(host, typeof(ITGConfig)); AddEndpoint(host, typeof(ITGDreamDaemon)); AddEndpoint(host, typeof(ITGInstance)); AddEndpoint(host, typeof(ITGInterop)); AddEndpoint(host, typeof(ITGRepository)); host.Authorization.ServiceAuthorizationManager = instance; host.Authentication.ServiceAuthenticationManager = new AuthenticationHeaderDecoder(); return(host); }
/// <summary> /// Creates and starts a <see cref="ServiceHost"/> for a <see cref="Instance"/> at <paramref name="config"/> /// </summary> /// <param name="config">The <see cref="IInstanceConfig"/> for the <see cref="Instance"/></param> /// <returns>The inactive <see cref="ServiceHost"/> on success, <see langword="null"/> on failure</returns> ServiceHost SetupInstance(IInstanceConfig config) { Instance instance; string instanceName; try { if (hosts.ContainsKey(config.Directory)) { var datInstance = ((Instance)hosts[config.Directory].SingletonInstance); Logger.WriteError(String.Format("Unable to start instance at path {0}. Has the same name as instance at path {1}. Detaching...", config.Directory, datInstance.ServerDirectory()), EventID.InstanceInitializationFailure, LoggingID); return(null); } if (!config.Enabled) { return(null); } var ID = LockLoggingID(); Logger.WriteInfo(String.Format("Instance {0} ({1}) assigned logging ID {2}", config.Name, config.Directory, ID), EventID.InstanceIDAssigned, ID); instanceName = config.Name; instance = new Instance(config, ID); } catch (Exception e) { Logger.WriteError(String.Format("Unable to start instance at path {0}. Detaching... Error: {1}", config.Directory, e.ToString()), EventID.InstanceInitializationFailure, LoggingID); return(null); } var host = CreateHost(instance, String.Format("{0}/{1}", ServerInterface.InstanceInterfaceName, instanceName)); hosts.Add(instanceName, host); foreach (var J in ServerInterface.ValidInstanceInterfaces) { AddEndpoint(host, J); } host.Authorization.ServiceAuthorizationManager = instance; return(host); }
/// <inheritdoc /> public string RenameInstance(string name, string new_name) { if (name == new_name) { return(null); } var res = CheckInstanceName(new_name); if (res != null) { return(res); } lock (this) { //we have to check em all anyway IInstanceConfig the_droid_were_looking_for = null; foreach (var ic in GetInstanceConfigs()) { if (ic.Name == name) { the_droid_were_looking_for = ic; break; } else if (ic.Name == new_name) { return(String.Format("There is already another instance named {0}!", new_name)); } } if (the_droid_were_looking_for == null) { return(String.Format("There is no instance named {0}!", name)); } var ie = InstanceEnabled(name); if (ie) { SetInstanceEnabled(name, false); } the_droid_were_looking_for.Name = new_name; string result = ""; try { the_droid_were_looking_for.Save(); result = null; } catch (Exception e) { result = "Could not save instance config! Error: " + e.ToString(); } finally { if (ie) { var resRestore = SetInstanceEnabled(new_name, true); if (resRestore != null) { result = (result + " " + resRestore).Trim(); } } } return(result); } }