async Task<EditValidationResult> ValidateEdit(Stream metadataStream)
        {
            EditValidationResult result = new EditValidationResult();

            JObject metadata = await ServiceHelpers.ReadJObject(metadataStream);
            if (metadata != null)
            {
                ValidationHelpers.CheckDisallowedEditProperty(metadata, "namespace", result.Errors);
                ValidationHelpers.CheckDisallowedEditProperty(metadata, "id", result.Errors);
                ValidationHelpers.CheckDisallowedEditProperty(metadata, "version", result.Errors);

                if (result.Errors.Count > 0)
                {
                    // the edit request was invalid so don't waste any more cycles on this request 
                    return result;
                }

                result.EditMetadata = metadata;

                JToken catalogEntryAddress;
                if (metadata.TryGetValue("catalogEntry", out catalogEntryAddress))
                {
                    JObject catalogEntry = await CatalogHelpers.LoadFromCatalog(catalogEntryAddress.ToString(), Configuration.StoragePrimary, Configuration.StorageContainerCatalog, Configuration.CatalogBaseAddress);

                    if (catalogEntry != null)
                    {
                        result.CatalogEntry = catalogEntry;
                        result.PackageIdentity = PackageIdentity.FromCatalogEntry(catalogEntry);

                        JToken isListed;
                        if (metadata.TryGetValue("listed", out isListed))
                        {
                            if (isListed.Type != JTokenType.Boolean)
                            {
                                result.Errors.Add("listed must be a boolean value");
                            }
                            else
                            {
                                result.Listed = isListed.ToObject<bool>();
                            }
                        }
                        else
                        {
                            result.Listed = catalogEntry["listed"].ToObject<bool>();
                        }

                        ValidateEdit(result);
                    }
                    else
                    {
                        result.Errors.Add("unable to load catalogEntry");
                    }
                }
                else
                {
                    result.Errors.Add("corresponding catalogEntry must be specified");
                }
            }
            else
            {
                result.Errors.Add("unable to read content as JSON");
            }

            return result;
        }
 static Task<Uri> AddToCatalog(JObject nuspec, Uri itemType, PublicationDetails publicationDetails, bool isListed)
 {
     CatalogItem catalogItem = new GraphCatalogItem(nuspec, itemType, publicationDetails, isListed);
     return CatalogHelpers.AddToCatalog(catalogItem, Configuration.StoragePrimary, Configuration.StorageContainerCatalog, Configuration.CatalogBaseAddress);
 }
Exemplo n.º 3
0
        static Task <Uri> AddToCatalog(PackageIdentity packageIdentity, PublicationDetails publicationDetails)
        {
            CatalogItem catalogItem = new DeleteCatalogItem(packageIdentity, publicationDetails);

            return(CatalogHelpers.AddToCatalog(catalogItem, Configuration.StoragePrimary, Configuration.StorageContainerCatalog, Configuration.CatalogBaseAddress));
        }