/// <summary> /// Adds the or update monthly targets. /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="monthlyTargets">The monthly targets.</param> /// <param name="userName">Name of the user.</param> public void AddOrUpdateMonthlyTargets(int targetId, IList <RollupTargetItem> monthlyTargets, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName)?.Id ?? 0; DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); foreach (RollupTargetItem target in monthlyTargets) { if (target.TargetId.HasValue) { var existingMonthlyTarget = monthlyTargetRepository.Get(target.TargetId.Value); existingMonthlyTarget.RolledUpGoalValue = target.RollUpValue; existingMonthlyTarget.LastModifiedBy = loggedInUserId; existingMonthlyTarget.LastModifiedOn = curTimestamp; var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget); monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId; existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory); } else { if (target.RollUpValue.HasValue) { var monthlyTarget = CreateMonthlyRollupTarget(targetId, target.TargetEntryDate.Month, loggedInUserId); monthlyTarget.RolledUpGoalValue = target.RollUpValue; monthlyTargetRepository.AddOrUpdate(monthlyTarget); } } } monthlyTargetRepository.Save(); }
/// <summary> /// Updates the existing monthly target. /// </summary> /// <param name="existingMonthlyTarget">The existing monthly target.</param> /// <param name="targetValue">The target value.</param> /// <param name="targetEntryDate">The target entry date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> /// <returns></returns> private MonthlyTarget UpdateExistingMonthlyRollupTarget(MonthlyTarget existingMonthlyTarget, int loggedInUserId) { DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); existingMonthlyTarget.LastModifiedBy = loggedInUserId; existingMonthlyTarget.LastModifiedOn = curTimestamp; var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget); monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId; existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory); return(existingMonthlyTarget); }
/// <summary> /// Convert the given method into optimized Ast format. /// </summary> protected static AstNode CreateOptimizedAst(AssemblyCompiler compiler, MethodSource source) { // Build AST DecompilerContext context; AstBlock ast; if (source.IsDotNet) { context = new DecompilerContext(source.Method); var astBuilder = new IL2Ast.AstBuilder(source.ILMethod, true, context); var children = astBuilder.Build(); ast = new AstBlock(children.Select(x => x.SourceLocation).FirstOrDefault(), children); if ((source.ILMethod.IsConstructor) && (source.Method.DeclaringType.Fields.Any(x => x.FieldType.IsEnum()))) { // Ensure all fields are initialized AddFieldInitializationCode(source, ast); } if (source.Method.NeedsGenericInstanceTypeParameter && (source.Name == ".ctor")) { // Add code to safe the generic instance type parameter into the generic instance field. AddGenericInstanceFieldInitializationCode(ast); } } else if (source.IsJava) { var astBuilder = new Java2Ast.AstBuilder(compiler.Module, source.JavaMethod, source.Method.DeclaringType, true); context = new DecompilerContext(source.Method); ast = astBuilder.Build(); } else if (source.IsAst) { context = new DecompilerContext(source.Method); ast = source.Ast; } else { throw new NotSupportedException("Unknown source"); } // Optimize AST var astOptimizer = new AstOptimizer(context, ast); astOptimizer.Optimize(); // Optimize AST towards the target TargetConverters.Convert(context, ast, source, compiler); // Return return return(ast); }
/// <summary> /// Creates the monthly target. /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="targetValue">The target value.</param> /// <param name="targetEntryDate">The target entry date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> /// <returns></returns> private MonthlyTarget CreateMonthlyRollupTarget(int targetId, int month, int loggedInUserId) { DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); var monthlyTarget = new MonthlyTarget { TargetId = targetId, Month = month, CreatedBy = loggedInUserId, CreatedOn = curTimestamp, LastModifiedBy = loggedInUserId, LastModifiedOn = curTimestamp }; var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(monthlyTarget); monthlyTargetHistory.TargetId = targetId; monthlyTarget.MonthlyTargetHistory = new List <MonthlyTargetHistory> { monthlyTargetHistory }; return(monthlyTarget); }
/// <summary> /// Adds the or update daily targets. /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="dailyTargets">The daily targets.</param> /// <param name="userName">Name of the user.</param> public void AddOrUpdateDailyTargets(int targetId, IList <RollupTargetItem> dailyTargets, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName)?.Id ?? 0; DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); // exclude months before previous month from roll up var targetMonths = dailyTargets?.Where(x => x.TargetEntryDate.Month >= (curTimestamp.Month - 1))? .Select(x => x.TargetEntryDate.Month).Distinct(); if (targetMonths == null || !targetMonths.Any()) { return; } foreach (int month in targetMonths) { decimal?monthlyRollupValue = null; var monthlyTarget = AdjustMonthlyTarget(targetId, month, loggedInUserId); var dailyTargetsInMonth = dailyTargets.Where(x => x.TargetEntryDate.Month == month); foreach (RollupTargetItem target in dailyTargetsInMonth) { DailyTarget existingDailyTarget = null; if (target.TargetId.HasValue) { existingDailyTarget = dailyTargetRepository.Get(target.TargetId.Value); } else { //extra check for duplicate entry existingDailyTarget = dailyTargetRepository.GetAll().FirstOrDefault(x => x.MonthlyTargetId == monthlyTarget.Id && x.Day == target.TargetEntryDate.Day); } if (existingDailyTarget != null) { if ((target.IsHoliday && existingDailyTarget.MaxGoalValue.HasValue) || target.GoalValue.HasValue) { existingDailyTarget.MaxGoalValue = target.GoalValue; } existingDailyTarget.RolledUpGoalValue = target.RollUpValue; existingDailyTarget.LastModifiedBy = loggedInUserId; existingDailyTarget.LastModifiedOn = curTimestamp; existingDailyTarget.DailyTargetHistory.Add( TargetConverters.ConvertDailyTargetToDailyTargetHistory(existingDailyTarget) ); } else if (target.RollUpValue.HasValue || target.GoalValue.HasValue) { var dailyTarget = new DailyTarget { MonthlyTarget = monthlyTarget, MonthlyTargetId = monthlyTarget.Id, Day = target.TargetEntryDate.Day, RolledUpGoalValue = target.RollUpValue, MaxGoalValue = target.GoalValue, IsManual = false, CreatedBy = loggedInUserId, CreatedOn = curTimestamp, LastModifiedBy = loggedInUserId, LastModifiedOn = curTimestamp }; dailyTarget.DailyTargetHistory = new List <DailyTargetHistory> { TargetConverters.ConvertDailyTargetToDailyTargetHistory(dailyTarget) }; dailyTargetRepository.AddOrUpdate(dailyTarget); } if (monthlyRollupValue.HasValue) { if (target.RollUpValue.HasValue) { monthlyRollupValue += target.RollUpValue.Value; } } else { monthlyRollupValue = target.RollUpValue; } } monthlyTarget.RolledUpGoalValue = monthlyRollupValue; } dailyTargetRepository.Save(); }
/// <summary> /// Convert the given method into optimized Ast format. /// </summary> internal protected static AstNode CreateOptimizedAst(AssemblyCompiler compiler, MethodSource source, bool generateSetNextInstructionCode, StopAstConversion debugStop = StopAstConversion.None, AstOptimizationStep debugStopOptimizing = AstOptimizationStep.None ) { // Build AST DecompilerContext context; AstBlock ast; if (source.IsDotNet) { context = new DecompilerContext(source.Method); var astBuilder = new IL2Ast.AstBuilder(source.ILMethod, true, context); var children = astBuilder.Build(); ast = new AstBlock(children.Select(x => x.SourceLocation).FirstOrDefault(), children); if ((source.ILMethod.IsConstructor) && (source.Method.DeclaringType.Fields.Any(x => x.FieldType.IsEnum() || x.Name.EndsWith(NameConstants.Atomic.FieldUpdaterPostfix)))) { // Ensure all fields are initialized AddFieldInitializationCode(compiler, source, ast); } if (source.Method.NeedsGenericInstanceTypeParameter && (source.Name == ".ctor")) { // Add code to save the generic instance type parameter into the generic instance field. AddGenericInstanceFieldInitializationCode(source, ast, compiler.Module.TypeSystem); } } else if (source.IsJava) { var astBuilder = new Java2Ast.AstBuilder(compiler.Module, source.JavaMethod, source.Method.DeclaringType, true); context = new DecompilerContext(source.Method); ast = astBuilder.Build(); } else if (source.IsAst) { context = new DecompilerContext(source.Method); ast = source.Ast; } else { throw new NotSupportedException("Unknown source"); } if (debugStop == StopAstConversion.AfterILConversion) { return(ast); } // Optimize AST var astOptimizer = new AstOptimizer(context, ast); astOptimizer.Optimize(debugStopOptimizing); if (debugStop == StopAstConversion.AfterOptimizing) { return(ast); } // Optimize AST towards the target TargetConverters.Convert(context, ast, source, compiler, debugStop); if (generateSetNextInstructionCode) { SetNextInstructionGenerator.Convert(ast, source, compiler); } // Return return return(ast); }