コード例 #1
0
        public async Task <PackageApiModel> PostAsync(string packageName, string packageType, string configType, string version, List <string> tags, IFormFile package)
        {
            if (string.IsNullOrEmpty(packageType))
            {
                throw new InvalidInputException("Package Type must be provided");
            }

            bool isValidPackageType = Enum.TryParse(packageType, true, out PackageType uploadedPackageType);

            if (!isValidPackageType)
            {
                throw new InvalidInputException($"Provided packageType {packageType} is not valid.");
            }

            if (uploadedPackageType.Equals(PackageType.EdgeManifest) && !string.IsNullOrEmpty(configType))
            {
                throw new InvalidInputException($"Package of type EdgeManifest cannot have parameter " +
                                                $"configType.");
            }

            if (configType == null)
            {
                configType = string.Empty;
            }

            if (package == null || package.Length == 0 || string.IsNullOrEmpty(package.FileName))
            {
                throw new InvalidInputException("Package uploaded is missing or invalid.");
            }

            string packageContent;

            using (var streamReader = new StreamReader(package.OpenReadStream()))
            {
                packageContent = await streamReader.ReadToEndAsync();
            }

            if (!PackagesHelper.VerifyPackageType(packageContent, uploadedPackageType))
            {
                throw new InvalidInputException($@"Package uploaded is invalid. Package contents
                            do not match with the given package type {packageType}.");
            }

            var packageToAdd = new PackageApiModel(
                packageContent,
                !string.IsNullOrWhiteSpace(packageName) ? packageName : package.FileName,
                uploadedPackageType,
                version,
                configType,
                tags ?? new List <string>());

            return(new PackageApiModel(await this.storage.AddPackageAsync(packageToAdd.ToServiceModel(), this.GetClaimsUserDetails(), this.GetTenantId())));
        }
コード例 #2
0
        public async Task <ActionResult <PackageApiModel> > RemoveTagsAsync(string id)
        {
            var package = await this.GetAsync(id);

            PackageApiModel modifiedPackage = null;

            foreach (var tag in package.Tags)
            {
                modifiedPackage = (await this.RemoveTagAsync(id, tag)).Value;
            }

            return(modifiedPackage);
        }
        public async Task <PackageApiModel> PostAsync(string packageType, string configType, IFormFile package)
        {
            if (string.IsNullOrEmpty(packageType))
            {
                throw new InvalidInputException("Package Type must be provided");
            }

            bool isValidPackageType = Enum.TryParse(packageType, true, out PackageType uploadedPackageType);

            if (!isValidPackageType)
            {
                throw new InvalidInputException($"Provided packageType {packageType} is not valid.");
            }

            if (uploadedPackageType.Equals(PackageType.EdgeManifest) &&
                !(string.IsNullOrEmpty(configType)))
            {
                throw new InvalidInputException($"Package of type EdgeManifest cannot have parameter " +
                                                $"configType.");
            }

            if (configType == null)
            {
                configType = string.Empty;
            }

            if (package == null || package.Length == 0 || string.IsNullOrEmpty(package.FileName))
            {
                throw new InvalidInputException("Package uploaded is missing or invalid.");
            }

            string packageContent;

            using (var streamReader = new StreamReader(package.OpenReadStream()))
            {
                packageContent = await streamReader.ReadToEndAsync();
            }

            var packageToAdd = new PackageApiModel(
                packageContent,
                package.FileName,
                uploadedPackageType,
                configType);

            return(new PackageApiModel(await this.storage.AddPackageAsync(packageToAdd.ToServiceModel())));
        }
コード例 #4
0
        public IHttpActionResult UpgradeStore([FromBody] PackageApiModel package)
        {
            var result = _business.UpgradeStore(package.ObjectID, package.PackageID);

            return(Ok(result));
        }