コード例 #1
0
 /// <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));
     }
 }
コード例 #2
0
        /// <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);
                }
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public string CreateInstance(string Name, string path)
        {
            path = Helpers.NormalizePath(path);
            var res = CheckInstanceName(Name);

            if (res != null)
            {
                return(res);
            }
            if (File.Exists(path) || Directory.Exists(path))
            {
                return("Cannot create instance at pre-existing path!");
            }
            lock (this)
            {
                if (Config.InstancePaths.Contains(path))
                {
                    return(String.Format("Instance at {0} already exists!", path));
                }
                foreach (var oic in GetInstanceConfigs())
                {
                    if (Name == oic.Name)
                    {
                        return(String.Format("Instance named {0} already exists!", oic.Name));
                    }
                }
                IInstanceConfig ic;
                try
                {
                    ic = new InstanceConfig(path)
                    {
                        Name = Name
                    };
                    Directory.CreateDirectory(path);
                    ic.Save();
                    Config.InstancePaths.Add(path);
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }
                return(SetupOneInstance(ic));
            }
        }