annotate MetroWpf/Stocks.Common/Factory.cs @ 90:d523381be45a

nuge restore added
author stevenhollidge <stevenhollidge@hotmail.com>
date Mon, 30 Apr 2012 10:48:49 +0100
parents a8b50a087544
children
rev   line source
24
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents: 20
diff changeset
1 using Stocks.Common.Core;
20
adminsh@apollo
parents:
diff changeset
2 using Stocks.Common.Models;
adminsh@apollo
parents:
diff changeset
3 using System;
adminsh@apollo
parents:
diff changeset
4 using Stocks.Common.Exceptions;
adminsh@apollo
parents:
diff changeset
5
adminsh@apollo
parents:
diff changeset
6 namespace Stocks.Common
adminsh@apollo
parents:
diff changeset
7 {
adminsh@apollo
parents:
diff changeset
8 public class Factory
adminsh@apollo
parents:
diff changeset
9 {
adminsh@apollo
parents:
diff changeset
10 public static Price CreatePrice(string webPriceData)
adminsh@apollo
parents:
diff changeset
11 {
adminsh@apollo
parents:
diff changeset
12 if (string.IsNullOrEmpty(webPriceData))
adminsh@apollo
parents:
diff changeset
13 throw new InvalidWebPriceDataException(webPriceData);
adminsh@apollo
parents:
diff changeset
14
adminsh@apollo
parents:
diff changeset
15 try
adminsh@apollo
parents:
diff changeset
16 {
adminsh@apollo
parents:
diff changeset
17 var symbol = webPriceData.Substring(1, webPriceData.IndexOf('"', 2) - 1);
adminsh@apollo
parents:
diff changeset
18
adminsh@apollo
parents:
diff changeset
19 decimal price = decimal.Parse(webPriceData.Substring(
adminsh@apollo
parents:
diff changeset
20 webPriceData.Length - webPriceData.Reverse().IndexOf(",")));
adminsh@apollo
parents:
diff changeset
21
adminsh@apollo
parents:
diff changeset
22 return new Price()
adminsh@apollo
parents:
diff changeset
23 {
adminsh@apollo
parents:
diff changeset
24 Symbol = symbol,
adminsh@apollo
parents:
diff changeset
25 PreviousPrice = price,
adminsh@apollo
parents:
diff changeset
26 CurrentPrice = price
adminsh@apollo
parents:
diff changeset
27 };
adminsh@apollo
parents:
diff changeset
28 }
adminsh@apollo
parents:
diff changeset
29 catch (Exception e)
adminsh@apollo
parents:
diff changeset
30 {
adminsh@apollo
parents:
diff changeset
31 throw new InvalidWebPriceDataException(webPriceData, e);
adminsh@apollo
parents:
diff changeset
32 }
adminsh@apollo
parents:
diff changeset
33 }
adminsh@apollo
parents:
diff changeset
34 }
adminsh@apollo
parents:
diff changeset
35 }