예제 #1
0
        private async Task <ArticleModel> MapArticleResultToModelAsync(ArticleResult articleResult)
        {
            var article = new ArticleModel()
            {
                ArticleCategoryId   = articleResult.ArticleCategoryId,
                ArticleCategoryName = articleResult.ArticleCategoryName,
                Content             = articleResult.Content,
                Id                 = articleResult.Id,
                CreatedBy          = articleResult.CreatedBy,
                CreatedById        = articleResult.CreatedById,
                CreatedDate        = articleResult.CreatedDate,
                Description        = articleResult.Description,
                Name               = articleResult.Name,
                CreatedByPhotoCode = articleResult.CreatedByPhotoCode
            };

            if (articleResult.Picture != null)
            {
                article.Picture = new PictureRequestModel()
                {
                    PictureId = articleResult.Picture.Id
                };
            }

            article.CreatedByIdentityId = await _userManager.EncryptUserIdAsync(article.CreatedById);

            return(article);
        }
예제 #2
0
        public static ArticleListViewModel Create(ArticleResult result, int parentEntityId, string tabId)
        {
            var model = Create <ArticleListViewModel>(tabId, parentEntityId);

            model.ContentId = parentEntityId;
            model.Init(result);
            return(model);
        }
예제 #3
0
        public static ArticleListViewModel Create(ArticleResult result, int parentEntityId, string tabId, bool allowMultipleEntitySelection, bool isSelect, int[] ids)
        {
            var model = Create(result, parentEntityId, tabId);

            model.AllowMultipleEntitySelection = allowMultipleEntitySelection;
            model.IsSelect    = isSelect;
            model.SelectedIDs = ids;
            return(model);
        }
예제 #4
0
        public static ArticleListViewModel Create(ArticleResult result, int parentEntityId, string tabId, bool allowMultipleEntitySelection, bool isSelect, int id)
        {
            var selectedIds = new int[] { };

            if (id > 0)
            {
                selectedIds = new[] { id };
            }

            return(Create(result, parentEntityId, tabId, allowMultipleEntitySelection, isSelect, selectedIds));
        }
예제 #5
0
 public bool Execute()
 {
     try
     {
         Result = new ArticleScrape(Parameters).Execute();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #6
0
        // GET api/<controller>
        public IHttpActionResult GetAll()
        {
            var resultsToShow = 20;
            var pageNumber    = 1;
            var fromDate      = new DateTime(2018, 1, 1);
            var country       = "gb";

            var pageSize  = Request.GetQueryString("pageSize");
            var page      = Request.GetQueryString("page");
            var from      = Request.GetQueryString("fromDate");
            var countryQs = Request.GetQueryString("country");

            if (!string.IsNullOrEmpty(pageSize))
            {
                resultsToShow = Convert.ToInt16(pageSize);
            }

            if (!string.IsNullOrEmpty(page))
            {
                pageNumber = Convert.ToInt16(page);
            }

            if (!string.IsNullOrEmpty(from))
            {
                fromDate = Convert.ToDateTime(from);
            }

            if (!string.IsNullOrEmpty(countryQs))
            {
                country = countryQs;
            }


            var rowStart = 1 + (pageNumber * resultsToShow) - resultsToShow;

            var a = _articleResultRepository.GetAll(fromDate, resultsToShow, country, rowStart);

            var result = new ArticleResult();

            if (a.Any())
            {
                result.TotalResults = a[0].TotalResults;
                result.Articles     = a[0].Articles.ToList();
            }


            return(Json(result));
        }
        public ArticleResult ConvertToResult(string result)
        {
            HtmlDocument htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(result);
            var node = htmlDocument.DocumentNode;

            ArticleResult a = new ArticleResult()
            {
                Title      = (node.Descendants("h1").FirstOrDefault()?.InnerText ?? string.Empty).Trim(),
                ViewsCount = (node.Descendants("p").FirstOrDefault(c => c.Attributes["class"]?.Value == "views-count")?.InnerText ?? string.Empty).Trim(),
                AuthorTime = (node.Descendants("p").FirstOrDefault(c => c.Attributes["class"]?.Value == "author-time")?.InnerText ?? string.Empty).Trim(),
                Content    = (node.Descendants("div").FirstOrDefault(c => c.Attributes["class"]?.Value == "post-content")?.InnerHtml ?? string.Empty).Trim()
            };

            a.Title      = System.Net.WebUtility.HtmlDecode(a.Title);
            a.AuthorTime = a.AuthorTime.Replace("\n", string.Empty).RemoveDoubleSpaces();

            return(a);
        }
예제 #8
0
        public void Init(ArticleResult result)
        {
            ContentName          = result.ContentName;
            IsVirtual            = result.IsVirtual;
            ShowAddNewItemButton = result.IsUpdatable && result.IsAddNewAccessable && !IsWindow && !result.ContentDisableChangingActions;

            if (result is ArticleInitListResult listResult)
            {
                TitleFieldName = listResult.TitleFieldName;
                PageSize       = listResult.PageSize;
                DisplayFields  = listResult.DisplayFields;
            }

            if (result is ArticleInitTreeResult treeResult)
            {
                IsTree            = true;
                CustomFilter      = treeResult.Filter;
                AutoCheckChildren = treeResult.AutoCheckChildren;
            }
        }
        public WikiDownArticleHtmlString(ArticleResult articleResult, Repository repository)
        {
            if (articleResult == null)
            {
                throw new ArgumentNullException("articleResult");
            }
            if (articleResult.ArticleRevision == null)
            {
                throw new ArgumentOutOfRangeException(
                          "articleResult",
                          "ArticleResult cannot have a null ArticleRevision.");
            }
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            this.html       = MarkdownService.MakeHtml(articleResult.ArticleRevision.MarkdownContent);
            this.repository = repository;
        }
예제 #10
0
        public ArticleResult ConvertToResult(string result)
        {
            HtmlDocument htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(result);
            var node = htmlDocument.DocumentNode;

            ArticleResult a = new ArticleResult()
            {
                Title = (node.Descendants("h1").FirstOrDefault()?.InnerText ?? string.Empty).Trim(),
                //Author = (node.Descendants("a").FirstOrDefault()?.InnerText ?? string.Empty).Trim(),
                //ViewsCount = (node.Descendants("span").FirstOrDefault()?.InnerText ?? string.Empty).Trim(),
                Content = (node.Descendants("div").FirstOrDefault(c => c.Attributes["id"]?.Value == "articleContainerColumnLeft")?.InnerHtml ?? string.Empty).Trim()
            };

            a.Title   = System.Net.WebUtility.HtmlDecode(a.Title);
            a.Content = System.Net.WebUtility.HtmlDecode(a.Content).Replace("\t", "").Replace("\n", "");
            a.Content = Regex.Replace(a.Content, "<!--.*?-->", "", RegexOptions.Singleline);

            return(a);
        }
예제 #11
0
        public List <ArticleResult> GetFeed(string userId)
        {
            var result   = new List <ArticleResult>();
            var articles = _departmentProfileService.GetArticlesForUser(userId);

            foreach (var article in articles)
            {
                var articleResult = new ArticleResult();
                articleResult.Id              = article.DepartmentProfileArticleId;
                articleResult.Title           = article.Title;
                articleResult.Body            = article.Body;
                articleResult.SmallImage      = article.SmallImage;
                articleResult.LargeImage      = article.LargeImage;
                articleResult.Keywords        = article.Keywords;
                articleResult.CreatedOn       = article.CreatedOn;
                articleResult.CreatedByUserId = article.CreatedByUserId;
                articleResult.StartOn         = article.StartOn;
                articleResult.ExpiresOn       = article.ExpiresOn;

                result.Add(articleResult);
            }

            return(result);
        }
 internal void InitializeNewArticle(ArticleResult article)
 {
     ArticleLoading = false;
     Articles.Clear();
     Articles.Add(article);
 }
예제 #13
0
        private ArticleResult FetchArticles()
        {
            var country       = Request.QueryString.Get("country");
            var duration      = Request.QueryString.Get("duration");
            var resultsToShow = Request.QueryString.Get("results");
            var page          = Request.QueryString.Get("page");

            var result = new ArticleResult();

            var api = new RestClient(Baseurl);

            var fromDate = new Parameter
            {
                Type  = ParameterType.QueryString,
                Name  = "fromDate",
                Value = DateTime.Now.AddHours(-6).ToString("yyyy-MM-ddTHH:mm:ss")
            };

            if (duration != null)
            {
                if (int.TryParse(duration, out int dur))
                {
                    fromDate.Value = DateTime.Now.AddHours(-dur).ToString("yyyy-MM-ddTHH:mm:ss");
                }
            }

            var pageNumber = new Parameter
            {
                Type  = ParameterType.QueryString,
                Name  = "page",
                Value = 1
            };

            if (page != null)
            {
                if (int.TryParse(page, out int p))
                {
                    pageNumber.Value = p;
                }
            }


            var pageSize = new Parameter
            {
                Type  = ParameterType.QueryString,
                Name  = "pageSize",
                Value = 50
            };

            if (resultsToShow != null)
            {
                if (int.TryParse(resultsToShow, out int r))
                {
                    pageSize.Value = r;
                }
            }


            var request = new RestRequest("api/Articles", Method.GET);

            request.AddParameter(fromDate);
            request.AddParameter(pageNumber);
            request.AddParameter(pageSize);

            if (country != null)
            {
                request.AddParameter(new Parameter
                {
                    Type  = ParameterType.QueryString,
                    Name  = "country",
                    Value = country
                });
            }

            var queryResult = api.Execute <ArticleResult>(request).Data;

            return(queryResult);
        }