/// <summary>
        /// Creates the Azure storage container for the dataset and adds the attachment records
        /// to the nomination document.
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="user"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <NominationStatus?> CreateDatasetStorageAsync(DatasetStorage storage, ClaimsPrincipal user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var docUri  = CreateUserDataDocumentUri(storage.Id);
            var options = new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString())
            };

            Document document = await Client.ReadDocumentAsync(docUri, options);

            if (document == null)
            {
                return(null);
            }

            var containerUri = await SasTokens.CreateDatasetContainer(storage);

            var name   = GetUserName(user);
            var email  = GetUserEmail(user);
            var status = NominationStatus.Uploading;

            document.SetPropertyValue("modified", DateTime.UtcNow);
            document.SetPropertyValue("modifiedByUserName", name);
            document.SetPropertyValue("modifiedByUserEmail", email);
            document.SetPropertyValue("nominationStatus", status.ToString());
            await Client.ReplaceDocumentAsync(document.SelfLink, document);

            var datasetRecordLink = new Attachment
            {
                Id          = "Content", // "Slug" is ID with hard-attach
                ContentType = "x-azure-blockstorage",
                MediaLink   = containerUri,
            };

            datasetRecordLink.SetPropertyValue("storageType", "blob");
            datasetRecordLink.SetPropertyValue("container", storage.ContainerName);
            datasetRecordLink.SetPropertyValue("account", storage.AccountName);

            await Client.UpsertAttachmentAsync(document.SelfLink, datasetRecordLink, options);

            return(status);
        }
Пример #2
0
        public async Task <DatasetEditStorageItem> InitiateDatasetContentEdit(Guid id, IPrincipal user, CancellationToken token)
        {
            var dataset = await GetDatasetEditById(id, user, token);

            if (dataset.EditStatus == DatasetEditStatus.ContentsModified)
            {
                // Already in content edit mode
                return(dataset);
            }

            var details = await DatasetStorage.GetDatasetStorageDetails(id, token);

            var blobDetails = details as DatasetBlobStorageDetails;

            if (blobDetails == null)
            {
                throw new InvalidOperationException("Dataset storage must be blob storage.");
            }

            var datasetStorage = new DatasetStorage
            {
                Id          = dataset.Id,
                DatasetName = dataset.Name,
                AccountName = blobDetails.Account
            };
            await SasTokens.FindUniqueDatasetUpdateContainerName(datasetStorage);

            await SasTokens.CreateDatasetContainer(datasetStorage);

            dataset.EditStatus               = DatasetEditStatus.ContentsModified;
            dataset.ContentEditAccount       = datasetStorage.AccountName;
            dataset.ContentEditContainer     = datasetStorage.ContainerName;
            dataset.OriginalStorageAccount   = blobDetails.Account;
            dataset.OriginalStorageContainer = blobDetails.Container;
            return(await UpdateDatasetEditItemDocument(user, dataset, token));
        }