예제 #1
0
 public ActionResult Edit(Menu obj)
 {
     if (string.IsNullOrEmpty(obj.Name))
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
     else
     {
         Menu model = MenuBLL.GetById(obj.Id);
         if (model == null)
         {
             return(Json(false, JsonRequestBehavior.AllowGet));
         }
         else
         {
             model.Name      = obj.Name;
             model.ShowOrder = obj.ShowOrder;
             UrlRecord url = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Menu" && o.EntityId == obj.Id);
             url.Slug = obj.ValidateSeName("", obj.Name, true);
             UrlBLL.Update(url);
             MenuBLL.Update(model);
             CacheManager.Remove(Consts.MenuCacheKey);
             CacheManager.Remove(Consts.UrlRecordCacheKey);
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
     }
 }
예제 #2
0
 public ActionResult Edit(Category obj)
 {
     if (string.IsNullOrEmpty(obj.Name) || obj.MenuId == Guid.Empty)
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
     else
     {
         Category model = CateBLL.GetById(obj.Id);
         if (model == null)
         {
             return(Json(false, JsonRequestBehavior.AllowGet));
         }
         else
         {
             model.Name      = obj.Name;
             model.ShowOrder = obj.ShowOrder;
             model.ParentId  = obj.ParentId;
             model.MenuId    = obj.MenuId;
             UrlRecord url = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Category" && o.EntityId == obj.Id);
             url.Slug = obj.ValidateSeName("", obj.Name, true);
             UrlBLL.Update(url);
             CateBLL.Update(model);
             CacheManager.Remove(Consts.CategoryCacheKey);
             CacheManager.Remove(Consts.UrlRecordCacheKey);
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
     }
 }
예제 #3
0
        public ActionResult Delete(Guid id)
        {
            Menu      obj       = MenuBLL.GetById(id);
            UrlRecord urlRecord = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Menu" && o.EntityId == obj.Id);

            if (urlRecord != null)
            {
                UrlBLL.Delete(urlRecord);
            }
            MenuBLL.Delete(obj);
            CacheManager.Remove(Consts.MenuCacheKey);
            CacheManager.Remove(Consts.UrlRecordCacheKey);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
 private void MatchWebUrl(object obj)
 {
     try
     {
         Dictionary <string, object> dic = (Dictionary <string, object>)obj;
         string          html            = dic["Result"].ToString();
         string          host            = dic["Host"].ToString();
         string          webUrl          = dic["Url"].ToString();
         int             depth           = (int)dic["Depth"];
         string          matchStr        = "<a[\\s^\\s]+href=\"(?<href>\\S+)\"";//命名分组
         MatchCollection collection      = Regex.Matches(html, matchStr, RegexOptions.IgnoreCase | RegexOptions.Compiled);
         string          content         = string.Empty;
         foreach (Match item in collection)
         {
             string href = item.Groups["href"].Value;
             //无效链接
             if (string.IsNullOrEmpty(href) || href == "#" || href.ToLower().Contains("javascript"))
             {
                 continue;
             }
             //没有域名的链接
             if (!href.Contains("http") && !href.Contains("ftp"))
             {
                 href = "http://" + host + href;
             }
             //外链接
             if (!href.Contains("http://" + host))
             {
                 continue;
             }
             //是否已保存
             if (UrlBLL.IsExistUrl(href))
             {
                 continue;
             }
             UrlEntity urlEnt = new UrlEntity();
             urlEnt.AddDate = DateTime.Now;
             urlEnt.Depth   = depth;
             urlEnt.Host    = host;
             urlEnt.Url     = href;
             urlEnt.WebUrl  = webUrl;
             UrlBLL.Insert(urlEnt);
         }
     }
     catch (Exception ex)
     {
         LogHelper.LogTrace(ex.Message);
     }
 }
예제 #5
0
 public ActionResult Delete(Guid id)
 {
     foreach (Guid gid in GetIdAndChildId(TableCache.Where(o => o.Id == id).ToList()))
     {
         Category  obj       = CateBLL.GetById(gid);
         UrlRecord urlRecord = UrlBLL.Table.FirstOrDefault(o => o.EntityName == "Category" && o.EntityId == obj.Id);
         if (urlRecord != null)
         {
             UrlBLL.Delete(urlRecord);
         }
         CateBLL.Delete(obj);
     }
     CacheManager.Remove(Consts.CategoryCacheKey);
     CacheManager.Remove(Consts.UrlRecordCacheKey);
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
예제 #6
0
        /// <summary>
        /// 获取图片url
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void image_Click(object sender, EventArgs e)
        {
            try
            {
                string host = this.txtHost.Text;
                if (string.IsNullOrEmpty(host))
                {
                    MessageBox.Show("请输入主机");
                    return;
                }
                CookieContainer cookie = new CookieContainer();
                if (this.ckbLogin.Checked)
                {
                    string msg = "";
                    cookie = this.GetCookie(ref msg);
                    if (msg != "")
                    {
                        MessageBox.Show(msg);
                        return;
                    }
                }

                this.image.Text = "执行中...";
                List <UrlEntity> urlList = UrlBLL.GetList(host);
                foreach (var item in urlList)
                {
                    RequestEntity requestEnt = new RequestEntity();
                    requestEnt.postUrl = item.Url;
                    requestEnt.method  = "get";
                    requestEnt.host    = item.Host;
                    requestEnt.cookie  = cookie;
                    string result = RequestHelper.ImplementOprater(requestEnt);
                    MatchImageUrl(result, item.Host, item.WebUrl);
                    UrlBLL.UpdateUsered(item.Id);
                }
                this.image.Text = "获取图片url";
            }
            catch (Exception ex)
            {
                LogHelper.LogTrace("报错:" + ex.Message);
                Application.Exit();
            }
        }
예제 #7
0
        /// <summary>
        /// 匹配网页链接
        /// </summary>
        /// <param name="html"></param>
        private void MatchWebUrl(string html, string host, string webUrl, int depth)
        {
            string          matchStr   = "<a[\\s^\\s]+href=\"(?<href>\\S+)\"";//命名分组
            MatchCollection collection = Regex.Matches(html, matchStr, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            string          content    = string.Empty;

            foreach (Match item in collection)
            {
                string href = item.Groups["href"].Value;
                //无效链接
                if (string.IsNullOrEmpty(href) || href == "#" || href.ToLower().Contains("javascript"))
                {
                    continue;
                }
                //没有域名的链接
                if (!href.Contains("http") && !href.Contains("ftp"))
                {
                    href = "http://" + host + href;
                }
                //外链接
                if (!href.Contains("http://" + host))
                {
                    continue;
                }
                //是否已保存
                if (UrlBLL.IsExistUrl(href))
                {
                    continue;
                }
                UrlEntity urlEnt = new UrlEntity();
                urlEnt.AddDate = DateTime.Now;
                urlEnt.Depth   = depth;
                urlEnt.Host    = host;
                urlEnt.Url     = href;
                urlEnt.WebUrl  = webUrl;
                UrlBLL.Insert(urlEnt);
            }
        }
예제 #8
0
 public ActionResult Add(Menu obj)
 {
     if (string.IsNullOrEmpty(obj.Name))
     {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
     else
     {
         obj.Id = Guid.NewGuid();
         UrlRecord url = new UrlRecord
         {
             Id         = Guid.NewGuid(),
             EntityId   = obj.Id,
             EntityName = "Menu",
             Slug       = obj.ValidateSeName("", obj.Name, true)
         };
         UrlBLL.Create(url);
         MenuBLL.Create(obj);
         CacheManager.Remove(Consts.MenuCacheKey);
         CacheManager.Remove(Consts.UrlRecordCacheKey);
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
 }
예제 #9
0
        /// <summary>
        /// 获取url
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void confirm_Click(object sender, EventArgs e)
        {
            try
            {
                string url = this.txtUrl.Text;
                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show("请输入首页链接");
                    return;
                }
                CookieContainer cookie = new CookieContainer();
                if (this.ckbLogin.Checked)
                {
                    string msg = "";
                    cookie = this.GetCookie(ref msg);
                    if (msg != "")
                    {
                        MessageBox.Show(msg);
                        return;
                    }
                }

                string host = string.Empty;
                if (url.Contains("http"))
                {
                    string[] arr = url.Split('/');
                    if (arr.Length >= 3)
                    {
                        host = arr[2];
                    }
                }
                this.confirm.Text = "执行中...";
                int           depth      = 1;
                RequestEntity requestEnt = new RequestEntity();
                requestEnt.postUrl = url;
                requestEnt.method  = "get";
                requestEnt.host    = host;
                requestEnt.cookie  = cookie;
                string result = RequestHelper.ImplementOprater(requestEnt);
                MatchWebUrl(result, host, url, depth);
                for (int i = 1; i <= 3; i++)
                {
                    depth = i + 1;
                    List <UrlEntity> urlList = UrlBLL.GetList(host, i);
                    foreach (var item in urlList)
                    {
                        requestEnt         = new RequestEntity();
                        requestEnt.postUrl = item.Url;
                        requestEnt.method  = "get";
                        requestEnt.host    = item.Host;
                        if (this.ckbLogin.Checked && cookie.Count == 0)
                        {
                            string msg = "";
                            cookie = this.GetCookie(ref msg);
                            if (msg != "")
                            {
                                MessageBox.Show(msg);
                                return;
                            }
                        }
                        requestEnt.cookie = cookie;
                        result            = RequestHelper.ImplementOprater(requestEnt);
                        Thread thread = new Thread(MatchWebUrl);
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic["Result"] = result;
                        dic["Host"]   = item.Host;
                        dic["Url"]    = item.Url;
                        dic["Depth"]  = depth;
                        thread.Start(dic);
                        //MatchWebUrl(result, item.Host, item.Url, depth);
                    }
                }
                this.confirm.Text = "获取url";
            }
            catch (Exception ex)
            {
                LogHelper.LogTrace("报错:" + ex.Message);
                Application.Exit();
            }
        }