예제 #1
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
                });
            }
        }
예제 #2
0
        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)
                        };
                        manifest = _repository.AddPackage(package);

                        _installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);
                    }
                    finally
                    {
                        _tempPackager.Dispose();
                    }

                    var json = new JavaScriptSerializer().Serialize(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 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,
                            AnalyzeOnly           = uploadPackage.AnalyzeOnly,
                            SummeryOnly           = uploadPackage.SummeryOnly,
                            Version               = uploadPackage.Version
                        };
                        manifest = _repository.AddPackage(package);

                        if (!uploadPackage.AnalyzeOnly)
                        {
                            _installationRecorder.RecordInstall(uploadPackage.PackageId, uploadPackage.Description, DateTime.Now);
                        }
                    }
                    finally
                    {
                        _tempPackager.Dispose();
                    }

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

                    var json = Json.Encode(new { manifest.ManifestReport });
                    JsonResponse(json, manifest.ManifestReport.ErrorOccured, manifest.ManifestReport.WarningOccured, context);

                    context.Response.AddHeader("Location", ShipServiceUrl.PackageLatestVersion);
                }
                catch (NotFoundException)
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                }
            }
            else if (Successor != null)
            {
                Successor.HandleRequest(context);
            }
        }