Пример #1
0
        /// <summary>
        /// 根据drawImg树结构进行绘图
        /// </summary>
        /// <param name="drawImg">drawImg树结构</param>
        /// <returns>返回绘制的图片</returns>
        public Image DrawTree(DrawImg drawImg)
        {
            Bitmap bitmap = new Bitmap(drawImg.Width, drawImg.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                Image background = null;
                if (!string.IsNullOrEmpty(drawImg.BackgroundUrl))
                {
                    WebResponse webResponse = HttpWebRequestHelper.HttpGet(drawImg.BackgroundUrl);
                    background = webResponse.GetBitmap();
                }
                else if (!string.IsNullOrEmpty(drawImg.BackgroundPath))
                {
                    background = Image.FromFile(drawImg.BackgroundPath);
                }
                else if (drawImg.BackgroundImage != null)
                {
                    background = drawImg.BackgroundImage;
                }
                if (drawImg.BackgroundColor != null)
                {
                    g.FillRectangle(new SolidBrush(drawImg.BackgroundColor), new Rectangle(0, 0, drawImg.Width, drawImg.Height));
                }
                if (background != null)
                {
                    g.DrawImage(background, new Rectangle(0, 0, drawImg.Width, drawImg.Height));
                }
                if (drawImg.DrawList != null && drawImg.DrawList.Count > 0)
                {
                    foreach (Draw childDraw in drawImg.DrawList)
                    {
                        if (childDraw.GetType() == typeof(DrawImg))
                        {
                            DrawImg tempDrawImg = (DrawImg)childDraw;
                            using (Image childImage = DrawTree(tempDrawImg))
                            {
                                childImage.RotateFlip(tempDrawImg.Rotate);
                                g.DrawImage(childImage, new Rectangle(childDraw.Left, childDraw.Top, childImage.Width, childImage.Height));
                            }
                        }
                        else if (childDraw.GetType() == typeof(DrawText))
                        {
                            DrawText   tempDrawText = (DrawText)childDraw;
                            Font       font         = new Font(tempDrawText.FontFamily, tempDrawText.FontSize, tempDrawText.FontStyle);
                            RectangleF rectangleF   = new RectangleF(tempDrawText.Left, tempDrawText.Top, tempDrawText.Width, tempDrawText.Height);
                            g.DrawString(tempDrawText.Text, font, new SolidBrush(tempDrawText.FontColor), rectangleF);
                        }
                    }
                }
                g.Save();
            }
            return(bitmap);
        }
Пример #2
0
 public static void HttpPost(AsyncCallback asyncCallback, AsyncFailCallback asyncFailCallback, string RequestUrl, string Body, CookieContainer CookieContainer = null)
 {
     _SameTimeOperLock.LockOnMaxThread();
     ThreadPool.QueueUserWorkItem((obj) => {
         try
         {
             asyncCallback(HttpWebRequestHelper.HttpPost(RequestUrl, Body, CookieContainer));
         }
         catch (Exception ex)
         {
             asyncFailCallback(ex);
         }
         _SameTimeOperLock.UnLock();
     });
 }
Пример #3
0
 /// <summary>
 /// 检查指定日期是否为国家法定工作日
 /// </summary>
 /// <param name="date">指定日期</param>
 /// <returns>如果是返回true</returns>
 public static bool IsPrcWorkDay(DateTime date)
 {
     lock (typeof(DateHelper))
     {
         if (_workDayDateCache.ToString("yyyyMMdd") == date.ToString("yyyyMMdd"))
         {
             return(_isWorkDayCache);
         }
         else
         {
             while (true)
             {
                 string dateStrFormat = date.ToString("yyyyMMdd");
                 try
                 {
                     JObject retJson = HttpWebRequestHelper.HttpGet($"http://tool.bitefu.net/jiari/?d={dateStrFormat}&back=json").GetJsonObj();
                     _workDayDateCache = date;
                     return(_isWorkDayCache = Convert.ToString(retJson[dateStrFormat]) == "0");
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.Message);
                     Console.WriteLine("检查法定工作日出错,10秒后重试...");
                     Thread.Sleep(10000);
                 }
                 try
                 {
                     JObject retJson = HttpWebRequestHelper.HttpGet($"http://api.goseek.cn/Tools/holiday?date={dateStrFormat}").GetJsonObj();
                     _workDayDateCache = date;
                     return(_isWorkDayCache = Convert.ToString(retJson["data"]) == "0");
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex.Message);
                     Console.WriteLine("检查法定工作日出错,10秒后重试...");
                     Thread.Sleep(10000);
                 }
             }
         }
     }
 }
Пример #4
0
 /// <summary>
 /// 获取本机在外网的ip地址
 /// </summary>
 /// <returns></returns>
 public static string GetOuterNetIP()
 {
     using (var webClient = new WebClient())
     {
         while (true)
         {
             try
             {
                 string text   = HttpWebRequestHelper.HttpGet("http://pv.sohu.com/cityjson?ie=utf-8").GetText();
                 Match  rebool = Regex.Match(text, @"\d{2,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
                 return(rebool.Value);
             }
             catch (Exception ex)
             {
                 Console.WriteLine("获取本机的外网ip失败,5秒后重试...");
                 Console.WriteLine(ex.StackTrace);
                 Thread.Sleep(5000);
             }
         }
     }
 }