Esempio n. 1
0
        public bool CopyImageIntoCache(string fn)
        {
            bool rt = false;

            try
            {
                string fileName = Path.GetFileName(fn);
                if (!this.ExistsFile(fileName, fn))
                {
                    string fullName = this.GetFullName(fileName);
                    if (File.Exists(fullName))
                    {
                        FileEx.DeleteWithoutException(fullName);
                    }
                    File.Copy(fn, fullName);
                    rt = BotApi.UpoadImageFile(fullName);
                }
                else
                {
                    rt = true;
                }
            }
            catch (Exception e)
            {
                Log.Exception(e);
                rt = false;
            }
            return(rt);
        }
Esempio n. 2
0
 private static void DownImageAndSave(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         string text = WebImageHelper.GetImageFileName(url);
         FileEx.DeleteWithoutException(text);
         using (WebClient webClient = new WebClient())
         {
             try
             {
                 webClient.DownloadFile(url, text);
             }
             catch (Exception e)
             {
                 Log.Exception(e);
                 Log.Info("无法下载图片,url=" + url);
             }
         }
         try
         {
             BitmapImageEx.ResizeImageAndSave(text, 300);
         }
         catch (Exception e2)
         {
             Log.Exception(e2);
         }
     }
 }
Esempio n. 3
0
 public void DeleteImage(string imgName)
 {
     if (!string.IsNullOrEmpty(imgName))
     {
         var fn = this.GetFullName(imgName);
         FileEx.DeleteWithoutException(fn);
         //BotSvrApi.Delete(fn, this._fileType);
     }
 }
Esempio n. 4
0
        public string AddNewImage(string fullFn)
        {
            string imagePath = null;
            string extension = Path.GetExtension(fullFn);

            if (!string.IsNullOrEmpty(extension))
            {
                extension = extension.ToLower();
            }
            Util.Assert(validImgExtensions.Contains(extension));
            for (int i = 0; i < 2; i++)
            {
                imagePath = StringEx.xGenGuidB32Str() + extension;
                var fullName = this.GetFullName(imagePath);
                File.Copy(fullFn, fullName);
                if (BotApi.UpoadImageFile(fullName))
                {
                    break;
                }
                FileEx.DeleteWithoutException(fullName);
                imagePath = null;
            }
            return(imagePath);
        }