Commit 7c66a5e
Changed files (9)
product
desktop.ui
presenters
views
messages
service
specs
integration
service
handlers
unit
service
product/desktop.ui/presenters/StockWatchPresenter.cs
@@ -15,7 +15,6 @@ namespace solidware.financials.windows.ui.presenters
{
UICommandBuilder builder;
Timer timer;
- ObservableCommand refresh_command;
public StockWatchPresenter(UICommandBuilder builder, Timer timer)
{
@@ -26,17 +25,18 @@ namespace solidware.financials.windows.ui.presenters
public virtual ICollection<StockViewModel> Stocks { get; set; }
public ObservableCommand AddSymbol { get; set; }
+ public ObservableCommand Refresh { get; set; }
public void present()
{
timer.start_notifying(this, new TimeSpan(0, 1, 0));
AddSymbol = builder.build<AddSymbolCommand>(this);
- refresh_command = builder.build<RefreshStockPricesCommand>(this);
+ Refresh = builder.build<RefreshStockPricesCommand>(this);
}
public void notify()
{
- refresh_command.Execute(this);
+ Refresh.Execute(this);
}
public void notify(CurrentStockPrice message)
product/desktop.ui/views/StockWatch.xaml
@@ -1,6 +1,9 @@
<UserControl x:Class="solidware.financials.windows.ui.views.StockWatch" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
- <Button Command="{Binding Path=AddSymbol}">Add Symbol</Button>
+ <DockPanel>
+ <Button Command="{Binding Path=AddSymbol}" DockPanel.Dock="Left">Add Symbol</Button>
+ <Button Command="{Binding Path=Refresh}" DockPanel.Dock="Right">Refresh</Button>
+ </DockPanel>
<ListView ItemsSource="{Binding Path=Stocks}">
<ListView.ItemTemplate>
<DataTemplate>
product/messages/CurrentStockPrice.cs
@@ -1,4 +1,5 @@
-using gorilla.utility;
+using System.Text;
+using gorilla.utility;
using solidware.financials.infrastructure.eventing;
namespace solidware.financials.messages
@@ -8,9 +9,18 @@ namespace solidware.financials.messages
public string Symbol { get; set; }
public decimal Price { get; set; }
+ public string Change { get; set; }
+ public string ChangePercentage { get; set; }
+ public decimal Open { get; set; }
+ public decimal High { get; set; }
+ public decimal Low { get; set; }
+
public override string ToString()
{
- return "{0}: {1:C}".format(Symbol, Price);
+ var builder = new StringBuilder();
+ builder.AppendLine("{0} {1:C} {2} / {3}%".format(Symbol,Price,Change, ChangePercentage));
+ builder.AppendLine("O:{0:C} H:{1:C} L:{2:C}".format(Open, High, Low));
+ return builder.ToString();
}
}
}
\ No newline at end of file
product/service/handlers/GoogleLookupService.cs
@@ -3,18 +3,43 @@ using System.IO;
using System.Net;
using gorilla.utility;
using Newtonsoft.Json;
+using solidware.financials.messages;
namespace solidware.financials.service.handlers
{
public class GoogleLookupService : StockPriceLookupService
{
- public decimal FindPriceFor(string symbol)
+ public CurrentStockPrice FindPriceFor(string symbol)
{
//www.google.com/finance/info?infotype=infoquoteall&q=C,JPM,AIG
- dynamic convert = JsonConvert.DeserializeObject(Open("http://www.google.com/finance/info?infotype=infoquoteall&q={0}".format(symbol)).Remove(0, 4));
- var item = convert[0];
- Console.Out.WriteLine(item);
- return item.l;
+ try
+ {
+ dynamic convert = JsonConvert.DeserializeObject(Open("http://www.google.com/finance/info?infotype=infoquoteall&q={0}".format(symbol)).Remove(0, 4));
+ var item = convert[0];
+ Console.Out.WriteLine(item);
+ var price = MapFrom(item);
+ price.Symbol = symbol;
+ return price;
+ }
+ catch (Exception e)
+ {
+ Console.Out.WriteLine(e);
+ return new CurrentStockPrice {Symbol = symbol};
+ }
+ }
+
+ CurrentStockPrice MapFrom(dynamic item)
+ {
+ return new CurrentStockPrice
+ {
+ Symbol = item.t,
+ Price = item.l,
+ Change = item.c,
+ ChangePercentage = item.cp,
+ High = item.hi,
+ Low = item.lo,
+ Open = item.op,
+ };
}
string Open(string url)
@@ -25,27 +50,6 @@ namespace solidware.financials.service.handlers
}
}
- public class GoogleFeed
- {
- public int id { get; set; }
- public string Symbol { get; set; }
- public string Exchange { get; set; }
- public decimal CurrentPrice { get; set; }
- public string LastTradeTime { get; set; }
- public string Change { get; set; }
- public string ChangePercentage { get; set; }
- public decimal Open { get; set; }
- public decimal High { get; set; }
- public decimal Low { get; set; }
- public decimal Volume { get; set; }
- public decimal AverageVolume { get; set; }
- public decimal OneYearHigh { get; set; }
- public decimal OneYearLow { get; set; }
- public string MarketCapital { get; set; }
- public string Name { get; set; }
- public string Type { get; set; }
- }
-
/*
{
"id": "666908",
product/service/handlers/StockPriceLookupService.cs
@@ -1,7 +1,9 @@
-namespace solidware.financials.service.handlers
+using solidware.financials.messages;
+
+namespace solidware.financials.service.handlers
{
public interface StockPriceLookupService
{
- decimal FindPriceFor(string symbol);
+ CurrentStockPrice FindPriceFor(string symbol);
}
}
\ No newline at end of file
product/service/handlers/StockPriceRequestQueryHandler.cs
@@ -16,11 +16,7 @@ namespace solidware.financials.service.handlers
public void handle(StockPriceRequestQuery item)
{
- bus.publish(new CurrentStockPrice
- {
- Symbol = item.Symbol,
- Price = service.FindPriceFor(item.Symbol),
- });
+ bus.publish(service.FindPriceFor(item.Symbol));
}
}
}
\ No newline at end of file
product/service/handlers/StubLookupService.cs
@@ -1,12 +1,17 @@
using System;
+using solidware.financials.messages;
namespace solidware.financials.service.handlers
{
public class StubLookupService : StockPriceLookupService
{
- public decimal FindPriceFor(string symbol)
+ public CurrentStockPrice FindPriceFor(string symbol)
{
- return Convert.ToDecimal(new Random().NextDouble());
+ return new CurrentStockPrice
+ {
+ Symbol = symbol,
+ Price = Convert.ToDecimal(new Random().NextDouble()),
+ };
}
}
}
\ No newline at end of file
product/specs/integration/service/handlers/GoogleLookupServiceSpecs.cs
@@ -1,4 +1,5 @@
using Machine.Specifications;
+using solidware.financials.messages;
using solidware.financials.service.handlers;
namespace specs.integration.service.handlers
@@ -19,11 +20,11 @@ namespace specs.integration.service.handlers
It should_not_blow_up = () =>
{
- result.should_be_greater_than(0m);
+ result.Price.should_be_greater_than(0m);
};
static GoogleLookupService sut;
- static decimal result;
+ static CurrentStockPrice result;
}
}
}
\ No newline at end of file
product/specs/unit/service/handlers/StockPriceRequestQueryHandlerSpecs.cs
@@ -26,7 +26,8 @@ namespace specs.unit.service.handlers
Establish context = () =>
{
query = new StockPriceRequestQuery {Symbol = "ARX.TO"};
- service.is_told_to(x => x.FindPriceFor("ARX.TO")).it_will_return(26.81m);
+ price = new CurrentStockPrice();
+ service.is_told_to(x => x.FindPriceFor("ARX.TO")).it_will_return(price);
};
Because of = () =>
@@ -36,14 +37,11 @@ namespace specs.unit.service.handlers
It should_publish_the_current_price = () =>
{
- bus.was_told_to(x => x.publish(new CurrentStockPrice
- {
- Symbol = "ARX.TO",
- Price = 26.81m,
- }));
+ bus.was_told_to(x => x.publish(price));
};
static StockPriceRequestQuery query;
+ static CurrentStockPrice price;
}
}
}
\ No newline at end of file