/// <summary>
        /// The method that implements the export logic
        /// </summary>
        /// <param name="charts"></param>
        /// <returns></returns>
        private async Task <ActivityResponse> Export(List <CalendarChart> charts)
        {
            ActivityResponse response      = new ActivityResponse();
            EStartFilter     requestFilter = _mapperService.GetFilterParams <EStartFilter>();

            string destSubFolder;

            if (requestFilter.UpdatedInPastDays.HasValue)
            {
                destSubFolder = _ftp.GetDestinationFolder(requestFilter.StartDate, requestFilter.EndDate, true);
            }
            else
            {
                destSubFolder = _ftp.GetDestinationFolder(requestFilter.StartDate, requestFilter.EndDate);
            }

            var timezones = charts.Select(x => x.TimezoneOffset).Distinct().ToList();

            timezones.ForEach(async timezone =>
            {
                var timezoneClocks = charts.Where(x => x.TimezoneOffset.Equals(timezone)).ToList();
                string fileName    = destSubFolder + string.Join("_", "CSS", timezone,
                                                                 requestFilter.StartDate.ToString("yyyyMMdd"), requestFilter.EndDate.ToString("yyyyMMdd"))
                                     + ".ftp";
                var exportText = _scheduleClockService.GenerateExportText(timezoneClocks);
                var status     = await Task.FromResult(_ftp.Write(fileName, exportText));
                if (status)
                {
                    response.Completed.Add(new ActivityData()
                    {
                        Bytes = exportText.Length, DataSet = fileName
                    });
                }
                else
                {
                    response.Failed.Add(new ActivityData()
                    {
                        Bytes = exportText.Length, DataSet = fileName, Metadata = Messages.ExportFailed
                    });
                }
            });

            return(await Task.FromResult(response));
        }
Esempio n. 2
0
        /// <summary>
        /// The helper method to push data to Estart FTP server
        /// </summary>
        /// <returns></returns>
        private async Task <DispatchResponse> PushToEStart()
        {
            List <DispatchData> data  = new List <DispatchData>();
            var agentSchedulingGroups = await _agentSchedulingGroupRepository.GetAgentSchedulingGroups(true);

            agentSchedulingGroups.ForEach(async asg =>
            {
                var agents      = await _agentRepository.GetAgents(asg.AgentSchedulingGroupId);
                var agentString = string.Join("\n", agents.Select(x => x.Ssn).ToList());
                if (!string.IsNullOrWhiteSpace(agentString))
                {
                    var filename = _ftp.GetEmployeesFileName(asg.RefId?.ToString() ?? asg.Name.Substring(0, 10).Trim());
                    var status   = _ftp.Write(filename, agentString);
                    if (status)
                    {
                        data.Add(new DispatchData()
                        {
                            DataSet = filename,
                            Bytes   = Encoding.Default.GetBytes(agentString).Length
                        });
                    }
                }
            });

            if (data.Any())
            {
                return(new DispatchResponse()
                {
                    Data = data,
                    Status = ProcessStatus.Success.ToString()
                });
            }
            else
            {
                return(new DispatchResponse()
                {
                    Status = ProcessStatus.Failed.ToString(),
                    Message = Messages.NoAgentsEStartProvisioned
                });
            }
        }