comparison MetroWpf/Stocks.Common/Factory.cs @ 20:6109bc268b90

Latest
author adminsh@apollo
date Tue, 20 Mar 2012 13:37:46 +0000
parents
children a8b50a087544
comparison
equal deleted inserted replaced
19:09d18d6e5f40 20:6109bc268b90
1 using NLog;
2 using Stocks.Common.Core;
3 using Stocks.Common.Models;
4 using System;
5 using Stocks.Common.Exceptions;
6
7 namespace Stocks.Common
8 {
9 public class Factory
10 {
11 public static Price CreatePrice(string webPriceData)
12 {
13 if (string.IsNullOrEmpty(webPriceData))
14 throw new InvalidWebPriceDataException(webPriceData);
15
16 try
17 {
18 var symbol = webPriceData.Substring(1, webPriceData.IndexOf('"', 2) - 1);
19
20 decimal price = decimal.Parse(webPriceData.Substring(
21 webPriceData.Length - webPriceData.Reverse().IndexOf(",")));
22
23 return new Price()
24 {
25 Symbol = symbol,
26 PreviousPrice = price,
27 CurrentPrice = price
28 };
29 }
30 catch (Exception e)
31 {
32 throw new InvalidWebPriceDataException(webPriceData, e);
33 }
34 }
35 }
36 }