//DB에 저장되어 있는 해당 Boardid와 동일한 Snapshot의 가장 최신 정보를 불러와 ContentReivigion의 중복을 체크하는 함수. public void CompareContent(int for_boardid, SnapshotDTO Snapshot) { var LastSnapshot = GetsnapshotbyBoard(for_boardid); var CurrentSnapshot = Snapshot; //예전 데이터가 없는 경우 -> Crawler가 처음 돌때. if (LastSnapshot == null) { foreach (var eachCurrentRevision in CurrentSnapshot.ContentRevisions) { var Revisionchecksum = eachCurrentRevision.Details_Html + eachCurrentRevision.Content.Url_Params; var checksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(Revisionchecksum)); eachCurrentRevision.CheckSum = checksum; } Console.WriteLine("이번에" + for_boardid + "에서 새로 생성된 글은" + Snapshot.ContentRevisions.Count + "개 입니다."); //DB에 Snapshot을 저장하는 부분. SendSnapshot(CurrentSnapshot.ContentRevisions, for_boardid); return; } //예전 데이터와 비교하는 부분. foreach (var eachCurrentRevision in CurrentSnapshot.ContentRevisions) { var Revisionchecksum = eachCurrentRevision.Details_Html + eachCurrentRevision.Content.Url_Params; var checksum = Convert.ToBase64String(HashHelper.ObjectToMD5Hash(Revisionchecksum)); eachCurrentRevision.CheckSum = checksum; //예전 ContentReivigion의 CheckSum과 비교를 하여, 같은 경우, 예전 ContentReivigon의 아이디를 부여함. foreach (var eachLastRevision in LastSnapshot.ContentRevisions) { if (eachCurrentRevision.CheckSum.Equals(eachLastRevision.CheckSum)) { eachCurrentRevision.id = eachLastRevision.id; } } } //중복된 데이터와 달리 처음으로 들어간 데이터는 Id를 설정 해 주지 않았으므로, Id가 0이 됨. Console.WriteLine("이번에" + for_boardid + "에서 새로 생성된 글은" + CurrentSnapshot.ContentRevisions.Where(p => p.id.Equals(0)).Count() + "개 입니다."); //DB에 Snapshot을 저장하는 부분. SendSnapshot(CurrentSnapshot.ContentRevisions, for_boardid); }
//ContentRevigion을 Count 갯수 만큼 가져오는 함수. public void GetList(int count, int for_boardid) { var pagecount = (int)((count - 1) / perpage); var dic = new Dictionary <int, List <ContentRevisionDTO> >(); try { Parallel.For(1, pagecount + 2, i => { var list = GetContentsPerPage(i); if (list == null) { Console.WriteLine(for_boardid + "GetContentsPerPage 할때 문제가 있습니다."); } else { Console.WriteLine(for_boardid + "GetContentsPerPage이 정상적으로 작동됩니다."); } dic.Add(i, list); }); var orderedlist = dic.OrderBy(d => d.Key); var finallist = new List <ContentRevisionDTO>(); foreach (var eachList in orderedlist) { finallist.AddRange(eachList.Value); } Snapshot = new SnapshotDTO { ContentRevisions = finallist.Take(count).ToList(), }; } catch (Exception e) { Console.WriteLine(e); } }
public SnapshotDTO SendSnapshot(List <ContentRevisionDTO> ContentRevisionList, int for_boardid) { //snapshot 저장 부분; SnapshotDTO snapshot; snapshot = new SnapshotDTO { For_BoardId = for_boardid, Taken = DateTime.Now, ContentRevisions = ContentRevisionList }; try { var dto = client.Send <EnvelopeDTO <SnapshotDTO> >(new SnapshotCreateRequestDTO { Snapshot = snapshot }); return(dto.SafeBody); } catch (OutOfMemoryException) { Console.WriteLine("메모리 오류 입니다."); return(null); }catch (NotImplementedException ne) { Console.WriteLine(ne); return(null); } catch (Exception e) { return(null); } }
public SnapshotViewModel(SnapshotDTO dto, int no) { No = no; Path = dto.Path; FullDate = dto.FullDate; }