コード例 #1
0
        private async Task<HttpResponseMessage> ProcessPackage(Stream stream, string stageOwner, string stageName, string packageOwner)
        {
            Uri nupkgLocation = null;
            Uri nuspecLocation = null;
            PackageStorageBase storage = null;
            bool storageSaveSuccess = false;
            bool tryStorageCleanup = false;
            HttpResponseMessage response;

            try
            {
                var package = StagePackage.ReadFromStream(stream);

                if (package.IsValid)
                {
                    Uri baseAddress = Utils.CreateBaseAddress(Request.RequestUri, "stage/");

                    //TODO: currently the Location is storage URI to the blob, it might be more flexible to make this the blob name

                    storage = new AzurePackageStorage();
                    nupkgLocation = await storage.Save(stream, package.GetNupkgName(storage.Root), package.GetNupkgName(string.Empty), "application/octet-stream");
                    nuspecLocation = await storage.Save(package.NuspecStream, package.GetNuspecName(storage.Root), package.GetNuspecName(string.Empty), "text/xml");

                    storageSaveSuccess = true;

                    response = await Persistence.CreatePackage(baseAddress, stageOwner, stageName, package.Id, package.Version, packageOwner, nupkgLocation, nuspecLocation);

                    if (response.StatusCode != HttpStatusCode.Created)
                    {
                        tryStorageCleanup = true;
                    }
                }
                else
                {
                    response = Utils.CreateErrorResponse(HttpStatusCode.BadRequest, package.Reason);
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                tryStorageCleanup = true;
                response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }

            if (storageSaveSuccess && tryStorageCleanup)
            {
                try
                {
                    await storage.Delete(nupkgLocation);
                    await storage.Delete(nuspecLocation);
                }
                catch (Exception e)
                {
                    Trace.TraceWarning(e.Message);
                }
            }

            return response;
        }
コード例 #2
0
        public static async Task CleanUpArtifacts(List <Uri> artifacts)
        {
            PackageStorageBase storage = new AzurePackageStorage();

            foreach (var artifact in artifacts)
            {
                try
                {
                    await storage.Delete(artifact);
                }
                catch (Exception e)
                {
                    Trace.TraceWarning(e.Message);
                }
            }
        }
コード例 #3
0
ファイル: Utils.cs プロジェクト: NuGet/Entropy
 public static async Task CleanUpArtifacts(List<Uri> artifacts)
 {
     PackageStorageBase storage = new AzurePackageStorage();
     foreach (var artifact in artifacts)
     {
         try
         {
             await storage.Delete(artifact);
         }
         catch (Exception e)
         {
             Trace.TraceWarning(e.Message);
         }
     }
 }
コード例 #4
0
        private async Task <HttpResponseMessage> ProcessPackage(Stream stream, string stageOwner, string stageName, string packageOwner)
        {
            Uri nupkgLocation          = null;
            Uri nuspecLocation         = null;
            PackageStorageBase storage = null;
            bool storageSaveSuccess    = false;
            bool tryStorageCleanup     = false;
            HttpResponseMessage response;

            try
            {
                var package = StagePackage.ReadFromStream(stream);

                if (package.IsValid)
                {
                    Uri baseAddress = Utils.CreateBaseAddress(Request.RequestUri, "stage/");

                    //TODO: currently the Location is storage URI to the blob, it might be more flexible to make this the blob name

                    storage       = new AzurePackageStorage();
                    nupkgLocation = await storage.Save(stream, package.GetNupkgName(storage.Root), package.GetNupkgName(string.Empty), "application/octet-stream");

                    nuspecLocation = await storage.Save(package.NuspecStream, package.GetNuspecName(storage.Root), package.GetNuspecName(string.Empty), "text/xml");

                    storageSaveSuccess = true;

                    response = await Persistence.CreatePackage(baseAddress, stageOwner, stageName, package.Id, package.Version, packageOwner, nupkgLocation, nuspecLocation);

                    if (response.StatusCode != HttpStatusCode.Created)
                    {
                        tryStorageCleanup = true;
                    }
                }
                else
                {
                    response = Utils.CreateErrorResponse(HttpStatusCode.BadRequest, package.Reason);
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                tryStorageCleanup = true;
                response          = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }

            if (storageSaveSuccess && tryStorageCleanup)
            {
                try
                {
                    await storage.Delete(nupkgLocation);

                    await storage.Delete(nuspecLocation);
                }
                catch (Exception e)
                {
                    Trace.TraceWarning(e.Message);
                }
            }

            return(response);
        }