public CostsDto CalculateProjectCosts(IList <ResourceSeriesDto> resourceSeriesSet) { if (resourceSeriesSet == null) { throw new ArgumentNullException(nameof(resourceSeriesSet)); } var costs = new CostsDto(); if (resourceSeriesSet.Any()) { costs.DirectCost = resourceSeriesSet .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.Direct) .Sum(x => x.Values.Sum(y => y * x.UnitCost)); costs.IndirectCost = resourceSeriesSet .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.Indirect) .Sum(x => x.Values.Sum(y => y * x.UnitCost)); costs.OtherCost = resourceSeriesSet .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.None) .Sum(x => x.Values.Sum(y => y * x.UnitCost)); costs.TotalCost = resourceSeriesSet .Sum(x => x.Values.Sum(y => y * x.UnitCost)); } return(costs); }
public void CalculateCosts() { lock (m_Lock) { IList <IResourceSchedule <int> > resourceSchedules = GraphCompilation?.ResourceSchedules; IList <ResourceDto> resources = ResourceSettingsDto.Resources; if (resourceSchedules == null || resources == null) { return; } IList <ResourceSeriesDto> resourceSeriesSet = m_ProjectManager.CalculateResourceSeriesSet(resourceSchedules, resources, ResourceSettingsDto.DefaultUnitCost); ResourceSeriesSet.Clear(); foreach (ResourceSeriesDto series in resourceSeriesSet) { ResourceSeriesSet.Add(series); } ClearCosts(); if (HasCompilationErrors) { return; } CostsDto costs = m_ProjectManager.CalculateProjectCosts(resourceSeriesSet); DirectCost = costs.DirectCost; IndirectCost = costs.IndirectCost; OtherCost = costs.OtherCost; TotalCost = costs.TotalCost; } }