Ejemplo n.º 1
0
        private static List <GspDataAccess.Exporter> LoadGspExportersNewPaging(GspDBEntities gspDb, int skip, int take)
        {
            var exporters = gspDb.Exporters.OrderByDescending(x => x.Changed).Skip(skip).Take(take).ToList();

            return(exporters);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var gspDb     = new GspDBEntities();
            var payslipDb = new EpbPayslipDbEntities();

            var syncSettings = payslipDb.SyncSettings.FirstOrDefault(x => x.SyncTable == (int)SyncTable.Exporter);

            if (syncSettings == null)
            {
                CreateFirstExporterSyncStatusEntry(payslipDb, SyncTable.Exporter);
                syncSettings = payslipDb.SyncSettings.FirstOrDefault(x => x.SyncTable == (int)SyncTable.Exporter);
            }
            if (syncSettings == null)
            {
                return;
            }

            if (syncSettings.IsCycleComplete)
            {
                syncSettings.NewSyncEntry      = 0;
                syncSettings.ModifiedSyncEntry = 0;

                syncSettings.Skip = 0;
                //syncSettings.Take = 0;

                syncSettings.IsCycleComplete = false;
            }
            syncSettings.Skip = 0;

            var count = syncSettings.IsInitialSync
                ? gspDb.Exporters.Count()
                : gspDb.Exporters.Count(x => x.Changed >= syncSettings.LastSyncDate);

            if (count == 0)
            {
                return;
            }

            Console.WriteLine("Total Syncable " + SyncTable.Exporter + " Found: " + count +
                              "\n\n***********Sync Staus***********\n\n" +
                              "Last Sync Date:" + syncSettings.LastSyncDate + "\n" +
                              "Is One Way Sync? : " + syncSettings.IsOneWaySync + " \n" +
                              "Is First Sync? : " + syncSettings.IsInitialSync + " \n" +
                              "Query Helper Take Value: " + syncSettings.Take + "\n" +
                              "Query Helper Skip Value: " + syncSettings.Skip + "\n");

            Console.WriteLine(
                "System is  giving you 30 seconds to validate and cancel the sync operation if anything found wrong!");
            Thread.Sleep(30000);

            //for (var i = 0; i < count/syncSettings.Take + 1; i++)
            //{
            //    //Read Gsp Exporters
            //    var gspExporters = LoadGspExporters(gspDb, syncSettings.Skip, syncSettings.Take);

            //    //Convert to Payslip Exporter
            //    var payslipExporters = ConvertToPayslipExporter(gspExporters);

            //    //save to payslip db
            //    var save = SyncExportersToPayslipDb(payslipDb, payslipExporters, syncSettings);
            //}

            int currentPageSize = 10, currentPageNumber = 1, currentTakeNumber = 10;

            for (currentPageNumber = 1; (currentPageNumber - 1) * currentPageSize < count; currentPageNumber++)
            {
                var currentSkipNumber = (currentPageNumber - 1) * currentPageSize;
                if ((currentPageNumber * currentPageSize) >= count)
                {
                    currentTakeNumber = count - ((currentPageNumber - 1) * currentPageSize);
                }

                //Read Gsp Exporters
                var gspExporters = LoadGspExportersNewPaging(gspDb, currentSkipNumber, currentTakeNumber);

                //Convert to Payslip Exporter
                var payslipExporters = ConvertToPayslipExporter(gspExporters);

                //save to payslip db
                var save = SyncExportersToPayslipDb(payslipDb, payslipExporters, syncSettings);
            }

            syncSettings.IsCycleComplete = true;
            syncSettings.LastSyncDate    = DateTime.Now.AddMinutes(-30);
            syncSettings.Modified        = DateTime.Now;
            if (syncSettings.IsInitialSync)
            {
                syncSettings.IsInitialSync = false;
            }


            payslipDb.SaveChanges();

            Console.WriteLine("Wow, the sync has been completed successfully!");
            Console.ReadLine();
        }