From a688a343e93da96392bd35787972b2a894dcc3c7 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 13 May 2017 15:52:02 +0200 Subject: [PATCH] Created a startable application --- Arge.API.Skin/Arge.API.Skin.csproj | 49 ++++++++++ .../Arge.API.Skin.csproj.DotSettings | 2 + Arge.API.Skin/Properties/AssemblyInfo.cs | 35 +++++++ .../Resources/CachedResourceDictionary.cs | 56 +++++++++++ Arge.sln | 11 +++ Arge/App.config | 14 ++- Arge/App.xaml | 10 +- Arge/Arge.csproj | 47 +++++++++- Arge/Bootstrapper/ArgeBootstrapper.cs | 29 ++++++ Arge/Bootstrapper/UnityBootstrapper.cs | 94 +++++++++++++++++++ Arge/ViewModels/AbstractViewModel.cs | 44 +++++++++ Arge/ViewModels/ShellViewModel.cs | 6 ++ Arge/Views/ShellView.xaml | 11 +++ Arge/Views/ShellView.xaml.cs | 16 ++++ Arge/packages.config | 7 ++ 15 files changed, 427 insertions(+), 4 deletions(-) create mode 100644 Arge.API.Skin/Arge.API.Skin.csproj create mode 100644 Arge.API.Skin/Arge.API.Skin.csproj.DotSettings create mode 100644 Arge.API.Skin/Properties/AssemblyInfo.cs create mode 100644 Arge.API.Skin/Resources/CachedResourceDictionary.cs create mode 100644 Arge/Bootstrapper/ArgeBootstrapper.cs create mode 100644 Arge/Bootstrapper/UnityBootstrapper.cs create mode 100644 Arge/ViewModels/AbstractViewModel.cs create mode 100644 Arge/ViewModels/ShellViewModel.cs create mode 100644 Arge/Views/ShellView.xaml create mode 100644 Arge/Views/ShellView.xaml.cs create mode 100644 Arge/packages.config diff --git a/Arge.API.Skin/Arge.API.Skin.csproj b/Arge.API.Skin/Arge.API.Skin.csproj new file mode 100644 index 0000000..1151613 --- /dev/null +++ b/Arge.API.Skin/Arge.API.Skin.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE} + Library + Properties + Arge.API.Skin + Arge.API.Skin + v4.5 + 512 + + + true + full + false + ..\bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\bin\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Arge.API.Skin/Arge.API.Skin.csproj.DotSettings b/Arge.API.Skin/Arge.API.Skin.csproj.DotSettings new file mode 100644 index 0000000..d44b148 --- /dev/null +++ b/Arge.API.Skin/Arge.API.Skin.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/Arge.API.Skin/Properties/AssemblyInfo.cs b/Arge.API.Skin/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..25918da --- /dev/null +++ b/Arge.API.Skin/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +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("Arge.API.Skin")] +[assembly: AssemblyDescription("Skin-API of Arge")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Wyrez")] +[assembly: AssemblyProduct("Arge.API.Skin")] +[assembly: AssemblyCopyright("Copyright © Wyrez 2017")] +[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("30bac2d7-4fb2-4464-a573-00dc9f211afe")] + +// 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 --git a/Arge.API.Skin/Resources/CachedResourceDictionary.cs b/Arge.API.Skin/Resources/CachedResourceDictionary.cs new file mode 100644 index 0000000..658a58a --- /dev/null +++ b/Arge.API.Skin/Resources/CachedResourceDictionary.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows; + +namespace Arge.API.Skin +{ + public class CachedResourceDictionary : ResourceDictionary + { + #region Properties & Fields + + // ReSharper disable InconsistentNaming + private static readonly List _cachedDictionaries = new List(); + private static readonly ResourceDictionary _innerDictionary = new ResourceDictionary(); + // ReSharper restore + + public new Uri Source + { + get => null; + set + { + lock (_innerDictionary) + { + UpdateCache(value); + + MergedDictionaries.Clear(); + MergedDictionaries.Add(_innerDictionary); + } + } + } + + #endregion + + #region Methods + + private static void UpdateCache(Uri source) + { + string uriPath = source.OriginalString; + if (_cachedDictionaries.Contains(uriPath)) return; + + _cachedDictionaries.Add(uriPath); + + ResourceDictionary newDictionary = new ResourceDictionary { Source = new Uri(uriPath, source.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative) }; + CopyDictionaryEntries(newDictionary, _innerDictionary); + } + + private static void CopyDictionaryEntries(IDictionary source, IDictionary target) + { + foreach (object key in source.Keys) + if (!target.Contains(key)) + target.Add(key, source[key]); + } + + #endregion + } +} diff --git a/Arge.sln b/Arge.sln index ae2f396..1ef95b2 100644 --- a/Arge.sln +++ b/Arge.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arge", "Arge\Arge.csproj", "{4509B24A-6B26-41B0-8B62-1C4201317692}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{D786947A-A8D7-485E-9726-839655841958}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arge.API.Skin", "Arge.API.Skin\Arge.API.Skin.csproj", "{30BAC2D7-4FB2-4464-A573-00DC9F211AFE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,8 +19,15 @@ Global {4509B24A-6B26-41B0-8B62-1C4201317692}.Debug|Any CPU.Build.0 = Debug|Any CPU {4509B24A-6B26-41B0-8B62-1C4201317692}.Release|Any CPU.ActiveCfg = Release|Any CPU {4509B24A-6B26-41B0-8B62-1C4201317692}.Release|Any CPU.Build.0 = Release|Any CPU + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {30BAC2D7-4FB2-4464-A573-00DC9F211AFE} = {D786947A-A8D7-485E-9726-839655841958} + EndGlobalSection EndGlobal diff --git a/Arge/App.config b/Arge/App.config index 8e15646..86c562e 100644 --- a/Arge/App.config +++ b/Arge/App.config @@ -1,6 +1,18 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/Arge/App.xaml b/Arge/App.xaml index de57dd1..06eb21f 100644 --- a/Arge/App.xaml +++ b/Arge/App.xaml @@ -1,7 +1,15 @@  + xmlns:arge="clr-namespace:Arge" + xmlns:bootstrapper="clr-namespace:Arge.Bootstrapper"> + + + + + + + diff --git a/Arge/Arge.csproj b/Arge/Arge.csproj index 9feb6dc..05dd049 100644 --- a/Arge/Arge.csproj +++ b/Arge/Arge.csproj @@ -18,7 +18,7 @@ true full false - bin\Debug\ + ..\bin\ DEBUG;TRACE prompt 4 @@ -27,14 +27,42 @@ AnyCPU pdbonly true - bin\Release\ + ..\bin\ TRACE prompt 4 + + ..\packages\Caliburn.Micro.Core.3.0.3\lib\net45\Caliburn.Micro.dll + + + ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.dll + + + ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.Core.dll + + + ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + + + ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll + + + ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll + + + ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll + + + + + + ..\packages\Caliburn.Micro.3.0.3\lib\net45\System.Windows.Interactivity.dll + True + @@ -57,8 +85,15 @@ App.xaml Code + + + + + ShellView.xaml + + Code @@ -76,6 +111,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -84,5 +120,12 @@ + + + + Designer + MSBuild:Compile + + \ No newline at end of file diff --git a/Arge/Bootstrapper/ArgeBootstrapper.cs b/Arge/Bootstrapper/ArgeBootstrapper.cs new file mode 100644 index 0000000..fbc6b57 --- /dev/null +++ b/Arge/Bootstrapper/ArgeBootstrapper.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Windows; +using Arge.ViewModels; + +namespace Arge.Bootstrapper +{ + public class ArgeBootstrapper : UnityBootstrapper + { + #region Methods + + protected override void RegisterTypes() + { + } + + protected override void OnStartup(object sender, StartupEventArgs e) + { + Dictionary settings = new Dictionary + { + { "Title", "Arge" }, + { "SizeToContent", SizeToContent.Manual }, + { "Width" , 1280 }, + { "Height" , 720 } + }; + DisplayRootViewFor(settings); + } + + #endregion + } +} diff --git a/Arge/Bootstrapper/UnityBootstrapper.cs b/Arge/Bootstrapper/UnityBootstrapper.cs new file mode 100644 index 0000000..4f52fd8 --- /dev/null +++ b/Arge/Bootstrapper/UnityBootstrapper.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using Caliburn.Micro; +using Microsoft.Practices.Unity; + +namespace Arge.Bootstrapper +{ + public abstract class UnityBootstrapper : BootstrapperBase + { + #region Properties & Fields + + protected IUnityContainer Container; + + #endregion + + #region Constructors + + protected UnityBootstrapper() + { + Initialize(); + } + + #endregion + + #region Methods + + protected override void Configure() + { + Container = new UnityContainer(); + RegisterSingleton(Container); + RegisterInterface(); + RegisterInterface(); + } + + protected abstract void RegisterTypes(); + + protected override object GetInstance(Type service, string key) + { + return key != null ? Container.Resolve(service, key) : Container.Resolve(service); + } + + protected override IEnumerable GetAllInstances(Type service) + { + return Container.ResolveAll(service); + } + + protected override void BuildUp(object instance) + { + instance = Container.BuildUp(instance); + base.BuildUp(instance); + } + + #region Container-Registration + + protected void RegisterInterface(bool registerTypeToo = true, bool registerAsSingleton = true, string uniqueName = null) + where TImplementation : TInterface + { + RegisterTypeIfMissing(typeof(TInterface), typeof(TImplementation), registerAsSingleton, uniqueName); + if (registerTypeToo) + RegisterTypeIfMissing(typeof(TImplementation), typeof(TImplementation), registerAsSingleton, uniqueName); + } + + protected void RegisterSingleton() + { + RegisterTypeIfMissing(typeof(T), typeof(T), true); + } + + protected void RegisterSingleton(T instance) + { + Container.RegisterInstance(typeof(T), instance, new ContainerControlledLifetimeManager()); + } + + protected void RegisterTypeIfMissing(Type fromType, Type toType, bool registerAsSingleton, string uniqueName = null) + { + if (fromType == null) + throw new ArgumentNullException(nameof(fromType)); + + if (toType == null) + throw new ArgumentNullException(nameof(toType)); + + if (!Container.IsRegistered(fromType)) + { + if (registerAsSingleton) + Container.RegisterType(fromType, toType, uniqueName, new ContainerControlledLifetimeManager()); + else + Container.RegisterType(fromType, toType, uniqueName); + } + } + + #endregion + + #endregion + } +} diff --git a/Arge/ViewModels/AbstractViewModel.cs b/Arge/ViewModels/AbstractViewModel.cs new file mode 100644 index 0000000..c2dab7c --- /dev/null +++ b/Arge/ViewModels/AbstractViewModel.cs @@ -0,0 +1,44 @@ +using System.Runtime.CompilerServices; +using Caliburn.Micro; + +namespace Arge.ViewModels +{ + public abstract class AbstractViewModel : PropertyChangedBase + { + #region Method + + /// + /// Checks if the property already matches the desirec value or needs to be updated. + /// + /// Type of the property. + /// Reference to the backing-filed. + /// Value to apply. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected virtual bool RequiresUpdate(ref T storage, T value) + { + return !Equals(storage, value); + } + + /// + /// Checks if the property already matches the desired value and updates it if not. + /// + /// Type of the property. + /// Reference to the backing-filed. + /// Value to apply. + /// Name of the property used to notify listeners. This value is optional + /// and can be provided automatically when invoked from compilers that support . + /// true if the value was changed, false if the existing value matched the desired value. + protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) + { + if (!RequiresUpdate(ref storage, value)) return false; + + storage = value; + // ReSharper disable once ExplicitCallerInfoArgument + NotifyOfPropertyChange(propertyName); + return true; + } + + #endregion + } +} diff --git a/Arge/ViewModels/ShellViewModel.cs b/Arge/ViewModels/ShellViewModel.cs new file mode 100644 index 0000000..20d537c --- /dev/null +++ b/Arge/ViewModels/ShellViewModel.cs @@ -0,0 +1,6 @@ +namespace Arge.ViewModels +{ + public class ShellViewModel : AbstractViewModel + { + } +} diff --git a/Arge/Views/ShellView.xaml b/Arge/Views/ShellView.xaml new file mode 100644 index 0000000..abfff71 --- /dev/null +++ b/Arge/Views/ShellView.xaml @@ -0,0 +1,11 @@ + + + + diff --git a/Arge/Views/ShellView.xaml.cs b/Arge/Views/ShellView.xaml.cs new file mode 100644 index 0000000..a4d8f3f --- /dev/null +++ b/Arge/Views/ShellView.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows.Controls; + +namespace Arge.Views +{ + public partial class ShellView : UserControl + { + #region Constructors + + public ShellView() + { + InitializeComponent(); + } + + #endregion + } +} diff --git a/Arge/packages.config b/Arge/packages.config new file mode 100644 index 0000000..6c39799 --- /dev/null +++ b/Arge/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file