Example #1
0
        private async Task PurgeObjectStorage(string path, int purgeLimitSec)
        {
            ObjectStorage o = new ObjectStorage(
                LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey)
                , LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey)
                , config.GetValue(Category.Backup, Key.ObjectStorageServiceUrl)
                );

            var task  = o.List(bucketName, path);
            var files = await task;

            foreach (var file in files)
            {
                DateTime.TryParseExact(file.LastWriteTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date);
                string   filenameWithExtention = file.Name.Replace(".full", "");
                string   filename      = filenameWithExtention.Replace(".log", "");
                string[] splitfilename = filename.Split(new string[] { "__" }, StringSplitOptions.None);
                if (splitfilename.Count() == 3)
                {
                    if (date < DateTime.Now.Add(new TimeSpan(0, 0, Math.Abs(purgeLimitSec) * -1)))
                    {
                        var   task2 = o.DeleteFileAsync(bucketName, file.Name);
                        await task2;
                    }
                }
            }
        }