/// <inheritdoc /> public string ImportInstance(string path) { path = Helpers.NormalizePath(path); lock (this) { if (Config.InstancePaths.Contains(path)) { return(String.Format("Instance at {0} already exists!", path)); } if (!Directory.Exists(path)) { return(String.Format("There is no instance located at {0}!", path)); } IInstanceConfig ic; try { ic = InstanceConfig.Load(path); foreach (var oic in GetInstanceConfigs()) { if (ic.Name == oic.Name) { return(String.Format("Instance named {0} already exists!", oic.Name)); } } ic.Save(); Config.InstancePaths.Add(path); } catch (Exception e) { return(e.ToString()); } return(SetupOneInstance(ic)); } }
/// <summary> /// Enumerates configured <see cref="IInstanceConfig"/>s. Detaches those that fail to load /// </summary> /// <returns>Each configured <see cref="IInstanceConfig"/></returns> IEnumerable <IInstanceConfig> GetInstanceConfigs() { var pathsToRemove = new List <string>(); lock (this) { var IPS = Config.InstancePaths; foreach (var I in IPS) { IInstanceConfig ic; try { ic = InstanceConfig.Load(I); } catch (Exception e) { Logger.WriteError(String.Format("Unable load instance config at path {0}. Error: {1} Detaching...", I, e.ToString()), EventID.InstanceInitializationFailure, LoggingID); pathsToRemove.Add(I); continue; } yield return(ic); } foreach (var I in pathsToRemove) { IPS.Remove(I); } } }