Beispiel #1
0
        public GeneralResponse GetQueuesFromAsterisk()
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                var    monitoring = new MonitoringControllerService();
                string Token      = monitoring.login("saman", "102030");

                List <QueueWSDL> queues      = monitoring.getQueue(Token).ToList <QueueWSDL>();
                List <Queue>     savedQueues = _queueRepository.FindAll().ToList <Queue>();

                foreach (var item in queues)
                {
                    foreach (var _item in savedQueues)
                    {
                        if (item.id == _item.AsteriskID)
                        {
                            _item.QueueName = item.name;
                            _queueRepository.Save(_item);
                        }
                    }
                }

                if (queues.Count() > savedQueues.Count())
                {
                    var result = queues.Where(x => savedQueues.All(s => s.AsteriskID != x.id));

                    foreach (var item in result)
                    {
                        var queue = new Queue();
                        queue.AsteriskID = item.id;
                        queue.ID         = Guid.NewGuid();
                        queue.QueueName  = item.name;

                        _queueRepository.Add(queue);
                    }
                }

                if (queues.Count() < savedQueues.Count())
                {
                    IEnumerable <QueueLocalPhoneStore> queueLocalPhone = _queueLocalPhoneRepository.FindAll();

                    var result1 = queueLocalPhone.Where(x => queues.All(s => s.id != x.Queue.AsteriskID));

                    foreach (var item in result1)
                    {
                        _queueLocalPhoneRepository.Remove(item);
                    }
                }

                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }