Пример #1
0
        public void Run()
        {
            logger = new Logger();


            Task <List <E_TRANSACTION> > t1 = Task.Factory.StartNew(MastercardTrx1);
            Task <List <E_TRANSACTION> > t2 = Task.Factory.StartNew(MastercardTrx2);
            Task <List <E_TRANSACTION> > t3 = Task.Factory.StartNew(MastercardTrx3);

            Console.WriteLine("  MastercardTransactions waiting for Merging ");

            List <Task> taskList = new List <Task> {
                t1, t2, t3
            };

            Task.WaitAll(taskList.ToArray());
            Console.WriteLine("  MastercardTransactions Merged");

            using (EtzbkDataContext db = new EtzbkDataContext())
            {
                try
                {
                    var allTmcData = DataManupulation.MergeEntityList(new List <List <E_TRANSACTION> >()
                    {
                        t1.Result.ToList(), t2.Result.ToList(), t3.Result.ToList()
                    });


                    //PROCESS DATA

                    Console.WriteLine(" Merge All Data Spooled... Removing Duplicate record");


                    var uniqueIDs     = allTmcData.Select(u => u.UNIQUE_TRANSID).Distinct().ToArray();
                    var uniqueIDsOnDB = db.E_TRANSACTION.Where(u => uniqueIDs.Contains(u.UNIQUE_TRANSID)).Select(u => u.UNIQUE_TRANSID).ToArray();
                    var etrxData      = allTmcData.Where(u => !uniqueIDsOnDB.Contains(u.UNIQUE_TRANSID));
                    Console.WriteLine(uniqueIDsOnDB.Count() + " Duplicate record removed--NonEtzCardTransaction");

                    logger.LogInfoMessage(nameof(MastercardTransactions) + " " + etrxData.Count() + " Record ready to be Inserted");
                    db.E_TRANSACTION.AddRange(etrxData);
                    db.SaveChanges();

                    logger.LogInfoMessage(nameof(MastercardTransactions) + " " + etrxData.Count() + " Record Inserted for Settlement");

                    Console.WriteLine(etrxData.Count() + " Record Inserted for Settlement");
                    Console.WriteLine("Marking Transaction as spooled transaction");
                    if (uniqueIDs.Count() > 0)
                    {
                        DataManupulation.UpdateTMCProcccessedTransaction(uniqueIDs);
                    }
                    Console.WriteLine("Spooled transactions Marked");
                    Console.WriteLine("Spooled transactions Marked");
                }
                catch (SqlException ex)
                {
                    Console.WriteLine("SQLException from MastercardTransactions Run " + ExceptionExtensions.GetFullMessage(ex));
                    logger.LogDebugMessage("SQLException from Run " + nameof(MastercardTransactions) + " " + ExceptionExtensions.GetFullMessage(ex));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception from Run " + ExceptionExtensions.GetFullMessage(ex));
                    logger.LogDebugMessage("Exception from Run " + nameof(MastercardTransactions) + " " + ExceptionExtensions.GetFullMessage(ex));
                }
            }
            logger.LogInfoMessage(nameof(MastercardTransactions) + " Merged ");



            Console.WriteLine("MastercardTransactions Transaction spool Completed");
        }
        public void Run()
        {
            logger = new Logger();

            logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + " Starting  EtranzactChannelTransaction ");

            Task <List <E_TRANSACTION> > t1 = Task.Factory.StartNew(Channel1);
            Task <List <E_TRANSACTION> > t2 = Task.Factory.StartNew(Channel2);
            Task <List <E_TRANSACTION> > t3 = Task.Factory.StartNew(Channel3);
            Task <List <E_TRANSACTION> > t4 = Task.Factory.StartNew(Channel4);
            Task <List <E_TRANSACTION> > t5 = Task.Factory.StartNew(Channel5);
            Task <List <E_TRANSACTION> > t6 = Task.Factory.StartNew(Channel6);
            Task <List <E_TRANSACTION> > t7 = Task.Factory.StartNew(Channel7);
            Task <List <E_TRANSACTION> > t8 = Task.Factory.StartNew(Channel8);


            logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + "  EtranzactChannelTransaction waiting for Merging ");
            Console.WriteLine("  EtranzactChannelTransaction waiting for Merging ");
            using (EtzbkDataContext db = new EtzbkDataContext())
            {
                try
                {
                    List <Task> taskList = new List <Task> {
                        t1, t2, t3, t4, t5, t6, t7, t8
                    };
                    Task.WaitAll(taskList.ToArray());
                    Console.WriteLine("  EtranzactChannelTransaction Merged");

                    //Merge All Data Spooled
                    var allTmcData = DataManupulation.MergeEntityList(new List <List <E_TRANSACTION> >()
                    {
                        t1.Result.ToList(), t2.Result.ToList(), t3.Result.ToList(), t4.Result.ToList(), t5.Result.ToList(), t6.Result.ToList(), t7.Result.ToList(), t8.Result.ToList()
                    });

                    Console.WriteLine(" Merge All Data Spooled... Removing Duplicate record");

                    //Remove duplicate value
                    var uniqueIDs     = allTmcData.Select(u => u.UNIQUE_TRANSID).Distinct().ToArray();
                    var uniqueIDsOnDB = db.E_TRANSACTION.Where(u => uniqueIDs.Contains(u.UNIQUE_TRANSID)).Select(u => u.UNIQUE_TRANSID).ToArray();
                    var etrxData      = allTmcData.Where(u => !uniqueIDsOnDB.Contains(u.UNIQUE_TRANSID));

                    Console.WriteLine(uniqueIDsOnDB.Count() + " Duplicate record removed--NonEtzCardTransaction");

                    logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + " " + etrxData.Count() + " Record ready to be Inserted");

                    db.E_TRANSACTION.AddRange(etrxData);
                    db.SaveChanges();

                    logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + " " + etrxData.Count() + " Record Inserted for Settlement");

                    Console.WriteLine(etrxData.Count() + " Record Inserted for Settlement");
                    Console.WriteLine("Marking Transaction as spooled transaction");
                    if (uniqueIDs.Count() > 0)
                    {
                        DataManupulation.UpdateTMCProcccessedTransaction(uniqueIDs);
                    }
                    Console.WriteLine("Spooled transactions Marked");
                }
                catch (SqlException ex)
                {
                    Console.WriteLine("SQLException from EtranzactChannelTransaction Run " + ExceptionExtensions.GetFullMessage(ex));
                    logger.LogDebugMessage("SQLException from Run " + nameof(EtranzactChannelTransaction) + " " + ExceptionExtensions.GetFullMessage(ex));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception from EtranzactChannelTransaction Run " + ExceptionExtensions.GetFullMessage(ex));
                    logger.LogDebugMessage("Exception from Run " + nameof(EtranzactChannelTransaction) + " " + ExceptionExtensions.GetFullMessage(ex));
                }

                logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + " Merged ");


                Console.WriteLine("ETZ Channel Transaction Completed");

                logger.LogInfoMessage(nameof(EtranzactChannelTransaction) + " ETZ Channel  Transaction Completed ");
            }
        }