Ejemplo n.º 1
0
        /// <summary>
        /// This is the method that runs the actual process
        /// </summary>
        public void CheckForAndPublishChanges()
        {
            this.logger.LogInformation($"Running Change Detection on thread: {Thread.CurrentThread.ManagedThreadId}");

            Dictionary <string, CDCRecord> allChangeRecords = new Dictionary <string, CDCRecord>();
            List <string> orderedChanges = new List <string>();

            RunStoredProcedure("GetUpdatedLoanEntities", ConnectionString, (reader) =>
            {
                while (reader.Read())
                {
                    var record = new LoanCDCRecord(reader);
                    allChangeRecords.Add(record.LSNString, record);
                }
                reader.NextResult();
                while (reader.Read())
                {
                    var record = new ApplicantCDCRecord(reader);
                    allChangeRecords.Add(record.LSNString, record);
                }
                reader.NextResult();
                while (reader.Read())
                {
                    var record = new LoanApplicantCDCRecord(reader);
                    allChangeRecords.Add(record.LSNString, record);
                }
                reader.NextResult();
                while (reader.Read())
                {
                    var record = new PropertyCDCRecord(reader);
                    allChangeRecords.Add(record.LSNString, record);
                }


                reader.NextResult();

                while (reader.Read())
                {
                    orderedChanges.Add(Convert.ToBase64String((byte[])reader.GetValue(0)));
                }
            });

            DataTable sentMessages = new DataTable()
            {
                Columns =
                {
                    new DataColumn("ChangeId",     typeof(Int64)),
                    new DataColumn("EventSentUTC", typeof(DateTimeOffset))
                }
            };

            foreach (var lsn in orderedChanges)
            {
                CDCRecord record = allChangeRecords[lsn];

                if (record is LoanCDCRecord loancdc)
                {
                    SendLoanEvent(loancdc);
                    sentMessages.Rows.Add(record.ChangeId, DateTimeOffset.UtcNow);
                }
                else if (record is LoanApplicantCDCRecord loanapplicantcdc)
                {
                    SendLoanApplicantEvent(loanapplicantcdc);
                    sentMessages.Rows.Add(record.ChangeId, DateTimeOffset.UtcNow);
                }
                else if (record is PropertyCDCRecord propertyCdc)
                {
                    SendPropertyEvent(propertyCdc);
                    sentMessages.Rows.Add(record.ChangeId, DateTimeOffset.UtcNow);
                }
                else if (record is ApplicantCDCRecord applicantCdc)
                {
                    SendApplicantEvent(applicantCdc);
                    sentMessages.Rows.Add(record.ChangeId, DateTimeOffset.UtcNow);
                }
            }

            //Store the record in outbox postmarks
            if (sentMessages.Rows.Count > 0)
            {
                RunStoredProcedure("cdc.StoreOutboxPostmark", ConnectionString, null, new Dictionary <string, object> {
                    { "@postmarks", sentMessages }
                });
            }
        }
Ejemplo n.º 2
0
 private void SendPropertyEvent(PropertyCDCRecord propertyCdc)
 {
 }