Пример #1
0
        /// <summary>
        /// 添加友情连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            int    place = Convert.ToInt32(ddlPlace.SelectedValue);
            string name  = this.txtLinkName.Text.Trim();
            string title = this.txtLinkTitle.Text.Trim();
            string url   = this.txtLinkUrl.Text.Trim();

            if (name.Length == 0 || url.Length == 0)
            {
                lblError.Text = "各项不能为空";
                return;
            }
            Links item = new Links();

            item.linkname  = name;
            item.linktitle = title;
            item.linkurl   = url;
            item.addtime   = DateTime.Now;
            item.istj      = place;
            if (lblId.Text != "")
            {
                item.id = Convert.ToInt32(lblId.Text.Trim());
                int num = LinksService.Update(item);
            }
            else
            {
                int num = LinksService.Add(item);
            }
            pnlAdd.Visible  = false;
            pnlList.Visible = true;
            sp.InitBindData(repInfo, pager1, "Links", "id", sear());
        }
Пример #2
0
        /// <summary>
        /// 修改连接信息
        /// </summary>
        private void ModLink()
        {
            int    id    = CRequest.GetInt("id", 0);
            string name  = CRequest.GetString("name");
            string title = CRequest.GetString("title");
            string path  = CRequest.GetString("path");
            int    place = CRequest.GetInt("place", 0);
            Links  item  = LinksService.GetModel(id);

            if (item != null)
            {
                item.linkname  = name;
                item.linktitle = title;
                item.linkurl   = path;
                item.istj      = place;
                int num = LinksService.Update(item);
                if (num > 0)
                {
                    Response.Write("success");
                }
                else
                {
                    Response.Write("fail");
                }
            }
        }
Пример #3
0
        /// <summary>在调用操作方法后调用。</summary>
        /// <param name="filterContext">有关当前请求和操作的信息。</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (filterContext.HttpContext.Request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
            {
                if (filterContext.Result is ViewResult)
                {
                    filterContext.Result = ResultData(null, false, "该URL仅支持Get请求方式", false, HttpStatusCode.MethodNotAllowed);
                }
                return;
            }

            #region 准备页面数据模型

            ViewBag.menus = MenuService.GetQueryFromCache <MenuDto>(m => m.Status == Status.Available).OrderBy(m => m.Sort).ToList(); //菜单
            var model = new PageFootViewModel                                                                                         //页脚
            {
                Links = LinksService.GetQueryFromCache <LinksDto>(l => l.Status == Status.Available).OrderByDescending(l => l.Recommend).ThenByDescending(l => l.Weight).ThenByDescending(l => new Random().Next()).Take(40).ToList()
            };
            ViewBag.Footer = model;

            #endregion

            ViewData["ActionElapsed"] = Stopwatch.ElapsedMilliseconds + "ms";
            if (Stopwatch.ElapsedMilliseconds > 5000)
            {
                LogManager.Debug($"请求路径:{Request.Scheme}://{Request.Host}{HttpUtility.UrlDecode(Request.Path)}执行耗时{Stopwatch.ElapsedMilliseconds}ms");
            }
        }
Пример #4
0
        private static IEnumerable <Link> CreateSharedLinks(LinkData linkData)
        {
            Console.WriteLine("Creating Shared Links ...");
            var links = new Link[]
            {
                new Link
                {
                    SyncPointId           = _currentFolder.SyncpointId,
                    VirtualPath           = $"{_currentFolder.VirtualPath}{linkData.FileName}",
                    LinkExpireInDays      = 90,
                    LinkExpirationPolicy  = ShareLinkExpirationPolicy.Enabled,
                    PasswordProtectPolicy = ShareLinkPasswordProtectedPolicy.Disabled,
                    RolId            = 1,
                    SharedLinkPolicy = ShareLinkPolicy.IntendedOnly,
                    IrmRoleType      = IrmRoleType.Reader,
                    IsIrmProtected   = true,
                    Users            = new User []
                    {
                        new User {
                            EmailAddress = linkData.Email
                        }
                    },
                    Message = linkData.OldMessage
                }
            };

            return(LinksService.CreateSharedLinks(links));
        }
Пример #5
0
        public async Task <IActionResult> ShuffleDeck([FromBody] ShuffleRequest request)
        {
            var decks = await Services.DeckService.Find(request.DeckName);

            if (!decks.Any())
            {
                return(NotFound(string.Format(Resource.DeckNotFound, request.DeckName)));
            }

            if (decks.Count() > 1)
            {
                return(BadRequest(string.Format(Resource.MultiplyDeckNames, request.DeckName)));
            }

            var deck = decks.First();

            deck = await Services.ShuffleService.Shuffle(deck);

            await Services.DeckService.Update(deck);

            var response = Mapper.MapToDeckHeader(deck);

            await LinksService.AddLinksAsync(response);

            return(Ok(response));
        }
Пример #6
0
        public ActionResult GetPageData(int page = 1, int size = 10)
        {
            List <Links> list      = LinksService.GetAll().OrderBy(p => p.Status).ThenByDescending(p => p.Recommend).ThenByDescending(p => p.Id).Skip((page - 1) * size).Take(size).ToList();
            var          total     = LinksService.GetAll().Count();
            var          pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();

            return(PageResult(list, pageCount, total));
        }
Пример #7
0
        public async Task <ActionResult> Index([FromServices] IWebHostEnvironment hostEnvironment)
        {
            var list = await LinksService.GetQueryFromCacheAsync <bool, LinksDto>(l => l.Status == Status.Available, l => l.Recommend, false);

            ViewBag.Html = await new FileInfo(Path.Combine(hostEnvironment.WebRootPath, "template", "links.html")).ShareReadWrite().ReadAllTextAsync(Encoding.UTF8);
            ViewBag.Ads  = AdsService.GetByWeightedPrice(AdvertiseType.InPage, Request.Location());
            return(CurrentUser.IsAdmin ? View("Index_Admin", list) : View(list));
        }
Пример #8
0
        public async Task <ActionResult> Index()
        {
            var list = await LinksService.GetQueryFromCacheAsync <bool, LinksDto>(l => l.Status == Status.Available, l => l.Recommend, false);

            ViewBag.Html = await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "links.html"));

            return(CurrentUser.IsAdmin ? View("Index_Admin", list) : View(list));
        }
Пример #9
0
        public WindowFormLink(Link l)
        {
            InitializeComponent();
            linkService      = new LinksService();
            categorieService = new CategorieService();

            _link = l;
        }
Пример #10
0
        public async Task <ActionResult> Toggle(int id, bool state)
        {
            Links link = await LinksService.GetByIdAsync(id);

            link.Status = !state ? Status.Available : Status.Unavailable;
            bool b = await LinksService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #11
0
        public async Task <ActionResult> ToggleRecommend(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Recommend = !m.Recommend
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #12
0
        public ActionResult ToggleRecommend(int id, bool state)
        {
            Links link = LinksService.GetById(id);

            link.Recommend = !state;
            bool b = LinksService.SaveChanges() > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #13
0
        public ActionResult Toggle(int id, bool state)
        {
            Links link = LinksService.GetById(id);

            link.Status = !state ? Status.Available : Status.Unavailable;
            bool b = LinksService.SaveChanges() > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #14
0
        public async Task <ActionResult> ToggleRecommend(int id, bool state)
        {
            Links link = await LinksService.GetByIdAsync(id);

            link.Recommend = !state;
            bool b = await LinksService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #15
0
        public async Task <ActionResult> ToggleWhitelist(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Except = !m.Except
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #16
0
        public WindowFormLink(int defaultIdCategoria = 0)
        {
            InitializeComponent();
            linkService      = new LinksService();
            categorieService = new CategorieService();

            _link             = new Link();
            _link.IdCategoria = defaultIdCategoria;
        }
Пример #17
0
        public async Task <ActionResult> Toggle(int id)
        {
            var b = await LinksService.GetQuery(m => m.Id == id).UpdateFromQueryAsync(m => new Links()
            {
                Status = m.Status == Status.Unavailable ? Status.Available : Status.Unavailable
            }) > 0;

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #18
0
        public ActionResult ToggleWhitelist(int id, bool state)
        {
            Links link = LinksService.GetById(id);

            link.Except = !state;
            bool b = LinksService.UpdateEntitySaved(link);

            return(ResultData(null, b, b ? "切换成功!" : "切换失败!"));
        }
Пример #19
0
        public async Task <ActionResult> Edit(Links model)
        {
            Links links = await LinksService.GetByIdAsync(model.Id);

            links.Name = model.Name;
            links.Url  = model.Url;
            bool b = await LinksService.SaveChangesAsync() > 0;

            return(ResultData(null, b, b ? "保存成功" : "保存失败"));
        }
Пример #20
0
        public async Task <ActionResult> Edit(Links model)
        {
            var b = await LinksService.GetQuery(m => m.Id == model.Id).UpdateFromQueryAsync(m => new Links()
            {
                Name = model.Name,
                Url  = model.Url
            }) > 0;

            return(ResultData(null, b, b ? "保存成功" : "保存失败"));
        }
Пример #21
0
        /// <summary>
        /// Delete连接
        /// </summary>
        private void DelLink()
        {
            int id  = CRequest.GetInt("id", 0);
            int num = LinksService.Delete(id);

            if (num > 0)
            {
                Response.Redirect("/admin/link.aspx");
            }
        }
Пример #22
0
        public ActionResult Edit(Links model)
        {
            Links links = LinksService.GetById(model.Id);

            links.Name = model.Name;
            links.Url  = model.Url;
            bool b = LinksService.UpdateEntitySaved(links);

            return(ResultData(null, b, b ? "保存成功" : "保存失败"));
        }
Пример #23
0
        public ActionResult Edit(Links model)
        {
            Links links = LinksService.GetById(model.Id);

            links.Name = model.Name;
            links.Url  = model.Url;
            bool b = LinksService.SaveChanges() > 0;

            return(ResultData(null, b, b ? "保存成功" : "保存失败"));
        }
Пример #24
0
        /// <summary>
        /// 申请友链
        /// </summary>
        /// <param name="link"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ActionResult> Apply(Links link, CancellationToken cancellationToken)
        {
            if (!link.Url.MatchUrl() || link.Url.Contains(Request.Host.Host))
            {
                return(ResultData(null, false, "添加失败!链接非法!"));
            }

            if (link.Url.Contains(new[] { "?", "&", "=" }))
            {
                return(ResultData(null, false, "添加失败!请移除链接中的查询字符串后再试!如遇特殊情况,请联系站长进行处理。"));
            }

            if (!link.Url.Contains(link.UrlBase))
            {
                return(ResultData(null, false, "站点主页和友链地址不匹配,请检查"));
            }

            var host = new Uri(link.Url).Host;

            if (LinksService.Any(l => l.Url.Contains(host)))
            {
                return(ResultData(null, false, "添加失败!检测到您的网站已经是本站的友情链接了!"));
            }

            HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.47");
            HttpClient.DefaultRequestHeaders.Referrer = new Uri(Request.Scheme + "://" + Request.Host);
            HttpClient.DefaultRequestHeaders.Add("X-Forwarded-For", "1.1.1.1");
            HttpClient.DefaultRequestHeaders.Add("X-Forwarded-Host", "1.1.1.1");
            HttpClient.DefaultRequestHeaders.Add("X-Real-IP", "1.1.1.1");
            HttpClient.DefaultRequestVersion = new Version(2, 0);
            return(await HttpClient.GetAsync(link.Url, cancellationToken).ContinueWith(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    return ResultData(null, false, "添加失败!检测到您的网站疑似挂了,或者连接到你网站的时候超时,请检查下!");
                }

                var res = t.Result;
                if (!res.IsSuccessStatusCode)
                {
                    return ResultData(null, false, "添加失败!检测到您的网站疑似挂了!返回状态码为:" + res.StatusCode);
                }

                using var httpContent = res.Content;
                var s = httpContent.ReadAsStringAsync().Result;
                if (!s.Contains(Request.Host.Host))
                {
                    return ResultData(null, false, $"添加失败!检测到您的网站上未将本站设置成友情链接,请先将本站主域名:{Request.Host}在您的网站设置为友情链接,并且能够展示后,再次尝试添加即可!");
                }

                var b = LinksService.AddEntitySaved(link) != null;
                return ResultData(null, b, b ? "添加成功!这可能有一定的延迟,如果没有看到您的链接,请稍等几分钟后刷新页面即可,如有疑问,请联系站长。" : "添加失败!这可能是由于网站服务器内部发生了错误,如有疑问,请联系站长。");
            }));
        }
Пример #25
0
        /// <summary>
        /// 申请友链
        /// </summary>
        /// <param name="links"></param>
        /// <returns></returns>
        public async Task <ActionResult> Apply(Links links)
        {
            if (!links.Url.MatchUrl())
            {
                return(ResultData(null, false, "添加失败!链接非法!"));
            }

            var host = new Uri(links.Url).Host;

            if (LinksService.Any(l => l.Url.Contains(host)))
            {
                return(ResultData(null, false, "添加失败!检测到您的网站已经是本站的友情链接了!"));
            }

            HttpClient.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue.Parse("Mozilla/5.0"));
            HttpClient.DefaultRequestHeaders.Referrer = new Uri(Request.Scheme + "://" + Request.Host.ToString());
            return(await await HttpClient.GetAsync(links.Url).ContinueWith(async t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    return ResultData(null, false, "添加失败!检测到您的网站疑似挂了,或者连接到你网站的时候超时,请检查下!");
                }

                var res = await t;
                if (!res.IsSuccessStatusCode)
                {
                    return ResultData(null, false, "添加失败!检测到您的网站疑似挂了!返回状态码为:" + res.StatusCode);
                }

                var s = await res.Content.ReadAsStringAsync();
                if (!s.Contains(CommonHelper.SystemSettings["Domain"]))
                {
                    return ResultData(null, false, $"添加失败!检测到您的网站上未将本站设置成友情链接,请先将本站主域名:{CommonHelper.SystemSettings["Domain"]}在您的网站设置为友情链接,并且能够展示后,再次尝试添加即可!");
                }

                var entry = LinksService.Get(l => l.Url.Equals(links.Url));
                bool b;
                if (entry is null)
                {
                    b = LinksService.AddEntitySaved(links) != null;
                }
                else
                {
                    entry.Url = links.Url;
                    entry.Except = links.Except;
                    entry.Name = links.Name;
                    entry.Recommend = links.Recommend;
                    b = LinksService.SaveChanges() > 0;
                }

                return ResultData(null, b, b ? "添加成功!这可能有一定的延迟,如果没有看到您的链接,请稍等几分钟后刷新页面即可,如有疑问,请联系站长。" : "添加失败!这可能是由于网站服务器内部发生了错误,如有疑问,请联系站长。");
            }));
        }
Пример #26
0
 /// <summary>在调用操作方法后调用。</summary>
 /// <param name="filterContext">有关当前请求和操作的信息。</param>
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     if (filterContext.Result is ViewResult)
     {
         ViewBag.menus = MenuService.GetQueryFromCache(m => m.ParentId == null && m.Status == Status.Available).OrderBy(m => m.Sort).ToList(); //菜单
         var model = new PageFootViewModel                                                                                                     //页脚
         {
             Links = LinksService.GetQueryFromCache <LinksDto>(l => l.Status == Status.Available).OrderByDescending(l => l.Recommend).ThenByDescending(l => l.Weight).Take(30).ToList()
         };
         ViewBag.Footer = model;
     }
 }
Пример #27
0
        public ActionResult Index()
        {
            UserInfoOutputDto     user = HttpContext.Session.GetByRedis <UserInfoOutputDto>(SessionKey.UserInfo);
            List <LinksOutputDto> list = LinksService.LoadEntities <object, LinksOutputDto>(l => l.Status == Status.Available, l => l.Recommend, false).ToList();

            if (user != null && user.IsAdmin)
            {
                return(View("Index_Admin", list));
            }

            return(View(list));
        }
Пример #28
0
        public async Task <IActionResult> GetDecks()
        {
            var decks = await Services.DeckService.FindAll();

            var response = decks.Select(d => Mapper.MapToDeckHeader(d)).ToArray();

            foreach (var r in response)
            {
                await LinksService.AddLinksAsync(r);
            }

            return(Ok(response));
        }
Пример #29
0
        public HttpResponseMessage Get(int page = 10, int pageSize = 20)
        {
            var service = new LinksService(HttpContextHelper.LinkShortenContext);

            try
            {
                var result = service.GetLinks(page, pageSize);
                return(this.Request.CreateResponse(HttpStatusCode.OK, result));
            } catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #30
0
        /// <summary>
        /// init services, caricamento categorie
        /// </summary>
        void Init()
        {
            // init services
            categoriaService = new CategorieService();
            linksService     = new LinksService();

            // load elementi
            LoadCategorie(categoriaService.GetAll());

            //ui
            this.Title = "Gestione link - " + new ConfigManager().GetKey("FileName");
            // TODO
            //txbCount.Text = "";
        }