Exemplo n.º 1
0
        ///<Summary>
        /// Gets the answer
        ///</Summary>
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                Log.Info("RelieveNumbersJob запущен!");
                IQueryable <Phone2Client> P2CForRelieve   = _phone2clientrepository.GetRowsForRelieveNumbers();
                List <Phone2Client>       InfoForAsterisk = new List <Phone2Client>();
                if (P2CForRelieve.Count() > 0)
                {
                    InfoForAsterisk = P2CForRelieve.ToList <Phone2Client>();//список телефонов для Asterisk
                }

                if (InfoForAsterisk.Count() > 0)
                {
                    if (Asterisk.RelieveNumbers(InfoForAsterisk.Select(t => t.phone.Phone_Value).ToList <string>()))
                    {
                        foreach (Phone2Client item in InfoForAsterisk)
                        {
                            item.status = 0;
                            _phone2clientrepository.Edit(item);
                        }
                    }
                    else
                    {
                        Log.Error("Метод Asterisk RelieveNumbers вернул ошибку!");
                    }

                    _phone2clientrepository.Save();
                }

                Log.Info("RelieveNumbersJob успешно выполнен!");
                Console.WriteLine("RelieveNumbersJob is running....." + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                Log.Error(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace));
                Console.WriteLine("RelieveNumbersJob is running with error! " + DateTime.Now.ToString());
                Console.WriteLine(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace));
            }
        }
Exemplo n.º 2
0
        private void ReserveNumber(IQueryable <Phone> freephones, Dictionary <int, int> EnabledClients)
        {
            List <Phone>  FreePhonesList  = freephones.ToList <Phone>();
            List <Phone>  PhonesForClient = new List <Phone>();  //список выделенных для клиента номеров
            List <string> ClientsPhones   = new List <string>(); //список номеров для переадресации

            foreach (KeyValuePair <int, int> item in EnabledClients)
            {
                if (FreePhonesList.Count < item.Value)
                {
                    // не хватает номеров
                    //string AdminEmail = System.Configuration.ConfigurationSettings.AppSettings["AdminEmail"].ToString();
                    //SendEmailJobInfo new_sendemailjobinfo = new SendEmailJobInfo() { message = "Не хватает телефонных номеров! Необходимо заказать " + (item.Value - freephones.Count()).ToString() + " номеров!", date = DateTime.Now.ToUniversalTime(), status = false, subject = "Calltracking. Warning!", To = AdminEmail };
                    //_sendemailjobinfoRep.Add(new_sendemailjobinfo);
                    //_sendemailjobinfoRep.Save();
                    break;
                }
                else
                {
                    PhonesForClient = FreePhonesList.GetRange(0, item.Value);
                    FreePhonesList  = FreePhonesList.GetRange(item.Value, FreePhonesList.Count - item.Value);
                    ClientsPhones   = _usernumberRep.FindBy(t => t.ClientId == item.Key).Select(t => t.number).ToList <string>();//!!!!!!!!!!! выбираем номера для переадресации
                    List <Phone2Client> Phone2ClientListForClient = _phone2clientrepository.FindBy(t => t.PhoneId == 1 && t.status == 1 && t.IsLast == true && t.ClientId == item.Key).Take(item.Value).ToList <Phone2Client>();

                    int indexforPhonesForClient = 0;                        //индекс необходим для прохода по списку уже выделенных для текущего клиента телефонов
                    foreach (Phone2Client p2c in Phone2ClientListForClient) //редактируем записи в БД
                    {
                        p2c.PhoneId = PhonesForClient[indexforPhonesForClient].Id;
                        _phone2clientrepository.Edit(p2c);
                        indexforPhonesForClient++;
                    }
                }
            }

            _phone2clientrepository.Save();
        }