public async Task LoadAndPurge()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardVerizon);

            string            cdnEndpointName   = Recording.GenerateAssetName("endpoint-");
            CdnEndpointData   cdnEndpointData   = ResourceDataHelper.CreateEndpointData();
            DeepCreatedOrigin deepCreatedOrigin = new DeepCreatedOrigin("testOrigin")
            {
                HostName = "testsa4dotnetsdk.blob.core.windows.net"
            };

            cdnEndpointData.Origins.Add(deepCreatedOrigin);
            var lro = await cdnProfile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, cdnEndpointName, cdnEndpointData);

            CdnEndpointResource cdnEndpoint     = lro.Value;
            PurgeOptions        purgeParameters = new PurgeOptions(new List <string>
            {
                "/*"
            });

            Assert.DoesNotThrowAsync(async() => await cdnEndpoint.PurgeContentAsync(WaitUntil.Completed, purgeParameters));
            LoadOptions loadParameters = new LoadOptions(new List <string>
            {
                "/testfile/file1.txt"
            });

            Assert.DoesNotThrowAsync(async() => await cdnEndpoint.LoadContentAsync(WaitUntil.Completed, loadParameters));
        }
Exemple #2
0
        public virtual CdnEndpointPurgeContentOperation PurgeContent(PurgeOptions contentFilePaths, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (contentFilePaths == null)
            {
                throw new ArgumentNullException(nameof(contentFilePaths));
            }

            using var scope = _clientDiagnostics.CreateScope("CdnEndpoint.PurgeContent");
            scope.Start();
            try
            {
                var response  = _cdnEndpointsRestClient.PurgeContent(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths, cancellationToken);
                var operation = new CdnEndpointPurgeContentOperation(_clientDiagnostics, Pipeline, _cdnEndpointsRestClient.CreatePurgeContentRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths).Request, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemple #3
0
        private static async Task <int> PurgeAsync(PurgeOptions options)
        {
            try
            {
                // Create service
                var service = DriveServiceHelper.Create(options);

                // Get folder
                var folder = await service.CreateFolderIfNotExistsAsync(options.SharedFolder);

                foreach (var file in await service.ListFilesAsync(null, folder, DateTime.UtcNow.AddDays(-options.Days)))
                {
                    // Delete file
                    await service.DeleteFileAsync(file);
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);

                return(1);
            }
        }
Exemple #4
0
        public void PurgeDeletes(KeyValuePurgeOptions options)
        {
            long dmThresh = options == null
                ? KeyValuePurgeOptions.DefaultThresholdMillis
                : options.DeleteMarkersThresholdMillis;

            DateTime limit;

            if (dmThresh < 0)
            {
                limit = DateTime.UtcNow.AddMilliseconds(600000); // long enough in the future to clear all
            }
            else if (dmThresh == 0)
            {
                limit = DateTime.UtcNow.AddMilliseconds(KeyValuePurgeOptions.DefaultThresholdMillis);
            }
            else
            {
                limit = DateTime.UtcNow.AddMilliseconds(-dmThresh);
            }

            IList <string> noKeepList = new List <string>();
            IList <string> keepList   = new List <string>();

            VisitSubject(KeyValueUtil.ToStreamSubject(BucketName), DeliverPolicy.LastPerSubject, true, false, m =>
            {
                KeyValueEntry kve = new KeyValueEntry(m);
                if (!kve.Operation.Equals(KeyValueOperation.Put))
                {
                    if (kve.Created > limit) // created > limit, so created after
                    {
                        keepList.Add(new BucketAndKey(m).Key);
                    }
                    else
                    {
                        noKeepList.Add(new BucketAndKey(m).Key);
                    }
                }
            });

            foreach (string key in noKeepList)
            {
                jsm.PurgeStream(StreamName, PurgeOptions.WithSubject(RawKeySubject(key)));
            }

            foreach (string key in keepList)
            {
                PurgeOptions po = PurgeOptions.Builder()
                                  .WithSubject(RawKeySubject(key))
                                  .WithKeep(1)
                                  .Build();
                jsm.PurgeStream(StreamName, po);
            }
        }
        public void TestPurgeStreamAndOptions()
        {
            Context.RunInJsServer(c =>
            {
                Assert.Throws <ArgumentException>(() => PurgeOptions.Builder().WithKeep(1).WithSequence(1).Build());

                IJetStreamManagement jsm = c.CreateJetStreamManagementContext();
                Assert.Throws <NATSJetStreamException>(() => jsm.PurgeStream(STREAM));

                CreateMemoryStream(c, STREAM, Subject(1), Subject(2));

                StreamInfo si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(0u, si.State.Messages);

                JsPublish(c, Subject(1), 10);
                si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(10u, si.State.Messages);

                PurgeOptions options = PurgeOptions.Builder().WithKeep(7).Build();
                PurgeResponse pr     = jsm.PurgeStream(STREAM, options);
                Assert.True(pr.Success);
                Assert.Equal(3u, pr.Purged);

                options = PurgeOptions.Builder().WithSequence(9).Build();
                pr      = jsm.PurgeStream(STREAM, options);
                Assert.True(pr.Success);
                Assert.Equal(5u, pr.Purged);
                si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(2u, si.State.Messages);

                pr = jsm.PurgeStream(STREAM);
                Assert.True(pr.Success);
                Assert.Equal(2u, pr.Purged);
                si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(0u, si.State.Messages);

                JsPublish(c, Subject(1), 10);
                JsPublish(c, Subject(2), 10);
                si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(20u, si.State.Messages);
                jsm.PurgeStream(STREAM, PurgeOptions.WithSubject(Subject(1)));
                si = jsm.GetStreamInfo(STREAM);
                Assert.Equal(10u, si.State.Messages);

                options = PurgeOptions.Builder().WithSubject(Subject(1)).WithSequence(1).Build();
                Assert.Equal(Subject(1), options.Subject);
                Assert.Equal(1u, options.Sequence);

                options = PurgeOptions.Builder().WithSubject(Subject(1)).WithKeep(2).Build();
                Assert.Equal(2u, options.Keep);
            });
        }
        public PurgeOptions Decorate()
        {
            var opts = new PurgeOptions
            {
                Email  = FetchOption("Email").Value,
                Domain = ConvertToDomainType(FetchOption("Domain").Value),
                Action = ConvertToActionType(FetchOption("Action").Value),
                Type   = ConvertToPurgeType(FetchOption("Type").Value),
                File   = FetchOption("File").Value
            };

            return(opts);
        }
        private void RequestPurge(PurgeOptions options, string[] arls)
        {
            var results = _purgable.Purge(options, arls);

            foreach (var result in results)
            {
                if (result.resultCode == 100)
                {
                    LogResultSuccess(result);
                }
                else
                {
                    LogResultFailure(result);
                }
            }
        }
Exemple #8
0
        public virtual ArmOperation PurgeContent(bool waitForCompletion, PurgeOptions contentFilePaths, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(contentFilePaths, nameof(contentFilePaths));

            using var scope = _cdnEndpointClientDiagnostics.CreateScope("CdnEndpoint.PurgeContent");
            scope.Start();
            try
            {
                var response  = _cdnEndpointRestClient.PurgeContent(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths, cancellationToken);
                var operation = new CdnArmOperation(_cdnEndpointClientDiagnostics, Pipeline, _cdnEndpointRestClient.CreatePurgeContentRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths).Request, response, OperationFinalStateVia.Location);
                if (waitForCompletion)
                {
                    operation.WaitForCompletionResponse(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemple #9
0
        private static void RunPurge(PurgeOptions options)
        {
            if (!options.Confirm)
            {
                Console.Write($"Do you want to purge the queue '{options.QueueName}'? (Y/N) ");
                var answer = Console.ReadLine();

                if (string.IsNullOrEmpty(answer) || !answer.Equals("Y", StringComparison.CurrentCultureIgnoreCase))
                {
                    return;
                }
            }

            uint messageCount;

            using (var connection = GetConnection(options))
                using (var channel = connection.CreateModel())
                {
                    messageCount = channel.QueuePurge(options.QueueName);
                }

            Console.WriteLine($"{messageCount} message{(messageCount != 1 ? "s" : "")} purged from '{options.QueueName}'.");
        }
Exemple #10
0
        public void CleanJournal(PurgeOptions options)
        {
            long oldPercent = 0;
            IEnumerable <string> userList              = TShock.Users.GetUsers().Select(i => i.Name);
            List <long>          deleteList            = new List <long>();
            JournalLoadingPercentChangedEventArgs args = new JournalLoadingPercentChangedEventArgs()
            {
                Label   = "Purge",
                Percent = 0
            };

            if (JournalLoadingPercentChanged != null)
            {
                JournalLoadingPercentChanged(this, args);
            }

            for (int i = 0; i < this.BankAccounts.Count; i++)
            {
                double       pcc     = (double)i / (double)BankAccounts.Count * 100;
                IBankAccount account = bankAccounts.ElementAtOrDefault(i);

                if ((options & PurgeOptions.RemoveOrphanedAccounts) == PurgeOptions.RemoveOrphanedAccounts &&
                    userList.Contains(account.UserAccountName) == false)
                {
                    if (deleteList.Contains(account.BankAccountK) == false)
                    {
                        deleteList.Add(account.BankAccountK);
                        continue;
                    }
                }

                if ((options & PurgeOptions.RemoveZeroBalanceAccounts) == PurgeOptions.RemoveZeroBalanceAccounts &&
                    (account.Balance <= 0 && account.IsSystemAccount == false))
                {
                    if (deleteList.Contains(account.BankAccountK) == false)
                    {
                        deleteList.Add(account.BankAccountK);
                        continue;
                    }
                }

                if (oldPercent != (int)pcc)
                {
                    args.Percent = (int)pcc;
                    if (JournalLoadingPercentChanged != null)
                    {
                        JournalLoadingPercentChanged(this, args);
                    }
                    oldPercent = (int)pcc;
                }
            }

            if (deleteList.Count > 0)
            {
                args.Label   = "Clean";
                args.Percent = 0;
                for (int i = 0; i < deleteList.Count; i++)
                {
                    double pcc = (double)i / (double)deleteList.Count * 100;

                    DeleteBankAccount(deleteList[i]);

                    if (oldPercent != (int)pcc)
                    {
                        args.Percent = (int)pcc;
                        if (JournalLoadingPercentChanged != null)
                        {
                            JournalLoadingPercentChanged(this, args);
                        }
                        oldPercent = (int)pcc;
                    }
                }
            }
        }
Exemple #11
0
 /// <summary>
 /// Deletes all the items in the offline table that match the query.
 /// </summary>
 /// <typeparam name="U">The type of the data transfer object (DTO) or model that is returned by the query.</typeparam>
 /// <param name="query">An OData query that determines which items to delete.</param>
 /// <param name="options">The options used to configure the purge operation.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
 /// <returns>A task that completes when the purge operation has finished.</returns>
 public Task PurgeItemsAsync <U>(ITableQuery <U> query, PurgeOptions options, CancellationToken cancellationToken = default)
 {
     Arguments.IsNotNull(query, nameof(query));
     return(PurgeItemsAsync(((TableQuery <T>)query).ToODataString(true), options, cancellationToken));
 }
Exemple #12
0
 private int RunPurgeAndReturnExitCode(PurgeOptions opt)
 {
     this.fidx.PurgeIndex();
     this.fidx.SaveIndex();
     return(0);
 }
        public void CleanJournal(PurgeOptions options)
        {
            long oldPercent = 0;
            List<string> userList = TShock.Users.GetUsers().Select(i => i.Name).ToList();
            List<long> deleteList = new List<long>();
            JournalLoadingPercentChangedEventArgs args = new JournalLoadingPercentChangedEventArgs() {
                Label = "Scrub",
                Percent = 0
            };

            if (JournalLoadingPercentChanged != null) {
                JournalLoadingPercentChanged(this, args);
            }

            for (int i = 0; i < this.BankAccounts.Count; i++) {
                double pcc = (double)i / (double)BankAccounts.Count * 100;
                IBankAccount account = this.bankAccounts.ElementAtOrDefault(i);

                if ((options & PurgeOptions.RemoveOrphanedAccounts) == PurgeOptions.RemoveOrphanedAccounts
                    && userList.Contains(account.UserAccountName) == false) {
                    if (deleteList.Contains(account.BankAccountK) == false) {
                        deleteList.Add(account.BankAccountK);
                        userList.Remove(account.UserAccountName);
                        continue;
                    }
                }

                if ((options & PurgeOptions.RemoveZeroBalanceAccounts) == PurgeOptions.RemoveZeroBalanceAccounts
                    && (account.Balance <= 0 && account.IsSystemAccount == false)) {
                    if (deleteList.Contains(account.BankAccountK) == false) {
                        deleteList.Add(account.BankAccountK);
                        continue;
                    }
                }

                if (oldPercent != (int)pcc) {
                    args.Percent = (int)pcc;
                    if (JournalLoadingPercentChanged != null) {
                        JournalLoadingPercentChanged(this, args);
                    }
                    oldPercent = (int)pcc;
                }
            }

            if (deleteList.Count > 0) {
                args.Label = "Clean";
                args.Percent = 0;
                for (int i = 0; i < deleteList.Count; i++) {
                    double pcc = (double)i / (double)deleteList.Count * 100;

                    DeleteBankAccountAsync(deleteList[i]).Wait();

                    if (oldPercent != (int)pcc) {
                        args.Percent = (int)pcc;
                        if (JournalLoadingPercentChanged != null) {
                            JournalLoadingPercentChanged(this, args);
                        }
                        oldPercent = (int)pcc;
                    }
                }
            }
        }
        public async virtual Task <ArmOperation> PurgeContentAsync(bool waitForCompletion, PurgeOptions contentFilePaths, CancellationToken cancellationToken = default)
        {
            if (contentFilePaths == null)
            {
                throw new ArgumentNullException(nameof(contentFilePaths));
            }

            using var scope = _cdnEndpointClientDiagnostics.CreateScope("CdnEndpoint.PurgeContent");
            scope.Start();
            try
            {
                var response = await _cdnEndpointRestClient.PurgeContentAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths, cancellationToken).ConfigureAwait(false);

                var operation = new CdnArmOperation(_cdnEndpointClientDiagnostics, Pipeline, _cdnEndpointRestClient.CreatePurgeContentRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, contentFilePaths).Request, response, OperationFinalStateVia.Location);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }