コード例 #1
0
        /// <inheritdoc />
        public async Task UpdateInstaller(string packageIdentifier, string packageVersion, string installerIdentifier, Installer installer)
        {
            // Fetch Current Package
            CosmosDocument <CosmosPackageManifest> cosmosDocument =
                await this.cosmosDatabase.GetByIdAndPartitionKey <CosmosPackageManifest>(packageIdentifier, packageIdentifier);

            // Update Installer
            cosmosDocument.Document.UpdateInstaller(installer, packageVersion);

            // Save Document
            ApiDataValidator.Validate(cosmosDocument.Document);
            await this.cosmosDatabase.Update <CosmosPackageManifest>(cosmosDocument);
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task UpdateVersion(string packageIdentifier, string packageVersion, Version version)
        {
            // Fetch Current Package
            CosmosDocument <CosmosPackageManifest> cosmosDocument =
                await this.cosmosDatabase.GetByIdAndPartitionKey <CosmosPackageManifest>(packageIdentifier, packageIdentifier);

            // Update
            cosmosDocument.Document.Versions.Update(version);

            // Save Package
            ApiDataValidator.Validate(cosmosDocument.Document);
            await this.cosmosDatabase.Update <CosmosPackageManifest>(cosmosDocument);
        }
コード例 #3
0
        /// <inheritdoc />
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // Create Validation Results
            var results = new List <ValidationResult>();

            // Verify Optional Fields
            if (this.Versions != null)
            {
                ApiDataValidator.Validate(this.Versions, results);
            }

            // Return Results
            return(results);
        }
コード例 #4
0
        /// <inheritdoc />
        public async Task AddPackage(Package package)
        {
            // Convert Package to Manifest for storage
            PackageManifest       packageManifest       = new PackageManifest(package);
            CosmosPackageManifest cosmosPackageManifest = new CosmosPackageManifest(packageManifest);

            // Create Document and add to cosmos.
            CosmosDocument <CosmosPackageManifest> cosmosDocument = new CosmosDocument <CosmosPackageManifest>
            {
                Document = cosmosPackageManifest,
            };

            ApiDataValidator.Validate(cosmosDocument.Document);
            await this.cosmosDatabase.Add <CosmosPackageManifest>(cosmosDocument);
        }
コード例 #5
0
        /// <inheritdoc />
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> results = new List <ValidationResult>();

            // Base
            results.AddRange(base.Validate(validationContext));

            // Validate Optional Members
            if (this.Versions != null)
            {
                ApiDataValidator.Validate(this.Versions, results);
            }

            // Return Results
            return(results);
        }
コード例 #6
0
        public async Task <IActionResult> LocalePutAsync(
            [HttpTrigger(
                 AuthorizationLevel.Function,
                 FunctionConstants.FunctionPut,
                 Route = "packages/{packageIdentifier}/versions/{packageVersion}/locales/{packageLocale}")]
            HttpRequest req,
            string packageIdentifier,
            string packageVersion,
            string packageLocale,
            ILogger log)
        {
            Dictionary <string, string> headers = null;
            Locale locale = null;

            try
            {
                // Parse Headers
                headers = HeaderProcessor.ToDictionary(req.Headers);

                // Parse body as package
                locale = await Parser.StreamParser <Locale>(req.Body, log);

                ApiDataValidator.Validate(locale);

                if (locale.PackageLocale != packageLocale)
                {
                    throw new InvalidArgumentException(
                              new InternalRestError(
                                  ErrorConstants.LocaleDoesNotMatchErrorCode,
                                  ErrorConstants.LocaleDoesNotMatchErrorMessage));
                }

                await this.dataStore.UpdateLocale(packageIdentifier, packageVersion, packageLocale, locale);
            }
            catch (DefaultException e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.ProcessError(e.InternalRestError));
            }
            catch (Exception e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.UnhandledError(e));
            }

            return(new ApiObjectResult(new ApiResponse <Locale>(locale)));
        }
コード例 #7
0
        /// <inheritdoc/>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // Create Validation Results
            var results = new List <ValidationResult>();

            // Optional Objects
            if (this.PackageFamilyNames != null)
            {
                ApiDataValidator.Validate(this.PackageFamilyNames, results);
            }

            if (this.ProductCodes != null)
            {
                ApiDataValidator.Validate(this.ProductCodes, results);
            }

            return(results);
        }
コード例 #8
0
        /// <inheritdoc />
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // Create Validation Results
            var results = new List <ValidationResult>();

            // Verify Required Fields
            if (this.DefaultLocale == null)
            {
                results.Add(new ValidationResult($"{nameof(this.DefaultLocale)} in {validationContext.ObjectType} must not be null."));
            }
            else
            {
                ApiDataValidator.Validate(this.DefaultLocale, results);
            }

            // Return Results
            return(results);
        }
コード例 #9
0
        /// <inheritdoc/>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // Create Validation Results
            var results = new List <ValidationResult>();

            // Validate Required Members
            if (this.RequestMatch == null)
            {
                results.Add(new ValidationResult($"{nameof(this.RequestMatch)} in {validationContext.ObjectType} must not be null."));
            }
            else
            {
                ApiDataValidator.Validate(this.RequestMatch, results);
            }

            // Return Results
            return(results);
        }
コード例 #10
0
        public async Task <IActionResult> ManifestPutAsync(
            [HttpTrigger(AuthorizationLevel.Function, FunctionConstants.FunctionPut, Route = "packageManifests/{packageIdentifier}")]
            HttpRequest req,
            string packageIdentifier,
            ILogger log)
        {
            Dictionary <string, string> headers         = null;
            PackageManifest             packageManifest = null;

            try
            {
                // Parse Headers
                headers = HeaderProcessor.ToDictionary(req.Headers);

                // Parse Stream
                packageManifest = await Parser.StreamParser <PackageManifest>(req.Body, log);

                ApiDataValidator.Validate(packageManifest);

                // Validate Versions Match
                if (packageManifest.PackageIdentifier != packageIdentifier)
                {
                    throw new InvalidArgumentException(
                              new InternalRestError(
                                  ErrorConstants.PackageDoesNotMatchErrorCode,
                                  ErrorConstants.PackageDoesNotMatchErrorMessage));
                }

                await this.dataStore.UpdatePackageManifest(packageIdentifier, packageManifest);
            }
            catch (DefaultException e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.ProcessError(e.InternalRestError));
            }
            catch (Exception e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.UnhandledError(e));
            }

            return(new ApiObjectResult(new ApiResponse <PackageManifest>(packageManifest)));
        }
コード例 #11
0
        public async Task <IActionResult> ManifestSearchPostAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, FunctionConstants.FunctionPost, Route = "manifestSearch")]
            HttpRequest req,
            ILogger log)
        {
            Dictionary <string, string>          headers                = null;
            ManifestSearchRequest                manifestSearch         = null;
            ApiDataPage <ManifestSearchResponse> manifestSearchResponse = new ApiDataPage <ManifestSearchResponse>();

            try
            {
                // Parse Headers
                headers = HeaderProcessor.ToDictionary(req.Headers);

                // Get Manifest Search Request and Validate.
                manifestSearch = await Parser.StreamParser <ManifestSearchRequest>(req.Body, log);

                ApiDataValidator.Validate(manifestSearch);

                manifestSearchResponse = await this.dataStore.SearchPackageManifests(manifestSearch, headers, req.Query);
            }
            catch (DefaultException e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.ProcessError(e.InternalRestError));
            }
            catch (Exception e)
            {
                log.LogError(e.ToString());
                return(ActionResultHelper.UnhandledError(e));
            }

            return(manifestSearchResponse.Items.Count() switch
            {
                0 => new NoContentResult(),
                _ => new ApiObjectResult(new ApiResponse <List <ManifestSearchResponse> >(manifestSearchResponse.Items.ToList(), manifestSearchResponse.ContinuationToken)),
            });
コード例 #12
0
        /// <inheritdoc />
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // Create Validation Results
            var results = new List <ValidationResult>();

            // URL Are generally nullable, but not in this instance.
            if (string.IsNullOrEmpty(this.InstallerUrl))
            {
                results.Add(new ValidationResult($"{nameof(this.InstallerUrl)} in {validationContext.ObjectType} must not be null."));
            }

            // Optional Objects
            if (this.Platform != null)
            {
                ApiDataValidator.Validate(this.Platform, results);
            }

            if (this.InstallModes != null)
            {
                ApiDataValidator.Validate(this.InstallModes, results);
            }

            if (this.InstallerSwitches != null)
            {
                ApiDataValidator.Validate(this.InstallerSwitches, results);
            }

            if (this.InstallerSuccessCodes != null)
            {
                ApiDataValidator.Validate(this.InstallerSwitches, results);
            }

            if (this.Commands != null)
            {
                ApiDataValidator.Validate(this.Commands, results);
            }

            if (this.Protocols != null)
            {
                ApiDataValidator.Validate(this.Protocols, results);
            }

            if (this.FileExtensions != null)
            {
                ApiDataValidator.Validate(this.FileExtensions, results);
            }

            if (this.Dependencies != null)
            {
                ApiDataValidator.Validate(this.Dependencies, results);
            }

            if (this.Capabilities != null)
            {
                ApiDataValidator.Validate(this.Capabilities, results);
            }

            if (this.RestrictedCapabilities != null)
            {
                ApiDataValidator.Validate(this.RestrictedCapabilities, results);
            }

            // Return Results
            return(results);
        }