public void TestUpdatePerson()
        {
            AddDataForTestingTransaction addDataForTesting = new AddDataForTestingTransaction();

            clientManagement = new ClientManager(DataUtil.TESTDB);
            clientServices   = new ClientServices(clientManagement);

            DeleteAllData();
            ApplicationSettingsServices _appSettings = ServicesProvider.GetInstance().GetApplicationSettingsServices();

            _appSettings.FillGeneralDatabaseParameter();
            _appSettings.UpdateSelectedParameter(OGeneralSettings.ID_PATTERN, "[0-9]{2}[A-Z]{2}");

            EconomicActivity agriculture = addDataForTesting.AddDomainOfApplicationAgriculture();
            District         district    = addDataForTesting.AddDistrictIntoDatabase();

            Person person = AddPerson(true, agriculture, 1, "Dushambe", district, "Nicolas", "MANGIN", 'M', "12ED");

            person.Branch = _branch;
            Assert.AreEqual(String.Empty, clientServices.SavePerson(ref person));

            person.FirstName          = "floriane";
            person.IdentificationData = "34PP";
            Assert.AreEqual(String.Empty, clientServices.SavePerson(ref person));
        }
Exemple #2
0
        protected override void OnStart(string[] args)
        {
#if DEBUG
            //Debugger.Launch();
#endif

            Log.Info("Job factory startup task configuration");

            try
            {
                scheduler = StdSchedulerFactory.GetDefaultScheduler();
                //ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
                //scheduler = schedulerFactory.GetScheduler();

                ApplicationSettingsServices generalSettingsService = ServiceProvider.GetApplicationSettingsServices();
                generalSettingsService.FillGeneralDatabaseParameter();
                Log.Debug("Application settings loaded");

                //IJobDetail InitializationJob = JobBuilder.Create<SMSChargeJob>().WithIdentity(typeof(InitializationJob).Name).Build();
                IJobDetail SMSChargeJob      = JobBuilder.Create <SMSChargeJob>().WithIdentity(typeof(SMSChargeJob).Name).Build();
                IJobDetail MessagingJob      = JobBuilder.Create <MessagingJob>().WithIdentity(typeof(MessagingJob).Name).Build();
                IJobDetail ChequeCloseOutJob = JobBuilder.Create <ChequeCloseOutJob>().WithIdentity(typeof(ChequeCloseOutJob).Name).Build();

                IJobDetail PasswordResetJob = JobBuilder.Create <PasswordResetJob>().WithIdentity(typeof(PasswordResetJob).Name).Build();

                //ITrigger InitializationJobTrigger = TriggerBuilder.Create().WithIdentity("InitializationJobTrigger")
                //.StartNow().WithPriority(5).WithSimpleSchedule(s => s.WithRepeatCount(0).WithIntervalInMinutes(1)).Build();

                ITrigger SMSChargeJobTrigger = TriggerBuilder.Create().WithIdentity("SMSChargeJobTrigger")
                                               .WithCronSchedule("0 0 1 ? * 6L").Build(); //Fires at 1am every last friday

                ITrigger MessagingJobTrigger = TriggerBuilder.Create().WithIdentity("MessagingJobTrigger")
                                               .StartNow().WithSimpleSchedule(x => x.WithIntervalInMinutes(2).RepeatForever()
                                                                              .WithMisfireHandlingInstructionNextWithExistingCount()).StartNow().Build();

                ITrigger ChequeCloseOutJobTrigger = TriggerBuilder.Create().WithIdentity("ChequeCloseOutJobTrigger")

                                                                                              /*.StartNow()
                                                                                               * .WithSimpleSchedule(x => x.WithIntervalInHours(24).RepeatForever()
                                                                                               * .WithMisfireHandlingInstructionNextWithExistingCount()).StartNow()
                                                                                               * .Build();*/
                                                    .WithCronSchedule("0 0 0 * * ?").Build(); // Fires at midnight everyday.

                ITrigger PasswordResetJobTrigger = TriggerBuilder.Create().WithIdentity("PasswordResetJobTrigger")
                                                   .WithCronSchedule("0 0 0 * * ?").Build(); // Fires at midnight everyday.


                //scheduler.ScheduleJob(InitializationJob, InitializationJobTrigger);
                scheduler.ScheduleJob(MessagingJob, MessagingJobTrigger);
                scheduler.ScheduleJob(SMSChargeJob, SMSChargeJobTrigger);
                scheduler.ScheduleJob(ChequeCloseOutJob, ChequeCloseOutJobTrigger);
                scheduler.ScheduleJob(PasswordResetJob, PasswordResetJobTrigger);
                scheduler.Start();

                Log.Info("Job factory started");
            }
            catch (SchedulerException se)
            {
                Log.Error(se);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            CsvFileDescription fileDescription = new CsvFileDescription
            {
                SeparatorChar           = ',',
                FirstLineHasColumnNames = true
            };
            CsvContext cc = new CsvContext();

            var dir = Directory.GetCurrentDirectory();

            string sourceFilePath = dir + "/client_table.csv";

            Console.WriteLine("***********************************************************");
            Console.WriteLine("***********************************************************");
            Console.WriteLine("****************OpenCBS DATABASE MIGRATOR******************");
            Console.WriteLine("***********************************************************");
            Console.WriteLine("***********************************************************");
            Console.WriteLine("                                                           ");
            Console.WriteLine("**   Ensure that a csv file named \"client_table.csv\"     **");
            Console.WriteLine("**   exists in the bin directory of the migrator before  **");
            Console.WriteLine("**                       proceeding.                     **");
            Console.WriteLine("******            Press 'enter' to continue        ********");
            Console.WriteLine("                                                           ");
            Console.WriteLine("***********************************************************");
            Console.WriteLine("***********************************************************");

            Console.ReadKey();
            try
            {
                ApplicationSettingsServices generalSettingsService = ServicesProvider.GetInstance().GetApplicationSettingsServices();
                generalSettingsService.FillGeneralDatabaseParameter();

                SelectDefaultUser();
                SelectDefaultBranch();
                SelectDefaultEconomicActivity();
                SelectDefaultLocation();

                List <FromModel.Client> clients = cc.Read <FromModel.Client>(sourceFilePath, fileDescription).ToList();
                Console.WriteLine("");
                Console.WriteLine("***********************************************************");
                Console.WriteLine(String.Format("Migrating {0} clients data", clients.Count));
                Console.WriteLine("***********************************************************");
                Console.WriteLine("");

                var             _clientService = ServicesProvider.GetInstance().GetClientServices();
                int             count          = 0;
                MigrationResult result         = null;
                foreach (FromModel.Client client in clients)
                {
                    result            = new MigrationResult();
                    result.full_name  = client.full_name;
                    result.surname    = client.surname;
                    result.first_name = client.first_name;

                    try
                    {
                        if (!String.IsNullOrEmpty(client.first_name)
                            ||
                            !String.IsNullOrEmpty(client.surname)
                            ||
                            !String.IsNullOrEmpty(client.full_name))
                        {
                            #region Individual migration
                            if (client.c_type == ClientType.INDIVIDUAL ||
                                client.c_type == ClientType.DIRECTORS ||
                                client.c_type == ClientType.CHILDREN ||
                                client.c_type == ClientType.JOINT ||
                                client.c_type == ClientType.STAFF ||
                                client.c_type == ClientType.CASHIER)
                            {
                                result.type = "INDIVIDUAL";

                                var _query = client.full_name;
                                int onlyActive = 2; //inactive and active
                                int _numbersTotalPage, _numberOfRecords;

                                var results = ServicesProvider.GetInstance().GetClientServices().FindTiers(out _numbersTotalPage, out _numberOfRecords,
                                                                                                           _query, onlyActive, 1, 1, 1, 1);

                                if (results.Count > 0)
                                {
                                    exist.Add(client);

                                    result.migrated       = "no";
                                    result.failure_reason = "duplicate";
                                    dump.Add(result);
                                    continue;
                                }
                                ++count;
                                Console.WriteLine(count + "). Migrating \"INDIVIDUAL\" " + client.full_name);
                                SavePerson(client);
                                result.migrated       = "yes";
                                result.failure_reason = "";
                                dump.Add(result);
                                migrated.Add(client);
                            }
                            #endregion
                            #region Corporate migration
                            else if (client.c_type == ClientType.GOVT ||
                                     client.c_type == ClientType.SOLE_PROPRIETORSHIP ||
                                     client.c_type == ClientType.FINANCIAL_INSTITUTION ||
                                     client.c_type == ClientType.EDUCATIONAL_INSTITUTION ||
                                     client.c_type == ClientType.COMPANY)
                            {
                                result.type = "CORPORATE";

                                var _query = client.full_name;
                                int onlyActive = 2; //inactive and active
                                int _numbersTotalPage, _numberOfRecords;


                                var results = ServicesProvider.GetInstance().GetClientServices().
                                              FindTiersCorporates(onlyActive, 1, out _numbersTotalPage, out _numberOfRecords, _query);

                                if (results.Count > 0)
                                {
                                    exist.Add(client);
                                    result.migrated       = "no";
                                    result.failure_reason = "duplicate";
                                    dump.Add(result);
                                    continue;
                                }

                                ++count;
                                Console.WriteLine(count + "). Migrating \"CORPORATE\" " + client.full_name);
                                SaveCorporate(client);
                                result.migrated       = "yes";
                                result.failure_reason = "";
                                dump.Add(result);
                                migrated.Add(client);
                            }
                            #endregion
                            #region Group migration
                            else if (client.c_type == ClientType.GROUP ||
                                     client.c_type == ClientType.CHURCH_MINISTRIES)
                            {
                                result.type = "GROUP";

                                /*var _query = "";
                                 * int onlyActive = 2; //inactive and active
                                 * int _numbersTotalPage, _numberOfRecords;
                                 *
                                 * var results = ServicesProvider.GetInstance().GetClientServices().FindTiers(out _numbersTotalPage, out _numberOfRecords,
                                 *              _query, onlyActive, 1, 1, 1, 1);
                                 *
                                 * if (results.Count > 0)
                                 * {
                                 *  exist.Add(client);
                                 *  continue;
                                 * }
                                 */
                                //++count;
                                Console.WriteLine(count + "). Migrating \"GROUP\" " + client.full_name);
                                error.Add(client);
                                result.migrated       = "no";
                                result.failure_reason = "Requires group members";
                                dump.Add(result);
                                //SaveGroup(client);
                            }
                            #endregion
                        }
                    }
                    catch (CustomFieldsAreNotFilledCorrectlyException exc)
                    {
                        Console.WriteLine(CustomExceptionHandler.ShowExceptionText(exc));
                        error.Add(client);
                        result.migrated       = "no";
                        result.failure_reason = exc.Message;
                        dump.Add(result);
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(CustomExceptionHandler.ShowExceptionText(exc));
                        error.Add(client);
                        result.migrated       = "no";
                        result.failure_reason = exc.Message;
                        dump.Add(result);
                    }
                    finally
                    {
                        //dump.Add(result);
                    }
                }

                string resultDir = dir + "/result";
                if (!Directory.Exists(resultDir))
                {
                    Directory.CreateDirectory(resultDir);
                }

                string resultFilePath     = resultDir + "/migration.csv";
                string errorFilePath      = resultDir + "/error.csv";
                string successfulFilePath = resultDir + "/successful.csv";
                string duplicatesFilePath = resultDir + "/duplicates.csv";

                cc.Write(dump, resultFilePath, fileDescription);
                cc.Write(error, errorFilePath, fileDescription);
                cc.Write(migrated, successfulFilePath, fileDescription);
                cc.Write(exist, duplicatesFilePath, fileDescription);

                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("***********************************************************");
                //Console.WriteLine(String.Format("Migrated {0} clients data", migrated.Count));
                Console.WriteLine("Results:");
                Console.WriteLine("Total: " + clients.Count);
                Console.WriteLine("Successful: " + migrated.Count);
                Console.WriteLine("Failed: " + error.Count);
                Console.WriteLine("Duplicates: " + exist.Count);
                Console.WriteLine("Migration result saved to " + resultDir);
                Console.WriteLine("***********************************************************");


                Console.ReadLine();
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception: " + exc);
                Console.ReadLine();
            }
        }