public EnvelopeDTO <GenericDummyDTO> Any(ContentUpdateImagesRequestDTO req) { var contentId = req.ContentId; if (contentId == null) { return(Fail <GenericDummyDTO>("ContentUpdateImagesRequestDTO : parameter 'ContentId' is empty.")); } using (var entities = new CrawlerStorage()) { try { var content = entities.Contents.SingleOrDefault(p => p.Id == contentId); //content.Srcdatas = req.SrcData.Select(p => new Srcdata //{ // SourceUrl = p.SourceUrl, // Content = content, // SrcGuId = new Guid(), //}).ToList(); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (Exception e) { return(Fail <GenericDummyDTO>("ContentUpdateImagesRequestDTO : Exception - " + e.Message)); } } }
public EnvelopeDTO <GenericDummyDTO> Any(SnapshotToContentRevisionUpdateRequestDTO req) { var Has_ContentRevisioid = req.Has_ContentRevisionId; var for_snapshotid = req.For_SnapshotId; var seqno = req.Seqno; using (var entities = new CrawlerStorage()) { try { var snapshotTocontentrevision = entities.SnapshotToContentRevisions.SingleOrDefault(p => p.Has_ContentRevisionId == Has_ContentRevisioid); snapshotTocontentrevision.For_SnapshotId = for_snapshotid.Value; snapshotTocontentrevision.Seqno = seqno.Value; entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } }
/// <summary> /// SnapshotToContent를 For_SnapshotId, Has_ContentId, Seqno 통해서 Create 하는 함수 /// </summary> /// <param name="req"> /// For_SnapshotId /// </param> /// <param name="req"> /// Has_ContentId /// </param> /// <param name="req"> /// Seqno /// </param> /// <returns></returns> public EnvelopeDTO <GenericDummyDTO> Any(SnapshotToContentRevisionCreateRequestDTO req) { var For_SnapshotId = req.For_SnapshotId; var Has_ContentRevisionId = req.Has_ContentRevisionId; var Seqno = req.Seqno; if (!For_SnapshotId.HasValue && Has_ContentRevisionId.HasValue && Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'For_SnapshotId' is empty.")); } if (For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue && Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'Has_ContentRevisionId' is empty.")); } if (For_SnapshotId.HasValue && Has_ContentRevisionId.HasValue && !Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'Seqno' is empty.")); } if (!For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue && Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'For_SnapshotId' && 'Has_ContentRevisionId' are empty.")); } if (!For_SnapshotId.HasValue && Has_ContentRevisionId.HasValue && !Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'For_SnapshotId' && 'Seqno' are empty.")); } if (For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue && !Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'Has_ContentRevisionId' && 'Seqno' are empty.")); } if (!For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue && !Seqno.HasValue) { return(Fail <GenericDummyDTO>("SnapshotToContentCreateRequestDTO : parameter 'For_SnapshotId' && 'Has_ContentRevisionId' && 'Seqno' are empty.")); } else { using (var entities = new CrawlerStorage()) { try { var snapshotTocontentrevision = new SnapshotToContentRevision(); snapshotTocontentrevision.For_SnapshotId = For_SnapshotId.Value; snapshotTocontentrevision.Has_ContentRevisionId = Has_ContentRevisionId.Value; snapshotTocontentrevision.Seqno = Seqno.Value; entities.SnapshotToContentRevisions.Add(snapshotTocontentrevision); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (Exception e) { return(Fail <GenericDummyDTO>("e")); } } } }
public EnvelopeDTO <List <ContentRevisionDTO> > Any(ContentRevisionListGetbyKeywordRequestDTO req) { var Keyword = req.Keyword; List <ContentRevisionDTO> searchedContentRevisionList = new List <ContentRevisionDTO>(); if (string.IsNullOrWhiteSpace(Keyword)) { return(Fail <List <ContentRevisionDTO> >("ContentRevisionListGetbyKeywordRequestDTO : parameter 'Keyword' is empty.")); } else { using (var entites = new CrawlerStorage()) { try { var contentRevisions = (from c in entites.ContentRevisions select c).ToList(); foreach (var eachcontentRevision in contentRevisions) { if (eachcontentRevision.Content.Article.Contains(Keyword)) { searchedContentRevisionList.Add(new ContentRevisionDTO { Crawled = eachcontentRevision.Crawled, Details = eachcontentRevision.Details, Details_Html = eachcontentRevision.Details_Html, Board = new BoardDTO { Website = new WebsiteDTO { Website_logo = eachcontentRevision.SnapshotToContentRevisions.First().Snapshot.Board.Website.website_logo, Website_URL = eachcontentRevision.SnapshotToContentRevisions.First().Snapshot.Board.Website.Website_URL, Label = eachcontentRevision.SnapshotToContentRevisions.First().Snapshot.Board.Website.Label } }, Content = new ContentDTO { Article = eachcontentRevision.Content.Article, Contents_URL = eachcontentRevision.Content.Contents_URL } }); } } if (searchedContentRevisionList.Count == 0) { return(Fail <List <ContentRevisionDTO> >("ContentRevisionListGetbyKeywordRequestDTO : contentRevisions is null")); } return(Succeeded(new List <ContentRevisionDTO>(searchedContentRevisionList))); } catch (Exception e) { return(Fail <List <ContentRevisionDTO> >("ContentRevisionListGetbyKeywordRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// Board를 Label, For_WebsiteId를 통해서 Create하는 함수 /// </summary> /// <param name="req"> /// Label /// </param> /// <param name="req"> /// For_WebsiteId /// </param> /// <returns></returns> public EnvelopeDTO <GenericDummyDTO> Any(BoardCreateRequestDTO req) { var Label = req.Label; var For_WebsiteId = req.For_WebsiteId; if (!For_WebsiteId.HasValue && !string.IsNullOrWhiteSpace(Label)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'For_WebsiteId' is empty.")); } if (For_WebsiteId.HasValue && string.IsNullOrWhiteSpace(Label)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'For_WebsiteId' is empty.")); } if (!For_WebsiteId.HasValue && string.IsNullOrWhiteSpace(Label)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'For_WebsiteId' && 'Label' are empty.")); } else { using (var entities = new CrawlerStorage()) { try { var board = new Board(); board.Label = Label; board.For_WebsiteId = For_WebsiteId.Value; entities.Boards.Add(board); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } } }
/// <summary> /// Content를 ContentDTO를 통해서 Create 하는 함수 /// </summary> /// <param name="req"> /// ContentDOT /// </param> /// <returns></returns> public EnvelopeDTO <GenericDummyDTO> Any(ContentCreateRequestDTO req) { var Content = req.Content; List <SrcdataDTO> SrcdataList = new List <SrcdataDTO> (); using (var entities = new CrawlerStorage()) { try { var content = new Content(); content.Contents_URL = Content.Contents_URL; content.Article = Content.Article; content.Url_Params = Content.Url_Params; content.ContentGuId = Guid.NewGuid(); entities.Contents.Add(content); //foreach (var data in Content.SrcDatas) //{ // var srcdata = new Srcdata(); // srcdata.SrcGuId = Guid.NewGuid(); // srcdata.SourceUrl = data.SourceUrl; // srcdata.Content = content; // entities.Srcdatas.Add(srcdata); //} entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } } }
/// <summary> /// SnapshotToContentDTO를 For_SnapshotId, Has_ContentId를 통해서 가져오는 함수 /// </summary> /// <param name="req"> /// For_SnapshotId /// </param> /// <param name="req"> /// Has_ContentId /// </param> /// <returns></returns> public EnvelopeDTO <SnapshotToContentRevisionDTO> Any(SnapshotToContentRevisionGetbyIdRequestDTO req) { var For_SnapshotId = req.For_SnapshotId; var Has_ContentRevisionId = req.Has_ContentRevisionId; if (!For_SnapshotId.HasValue && Has_ContentRevisionId.HasValue) { return(Fail <SnapshotToContentRevisionDTO>("SnapshotToContentRevisionGetbyIdRequestDTO : parameter 'For_SnapshotId' is empty.")); } if (For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue) { return(Fail <SnapshotToContentRevisionDTO>("SnapshotToContentRevisionGetbyIdRequestDTO : parameter 'Has_ContentRevisionId' is empty.")); } if (!For_SnapshotId.HasValue && !Has_ContentRevisionId.HasValue) { return(Fail <SnapshotToContentRevisionDTO>("SnapshotToContentRevisionGetbyIdRequestDTO : parameter 'For_SnapshotId' && 'Has_ContentRevisionId' are empty.")); } else { using (var entities = new CrawlerStorage()) { try { var snapshotTocontentrevision = (from s in entities.SnapshotToContentRevisions.AsNoTracking() where s.For_SnapshotId == For_SnapshotId && s.Has_ContentRevisionId == Has_ContentRevisionId select new SnapshotToContentRevisionDTO { For_SnapshotId = s.For_SnapshotId, Has_ContentRevisionId = s.Has_ContentRevisionId, Seqno = s.Seqno }).SingleOrDefault(); if (snapshotTocontentrevision == null) { return(Fail <SnapshotToContentRevisionDTO>("SnapshotToContentRevisionGetbyIdRequestDTO : SnapshotToContentREvision matching given 'snapshotTocontentrevision' does not exist.")); } return(Succeeded(snapshotTocontentrevision)); } catch (Exception e) { return(Fail <SnapshotToContentRevisionDTO>("SnapshotToContentRevisionGetbyIdRequestDTO : Exception - " + e.Message)); } } } }
public EnvelopeDTO <GenericDummyDTO> Any(TimePeriodCreateRequestDTO req) { var Scheduled = req.Scheduled; using (var entities = new CrawlerStorage()) { var LastTimepriods = entities.TimePeriods.Any(p => p.Scheduled == Scheduled); if (!LastTimepriods) { try { var timeperiod = new TimePeriod(); timeperiod.Scheduled = Scheduled.Value; timeperiod.ShortGuid = Guid.NewGuid(); entities.TimePeriods.Add(timeperiod); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } else { return(Fail <GenericDummyDTO>("TimePeriodCreateRequestDTO : parameter 'Scheduled' is already exist.")); } } }
/// <summary> /// WebsiteList를 가져오는 함수 /// </summary> /// <returns> /// WebsiteList /// </returns> public EnvelopeDTO <List <WebsiteDTO> > Any(WebsiteGetListRequestDTO req) { using (var entities = new CrawlerStorage()) { var websites = (from w in entities.Websites.AsNoTracking() orderby w.Id select new WebsiteDTO { Id = w.Id, Label = w.Label, Mobile_URL = w.Mobile_URL, Website_URL = w.Website_URL, Website_logo = w.website_logo }).ToList(); return(Succeeded(websites)); } }
/// <summary> /// Cotent를 contentId를 통해서 불러오는 함수 /// </summary>SSSSSS /// <param name="req"> /// ContentId /// </param> /// <returns></returns> public EnvelopeDTO <ContentRevisionDTO> Any(ContentRevisionGetbyCheckSumRequestDTO req) { var checksum = req.CheckSum; if (string.IsNullOrWhiteSpace(checksum)) { return(Fail <ContentRevisionDTO>("ContentRevisionGetbyCheckSumRequestDTO : parameter 'checksum' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { var contentrevision = (from c in entities.ContentRevisions.AsNoTracking() where c.CheckSum == checksum select new ContentRevisionDTO { id = c.Id //SrcDatas = (from src in c.Srcdatas // select new SrcdataDTO // { // Id = src.Id, // SrcGuId = src.SrcGuId, // For_ContentId = src.For_ContentId, // SourceUrl = src.SourceUrl // }).ToList() }).SingleOrDefault(); if (contentrevision == null) { return(Fail <ContentRevisionDTO>("ContentRevisionGetbyCheckSumRequestDTO : Contents matching given 'contentrevision' does not exist.")); } return(Succeeded(contentrevision)); } catch (Exception e) { return(Fail <ContentRevisionDTO>("ContentRevisionGetbyCheckSumRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// Srcdata를 For_ContentId를 통해서 가져오는 함수 /// </summary> /// <param name="req" /// For_ContentId /// ></param> /// <returns></returns> public EnvelopeDTO <List <SrcdataDTO> > Any(SrcdataGetbycontentIdRequestDTO req) { var For_ContentId = req.For_ContentId; if (!For_ContentId.HasValue) { return(Fail <List <SrcdataDTO> >("SrcdataGetbyIdRequestDTO : parameter 'For_ContentId' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { var srcdata = (from s in entities.Srcdatas.AsNoTracking() where s.For_ContentId == For_ContentId select new SrcdataDTO { Id = s.Id, SrcGuId = s.SrcGuId, SourceUrl = s.Original_SourceUrl, For_ContentId = s.For_ContentId, OriginalPayload = s.OriginalPayload, IsDepricated = s.IsDepricated }).ToList(); if (srcdata == null) { return(Fail <List <SrcdataDTO> >("SrcdataGetbyIdRequestDTO : Src matching given 'For_ContentId' does not exist.")); } return(Succeeded(srcdata)); } catch (Exception e) { return(Fail <List <SrcdataDTO> >("SrcdataGetbyIdRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// Website를 Website_Id를 통해서 불러오는 함수 /// </summary> /// <param name="req"> /// Website_Id /// </param> /// <returns></returns> public EnvelopeDTO <WebsiteDTO> Any(WebsiteGetbyIdRequestDTO req) { var websiteId = req.WebsiteId; if (!websiteId.HasValue) { return(Fail <WebsiteDTO>("WebsiteGetbyIdRequestDTO : parameter 'websiteId' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { var website = (from w in entities.Websites.AsNoTracking() where w.Id == websiteId select new WebsiteDTO { Id = w.Id, Label = w.Label, Website_URL = w.Website_URL, Mobile_URL = w.Mobile_URL, Website_logo = w.website_logo }).SingleOrDefault(); if (website == null) { return(Fail <WebsiteDTO>("WebsiteGetbyIdRequestDTO : Website matching given 'WebsiteId' does not exist.")); } return(Succeeded(website)); } catch (Exception e) { return(Fail <WebsiteDTO>("WebsiteGetbyIdRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// Timepriod를 TimeperiodId를 통해 가져오는 함수 /// </summary> /// <param name="req"> /// TimeperiodId /// </param> /// <returns> /// TimeperiodDTO /// </returns> public EnvelopeDTO <TimePeriodDTO> Any(TimePeriodGetbyIdRequestDTO req) { var TimeperiodId = req.TimeperiodId; if (TimeperiodId.HasValue) { return(Fail <TimePeriodDTO>("TimePeriodGetbyIdRequestDTO : parameter 'TimeperiodId' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { var timePeriod = (from t in entities.TimePeriods.AsNoTracking() where t.Id == TimeperiodId select new TimePeriodDTO { Id = t.Id, Label = t.Label, Scheduled = t.Scheduled, Crawled = t.Crawled }).SingleOrDefault(); if (timePeriod == null) { return(Fail <TimePeriodDTO>("TimePeriodGetbyIdRequestDTO : TimePeriod matching given 'WebsiteId' does not exist.")); } return(Succeeded(timePeriod)); } catch (Exception e) { return(Fail <TimePeriodDTO>("TimePeriodGetbyIdRequestDTO : Exception - " + e.Message)); } } } }
public EnvelopeDTO <ErrorLogDTO> Any(ErrorLogCreateRequestDTO req) { var ErrorLog = req.ErrorLog; using (var entities = new CrawlerStorage()) { try { var errorlog = new ErrorLog(); errorlog.Error_Address = ErrorLog.Error_Address; errorlog.Error_URL = ErrorLog.Error_URL; errorlog.Error_Details = ErrorLog.Error_Details; errorlog.Hresult = ErrorLog.Hresult; entities.ErrorLogs.Add(errorlog); entities.SaveChanges(); return(Succeeded(new ErrorLogDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } }
/// <summary> /// Cotent를 contentId를 통해서 불러오는 함수 /// </summary> /// <param name="req"> /// ContentId /// </param> /// <returns></returns> //public EnvelopeDTO<ContentDTO> Any(ContentGetbyIdRequestDTO req) //{ // var contentId = req.ContentId; // if (!contentId.HasValue) // { // return Fail<ContentDTO>("ContentGetbyIdRequestDTO : parameter 'contentId' is empty."); // } // else // { // using (var entities = new CrawlerStorage()) // { // try // { // var content = (from c in entities.Contents.AsNoTracking() // where c.Id == contentId // select new ContentDTO // { // Id = c.Id, // ContentGuId = c.ContentGuId, // Article = c.Article, // Contents_URL = c.Contents_URL, // //SrcDatas = (from src in c.Srcdatas // // select new SrcdataDTO // // { // // Id = src.Id, // // SrcGuId = src.SrcGuId, // // For_ContentId = src.For_ContentId, // // SourceUrl = src.SourceUrl // // }).ToList() // }).SingleOrDefault(); // if (content == null) // { // return Fail<ContentDTO>("ContentGetbyIdRequestDTO : Contents matching given 'contentId' does not exist."); // } // return Succeeded(content); // } // catch (Exception e) // { // return Fail<ContentDTO>("ContentGetbyIdRequestDTO : Exception - " + e.Message); // } // } // } //} public EnvelopeDTO <GenericDummyDTO> Any(ContentUpdateDeatilsRequestDTO req) { var contentId = req.ContentId; if (contentId == null) { return(Fail <GenericDummyDTO>("ContentUpdateDeatilsRequestDTO : parameter 'ContentId' is empty.")); } using (var entities = new CrawlerStorage()) { try { var content = entities.Contents.SingleOrDefault(p => p.Id == contentId); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (Exception e) { return(Fail <GenericDummyDTO>("ContentUpdateDeatilsRequestDTO : Exception - " + e.Message)); } } }
/// <summary> /// Board를 BoardId 를 통해서 불러오는 함수 /// </summary> /// <param name="req"> /// BoardId /// </param> /// <returns></returns> public EnvelopeDTO <BoardDTO> Any(BoardGetbyIdRequestDTO req) { var boardid = req.BoardId; if (!boardid.HasValue) { return(Fail <BoardDTO>("BoardGetRequestDTO : parameter 'boardid' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { var board = (from b in entities.Boards.AsNoTracking() where b.Id == boardid select new BoardDTO { Id = b.Id, For_WebsiteId = b.For_WebsiteId, Label = b.Label }).SingleOrDefault(); board.Website = (from w in entities.Websites.AsNoTracking() where w.Id == board.For_WebsiteId select new WebsiteDTO { Id = w.Id, Label = w.Label, Website_URL = w.Website_URL, Mobile_URL = w.Mobile_URL }).SingleOrDefault(); board.Snapshots = (from s in entities.Snapshots.AsNoTracking() where s.For_BoardId == board.Id select new SnapshotDTO { Id = s.Id, For_BoardId = s.For_BoardId, For_Timeperiod = s.For_Timeperiod, Taken = s.Taken, TimePeriod = new TimePeriodDTO { Id = s.TimePeriod.Id, Label = s.TimePeriod.Label, Crawled = s.TimePeriod.Crawled, Scheduled = s.TimePeriod.Scheduled }, Board = new BoardDTO { Id = s.Board.Id, Label = s.Board.Label, For_WebsiteId = s.Board.For_WebsiteId }, ContentRevisions = (from c in s.SnapshotToContentRevisions let con = c.ContentRevision select new ContentRevisionDTO { recommandCount = con.RecommandCount, viewCount = con.ViewCount, For_ContentId = con.For_ContentId, Details = con.Details, Details_Html = con.Details_Html, Content = new ContentDTO { Article = con.Content.Article, Contents_URL = con.Content.Contents_URL, } }).ToList() }).OrderByDescending(s => s.Id).ToList(); if (board == null) { return(Fail <BoardDTO>("BoardGetRequestDTO : Board matching given 'BoardId' does not exist.")); } return(Succeeded(board)); } catch (Exception e) { return(Fail <BoardDTO>("BoardGetRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// WebsiteList를 가져오는 함수 /// </summary> /// <returns> /// WebsiteList /// </returns> public EnvelopeDTO <List <BoardDTO> > Any(BoardGetListRequestDTO req) { using (var entities = new CrawlerStorage()) { var boards = (from b in entities.Boards.AsNoTracking() orderby b.Id select new BoardDTO { Id = b.Id, For_WebsiteId = b.For_WebsiteId, Label = b.Label, }).ToList(); foreach (var board in boards) { board.Website = (from w in entities.Websites.AsNoTracking() where w.Id == board.For_WebsiteId select new WebsiteDTO { Id = w.Id, Label = w.Label, Website_URL = w.Website_URL, Website_logo = w.website_logo, }).SingleOrDefault(); board.Snapshots = (from s in entities.Snapshots.AsNoTracking() where s.For_BoardId == board.Id select new SnapshotDTO { ContentRevisions = (from c in s.SnapshotToContentRevisions let con = c.ContentRevision select new ContentRevisionDTO { recommandCount = con.RecommandCount, viewCount = con.ViewCount, For_ContentId = con.For_ContentId, Details = con.Details, Details_Html = con.Details_Html, Crawled = con.Crawled, Content = new ContentDTO { Article = con.Content.Article, Contents_URL = con.Content.Contents_URL, } }).ToList() }).ToList(); List <ContentRevisionDTO> ContentRevisionList = new List <ContentRevisionDTO>(); List <ContentRevisionDTO> finalList = new List <ContentRevisionDTO>(); foreach (var snapshot in board.Snapshots) { foreach (var contentrevision in snapshot.ContentRevisions) { ContentRevisionList.Add(contentrevision); } } finalList = ContentRevisionList.GroupBy(p => p.For_ContentId).Select(g => g.First()).ToList(); board.Snapshots = null; board.ContentRevisions = finalList; } return(Succeeded(boards)); } }
public EnvelopeDTO <List <ContentRevisionDTO> > Any(ContentRevisionListGetbyBoardIdListRequestDTO req) { var boardid = req.boardId; List <ContentRevisionDTO> ContentRevisionList = new List <ContentRevisionDTO>(); if (!boardid.HasValue) { return(Fail <List <ContentRevisionDTO> >("BoardGetContentRevisionListRequestDTO : parameter 'boardid' is empty.")); } using (var entities = new CrawlerStorage()) { var board = (from b in entities.Boards.AsNoTracking() where b.Id == boardid select new BoardDTO { Id = b.Id, For_WebsiteId = b.For_WebsiteId, Label = b.Label, }).SingleOrDefault(); board.Snapshots = (from s in entities.Snapshots.AsNoTracking() where s.For_BoardId == board.Id select new SnapshotDTO { Id = s.Id, For_BoardId = s.For_BoardId, For_Timeperiod = s.For_Timeperiod, Taken = s.Taken, ContentRevisions = (from c in s.SnapshotToContentRevisions let con = c.ContentRevision select new ContentRevisionDTO { recommandCount = con.RecommandCount, viewCount = con.ViewCount, For_ContentId = con.For_ContentId, Details = con.Details, Details_Html = con.Details_Html, Crawled = con.Crawled, Board = new BoardDTO { Id = boardid.Value }, Content = new ContentDTO { Article = con.Content.Article, Contents_URL = con.Content.Contents_URL, } }).ToList() }).ToList(); foreach (var snapshot in board.Snapshots) { foreach (var contentrevision in snapshot.ContentRevisions) { ContentRevisionList.Add(contentrevision); } } var contentList1 = ContentRevisionList; List <ContentRevisionDTO> finalList = contentList1.GroupBy(p => p.For_ContentId).Select(g => g.First()).ToList(); return(Succeeded(finalList)); } }
public EnvelopeDTO <List <SnapshotDTO> > Any(SnapshotListGetbyDataAndBoardIdRequestDTO req) { var startdate = req.StartDate; var enddate = req.EndDate; List <int> BoardList = req.boardIdList; List <SnapshotDTO> SnapshotList = new List <SnapshotDTO>(); if (!startdate.HasValue && enddate.HasValue && BoardList.Count != 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'startdate' is empty.")); } if (startdate.HasValue && !enddate.HasValue && BoardList.Count != 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'enddate' is empty.")); } if (startdate.HasValue && enddate.HasValue && BoardList.Count == 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'BoardList' is empty.")); } if (!startdate.HasValue && !enddate.HasValue && BoardList.Count != 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'startdate' and 'enddate' is empty.")); } if (!startdate.HasValue && enddate.HasValue && BoardList.Count != 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'startdate' and 'BoardList' is empty.")); } if (startdate.HasValue && !enddate.HasValue && BoardList.Count != 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : parameter 'enddate' and 'BoardList' is empty.")); } else { using (var entities = new CrawlerStorage()) { try { foreach (var boardid in BoardList) { var snapshots = (from s in entities.Snapshots.AsNoTracking() where s.For_BoardId == boardid select new SnapshotDTO { Board = new BoardDTO { Id = s.Board.Id, Label = s.Board.Label, For_WebsiteId = s.Board.For_WebsiteId }, ContentRevisions = (from c in s.SnapshotToContentRevisions let con = c.ContentRevision select new ContentRevisionDTO { Crawled = con.Crawled, Details = con.Details, Details_Html = con.Details_Html, isDepricate = con.IsDepricated, }).ToList(), }).ToList(); foreach (var snapshot in snapshots) { SnapshotList.Add(snapshot); } } if (SnapshotList.Count == 0) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : SnapshotList is null")); } return(Succeeded(new List <SnapshotDTO>(SnapshotList))); } catch (Exception e) { return(Fail <List <SnapshotDTO> >("ContentRevisionListGetbyDataAndBoardIdRequestDTO : Exception - " + e.Message)); } } } }
/// <summary> /// Snapshot을 SnapshotDTO를 통해서 Create 하는 함수 /// </summary> /// <param name="req"> /// SnapshotDTO /// </param> /// <returns></returns> public EnvelopeDTO <SnapshotDTO> Any(SnapshotCreateRequestDTO req) { // 단정하기. Debug.Assert(req.Snapshot.Id == 0); Debug.Assert(req.Snapshot.ContentRevisions != null); var Snapshot = req.Snapshot; using (var entities = new CrawlerStorage()) { try { // 가장 최근의 TimePeriod를 가져온다. var timeperiod = entities.TimePeriods.OrderByDescending(t => t.Scheduled).FirstOrDefault(); var snapshot = new Snapshot { For_Timeperiod = timeperiod.Id, Taken = Snapshot.Taken, For_BoardId = Snapshot.For_BoardId }; entities.Snapshots.Add(snapshot); // 해당하는 boardId의 가장 최근의 Snapshot을 가져온다. var LastSnapshot = entities.Snapshots.Where(p => p.For_BoardId == Snapshot.For_BoardId).OrderByDescending(t => t.Id).FirstOrDefault(); if (LastSnapshot != null) { foreach (var eachCurrentRevision in Snapshot.ContentRevisions) { foreach (var eachLastRevision in LastSnapshot.SnapshotToContentRevisions) { if (eachCurrentRevision.CheckSum.Equals(eachLastRevision.ContentRevision.CheckSum)) { eachCurrentRevision.id = eachLastRevision.ContentRevision.Id; } } } } int contentseq = 0; List <long> sizelist = new List <long>(); if (Snapshot.ContentRevisions == null) { return(Fail <SnapshotDTO>("발생하면 안됨.")); } foreach (var contentRevision in Snapshot.ContentRevisions) { // 이미 뭔가 있는 상황 if (contentRevision.id != 0) { var snapshotTocontentrevision = new SnapshotToContentRevision { Has_ContentRevisionId = contentRevision.id, Seqno = ++contentseq, Snapshot = snapshot }; entities.SnapshotToContentRevisions.Add(snapshotTocontentrevision); continue; } // snapshotcontentrevision.id -> snapshotcontentrevision가 DB에 있었던 정보인지 아닌지 판단함 var newContentRevision = new ContentRevision { Details = contentRevision.Details, Details_Html = contentRevision.Details_Html, Crawled = contentRevision.Crawled, RecommandCount = contentRevision.recommandCount, ViewCount = contentRevision.viewCount, CheckSum = contentRevision.CheckSum }; var contentChecksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(contentRevision.Content.Url_Params)); var existingContent = entities.Contents.SingleOrDefault(p => p.CheckSum.Equals(contentChecksum)); var content = existingContent == null ? new Content { Article = contentRevision.Content.Article, Contents_URL = contentRevision.Content.Contents_URL, ContentGuId = Guid.NewGuid(), Url_Params = contentRevision.Content.Url_Params, CheckSum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(contentRevision.Content.Url_Params)) } : existingContent; // 글 중에서 그림이 없는 글이 있을 수 있으므로 그림 여부 판단 -> 없으면 if문 해당 안되므로 저장을 안함. if (contentRevision.SrcDatas != null) { foreach (var data in contentRevision.SrcDatas) { // 그림 데이터 중에서 originalpayload가 없는 경우, commonCrawler에서 다운로드 이미지 하는 부분에서 isDepricated 변수가 true로 넘어오므로 판단할 수 있다. if (data == null || data.OriginalPayload == null) { continue; } var srcdataChecksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(data.OriginalPayload)); var existingSrcdataId = entities.Srcdatas.Where(s => s.CheckSum.Equals(srcdataChecksum)).Select(s => s.Id).FirstOrDefault(); // ExistSrcdata는 기존 DB에서 가지고 있던 Srcdata 이미지와 중복되는지 여부를 판단 해준다. if (existingSrcdataId == 0) { var srcdata = new Srcdata { SrcGuId = Guid.NewGuid(), Original_SourceUrl = data.SourceUrl, Content = content, FileName = data.FileName, OriginalPayload = data.OriginalPayload, OriginalPayload_Size = data.OriginalPayload_Size, CheckSum = srcdataChecksum }; entities.Srcdatas.Add(srcdata); } } } newContentRevision.Content = content; entities.ContentRevisions.Add(newContentRevision); entities.SnapshotToContentRevisions.Add(new SnapshotToContentRevision { ContentRevision = newContentRevision, Snapshot = snapshot, Seqno = ++contentseq, }); } try { entities.SaveChanges(); return(Succeeded(new SnapshotDTO())); } catch (Exception e) { return(null); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } }
/// <summary> /// Srcdata를 For_ContentId, Src를 통해서 Create 하는 함수 /// </summary> /// <param name="req"> /// For_ContentId /// </param> /// <param name="req"> /// Src /// </param> /// <returns></returns> public EnvelopeDTO <GenericDummyDTO> Any(SrcdataCreateRequestDTO req) { var srcdata = req.Srcdata; try { if (!srcdata.For_ContentId.HasValue && !string.IsNullOrWhiteSpace(srcdata.SourceUrl)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'For_ContentId' is empty.")); } if (srcdata.For_ContentId.HasValue && string.IsNullOrWhiteSpace(srcdata.SourceUrl)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'SourceUrl' is empty.")); } if (!srcdata.For_ContentId.HasValue && string.IsNullOrWhiteSpace(srcdata.SourceUrl)) { return(Fail <GenericDummyDTO>("BoardCreateRequestDTO : parameter 'For_ContentId' && 'SourceUrl' are empty.")); } else { using (var entities = new CrawlerStorage()) { try { var DBsrcdata = new Srcdata(); DBsrcdata.Original_SourceUrl = srcdata.SourceUrl; DBsrcdata.For_ContentId = srcdata.For_ContentId.Value; DBsrcdata.FileName = srcdata.FileName; DBsrcdata.OriginalPayload = srcdata.OriginalPayload; DBsrcdata.CheckSum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(srcdata.SourceUrl)); DBsrcdata.SrcGuId = Guid.NewGuid(); entities.Srcdatas.Add(DBsrcdata); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public ServiceBase() { context = new CrawlerStorage(); }
/// <summary> /// Website를 추가하는 함수 /// </summary> /// <param name="req.Label"> /// 이름을 지정 /// </param> /// <param name="req.Website_URL"> /// 웹 주소 /// </param> /// /// <param name="req.Mobile_URL"> /// 모바일 주소 /// </param> /// <returns></returns> public EnvelopeDTO <GenericDummyDTO> Any(WebsiteCreateRequestDTO req) { string Label = req.Label; string Webstie_URL = req.Website_URL; string Mobile_URL = req.Mobile_URL; if (string.IsNullOrWhiteSpace(Label) && !string.IsNullOrWhiteSpace(Webstie_URL) && !string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Label' is empty.")); } if (!string.IsNullOrWhiteSpace(Label) && string.IsNullOrWhiteSpace(Webstie_URL) && !string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Webstie_URL' is empty.")); } if (!string.IsNullOrWhiteSpace(Label) && !string.IsNullOrWhiteSpace(Webstie_URL) && string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Mobile_URL' is empty.")); } if (string.IsNullOrWhiteSpace(Label) && string.IsNullOrWhiteSpace(Webstie_URL) && !string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Label' && 'Webstie_URL' are empty.")); } if (string.IsNullOrWhiteSpace(Label) && !string.IsNullOrWhiteSpace(Webstie_URL) && string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Label' && 'Mobile_URL' are empty.")); } if (!string.IsNullOrWhiteSpace(Label) && string.IsNullOrWhiteSpace(Webstie_URL) && string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Webstie_URL' && 'Mobile_URL' are empty.")); } if (string.IsNullOrWhiteSpace(Label) && string.IsNullOrWhiteSpace(Webstie_URL) && string.IsNullOrWhiteSpace(Mobile_URL)) { return(Fail <GenericDummyDTO>("WebsiteCreateRequestDTO : parameter 'Webstie_URL' && 'Scheduled' && 'Mobile_URL' are empty.")); } else { using (var entities = new CrawlerStorage()) { try { var website = new Website(); website.Label = Label; website.Website_URL = Webstie_URL; website.Mobile_URL = Mobile_URL; entities.Websites.Add(website); entities.SaveChanges(); return(Succeeded(new GenericDummyDTO())); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } } } }