# HG changeset patch # User adminsh@apollo # Date 1332274715 0 # Node ID a8b50a0875444edc1315a63885b800c11a892fee # Parent 399398841fd06e46f58aad4ca05d00440b842821 Stocks and FxRates working, new menu introduced. Working nicely so far diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/Ccy.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/Ccy.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,16 @@ +namespace FxRates.Common +{ + public enum Ccy + { + EURtoUSD, + USDtoJPY, + GBPtoUSD, + EURtoGBP, + USDtoCHF, + EURtoJPY, + EURtoCHF, + USDtoCAD, + AUDtoUSD, + GBPtoJPY + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/FxRate.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/FxRate.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,39 @@ +using System; + +namespace FxRates.Common +{ + public class FxRate : IFxRate + { + private FxRate(Ccy ccy, decimal bid, decimal offer, DateTime timestamp) + { + Ccy = ccy; + Bid = bid; + PreviousOffer = offer; + Offer = offer; + Timestamp = timestamp; + } + + #region IFxRate Members + + public decimal Bid { get; private set; } + public Ccy Ccy { get; private set; } + public decimal Offer { get; private set; } + public decimal PreviousOffer { get; private set; } + public DateTime Timestamp { get; private set; } + + #endregion + + public static FxRate Create(Ccy ccy, decimal bid, decimal offer, DateTime timestamp) + { + return new FxRate(ccy, bid, offer, timestamp); + } + + public void UpdatePrice(decimal bid, decimal offer, DateTime timestamp) + { + Bid = bid; + PreviousOffer = Offer; + Offer = offer; + Timestamp = timestamp; + } + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/FxRates.Common.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/FxRates.Common.csproj Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,53 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {789B8256-13E5-41B0-84B5-29A98A3F6E74} + Library + Properties + FxRates.Common + FxRates.Common + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/IFxRate.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/IFxRate.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,13 @@ +using System; + +namespace FxRates.Common +{ + public interface IFxRate + { + decimal Bid { get; } + Ccy Ccy { get; } + decimal Offer { get; } + decimal PreviousOffer { get; } + DateTime Timestamp { get; } + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/IPricingService.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/IPricingService.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace FxRates.Common +{ + public interface IPricingService + { + bool IsRunning { get; } + List GetFullCurrentPrices(); + void Start(); + void Stop(); + event EventHandler PriceUpdate; + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/PriceUpdateEventArgs.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/PriceUpdateEventArgs.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,9 @@ +using System; + +namespace FxRates.Common +{ + public class PriceUpdateEventArgs : EventArgs + { + public FxRate LatestPrice { get; set; } + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Common/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Common/Properties/AssemblyInfo.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,39 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. + +[assembly: AssemblyTitle("FxRates.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FxRates.Common")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM + +[assembly: Guid("bd6efb1c-907d-4a6f-9599-42e64a863603")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Service/FxRates.Service.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Service/FxRates.Service.csproj Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,56 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {0AFFFD20-14C7-44A9-B27E-93165001241C} + Library + Properties + FxRates.Service + FxRates.Service + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + {789B8256-13E5-41B0-84B5-29A98A3F6E74} + FxRates.Common + + + + + \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Service/PriceFactory.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Service/PriceFactory.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FxRates.Common; + +namespace FxRates.Service +{ + class PriceFactory + { + private int _numberOfCcys; + + public PriceFactory() + { + _numberOfCcys = (int) Enum.GetValues(typeof(Ccy)).Cast().Max() + 1; + } + + public readonly List CurrentPrices = new List + { + FxRate.Create(Ccy.AUDtoUSD, (decimal) 1.0724, (decimal) 1.0731, DateTime.Now), + FxRate.Create(Ccy.EURtoCHF, (decimal) 1.2075, (decimal) 1.2094, DateTime.Now), + FxRate.Create(Ccy.EURtoGBP, (decimal) 0.8375, (decimal) 0.8401, DateTime.Now), + FxRate.Create(Ccy.EURtoJPY, (decimal) 103.2930, (decimal) 103.3180, DateTime.Now), + FxRate.Create(Ccy.EURtoUSD, (decimal) 1.3154, (decimal) 1.3276, DateTime.Now), + FxRate.Create(Ccy.GBPtoJPY, (decimal) 123.3250, (decimal) 123.3350, DateTime.Now), + FxRate.Create(Ccy.GBPtoUSD, (decimal) 1.5707, (decimal) 1.5723, DateTime.Now), + FxRate.Create(Ccy.USDtoCAD, (decimal) 0.9974, (decimal) 0.9999, DateTime.Now), + FxRate.Create(Ccy.USDtoCHF, (decimal) 0.9179, (decimal) 0.9191, DateTime.Now), + FxRate.Create(Ccy.USDtoJPY, (decimal) 78.5090, (decimal) 78.5187, DateTime.Now) + }; + + public FxRate GetNextPrice() + { + Random random = new Random(); + + var ccyIndex = random.Next(0, _numberOfCcys); + var rate = CurrentPrices[ccyIndex]; + + int randomSpread = random.Next(-100, 100); + decimal deltaPercentage = (decimal) randomSpread / 10000; + if (deltaPercentage != 0) + { + var bid = Math.Round(rate.Bid * (1 + deltaPercentage), 4); + var offer = Math.Round(rate.Offer * (1 + deltaPercentage), 4); + rate.UpdatePrice(bid, offer, DateTime.Now); + } + return rate; + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Service/PricingService.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Service/PricingService.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,47 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using FxRates.Common; +using System.Collections.Generic; + +namespace FxRates.Service +{ + public class PricingService : IPricingService + { + PriceFactory factory; + bool _isRunning = false; + public bool IsRunning { get { return _isRunning; } } + + public PricingService() + { + factory = new PriceFactory(); + } + + public void Start() + { + Task.Factory.StartNew(() => + { + _isRunning = true; + while (_isRunning) + { + Thread.Sleep(10); + if (PriceUpdate == null) continue; + var latestPrice = factory.GetNextPrice(); + PriceUpdate(null, new PriceUpdateEventArgs { LatestPrice = latestPrice }); + } + }); + } + + public void Stop() + { + _isRunning = false; + } + + public List GetFullCurrentPrices() + { + return factory.CurrentPrices; + } + + public event EventHandler PriceUpdate; + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.Service/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.Service/Properties/AssemblyInfo.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FxRates.Service")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FxRates.Service")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9a0b61cc-fb8c-4208-8248-90665e07b757")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Controls/TimerTextBlock.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Controls/TimerTextBlock.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,187 @@ +using System; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; + +namespace FxRates.UI.Controls +{ + public delegate void Invoker(); + + public class TimerTextBlock : TextBlock + { + //private static Timer _UpdateTimer = new Timer(UpdateTimer, null, 1000, 1000); + + public static readonly DependencyProperty TimeSpanProperty = + DependencyProperty.Register("TimeSpan", typeof (TimeSpan), typeof (TimerTextBlock), + new UIPropertyMetadata(TimeSpan.Zero)); + + public static readonly DependencyProperty IsStartedProperty = + DependencyProperty.Register("IsStarted", typeof (bool), typeof (TimerTextBlock), + new UIPropertyMetadata(false)); + + public static readonly DependencyProperty TimeFormatProperty = + DependencyProperty.Register("TimeFormat", typeof (string), typeof (TimerTextBlock), + new UIPropertyMetadata(null)); + + public static readonly DependencyProperty IsCountDownProperty = + DependencyProperty.Register("IsCountDown", typeof (bool), typeof (TimerTextBlock), + new UIPropertyMetadata(false)); + + private Invoker _UpdateTimeInvoker; + + public TimerTextBlock() + { + Init(); + } + + public TimerTextBlock(Inline inline) : base(inline) + { + Init(); + } + + /// + /// Represents the time remaining for the count down to complete if + /// the control is initialized as a count down timer otherwise, it + /// represents the time elapsed since the timer has started. + /// + /// + /// + public TimeSpan TimeSpan + { + get { return (TimeSpan) GetValue(TimeSpanProperty); } + set + { + if (value < TimeSpan.Zero) + throw new ArgumentException(); + + SetValue(TimeSpanProperty, value); + } + } + + // Using a DependencyProperty as the backing store for TimeSpan. This enables animation, styling, binding, etc... + + public bool IsStarted + { + get { return (bool) GetValue(IsStartedProperty); } + set { SetValue(IsStartedProperty, value); } + } + + // Using a DependencyProperty as the backing store for IsStarted. This enables animation, styling, binding, etc... + + /// + /// Format string for displaying the time span value. + /// + public string TimeFormat + { + get { return (string) GetValue(TimeFormatProperty); } + set { SetValue(TimeFormatProperty, value); } + } + + // Using a DependencyProperty as the backing store for TimeFormat. This enables animation, styling, binding, etc... + + /// + /// Represents whether the control is a CountDown or regular timer. + /// + public bool IsCountDown + { + get { return (bool) GetValue(IsCountDownProperty); } + set { SetValue(IsCountDownProperty, value); } + } + + public event EventHandler OnCountDownComplete; + + private static event EventHandler OnTick; + + private void Init() + { + Loaded += TimerTextBlock_Loaded; + Unloaded += TimerTextBlock_Unloaded; + } + + ~TimerTextBlock() + { + Dispose(); + } + + public void Dispose() + { + OnTick -= TimerTextBlock_OnTick; + } + + // Using a DependencyProperty as the backing store for IsCountDown. This enables animation, styling, binding, etc... + + /// + /// Sets the time span to zero and stops the timer. + /// + public void Reset() + { + IsStarted = false; + TimeSpan = TimeSpan.Zero; + } + + private static void UpdateTimer(object state) + { + EventHandler onTick = OnTick; + if (onTick != null) + onTick(null, EventArgs.Empty); + } + + private void TimerTextBlock_Loaded(object sender, RoutedEventArgs e) + { + var binding = new Binding("TimeSpan"); + binding.Source = this; + binding.Mode = BindingMode.OneWay; + binding.StringFormat = TimeFormat; + + SetBinding(TextProperty, binding); + + _UpdateTimeInvoker = UpdateTime; + + OnTick += TimerTextBlock_OnTick; + } + + private void TimerTextBlock_Unloaded(object sender, RoutedEventArgs e) + { + OnTick -= TimerTextBlock_OnTick; + } + + private void TimerTextBlock_OnTick(object sender, EventArgs e) + { + Dispatcher.Invoke(_UpdateTimeInvoker); + } + + private void UpdateTime() + { + if (IsStarted) + { + TimeSpan step = TimeSpan.FromSeconds(1); + if (IsCountDown) + { + if (TimeSpan >= TimeSpan.FromSeconds(1)) + { + TimeSpan -= step; + if (TimeSpan.TotalSeconds <= 0) + { + TimeSpan = TimeSpan.Zero; + IsStarted = false; + NotifyCountDownComplete(); + } + } + } + else + { + TimeSpan += step; + } + } + } + + private void NotifyCountDownComplete() + { + EventHandler handler = OnCountDownComplete; + if (handler != null) + handler(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/AbsoluteNumberConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/AbsoluteNumberConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,22 @@ +using System; +using System.Windows.Data; + +namespace FxRates.UI.Converters +{ + public class AbsoluteNumberConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return Math.Abs((decimal) value); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/BoolToServiceRunningTextConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/BoolToServiceRunningTextConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,22 @@ +using System; +using System.Windows.Data; + +namespace FxRates.UI.Converters +{ + public class BoolToServiceRunningTextConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return (bool) value ? "Service Running" : "Service Stopped"; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/BoolToSubscribedTextConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/BoolToSubscribedTextConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,22 @@ +using System; +using System.Windows.Data; + +namespace FxRates.UI.Converters +{ + public class BoolToSubscribedTextConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return (bool) value ? "Subscribed" : "Unsubscribed"; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/CcyFromIconConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/CcyFromIconConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,23 @@ +using System; +using System.Windows.Data; +using FxRates.UI.Helpers; + +namespace FxRates.UI.Converters +{ + public class CcyFromIconConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return IconHelper.GetCcyIcon(value.ToString().Substring(0,3)); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/CcyToDisplayNameConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/CcyToDisplayNameConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,78 @@ +using System; +using System.Windows.Data; +using FxRates.Common; + +namespace FxRates.UI.Converters +{ + public class CcyToDisplayNameConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + string result; + try + { + switch ((Ccy)value) + { + case Ccy.AUDtoUSD: + result = "AUD to USD"; + break; + + case Ccy.EURtoCHF: + result = "EUR to CHF"; + break; + + case Ccy.EURtoGBP: + result = "EUR to GBP"; + break; + + case Ccy.EURtoJPY: + result = "EUR to JPY"; + break; + + case Ccy.EURtoUSD: + result = "EUR to USD"; + break; + + case Ccy.GBPtoJPY: + result = "GBP to JPY"; + break; + + case Ccy.GBPtoUSD: + result = "GBP to USD"; + break; + + case Ccy.USDtoCAD: + result = "USD to CAD"; + break; + + case Ccy.USDtoCHF: + result = "USD to CHF"; + break; + + case Ccy.USDtoJPY: + result = "USD to JPY"; + break; + + default: + result = "Unknown"; + break; + } + } + catch + { + result = "Unknown"; + } + + return result; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/CcyToIconConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/CcyToIconConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,23 @@ +using System; +using System.Windows.Data; +using FxRates.UI.Helpers; + +namespace FxRates.UI.Converters +{ + public class CcyToIconConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return IconHelper.GetCcyIcon(value.ToString().Substring(5, 3)); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/DateTimeToTimeConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/DateTimeToTimeConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,24 @@ +using System; +using System.Windows.Data; + +namespace FxRates.UI.Converters +{ + public class DateTimeToTimeConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + string dateTimeString = ((DateTime) value).ToString("HH:mm:ss.ffff"); + + return dateTimeString; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Converters/DeltaToIconConverter.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Converters/DeltaToIconConverter.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,46 @@ +using System; +using System.Windows.Data; +using System.Windows.Media.Imaging; + +namespace FxRates.UI.Converters +{ + public class DeltaToIconConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + string uri; + BitmapImage image; + decimal delta; + string file = "UNK"; + + try + { + delta = (decimal) value; + { + if (delta > 0) + file = "UP"; + else if (delta < 0) + file = "DOWN"; + else + file = "LEVEL"; + } + } + finally + { + uri = string.Format("../Images/{0}.png", file); + image = new BitmapImage(new Uri(uri, UriKind.Relative)); + } + + return image; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/FxRates.UI.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/FxRates.UI.csproj Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,113 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {4BD124E6-F437-47F4-93C9-E09170EB06A2} + Library + Properties + FxRates.UI + FxRates.UI + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\Libs\MvvmLight.4.0.0\GalaSoft.MvvmLight.WPF4.dll + + + + + + + ..\Libs\Rx-Main.1.0.11226\lib\Net4\System.Reactive.dll + + + + + + + + + + + + + + + + + + + + + + + + + + FxRatesView.xaml + + + + + MSBuild:Compile + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + {789B8256-13E5-41B0-84B5-29A98A3F6E74} + FxRates.Common + + + + + \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Helpers/IconHelper.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Helpers/IconHelper.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,26 @@ +using System; +using System.Windows.Media.Imaging; + +namespace FxRates.UI.Helpers +{ + class IconHelper + { + public static BitmapImage GetCcyIcon(string isocode) + { + string uri; + BitmapImage image; + try + { + uri = string.Format("../Images/{0}.png", isocode); + image = new BitmapImage(new Uri(uri, UriKind.Relative)); + } + catch + { + uri = string.Format("../Images/{0}.png", "UNK"); + image = new BitmapImage(new Uri(uri, UriKind.Relative)); + } + + return image; + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Helpers/XamlHelper.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Helpers/XamlHelper.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,22 @@ +using System.Windows; +using System.Windows.Media; + +namespace FxRates.UI.Helpers +{ + public static class XamlHelper + { + /// + /// Finds a parent of a given control/item on the visual tree. + /// + /// Type of Parent + /// Child whose parent is queried + /// Returns the first parent item that matched the type (T), if no match found then it will return null + public static T TryFindParent(this DependencyObject child) where T : DependencyObject + { + var parentObject = VisualTreeHelper.GetParent(child); + if (parentObject == null) return null; + var parent = parentObject as T; + return parent ?? TryFindParent(parentObject); + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/AUD.png Binary file MetroWpf/FxRates.UI/Images/AUD.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/BRL.png Binary file MetroWpf/FxRates.UI/Images/BRL.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/CAD.png Binary file MetroWpf/FxRates.UI/Images/CAD.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/CHF.png Binary file MetroWpf/FxRates.UI/Images/CHF.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/CNY.png Binary file MetroWpf/FxRates.UI/Images/CNY.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/DOWN.png Binary file MetroWpf/FxRates.UI/Images/DOWN.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/EUR.png Binary file MetroWpf/FxRates.UI/Images/EUR.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/GBP.png Binary file MetroWpf/FxRates.UI/Images/GBP.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/INR.png Binary file MetroWpf/FxRates.UI/Images/INR.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/JPY.png Binary file MetroWpf/FxRates.UI/Images/JPY.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/LEVEL.png Binary file MetroWpf/FxRates.UI/Images/LEVEL.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/NZD.png Binary file MetroWpf/FxRates.UI/Images/NZD.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/RUB.png Binary file MetroWpf/FxRates.UI/Images/RUB.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/THB.png Binary file MetroWpf/FxRates.UI/Images/THB.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/UNK.png Binary file MetroWpf/FxRates.UI/Images/UNK.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/UP.png Binary file MetroWpf/FxRates.UI/Images/UP.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/USD.png Binary file MetroWpf/FxRates.UI/Images/USD.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/ZAR.png Binary file MetroWpf/FxRates.UI/Images/ZAR.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Images/help.png Binary file MetroWpf/FxRates.UI/Images/help.png has changed diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Models/DisplayFxRate.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Models/DisplayFxRate.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,138 @@ +using System; +using FxRates.Common; +using GalaSoft.MvvmLight; + +namespace FxRates.UI.Models +{ + public class DisplayFxRate : ObservableObject, IFxRate + { + private DisplayFxRate() { } + + public static DisplayFxRate Create(FxRate rate) + { + var display = new DisplayFxRate() + { + Ccy = rate.Ccy, + Bid = rate.Bid, + Offer = rate.Offer, + PreviousOffer = rate.PreviousOffer, + Timestamp = rate.Timestamp, + Spread = getSpread(rate), + Delta = getDelta(rate) + }; + + return display; + } + + public void Update(FxRate rate) + { + this.Bid = rate.Bid; + this.Offer = rate.Offer; + this.PreviousOffer = rate.PreviousOffer; + this.Timestamp = rate.Timestamp; + this.Spread = getSpread(rate); + this.Delta = getDelta(rate); + } + + private static decimal getSpread(IFxRate rate) + { + return Math.Round(rate.Offer - rate.Bid, 4); + } + + private static decimal getDelta(IFxRate rate) + { + return Math.Round(rate.Offer - rate.PreviousOffer, 4); + } + + public const string CcyPropertyName = "Ccy"; + private Ccy _ccy; + public Ccy Ccy + { + get { return _ccy; } + private set + { + if (_ccy == value) return; + _ccy = value; + RaisePropertyChanged(CcyPropertyName); + } + } + + public const string BidPropertyName = "Bid"; + private decimal _bid = 0; + public decimal Bid + { + get { return _bid; } + private set + { + if (_bid == value) return; + _bid = value; + RaisePropertyChanged(BidPropertyName); + } + } + + public const string OfferPropertyName = "Offer"; + private decimal _offer = 0; + public decimal Offer + { + get { return _offer; } + private set + { + if (_offer == value) return; + _offer = value; + RaisePropertyChanged(OfferPropertyName); + } + } + + public const string PreviousOfferPropertyName = "PreviousOffer"; + private decimal _previousOffer = 0; + public decimal PreviousOffer + { + get { return _previousOffer; } + private set + { + if (_previousOffer == value) return; + _previousOffer = value; + RaisePropertyChanged(PreviousOfferPropertyName); + } + } + + public const string DeltaPropertyName = "Delta"; + private decimal _delta = 0; + public decimal Delta + { + get { return _delta; } + private set + { + if (_delta == value) return; + _delta = value; + RaisePropertyChanged(DeltaPropertyName); + } + } + + public const string SpreadPropertyName = "Spread"; + private decimal _spread = 0; + public decimal Spread + { + get { return _spread; } + private set + { + if (_spread == value) return; + _spread = value; + RaisePropertyChanged(SpreadPropertyName); + } + } + + public const string TimestampPropertyName = "Timestamp"; + private DateTime _timestamp = DateTime.MinValue; + public DateTime Timestamp + { + get { return _timestamp;} + private set + { + if (_timestamp == value) return; + _timestamp = value; + RaisePropertyChanged(TimestampPropertyName); + } + } + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Properties/AssemblyInfo.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FxRates.UI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FxRates.UI")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d7408b4d-c599-40a9-88be-099fc8f6c3ed")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/ViewModels/FxRatesViewModel.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/ViewModels/FxRatesViewModel.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,109 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Reactive; +using System.Reactive.Linq; +using System.Windows.Input; +using FxRates.Common; +using FxRates.UI.Models; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; + +namespace FxRates.UI.ViewModels +{ + public class FxRatesViewModel : ViewModelBase + { + private IPricingService pricingService; + + public BindingList DisplayFxRates { get; set; } + public ICommand ServiceRunningCommand { get; set; } + public ICommand SubscriptionCommand { get; set; } + + public FxRatesViewModel(IPricingService service) + { + pricingService = service; + GetLatestPrices(); + + SubscriptionCommand = new RelayCommand(SubscriptionCommand_Execute); + ServiceRunningCommand = new RelayCommand(ServiceRunningCommand_Execute); + + var priceUpdates = Observable.FromEventPattern( + pricingService, "PriceUpdate"); + + priceUpdates.Where(e => (Subscribed) + // && (e.EventArgs.LatestPrice.Ccy == Ccy.EURtoGBP) example of filter + ) + //.Throttle(TimeSpan.FromSeconds(1)) example of throttling + .Subscribe(PriceUpdate); + } + + public void PriceUpdate(EventPattern e) + { + var displayRate = DisplayFxRates.First(rate => rate.Ccy == e.EventArgs.LatestPrice.Ccy); + + if (displayRate != null) + displayRate.Update(e.EventArgs.LatestPrice); + } + + + private void GetLatestPrices() + { + DisplayFxRates = new BindingList(); + var currentRates = pricingService.GetFullCurrentPrices(); + foreach (var latestRate in currentRates) + { + var displayRate = DisplayFxRate.Create(latestRate); + DisplayFxRates.Add(displayRate); + } + } + + private const string SubscribedPropertyName = "Subscribed"; + private bool _subscribed = false; + public bool Subscribed + { + get { return _subscribed; } + set + { + if (_subscribed == value) return; + _subscribed = value; + RaisePropertyChanged(SubscribedPropertyName); + } + } + + private const string ServiceRunningPropertyName = "ServiceRunning"; + private bool _serviceRunning; + public bool ServiceRunning + { + get + { + return _serviceRunning; + } + set + { + if (_serviceRunning == value) return; + _serviceRunning = value; + RaisePropertyChanged(ServiceRunningPropertyName); + } + } + + void ServiceRunningCommand_Execute() + { + if (pricingService.IsRunning) + { + pricingService.Stop(); + ServiceRunning = false; + } + else + { + pricingService.Start(); + ServiceRunning = true; + } + } + + void SubscriptionCommand_Execute() + { + //toggle subscribed + Subscribed = !Subscribed; + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/FxRates.UI/Views/FxRatesView.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Views/FxRatesView.xaml Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Login/LoginView.xaml.cs --- a/MetroWpf/MetroWpf/Presentation/Login/LoginView.xaml.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace MetroWpf.Presentation.Login -{ - /// - /// Interaction logic for LoginView.xaml - /// - public partial class LoginView : UserControl - { - public LoginView() - { - InitializeComponent(); - } - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Login/LoginViewModel.cs --- a/MetroWpf/MetroWpf/Presentation/Login/LoginViewModel.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; -using GalaSoft.MvvmLight.Messaging; -using MetroWpf.Messages; - -namespace MetroWpf.Presentation.Login -{ - /// - /// Login view view model class - /// - public sealed class LoginViewModel : - ViewModelBase - { - #region · Data Properties · - - /// - /// Gets or sets whether the form is busy - /// - private bool isBusy; - public bool IsBusy - { - get { return isBusy; } - set - { - if (this.isBusy != value) - { - this.isBusy = value; - RaisePropertyChanged("IsBusy"); - //relay requery? - } - } - } - - /// - /// Gets or sets the user name - /// - private string userId; - public string UserId - { - get { return this.userId; } - set - { - if (this.userId != value) - { - this.userId = value; - RaisePropertyChanged("UserId"); - LoginCommand.RaiseCanExecuteChanged(); - } - } - } - - /// - /// Gets or sets the password - /// - private string password; - public string Password - { - get { return this.password; } - set - { - if (this.password != value) - { - this.password = value; - RaisePropertyChanged("Password"); - LoginCommand.RaiseCanExecuteChanged(); - } - } - } - - #endregion - - #region · Constructors · - - /// - /// Initializes a new instance of the class - /// - public LoginViewModel() - : base() - { - LoginCommand = new RelayCommand(LoginCommandExecute, CanLoginCommandExecute); - CloseCommand = new RelayCommand(CloseCommandExecute); - } - - #endregion - - #region · Command Actions · - - #region LoginCommand - - public RelayCommand LoginCommand { get; set; } - - private void LoginCommandExecute() - { - //successful login! - - Messenger.Default.Send(new UserAuthenticatedMessage() { UserId = userId }); - } - - private bool CanLoginCommandExecute() - { - if (string.IsNullOrEmpty(UserId) || - string.IsNullOrEmpty(Password)) - return false; - - return true; - } - - #endregion - - #region CloseCommand - public RelayCommand CloseCommand { get; set; } - - private void CloseCommandExecute() - { - } - #endregion - - #endregion - } -} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Login/UserLogin.cs --- a/MetroWpf/MetroWpf/Presentation/Login/UserLogin.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GalaSoft.MvvmLight; - -namespace MetroWpf.Presentation.Login -{ - public sealed class UserLogin : - ObservableObject, - IDataErrorInfo - { - #region · Fields · - - private Dictionary _errors - = new Dictionary(); - - #endregion - - #region · IDataErrorInfo Members · - - public string Error - { - get { return null; } - } - - public string this[string columnName] - { - get { return null; } - } - - #endregion - - #region · Properties · - - public string UserId { get; set; } - public string Password { get; set; } - - #endregion - - #region · Constructors · - - public UserLogin() - { - } - - #endregion - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Menu/MenuView.xaml --- a/MetroWpf/MetroWpf/Presentation/Menu/MenuView.xaml Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Menu/MenuView.xaml.cs --- a/MetroWpf/MetroWpf/Presentation/Menu/MenuView.xaml.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -using System.Windows.Controls; -using GalaSoft.MvvmLight.Messaging; -using MetroWpf.Messages; - -namespace MetroWpf.Presentation.Menu -{ - /// - /// Interaction logic for TabMenu.xaml - /// - public partial class MenuView : UserControl - { - public MenuView() - { - InitializeComponent(); - } - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Menu/MenuViewModel.cs --- a/MetroWpf/MetroWpf/Presentation/Menu/MenuViewModel.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Messaging; -using MetroWpf.Messages; - -namespace MetroWpf.Presentation.Menu -{ - public class MenuViewModel : ViewModelBase - { - private Screen selectedTabIndex; - public Screen SelectedTabIndex - { - get { return selectedTabIndex; } - set - { - if (selectedTabIndex == value) - return; - - selectedTabIndex = value; - RaisePropertyChanged("SelectedTabIndex"); - } - } - - private bool showStocks; - public bool ShowStocks - { - get { return showStocks; } - set - { - if (showStocks == value) - return; - - showStocks = value; - RaisePropertyChanged("ShowStocks"); - } - } - - private bool showFxRates; - public bool ShowFxRates - { - get { return showFxRates; } - set - { - if (showFxRates == value) - return; - - showFxRates = value; - RaisePropertyChanged("ShowFxRates"); - } - } - - private bool showLogin; - public bool ShowLogin - { - get { return showLogin; } - set - { - if (showLogin == value) - return; - - showLogin = value; - RaisePropertyChanged("ShowLogin"); - } - } - - private bool showUserProfile; - public bool ShowUserProfile - { - get { return showUserProfile; } - set - { - if (showUserProfile == value) - return; - - showUserProfile = value; - RaisePropertyChanged("ShowUserProfile"); - } - } - - private bool showSettings; - public bool ShowSettings - { - get { return showSettings; } - set - { - if (showSettings == value) - return; - - showSettings = value; - RaisePropertyChanged("ShowSettings"); - } - } - - private bool showAbout; - public bool ShowAbout - { - get { return showAbout; } - set - { - if (showAbout == value) - return; - - showAbout = value; - RaisePropertyChanged("ShowAbout"); - } - } - - private bool showHelp; - public bool ShowHelp - { - get { return showHelp; } - set - { - if (showHelp == value) - return; - - showHelp = value; - RaisePropertyChanged("ShowHelp"); - } - } - - public MenuViewModel() - { - Init(); - } - - private void Init() - { - Messenger.Default.Register( - this, - message => ChangeDisplayScreen(message.DisplayScreen)); - - Messenger.Default.Register( - this, - message => UserAuthenticated(message.UserId)); - - ChangeDisplayScreen(Screen.Login); - } - - private void UserAuthenticated(string userId) - { - Messenger.Default.Send(new NavigationMessage() { DisplayScreen= Screen.Stocks }); - } - - private void ChangeDisplayScreen(Screen screen) - { - switch (screen) - { - case Screen.Login: - ShowLogin = true; - - ShowStocks = false; - ShowFxRates = false; - ShowUserProfile = false; - ShowSettings = false; - ShowAbout = false; - ShowHelp = false; - break; - case Screen.Stocks: - ShowStocks = true; - ShowFxRates = true; - - ShowLogin = false; - ShowUserProfile = false; - ShowSettings = false; - ShowAbout = false; - ShowHelp = false; - break; - case Screen.UserProfile: - ShowUserProfile = true; - - ShowStocks = false; - ShowFxRates = false; - ShowLogin = false; - ShowSettings = false; - ShowAbout = false; - ShowHelp = false; - break; - case Screen.Settings: - ShowSettings = true; - - ShowStocks = false; - ShowFxRates = false; - ShowLogin = false; - ShowUserProfile = false; - ShowAbout = false; - ShowHelp = false; - break; - case Screen.About: - ShowAbout = true; - - ShowStocks = false; - ShowFxRates = false; - ShowLogin = false; - ShowUserProfile = false; - ShowSettings = false; - ShowHelp = false; - break; - case Screen.Help: - ShowLogin = false; - ShowUserProfile = false; - ShowSettings = false; - ShowAbout = false; - ShowHelp = true; - break; - } - - SelectedTabIndex = screen; - } - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Screen.cs --- a/MetroWpf/MetroWpf/Presentation/Screen.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - -namespace MetroWpf.Presentation -{ - public enum Screen - { - Stocks, - FxRates, - Login, - UserProfile, - Settings, - About, - Help - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Settings/SettingsView.xaml --- a/MetroWpf/MetroWpf/Presentation/Settings/SettingsView.xaml Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Settings/SettingsView.xaml.cs --- a/MetroWpf/MetroWpf/Presentation/Settings/SettingsView.xaml.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace MetroWpf.Presentation.Settings -{ - /// - /// Interaction logic for SettingsView.xaml - /// - public partial class SettingsView : UserControl - { - public SettingsView() - { - InitializeComponent(); - } - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Settings/SettingsViewModel.cs --- a/MetroWpf/MetroWpf/Presentation/Settings/SettingsViewModel.cs Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Messaging; -using MetroWpf.Messages; -using MetroWpf.Styles; - -namespace MetroWpf.Presentation.Settings -{ - public class SettingsViewModel : ViewModelBase - { - ApplicationStyle _selectedApplicationStyle; - - public SettingsViewModel() - { - _selectedApplicationStyle = ApplicationStyle.BlueLight; - } - - public ApplicationStyle SelectedApplicationStyle - { - get { return _selectedApplicationStyle; } - set - { - _selectedApplicationStyle = value; - RaisePropertyChanged("SelectedApplicationStyle"); - - Messenger.Default.Send( - new ApplicationStyleChangeMessage() - { ApplicationStyle = _selectedApplicationStyle }); - } - } - } -} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/Presentation/Shell/MainWindow.xaml --- a/MetroWpf/MetroWpf/Presentation/Shell/MainWindow.xaml Tue Mar 20 16:53:29 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Login/LoginView.xaml.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Login/LoginView.xaml.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,13 @@ +namespace MetroWpf.UI.Login +{ + /// + /// Interaction logic for LoginView.xaml + /// + public partial class LoginView + { + public LoginView() + { + InitializeComponent(); + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Login/LoginViewModel.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Login/LoginViewModel.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,120 @@ +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight.Messaging; +using MetroWpf.Messages; + +namespace MetroWpf.UI.Login +{ + /// + /// Login view view model class + /// + public sealed class LoginViewModel : + ViewModelBase + { + #region · Data Properties · + + /// + /// Gets or sets whether the form is busy + /// + private bool isBusy; + public bool IsBusy + { + get { return isBusy; } + set + { + if (this.isBusy != value) + { + this.isBusy = value; + RaisePropertyChanged("IsBusy"); + //relay requery? + } + } + } + + /// + /// Gets or sets the user name + /// + private string userId; + public string UserId + { + get { return this.userId; } + set + { + if (this.userId != value) + { + this.userId = value; + RaisePropertyChanged("UserId"); + LoginCommand.RaiseCanExecuteChanged(); + } + } + } + + /// + /// Gets or sets the password + /// + private string password; + public string Password + { + get { return this.password; } + set + { + if (this.password != value) + { + this.password = value; + RaisePropertyChanged("Password"); + LoginCommand.RaiseCanExecuteChanged(); + } + } + } + + #endregion + + #region · Constructors · + + /// + /// Initializes a new instance of the class + /// + public LoginViewModel() + : base() + { + LoginCommand = new RelayCommand(LoginCommandExecute, CanLoginCommandExecute); + CloseCommand = new RelayCommand(CloseCommandExecute); + } + + #endregion + + #region · Command Actions · + + #region LoginCommand + + public RelayCommand LoginCommand { get; set; } + + private void LoginCommandExecute() + { + //successful login! + + Messenger.Default.Send(new UserAuthenticatedMessage() { UserId = userId }); + } + + private bool CanLoginCommandExecute() + { + if (string.IsNullOrEmpty(UserId) || + string.IsNullOrEmpty(Password)) + return false; + + return true; + } + + #endregion + + #region CloseCommand + public RelayCommand CloseCommand { get; set; } + + private void CloseCommandExecute() + { + } + #endregion + + #endregion + } +} \ No newline at end of file diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Login/UserLogin.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Login/UserLogin.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.ComponentModel; +using GalaSoft.MvvmLight; + +namespace MetroWpf.UI.Login +{ + public sealed class UserLogin : + ObservableObject, + IDataErrorInfo + { + #region · Fields · + + private Dictionary _errors + = new Dictionary(); + + #endregion + + #region · IDataErrorInfo Members · + + public string Error + { + get { return null; } + } + + public string this[string columnName] + { + get { return null; } + } + + #endregion + + #region · Properties · + + public string UserId { get; set; } + public string Password { get; set; } + + #endregion + + #region · Constructors · + + public UserLogin() + { + } + + #endregion + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Screen.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Screen.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,14 @@ + +namespace MetroWpf.Presentation +{ + public enum Screen + { + Stocks, + FxRates, + Login, + UserProfile, + Settings, + About, + Help + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Settings/SettingsView.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Settings/SettingsView.xaml Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Settings/SettingsView.xaml.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Settings/SettingsView.xaml.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace MetroWpf.UI.Settings +{ + /// + /// Interaction logic for SettingsView.xaml + /// + public partial class SettingsView : UserControl + { + public SettingsView() + { + InitializeComponent(); + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Settings/SettingsViewModel.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Settings/SettingsViewModel.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,31 @@ +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Messaging; +using MetroWpf.Messages; +using MetroWpf.Styles; + +namespace MetroWpf.UI.Settings +{ + public class SettingsViewModel : ViewModelBase + { + ApplicationStyle _selectedApplicationStyle; + + public SettingsViewModel() + { + _selectedApplicationStyle = ApplicationStyle.BlueLight; + } + + public ApplicationStyle SelectedApplicationStyle + { + get { return _selectedApplicationStyle; } + set + { + _selectedApplicationStyle = value; + RaisePropertyChanged("SelectedApplicationStyle"); + + Messenger.Default.Send( + new ApplicationStyleChangeMessage() + { ApplicationStyle = _selectedApplicationStyle }); + } + } + } +} diff -r 399398841fd0 -r a8b50a087544 MetroWpf/MetroWpf/UI/Shell/ShellView.xaml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf/UI/Shell/ShellView.xaml Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +