public void Serialize(MobileOperatorWithMemo mobileOperator, string path, bool withCallsJournal = true, bool withSmsJournal = true) { MemoMobileOperator memo = mobileOperator.GetMemo(withCallsJournal, withSmsJournal); DataContractJsonSerializer serializer = new DataContractJsonSerializer(memo.GetType()); using (Stream stream = File.Create(path)) { serializer.WriteObject(stream, memo); } }
public void Serialize(MobileOperatorWithMemo mobileOperator, string path, bool withCallsJournal = true, bool withSmsJournal = true) { MemoMobileOperator memo = mobileOperator.GetMemo(withCallsJournal, withSmsJournal); var serializer = ProtoBuf.Serializer.CreateFormatter <MemoMobileOperator>(); using (Stream stream = File.Create(path)) { ProtoBuf.Serializer.Serialize <MemoMobileOperator>(stream, memo); } }
public void Serialize(MobileOperatorWithMemo mobileOperator, string path, bool withCallsJournal = true, bool withSmsJournal = true) { MemoMobileOperator memo = mobileOperator.GetMemo(withCallsJournal, withSmsJournal); BinaryFormatter serializer = new BinaryFormatter(); using (Stream streamWriter = File.Create(path)) { serializer.Serialize(streamWriter, memo); } }
public void Serialize(MobileOperatorWithMemo mobileOperator, string path, bool withCallsJournal = true, bool withSmsJournal = true) { MemoMobileOperator memo = mobileOperator.GetMemo(withCallsJournal, withSmsJournal); XmlSerializer serializer = new XmlSerializer(memo.GetType()); using (StreamWriter streamWriter = File.CreateText( path)) { serializer.Serialize(streamWriter, memo); } }
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); }