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

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