Esempio n. 1
0
        public async Task ProcessAsync(CallPruneCommand command, IQuidjiboProgress progress, CancellationToken cancellationToken)
        {
            try
            {
                progress.Report(1, $"Starting the {Name} Task");

                //await Task.Run(async () =>
                //{
                var _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>();
                var logic = new CallPruneLogic();

                var items = await _departmentsService.GetAllDepartmentCallPruningsAsync();

                if (items != null)
                {
                    _logger.LogInformation("CallPrune::Call Pruning To Process: " + items.Count);

                    foreach (var i in items)
                    {
                        var item = new CallPruneQueueItem();
                        item.PruneSettings = i;

                        _logger.LogInformation("CallPrune::Pruning Calls for DepartmentId:" + item.PruneSettings.DepartmentId);
                        item.PruneSettings.Department =
                            await _departmentsService.GetDepartmentByIdAsync(item.PruneSettings.DepartmentId);

                        var result = await logic.Process(item);

                        if (result.Item1)
                        {
                            _logger.LogInformation($"CallPrune::Pruned Calls for Department {item.PruneSettings.DepartmentId} successfully.");
                        }
                        else
                        {
                            _logger.LogInformation($"CallPrune::Failed to Process Calls for Department {item.PruneSettings.DepartmentId} error {result.Item2}");
                        }
                    }
                }
                //}, cancellationToken);

                progress.Report(100, $"Finishing the {Name} Task");
            }
            catch (Exception ex)
            {
                Resgrid.Framework.Logging.LogException(ex);
                _logger.LogError(ex.ToString());
            }
        }
Esempio n. 2
0
        public async Task ProcessAsync(CallPruneCommand command, IQuidjiboProgress progress, CancellationToken cancellationToken)
        {
            progress.Report(1, $"Starting the {Name} Task");

            await Task.Factory.StartNew(() =>
            {
                var _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>();
                var logic = new CallPruneLogic();

                var items = _departmentsService.GetAllDepartmentCallPrunings();

                if (items != null)
                {
                    _logger.LogInformation("CallPrune::Call Pruning To Process: " + items.Count);

                    foreach (var i in items)
                    {
                        var item           = new CallPruneQueueItem();
                        item.PruneSettings = i;

                        _logger.LogInformation("CallPrune::Processing Calls for DepartmentId:" + item.PruneSettings.DepartmentId);

                        var result = logic.Process(item);

                        if (result.Item1)
                        {
                            _logger.LogInformation($"CallPrune::Processing Calls for Department {item.PruneSettings.DepartmentId} successfully.");
                        }
                        else
                        {
                            _logger.LogInformation($"CallPrune::Failed to Process Calls for Department {item.PruneSettings.DepartmentId} error {result.Item2}");
                        }
                    }
                }
            }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);


            progress.Report(100, $"Finishing the {Name} Task");
        }
Esempio n. 3
0
        public async Task <Tuple <bool, string> > Process(CallPruneQueueItem item)
        {
            bool   success = true;
            string result  = "";

            if (item != null && item.PruneSettings != null)
            {
                try
                {
                    var calls = await _callsService.GetActiveCallsByDepartmentAsync(item.PruneSettings.DepartmentId);

                    if (calls != null && calls.Count > 0)
                    {
                        var emailImportCalls = calls.Where(x => x.CallSource == (int)CallSources.EmailImport || x.CallSource == (int)CallSources.AudioImport);
                        var userCalls        = calls.Where(x => x.CallSource == (int)CallSources.User);

                        if (item.PruneSettings.PruneEmailImportedCalls.HasValue &&
                            item.PruneSettings.PruneEmailImportedCalls.Value & item.PruneSettings.EmailImportCallPruneInterval.HasValue)
                        {
                            if (emailImportCalls.Any())
                            {
                                foreach (var call in emailImportCalls)
                                {
                                    if (call.LoggedOn.AddMinutes(item.PruneSettings.EmailImportCallPruneInterval.Value) < DateTime.UtcNow)
                                    {
                                        call.State          = (int)CallStates.Closed;
                                        call.ClosedOn       = DateTime.UtcNow;
                                        call.CompletedNotes = "Call automatically closed by the system.";
                                        call.ClosedByUserId = item.PruneSettings.Department.ManagingUserId;

                                        await _callsService.SaveCallAsync(call);
                                    }
                                }
                            }
                        }

                        if (item.PruneSettings.PruneUserEnteredCalls.HasValue &&
                            item.PruneSettings.PruneUserEnteredCalls.Value & item.PruneSettings.UserCallPruneInterval.HasValue)
                        {
                            if (userCalls.Any())
                            {
                                foreach (var call in userCalls)
                                {
                                    if (call.LoggedOn.AddMinutes(item.PruneSettings.UserCallPruneInterval.Value) < DateTime.UtcNow)
                                    {
                                        call.State          = (int)CallStates.Closed;
                                        call.ClosedOn       = DateTime.UtcNow;
                                        call.CompletedNotes = "Call automatically closed by the system.";
                                        call.ClosedByUserId = item.PruneSettings.Department.ManagingUserId;

                                        await _callsService.SaveCallAsync(call);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    result  = ex.ToString();
                }
            }

            return(new Tuple <bool, string>(success, result));
        }