private void ComputeAndExecute(
            string siteCode,
            ISiteContext siteContext,
            LaborRate[] laborRates,
            string[] siteEmployeeCodes,
            string[] tnaEmployeeCodes,
            DateTime minDate,
            DateTime maxDate,
            Action <IEnumerable <EfficiencyRecord> > execute)
        {
            lock (_locks.GetOrAdd(siteCode, new object()))
            {
                var siteTime           = TrimDate(siteContext.CurrentSiteTime, TimeSpan.TicksPerMinute);
                var siteEmployeeShifts = siteEmployeeCodes?.Any() == true
                    ? _efficiencyShiftProvider.GetShiftsForSiteEmployeeCodes(siteCode, siteTime, siteEmployeeCodes, minDate, maxDate)
                    : new EfficiencyShift[0];

                if (siteEmployeeShifts.Any())
                {
                    var efficiencyRecords = _efficiencyEngine.Compute(siteEmployeeShifts, laborRates, minDate, maxDate);
                    execute?.Invoke(efficiencyRecords);
                }

                var tnaShifts = tnaEmployeeCodes?.Any() == true
                    ? _efficiencyShiftProvider.GetShiftsForTnaEmployeeCodes(siteCode, siteTime, tnaEmployeeCodes, minDate, maxDate)
                    : new EfficiencyShift[0];

                if (tnaShifts.Any())
                {
                    var efficiencyRecords = _efficiencyEngine.Compute(tnaShifts, laborRates, minDate, maxDate);
                    execute?.Invoke(efficiencyRecords);
                }
            }
        }
Ejemplo n.º 2
0
 public IEnumerable <EfficiencyRecord> Compute(IEnumerable <Transaction> modifiedTransactions, LaborRate[] laborRates, DateTime minDate, DateTime maxDate)
 {
     return(modifiedTransactions.GroupBy(x => x.SiteCode)
            .SelectMany(x => _efficiencyEngine.Compute(_dateRangeTimeSheetShiftProvider.GetShifts(x.Key, minDate, maxDate), laborRates, minDate, maxDate)));
 }