public override string GetPath()
 {
     return(String.Format(
                "{0}/{1}",
                Id.ToLowerInvariant(),
                SemanticVersionHelper.Normalize(Version).ToLowerInvariant()));
 }
Example #2
0
 private string GetKey(string id, string version)
 {
     return((id + "/" + SemanticVersionHelper.Normalize(version)).ToLower());
 }
Example #3
0
        private async Task DeleteP(List <PackageConfigParser.Package> IdAndVersion)
        {
            var dc = GetDatacenter(0, required: false);

            if (dc != null)
            {
                var defaults = await LoadDefaultsFromAzure(dc, DatabaseConnectionString, StorageConnectionString);

                DatabaseConnectionString = defaults.DatabaseConnectionString;
                StorageConnectionString  = defaults.StorageConnectionString;
            }

            StorageAccount = CloudStorageAccount.Parse(StorageConnectionString);


            // Connect to the database
            using (var conn = new SqlConnection(DatabaseConnectionString))
            {
                await conn.OpenAsync();

                foreach (PackageConfigParser.Package pkg in IdAndVersion)
                {
                    Id      = pkg.Id;
                    Version = pkg.Version;

                    // Parse the version
                    if (!String.IsNullOrWhiteSpace(Version))
                    {
                        Version = SemanticVersionHelper.Normalize(Version);
                    }



                    var packages = conn.Query(@"
                    SELECT
                        p.[Key],
                        p.PackageRegistrationKey,
                        pr.Id,
                        p.NormalizedVersion AS Version, 
                        p.Hash 
                    FROM Packages p
                    INNER JOIN PackageRegistrations pr ON p.PackageRegistrationKey = pr.[Key]
                    WHERE pr.Id = @Id AND (@AllVersions = 1 OR p.NormalizedVersion = @Version)", new
                    {
                        Id,
                        AllVersions,
                        Version
                    });

                    await Console.WriteInfoLine(Strings.Package_DeleteCommand_DeleteList_Header, (dc == null ? "<unknown>" : dc.FullName));

                    foreach (var package in packages)
                    {
                        await Console.WriteInfoLine(
                            Strings.Package_DeleteCommand_DeleteList_Item,
                            (string)package.Id,
                            (string)package.Version);
                    }

                    // Ask the user to confirm by typing the ID
                    if (!WhatIf && !Quiet)
                    {
                        await Console.WriteInfoLine(Strings.Package_DeleteCommand_NonWhatIf);

                        string typed = await Console.Prompt(Strings.Package_DeleteCommand_DeleteList_Confirm);

                        if (!String.Equals(typed, Id, StringComparison.Ordinal))
                        {
                            await Console.WriteErrorLine(Strings.Package_DeleteCommand_IncorrectId, typed);

                            return;
                        }
                    }

                    foreach (var package in packages)
                    {
                        await DeletePackage(package, conn);
                    }

                    if (AllVersions)
                    {
                        await DeleteRegistration(conn);
                    }
                }
            }
        }
Example #4
0
        protected override async Task OnExecute()
        {
            if (String.IsNullOrWhiteSpace(Version) && !All)
            {
                await Console.WriteErrorLine(Strings.Package_AllVersionsRequiredIfVersionNull);

                return;
            }

            // Get Datacenter 0
            var dc = GetDatacenter(0, required: false);

            if (dc != null)
            {
                var defaults = await LoadDefaultsFromAzure(dc, DatabaseConnectionString, StorageConnectionString);

                DatabaseConnectionString = defaults.DatabaseConnectionString;
                StorageConnectionString  = defaults.StorageConnectionString;
            }

            StorageAccount = CloudStorageAccount.Parse(StorageConnectionString);

            // Parse the version
            if (!String.IsNullOrWhiteSpace(Version))
            {
                Version = SemanticVersionHelper.Normalize(Version);
            }

            if (!String.IsNullOrWhiteSpace(Version) && All)
            {
                await Console.WriteErrorLine(Strings.Package_VersionAndAllVersionsSpecified);

                return;
            }

            IEnumerable <dynamic> packages;
            int totalCount;

            // Get all of the packages to be processed
            using (var conn = new SqlConnection(DatabaseConnectionString))
            {
                await conn.OpenAsync();

                var sql = Unsupported ? SqlUnsupportedPackages : SqlAllPackages;

                await Console.WriteInfoLine("Getting the list of packages to process from SQL.{0}", Unsupported? " Filtering to those containing an 'Unsupported' framework." : "");

                packages = conn.Query(sql, new
                {
                    Id,
                    All,
                    Version
                });

                totalCount = packages.Count();
                await Console.WriteInfoLine("Found {0} package(s) to process", totalCount);
            }

            if (!WhatIf)
            {
                bool confirmed = await Console.Confirm(
                    String.Format(
                        Strings.Package_PopulatePackageFrameworksCommand_Confirm,
                        packages.Count(),
                        (dc == null ? "<unknown>" : dc.FullName)),
                    defaultValue : true);

                if (!confirmed)
                {
                    await Console.WriteErrorLine(Strings.SystemConsole_ConfirmDenied);

                    return;
                }
            }

            int processedCount = 0;

            packages
            .AsParallel()
            .AsOrdered()
            // Use 2 threads per processor, because we might find ourselves
            // waiting on SQL
            .WithDegreeOfParallelism(System.Environment.ProcessorCount * 2)
            .ForAll(package =>
            {
                var thisPackageId = Interlocked.Increment(ref processedCount);
                ProcessPackage(package, thisPackageId, totalCount);
            });
        }