public static void Process(VoteSummaryDBE voteSummary, IStatelessSession session, bool newRecord) { if (voteSummary.ProcessingComplete) { return; } var url = String.Format(URI_FORMAT, voteSummary.VoteIDCDep); if (web == null) { web = new WebClient(); } StartNetwork(); var webStream = web.OpenRead(url); VoteDetailCollectionDIO detailData; using (var streamReader = new StreamReader(webStream, Encoding.GetEncoding("ISO-8859-2"))) { if (streamReader.EndOfStream) { StopNetwork(); return; } XmlSerializer summarySerializer = new XmlSerializer(typeof(VoteDetailCollectionDIO)); detailData = (VoteDetailCollectionDIO)summarySerializer.Deserialize(streamReader); detailData.Vote = voteSummary; } StopNetwork(); ProcessData(detailData, session, newRecord); using (var trans = session.BeginTransaction()) { voteSummary.ProcessingComplete = true; session.Update(voteSummary); trans.Commit(); } }
private static void ProcessData(VoteSummaryCollectionDIO summaryList) { using (var sess = GlobalSessionFactory.OpenStatelessSession()) { int idx = 0; var parliamentaryDay = sess.QueryOver <ParliamentaryDayDBE>().Where(ps => ps.Date == summaryList.VoteDate).List().FirstOrDefault(); if (parliamentaryDay != null && parliamentaryDay.ProcessingComplete) { return; } if (parliamentaryDay == null) { parliamentaryDay = new ParliamentaryDayDBE() { Date = summaryList.VoteDate, }; sess.Insert(parliamentaryDay); } foreach (var summaryEntry in summaryList.VoteSummary) { UpdateProgress(new ProgressEventArgs() { Progress = ((float)idx) / summaryList.VoteSummary.Count, }); idx++; using (var trans = sess.BeginTransaction()) { var voteSummary = sess.QueryOver <VoteSummaryDBE>().Where(vs => vs.VoteIDCDep == summaryEntry.VoteId).List().FirstOrDefault(); if (voteSummary != null) { // Already processed trans.Commit(); DetailProcessor.Process(voteSummary, sess, false); continue; } voteSummary = new VoteSummaryDBE() { VoteIDCDep = summaryEntry.VoteId, ParliamentaryDay = parliamentaryDay, Chamber = summaryEntry.Chamber, CountAbstentions = summaryEntry.CountAbstentions, CountHaveNotVoted = summaryEntry.CountHaveNotVoted, CountPresent = summaryEntry.CountPresent, CountVotesNo = summaryEntry.CountVotesNo, CountVotesYes = summaryEntry.CountVotesYes, Description = summaryEntry.Description, VoteTime = DateTime.ParseExact(summaryEntry.VoteTime, "dd.MM.yyyy HH:mm", null), ProcessingComplete = false, }; sess.Insert(voteSummary); trans.Commit(); DetailProcessor.Process(voteSummary, sess, true); } } using (var trans = sess.BeginTransaction()) { parliamentaryDay.ProcessingComplete = true; sess.Update(parliamentaryDay); trans.Commit(); } } }