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; }
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); } } }
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); } } }
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); }