Mercurial > silverbladetech
comparison Stocks/Stocks.Common/Factory.cs @ 0:e5d46bb6cdb0
Initial commit
author | adminSH stevenhollidge@hotmail.com |
---|---|
date | Mon, 20 Feb 2012 13:52:35 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e5d46bb6cdb0 |
---|---|
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 } |