public override void HandleRequest(HttpContextBase context)
        {
            if (CanHandle(context))
            {
                try
                {
                    if (context.Request.Files.Count == 0)
                    {
                        context.Response.StatusCode = (int) HttpStatusCode.BadRequest;
                    }

                    var file = context.Request.Files[0];

                    var uploadPackage = GetRequest(context.Request);

                    PackageManifest manifest;
                    try
                    {
                        var package = new InstallPackage
                        {
                            Path = _tempPackager.GetPackageToInstall(file.InputStream),
                            DisableIndexing = uploadPackage.DisableIndexing,
                            EnableSecurityInstall = uploadPackage.EnableSecurityInstall
                        };
                        manifest = _repository.AddPackage(package);

                        _installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);

                    }
                    finally
                    {
                        _tempPackager.Dispose();
                    }

                    foreach (var entry in manifest.Entries)
                    {
                        if (entry.ID.HasValue)
                        {
                            _publishService.AddToPublishQueue(entry.ID.Value);
                        }
                    }

                    var json = Json.Encode(new { manifest.Entries });

                    JsonResponse(json, HttpStatusCode.Created, context);

                    context.Response.AddHeader("Location", ShipServiceUrl.PackageLatestVersion);                       
                }
                catch (NotFoundException)
                {
                    context.Response.StatusCode = (int) HttpStatusCode.NotFound;
                }
            }
            else if (Successor != null)
            {
                Successor.HandleRequest(context);
            }
        }
        public static Response AsNewPackage(this IResponseFormatter formatter, InstallPackage package, PackageManifest manifest)
        {
            string fileName = Path.GetFileName(package.Path);
            string url = string.Format("{0}/{1}", formatter.Context.Request.Url, fileName);

            return new Response
                       {
                           StatusCode = HttpStatusCode.Created
                       }
                .WithHeader("Location", url);
        }
예제 #3
0
        private dynamic InstallUploadPackage(dynamic o)
        {
            try
            {
                var file = Request.Files.FirstOrDefault();

                var uploadPackage = this.Bind<InstallUploadPackage>();

                if (file == null)
                {
                    return new Response {StatusCode = HttpStatusCode.BadRequest};
                }

                PackageManifest manifest;
                try
                {
                    var package = new InstallPackage
                                      {
                                          Path = _tempPackager.GetPackageToInstall(file.Value), 
                                          DisableIndexing = uploadPackage.DisableIndexing,
                                          EnableSecurityInstall = uploadPackage.EnableSecurityInstall
                                      };
                    manifest = _repository.AddPackage(package);
                    _installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);
                }
                finally 
                {
                    _tempPackager.Dispose();
                }

                if (uploadPackage.DisableManifest)
                {
                    // Skip manifest reporting. Nancy will return an empty message body.
                    manifest = null;
                }

                return Response
                            .AsJson(manifest, HttpStatusCode.Created)
                            .WithHeader("Location", ShipServiceUrl.PackageLatestVersion);
            }
            catch (NotFoundException)
            {
                return new Response
                {
                    StatusCode = HttpStatusCode.NotFound
                };
            }
        }
예제 #4
0
 public PackageManifest AddPackage(InstallPackage package)
 {
     return _packageRunner.Execute(package.Path, package.DisableIndexing);
 }