view MetroWpf/Stocks.Common/Factory.cs @ 39:4b8b38d17d24 MetroWPF CTP v0.1

Quick tidy up for ctp 0.1 release
author adminsh@apollo
date Tue, 03 Apr 2012 15:33:18 +0100
parents a8b50a087544
children
line wrap: on
line source

using Stocks.Common.Core;
using Stocks.Common.Models;
using System;
using Stocks.Common.Exceptions;

namespace Stocks.Common
{
  public class Factory
  {
    public static Price CreatePrice(string webPriceData)
    {
      if (string.IsNullOrEmpty(webPriceData))
        throw new InvalidWebPriceDataException(webPriceData);

      try
      {
        var symbol = webPriceData.Substring(1, webPriceData.IndexOf('"', 2) - 1);

        decimal price = decimal.Parse(webPriceData.Substring(
            webPriceData.Length - webPriceData.Reverse().IndexOf(",")));

        return new Price()
        {
          Symbol = symbol,
          PreviousPrice = price,
          CurrentPrice = price
        };
      }
      catch (Exception e)
      {
        throw new InvalidWebPriceDataException(webPriceData, e);
      }
    }
  }
}