public void AddPatch(string patchName, PatchOptions Options = null) { if (string.IsNullOrWhiteSpace(patchName)) { throw new ApplicationException("Patch Name required"); } else { var cfgWriter = new BuildConfigurationWriter(_configFileName, _configLocalFileName); var cfg = cfgWriter.Read(); // load options //DatabaseOptions dbopt = LoadDatabaseOptions(cfg); //create unique id prefix to avoid collisions string prefix = $"{DateTime.Now:yyyyMMddHHmm}-{_rand.Next(0, 9999):0000}"; // patch names are limited to 50 char total at present, but this could be a property of the plugin string finalId = $"{prefix}-{patchName.Trim()}"; finalId = finalId.Substring(0, Math.Min(50, finalId.Length)); string patchPath = _io.Path.Combine(cfg.PatchFolder, finalId); if (!_io.Directory.Exists(patchPath)) { _io.Directory.CreateDirectory(patchPath); // when adding a patch, make it dependent on all patches // that don't already have a dependency. // need to guard against circular dependencies var openPatches = cfg.GetOpenPatches(); cfg.patches.Add(new Patch(finalId, openPatches)); cfgWriter.Write(cfg); } else { // create custom exception throw new ApplicationException($"A folder named '{finalId}' already exists"); } } }
public void InitConfig(InitOptions Options) { var cfgWriter = new BuildConfigurationWriter(_configFileName, _configLocalFileName); DatabaseBuildConfiguration databaseBuildConfiguration = new DatabaseBuildConfiguration() { DatabaseType = Options?.DbType, ConnectionString = null, PatchFolder = "Patches", CodeFolder = "Code" }; if (!_io.Directory.Exists(databaseBuildConfiguration.PatchFolder)) { _io.Directory.CreateDirectory(databaseBuildConfiguration.PatchFolder); } if (!_io.Directory.Exists(databaseBuildConfiguration.CodeFolder)) { _io.Directory.CreateDirectory(databaseBuildConfiguration.CodeFolder); } cfgWriter.Write(databaseBuildConfiguration); }