Пример #1
0
        private async Task <AgentStartStops> GetAgentStartStopFromRowAsync(IXLWorksheet worksheet, int rowNumber, string agentNameColumn, string twelveAmColumn, ExcelCell phoneColorKeyCell)
        {
            AgentStartStops agentStartStop   = new AgentStartStops();
            List <int>      phoneTimeColumns = new List <int>();

            if (_log.IsDebugEnabled)
            {
                _log.Debug($"ExcelReader.GetAgentStartStopFromRowAsync - Creating row object from worksheet and rowNumber { rowNumber }");
            }
            IXLRow row = await Task.Run(() => worksheet.Row(rowNumber));

            agentStartStop.AgentName = row.Cell(XLHelper.GetColumnNumberFromLetter(agentNameColumn)).Value.ToString();
            if (_log.IsDebugEnabled)
            {
                _log.Debug($"ExcelReader.GetAgentStartStopFromRowAsync - Setting AgentName = { agentStartStop.AgentName }");
            }
            int twelveAmColumnInt = XLHelper.GetColumnNumberFromLetter(twelveAmColumn);

            for (int i = twelveAmColumnInt; i <= twelveAmColumnInt + 23; i++)
            {
                if (row.Cell(i).Style.Fill.ToString() == await GetPhoneTimeCellFill(worksheet, phoneColorKeyCell))
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug($"ExcelReader.GetAgentStartStopFromRowAsync - Adding {i} to phoneTimeColumns List<int>");
                    }
                    phoneTimeColumns.Add(i);
                }
            }

            List <Task <StartStop> > tasks = new List <Task <StartStop> >();

            foreach (int column in phoneTimeColumns)
            {
                tasks.Add(GetStartStopByCellPositionAsync(column - twelveAmColumnInt));
            }

            StartStop[] results = await Task.WhenAll(tasks);

            foreach (StartStop startStop in results)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug($"ExcelReader.GetAgentStartStopFromRowAsync - Adding start:{ startStop.Start } and stop: { startStop.Stop } to agentStartStop.StartStopList");
                }
                agentStartStop.StartStopList.Add(startStop);
            }

            return(agentStartStop);
        }
        private async Task <AgentData> GetAgentDataByStartStopAsync(IGetStatuses getStatuses, IGetCalls getCalls, AgentStartStops agentStartStop, DateTime day, int utcOffset, List <AgentMapping> mappings)
        {
            List <Task <List <Call> > >   callTasks   = new List <Task <List <Call> > >();
            List <Task <List <Status> > > statusTasks = new List <Task <List <Status> > >();

            string agentName = agentStartStop.AgentName;

            foreach (AgentMapping mapping in mappings)
            {
                agentName = (agentName == mapping.ExcelAgentName) ? mapping.TalkdeskAgentName : agentName;
            }

            foreach (StartStop startStop in agentStartStop.StartStopList)
            {
                DateTime startTime = day.Add(startStop.Start);
                DateTime stopTime  = day.Add(startStop.Stop);
                callTasks.Add(getCalls.GetCallListAsync(agentName, startTime, stopTime, utcOffset));
                statusTasks.Add(getStatuses.GetStatusesListAsync(await getStatuses.GetUserIdFromNameAsync(agentName), startTime, stopTime, utcOffset));
            }

            AgentData agentData = new AgentData()
            {
                AgentName = agentStartStop.AgentName
            };

            List <Call>[] callResults = await Task.WhenAll(callTasks);

            foreach (List <Call> calls in callResults)
            {
                agentData.Calls.AddRange(calls);
            }

            List <Status>[] statusResults = await Task.WhenAll(statusTasks);

            foreach (List <Status> statuses in statusResults)
            {
                agentData.Statuses.AddRange(statuses);
            }
            return(agentData);
        }