Пример #1
0
        public static void SaveCodeToFile()
        {
            OleDbDataReader reader = VTSCommon.ExcelToDataReader(string.Concat(Base_Path, "Site.xlsx"), "Sheet1");

            string domain = string.Empty;
            string url    = string.Empty;
            string jsPath = string.Empty;
            string isSave = "NO";

            while (reader.Read())
            {
                domain = reader["域名"].ToString();
                url    = reader["地址"].ToString();
                jsPath = reader["SKCode"].ToString();
                isSave = reader["是否保存"].ToString();

                if (isSave == "YES")
                {
                    if (!string.IsNullOrEmpty(url))
                    {
                        Js_Content = System.Web.HttpUtility.UrlEncode(VTSCommon.ReadTextToendByDefault(string.Concat(Base_Path, "owl.carousel.min.js")));
                        Console.WriteLine(reader["ID"].ToString() + ":" + NetHelper.HttpPost(url, "action=savecontent&path=" + jsPath + "&content=" + Js_Content) + "  " + domain);
                    }
                }
            }
            reader.Close();
        }
Пример #2
0
        public static void DeleteImage(string imageid)
        {
            List <string> ls  = VTSCommon.LoadTextToList(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), true);
            string        str = ls.Find(x => x.StartsWith(imageid));

            string[] arr = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr != null)
            {
                if (arr.Length == 4 || arr.Length == 6)
                {
                    if (System.IO.File.Exists(ConfigHelper.BaseDirectory + arr[2]))
                    {
                        System.IO.File.Delete(ConfigHelper.BaseDirectory + arr[2]);
                    }
                }
            }
            ls.Remove(str);

            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), false))
            {
                foreach (string item in ls)
                {
                    sw.WriteLine(item);
                }
            }
        }
Пример #3
0
 public byte[] CacheImage(string imageFilePath, out int length)
 {
     byte[] cache = CacheHelper.Get <byte[]>(imageFilePath);
     if (cache == null)
     {
         CacheHelper.Insert(imageFilePath, VTSCommon.GetPictureData(imageFilePath));
         cache = CacheHelper.Get <byte[]>(imageFilePath);
     }
     length = cache.Length;
     return(cache);
 }
Пример #4
0
        public static void CheckServer()
        {
            OleDbDataReader reader = VTSCommon.ExcelToDataReader(string.Concat(Base_Path, "Site.xlsx"), "Sheet1");
            string          url    = string.Empty;

            while (reader.Read())
            {
                url = reader["服务地址"].ToString();
                if (!string.IsNullOrEmpty(url))
                {
                    Console.WriteLine(reader["ID"].ToString() + ":" + NetHelper.HttpPost(url, "action=checkserver") + "  " + url);
                }
            }
            reader.Close();
        }
Пример #5
0
        static void Main(string[] args)
        {
            //string url = "http://127.0.0.1/demo/webs.php";

            //Console.WriteLine(HttpPost(url, "action=checkserver"));

            //Console.WriteLine(HttpPost(url, "action=checkfile&path=d:\\httpd.conf"));

            //Console.WriteLine(HttpPost(url, "action=getsize&path=d:\\httpd.conf"));

            //Console.WriteLine(HttpPost(url, "action=getcontent&path=d:\\httpd.conf"));

            //Console.WriteLine(HttpPost(url, "action=savecontent&path=d:\\httpd.conf&content=hello"));

            Js_Content = VTSCommon.ReadTextToendByDefault(string.Concat(Base_Path, "default\\owl.carousel.min.js"));

            Run(args);
        }
Пример #6
0
        public static void CheckFileExists()
        {
            OleDbDataReader reader = VTSCommon.ExcelToDataReader(string.Concat(Base_Path, "Site.xlsx"), "Sheet1");
            string          domain = string.Empty;
            string          url    = string.Empty;
            string          jsPath = string.Empty;

            while (reader.Read())
            {
                domain = reader["域名"].ToString();
                url    = reader["地址"].ToString();
                jsPath = reader["SKCode"].ToString();
                if (!string.IsNullOrEmpty(url))
                {
                    Console.WriteLine(reader["ID"].ToString() + ":" + NetHelper.HttpPost(url, "action=checkfile&path=" + jsPath) + "  " + domain);
                }
            }
            reader.Close();
        }
Пример #7
0
        public static void SaveImage(string imageid, string skipurl, string title = "title", string alt = "alt")
        {
            List <string> ls = VTSCommon.LoadTextToList(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), true);
            //获取信息
            string str = ls.Find(x => x.StartsWith(imageid));

            ls.Remove(str);

            //逐个修改字段的值
            if (!string.IsNullOrEmpty(str))
            {
                string[] arr = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (arr != null)
                {
                    if (arr.Length == 4)
                    {
                        arr[3] = skipurl;
                        str    = string.Concat(arr[0], "|", arr[1], "|", arr[2], "|", arr[3], "|", title, "|", alt);
                        ls.Add(str);
                    }

                    if (arr.Length == 6)
                    {
                        arr[3] = skipurl;
                        arr[4] = title;
                        arr[5] = alt;
                        str    = string.Concat(arr[0], "|", arr[1], "|", arr[2], "|", arr[3], "|", arr[4], "|", arr[5]);
                        ls.Add(str);
                    }
                }
            }

            //保存动作
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Concat(ConfigHelper.BaseDirectory, "imagedata.txt"), false))
            {
                foreach (string item in ls)
                {
                    sw.WriteLine(item);
                }
            }
        }
Пример #8
0
        public void ProcessRequest(HttpContext Context)
        {
            #region Note
            //<img src="${siteurl}Timthumb.ashx?src=${item.Images.Bigimg}&amp;h=95&amp;w=142&amp;zc=1" width="142" height="95" alt="${item.title}" />
            #endregion

            Context.Response.Clear();
            Context.Response.ClearHeaders();
            Context.Response.ClearContent();
            Context.Response.ContentType = "image/jpeg";

            string static_cache  = "/cache/cache_images/";
            string static_random = "/common/images/random/tb";

            //宽度
            int w = VTSRequest.GetQueryInt("w");
            //高度
            int h = VTSRequest.GetQueryInt("h");

            //预留
            int zc = VTSRequest.GetQueryInt("zc");
            //图片地址
            string src = VTSRequest.GetQueryString("src");

            //原始 URL --一张图片一个唯一的URL地址
            string url = VTSRequest.GetRawUrl();

            //图片名字
            string md5 = MD5Encrypt.DataToMD5(url);

            //////////////开始分文件夹/////////////////
            string folderName = md5.Substring(0, 2);
            string imageDir   = Context.Server.MapPath(static_cache + folderName);

            if (!Directory.Exists(imageDir))
            {
                Directory.CreateDirectory(imageDir);
            }
            //////////////结束分文件夹/////////////////

            //物理地址
            string imageSavePath = string.Concat(imageDir, "\\", md5, ".jpg"); //Context.Server.MapPath("/cache/cache_images/" + md5 + ".jpg");

            //VTS.Log.LogOut.Info(string.Format("ManagedThreadId:{0} src:{1},url:{2}", System.Threading.Thread.CurrentThread.ManagedThreadId, src, url));
            /*******************************************************************************************************************************************************/
            byte[] b = null;

            if (File.Exists(imageSavePath))
            {
                #region 图片已存在

                #region 缓存策略
                //正确显示图片 才设置图片缓存策略
                //配置成一个星期 168小时
                Context.Response.Cache.SetExpires(DateTime.Now.AddHours(168));
                //下面的代码示例演示如何设置 Cache-Control: max-age 标题,为 0 小时,30 分钟和 0 秒。
                TimeSpan ts = new TimeSpan(168, 0, 0);
                Context.Response.Cache.SetMaxAge(ts);
                #endregion

                b = VTSCommon.GetPictureData(imageSavePath);
                Context.Response.OutputStream.Write(b, 0, b.Length);
                #endregion
            }
            else
            {
                #region 图片不存在

                #region 线程池生成
                ImagePackage image = new ImagePackage();
                image.Src      = src;
                image.SavePath = imageSavePath;
                image.Width    = w;
                image.Height   = h;

                //线程池生成
                WaitCallback callBack = new WaitCallback(GeneratePicture);
                ThreadPool.QueueUserWorkItem(callBack, image);

                //直接生成
                //GeneratePicture(image);
                #endregion

                #region 响应  随机
                imageSavePath = Context.Server.MapPath(string.Concat(static_random, ImageRandom.GetRandomInt().ToString(), ".jpg"));
                b             = VTSCommon.GetPictureData(imageSavePath);
                #endregion

                //清除缓存头策略
                Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Context.Response.Cache.SetNoStore();
                Context.Response.OutputStream.Write(b, 0, b.Length);
                #endregion
            }
            Context.ApplicationInstance.CompleteRequest();
        }