コード例 #1
0
ファイル: ScenarioScheduler.cs プロジェクト: fazar/Pear
 public ScenarioScheduler()
 {
     Schedule(() =>
     {
         using (var dataContext = new DataContext())
         {
             try
             {
                 IScenarioService scenarioService = new ScenarioService(dataContext);
                 IOutputConfigService outputService = new OutputConfigService(dataContext);
                 var scenarios = scenarioService.GetScenarios(new GetScenariosRequest { Take = 0 }).Scenarios;
                 //var outputResults = new List<CalculateOutputResponse>();
                 foreach (var scenario in scenarios)
                 {
                     var outputResult = outputService.CalculateOputput(new CalculateOutputRequest { ScenarioId = scenario.Id });
                     SerializationHelper.SerializeObject<CalculateOutputResponse>(outputResult, "output-scenario-" + scenario.Id);
                 }
             }
             catch
             {
                 //logging here
             }
         }
     }).ToRunEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(0, 0);
     //
 }
コード例 #2
0
ファイル: KpisInstaller.cs プロジェクト: fazar/Pear
 public KpisInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #3
0
ファイル: TypeInstaller.cs プロジェクト: fazar/Pear
 public TypeInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #4
0
ファイル: PmsConfigsInstaller.cs プロジェクト: fazar/Pear
 public PmsConfigsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #5
0
ファイル: MenuInstaller.cs プロジェクト: fazar/Pear
 public MenuInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #6
0
ファイル: GroupsInstaller.cs プロジェクト: fazar/Pear
 public GroupsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #7
0
ファイル: MeasurementsInstaller.cs プロジェクト: fazar/Pear
 public MeasurementsInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #8
0
 public KpiAchievementsInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #9
0
ファイル: PeriodeInstaller.cs プロジェクト: fazar/Pear
 public PeriodeInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #10
0
ファイル: PillarsInstaller.cs プロジェクト: fazar/Pear
 public PillarsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #11
0
ファイル: ActivityInstaller.cs プロジェクト: fazar/Pear
 public ActivityInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #12
0
 public ScoreIndicatorsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #13
0
ファイル: PmsSummariesInstaller.cs プロジェクト: fazar/Pear
 public PmsSummariesInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
コード例 #14
0
ファイル: UsersInstaller.cs プロジェクト: fazar/Pear
 public UsersInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #15
0
ファイル: RoleGroupsInstaller.cs プロジェクト: fazar/Pear
 public RoleGroupsInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #16
0
 public KpiWithRelationModelInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #17
0
ファイル: KpiTransformationJob.cs プロジェクト: fazar/Pear
        public void Process(SaveKpiTransformationScheduleResponse kpiTransformationSchedule)
        {
            var kpiPattern = @"k(\d+)";
            JobManager.AddJob(() =>
            {
                var complete = true;
                using (var dataContext = new DataContext())
                {
                    var kpiAchievementService = new KpiAchievementService(dataContext);
                    var logService = new KpiTransformationLogService(dataContext);
                    var kpiTransformationScheduleService = new KpiTransformationScheduleService(dataContext);
                    var kpiService = new KpiService(dataContext);
                    for (var date = kpiTransformationSchedule.Start; date <= kpiTransformationSchedule.End; date = Increment(kpiTransformationSchedule, date))
                    {
                        foreach (var kpi in kpiTransformationSchedule.SelectedKpis)
                        {
                            try
                            {
                                var kpiTransformed = kpi.CustomFormula;
                                var ytdTransformed = kpi.CustomFormula;
                                var mtdTransformed = kpi.CustomFormula;
                                var itdTransformed = kpi.CustomFormula;
                                var existingKpiActual = kpiAchievementService.GetKpiAchievement(kpi.Id, date, kpiTransformationSchedule.PeriodeType);
                                if (kpi.MethodId == 1)
                                {
                                    if (string.IsNullOrEmpty(kpi.CustomFormula)) {
                                        //log here for dependency error
                                        var logRequest = new SaveKpiTransformationLogRequest
                                        {
                                            KpiId = kpi.Id,
                                            KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                            Periode = date,
                                            Status = KpiTransformationStatus.Error,
                                            Notes = "Method input is formula but the formula is not defined"
                                        };
                                        logService.Save(logRequest);
                                        continue;
                                    }
                                    Regex r = new Regex(kpiPattern, RegexOptions.IgnoreCase);
                                    Match m = r.Match(kpi.CustomFormula);
                                    var meetRequirements = true;
                                    while (m.Success)
                                    {
                                        Group g = m.Groups[1];
                                        var relatedKpiId = int.Parse(g.Value);
                                        var relatedKpiActual = kpiAchievementService.GetKpiAchievement(relatedKpiId, date, kpiTransformationSchedule.PeriodeType);
                                        if (relatedKpiActual.IsSuccess && relatedKpiActual.Value.HasValue)
                                        {
                                            kpiTransformed = Regex.Replace(kpiTransformed, "k" + g.Value, relatedKpiActual.Value.ToString(), RegexOptions.IgnoreCase);
                                            if (kpi.YtdFormula == YtdFormula.Custom)
                                            {
                                                if (relatedKpiActual.Mtd.HasValue && relatedKpiActual.Ytd.HasValue && relatedKpiActual.Itd.HasValue)
                                                {
                                                    switch (kpiTransformationSchedule.PeriodeType)
                                                    {
                                                        case PeriodeType.Daily:
                                                            mtdTransformed = Regex.Replace(mtdTransformed, "k" + g.Value, relatedKpiActual.Mtd.ToString(), RegexOptions.IgnoreCase);
                                                            ytdTransformed = Regex.Replace(ytdTransformed, "k" + g.Value, relatedKpiActual.Ytd.ToString(), RegexOptions.IgnoreCase);
                                                            itdTransformed = Regex.Replace(itdTransformed, "k" + g.Value, relatedKpiActual.Itd.ToString(), RegexOptions.IgnoreCase);
                                                            break;
                                                        case PeriodeType.Monthly:
                                                            ytdTransformed = Regex.Replace(ytdTransformed, "k" + g.Value, relatedKpiActual.Ytd.ToString(), RegexOptions.IgnoreCase);
                                                            itdTransformed = Regex.Replace(itdTransformed, "k" + g.Value, relatedKpiActual.Itd.ToString(), RegexOptions.IgnoreCase);
                                                            break;
                                                        case PeriodeType.Yearly:
                                                            itdTransformed = Regex.Replace(itdTransformed, "k" + g.Value, relatedKpiActual.Itd.ToString(), RegexOptions.IgnoreCase);
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                                else
                                                {
                                                    //log here for dependency error
                                                    var logRequest = new SaveKpiTransformationLogRequest
                                                    {
                                                        KpiId = kpi.Id,
                                                        KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                        Periode = date,
                                                        Status = KpiTransformationStatus.Error,
                                                        Notes = "The aggregation for <strong>" + relatedKpiActual.Kpi.Name + " (" + relatedKpiActual.Kpi.Measurement + ")</strong> has not been proceed"
                                                    };
                                                    logService.Save(logRequest);
                                                    meetRequirements = false;
                                                    complete = false;
                                                }

                                            }
                                        }
                                        else
                                        {
                                            var relatedKpi = kpiService.GetBy(new Services.Requests.Kpi.GetKpiRequest { Id = relatedKpiId });
                                            var logRequest = new SaveKpiTransformationLogRequest
                                            {
                                                KpiId = kpi.Id,
                                                KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                Periode = date,
                                                Status = KpiTransformationStatus.Error,
                                                Notes = "Kpi <strong>" + relatedKpi.Name + " (" + relatedKpi.Measurement.Name + ")</strong> has no value for this periode of time"
                                            };
                                            logService.Save(logRequest);
                                            meetRequirements = false;
                                            complete = false;
                                        }
                                        m = m.NextMatch();
                                    }
                                    if (kpi.YtdFormula == YtdFormula.Custom )
                                    {
                                        if (meetRequirements) {
                                            var kpiActualRequest = new UpdateKpiAchievementItemRequest
                                            {
                                                Id = existingKpiActual.IsSuccess ? existingKpiActual.Id : 0,
                                                KpiId = kpi.Id,
                                                Periode = date,
                                                PeriodeType = kpiTransformationSchedule.PeriodeType,
                                                Value = new Expression(kpiTransformed).Evaluate().ToString(),
                                                UserId = kpiTransformationSchedule.UserId
                                            };
                                            if (mtdTransformed != kpi.CustomFormula)
                                            {
                                                kpiActualRequest.Mtd = (double?)new Expression(mtdTransformed).Evaluate();
                                            }
                                            if (ytdTransformed != kpi.CustomFormula)
                                            {
                                                kpiActualRequest.Ytd = (double?)new Expression(ytdTransformed).Evaluate();
                                            }
                                            if (itdTransformed != kpi.CustomFormula)
                                            {
                                                kpiActualRequest.Itd = (double?)new Expression(itdTransformed).Evaluate();
                                            }
                                            kpiActualRequest.UpdateDeviation = true;
                                            var resp = kpiAchievementService.UpdateKpiAchievementItem(kpiActualRequest);
                                            if (resp.IsSuccess)
                                            {
                                                switch (kpiTransformationSchedule.PeriodeType)
                                                {
                                                    case PeriodeType.Daily:
                                                        kpiAchievementService.UpdateKpiAchievementItem(kpi.Id, PeriodeType.Monthly, new DateTime(date.Year, date.Month, 1), kpiActualRequest.Mtd, kpiTransformationSchedule.UserId);
                                                        kpiAchievementService.UpdateKpiAchievementItem(kpi.Id, PeriodeType.Yearly, new DateTime(date.Year, 1, 1), kpiActualRequest.Ytd, kpiTransformationSchedule.UserId);
                                                        break;
                                                    case PeriodeType.Monthly:
                                                        kpiAchievementService.UpdateKpiAchievementItem(kpi.Id, PeriodeType.Yearly, new DateTime(date.Year, 1, 1), kpiActualRequest.Ytd, kpiTransformationSchedule.UserId);
                                                        break;
                                                    default:
                                                        break;
                                                }

                                                var logRequest = new SaveKpiTransformationLogRequest
                                                {
                                                    KpiId = kpi.Id,
                                                    KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                    Periode = date,
                                                    Status = KpiTransformationStatus.Complete,
                                                };
                                                logService.Save(logRequest);
                                            }
                                            else
                                            {
                                                var logRequest = new SaveKpiTransformationLogRequest
                                                {
                                                    KpiId = kpi.Id,
                                                    KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                    Periode = date,
                                                    Status = KpiTransformationStatus.Error,
                                                    Notes = resp.Message
                                                };
                                                logService.Save(logRequest);
                                                complete = false;
                                            }

                                        }

                                    }
                                    else
                                    {
                                        if (meetRequirements)
                                        {
                                            var request = new UpdateKpiAchievementItemRequest
                                            {
                                                Periode = date,
                                                PeriodeType = kpiTransformationSchedule.PeriodeType,
                                                Id = existingKpiActual.IsSuccess ? existingKpiActual.Id : 0,
                                                KpiId = kpi.Id,
                                                UserId = kpiTransformationSchedule.UserId,
                                                Value = new Expression(kpiTransformed).Evaluate().ToString()
                                            };
                                            var resp = kpiAchievementService.UpdateOriginalData(request);
                                            if (resp.IsSuccess)
                                            {
                                                var logRequest = new SaveKpiTransformationLogRequest
                                                {
                                                    KpiId = kpi.Id,
                                                    KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                    Periode = date,
                                                    Status = KpiTransformationStatus.Complete,
                                                };
                                                logService.Save(logRequest);
                                            }
                                            else
                                            {
                                                var logRequest = new SaveKpiTransformationLogRequest
                                                {
                                                    KpiId = kpi.Id,
                                                    KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                                    Periode = date,
                                                    Status = KpiTransformationStatus.Error,
                                                    Notes = resp.Message
                                                };
                                                logService.Save(logRequest);
                                                complete = false;
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    var request = new UpdateKpiAchievementItemRequest
                                    {
                                        Periode = date,
                                        PeriodeType = kpiTransformationSchedule.PeriodeType,
                                        Id = existingKpiActual.IsSuccess ? existingKpiActual.Id : 0,
                                        KpiId = kpi.Id,
                                        UserId = kpiTransformationSchedule.UserId,
                                        Value = existingKpiActual.Value.ToString(),
                                        Remark = existingKpiActual.Remark
                                    };
                                    var resp = kpiAchievementService.UpdateOriginalData(request);
                                    if (resp.IsSuccess)
                                    {
                                        var logRequest = new SaveKpiTransformationLogRequest
                                        {
                                            KpiId = kpi.Id,
                                            KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                            Periode = date,
                                            Status = KpiTransformationStatus.Complete,
                                        };
                                        logService.Save(logRequest);
                                    }
                                    else
                                    {
                                        var logRequest = new SaveKpiTransformationLogRequest
                                        {
                                            KpiId = kpi.Id,
                                            KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                            Periode = date,
                                            Status = KpiTransformationStatus.Error,
                                            Notes = resp.Message
                                        };
                                        logService.Save(logRequest);
                                        complete = false;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                var logRequest = new SaveKpiTransformationLogRequest
                                {
                                    KpiId = kpi.Id,
                                    KpiTransformationScheduleId = kpiTransformationSchedule.Id,
                                    Periode = date,
                                    Status = KpiTransformationStatus.Error,
                                    Notes = "Excception Message :" + e.Message + "<br/>Inner Exception Message : " + (e.InnerException != null ? e.InnerException.Message : "")
                                };
                                logService.Save(logRequest);
                                complete = false;
                            }

                        }
                        if (complete)
                        {
                            kpiTransformationScheduleService.UpdateStatus(kpiTransformationSchedule.Id, KpiTransformationStatus.Complete);
                        }
                        else
                        {
                            kpiTransformationScheduleService.UpdateStatus(kpiTransformationSchedule.Id, KpiTransformationStatus.Error);
                        }
                    }
                }

            }, (s) => s.ToRunNow());
        }
コード例 #18
0
ファイル: LevelsInstaller.cs プロジェクト: fazar/Pear
 public LevelsInstaller(DataContext context)
 {
     _context = context;
 }
コード例 #19
0
ファイル: MethodInstaller.cs プロジェクト: fazar/Pear
 public MethodInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }