/// <summary> /// Creates and saves a new napack. /// </summary> /// <param name="napackName">The name of the napack</param> /// <param name="newNapack">The new napack to create/save</param> /// <param name="napackSpec">The napack specification</param> public void SaveNewNapack(string napackName, NewNapack newNapack, NapackSpec napackSpec) { NapackVersionIdentifier version = new NapackVersionIdentifier(napackName, 1, 0, 0); NapackMetadata metadata = NapackMetadata.CreateFromNewNapack(napackName, newNapack); NapackVersion packageVersion = NapackVersion.CreateFromNewNapack(newNapack.NewNapackVersion); foreach (string author in newNapack.NewNapackVersion.Authors) { AddAuthorConsumption(author, version); } foreach (string userId in newNapack.metadata.AuthorizedUserIds) { AddUserAuthorization(userId, napackName); } foreach (NapackMajorVersion consumedPackage in newNapack.NewNapackVersion.Dependencies) { AddConsumingPackage(consumedPackage, version); } // Add the new napack to all the various stores. NapackStats stats = new NapackStats(); stats.AddVersion(newNapack.NewNapackVersion); searchIndices.Add(version.NapackName, NapackSearchIndex.CreateFromMetadataAndStats(metadata, stats)); statsStore.Add(version.NapackName, stats); packageMetadataStore.Add(version.NapackName, metadata); packageStore.Add(version.GetFullName(), packageVersion); specStore.Add(version.GetFullName(), napackSpec); }
public void SaveNewNapack(string napackName, NewNapack newNapack, NapackSpec napackSpec) { NapackVersionIdentifier version = new NapackVersionIdentifier(napackName, 1, 0, 0); NapackMetadata metadata = NapackMetadata.CreateFromNewNapack(napackName, newNapack); NapackVersion packageVersion = NapackVersion.CreateFromNewNapack(newNapack.NewNapackVersion); foreach (string author in newNapack.NewNapackVersion.Authors) { AddItem(author.ToUpperInvariant(), version, AuthorPackageTable, "authorName", "packageVersionList", false); } foreach (string userId in newNapack.metadata.AuthorizedUserIds) { AddItem(userId.ToUpperInvariant(), napackName, UserPackageTable, "userId", "packageNameList", true); } foreach (NapackMajorVersion consumedPackage in newNapack.NewNapackVersion.Dependencies) { AddItem(consumedPackage.ToString(), version, PackageConsumersTable, "packageMajorVersionId", "consumingPackages", false); } // Add the new napack to all the various stores. NapackStats stats = new NapackStats(); stats.AddVersion(newNapack.NewNapackVersion); ExecuteTransactionCommand((command) => { string statsEncoded = Serializer.Serialize(stats); command.Parameters.Add(napackName); command.Parameters.Add(statsEncoded); command.CommandText = $"INSERT INTO {PackageStatsTable} VALUES ($1, $2)"; command.ExecuteNonQuery(); command.Parameters.Clear(); string metadataEncoded = Serializer.Serialize(metadata); string safeDescriptionAndTags = GetSafeDescriptionAndTags(metadata); command.Parameters.Add(napackName); command.Parameters.Add(safeDescriptionAndTags); command.Parameters.Add(metadataEncoded); command.CommandText = $"INSERT INTO {PackageMetadataTable} VALUES ($1, $2, $3)"; command.ExecuteNonQuery(); command.Parameters.Clear(); string napackSpecEncoded = Serializer.Serialize(napackSpec); command.Parameters.Add(version.GetFullName()); command.Parameters.Add(napackSpecEncoded); command.CommandText = $"INSERT INTO {PackageSpecsTable} VALUES ($1, $2)"; command.ExecuteNonQuery(); command.Parameters.Clear(); string packageVersionEncoded = Serializer.Serialize(packageVersion); command.Parameters.Add(version.GetFullName()); command.Parameters.Add(packageVersionEncoded); command.CommandText = $"INSERT INTO {PackageStoreTable} VALUES ($1, $2)"; command.ExecuteNonQuery(); command.Parameters.Clear(); }); }
private void UpdatePackageMetadataStore(NapackMetadata package, NapackVersionIdentifier nextVersion, NapackAnalyst.UpversionType upversionType, NewNapackVersion newNapackVersion) { if (upversionType == NapackAnalyst.UpversionType.Major) { NapackMajorVersionMetadata newMajorVersionMetadata = new NapackMajorVersionMetadata() { Recalled = false, Versions = new Dictionary <int, List <int> > { [0] = new List <int> { 0 } }, License = newNapackVersion.License }; package.Versions.Add(nextVersion.Major, newMajorVersionMetadata); } else if (upversionType == NapackAnalyst.UpversionType.Minor) { package.Versions[nextVersion.Major].Versions.Add(nextVersion.Minor, new List <int> { 0 }); } else { package.Versions[nextVersion.Major].Versions[nextVersion.Minor].Add(nextVersion.Patch); } ExecuteTransactionCommand((command) => { NapackStats stats = GetItem <NapackStats>(command, PackageStatsTable, "packageName", package.Name, "packageStat", () => { throw new NapackStatsNotFoundException(package.Name); }); stats.AddVersion(newNapackVersion); string statsEncoded = Serializer.Serialize(stats); command.Parameters.Add(statsEncoded); command.Parameters.Add(package.Name); command.CommandText = $"UPDATE {PackageStatsTable} SET packageStat = $1 WHERE packageName = $2"; command.ExecuteNonQuery(); command.Parameters.Clear(); }); UpdatePackageMetadata(package); }