Ejemplo n.º 1
0
        public virtual void Visit(FormSubmit formSubmit, HtmlContainer htmlContainer)
        {
            HtmlDiv htmlDiv = verbose ? new HtmlDiv(formSubmit.Path) : new HtmlDiv();

            htmlDiv.Class.Add("formButton");

            if (!string.IsNullOrWhiteSpace(formSubmit.CssClass))
            {
                htmlDiv.Class.AddRange(formSubmit.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            if (!string.IsNullOrWhiteSpace(formSubmit.Path))
            {
                htmlDiv.Class.Add(string.Format("{0}{1}", "formId", formSubmit.Path));
            }

            htmlDiv.Hidden.Value = formSubmit.IsHidden;

            htmlContainer.Add(htmlDiv);

            HtmlSubmit htmlSubmit = new HtmlSubmit(formSubmit.Path, verbose, formSubmit.Parameter);

            htmlSubmit.Disabled.Value = formSubmit.IsDisabled;
            htmlDiv.Add(htmlSubmit);

            htmlSubmit.Add(new HtmlText(formSubmit.Content));
        }
 public IActionResult Index(FormSubmit answer)
 {
     answer.CreatedDate = DateTime.Now;
     _dbContext.FormSubmits.Add(answer);
     _dbContext.SaveChanges();
     return(View());
 }
Ejemplo n.º 3
0
        private void ShowFormSubmit()
        {
            FormSubmit form = new FormSubmit(solutionTracker.Changes);

            if (form.ShowDialog() == DialogResult.OK)
            {
                PostReview.ReviewInfo reviewInfo = form.Review;
                if (reviewInfo != null)
                {
                    VsBrowseUrl(reviewInfo.Uri);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Add(AddPostViewModel model)
        {
            FormSubmit submitInfo = new FormSubmit
            {
                IndexUrl = Url.Action(nameof(Index), "Post")
            };

            if (ModelState.IsValid)
            {
                Post post = new Post
                {
                    BlogId              = _appSettings.BlogID,
                    Title               = model.Title,
                    Content             = model.Content,
                    RowCreatedBy        = Convert.ToInt32(_userManager.GetUserId(User)),
                    RowModifiedBy       = Convert.ToInt32(_userManager.GetUserId(User)),
                    RowCreatedDateTime  = DateTime.Now,
                    RowModifiedDateTime = DateTime.Now
                };

                Result result = new Result(false, "Unable to add post at this time.");

                try
                {
                    await _post.AddPostAsync(post);

                    result.Succeeded = true;
                    result.Message   = "Post added.";
                }
                catch (Exception ex)
                {
                    SysException exception = new SysException(ex)
                    {
                        Url = UrlHelper.GetRequestUrl(HttpContext)
                    };
                }

                submitInfo.Result = result;
            }

            ViewData[Constants.FormSubmit] = submitInfo;

            return(View(model));
        }
Ejemplo n.º 5
0
        public virtual void Visit(FormSubmit formSubmit, HtmlContainer htmlContainer)
        {
            HtmlDiv htmlDiv = verbose ? new HtmlDiv(formSubmit.Path) : new HtmlDiv();

            htmlDiv.Class.Add("formButton");

            if (!string.IsNullOrWhiteSpace(formSubmit.CssClass))
            {
                htmlDiv.Class.AddRange(formSubmit.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            if (!string.IsNullOrWhiteSpace(formSubmit.Path))
            {
                htmlDiv.Class.Add(string.Format("{0}{1}", "formId", formSubmit.Path));
            }

            htmlDiv.Hidden.Value = formSubmit.IsHidden;

            htmlContainer.Add(htmlDiv);

            HtmlSubmit htmlSubmit = new HtmlSubmit(formSubmit.Path, verbose, formSubmit.Parameter);

            htmlSubmit.Class.AddRange(new string[] { "btnFix", "btn", "mt-2" });

            switch (formSubmit.Type)
            {
            case ButtonType.Primary:
            case ButtonType.Secondary:
            case ButtonType.Success:
            case ButtonType.Danger:
                htmlSubmit.Class.Add(string.Format("btn-{0}", formSubmit.Type.ToString().ToLower()));
                break;

            default:
            case ButtonType.NotSet:
                break;
            }

            htmlSubmit.Disabled.Value = formSubmit.IsDisabled;
            htmlDiv.Add(htmlSubmit);

            htmlSubmit.Add(new HtmlText(formSubmit.Content));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(EditPostViewModel model)
        {
            FormSubmit submitInfo = new FormSubmit
            {
                IndexUrl = Url.Action(nameof(Index), "Post")
            };

            if (ModelState.IsValid)
            {
                Post post = await _post.GetPostAsync(model.Id);

                post.Title               = model.Title;
                post.Content             = model.Content;
                post.RowModifiedBy       = Convert.ToInt32(_userManager.GetUserId(User));
                post.RowModifiedDateTime = DateTime.Now;

                Result result = new Result(false, "Unable to edit post at this time.");

                try
                {
                    await _post.EditPostAsync(post);

                    result.Succeeded = true;
                    result.Message   = "Post edited.";
                }
                catch (Exception ex)
                {
                    SysException exception = new SysException(ex)
                    {
                        Url = UrlHelper.GetRequestUrl(HttpContext)
                    };
                }

                submitInfo.Result = result;
            }

            ViewData[Constants.FormSubmit] = submitInfo;

            return(View(model));
        }
Ejemplo n.º 7
0
 protected void OnFormSubmit(EventArgs e) => FormSubmit?.Invoke();
Ejemplo n.º 8
0
        protected override Page DowloadContent(Request request, ISpider spider)
        {
            Site site = spider.Site;

            try
            {
                lock (_locker)
                {
                    _webDriver = _webDriver ?? WebDriverExtensions.Open(_browser, _option);

                    if (!_isLogined && Login != null)
                    {
                        _isLogined = Login.Handle(_webDriver as RemoteWebDriver);
                        if (!_isLogined)
                        {
                            throw new DownloadException("Login failed. Please check your login codes.");
                        }
                    }
                }

                Uri uri = request.Url;

                //#if NET_CORE
                //				string query = string.IsNullOrEmpty(uri.Query) ? "" : $"?{WebUtility.UrlEncode(uri.Query.Substring(1, uri.Query.Length - 1))}";
                //#else
                //				string query = string.IsNullOrEmpty(uri.Query) ? "" : $"?{HttpUtility.UrlPathEncode(uri.Query.Substring(1, uri.Query.Length - 1))}";
                //#endif
                //				string realUrl = $"{uri.Scheme}://{uri.DnsSafeHost}{(uri.Port == 80 ? "" : ":" + uri.Port)}{uri.AbsolutePath}{query}";

                //var domainUrl = $"{uri.Scheme}://{uri.DnsSafeHost}{(uri.Port == 80 ? "" : ":" + uri.Port)}";

                //var options = _webDriver.Manage();
                //if (options.Cookies.AllCookies.Count == 0 && spider.Site.Cookies?.PairPart.Count > 0)
                //{
                //	_webDriver.Url = domainUrl;
                //	options.Cookies.DeleteAllCookies();
                //	if (spider.Site.Cookies != null)
                //	{
                //		foreach (var c in spider.Site.Cookies.PairPart)
                //		{
                //			options.Cookies.AddCookie(new Cookie(c.Key, c.Value));
                //		}
                //	}
                //}

                string realUrl = request.Url.ToString();

                NetworkCenter.Current.Execute("webdriver-download", () =>
                {
                    _webDriver.Navigate().GoToUrl(realUrl);

                    NavigateCompeleted?.Invoke((RemoteWebDriver)_webDriver);
                });

                Thread.Sleep(_webDriverWaitTime);

                #region [WDY]

                #region [WDY] 表单填充+提交

                if (FormSubmit != null)
                {
                    FormSubmit.Handle(_webDriver as RemoteWebDriver);
                }

                #endregion

                #region [WDY] 弹出页面

                if (_returnPopupPage)
                {
                    var currentWindowHandle = _webDriver.CurrentWindowHandle;
                    var popupWindowHandle   = string.Empty;
                    foreach (var handle in _webDriver.WindowHandles)
                    {
                        if (handle != currentWindowHandle)
                        {
                            popupWindowHandle = handle;
                            break;
                        }
                    }
                    if (!string.IsNullOrEmpty(popupWindowHandle))
                    {
                        _webDriver.SwitchTo().Window(popupWindowHandle);
                    }
                }

                #endregion

                // [WDY] 页面内容, 禁止移动位置
                string content = _webDriver.PageSource;

                #region [WDY] iframe

                /*
                 *  [WDY] Iframe 设置
                 *  ReturnIframe = true 时, 返回 Iframe 的 html
                 */

                string iframeContent = null;
                if (_option.IframeOption != null && _option.IframeOption.ReturnIframe)
                {
                    if (!string.IsNullOrEmpty(_option.IframeOption.IframeUrl) || !string.IsNullOrEmpty(_option.IframeOption.IframeName))
                    {
                        var iframeElement = !string.IsNullOrEmpty(_option.IframeOption.IframeUrl)
                            ? _webDriver.FindElement(By.XPath($"//iframe[contains(@src,'{_option.IframeOption.IframeUrl}')]"))
                            : _webDriver.FindElement(By.XPath($"//iframe[contains(@name,'{_option.IframeOption.IframeName}')]"));

                        _webDriver.SwitchTo().Frame(iframeElement); // 此处 switchTo iframe 后, 下边 _webDriver.PageSource 则会返回iframe的html

                        iframeContent = _webDriver.PageSource;

                        //_webDriver.SwitchTo().ParentFrame();
                    }
                }

                #endregion

                #endregion

                Page page = new Page(request, site.RemoveOutboundLinks ? site.Domains : null)
                {
                    Content       = _webDriver.PageSource,
                    IframeContent = iframeContent,  //[WDY]
                    TargetUrl     = _webDriver.Url,
                    Title         = _webDriver.Title
                };

                // 结束后要置空, 这个值存到Redis会导置无限循环跑单个任务
                //request.PutExtra(Request.CycleTriedTimes, null);
                return(page);
            }
            catch (DownloadException de)
            {
                Page page = new Page(request, null)
                {
                    Exception = de
                };
                if (site.CycleRetryTimes > 0)
                {
                    page = Spider.AddToCycleRetry(request, site);
                }
                Logger.AllLog(spider.Identity, $"下载 {request.Url} 失败: {de.Message}.", NLog.LogLevel.Warn);
                return(page);
            }
            catch (Exception e)
            {
                Logger.AllLog(spider.Identity, $"下载 {request.Url} 失败: {e.Message}.", NLog.LogLevel.Warn);
                Page page = new Page(request, null)
                {
                    Exception = e
                };
                return(page);
            }
        }
Ejemplo n.º 9
0
 public void Save(FormSubmit i)
 {
 }
Ejemplo n.º 10
0
        public IActionResult IMDB()
        {
            FormSubmit t = new FormSubmit();

            return(View(t));
        }