예제 #1
0
        public static void CreatePolicy(IPolicyRepository policyRepository, string name, string dictionaryName)
        {
            var policy = new RuleEngineBasedPolicy(policyRepository.GetNextId(), name, dictionaryName);

            policyRepository.Add(policy);
            foreach (var rule in rules)
            {
                policy.AssignRule(rule);
            }
            foreach (var function in ruleFunctions)
            {
                policy.AssignRuleFunction(function);
            }
            Policy = policy;
        }
예제 #2
0
        public void SetupForCalculation(RuleEngineBasedPolicy policy, IEventPublisher publisher)
        {
            domain        = setupAppDomain();
            ruleEngine    = createRuleEngine();
            ruleFunctions = policy.RuleFunctions;

            var ruleDic = policy.Rules.ToDictionary(x => "Rule" + x.Id);

            ruleClasses = ruleEngine.SetupForCalculation("MITD.Core.RuleEngine", ruleDic, ruleFunctions);
            if (!string.IsNullOrEmpty(ruleEngine.CompileResult.Message))
            {
                throw new Exception(ruleEngine.CompileResult.Message);
            }
            hasBeenSetup       = true;
            preCalculationDone = false;
            publisher.Publish(new RulesCompiled(ruleEngine.CompileResult, ruleClasses));
        }
예제 #3
0
 public Policy AddPolicy(string name, string dictionaryName)
 {
     try
     {
         using (var scope = new TransactionScope())
         {
             var id     = policyRep.GetNextId();
             var policy = new RuleEngineBasedPolicy(id, name, dictionaryName);
             policyRep.Add(policy);
             scope.Complete();
             return(policy);
         }
     }
     catch (Exception exp)
     {
         var res = policyRep.TryConvertException(exp);
         if (res == null)
         {
             throw;
         }
         throw res;
     }
 }
예제 #4
0
        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();
                }
        }