示例#1
0
        public GeneralResponse GetLocalPhoneStoresFromAsterisk()
        {
            GeneralResponse response = new GeneralResponse();

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

            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }
示例#2
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);
        }
示例#3
0
        public GeneralResponse GetLocalPhoneStoresFromAsterisk()
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                MonitoringControllerService monitoring       = new MonitoringControllerService();
                string                 Token                 = monitoring.login("saman", "102030");
                List <DeviceWSDL>      devices               = monitoring.getDevice(Token).ToList <DeviceWSDL>();
                List <LocalPhoneStore> savedLocalPhoneStores = _localPhoneStoreRepository.FindAll().ToList <LocalPhoneStore>();

                foreach (var item in devices)
                {
                    foreach (var _item in savedLocalPhoneStores)
                    {
                        if (item.dialString == _item.AsteriskID)
                        {
                            _item.LocalPhoneStoreNumber = item.name;
                            _localPhoneStoreRepository.Save(_item);
                        }
                    }
                }

                if (devices.Count() > savedLocalPhoneStores.Count())
                {
                    var result = devices.Where(x => savedLocalPhoneStores.All(s => s.AsteriskID != x.dialString));

                    foreach (var item in result)
                    {
                        LocalPhoneStore localPhoneStore = new LocalPhoneStore();
                        localPhoneStore.AsteriskID            = item.dialString ?? string.Empty;
                        localPhoneStore.ID                    = Guid.NewGuid();
                        localPhoneStore.LocalPhoneStoreNumber = item.name;
                        localPhoneStore.Reserved              = false;
                        _localPhoneStoreRepository.Add(localPhoneStore);
                    }
                }

                if (devices.Count() < savedLocalPhoneStores.Count())
                {
                    IEnumerable <LocalPhoneStore> queueLocalPhone = _localPhoneStoreRepository.FindAll();

                    var result = queueLocalPhone.Where(x => devices.All(s => s.id != x.AsteriskID));

                    foreach (var item in result)
                    {
                        _localPhoneStoreRepository.Remove(item);
                    }
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }