示例#1
0
 public void Serialize(SerializedData data, Customer customer)
 {
     foreach (var formatter in _formatters)
     {
         formatter.Serialize(data, customer);
     }
 }
示例#2
0
        public Customer Deserialize(SerializedData serializedData)
        {
            string standardData = serializedData.StandardData;
            string name = Regex.Match(standardData, @"\b\w+\n", RegexOptions.Compiled).ToString().TrimEnd('\n');
            var customer = new Customer(name);

            var movieTitles = Regex.Matches(standardData, @"\t(.*?)\t", RegexOptions.Compiled);
            var moviePrices = Regex.Matches(standardData, @"\t\d+[,.]?(\d+)?\n", RegexOptions.Compiled);

            if (movieTitles.Count != moviePrices.Count)
            {
                throw new ArgumentException("data");
            }

            for (int i = 0; i < movieTitles.Count; ++i)
            {
                customer.Movies.Add(movieTitles[i].ToString().Trim('\t'), Convert.ToDouble(moviePrices[i].ToString().Trim('\t', '\n')));
            }

            string totalAmounAsString = Regex.Match(standardData, @" \d+[,.]?(\d+)?\n", RegexOptions.Compiled).ToString().TrimEnd('\n');
            customer.TotalAmount = Convert.ToDouble(totalAmounAsString);
            customer.FrequentRenterPoints = Convert.ToInt32(Regex.Match(standardData, @" (\d+) ", RegexOptions.Compiled).ToString());

            return customer;
        }
示例#3
0
 public void Serialize(SerializedData data, Customer customer)
 {
     foreach (var formatter in _formatters)
     {
         formatter.Serialize(data, customer);
     }
 }
示例#4
0
        public Customer Deserialize(SerializedData serializedData)
        {
            string standardData = serializedData.StandardData;
            string name         = Regex.Match(standardData, @"\b\w+\n", RegexOptions.Compiled).ToString().TrimEnd('\n');
            var    customer     = new Customer(name);

            var movieTitles = Regex.Matches(standardData, @"\t(.*?)\t", RegexOptions.Compiled);
            var moviePrices = Regex.Matches(standardData, @"\t\d+[,.]?(\d+)?\n", RegexOptions.Compiled);

            if (movieTitles.Count != moviePrices.Count)
            {
                throw new ArgumentException("data");
            }

            for (int i = 0; i < movieTitles.Count; ++i)
            {
                customer.Movies.Add(movieTitles[i].ToString().Trim('\t'), Convert.ToDouble(moviePrices[i].ToString().Trim('\t', '\n')));
            }

            string totalAmounAsString = Regex.Match(standardData, @" \d+[,.]?(\d+)?\n", RegexOptions.Compiled).ToString().TrimEnd('\n');

            customer.TotalAmount          = Convert.ToDouble(totalAmounAsString);
            customer.FrequentRenterPoints = Convert.ToInt32(Regex.Match(standardData, @" (\d+) ", RegexOptions.Compiled).ToString());

            return(customer);
        }
示例#5
0
 public void Serialize(SerializedData data, Customer customer)
 {
     using (var stream = new MemoryStream())
     {
         var jsonSerializer = new DataContractJsonSerializer(typeof(Customer), _serializableTypes);
         jsonSerializer.WriteObject(stream, customer);
         stream.Position = 0;
         var sr = new StreamReader(stream);
         data.JsonData = sr.ReadToEnd();
     }
 }
示例#6
0
 public void Serialize(SerializedData data, Customer customer)
 {
     using (var stream = new MemoryStream())
     {
         var jsonSerializer = new DataContractJsonSerializer(typeof(Customer), _serializableTypes);
         jsonSerializer.WriteObject(stream, customer);
         stream.Position = 0;
         var sr = new StreamReader(stream);
         data.JsonData = sr.ReadToEnd();
     }
 }
示例#7
0
        public Customer Deserialize(SerializedData serializedData)
        {
            using (var stream = new MemoryStream())
            {
                byte[] data = Encoding.UTF8.GetBytes(serializedData.JsonData);
                stream.Write(data, 0, data.Length);
                stream.Position = 0;
                var dataContractSerializer = new DataContractJsonSerializer(typeof(Customer), _serializableTypes);

                return dataContractSerializer.ReadObject(stream) as Customer;
            }
        }
示例#8
0
        public Customer Deserialize(SerializedData serializedData)
        {
            using (var stream = new MemoryStream())
            {
                byte[] data = Encoding.UTF8.GetBytes(serializedData.XmlData);
                stream.Write(data, 0, data.Length);
                stream.Position = 0;
                var dataContractSerializer = new DataContractSerializer(typeof(Customer), _serializableTypes);

                return(dataContractSerializer.ReadObject(stream) as Customer);
            }
        }
示例#9
0
        public void Serialize(SerializedData data, Customer customer)
        {
            var serializer = new DataContractSerializer(typeof(Customer), _serializableTypes);

            using (var sw = new StringWriter())
                using (var writer = new XmlTextWriter(sw))
                {
                    writer.Formatting = Formatting.Indented;
                    serializer.WriteObject(writer, customer);
                    writer.Flush();
                    data.XmlData = sw.ToString();
                }
        }
示例#10
0
        public void Serialize(SerializedData data, Customer customer)
        {
            var serializer = new DataContractSerializer(typeof(Customer), _serializableTypes);

            using (var sw = new StringWriter())
            using (var writer = new XmlTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;
                serializer.WriteObject(writer, customer);
                writer.Flush();
                data.XmlData = sw.ToString();
            }
        }
示例#11
0
        public void Serialize(SerializedData data, Customer customer)
        {
            var result = new StringBuilder(string.Format("Учет аренды для {0}\n", customer.Name));

            foreach (var movie in customer.Movies)
            {
                result.AppendFormat("\t{0}\t{1}\n", movie.Key, movie.Value);
            }

            result.AppendFormat("Сумма задолженности составляет {0}\n", customer.TotalAmount);
            result.AppendFormat("Вы заработали {0} за активность", customer.FrequentRenterPoints);
            data.StandardData = result.ToString();
        }
示例#12
0
        public void Serialize(SerializedData data, Customer customer)
        {
            var result = new StringBuilder(string.Format("Учет аренды для {0}\n", customer.Name));

            foreach (var movie in customer.Movies)
            {
                result.AppendFormat("\t{0}\t{1}\n", movie.Key, movie.Value);
            }

            result.AppendFormat("Сумма задолженности составляет {0}\n", customer.TotalAmount);
            result.AppendFormat("Вы заработали {0} за активность", customer.FrequentRenterPoints);
            data.StandardData = result.ToString();
        }