# HG changeset patch
# User adminsh@apollo
# Date 1332256069 0
# Node ID a7a4cde3999973a2c2cc10a856a37b28bbd9a6d1
# Parent dfc81f8bb83867fb7ef76ff363c05e5894c626ae
ninject aand company data updates
diff -r dfc81f8bb838 -r a7a4cde39999 MetroWpf/MetroWpf.sln.DotSettings.user
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf.sln.DotSettings.user Tue Mar 20 15:07:49 2012 +0000
@@ -0,0 +1,2 @@
+
+ False
\ No newline at end of file
diff -r dfc81f8bb838 -r a7a4cde39999 MetroWpf/MetroWpf/IoCModule.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf/IoCModule.cs Tue Mar 20 15:07:49 2012 +0000
@@ -0,0 +1,41 @@
+
+using GalaSoft.MvvmLight.Messaging;
+using MetroWpf.Framework;
+using MetroWpf.Framework.Interfaces;
+using MetroWpf.Presentation.About;
+using MetroWpf.Presentation.Login;
+using MetroWpf.Presentation.Menu;
+using MetroWpf.Presentation.Settings;
+using MetroWpf.Presentation.Shell;
+using MetroWpf.Presentation.Stocks;
+using MetroWpf.Presentation.UserProfile;
+using Ninject.Modules;
+using Stocks.Common;
+using Stocks.Service;
+
+namespace MetroWpf
+{
+ public class IoCModule : NinjectModule
+ {
+ public override void Load()
+ {
+ Bind()
+ .To()
+ .WithConstructorArgument("filename", "companyData.json");
+
+ Bind().To();
+ Bind().To();
+
+ Bind().To();
+ Bind().To();
+
+ Bind().ToSelf();
+ Bind().ToSelf();
+ Bind().ToSelf();
+ Bind().ToSelf();
+ Bind().ToSelf();
+ Bind().ToSelf();
+ Bind().ToSelf();
+ }
+ }
+}
diff -r dfc81f8bb838 -r a7a4cde39999 MetroWpf/MetroWpf/NinjectServiceLocatorExt.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf/NinjectServiceLocatorExt.cs Tue Mar 20 15:07:49 2012 +0000
@@ -0,0 +1,266 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using Ninject;
+using Ninject.Infrastructure;
+using Ninject.Planning.Bindings;
+using NinjectAdapter;
+
+namespace MetroWpf
+{
+ public class NinjectServiceLocatorExt :
+ NinjectServiceLocator,
+ ICustomTypeDescriptor
+ {
+ private readonly IKernel _kernel;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The kernel.
+ public NinjectServiceLocatorExt(IKernel kernel)
+ : base(kernel)
+ {
+ _kernel = kernel;
+ }
+
+ ///
+ /// Gets the kernel.
+ ///
+ public IKernel Kernel
+ {
+ get { return _kernel; }
+ }
+
+ ///
+ /// Returns a collection of custom attributes for this instance of a component.
+ ///
+ /// An containing the attributes for this object.
+ public AttributeCollection GetAttributes()
+ {
+ return new AttributeCollection(null);
+ }
+
+ ///
+ /// Returns the class name of this instance of a component.
+ ///
+ /// The class name of the object, or null if the class does not have a name.
+ public string GetClassName()
+ {
+ return null;
+ }
+
+ ///
+ /// Returns the name of this instance of a component.
+ ///
+ /// The name of the object, or null if the object does not have a name.
+ public string GetComponentName()
+ {
+ return null;
+ }
+
+ ///
+ /// Returns a type converter for this instance of a component.
+ ///
+ /// A that is the converter for this object, or null if there is no for this object.
+ public TypeConverter GetConverter()
+ {
+ return null;
+ }
+
+ ///
+ /// Returns the default event for this instance of a component.
+ ///
+ /// An that represents the default event for this object, or null if this object does not have events.
+ public EventDescriptor GetDefaultEvent()
+ {
+ return null;
+ }
+
+ ///
+ /// Returns the default property for this instance of a component.
+ ///
+ /// A that represents the default property for this object, or null if this object does not have properties.
+ public PropertyDescriptor GetDefaultProperty()
+ {
+ return null;
+ }
+
+ ///
+ /// Returns an editor of the specified type for this instance of a component.
+ ///
+ /// An of the specified type that is the editor for this object, or null if the editor cannot be found.
+ /// A that represents the editor for this object.
+ public object GetEditor(Type editorBaseType)
+ {
+ return null;
+ }
+
+ ///
+ /// Returns the events for this instance of a component.
+ ///
+ /// An that represents the events for this component instance.
+ public EventDescriptorCollection GetEvents()
+ {
+ return new EventDescriptorCollection(null);
+ }
+
+ ///
+ /// Returns the events for this instance of a component using the specified attribute array as a filter.
+ ///
+ /// An that represents the filtered events for this component instance.
+ /// An array of type that is used as a filter.
+ public EventDescriptorCollection GetEvents(Attribute[] attributes)
+ {
+ return new EventDescriptorCollection(null);
+ }
+
+ ///
+ /// Returns the properties for this instance of a component.
+ ///
+ /// A that represents the properties for this component instance.
+ public PropertyDescriptorCollection GetProperties()
+ {
+ var allBindings = GetAllBindings();
+
+ var result = new PropertyDescriptorCollection(allBindings
+ .Where(x => x.Value.Count == 1 && !x.Value.First().IsConditional)
+ .Select(x => new NinjectBindingPropertyDescriptor(_kernel, x.Key, x.Value.First()))
+ .ToArray());
+
+ return result;
+ }
+
+ ///
+ /// Returns the properties for this instance of a component using the attribute array as a filter.
+ ///
+ /// A that represents the filtered properties for this component instance.
+ /// An array of type that is used as a filter.
+ public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
+ {
+ return ((ICustomTypeDescriptor)this).GetProperties(null);
+ }
+
+ ///
+ /// Returns an object that contains the property described by the specified property descriptor.
+ ///
+ /// An that represents the owner of the specified property.
+ /// A that represents the property whose owner is to be found.
+ public object GetPropertyOwner(PropertyDescriptor pd)
+ {
+ return this;
+ }
+
+ ///
+ /// Gets all bindings registered with the kernel
+ ///
+ ///
+ private IEnumerable>> GetAllBindings()
+ {
+ var fi = typeof(KernelBase).GetField("bindings", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);
+ return (Multimap)fi.GetValue(_kernel);
+ }
+
+ public class NinjectBindingPropertyDescriptor : PropertyDescriptor
+ {
+ private readonly IBinding binding;
+ private readonly IKernel kernel;
+
+ ///
+ /// Initializes a new instance of the class with the specified name and attributes.
+ ///
+ ///
+ /// The name of the property.
+ /// Ninject binding
+ public NinjectBindingPropertyDescriptor(IKernel kernel, Type name, IBinding binding)
+ : base(name.Name, null)
+ {
+ this.kernel = kernel;
+ this.binding = binding;
+ }
+
+ ///
+ /// When overridden in a derived class, gets the type of the component this property is bound to.
+ ///
+ /// A that represents the type of component this property is bound to. When the or methods are invoked, the object specified might be an instance of this type.
+ public override Type ComponentType
+ {
+ get { return typeof(NinjectServiceLocatorExt); }
+ }
+
+ ///
+ /// When overridden in a derived class, gets a value indicating whether this property is read-only.
+ ///
+ /// true if the property is read-only; otherwise, false.
+ public override bool IsReadOnly
+ {
+ get { return true; }
+ }
+
+ ///
+ /// When overridden in a derived class, gets the type of the property.
+ ///
+ /// A that represents the type of the property.
+ public override Type PropertyType
+ {
+ get { return binding.Service; }
+ }
+
+ ///
+ /// When overridden in a derived class, returns whether resetting an object changes its value.
+ ///
+ /// true if resetting the component changes its value; otherwise, false.
+ /// The component to test for reset capability.
+ public override bool CanResetValue(object component)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// When overridden in a derived class, gets the current value of the property on a component.
+ ///
+ /// The value of a property for a given component.
+ /// The component with the property for which to retrieve the value.
+ public override object GetValue(object component)
+ {
+ var request = kernel.CreateRequest(binding.Service, null, binding.Parameters, false, true);
+ var result = kernel.Resolve(request).FirstOrDefault();
+ return result;
+ }
+
+ ///
+ /// When overridden in a derived class, resets the value for this property of the component to the default value.
+ ///
+ /// The component with the property value that is to be reset to the default value.
+ public override void ResetValue(object component)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// When overridden in a derived class, sets the value of the component to a different value.
+ ///
+ /// The component with the property value that is to be set.
+ /// The new value.
+ public override void SetValue(object component, object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// When overridden in a derived class, determines a value indicating whether the value of this property needs to be persisted.
+ ///
+ /// true if the property should be persisted; otherwise, false.
+ /// The component with the property to be examined for persistence.
+ public override bool ShouldSerializeValue(object component)
+ {
+ return false;
+ }
+ }
+ }
+}
diff -r dfc81f8bb838 -r a7a4cde39999 MetroWpf/Stocks.Common/companyData.json
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/Stocks.Common/companyData.json Tue Mar 20 15:07:49 2012 +0000
@@ -0,0 +1,1 @@
+[{"Symbol":"AAPL","Name":"Apple, Inc"},{"Symbol":"AXP","Name":"American Express Company"},{"Symbol":"BAC","Name":"Bank of America Corporation"},{"Symbol":"CSCO","Name":"Cisco Systems, Inc"},{"Symbol":"DIS","Name":"Walt Disney Company"},{"Symbol":"GE","Name":"General Electric Company"},{"Symbol":"GOOG","Name":"Google"},{"Symbol":"HPQ","Name":"Hewlett-Packard Company"},{"Symbol":"INTC","Name":"Intel Corporation"},{"Symbol":"JPM","Name":"JP Morgan Chase & Co"},{"Symbol":"KO","Name":"Coca-Cola Company"},{"Symbol":"MSFT","Name":"Microsoft Corporation"},{"Symbol":"PFE","Name":"Pfizer, Inc."},{"Symbol":"T","Name":"AT&T Inc."},{"Symbol":"UTX","Name":"United Technologies Corporation"},{"Symbol":"VZ","Name":"Verizon Communications Inc."},{"Symbol":"WMT","Name":"Wal-Mart Stores, Inc."},{"Symbol":"XOM","Name":"Exxon Mobil Corporation"}]
\ No newline at end of file
diff -r dfc81f8bb838 -r a7a4cde39999 MetroWpf/Stocks.Service/companyData.json
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/Stocks.Service/companyData.json Tue Mar 20 15:07:49 2012 +0000
@@ -0,0 +1,1 @@
+[{"Symbol":"AAPL","Name":"Apple, Inc"},{"Symbol":"AXP","Name":"American Express Company"},{"Symbol":"BAC","Name":"Bank of America Corporation"},{"Symbol":"CSCO","Name":"Cisco Systems, Inc"},{"Symbol":"DIS","Name":"Walt Disney Company"},{"Symbol":"GE","Name":"General Electric Company"},{"Symbol":"GOOG","Name":"Google"},{"Symbol":"HPQ","Name":"Hewlett-Packard Company"},{"Symbol":"INTC","Name":"Intel Corporation"},{"Symbol":"JPM","Name":"JP Morgan Chase & Co"},{"Symbol":"KO","Name":"Coca-Cola Company"},{"Symbol":"MSFT","Name":"Microsoft Corporation"},{"Symbol":"PFE","Name":"Pfizer, Inc."},{"Symbol":"T","Name":"AT&T Inc."},{"Symbol":"UTX","Name":"United Technologies Corporation"},{"Symbol":"VZ","Name":"Verizon Communications Inc."},{"Symbol":"WMT","Name":"Wal-Mart Stores, Inc."},{"Symbol":"XOM","Name":"Exxon Mobil Corporation"}]
\ No newline at end of file