/// <summary>
 /// 上传文件到OSS
 /// </summary>
 /// <param name="file">文件内存流</param>
 /// <param name="key">Key</param>
 /// <param name="bucketName">存储空间(Bucket)名称</param>
 /// <param name="bucketType">存储空间(Bucket)类型</param>
 /// <returns></returns>
 /// <Author>旷丽文</Author>
 public PutObjectResult PutFile(Stream file, string key, string bucketName, BucketType bucketType)
 {
     if (file == null)
     {
         throw new Exception("文件为空");
     }
     if (key.IsNullOrWhiteSpace())
     {
         throw new Exception("Key不能为空");
     }
     if (bucketName.IsNullOrWhiteSpace())
     {
         throw new Exception("bucket不能为空");
     }
     try
     {
         key        = key.Trim();
         bucketName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{bucketName}".ToLower();
         var result = this.Client.PutObject(bucketName, key, file);
         return(result);
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
     finally
     {
         file.Close();
         file.Dispose();
     }
 }
 /// <summary>
 /// 创建一个新的存储空间(Bucket)
 /// 不要平凡的创建存储空间
 /// </summary>
 /// <param name="bucketName">存储控件的名称,该名称一定要唯一</param>
 /// <param name="bucketType">存储空间类型</param>
 /// <returns>创建成功的话, 返回Bucket对象, 否则返回null</returns>
 public Bucket CreateBucket(string bucketName, BucketType bucketType)
 {
     if (bucketName.IsNullOrWhiteSpace())
     {
         throw new Exception("bucket不能为空");
     }
     try
     {
         var exist = this.BucketExist(bucketName, bucketType);
         if (exist == null)
         {
             throw new Exception("创建失败");
         }
         if ((bool)exist)
         {
             throw new Exception("该Bucket已经存在, 请更换名称");
         }
         bucketName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{bucketName}".ToLower();
         return(this.Client.CreateBucket(bucketName));
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
 }
 /// <summary>
 /// 上传字符串到OSS
 /// </summary>
 /// <param name="value">字符串值</param>
 /// <param name="key">Key</param>
 /// <param name="bucketName">存储空间(Bucket)名称</param>
 /// <param name="bucketType">存储空间(Bucket)类型</param>
 /// <returns></returns>
 /// <Author>旷丽文</Author>
 public PutObjectResult PutString(string value, string key, string bucketName, BucketType bucketType)
 {
     if (value.IsNullOrWhiteSpace())
     {
         throw new Exception("字符串不能为空");
     }
     if (key.IsNullOrWhiteSpace())
     {
         throw new Exception("Key不能为空");
     }
     if (bucketName.IsNullOrWhiteSpace())
     {
         throw new Exception("bucket不能为空");
     }
     value = value.Trim();
     try
     {
         key        = key.Trim();
         bucketName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{bucketName}".ToLower();
         byte[]       binaryData     = Encoding.ASCII.GetBytes(value);
         MemoryStream requestContent = new MemoryStream(binaryData);
         var          result         = this.Client.PutObject(bucketName, key, requestContent);
         requestContent.Close();
         requestContent.Dispose();
         return(result);
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
 }
 /// <summary>
 /// 获得所有的存储空间(Bucket)
 /// </summary>
 /// <returns>失败返回null</returns>
 /// <Author>旷丽文</Author>
 public IEnumerable <Bucket> GetListBuckets()
 {
     try
     {
         return(this.Client.ListBuckets());
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
 }
 /// <summary>
 /// 设置存储空间的访问权限
 /// </summary>
 /// <param name="buckteName">存储空间的名称</param>
 /// <param name="bucketType">存储空间(Bucket)类型</param>
 public void SetBucketAcl(string buckteName, BucketType bucketType)
 {
     try
     {
         buckteName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{buckteName}".ToLower();
         // 指定Bucket ACL为公共读
         this.Client.SetBucketAcl(buckteName, CannedAccessControlList.PublicRead);
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
     }
 }
 /// <summary>
 /// 判断存储空间(Bucket)是否存在
 /// </summary>
 /// <param name="bucketName"></param>
 /// <param name="bucketType"></param>
 /// <returns>是否存在的bool, 调用失败返回null</returns>
 /// <Author>旷丽文</Author>
 public bool?BucketExist(string bucketName, BucketType bucketType)
 {
     if (bucketName.IsNullOrWhiteSpace())
     {
         throw new Exception("bucket不能为空");
     }
     try
     {
         bucketName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{bucketName}".ToLower();
         return(this.Client.DoesBucketExist(bucketName));
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
 }
 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="bucketName">存储空间(Bucket)名称</param>
 /// <param name="bucketType">存储空间(Bucket)类型</param>
 /// <returns></returns>
 /// <Author>旷丽文</Author>
 public Stream DownFile(string key, string bucketName, BucketType bucketType)
 {
     if (key.IsNullOrWhiteSpace())
     {
         throw new Exception("Key不能为空");
     }
     try
     {
         key        = key.Trim();
         bucketName = $"{AppSettings["OSSBucketName"]}{bucketType.ToString()}{bucketName}".ToLower();
         var file = this.Client.GetObject(bucketName, key);
         return(file.Content);
     }
     catch (Exception ex)
     {
         LogerManager.Error(ex);
         return(null);
     }
 }
Esempio n. 8
0
        public void Execute(IJobExecutionContext context)
        {
            using (var wowLadderRepository = new WowLadderLiteDbRepository(SimpleLadderConfig.WowLadderLiteDbConnection))
                using (var trans = wowLadderRepository.BeginTransaction())
                {
                    try
                    {
                        if (wowLadderRepository.IsDownloadedToday)
                        {
                            return;
                        }

                        IReadOnlyList <PvpApiRowModel> ladderRows = _wowApiClient.GetAllPvpLadderRows();

                        if (!ladderRows.Any())
                        {
                            return;
                        }

                        foreach (BlizzardLocale locale in Enum.GetValues(typeof(BlizzardLocale)))
                        {
                            foreach (WowPvpBracket bracket in Enum.GetValues(typeof(WowPvpBracket)))
                            {
                                if (ladderRows.Any(lr => lr.Locale == (byte)locale && lr.Bracket == (byte)bracket))
                                {
                                    wowLadderRepository.RemoveRecords(locale, bracket);
                                }
                            }
                        }

                        wowLadderRepository.Create(ladderRows);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        LogerManager.LogError(ex);
                        trans.Rollback();
                    }
                }
        }
Esempio n. 9
0
        /// <summary>
        /// Return pvp world of warcraft ladder data from official blizzard web api
        /// </summary>
        /// <param name="locale">BlizzardLocale.All is invalid param for this method</param>
        /// <param name="bracket">WowPvpBracket.All is invalid param for this method</param>
        /// <returns></returns>
        public async Task <IReadOnlyList <PvpApiRowModel> > GetPvpLadderRowsAsync(BlizzardLocale locale, WowPvpBracket bracket)
        {
            if (locale == BlizzardLocale.All)
            {
                throw new InvalidEnumArgumentException(nameof(BlizzardLocale.All));
            }

            if (bracket == WowPvpBracket.All)
            {
                throw new InvalidEnumArgumentException(nameof(WowPvpBracket.All));
            }

            var url = $"{BaseUrl}/{bracket.Stringify()}?locale={locale}&apikey={ApiKey}";

            try
            {
                using (var content = await HttpClient.GetStreamAsync(url))
                    using (var streamReader = new StreamReader(content))
                        using (var jsonTextReader = new JsonTextReader(streamReader))
                        {
                            var serializer = new JsonSerializer();
                            var rows       = serializer.Deserialize <PvpApiRowsModel>(jsonTextReader);

                            foreach (var row in rows.Rows)
                            {
                                row.Locale       = (byte)locale;
                                row.DownloadedOn = DateTime.Now;
                                row.Bracket      = (byte)bracket;
                            }

                            return(rows.Rows);
                        }
            }
            catch (Exception ex)
            {
                LogerManager.LogError(ex, $"url: {url}");
                return(null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 执行方法, 并且返回
        /// </summary>
        /// <typeparam name="Result">返回值类型, 如果执行失败, 返回的是default(Result)的值</typeparam>
        /// <param name="func">委托</param>
        /// <returns>BusinesResult</returns>

        protected BusinessResult <Result> Runing <Result>(Func <Result> func)
        {
            try
            {
                if (func == null)
                {
                    throw new Exception("方法体为空, 处理无意义, 异常来自BusinesBase类的Runing方法");
                }
                Result result = func();
                return(new BusinessResult <Result>
                {
                    Msg = string.Empty,
                    Success = true,
                    Value = result
                });
            }
            catch (ParamsException ex)
            {
                return(new BusinessResult <Result>
                {
                    Msg = ex.Message,
                    Success = false,
                    Value = default(Result),
                    Exception = ex
                });
            }
            catch (Exception ex)
            {
                LogerManager.Error(ex);
                return(new BusinessResult <Result>
                {
                    Msg = ex.Message,
                    Success = false,
                    Value = default(Result),
                    Exception = ex
                });
            }
        }
Esempio n. 11
0
 protected TaskContext()
 {
     this.Log = LogerManager.GetLogger("TaskContext");
 }
Esempio n. 12
0
 public SequenceTask(T primaryData) : this(primaryData, null)
 {
     this.Log = LogerManager.GetLogger("TaskContext");
 }