Exemplo n.º 1
0
        public async Task ClearAsync(bool deleteUserBuckets)
        {
            try
            {
                _logger.LogInformation($"Deleting anonymous user bucket {_bucket.BucketKey}");
                await _bucket.DeleteAsync();

                // We need to wait because the server needs some time to settle down. If we try to create the bucket again immediately we'll get a conflict error.
                await Task.Delay(4000);
            }
            catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound)
            {
                _logger.LogInformation($"Nothing to delete because bucket {_bucket.BucketKey} does not exist yet");
            }

            if (deleteUserBuckets)
            {
                _logger.LogInformation($"Deleting user buckets for registered users");
                // delete all user buckets
                var buckets = await _bucket.GetBucketsAsync();

                string userBucketPrefix = _bucketPrefixProvider.GetBucketPrefix();
                foreach (string bucket in buckets)
                {
                    if (bucket.Contains(userBucketPrefix))
                    {
                        _logger.LogInformation($"Deleting user bucket {bucket}");
                        await _bucket.DeleteBucketAsync(bucket);
                    }
                }
            }

            // delete bundles and activities
            await _fdaClient.CleanUpAsync();

            // cleanup locally cached files but keep the directory as it is initialized at the start of the app and needed to run the web server
            Directory.EnumerateFiles(_localCache.LocalRootName).ToList().ForEach((string filePath) => File.Delete(filePath));
            Directory.EnumerateDirectories(_localCache.LocalRootName).ToList().ForEach((string dirPath) => Directory.Delete(dirPath, true));
        }
        public async Task ClearAsync(bool deleteUserBuckets)
        {
            try
            {
                _logger.LogInformation($"Deleting anonymous user bucket {_bucket.BucketKey}");
                await _bucket.DeleteAsync();

                // We need to wait because server needs some time to settle it down. If we would go and create bucket immediately again we would receive conflict.
                await Task.Delay(4000);
            }
            catch (ApiException e) when(e.ErrorCode == StatusCodes.Status404NotFound)
            {
                _logger.LogInformation($"Nothing to delete because bucket {_bucket.BucketKey} does not exists yet");
            }

            if (deleteUserBuckets)
            {
                _logger.LogInformation($"Deleting user buckets for registered users");
                // delete all user buckets
                var buckets = await _bucket.GetBucketsAsync();

                string userBucketPrefix = _userResolver.GetBucketPrefix();
                foreach (string bucket in buckets)
                {
                    if (bucket.Contains(userBucketPrefix))
                    {
                        _logger.LogInformation($"Deleting user bucket {bucket}");
                        await _bucket.DeleteBucketAsync(bucket);
                    }
                }
            }

            // delete bundles and activities
            await _fdaClient.CleanUpAsync();

            // cleanup locally cached files
            Directory.Delete(_localCache.LocalRootName, true);
        }