Example #1
0
        public void CopyBackup2ObjectStorage()
        {
            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

            try
            {
                if (Path.Substring(Path.Length - 1).Equals(@"\"))
                {
                    Path = Path.Substring(0, Path.Length - 1);
                }

                if (!Directory.Exists(Path))
                {
                    Directory.CreateDirectory(Path);
                }

                foreach (var a in targets)
                {
                    try
                    {
                        string localFileFullname  = Path + @"\" + a.BACKUP_FILE_NAME;
                        string remoteFileFullname = $@"backup/{config.GetServerName()}/" + a.BACKUP_FILE_NAME;
                        currentBackupFileName = localFileFullname;
                        if (!int.TryParse(config.GetValue(Category.Backup, Key.ObjectStorageBandWidthThrottleSleepMiliSec), out int sleepMiliSec))
                        {
                            sleepMiliSec = 0;
                        }

                        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)
                            );
                        o.UploadProgressEvent += ProgressLog;
                        o.UploadObjectAsync(bucketName, localFileFullname, remoteFileFullname, cancelTokenSource.Token, sleepMiliSec).Wait();
                        if (!IsRunning)
                        {
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Warn($"objectStorage Upload Error filename : {currentBackupFileName}, exception info : {ex.Message}, {ex.StackTrace}");
                    }
                }
            }
            catch (Exception ex)
            {
                log.Warn($"objectStorage Upload Error filename : {currentBackupFileName}, exception info : {ex.Message}, {ex.StackTrace}");
            }
            finally
            {
                log.Warn($"objectStorage Upload Completed filename : {currentBackupFileName}");
            }
        }
Example #2
0
        async Task UploadFileToObject(TableName tableName)
        {
            string bucketName = data.GetValue(DataManager.Category.ObjectStorage, DataManager.Key.Bucket);

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
            ObjectStorage           o = new ObjectStorage(
                LogClient.Config.Instance.GetValue(Category.Api, Key.AccessKey),
                LogClient.Config.Instance.GetValue(Category.Api, Key.SecretKey),
                data.GetValue(DataManager.Category.ObjectStorage, DataManager.Key.Endpoint));

            await o.UploadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + tableName.ToString() + ".txt"), tableName.ToString() + ".txt", cancelTokenSource.Token, 0);
        }
Example #3
0
        async Task IfNotExistsCreateTableInObject(TableName tableName, string filePath = "")
        {
            string bucketName = data.GetValue(Category.Backup, Key.BucketName);

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
            ObjectStorage           o = new ObjectStorage(
                LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey),
                LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey),
                data.GetValue(Category.Backup, Key.ObjectStorageServiceUrl));

            string key = string.Empty;

            if (filePath.Trim().Length > 0)
            {
                if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + filePath))
                {
                    Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + filePath);
                }

                key = filePath + @"/" + tableName.ToString();
            }
            else
            {
                key = tableName.ToString();
            }


            var fileListTask = o.List(bucketName, key + ".txt");
            List <ObjectStorageFile> lists = await fileListTask;


            bool isFileEmpty = false;

            foreach (var a in lists)
            {
                if (a.Length == 0)
                {
                    isFileEmpty = true;
                }
            }

            if (lists.Count() == 0 || isFileEmpty)
            {
                string json = "[]";
                File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + key + ".txt"), json);
                await o.UploadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + key + ".txt"), key + ".txt", cancelTokenSource.Token, 0);
            }
        }
Example #4
0
        private async void UpLoadFile2ObjectStorage(string folder, bool publicReadTrueOrFalse = false)
        {
            uploadCancellationTokenSources = new List <CancellationTokenSource>();
            List <Task> tasks = new List <Task>();

            string[] files = Directory.GetFiles(folder);
            foreach (string f in files)
            {
                CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
                uploadCancellationTokenSources.Add(cancelTokenSource);
                ObjectStorage o = new ObjectStorage(
                    logClientConfig.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey),
                    logClientConfig.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey),
                    dataManager.GetValue(DataManager.Category.ObjectStorage, DataManager.Key.Endpoint)
                    );
                tasks.Add(o.UploadObjectAsync(Bucket, Path.GetFullPath(f), Path.GetFileName(f), cancelTokenSource.Token, 0, publicReadTrueOrFalse));
            }
            await Task.WhenAll(tasks);
        }
Example #5
0
        async Task IfNotExistsCreateTableInObject(TableName tableName)
        {
            string bucketName = data.GetValue(DataManager.Category.ObjectStorage, DataManager.Key.Bucket);

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
            ObjectStorage           o = new ObjectStorage(
                LogClient.Config.Instance.GetValue(Category.Api, Key.AccessKey),
                LogClient.Config.Instance.GetValue(Category.Api, Key.SecretKey),
                data.GetValue(DataManager.Category.ObjectStorage, DataManager.Key.Endpoint));

            var fileListTask = o.List(bucketName, tableName.ToString());
            List <ObjectStorageFile> lists = await fileListTask;

            if (lists.Count() == 0)
            {
                string json = "[]";
                File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + tableName.ToString() + ".txt"), json);
                await o.UploadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + tableName.ToString() + ".txt"), tableName.ToString() + ".txt", cancelTokenSource.Token, 0);
            }
        }
Example #6
0
        private void ObjectUpload(string accessKey, string secretKey, string serviceUrl, string bucketName, string localFileFullname, string remoteFileFullname)
        {
            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

            try
            {
                string        filename = Path.GetFileName(localFileFullname);
                ObjectStorage o        = new ObjectStorage(accessKey, secretKey, serviceUrl);
                o.UploadProgressEvent += ProgressBar;
                o.UploadObjectAsync(bucketName, localFileFullname, remoteFileFullname, cancelTokenSource.Token, 0).Wait();
            }
            catch (Exception ex)
            {
                Common.FileLogWriteLine(logFileFullname, $"exception info : {ex.Message}, {ex.StackTrace}");
            }
            finally
            {
                Common.FileLogWriteLine(logFileFullname, "async cmd completed");
            }
        }
Example #7
0
        async Task UploadFileToObject(TableName tableName, string filePath = "")
        {
            string bucketName = data.GetValue(Category.Backup, Key.BucketName);

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
            ObjectStorage           o = new ObjectStorage(
                LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.AccessKey),
                LogClient.Config.Instance.GetValue(LogClient.Category.Api, LogClient.Key.SecretKey),
                data.GetValue(Category.Backup, Key.ObjectStorageServiceUrl));


            string key = string.Empty;

            if (filePath.Trim().Length > 0)
            {
                key = filePath + @"/" + tableName.ToString();
            }
            else
            {
                key = tableName.ToString();
            }

            await o.UploadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + key + ".txt"), key + ".txt", cancelTokenSource.Token, 0);
        }