Example #1
0
 public async Task Process(DownloadImage args)
 {
     try
     {
         using (var wc = new WebClient())
         {
             wc.DownloadFile($"{args.ImageUrl}", Path.Combine(chobbyla.paths.WritableDirectory, args.TargetPath));
         }
         SendCommand(new DownloadImageDone()
         {
             TargetPath = args.TargetPath, ImageUrl = args.ImageUrl, RequestToken = args.RequestToken
         });
     }
     catch (Exception ex)
     {
         Trace.TraceError("Error downloading image {0} : {1}", args?.ImageUrl, ex);
     }
 }
Example #2
0
 public async Task Process(DownloadImage args)
 {
     try
     {
         using (var wc = new WebClient())
         {
             var targetPath = Path.Combine(chobbyla.paths.WritableDirectory, args.TargetPath);
             var dir        = Path.GetDirectoryName(targetPath);
             if (!Directory.Exists(dir))
             {
                 Directory.CreateDirectory(dir);
             }
             wc.DownloadFile($"{args.ImageUrl}", targetPath);
         }
         SendCommand(new DownloadImageDone()
         {
             TargetPath = args.TargetPath, ImageUrl = args.ImageUrl, RequestToken = args.RequestToken
         });
     }
     catch (Exception ex)
     {
         Trace.TraceError("Error downloading image {0} : {1}", args?.ImageUrl, ex);
     }
 }
Example #3
0
 public async Task Process(DownloadImage args)
 {
     try
     {
         ImageType type;
         if (string.IsNullOrEmpty(args.ImageType) || !Enum.TryParse(args.ImageType, out type))
         {
             type = ImageType.Clans;
         }
         using (var wc = new WebClient())
         {
             wc.DownloadFile($"{GlobalConst.BaseSiteUrl}/img/{type}/{args.Name}.png",
                             Path.Combine(chobbyla.paths.WritableDirectory, "LuaUI", "Configs", type.ToString(), $"{args.Name}.png"));
             SendCommand(new DownloadImageDone()
             {
                 Name = args.Name, ImageType = args.ImageType, RequestToken = args.RequestToken
             });
         }
     }
     catch (Exception ex)
     {
         Trace.TraceError("Error downloading image {0} : {1}", args?.Name, ex);
     }
 }