Пример #1
0
 public bool Equals(MobileOperatorWithMemo mobileOperator)
 {
     if ((this.MaxNumber != mobileOperator.MaxNumber) || (this.MinNumber != mobileOperator.MinNumber) ||
         (this.CallPricing != mobileOperator.CallPricing) || (this.SmsPricing != mobileOperator.SmsPricing))
     {
         return(false);
     }
     if (!this.subscribers.Equals <int, MobileAccount>(mobileOperator.subscribers))
     {
         return(false);
     }
     if (!this.moneyOnAccount.Equals <int, int>(mobileOperator.moneyOnAccount))
     {
         return(false);
     }
     if (!this.smsJournal.Equals <KeyValuePair <int, int> >(mobileOperator.smsJournal))
     {
         return(false);
     }
     if (!this.callsJournal.Equals <KeyValuePair <int, int> >(mobileOperator.callsJournal))
     {
         return(false);
     }
     return(true);
 }
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #6
0
        public static void TestSerializer(IOperatorInfoSerializer serializer, string path, int IterationsNum)
        {
            MobileOperatorWithMemo ATnT = new MobileOperatorWithMemo(maxNumber: 10000, silent: true);
            int num        = 1000;
            int callNum    = 50;
            int smsNum     = 20;
            int friendsNum = 50;

            MobileAccountWithMemo[] subscribers = Filler.CreateSubscribersWithMemo(ATnT, num, true);
            Filler.GenerateRandomCalls(subscribers, callNum);
            Filler.GenerateRandomSms(subscribers, smsNum);
            Filler.CreatePhonebooks(subscribers, friendsNum);
            var watch = Stopwatch.StartNew();
            MobileOperatorWithMemo ATnT2 = null;

            for (int i = 0; i < IterationsNum; i++)
            {
                serializer.Serialize(ATnT, path);
                ATnT2 = serializer.Deserialize(path);
            }
            watch.Stop();
            Console.WriteLine("{0}ms", (UInt64)watch.ElapsedMilliseconds);
            Console.WriteLine("Is obj before serialization equal to itself after? {0}", ATnT.Equals(ATnT2));
        }