public void EmployeeJobInsexPointTest() { using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var jpRep = new MITD.PMS.Persistence.NH.JobPositionRepository(new NHUnitOfWork(session)); var empRep = new EmployeeRepository(new NHUnitOfWork(session)); var inquiryRep = new InquiryJobIndexPointRepository(new NHUnitOfWork(session)); var jobRep = new PMS.Persistence.NH.JobRepository(new NHUnitOfWork(session)); var jobIndexRep = new PMS.Persistence.NH.JobIndexRepository(new NHUnitOfWork(session)); var inquiryService = new JobPositionInquiryConfiguratorService(jpRep); var jobPosition = jpRep.GetBy(new JobPositionId(new PeriodId(1), new SharedJobPositionId(19))); var inquirerId = jobPosition.ConfigurationItemList.Select(c => c.Id.InquirerId).FirstOrDefault(); var inquirer = empRep.GetBy(inquirerId); var employees = inquiryService.GetJobPositionInquiryConfigurationItemBy(inquirer); foreach (var itm in employees) { var job = jobRep.GetById(itm.JobPosition.JobId); foreach (var jobIndexId in job.JobIndexList) { var jobIndex = jobIndexRep.GetById(jobIndexId.JobIndexId); var id = inquiryRep.GetNextId(); var inquiryIndexPoint = new InquiryJobIndexPoint(new InquiryJobIndexPointId(id), itm, jobIndex as JobIndex, Guid.NewGuid().ToString()); session.Save(inquiryIndexPoint); } } session.Transaction.Commit(); } }
private static void RegisterDataAccess(WindsorContainer container) { container.Register(Component.For <IConnectionProvider>() .UsingFactoryMethod(c => new ConnectionProvider(() => { var s = System.Configuration.ConfigurationManager. ConnectionStrings["PMSDBConnection"].ConnectionString; var res = new SqlConnection(s); res.Open(); return(res); })).LifestyleBoundTo <IService>()); DataAccessConfigHelper.ConfigureContainer <CustomFieldRepository>(container, () => { var session = PMSAdminSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection()); return(session); }, "PMSAdmin"); DataAccessConfigHelper.ConfigureContainer <PeriodRepository>(container, () => { var session = PMSSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection()); return(session); }, "PMS"); DataAccessConfigHelper.ConfigureContainer <RuleRepository>(container, () => { var session = RuleEngineSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection()); return(session); }, "RuleEngine"); }
public void JobPositionInPeriodTest() { Period period; JobPosition jobPosition; using (var session = PMSAdminSession.GetSession()) using (session.BeginTransaction()) { jobPosition = session.Query <JobPosition>().FirstOrDefault(); session.Transaction.Commit(); } using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { period = session.Query <Period>().FirstOrDefault(); var unitInPeriod = session.Query <Unit>().FirstOrDefault(); var jobInPeriod = session.Query <Job>().FirstOrDefault(); var sharedJobPosition = new SharedJobPosition(new SharedJobPositionId(jobPosition.Id.Id), jobPosition.Name, jobPosition.DictionaryName); var jobPositionInPeriod = new MITD.PMS.Domain.Model.JobPositions.JobPosition(period, sharedJobPosition, null, jobInPeriod, unitInPeriod); session.Save(jobPositionInPeriod); session.Transaction.Commit(); } }
private JobPosition createJobPositions() { JobPosition res = null; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var period = session.Query <Period>().Single(); var jpRoot = createJobPosition(period, null); assignJobPositionToEmployees(period, jpRoot); for (int i = 0; i < 5; i++) { var jpChild = createJobPosition(period, jpRoot); assignJobPositionToEmployees(period, jpChild); for (var j = 0; j < 3; j++) { var jp = createJobPosition(period, jpChild); assignJobPositionToEmployees(period, jp); } if (i == 2) { res = jpChild; } } session.Transaction.Commit(); } return(res); }
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 EmployeeRepTest() { using (var uow = new NHUnitOfWork(PMSSession.GetSession())) { var rep = new EmployeeRepository(uow); var x = rep.GetPoints(rep.First(), new CalculationId(10)); } }
public static bool ShowLoginDialog(PMSAuthRequest request, PMSSession session, string viewType) { var vw = LoginViewFactory .CreateLoginView(viewType); vw.Request = request; vw.Session = session; return((bool)(vw.ShowDialog())); }
public void EmployeeTest() { Job emp; using (var session = PMSSession.GetSession()) { long id = 98304; emp = session.Get <Job>(id); } var x = emp; }
public void LogServiceTest() { //LocatorCreator.Execute(); var container = new WindsorContainer(); container.Register(Component.For <ILoggerService>().ImplementedBy <DbLoggerService>().LifeStyle.BoundTo <IService>()); //container.Register(Component.For<ILogRepository>().ImplementedBy<LogRepository>().LifeStyle.Transient); container.Register(Component.For <IConnectionProvider>() .UsingFactoryMethod(c => new ConnectionProvider(() => { var s = System.Configuration.ConfigurationManager. ConnectionStrings["PMSDBConnection"].ConnectionString; var res = new SqlConnection(s); res.Open(); return(res); })).LifestyleBoundTo <IService>()); DataAccessConfigHelper.ConfigureContainer <UserRepository>(container, () => { var session = PMSSecuritySession.GetSession(container.Resolve <IConnectionProvider>().GetConnection()); return(session); }, "PMSSecurity"); var locator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => locator); //var userRep = ServiceLocator.Current.GetInstance<UserRepository>(); var uows = new MITD.Domain.Repository.UnitOfWorkScope( new Data.NH.NHUnitOfWorkFactory(() => PMSSecurity.Persistence.NH.PMSSecuritySession.GetSession())); using (var uow = new NHUnitOfWork(PMSSession.GetSession())) using (var uow2 = uows.CurrentUnitOfWork) { var logFactory = new LoggerServiceFactory(); var logManager = new LogManagerService(logFactory); var logService = new LogService(logManager); var gid = Guid.NewGuid(); Log log = new EventLog(new LogId(gid), "diddd", LogLevel.Information, null, "clll", "mett", "ttttt", "mmmmmmm"); logService.AddEventLog(log.Code, log.LogLevel, null, log.ClassName, log.MethodName, log.Title, log.Messages); } }
private Unit createUnitInPeriod(Period period) { Unit unit = null; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { unit = new Unit(period, GetSharedUnit(), null); session.Save(unit); session.Transaction.Commit(); } return(unit); }
private void initialized() { using (var uow = new NHUnitOfWork(PMSSession.GetSession())) { var periodRep = new PeriodRepository(uow); for (int i = 0; i < 5; i++) { var period = new Period(new PeriodId(periodRep.GetNextId()), "Test", DateTime.Now, DateTime.Now, 91); periodRep.Add(period); } uow.Commit(); } }
public void ConfigeJobPositionInquiry() { using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { JobPosition jp = createJobPositions(); var jpRep = new MITD.PMS.Persistence.NH.JobPositionRepository(new NHUnitOfWork(session)); var jobPositionForConfig = jpRep.GetBy(jp.Id); var configService = new JobPositionInquiryConfiguratorService(new MITD.PMS.Persistence.NH.JobPositionRepository(new NHUnitOfWork(session))); jobPositionForConfig.ConfigeInquirer(configService, true); session.Save(jobPositionForConfig); session.Transaction.Commit(); } }
private JobIndex createJobIndexInPeriod(Period period) { JobIndex jobIndex = null; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var jiRep = new PMS.Persistence.NH.JobIndexRepository(new NHUnitOfWork(session)); var id = jiRep.GetNextId(); jobIndex = new JobIndex(id, period, getSharedJobIndex(), jiRep.GetJobIndexGroupById(new Domain.Model.JobIndices.AbstractJobIndexId(1)), true); session.Save(jobIndex); session.Transaction.Commit(); } return(jobIndex); }
private JobPosition createJobPosition(Period period, JobPosition parentPosition) { JobPosition res = null; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var sharedJp = createSharedJobPosition(); var unit = createUnitInPeriod(period); var job = createJobInPeriod(period); res = new JobPosition(period, sharedJp, parentPosition, job, unit); session.Save(res); session.Transaction.Commit(); } return(res); }
public void isFullInquiryForms()//Period period) { JobIndex jobIndex = null; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { //var jiRep = new PMS.Persistence.NH.JobIndexRepository(new NHUnitOfWork(session)); var jiRep = new PMS.Persistence.NH.InquiryJobIndexPointRepository(new NHUnitOfWork(session)); var pRep = new PMS.Persistence.NH.PeriodRepository(new NHUnitOfWork(session)); var period = pRep.GetAll().First(); var has = jiRep.IsAllInquiryJobIndexPointsHasValue(period); //var id = jiRep.GetNextId(); //jobIndex = new JobIndex(id, period, getSharedJobIndex(),jiRep.GetJobIndexGroupById(new Domain.Model.JobIndices.AbstractJobIndexId(1)),true); //session.Save(jobIndex); session.Transaction.Commit(); } }
private Job createJobInPeriod(Period period) { Job job = null; var jobIndexInperiodList = new List <JobIndex>(); for (int i = 0; i < 5; i++) { var jobIndex = createJobIndexInPeriod(period); jobIndexInperiodList.Add(jobIndex); } using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { job = new Job(period, GetSharedJob(), null, new List <JobJobIndex>()); session.Save(job); session.Transaction.Commit(); } return(job); }
private IEnumerable <Employee> createEmployees(Period period) { var empList = new List <Employee>(); using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { for (int i = 0; i < 2; i++) { var emp = new Employee(Guid.NewGuid().ToString(), period, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); empList.Add(emp); session.Save(emp); } session.Transaction.Commit(); } return(empList); }
public void Start(Calculation calculation) { Task.Factory.StartNew(() => { publisher.RegisterHandler(new JobIndexPointPersister()); using (var transaction = new TransactionScope()) using (var reuow = new NHUnitOfWork(RuleEngineSession.GetSession())) using (var uow = new NHUnitOfWork(PMSSession.GetSession())) { var empRep = new EmployeeRepository(uow); var rebps = new RuleBasedPolicyEngineService(new LocatorProvider("PMSDb"), publisher); var policyRep = new MITD.PMS.Persistence.NH.PolicyRepository(uow, new PolicyConfigurator(rebps)); var policy = policyRep.GetById(calculation.PolicyId); var periodRep = new PeriodRepository(uow); var period = periodRep.GetById(calculation.PeriodId); var jiRep = new JobIndexRepository(uow); var jpRep = new JobPositionRepository(uow); var jipRep = new JobIndexPointRepository(uow); var ji = jiRep.GetAllJobIndex(period.Id).First(); var jp = jpRep.GetJobPositions(period.Id).First(); var en = calculation.EmployeeIdList.Select(i => i.EmployeeNo).ToList(); IList <Employee> employees = empRep.Find(e => en.Contains(e.Id.EmployeeNo) && e.Id.PeriodId == calculation.PeriodId); foreach (var employee in employees) { if (doStop) { break; } //var indices = policy.CalculateFor(DateTime.Now, employee, period,calculation, // new CalculationDataProvider(empRep),publisher, ); //publisher.Publish(new JobIndexPointsReady(indices)); } reuow.Commit(); uow.Commit(); transaction.Complete(); } }); }
private void assignJobPositionToEmployees(Period period, JobPosition jPosition) { var empList = createEmployees(period); using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var empRep = new EmployeeRepository(new NHUnitOfWork(session)); var jpRep = new MITD.PMS.Persistence.NH.JobPositionRepository(new NHUnitOfWork(session)); foreach (var emp in empList) { var employee = empRep.GetBy(emp.Id); var jobPosition = jpRep.GetBy(jPosition.Id); employee.AssignJobPosition(jobPosition, DateTime.Now, DateTime.Now, 0, 1, null); session.Save(employee); } session.Transaction.Commit(); } }
public void CalculationWithExceptionTest() { using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { //var calc = session.Query<Calculation>().Where(c => c.Id.Id == 10).FirstOrDefault(); //var emp = session.Query<Employee>().FirstOrDefault(); //List<EmployeeCalculationException> expList = new List<EmployeeCalculationException>(); //var exp = new EmployeeCalculationException(calc, emp.Id, 0, "dddddd"); //expList.Add(exp); //calc.UpdateCalculationException(expList); //session.Transaction.Commit(); } using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var calc = session.Query <Calculation>().Where(c => c.Id.Id == 10).FirstOrDefault(); } }
public void AssignJobPositionToEmployee() { using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var period = session.Query <Period>().First(); var employee = new Employee(Guid.NewGuid().ToString(), period, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); SharedEmployeeCustomField sharedEmployeeCustomField; JobCustomField sharedJobCustomField; using (var adminSession = PMSAdminSession.GetSession()) using (adminSession.BeginTransaction()) { var employeeCustomFielType = adminSession.Query <CustomFieldType>().First(); sharedEmployeeCustomField = new SharedEmployeeCustomField(new SharedEmployeeCustomFieldId(employeeCustomFielType.Id.Id), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1); //sharedJobCustomField = // new JobCustomField(new JobCustomFieldId(employeeCustomFielType.Id.Id), // Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1); } employee.AssignCustomFieldAndValue(sharedEmployeeCustomField, "30"); var jobposition = session.Query <JobPosition>().FirstOrDefault(); //employee.AssignJobPosition(jobposition, DateTime.Now.Date, DateTime.Now.Date, // new Dictionary<JobCustomField, string> {{sharedJobCustomField, "10"}}); session.Save(employee); session.Transaction.Commit(); using (session.BeginTransaction()) { var newEmployee = session.Query <Employee>() .FirstOrDefault( e => e.Id.EmployeeNo == employee.Id.EmployeeNo && e.Id.PeriodId == employee.Id.PeriodId); //newEmployee.AssignJobPositions(null, ); session.Update(newEmployee); session.Transaction.Commit(); } } }
public void Handle(JobIndexPointsReady eventData) { Task.Factory.StartNew(() => { using (var transaction = new TransactionScope()) using (var uow = new NHUnitOfWork(PMSSession.GetSession())) { var rep = new JobIndexPointRepository(uow); foreach (var item in eventData.PointsHolder.EmployeePointsForAdd) { rep.Add(item); } foreach (var item in eventData.PointsHolder.EmployeePointsForUpdate) { var employeePoint = rep.GetById(item.Key); employeePoint.SetValue(item.Value); } uow.Commit(); transaction.Complete(); } }); }
public void AddUpdateEmployeeTest() { using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var period = session.Query <Period>().First(); var employee = new Employee(Guid.NewGuid().ToString(), period, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); SharedEmployeeCustomField sharedEmployeeCustomField; using (var adminSession = PMSAdminSession.GetSession()) using (adminSession.BeginTransaction()) { var employeeCustomFielType = adminSession.Query <CustomFieldType>().First(); sharedEmployeeCustomField = new SharedEmployeeCustomField(new SharedEmployeeCustomFieldId(employeeCustomFielType.Id.Id), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1); } employee.AssignCustomFieldAndValue(sharedEmployeeCustomField, "30"); session.Save(employee); session.Transaction.Commit(); using (session.BeginTransaction()) { var rep = new EmployeeRepository(new NHUnitOfWork(session)); var fs = new ListFetchStrategy <Employee>(Enums.FetchInUnitOfWorkOption.NoTracking); fs.WithPaging(10, 1); fs.OrderBy(c => c.Id); rep.Find(e => e.Id.PeriodId == new PeriodId(1), fs); var newEmployee = session.Query <Employee>() .FirstOrDefault( e => e.Id.EmployeeNo == employee.Id.EmployeeNo && e.Id.PeriodId == employee.Id.PeriodId); newEmployee.Update("ehsan", "mohammadi"); session.Update(newEmployee); session.Transaction.Commit(); } } }
public void EmployeesInJobIndexLevelTest() { int firstLevel = 1; var periodId = new PeriodId(10); var enList = new string[] { "2000", "4000", "8000", "12000", "16000" }; var res = new Dictionary <int, IList <EmployeeId> >(); var calculationId = new CalculationId(10); using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var calculationExpRep = new CalculationExceptionRepository(new NHUnitOfWork(session)); var employeeJobs = (from jo in session.Query <Job>() join i in session.Query <JobPositionEmployee>() on jo.Id equals i.JobPosition.JobId where enList.Contains(i.EmployeeId.EmployeeNo) && i.EmployeeId.PeriodId == periodId select new { jo, i.EmployeeId });//.Distinct(); IEnumerable <EmployeeId> empCompletedInFirstLevel = new List <EmployeeId>(); Calculation calculation = null; if (calculationId != null) { calculation = session.Query <Calculation>().Where(c => c.Id == calculationId).SingleOrDefault(); if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedPath.HasValue) { firstLevel = calculation.CalculationResult.LastCalculatedPath.Value; } } var dummy = employeeJobs.Select(empJob => empJob.jo).Fetch(j => j.JobIndexList).ToFuture(); var employeeJobindexes = session.Query <Domain.Model.JobIndices.JobIndex>() .Where(j => employeeJobs.Select(empJob => empJob.jo).SelectMany(jo => jo.JobIndexList).Select(ji => ji.JobIndexId.Id).Contains(j.Id.Id)) .ToFuture(); var jobIndexLevels = employeeJobindexes.Where(ji => ji.CalculationLevel >= firstLevel).Select(ji => ji.CalculationLevel).Distinct().ToList(); //var empJobInexIdsLevel1 = employeeJobindexes.Where(ji=>jei.CalculationLevel ==1).Select(ji => ji.Id).ToList(); //var empLevel1 = employeeJobs.Where(empj => empj.jo.JobIndexList.Any(i => empJobInexIdsLevel1.Contains(i))).Select(empj => empj.EmployeeId).ToList(); for (int level = firstLevel; level <= jobIndexLevels.Max(); level++) { var empJobInexIdsLevel = employeeJobindexes.Where(ji => ji.CalculationLevel == level).Select(ji => ji.Id).ToList(); var empLevel = employeeJobs.Where(empj => empj.jo.JobIndexList.Select(j => j.JobIndexId).Any(i => empJobInexIdsLevel.Contains(i))) .Select(empj => empj.EmployeeId).OrderBy(emp => emp.EmployeeNo).ToList(); if (level == firstLevel) { if (calculation.CalculationResult != null && calculation.CalculationResult.LastCalculatedEmployeeId != null) { var enNotCompletedInFirstLevel = enList.Skip( enList.ToList().FindLastIndex(s => s == calculation.CalculationResult.LastCalculatedEmployeeId.EmployeeNo) + 1); //var expEmployeeIds = calculation.EmployeeCalculationExceptions.Select(exp => exp.EmployeeId).ToList(); var expEmployeeIds = calculationExpRep.GetAllBy(calculationId).Select(exp => exp.EmployeeId).ToList(); enNotCompletedInFirstLevel = enNotCompletedInFirstLevel.Union(expEmployeeIds.Select(exp => exp.EmployeeNo)); empLevel = empLevel.Where(emp => enNotCompletedInFirstLevel.Contains(emp.EmployeeNo)).ToList(); } } res.Add(level, empLevel); } } }
/// <summary> /// Validates the session. /// </summary> /// <param name="pmsSession">The PMS session.</param> /// <returns></returns> public PMSSession ValidateSession(PMSSession pmsSession) { throw new NotImplementedException(); }
/// <summary> /// Gets the shell user info. /// </summary> /// <param name="pmsSession">The PMS session.</param> /// <returns></returns> public ShellUserInfo GetShellUserInfo(PMSSession pmsSession) { throw new NotImplementedException(); }
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++; } } } } }
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 JobIndexPointTest() { PMSAdmin.Domain.Model.JobIndices.JobIndex jobIndex; PMSAdmin.Domain.Model.JobPositions.JobPosition jobPosition; PMSAdmin.Domain.Model.Jobs.Job job; PMSAdmin.Domain.Model.Units.Unit unit; RuleEngineBasedPolicy policy; long x = 190; using (var tr = new TransactionScope()) using (var adminSession = PMSAdminSession.GetSession()) { policy = new RuleEngineBasedPolicy(new PolicyId(x), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(policy); var jobIndexCategory = new PMSAdmin.Domain.Model.JobIndices.JobIndexCategory( new PMSAdmin.Domain.Model.JobIndices.AbstractJobIndexId(x + 1), null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(jobIndexCategory); jobIndex = new PMSAdmin.Domain.Model.JobIndices.JobIndex( new PMSAdmin.Domain.Model.JobIndices.AbstractJobIndexId(x + 2), jobIndexCategory, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(jobIndex); unit = new PMSAdmin.Domain.Model.Units.Unit(new PMSAdmin.Domain.Model.Units.UnitId(x + 3), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(unit); job = new PMSAdmin.Domain.Model.Jobs.Job(new PMSAdmin.Domain.Model.Jobs.JobId(x + 4), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(job); jobPosition = new JobPosition(new PMSAdmin.Domain.Model.JobPositions.JobPositionId(x + 5) , Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); adminSession.Save(jobPosition); adminSession.Flush(); tr.Complete(); } long y = x - 4; Employee emp; using (var tr = new TransactionScope()) using (var session = PMSSession.GetSession()) { var policy2 = session.Get <MITD.PMS.Domain.Model.Policies.RuleEngineBasedPolicy>( new MITD.PMS.Domain.Model.Policies.PolicyId(policy.Id.Id)); var period = new Period(new PeriodId(y), Guid.NewGuid().ToString(), DateTime.Now, DateTime.Now, 91); //period.Activate(null); session.Save(period); emp = new Employee(Guid.NewGuid().ToString(), period, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); session.Save(emp); var calc = new Calculation(new CalculationId(y), period, policy2, Guid.NewGuid().ToString(), DateTime.Now, "1"); session.Save(calc); var jobIndexGroup = new JobIndexGroup(new AbstractJobIndexId(y), period, null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); session.Save(jobIndexGroup); var ji = new JobIndex(new AbstractJobIndexId(y + 1), period, new SharedJobIndex( new SharedJobIndexId(jobIndex.Id.Id), jobIndex.Name, jobIndex.DictionaryName), jobIndexGroup, true); session.Save(ji); var j = new Job(period, new SharedJob(new SharedJobId(job.Id.Id), job.Name, job.DictionaryName)); session.Save(j); var u = new Unit(period, new SharedUnit(new SharedUnitId(unit.Id.Id), unit.Name, unit.DictionaryName), null); session.Save(u); var jp = new Domain.Model.JobPositions.JobPosition(period, new SharedJobPosition( new SharedJobPositionId(jobPosition.Id.Id), jobPosition.Name, jobPosition.DictionaryName), null, j, u); session.Save(jp); EmployeePoint p = new JobIndexPoint(new CalculationPointId(y), period, emp, calc, jp, ji, "hh", 10); session.Save(p); p = new SummaryEmployeePoint(new CalculationPointId(y + 1), period, emp, calc, "ff", 10); session.Save(p); session.Flush(); tr.Complete(); } using (var tr = new TransactionScope()) using (var session = PMSSession.GetSession()) { var lst = session.Query <EmployeePoint>().ToList(); session.Flush(); tr.Complete(); } }
public void JobIndexInPeriodTest() { long nextAbsIndexId; long jobIndexId; using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var period = session.Query <Period>().FirstOrDefault(); nextAbsIndexId = session.CreateSQLQuery("Select next value for dbo.Periods_AbstractJobIndexSeq").UniqueResult <long>(); var rootJobIndexCat = new JobIndexGroup(new AbstractJobIndexId(nextAbsIndexId), period, null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); session.Save((AbstractJobIndex)rootJobIndexCat); SharedJobIndex sharedJobIndex; SharedJobIndexCustomField sharedJobIndexCustomField; using (var sessionAdmin = PMSAdminSession.GetSession()) { var pmsAdminJobIndex = sessionAdmin.Query <MITD.PMSAdmin.Domain.Model.JobIndices.JobIndex>().FirstOrDefault(); sharedJobIndex = new SharedJobIndex(new SharedJobIndexId(pmsAdminJobIndex.Id.Id), pmsAdminJobIndex.Name, pmsAdminJobIndex.DictionaryName); var customFld = sessionAdmin.Query <CustomFieldType>().SingleOrDefault(); sharedJobIndexCustomField = new SharedJobIndexCustomField(new SharedJobIndexCustomFieldId(customFld.Id.Id), customFld.Name, customFld.DictionaryName, 1, 100); } nextAbsIndexId = session.CreateSQLQuery("Select next value for dbo.Periods_AbstractJobIndexSeq").UniqueResult <long>(); var jobIndex = new JobIndex(new AbstractJobIndexId(nextAbsIndexId), period, sharedJobIndex, rootJobIndexCat, true); jobIndex.UpdateCustomFields(new Dictionary <SharedJobIndexCustomField, string>() { { sharedJobIndexCustomField, "asdasdasdasd" } }); session.Save(jobIndex); session.Transaction.Commit(); } using (var session = PMSSession.GetSession()) using (session.BeginTransaction()) { var jobIndex = session.Query <JobIndex>().SingleOrDefault(j => j.Id == new AbstractJobIndexId(nextAbsIndexId)); // var rootJobIndexCat = session.Query<JobIndexCategory>().SingleOrDefault(p => p.Id == new AbstractJobIndexId(nextAbsIndexId)); // nextAbsIndexId = session.CreateSQLQuery("Select next value for dbo.AbstractJobIndexSeq").UniqueResult<long>(); // var jobIndexCat = new JobIndexCategory(new AbstractJobIndexId(nextAbsIndexId), rootJobIndexCat, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); // session.Save((AbstractJobIndex)jobIndexCat); // jobIndexId = session.CreateSQLQuery("Select next value for dbo.AbstractJobIndexSeq").UniqueResult<long>(); // var jobIndex = new JobIndex(new AbstractJobIndexId(jobIndexId), jobIndexCat, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); // session.Save((AbstractJobIndex)jobIndex); // session.Transaction.Commit(); } }