Exemple #1
0
 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);
     //
 }
Exemple #2
0
 public KpisInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #3
0
 public TypeInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #4
0
 public PmsConfigsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #5
0
 public MenuInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #6
0
 public GroupsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #7
0
 public MeasurementsInstaller(DataContext context)
 {
     _context = context;
 }
 public KpiAchievementsInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #9
0
 public PeriodeInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #10
0
 public PillarsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #11
0
 public ActivityInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
 public ScoreIndicatorsInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #13
0
 public PmsSummariesInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #14
0
 public UsersInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #15
0
 public RoleGroupsInstaller(DataContext context)
 {
     _context = context;
 }
 public KpiWithRelationModelInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #17
0
        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());
        }
Exemple #18
0
 public LevelsInstaller(DataContext context)
 {
     _context = context;
 }
Exemple #19
0
 public MethodInstaller(DataContext dataContext)
 {
     _dataContext = dataContext;
 }