public Mod(String Name, List <ModTitle> Titles, List <Release> Releases) { StringValidator.ValidateRequiredStringWithMaxLength(Name, nameof(Name), Mod.NameLength); ListValidator.ValidateRequiredListNotEmpty <ModTitle>(Titles, nameof(Titles)); ListValidator.ValidateRequiredListNotEmpty <Release>(Releases, nameof(Releases)); Regex modNameCaptureRegex = new Regex(Mod.ModNameCapturePattern); Match match = modNameCaptureRegex.Match(Name); if (!match.Success) { throw new ArgumentException($"Unable to parse \"{Name}\" to a valid mod name due to formatting.", "Name"); } // TODO: Should we validate that the modName matches the various modName properties (e.g. ReleaseFileName.ModName, ReleaseDownloadURL.ModName, etc.) foreach (Release release in Releases) { if (release.ReleaseFileName.ModName != Name) { throw new ArgumentException($"The mod name in the release filename \"{release.ReleaseFileName}\" does not match the specified mod name \"{Name}\".", nameof(Releases)); } if (release.ReleaseDownloadUrl.ModName != Name.Replace(" ", "%20")) { throw new ArgumentException($"The mod name in the release download URL \"{release.ReleaseDownloadUrl}\" does not match the specified mod name \"{Name}\".", nameof(Releases)); } } this.Name = match.Groups[1].Value; this.Releases = Releases.ConvertAll(release => new Release(release)); this.Titles = Titles.ConvertAll(title => new ModTitle(title)); }
public Release(DateTime ReleasedAt, String Sha1String, ReleaseDownloadUrl ReleaseDownloadUrl, ReleaseFileName ReleaseFileName, ModVersion ModVersion, FactorioVersion FactorioVersion, List <Dependency> Dependencies) { DateTimeValidator.ValidateRequiredDateTimeBeforePresent(ReleasedAt, nameof(ReleasedAt)); ObjectValidator.ValidateRequiredObject(Sha1String, nameof(Sha1String)); ObjectValidator.ValidateRequiredObject(ReleaseDownloadUrl, nameof(ReleaseDownloadUrl)); ObjectValidator.ValidateRequiredObject(ReleaseFileName, nameof(ReleaseFileName)); ObjectValidator.ValidateRequiredObject(ModVersion, nameof(ModVersion)); ObjectValidator.ValidateRequiredObject(FactorioVersion, nameof(FactorioVersion)); ListValidator.ValidateRequiredListNotEmpty(Dependencies, nameof(Dependencies)); Regex sha1CaptureRegex = new Regex(Release.Sha1CapturePattern); Match match = sha1CaptureRegex.Match(Sha1String); if (!match.Success) { throw new ArgumentException($"Unable to parse \"{Sha1String}\" to a valid SHA-1 hash due to formatting.", "Sha1String"); } String sha1 = match.Groups[1].Value; if (sha1.Length != Sha1Length) { throw new ArgumentException($"Unable to parse \"{Sha1String}\" to a valid SHA-1 hash due to length. The SHA-1 hash must have a length of exactly {Release.Sha1Length} characters.", "Sha1String"); } if (ModVersion != ReleaseFileName.ModVersion) { throw new ArgumentException("The specified release file name version does not match the specified release version.", "ReleaseFileName"); } this.ReleasedAt = ReleasedAt; this.ReleaseDownloadUrl = new ReleaseDownloadUrl(ReleaseDownloadUrl); this.ReleaseFileName = new ReleaseFileName(ReleaseFileName); this.Sha1 = sha1; this.ModVersion = new ModVersion(ModVersion); this.FactorioVersion = new FactorioVersion(FactorioVersion); // TODO: We may want to write an .AddDependency() method that validates that the dependency we're adding isn't for the release/mod itself. That would generate a circular dependency. this.Dependencies = Dependencies.ConvertAll(dependency => new Dependency(dependency)); }