Esempio n. 1
0
 public static MobileAccountWithMemo[] CreateSubscribersWithMemo(MobileOperator mobileOperator, int number, bool Sequentially = false)
 {
     MobileAccountWithMemo[] result = new MobileAccountWithMemo[number];
     for (int i = 0; i < number; i++)
     {
         if (Sequentially)
         {
             result[i] = new MobileAccountWithMemo(mobileOperator, i);
         }
         else
         {
             result[i] = new MobileAccountWithMemo(mobileOperator);
         }
     }
     return(result);
 }
 public MobileOperatorWithMemo(MemoMobileOperator memo) :
     base(memo.MaxNumber, memo.MinNumber, memo.CallPricing, memo.SmsPricing)
 {
     this.subscribers = new Dictionary <int, MobileAccount>(memo.memoSubscribers.Length);
     for (int i = 0; i < memo.memoSubscribers.Length; i++)
     {
         //creating subscribers automaticaly adds it to its operator
         var subscriber = new MobileAccountWithMemo(this, memo.memoSubscribers[i]);
     }
     this.moneyOnAccount = new Dictionary <int, int>(memo.Funds.Length);
     for (int i = 0; i < memo.Funds.Length; i++)
     {
         moneyOnAccount.Add(memo.Funds[i].Key, memo.Funds[i].Value);
     }
     this.smsJournal   = memo.smsJournal.Select(x => new KeyValuePair <int, int>(x.Key, x.Value)).ToList();
     this.callsJournal = memo.callsJournal.Select(x => new KeyValuePair <int, int>(x.Key, x.Value)).ToList();
 }
        public MemoMobileOperator GetMemo(bool withCallsJournal = false, bool withSmsJournal = false)
        {
            MemoMobileAccount[] memoAccounts = new MemoMobileAccount[this.subscribers.Count];
            int i = 0;

            foreach (var item in this.subscribers)
            {
                MobileAccountWithMemo temp = item.Value as MobileAccountWithMemo;
                if (temp != null)
                {
                    memoAccounts[i] = temp.GetMemo();
                    i++;
                }
            }
            Array.Resize(ref memoAccounts, i);

            var funds = this.moneyOnAccount.
                        Select(x => new CustomKeyValuePair <int, int>()
            {
                Key = x.Key, Value = x.Value
            }).ToArray();
            var smsJournal = withSmsJournal ? this.smsJournal.
                             Select(x => new CustomKeyValuePair <int, int>()
            {
                Key = x.Key, Value = x.Value
            }).ToArray() : null;
            var callsJournal = withCallsJournal ? this.callsJournal.
                               Select(x => new CustomKeyValuePair <int, int>()
            {
                Key = x.Key, Value = x.Value
            }).ToArray() : null;
            MemoMobileOperator result = new MemoMobileOperator()
            {
                MaxNumber       = this.MaxNumber,
                MinNumber       = this.MinNumber,
                CallPricing     = this.CallPricing,
                SmsPricing      = this.SmsPricing,
                memoSubscribers = memoAccounts,
                Funds           = funds,
                smsJournal      = smsJournal,
                callsJournal    = callsJournal
            };

            return(result);
        }