Esempio n. 1
0
        public async Task <bool> CleanUpDatasetEditAfterImport(Guid datasetId)
        {
            // Update Azure Search with the latest document
            await DatasetStorage.UpdateDatasetDetailsInSearchIndex(datasetId, default);

            // Retreive the dataset edit record (if present)
            var dataset = (await Client.CreateDocumentQuery <DatasetEditStorageItem>(
                               UserDataDocumentCollectionUri,
                               new FeedOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            })
                           .Where(d => d.Id == datasetId)
                           .AsDocumentQuery()
                           .GetQueryResultsAsync())
                          .SingleOrDefault();

            if (dataset == null)
            {
                return(false);
            }

            // Delete the original dataset container (if applicable)
            if (
                dataset.EditStatus == DatasetEditStatus.Importing &&
                !string.IsNullOrWhiteSpace(dataset.OriginalStorageAccount) &&
                !string.IsNullOrWhiteSpace(dataset.OriginalStorageContainer)
                )
            {
                await SasTokens.DeleteDatasetContainer(new DatasetStorage
                {
                    Id            = dataset.Id,
                    DatasetName   = dataset.Name,
                    AccountName   = dataset.OriginalStorageAccount,
                    ContainerName = dataset.OriginalStorageContainer,
                });
            }

            // Delete the edit record
            await Client.DeleteDocumentAsync(
                UserDataDocumentUriById(datasetId.ToString()),
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            },
                default);

            return(true);
        }
Esempio n. 2
0
        public async Task <bool> CancelDatasetChanges(Guid id, IPrincipal user, CancellationToken token)
        {
            var(original, modified) = await VerifyDatasetOwnership(id, user, token);

            if (original == null)
            {
                throw new InvalidOperationException("Invalid dataset id.");
            }

            var status = modified?.EditStatus ?? DatasetEditStatus.Unmodified;

            if (!(status == DatasetEditStatus.DetailsModified || status == DatasetEditStatus.ContentsModified))
            {
                return(false);
            }

            await Client.DeleteDocumentAsync(
                UserDataDocumentUriById(id.ToString()),
                new RequestOptions
            {
                PartitionKey = new PartitionKey(WellKnownIds.DatasetEditDatasetId.ToString())
            },
                token);

            if (modified.EditStatus == DatasetEditStatus.ContentsModified)
            {
                var datasetStorage = new DatasetStorage
                {
                    Id            = id,
                    DatasetName   = original.Name,
                    AccountName   = modified.ContentEditAccount,
                    ContainerName = modified.ContentEditContainer,
                };

                await SasTokens.DeleteDatasetContainer(datasetStorage);
            }

            return(true);
        }