public void EmployeeProvideDataTest() { var uows = new MITD.Domain.Repository.UnitOfWorkScope( new Data.NH.NHUnitOfWorkFactory(() => PMSAdmin.Persistence.NH.PMSAdminSession.GetSession())); using (var uow = new NHUnitOfWork(PMSSession.GetSession())) using (var uow2 = uows.CurrentUnitOfWork) { var pmsAdminService = new PMS.ACL.PMSAdmin.PMSAdminService( new PMSAdmin.Application.UnitService(new PMSAdmin.Persistence.NH.UnitRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.JobService(new PMSAdmin.Persistence.NH.JobRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.CustomFieldService(new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.JobPositionService(new PMSAdmin.Persistence.NH.JobPositionRepository(uows)), new PMSAdmin.Application.JobIndexService(new PMSAdmin.Persistence.NH.JobIndexRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)) , new PMSAdmin.Application.UnitIndexService(new PMSAdmin.Persistence.NH.UnitIndexRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows) )); var rep = new PMS.Persistence.NH.EmployeeRepository(uow); var provider = new PMS.Application.CalculationDataProvider(rep, pmsAdminService, new PMS.Persistence.NH.JobIndexPointRepository(uow)); var emp = rep.First(); MITD.PMSReport.Domain.Model.CalculationData empData; //var data = provider.Provide(emp, out empData); } }
public void CalculationTest() { MITD.PMSAdmin.Domain.Model.Policies.PolicyId policyId; var empLst = string.Empty; PMSAdmin.Domain.Model.JobIndices.JobIndex sharedji; using (var transaction = new TransactionScope()) using (var puow = new NHUnitOfWork(PMSAdminSession.GetSession())) using (var reuow = new NHUnitOfWork(RuleEngineSession.GetSession())) { var ruleRep = new RuleRepository(reuow); var rfRep = new RuleFunctionRepository(reuow); var reConfigRep = new REConfigeRepository(reuow); var rebps = new RuleBasedPolicyEngineService(new LocatorProvider("PMSDb"), publisher); var policyRep = new MITD.PMSAdmin.Persistence.NH.PolicyRepository(puow); var rule = new Rule(new RuleId(ruleRep.GetNextId()), Guid.NewGuid().ToString(), @" RuleExecutionUtil.Res.Add( new RuleResult{Value = data.Data}); ", RuleType.PerCalculation, 1); ruleRep.Add(rule); var policy = new MITD.PMSAdmin.Domain.Model.Policies.RuleEngineBasedPolicy( policyRep.GetNextId(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); policyId = policy.Id; policyRep.Add(policy); policy.AssignRule(rule); var jirep = new PMSAdmin.Persistence.NH.JobIndexRepository(puow); var ai = new PMSAdmin.Domain.Model.JobIndices.JobIndexCategory( jirep.GetNextId(), null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); jirep.Add(ai); sharedji = new PMSAdmin.Domain.Model.JobIndices.JobIndex( jirep.GetNextId(), ai, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); jirep.Add(sharedji); reuow.Commit(); puow.Commit(); transaction.Complete(); } Calculation calc; var puows = new UnitOfWorkScope(new NHUnitOfWorkFactory(() => PMSAdminSession.GetSession())); var uows = new UnitOfWorkScope(new NHUnitOfWorkFactory(() => { var res = PMSSession.GetSession(); res.SetBatchSize(100); return(res); })); Period period; using (var transaction = new TransactionScope()) using (var puow = puows.CurrentUnitOfWork as NHUnitOfWork) using (var uow = uows.CurrentUnitOfWork as NHUnitOfWork) { var periodRep = new PeriodRepository(uow); period = new Period(new PeriodId(periodRep.GetNextId()), Guid.NewGuid().ToString(), DateTime.Now, DateTime.Now, 91); periodRep.Add(period); var sjiService = new PMS.ACL.PMSAdmin.PMSAdminService(null, null, null, null, new PMSAdmin.Application.JobIndexService(new PMSAdmin.Persistence.NH.JobIndexRepository(puow), new PMSAdmin.Persistence.NH.CustomFieldRepository(puow)) , new PMSAdmin.Application.UnitIndexService(new PMSAdmin.Persistence.NH.UnitIndexRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows) ) ); var sji = sjiService.GetSharedJobIndex(new PMS.Domain.Model.JobIndices.SharedJobIndexId(sharedji.Id.Id)); var jiRep = new PMS.Persistence.NH.JobIndexRepository(uow); var jic = new PMS.Domain.Model.JobIndices.JobIndexGroup( jiRep.GetNextId(), period, null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); jiRep.Add(jic); var ji = new PMS.Domain.Model.JobIndices.JobIndex( jiRep.GetNextId(), period, sji, jic, true); jiRep.Add(ji); uow.Commit(); transaction.Complete(); } for (int j = 0; j < 10; j++) { using (var transaction = new TransactionScope()) using (var uow = uows.CurrentUnitOfWork as NHUnitOfWork) { var empRep = new EmployeeRepository(uow); for (int i = 0; i < 500; i++) { var emp = new Employee(Guid.NewGuid().ToString(), period, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); empLst += emp.Id.EmployeeNo + ";"; empRep.Add(emp); } empLst = empLst.Remove(empLst.Length - 1); uow.Commit(); transaction.Complete(); } } using (var transaction = new TransactionScope()) using (var uow = uows.CurrentUnitOfWork as NHUnitOfWork) { var rebps = new RuleBasedPolicyEngineService(new LocatorProvider("PMSDb"), publisher); var calcRep = new CalculationRepository(uow); var policyRep = new MITD.PMS.Persistence.NH.PolicyRepository(uow, new PolicyConfigurator(rebps)); var policy = policyRep.GetById(new PolicyId(policyId.Id)); calc = new Calculation(calcRep.GetNextId(), period, policy, Guid.NewGuid().ToString(), DateTime.Now, empLst); calcRep.Add(calc); uow.Commit(); transaction.Complete(); } //var calculator = new JobIndexPointCalculator(publisher); //using (var transaction = new TransactionScope()) //using (var uow = new NHUnitOfWork(PMSSession.GetSession())) //{ // var calcRep = new CalculationRepository(uow); // calc = calcRep.GetById(calc.Id); // calc.Run(calculator); // uow.Commit(); // transaction.Complete(); //} //var t = Task.Factory.StartNew(() => // { // Thread.Sleep(1000); // using (var transaction = new TransactionScope()) // using (var uow = new NHUnitOfWork(PMSSession.GetSession())) // { // var calcRep = new CalculationRepository(uow); // calc = calcRep.GetById(calc.Id); // calc.Stop(calculator); // uow.Commit(); // transaction.Complete(); // } // }); //t.Wait(); }
public void RuleTest() { using (var scope = new TransactionScope()) { using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["PMSDBConnection"].ConnectionString)) { var uows = new MITD.Domain.Repository.UnitOfWorkScope( new Data.NH.NHUnitOfWorkFactory(() => PMSAdmin.Persistence.NH.PMSAdminSession.GetSession(con))); using (var uow = new NHUnitOfWork(PMSSession.GetSession(con))) using (var uow2 = uows.CurrentUnitOfWork) { con.Open(); var pmsAdminService = new PMS.ACL.PMSAdmin.PMSAdminService( new PMSAdmin.Application.UnitService(new PMSAdmin.Persistence.NH.UnitRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.JobService(new PMSAdmin.Persistence.NH.JobRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.CustomFieldService(new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.JobPositionService(new PMSAdmin.Persistence.NH.JobPositionRepository(uows)), new PMSAdmin.Application.JobIndexService(new PMSAdmin.Persistence.NH.JobIndexRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)), new PMSAdmin.Application.UnitIndexService(new PMSAdmin.Persistence.NH.UnitIndexRepository(uows), new PMSAdmin.Persistence.NH.CustomFieldRepository(uows)) ); EventPublisher publisher = new EventPublisher(); var rep = new PMS.Persistence.NH.EmployeeRepository(uow); var periodRep = new PMS.Persistence.NH.PeriodRepository(uow); var calcRep = new PMS.Persistence.NH.CalculationRepository(uow); var policyRep = new MITD.PMS.Persistence.NH.PolicyRepository(uow, new PolicyConfigurator( new RuleBasedPolicyEngineService(new LocatorProvider("PMSDbConnection"), publisher))); var provider = new PMS.Application.CalculationDataProvider(rep, pmsAdminService, new PMS.Persistence.NH.JobIndexPointRepository(uow)); var policy = policyRep.GetById(new PolicyId(1)); var period = periodRep.GetBy(c => c.Active); var emp = rep.GetBy(new EmployeeId("150554", period.Id)); // if period has no calculation var calculation = new Calculation(calcRep.GetNextId(), period, policy, Guid.NewGuid().ToString(), DateTime.Now, "150554"); calcRep.Add(calculation); uow.Commit(); // if period has calculation , get it by its identifier //var calculation = calcRep.GetById(new CalculationId(1)); MITD.PMSReport.Domain.Model.CalculationData empData; var pathNo = 1; List <SummaryCalculationPoint> calcList = new List <SummaryCalculationPoint>(); var session = new CalculatorSession(); while (pathNo <= 2) { Utils.Res = new MITD.PMS.RuleContracts.RuleResult(); session.AddCalculationPoints(calcList); session.PathNo = pathNo; var data = provider.Provide(emp, out empData, calculation, true, session); var rule1 = new Rule10(); rule1.Execute(data); var rule2 = new Rule11(); rule2.Execute(data); var rule3 = new Rule12(); rule3.Execute(data); //var rule4 = new Rule13(); //rule4.Execute(data); var res = provider.Convert(Utils.Res, empData, emp, period, calculation); calcList = res.CalculationPoints.OfType <SummaryCalculationPoint>().ToList(); var jipRep = new JobIndexPointRepository(uow); if (res.EmployeePointsForAdd != null) { foreach (var point in res.EmployeePointsForAdd) { jipRep.Add(point); } } if (res.EmployeePointsForUpdate != null) { foreach (var point in res.EmployeePointsForUpdate) { var employeePoint = jipRep.GetById(point.Key); employeePoint.SetValue(point.Value); } } uow.Commit(); pathNo++; } } } } }