public object PostAuthor(DtoAuthor model)
        {
            var checkAuthorName = _context.Author.Where(c => c.Name == model.AuthorName).Any();

            if (checkAuthorName)
            {
                return(false);
            }

            Author author = new Author();

            author.Name        = model.AuthorName;
            author.Biography   = model.Biography;
            author.BirthDate   = model.BirthDate;
            author.DocumetIdFk = model.ImageIdFk;
            author.CreatedBy   = "Test:Safa";
            author.CreatedDate = DateTime.Now;

            this.Add(author);
            this.Save();

            model.AuthorId = author.Id;

            return(model);
        }
Ejemplo n.º 2
0
        public List <DtoAuthor> GetAll()
        {
            var dtoauthors = new List <DtoAuthor>();

            using (var client = new HttpClient())
            {
                var uri = new Uri("http://localhost/WebAPI/api/author/GetAll");

                var response = client.GetAsync(uri).Result;

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.ToString());
                }

                var responseContent = response.Content;
                var responseString  = responseContent.ReadAsStringAsync().Result;

                dynamic authors = JArray.Parse(responseString) as JArray;

                foreach (var obj in authors)
                {
                    DtoAuthor dto = obj.ToObject <DtoAuthor>();

                    dtoauthors.Add(dto);
                }
            }

            return(dtoauthors);
        }
        public DtoAuthor GetAuthor(Guid id)
        {
            var author = this.GetById(id);

            DtoAuthor model = _mapper.Map <Author, DtoAuthor>(author);

            return(model);
        }
Ejemplo n.º 4
0
        public void Update(DtoAuthor dto)
        {
            var author = pc.Author.Single(a => a.AuthorId == dto.AuthorId);

            author.FirstName = dto.FirstName;
            author.LastName  = dto.LastName;

            pc.SaveChanges();
        }
Ejemplo n.º 5
0
        public void Add(AuthorVM.Author author)
        {
            var dto = new DtoAuthor
            {
                FirstName = author.FirstName,
                LastName  = author.LastName
            };

            svc.Add(dto);
        }
Ejemplo n.º 6
0
        public void Add(DtoAuthor dto)
        {
            var author = new Author
            {
                FirstName = dto.FirstName,
                LastName  = dto.LastName
            };

            pc.Author.Add(author);
            pc.SaveChanges();
        }
Ejemplo n.º 7
0
        public void Update(AuthorVM.Author author)
        {
            var dto = new DtoAuthor
            {
                AuthorId  = author.AuthorID,
                FirstName = author.FirstName,
                LastName  = author.LastName
            };

            svc.Update(dto);
        }
Ejemplo n.º 8
0
        public async Task Add(DtoAuthor dto)
        {
            var author = new Author
            {
                FirstName = dto.FirstName,
                LastName  = dto.LastName
            };

            pc.Author.Add(author);
            await pc.SaveChangesAsync();
        }
Ejemplo n.º 9
0
        public async Task Update(DtoAuthor dto)
        {
            var author = new Author
            {
                AuthorId  = dto.AuthorId,
                FirstName = dto.FirstName,
                LastName  = dto.LastName
            };

            pc.Entry(author).State = EntityState.Modified;
            await pc.SaveChangesAsync();
        }
Ejemplo n.º 10
0
        private void mView_Send(object sender, EventArgs e)
        {
            var dto = new DtoAuthor {
                AuthorId = mView.AuthorId, FirstName = mView.FirstName, LastName = mView.LastName
            };

            if (dto.AuthorId > 0)
            {
                mView.Message = _authorDm.Update(dto);
            }
            else
            {
                mView.Message = _authorDm.Add(dto);
            }
        }
Ejemplo n.º 11
0
        public object UpdateAuthor(DtoAuthor model)
        {
            Author author = this.GetById(model.AuthorId);

            author.Name        = model.AuthorName;
            author.Biography   = model.Biography;
            author.BirthDate   = model.BirthDate;
            author.DocumetIdFk = model.ImageIdFk;
            author.UpdatedBy   = model.UpdatedBy;
            author.UpdatedDate = DateTime.Now;

            this.Update(author);
            this.Save();

            return(model);
        }
Ejemplo n.º 12
0
        public string Update(DtoAuthor dto)
        {
            if (dto.FirstName == "")
            {
                return("FirstName cannot be blank.");
            }

            if (dto.LastName == "")
            {
                return("LastName cannot be blank.");
            }

            _daoAuthor.Update(dto);

            return("Author was updated.");
        }
Ejemplo n.º 13
0
        public string Add(DtoAuthor dto)
        {
            if (dto.FirstName == "")
            {
                return("FirstName cannot be blank.");
            }

            if (dto.LastName == "")
            {
                return("LastName cannot be blank.");
            }

            _daoAuthor.Add(dto);

            return("Author was added.");
        }
Ejemplo n.º 14
0
        public async Task <DtoAuthor> Find(int id)
        {
            var dto = new DtoAuthor();

            var author = await pc.Author.FindAsync(id);

            if (author != null)
            {
                dto.AuthorId  = author.AuthorId;
                dto.FirstName = author.FirstName;
                dto.LastName  = author.LastName;
            }
            else
            {
                throw new Exception($"Author with ID = {id} was not found.");
            }

            return(dto);
        }
Ejemplo n.º 15
0
        public DtoAuthor Find(int id)
        {
            var dto = new DtoAuthor();

            var author = pc.Author.AsNoTracking().SingleOrDefault(a => a.AuthorId == id);

            if (author != null)
            {
                dto.AuthorId  = author.AuthorId;
                dto.FirstName = author.FirstName;
                dto.LastName  = author.LastName;
            }
            else
            {
                throw new Exception($"Author with ID = {id} was not found.");
            }

            return(dto);
        }
Ejemplo n.º 16
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            AuthorId          = 0;
            FirstName         = "";
            LastName          = "";
            lblAuthorID.Text  = "000";
            tbxFirstName.Text = "";
            tbxLastName.Text  = "";

            var dto = new DtoAuthor {
                AuthorId = 0, FirstName = "", LastName = ""
            };

            dtoauthors.Add(dto);

            currentauthoridx = dtoauthors.Count - 1;

            btnSend.Enabled   = false;
            btnDelete.Enabled = false;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 添加一条新闻
        /// </summary>
        /// <param name="model">新闻实体</param>
        /// <returns></returns>
        public static int Insert(DtoAuthor model)
        {
            try
            {
                if (model.Author == null)
                {
                    model.Author = "";
                }
                if (model.AuthorId == null)
                {
                    return(-1);
                }
                if (model.Url == null)
                {
                    return(-1);
                }

                var item = new T_Author()
                {
                    Author       = model.Author,
                    CreateTime   = DateTime.Now,
                    AuthorId     = model.AuthorId,
                    IsDeal       = model.IsDeal,
                    LastDealTime = DateTime.Now,
                    Url          = model.Url,
                    IsShow       = 0,
                    GroupId      = model.GroupId
                };


                var id = Sql.InsertId <T_Author>(item);

                return(id);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message + ex.StackTrace);
                return(-1);
            }
        }
Ejemplo n.º 18
0
        public void Add(DtoAuthor dto)
        {
            using (var client = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            })
            {
                string serailizeddto = JsonConvert.SerializeObject(dto);

                var inputMessage = new HttpRequestMessage
                {
                    Content = new StringContent(serailizeddto, Encoding.UTF8, "application/json")
                };

                inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage message =
                    client.PostAsync("WebAPI/api/author/Add", inputMessage.Content).Result;

                if (!message.IsSuccessStatusCode)
                {
                    throw new Exception(message.ToString());
                }
            }
        }
Ejemplo n.º 19
0
 public object UpdateAuthor(DtoAuthor model)
 {
     return(_authorService.UpdateAuthor(model));
 }
Ejemplo n.º 20
0
 public async Task Add(DtoAuthor dto)
 {
     await dao.Add(dto);
 }
Ejemplo n.º 21
0
 public object PostAuthor(DtoAuthor model)
 {
     return(_authorService.PostAuthor(model));
 }
Ejemplo n.º 22
0
 public async Task Update(DtoAuthor dto)
 {
     await dao.Update(dto);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// 根据搜索关键字搜索百家号的文章的url,再从文章取作者的url
        /// </summary>
        /// <param name="newsListUrl"></param>
        /// <param name="newsType"></param>
        /// <returns></returns>
        public int GatheringAuthorUrlFromSearch2(string keywords, int newsType, int searchPageIndex)
        {
            if (string.IsNullOrWhiteSpace(keywords))
            {
                return(0);
            }
            //百家号地址计数器,如果当前搜索页百家号地址小于2则不再读取下一页数据
            var iBjhCount = 0;
            //有效的百家号计数器
            var iHaveValidBjh = 0;
            //每次循环没有百家号计数
            var iContinueNo = 0;
            var strContent  = "";

            //贡献文章 总阅读数 作者文章 按时间
            //keywords = keywords.Replace("贡献文章", "\"贡献文章\"");
            //keywords = keywords.Replace("总阅读数", "\"总阅读数\"");
            //keywords = keywords.Replace("作者文章", "\"作者文章\"");
            //keywords = keywords.Replace("按时间", "\"按时间\"");

            keywords = keywords.Replace("贡献文章 ", "");
            keywords = keywords.Replace("贡献文章", "");
            keywords = keywords.Replace("总阅读数 ", "");
            keywords = keywords.Replace("总阅读数", "");
            keywords = keywords.Replace("作者文章 ", "");
            keywords = keywords.Replace("作者文章", "");
            keywords = keywords.Replace("按时间", "");

            //用来记录搜索关键字
            var groupid = keywords;

            if (groupid.Length > 50)
            {
                groupid = groupid.Substring(0, 30);
            }
            //keywords = keywords.Replace(" ","").Replace("\\","").Replace("%20","");
            keywords = keywords.Replace(" ", "%20");
            //keywords = System.Web.HttpUtility.UrlEncode(keywords);

            //var site = "%20site%3Abaijiahao.baidu.com";
            var inurl = "inurl%3Abaijiahao.baidu.com%20\"本文系作者授权百家号发表\"";

            var url = "https://www.baidu.com/s?wd=" + keywords + inurl;

            try
            {
                if (searchPageIndex > 0)
                {
                    url += "&pn=" + searchPageIndex * 10;
                }
                Log.Info(url + " 搜索 页码" + searchPageIndex);

                #region === 取内容 ===
                strContent = HttpHelper.GetContent(url, Encoding.UTF8);
                if (string.IsNullOrWhiteSpace(strContent))
                {
                    Thread.Sleep(1 * 1000);
                    //重新请求一次,因为用了代理后,经常会失败
                    strContent = HttpHelper.GetContentByAgent(url, Encoding.UTF8);
                    if (string.IsNullOrWhiteSpace(strContent))
                    {
                        //HttpHelper.IsUseProxy = false;
                        //重新请求一次,因为用了代理后,经常会失败
                        Thread.Sleep(1 * 1000);
                        strContent = HttpHelper.GetContentByAgent(url, Encoding.UTF8);
                        //HttpHelper.IsUseProxy = true;
                        if (string.IsNullOrWhiteSpace(strContent))
                        {
                            Log.Info(url + " 未抓取到任何内容 页码" + searchPageIndex);
                        }
                    }
                }
                #endregion

                //Log.Info("===========begin =============="+url + " " + searchPageIndex);

                //Log.Info(strContent);

                //Log.Info("===========end ==============" + url + " " + searchPageIndex);



                #region === deal baijiahao ===
                if (!string.IsNullOrWhiteSpace(strContent))
                {
                    var lista = XpathHelper.GetOuterHtmlListByXPath(strContent, "//div[@class='f13']/a[1]");
                    if (lista != null && lista.Count > 0)
                    {
                        iBjhCount     = 0;
                        iHaveValidBjh = 0;
                        foreach (var a in lista)
                        {
                            var href = XpathHelper.GetAttrValueByXPath(a, "//a", "href");

                            #region === deal baijiahao news url ===
                            Thread.Sleep(1 * 1000);

                            var str = HttpHelper.GetContentByAgent(href, Encoding.UTF8);
                            if (string.IsNullOrWhiteSpace(str))
                            {
                                str = HttpHelper.GetContent(href, Encoding.UTF8);
                            }
                            //取百家号主页里的百家号名称,appid
                            var author = "";
                            var appId  = "";
                            if (!string.IsNullOrWhiteSpace(str))
                            {
                                try
                                {
                                    author = XpathHelper.GetInnerHtmlByXPath(str, "//div[@class='author-detail']/a/p", "").Replace("-百家号", "");
                                    appId  = XpathHelper.GetAttrValueByXPath(str, "//div[@class='author-detail']/a", "href");
                                    //u?app_id=1546166210605725&fr=bjhvideo&wfr=spider
                                    if (!string.IsNullOrWhiteSpace(appId))
                                    {
                                        var str2 = appId.Split('=');
                                        appId = str2[1].Replace("&fr", "");
                                    }
                                    else
                                    {
                                        var iIndex = str.IndexOf("\"app_id\":");
                                        if (iIndex > 0)
                                        {
                                            appId = str.Substring(iIndex + 10, 19).Replace("\",\"type", "").Replace("\"", "").Replace(",", "").Replace("type", "");
                                        }
                                        else
                                        {
                                            #region === 重新取内容处理 ===
                                            Thread.Sleep(1 * 1000);

                                            str = HttpHelper.GetContent(href, Encoding.UTF8);
                                            if (string.IsNullOrWhiteSpace(str))
                                            {
                                                str = HttpHelper.GetContentByAgent(href, Encoding.UTF8);
                                            }

                                            if (!string.IsNullOrWhiteSpace(str))
                                            {
                                                try
                                                {
                                                    author = XpathHelper.GetInnerHtmlByXPath(str, "//div[@class='author-detail']/a/p", "").Replace("-百家号", "");
                                                    appId  = XpathHelper.GetAttrValueByXPath(str, "//div[@class='author-detail']/a", "href");
                                                    //u?app_id=1546166210605725&fr=bjhvideo&wfr=spider
                                                    if (!string.IsNullOrWhiteSpace(appId))
                                                    {
                                                        var str2 = appId.Split('=');
                                                        appId = str2[1].Replace("&fr", "");
                                                    }
                                                    else
                                                    {
                                                        iIndex = str.IndexOf("\"app_id\":");
                                                        if (iIndex > 0)
                                                        {
                                                            appId = str.Substring(iIndex + 10, 19).Replace("\",\"type", "").Replace("\"", "").Replace(",", "").Replace("type", "");
                                                        }
                                                        else
                                                        {
                                                        }
                                                    }
                                                }
                                                catch { }
                                            }
                                            #endregion
                                        }
                                    }
                                }
                                catch (Exception ex)
                                { }
                            }
                            else
                            {
                                Log.Info("取百家号主页内容没取到 href=" + href);
                            }
                            if (string.IsNullOrWhiteSpace(appId))
                            {
                                Log.Info("appid没取到 内容如下=== begin === href=" + href);
                                //Log.Info(str);
                                Log.Info("appid没取到 内容如下=== end === href" + href);
                                continue;
                            }
                            #region === 判断是否已存在 ===
                            var isHave = DalNews.IsExistsAuthor_Bjh(appId);
                            if (!isHave)
                            {
                                iHaveValidBjh++;
                                var model = new DtoAuthor()
                                {
                                    Author          = author,
                                    AuthorId        = appId,
                                    GroupId         = groupid,
                                    IntervalMinutes = 60,
                                    IsDeal          = 0,
                                    IsShow          = 0,
                                    LastDealTime    = DateTime.Now,
                                    RefreshTimes    = 0,
                                    Url             = "http://baijiahao.baidu.com/u?app_id=" + appId,
                                };
                                var id = DalNews.Insert_Author_Bjh(model);
                                Log.Info("keyword" + keywords + "authodid=" + id);
                            }
                            else
                            {
                                //iHaveValidBjh = 0;
                                Log.Info("appid" + appId + "已存在");
                            }
                            #endregion


                            #endregion
                        }
                    }
                }
                else
                {
                    Log.Error("url=" + url + " 无内容" + DateTime.Now);
                }
                #endregion

                //如果当前页有百家号>=3则翻页,否则结束
                if (iBjhCount >= 3)
                {
                    //当翻页到后面且没有新的百家号时退出,不再翻页
                    if (iHaveValidBjh < 1 && searchPageIndex > 30)
                    {
                        return(0);
                    }
                    searchPageIndex++;
                    GatheringAuthorUrlFromSearch(keywords, newsType, searchPageIndex);
                }
            }
            catch (Exception ex)
            {
                Log.Error("url=" + url + " " + DateTime.Now);
                Log.Error(ex.Message + ex.StackTrace);
            }
            return(0);
        }