annotate MetroWpf/Stocks.Common/Factory.cs @ 33:f3a0641c1586

bat files added to Messaging solution
author adminsh@apollo
date Thu, 22 Mar 2012 08:11:42 +0000
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 }