Example #1
0
        async Task DownloadFileFromObject(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.DownloadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + tableName.ToString() + ".txt"), tableName.ToString() + ".txt", cancelTokenSource.Token, 0);
        }
Example #2
0
        private void ObjectDownload(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.DownloadObjectAsync(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 #3
0
        async Task DownloadFileFromObject(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.DownloadObjectAsync(bucketName, Path.Combine(AppDomain.CurrentDomain.BaseDirectory + key + ".txt"), key + ".txt", cancelTokenSource.Token, 0);
        }
Example #4
0
        public async Task <bool> IsServerHealthHistoryNormal(string serverName)
        {
            bool result = false;

            try
            {
                string filePath = @"heartBeat/" + serverName;
                List <TBL_HEALTH_INFO> tbl_health_infos = new List <TBL_HEALTH_INFO>();

                string bucketName = config.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),
                    config.GetValue(Category.Backup, Key.ObjectStorageServiceUrl));

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

                await o.DownloadObjectAsync(
                    bucketName
                    , Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"/" + filePath + @"/" + "TBL_HEALTH_INFO" + ".txt")
                    , filePath + @"/" + "TBL_HEALTH_INFO" + ".txt", cancelTokenSource.Token, 0
                    );

                string json = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + filePath + @"/TBL_HEALTH_INFO.txt"));

                if (json.Length > 0)
                {
                    tbl_health_infos.Clear();

                    var TBL_HEALTH_INFOS = JsonConvert.DeserializeObject <List <KeyValuePair <TBL_HEALTH_INFO_KEY, TBL_HEALTH_INFO_VALUE> > >(json);

                    if (!int.TryParse(config.GetValue(Category.Ha, Key.HeartBeatTimeLimitSec), out int HeartBeatTimeLimitSec))
                    {
                        HeartBeatTimeLimitSec = 60;
                    }

                    if (TBL_HEALTH_INFOS.Count() > 0)
                    {
                        long cutTime = long.Parse(DateTime.Now.Add(new TimeSpan(0, 0, Math.Abs(HeartBeatTimeLimitSec) * -1)).ToString("yyyyMMddHHmmss"));
                        foreach (var a in TBL_HEALTH_INFOS)
                        {
                            if (!long.TryParse(a.Key.time, out long storedTime))
                            {
                                storedTime = 0;
                            }

                            if (cutTime < storedTime)
                            {
                                if (a.Value.healthInfo.Equals("normal", StringComparison.OrdinalIgnoreCase))
                                {
                                    tbl_health_infos.Add(new TBL_HEALTH_INFO
                                    {
                                        serverName = a.Key.serverName,
                                        time       = a.Key.time,
                                        healthInfo = a.Value.healthInfo
                                    });
                                    result = true;
                                }
                            }
                        }
                        if (tbl_health_infos.Count() == 0)
                        {
                            log.Warn($"IsServerHealthHistoryNormal read health count : {TBL_HEALTH_INFOS.Count()}, normal count : {tbl_health_infos.Count()}");
                        }
                    }
                    else
                    {
                        log.Warn($"IsServerHealthHistoryNormal failed : {serverName}");
                    }
                }
                else
                {
                    log.Warn($"IsServerHealthHistoryNormal failed : {serverName}");
                }
            }
            catch (Exception ex)
            {
                log.Error($@"IsServerHealthHistoryNormal failed : {ex.Message}, {ex.StackTrace}");
            }

            return(result);
        }