Inheritance: TimephasedRuleBase
Exemplo n.º 1
0
        public static IEnumerable <ProjectTaskTimeSheet> GenerateTimesheets(this ProjectTaskTimephasedRule rule)
        {
            var days = (decimal)rule.TimeRange.Duration.TotalDays;

            if (log.IsDebugEnabled)
            {
                log.Debug("rule.WeightValue=[{0}], Days=[{1}], TimeRange=[{2}]", rule.WeightValue, days, rule.TimeRange);
            }

            var weightValue = rule.WeightValue / days;

            return
                (rule.TimeRange
                 .ForEachDays()
                 .Select(day => {
                return new ProjectTaskTimeSheet(rule.ProjectId, rule.TaskId, rule.Id)
                {
                    StartTime = day.Start,
                    EndTime = day.End,
                    PlanWeightValue = weightValue
                };
            }));
        }
Exemplo n.º 2
0
        public static IEnumerable <ProjectTaskTimephasedRule> GenerateTimephasedRules(this IEnumerable <ProjectTaskTimeSheet> timesheets)
        {
            ProjectTaskTimeSheet      prevTimesheet = null;
            ProjectTaskTimephasedRule rule          = null;

            foreach (var timesheet in timesheets.OrderBy(ts => ts.TaskId).ThenBy(ts => ts.StartTime))
            {
                var populateRule = (prevTimesheet == null) || (prevTimesheet.TaskId != timesheet.TaskId) ||
                                   (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

                if (populateRule)
                {
                    if (rule != null)
                    {
                        yield return(rule);
                    }

                    rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
                    {
                        TimeRange   = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
                        WeightValue = timesheet.PlanWeightValue
                    };
                }
                else
                {
                    rule.TimeRange.End = timesheet.EndTime;
                    rule.WeightValue  += timesheet.PlanWeightValue;
                }

                prevTimesheet = timesheet;
            }

            if (rule != null)
            {
                yield return(rule);
            }
        }
Exemplo n.º 3
0
        public static IEnumerable<ProjectTaskTimephasedRule> GenerateTimephasedRules(this IEnumerable<ProjectTaskTimeSheet> timesheets) {
            ProjectTaskTimeSheet prevTimesheet = null;
            ProjectTaskTimephasedRule rule = null;

            foreach(var timesheet in timesheets.OrderBy(ts => ts.TaskId).ThenBy(ts => ts.StartTime)) {
                var populateRule = (prevTimesheet == null) || (prevTimesheet.TaskId != timesheet.TaskId) ||
                                   (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

                if(populateRule) {
                    if(rule != null) {
                        yield return rule;
                    }

                    rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
                           {
                               TimeRange = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
                               WeightValue = timesheet.PlanWeightValue
                           };
                }
                else {
                    rule.TimeRange.End = timesheet.EndTime;
                    rule.WeightValue += timesheet.PlanWeightValue;
                }

                prevTimesheet = timesheet;
            }

            if(rule != null)
                yield return rule;
        }
Exemplo n.º 4
0
        public static IEnumerable<ProjectTaskTimephasedRule> GenerateTimephasedRulesAsParallel(
            this IEnumerable<ProjectTaskTimeSheet> timesheets) {
            var timesheetList = timesheets.ToList();

#if !SILVERLIGHT

            return
                timesheets
                    .Select(x => x.TaskId)
                    .Distinct()
                    .AsParallel()
                    .AsOrdered()
                    .SelectMany(taskId => {
                                    ProjectTaskTimeSheet prevTimesheet = null;
                                    ProjectTaskTimephasedRule rule = null;

                                    var rules = new List<ProjectTaskTimephasedRule>();

                                    foreach(var timesheet in timesheetList.Where(x => x.TaskId == taskId)) {
                                        var populateRule = (prevTimesheet == null) ||
                                                           (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

                                        if(populateRule) {
                                            rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
                                                   {
                                                       TimeRange = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
                                                       WeightValue = timesheet.PlanWeightValue
                                                   };
                                            rules.Add(rule);
                                        }
                                        else {
                                            rule.TimeRange.End = timesheet.EndTime;
                                            rule.WeightValue += timesheet.PlanWeightValue;
                                        }

                                        prevTimesheet = timesheet;
                                    }
                                    return rules;
                                });
#else
			var rules = new List<ProjectTaskTimephasedRule>();

			object _syncLock = new object();

			Parallel.ForEach(timesheetList.Select(x => x.TaskId).Distinct(),
							 () => new List<ProjectTaskTimephasedRule>(),
							 (taskId, loop, localRules) =>
							 {
								 ProjectTaskTimeSheet prevTimesheet = null;
								 ProjectTaskTimephasedRule rule = null;

								 foreach(var timesheet in timesheetList.Where(x => x.TaskId == taskId))
								 {
									 var populateRule = (prevTimesheet == null) || (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

									 if(populateRule)
									 {
										 rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
												{
													TimeRange = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
													WeightValue = timesheet.PlanWeightValue
												};
										 localRules.Add(rule);
									 }
									 else
									 {
										 rule.TimeRange.End = timesheet.EndTime;
										 rule.WeightValue += timesheet.PlanWeightValue;
									 }

									 prevTimesheet = timesheet;
								 }
								 return localRules;
							 },
							 localRules =>
							 {
								 lock(_syncLock)
									 rules.AddRange(localRules);
							 });

			return rules.OrderBy(r => r.TaskId).ThenBy(r => r.TimeRange.Start);
#endif
        }
Exemplo n.º 5
0
        public static IEnumerable <ProjectTaskTimephasedRule> GenerateTimephasedRulesAsParallel(
            this IEnumerable <ProjectTaskTimeSheet> timesheets)
        {
            var timesheetList = timesheets.ToList();

#if !SILVERLIGHT
            return
                (timesheets
                 .Select(x => x.TaskId)
                 .Distinct()
                 .AsParallel()
                 .AsOrdered()
                 .SelectMany(taskId => {
                ProjectTaskTimeSheet prevTimesheet = null;
                ProjectTaskTimephasedRule rule = null;

                var rules = new List <ProjectTaskTimephasedRule>();

                foreach (var timesheet in timesheetList.Where(x => x.TaskId == taskId))
                {
                    var populateRule = (prevTimesheet == null) ||
                                       (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

                    if (populateRule)
                    {
                        rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
                        {
                            TimeRange = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
                            WeightValue = timesheet.PlanWeightValue
                        };
                        rules.Add(rule);
                    }
                    else
                    {
                        rule.TimeRange.End = timesheet.EndTime;
                        rule.WeightValue += timesheet.PlanWeightValue;
                    }

                    prevTimesheet = timesheet;
                }
                return rules;
            }));
#else
            var rules = new List <ProjectTaskTimephasedRule>();

            object _syncLock = new object();

            Parallel.ForEach(timesheetList.Select(x => x.TaskId).Distinct(),
                             () => new List <ProjectTaskTimephasedRule>(),
                             (taskId, loop, localRules) =>
            {
                ProjectTaskTimeSheet prevTimesheet = null;
                ProjectTaskTimephasedRule rule     = null;

                foreach (var timesheet in timesheetList.Where(x => x.TaskId == taskId))
                {
                    var populateRule = (prevTimesheet == null) || (prevTimesheet.PlanWeightValue != timesheet.PlanWeightValue);

                    if (populateRule)
                    {
                        rule = new ProjectTaskTimephasedRule(timesheet.ProjectId, timesheet.TaskId)
                        {
                            TimeRange   = new TimeRange(timesheet.StartTime, TimeSpan.FromDays(1)),
                            WeightValue = timesheet.PlanWeightValue
                        };
                        localRules.Add(rule);
                    }
                    else
                    {
                        rule.TimeRange.End = timesheet.EndTime;
                        rule.WeightValue  += timesheet.PlanWeightValue;
                    }

                    prevTimesheet = timesheet;
                }
                return(localRules);
            },
                             localRules =>
            {
                lock (_syncLock)
                    rules.AddRange(localRules);
            });

            return(rules.OrderBy(r => r.TaskId).ThenBy(r => r.TimeRange.Start));
#endif
        }