Exemple #1
0
 /// <summary>
 /// Save package on package consumers
 /// </summary>
 /// <param name="context">The database context to use</param>
 /// <param name="packageConsummer">The package consumer there and packages</param>
 /// <param name="packagesName">All packagename to add to packageConsumer</param>
 /// <param name="packageCache">All packages already find in database or just created. The key is {PackageId}/{Version}</param>
 /// <param name="token">The token, to cancel the processing</param>
 private void SavePackageInPackageConsumer(DataContext context, PackageConsumer packageConsummer, IEnumerable <PackageName> packagesName, IDictionary <string, Package> packageCache, CancellationToken token = default)
 {
     foreach (var packageName in packagesName)
     {
         token.ThrowIfCancellationRequested();
         // Search package in cache
         packageCache.TryGetValue(packageName.GetSerialized(), out var packageInDatabase);
         // Search package in database
         packageInDatabase = packageInDatabase ?? context.Packages.Where(p => p.PackageId == packageName.PackageId && p.Version == packageName.Version).FirstOrDefault();
         if (packageInDatabase == null)
         {
             // Create a package
             packageInDatabase = GetPackageWithMetadata(packageName, token);
             context.Packages.Add(packageInDatabase);
         }
         // Add package in cache
         packageCache.TryAdd(packageName.GetSerialized(), packageInDatabase);
         var packageReference = new PackageConsumerPackage()
         {
             Package = packageInDatabase, PackageConsumer = packageConsummer
         };
         packageConsummer.Packages.Add(packageReference);
         context.PackageConsumerPackages.Add(packageReference);
         context.PackageConsumer.Add(packageConsummer);
     }
 }
Exemple #2
0
 /// <summary>
 /// Transform <see cref="PackageConsumer"/> to <see cref="PackageConsumerDto"/>
 /// </summary>
 public static PackageConsumerDto ToDto(this PackageConsumer packageConsumer)
 {
     if (packageConsumer == null)
     {
         return(null);
     }
     return(new PackageConsumerDto()
     {
         name = packageConsumer.Name,
         projectId = packageConsumer.ProjectId,
     });
 }
Exemple #3
0
        /// <summary>
        /// Save in the project, all package consumers found
        /// And search Metadata of all unkonwn packages
        /// </summary>
        private void SavePackageConsumers(ICollection <PackageConsumerName> packageConsumerNames, DataContext context, SOUPSearchProject project, CancellationToken token)
        {
            var packageCache = new Dictionary <string, Package>(StringComparer.OrdinalIgnoreCase);
            // Add new packages found
            List <PackageConsumer> consumers = new List <PackageConsumer>();

            foreach (var packageConsumerName in packageConsumerNames)
            {
                var packageConsummer = new PackageConsumer()
                {
                    Project  = project,
                    Packages = new List <PackageConsumerPackage>(),
                    Name     = packageConsumerName.Name
                };
                consumers.Add(packageConsummer);
                SavePackageInPackageConsumer(context, packageConsummer, packageConsumerName.Packages, packageCache, token);
            }
        }