├── Samples ├── BeanTrader │ ├── Screenshot.png │ ├── .gitignore │ ├── NetFx │ │ ├── BeanTraderClient │ │ │ ├── BeanTrader.ico │ │ │ ├── BeanTrader.pfx │ │ │ ├── Resources │ │ │ │ ├── Images │ │ │ │ │ ├── RedBean.png │ │ │ │ │ ├── BlueBean.png │ │ │ │ │ ├── GreenBean.png │ │ │ │ │ └── YellowBean.png │ │ │ │ ├── Images.xaml │ │ │ │ ├── Themes │ │ │ │ │ └── Default.Accent.xaml │ │ │ │ ├── Styles.xaml │ │ │ │ └── StringResources.resx │ │ │ ├── Properties │ │ │ │ ├── Settings.settings │ │ │ │ ├── Settings.Designer.cs │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── Views │ │ │ │ ├── MainWindow.xaml.cs │ │ │ │ ├── MainWindow.xaml │ │ │ │ ├── TradingPage.xaml.cs │ │ │ │ ├── WelcomePage.xaml │ │ │ │ ├── WelcomePage.xaml.cs │ │ │ │ └── TradingPage.xaml │ │ │ ├── Models │ │ │ │ ├── TradeOffer.cs │ │ │ │ └── BeanDictionary.cs │ │ │ ├── DependencyInjection │ │ │ │ ├── BeanTraderServiceClientFactory.cs │ │ │ │ ├── ViewModelInstaller.cs │ │ │ │ ├── ViewInstaller.cs │ │ │ │ ├── Bootstrapper.cs │ │ │ │ └── ServiceInstaller.cs │ │ │ ├── BeanTraderCallback.cs │ │ │ ├── App.config │ │ │ ├── ViewModels │ │ │ │ ├── NewTradeOfferViewModel.cs │ │ │ │ └── OldUnusedViewModel.cs │ │ │ ├── App.xaml │ │ │ ├── Converters │ │ │ │ └── UIntToVisibleOnNonZeroConverter.cs │ │ │ ├── Controls │ │ │ │ ├── NewTradeOfferControl.xaml.cs │ │ │ │ ├── TradeOfferControl.xaml.cs │ │ │ │ ├── TradeOfferControl.xaml │ │ │ │ └── NewTradeOfferControl.xaml │ │ │ ├── packages.config │ │ │ ├── App.xaml.cs │ │ │ ├── DesignTimeData │ │ │ │ └── DesignTimeContexts.cs │ │ │ └── Services │ │ │ │ └── TradingService.cs │ │ ├── BeanTraderServer │ │ │ ├── BeanTrader.pfx │ │ │ ├── packages.config │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── App.config │ │ │ ├── Program.cs │ │ │ └── BeanTraderServer.csproj │ │ ├── BeanTraderInterfaces │ │ │ ├── Models │ │ │ │ ├── Beans.cs │ │ │ │ ├── TradeOffer.cs │ │ │ │ └── Trader.cs │ │ │ ├── IBeanTraderCallback.cs │ │ │ ├── IBeanTrader.cs │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ └── BeanTraderCommon.csproj │ │ ├── README.md │ │ └── BeanTrader.sln │ ├── NetCore │ │ ├── BeanTraderClient │ │ │ ├── BeanTrader.ico │ │ │ ├── BeanTrader.pfx │ │ │ ├── Resources │ │ │ │ ├── Images │ │ │ │ │ ├── RedBean.png │ │ │ │ │ ├── BlueBean.png │ │ │ │ │ ├── GreenBean.png │ │ │ │ │ └── YellowBean.png │ │ │ │ ├── Images.xaml │ │ │ │ ├── Themes │ │ │ │ │ └── Default.Accent.xaml │ │ │ │ ├── Styles.xaml │ │ │ │ ├── StringResources.resx │ │ │ │ └── StringResources.Designer.cs │ │ │ ├── Properties │ │ │ │ ├── Settings.settings │ │ │ │ ├── Settings.Designer.cs │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── Directory.Build.Props │ │ │ ├── Models │ │ │ │ ├── BeanTraderServiceClient.cs │ │ │ │ ├── TradeOffer.cs │ │ │ │ └── BeanDictionary.cs │ │ │ ├── App.config │ │ │ ├── Views │ │ │ │ ├── MainWindow.xaml.cs │ │ │ │ ├── MainWindow.xaml │ │ │ │ ├── TradingPage.xaml.cs │ │ │ │ ├── WelcomePage.xaml │ │ │ │ ├── WelcomePage.xaml.cs │ │ │ │ └── TradingPage.xaml │ │ │ ├── Connected Services │ │ │ │ └── BeanTraderService │ │ │ │ │ └── ConnectedService.json │ │ │ ├── DependencyInjection │ │ │ │ ├── ViewModelInstaller.cs │ │ │ │ ├── ViewInstaller.cs │ │ │ │ ├── Bootstrapper.cs │ │ │ │ ├── BeanTraderServiceClientFactory.cs │ │ │ │ └── ServiceInstaller.cs │ │ │ ├── BeanTraderCallback.cs │ │ │ ├── ViewModels │ │ │ │ ├── NewTradeOfferViewModel.cs │ │ │ │ └── OldUnusedViewModel.cs │ │ │ ├── App.xaml │ │ │ ├── Converters │ │ │ │ └── UIntToVisibleOnNonZeroConverter.cs │ │ │ ├── Controls │ │ │ │ ├── NewTradeOfferControl.xaml.cs │ │ │ │ ├── TradeOfferControl.xaml.cs │ │ │ │ ├── TradeOfferControl.xaml │ │ │ │ └── NewTradeOfferControl.xaml │ │ │ ├── App.xaml.cs │ │ │ ├── BeanTraderClient.Core.csproj │ │ │ ├── DesignTimeData │ │ │ │ └── DesignTimeContexts.cs │ │ │ └── Services │ │ │ │ └── TradingService.cs │ │ ├── BeanTraderServer │ │ │ ├── BeanTrader.pfx │ │ │ ├── packages.config │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── App.config │ │ │ ├── Program.cs │ │ │ └── BeanTraderServer.csproj │ │ ├── BeanTraderInterfaces │ │ │ ├── Models │ │ │ │ ├── Beans.cs │ │ │ │ ├── TradeOffer.cs │ │ │ │ └── Trader.cs │ │ │ ├── IBeanTraderCallback.cs │ │ │ ├── IBeanTrader.cs │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ └── BeanTraderCommon.csproj │ │ ├── README.md │ │ └── BeanTrader.sln │ └── README.md ├── README.md ├── .gitignore ├── .editorconfig └── .gitattributes ├── CODE-OF-CONDUCT.md ├── README.md └── docs └── win10apis └── README.md /Samples/BeanTrader/Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/Screenshot.png -------------------------------------------------------------------------------- /Samples/BeanTrader/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore publish output other than our manifests and readme 2 | **/ClickOnceManifests/*/* 3 | !**/ClickOnceManifests/*/*.manifest -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/BeanTrader.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/BeanTrader.ico -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/BeanTrader.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/BeanTrader.pfx -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderServer/BeanTrader.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderServer/BeanTrader.pfx -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/BeanTrader.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/BeanTrader.ico -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/BeanTrader.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/BeanTrader.pfx -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderServer/BeanTrader.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderServer/BeanTrader.pfx -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/RedBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/RedBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/RedBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/RedBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/BlueBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/BlueBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/GreenBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/GreenBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/BlueBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/BlueBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/GreenBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/GreenBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/YellowBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images/YellowBean.png -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/YellowBean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet/windows-desktop/HEAD/Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images/YellowBean.png -------------------------------------------------------------------------------- /Samples/README.md: -------------------------------------------------------------------------------- 1 | # Samples 2 | 3 | This folder contains sample .NET Core Windows Desktop applications. The samples include examples of porting WinForms, WPF, and UWP apps from .NET Framework to .NET Core. -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/Models/Beans.cs: -------------------------------------------------------------------------------- 1 | namespace BeanTrader.Models 2 | { 3 | public enum Beans 4 | { 5 | Red, 6 | Blue, 7 | Green, 8 | Yellow 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/Models/Beans.cs: -------------------------------------------------------------------------------- 1 | namespace BeanTrader.Models 2 | { 3 | public enum Beans 4 | { 5 | Red, 6 | Blue, 7 | Green, 8 | Yellow 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderServer/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderServer/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has adopted the code of conduct defined by the Contributor Covenant 4 | to clarify expected behavior in our community. 5 | 6 | For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). 7 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Directory.Build.Props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/bin 4 | $(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/obj 5 | 6 | -------------------------------------------------------------------------------- /Samples/.gitignore: -------------------------------------------------------------------------------- 1 | # Build output 2 | [Dd]ebug/ 3 | [Dd]ebugPublic/ 4 | [Rr]elease/ 5 | [Rr]eleases/ 6 | x64/ 7 | x86/ 8 | build/ 9 | bld/ 10 | [Bb]in/ 11 | [Oo]bj/ 12 | [Oo]ut/ 13 | [Tt]est[Rr]esult*/ 14 | [Bb]uild[Ll]og.* 15 | *.dll 16 | *.exe 17 | *.pdb 18 | 19 | # Nuget packages 20 | packages/ 21 | 22 | # User-specific files 23 | .vs/ 24 | *.suo 25 | *.user 26 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Models/BeanTraderServiceClient.cs: -------------------------------------------------------------------------------- 1 | public partial class BeanTraderServiceClient 2 | { 3 | public BeanTraderServiceClient(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 4 | base(callbackInstance, binding, remoteAddress) 5 | { } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/Models/TradeOffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace BeanTrader.Models 5 | { 6 | public class TradeOffer 7 | { 8 | public Guid Id { get; set; } 9 | public Guid SellerId { get; set; } 10 | public Dictionary Offering { get; set; } 11 | public Dictionary Asking { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/Models/TradeOffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace BeanTrader.Models 5 | { 6 | public class TradeOffer 7 | { 8 | public Guid Id { get; set; } 9 | public Guid SellerId { get; set; } 10 | public Dictionary Offering { get; set; } 11 | public Dictionary Asking { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Views/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | 3 | namespace BeanTraderClient.Views 4 | { 5 | /// 6 | /// Interaction logic for MainWindow.xaml 7 | /// 8 | public partial class MainWindow : MetroWindow 9 | { 10 | public MainWindow(WelcomePage welcomePage) 11 | { 12 | InitializeComponent(); 13 | 14 | MainFrame.Navigate(welcomePage); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Views/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using MahApps.Metro.Controls; 2 | 3 | namespace BeanTraderClient.Views 4 | { 5 | /// 6 | /// Interaction logic for MainWindow.xaml 7 | /// 8 | public partial class MainWindow : MetroWindow 9 | { 10 | public MainWindow(WelcomePage welcomePage) 11 | { 12 | InitializeComponent(); 13 | 14 | MainFrame.Navigate(welcomePage); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Models/TradeOffer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace BeanTrader.Models 5 | { 6 | public partial class TradeOffer 7 | { 8 | public override string ToString() => 9 | $"{BeansToString(Offering)} => {BeansToString(Asking)}"; 10 | 11 | private object BeansToString(Dictionary beans) => string.Join(", ", beans.Select(b => $"{b.Value} {b.Key.ToString()[0]}")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Models/TradeOffer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace BeanTrader.Models 5 | { 6 | public partial class TradeOffer 7 | { 8 | public override string ToString() => 9 | $"{BeansToString(Offering)} => {BeansToString(Asking)}"; 10 | 11 | private object BeansToString(Dictionary beans) => string.Join(", ", beans.Select(b => $"{b.Value} {b.Key.ToString()[0]}")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/IBeanTraderCallback.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.ServiceModel; 4 | 5 | namespace BeanTrader 6 | { 7 | public interface IBeanTraderCallback 8 | { 9 | [OperationContract(IsOneWay = true)] 10 | void AddNewTradeOffer(TradeOffer offer); 11 | 12 | [OperationContract(IsOneWay = true)] 13 | void RemoveTradeOffer(Guid offerId); 14 | 15 | [OperationContract(IsOneWay = true)] 16 | void TradeAccepted(TradeOffer offer, Guid buyerId); 17 | } 18 | } -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/IBeanTraderCallback.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.ServiceModel; 4 | 5 | namespace BeanTrader 6 | { 7 | public interface IBeanTraderCallback 8 | { 9 | [OperationContract(IsOneWay = true)] 10 | void AddNewTradeOffer(TradeOffer offer); 11 | 12 | [OperationContract(IsOneWay = true)] 13 | void RemoveTradeOffer(Guid offerId); 14 | 15 | [OperationContract(IsOneWay = true)] 16 | void TradeAccepted(TradeOffer offer, Guid buyerId); 17 | } 18 | } -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Connected Services/BeanTraderService/ConnectedService.json: -------------------------------------------------------------------------------- 1 | { 2 | "ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf", 3 | "Version": "15.0.30201.1201", 4 | "ExtendedData": { 5 | "inputs": [ 6 | "http://beantrader.eastus.cloudapp.azure.com:8080/" 7 | ], 8 | "collectionTypes": [ 9 | "System.Array", 10 | "System.Collections.Generic.Dictionary`2" 11 | ], 12 | "namespaceMappings": [ 13 | "*, BeanTraderService" 14 | ], 15 | "targetFramework": "netcoreapp3.0", 16 | "typeReuseMode": "None" 17 | } 18 | } -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DependencyInjection/BeanTraderServiceClientFactory.cs: -------------------------------------------------------------------------------- 1 | using System.ServiceModel; 2 | 3 | namespace BeanTraderClient.DependencyInjection 4 | { 5 | public class BeanTraderServiceClientFactory 6 | { 7 | private BeanTraderServiceCallback CallbackHandler { get; } 8 | 9 | public BeanTraderServiceClientFactory(BeanTraderServiceCallback callbackHandler) 10 | { 11 | CallbackHandler = callbackHandler; 12 | } 13 | 14 | public BeanTraderServiceClient GetServiceClient() => new BeanTraderServiceClient(new InstanceContext(CallbackHandler)); 15 | } 16 | } -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Images.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Images.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DependencyInjection/ViewModelInstaller.cs: -------------------------------------------------------------------------------- 1 | using Castle.MicroKernel.Registration; 2 | using Castle.MicroKernel.SubSystems.Configuration; 3 | using Castle.Windsor; 4 | using System; 5 | 6 | namespace BeanTraderClient.DependencyInjection 7 | { 8 | public class ViewModelInstaller : IWindsorInstaller 9 | { 10 | public void Install(IWindsorContainer container, IConfigurationStore store) 11 | { 12 | container.Register(Classes.FromThisAssembly() 13 | .Where(t => t.Name.EndsWith("ViewModel", StringComparison.Ordinal)) 14 | .LifestyleTransient()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DependencyInjection/ViewInstaller.cs: -------------------------------------------------------------------------------- 1 | using Castle.MicroKernel.Registration; 2 | using Castle.MicroKernel.SubSystems.Configuration; 3 | using Castle.Windsor; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | 7 | namespace BeanTraderClient.DependencyInjection 8 | { 9 | public class ViewInstaller : IWindsorInstaller 10 | { 11 | public void Install(IWindsorContainer container, IConfigurationStore store) 12 | { 13 | container.Register(Classes.FromThisAssembly() 14 | .BasedOn() 15 | .OrBasedOn(typeof(Page)) 16 | .LifestyleTransient()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DependencyInjection/ViewModelInstaller.cs: -------------------------------------------------------------------------------- 1 | using Castle.MicroKernel.Registration; 2 | using Castle.MicroKernel.SubSystems.Configuration; 3 | using Castle.Windsor; 4 | using System; 5 | 6 | namespace BeanTraderClient.DependencyInjection 7 | { 8 | public class ViewModelInstaller : IWindsorInstaller 9 | { 10 | public void Install(IWindsorContainer container, IConfigurationStore store) 11 | { 12 | container.Register(Classes.FromAssemblyContaining(typeof(ViewModelInstaller)) 13 | .Where(t => t.Name.EndsWith("ViewModel", StringComparison.Ordinal)) 14 | .LifestyleTransient()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DependencyInjection/ViewInstaller.cs: -------------------------------------------------------------------------------- 1 | using Castle.MicroKernel.Registration; 2 | using Castle.MicroKernel.SubSystems.Configuration; 3 | using Castle.Windsor; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | 7 | namespace BeanTraderClient.DependencyInjection 8 | { 9 | public class ViewInstaller : IWindsorInstaller 10 | { 11 | public void Install(IWindsorContainer container, IConfigurationStore store) 12 | { 13 | container.Register(Classes.FromAssemblyContaining(typeof(ViewInstaller)) 14 | .BasedOn() 15 | .OrBasedOn(typeof(Page)) 16 | .LifestyleTransient()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/BeanTraderCallback.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader; 2 | using BeanTrader.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BeanTraderClient 10 | { 11 | public class BeanTraderCallback : BeanTraderServiceCallback 12 | { 13 | public event Action AddNewTradeOfferHandler; 14 | public event Action RemoveTradeOfferHandler; 15 | public event Action TradeAcceptedHandler; 16 | 17 | public void AddNewTradeOffer(TradeOffer offer) => AddNewTradeOfferHandler?.Invoke(offer); 18 | public void RemoveTradeOffer(Guid offerId) => RemoveTradeOfferHandler?.Invoke(offerId); 19 | public void TradeAccepted(TradeOffer offer, Guid buyerId) => TradeAcceptedHandler?.Invoke(offer, buyerId); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/BeanTraderCallback.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader; 2 | using BeanTrader.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace BeanTraderClient 10 | { 11 | public class BeanTraderCallback : BeanTraderServiceCallback 12 | { 13 | public event Action AddNewTradeOfferHandler; 14 | public event Action RemoveTradeOfferHandler; 15 | public event Action TradeAcceptedHandler; 16 | 17 | public void AddNewTradeOffer(TradeOffer offer) => AddNewTradeOfferHandler?.Invoke(offer); 18 | public void RemoveTradeOffer(Guid offerId) => RemoveTradeOfferHandler?.Invoke(offerId); 19 | public void TradeAccepted(TradeOffer offer, Guid buyerId) => TradeAcceptedHandler?.Invoke(offer, buyerId); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Models/BeanDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | 6 | namespace BeanTrader.Models 7 | { 8 | // This is only needed because WPF DataTemplates can't format generic types 9 | [Serializable] 10 | public class BeanDictionary : Dictionary 11 | { 12 | public BeanDictionary(Dictionary source) : base(source) { } 13 | 14 | public BeanDictionary(): this(new Dictionary()) 15 | { 16 | foreach (var bean in Enum.GetValues(typeof(Beans)).Cast()) 17 | { 18 | Add(bean, 0); 19 | } 20 | } 21 | 22 | protected BeanDictionary(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) 23 | { } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Models/BeanDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | 6 | namespace BeanTrader.Models 7 | { 8 | // This is only needed because WPF DataTemplates can't format generic types 9 | [Serializable] 10 | public class BeanDictionary : Dictionary 11 | { 12 | public BeanDictionary(Dictionary source) : base(source) { } 13 | 14 | public BeanDictionary(): this(new Dictionary()) 15 | { 16 | foreach (var bean in Enum.GetValues(typeof(Beans)).Cast()) 17 | { 18 | Add(bean, 0); 19 | } 20 | } 21 | 22 | protected BeanDictionary(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) 23 | { } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DependencyInjection/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using Castle.Windsor; 2 | using Castle.Windsor.Installer; 3 | 4 | namespace BeanTraderClient.DependencyInjection 5 | { 6 | public static class Bootstrapper 7 | { 8 | private static IWindsorContainer container; 9 | private static readonly object syncRoot = new object(); 10 | 11 | public static IWindsorContainer Container 12 | { 13 | get 14 | { 15 | if (container == null) 16 | { 17 | lock (syncRoot) 18 | { 19 | if (container == null) 20 | { 21 | container = new WindsorContainer().Install(FromAssembly.This()); 22 | } 23 | } 24 | } 25 | 26 | return container; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DependencyInjection/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using Castle.Windsor; 2 | using Castle.Windsor.Installer; 3 | 4 | namespace BeanTraderClient.DependencyInjection 5 | { 6 | public static class Bootstrapper 7 | { 8 | private static IWindsorContainer container; 9 | private static object syncRoot = new object(); 10 | 11 | public static IWindsorContainer Container 12 | { 13 | get 14 | { 15 | if (container == null) 16 | { 17 | lock (syncRoot) 18 | { 19 | if (container == null) 20 | { 21 | container = new WindsorContainer().Install(FromAssembly.Containing(typeof(Bootstrapper))); 22 | } 23 | } 24 | } 25 | 26 | return container; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DependencyInjection/BeanTraderServiceClientFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.ServiceModel; 4 | 5 | namespace BeanTraderClient.DependencyInjection 6 | { 7 | public class BeanTraderServiceClientFactory 8 | { 9 | private BeanTraderServiceCallback CallbackHandler { get; } 10 | 11 | public BeanTraderServiceClientFactory(BeanTraderServiceCallback callbackHandler) 12 | { 13 | CallbackHandler = callbackHandler; 14 | } 15 | 16 | public BeanTraderServiceClient GetServiceClient() 17 | { 18 | var binding = new NetTcpBinding(); 19 | binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; 20 | 21 | var endpointAddress = new EndpointAddress(new Uri(ConfigurationManager.AppSettings["BeanTraderEndpointAddress"]), new DnsEndpointIdentity("BeanTrader")); 22 | 23 | return new BeanTraderServiceClient(new InstanceContext(CallbackHandler), binding, endpointAddress); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/IBeanTrader.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ServiceModel; 5 | 6 | namespace BeanTrader 7 | { 8 | [ServiceContract(Name = "BeanTraderService", CallbackContract = typeof(IBeanTraderCallback), SessionMode = SessionMode.Required)] 9 | public interface IBeanTrader 10 | { 11 | [OperationContract] 12 | IEnumerable ListenForTradeOffers(); 13 | 14 | [OperationContract] 15 | Trader GetCurrentTraderInfo(); 16 | 17 | [OperationContract(IsOneWay = true)] 18 | void Login(string name); 19 | 20 | [OperationContract(IsOneWay = true)] 21 | void Logout(); 22 | 23 | [OperationContract] 24 | Dictionary GetTraderNames(IEnumerable traderId); 25 | 26 | [OperationContract] 27 | bool AcceptTrade(Guid offerId); 28 | 29 | [OperationContract] 30 | Guid OfferTrade(TradeOffer offer); 31 | 32 | [OperationContract] 33 | bool CancelTradeOffer(Guid offerId); 34 | 35 | [OperationContract(IsOneWay = true)] 36 | void StopListening(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/IBeanTrader.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ServiceModel; 5 | 6 | namespace BeanTrader 7 | { 8 | [ServiceContract(Name = "BeanTraderService", CallbackContract = typeof(IBeanTraderCallback), SessionMode = SessionMode.Required)] 9 | public interface IBeanTrader 10 | { 11 | [OperationContract] 12 | IEnumerable ListenForTradeOffers(); 13 | 14 | [OperationContract] 15 | Trader GetCurrentTraderInfo(); 16 | 17 | [OperationContract(IsOneWay = true)] 18 | void Login(string name); 19 | 20 | [OperationContract(IsOneWay = true)] 21 | void Logout(); 22 | 23 | [OperationContract] 24 | Dictionary GetTraderNames(IEnumerable traderId); 25 | 26 | [OperationContract] 27 | bool AcceptTrade(Guid offerId); 28 | 29 | [OperationContract] 30 | Guid OfferTrade(TradeOffer offer); 31 | 32 | [OperationContract] 33 | bool CancelTradeOffer(Guid offerId); 34 | 35 | [OperationContract(IsOneWay = true)] 36 | void StopListening(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/ViewModels/NewTradeOfferViewModel.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace BeanTraderClient.ViewModels 6 | { 7 | public class NewTradeOfferViewModel 8 | { 9 | private readonly Func closeDialogFunc; 10 | 11 | public BeanDictionary BeansOffered { get; } = new BeanDictionary(); 12 | public BeanDictionary BeansAsked { get; } = new BeanDictionary(); 13 | public event Func CreateTradeHandler; 14 | 15 | public NewTradeOfferViewModel(Func closeDialogFunc) 16 | { 17 | this.closeDialogFunc = closeDialogFunc; 18 | } 19 | 20 | public async Task CreateTradeOfferAsync() 21 | { 22 | await closeDialogFunc().ConfigureAwait(false); 23 | 24 | await (CreateTradeHandler?.Invoke(new TradeOffer 25 | { 26 | Asking = BeansAsked, 27 | Offering = BeansOffered 28 | })).ConfigureAwait(false); 29 | } 30 | 31 | public async Task CancelTradeOfferAsync() 32 | { 33 | await closeDialogFunc().ConfigureAwait(false); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/ViewModels/NewTradeOfferViewModel.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace BeanTraderClient.ViewModels 6 | { 7 | public class NewTradeOfferViewModel 8 | { 9 | private readonly Func closeDialogFunc; 10 | 11 | public BeanDictionary BeansOffered { get; } = new BeanDictionary(); 12 | public BeanDictionary BeansAsked { get; } = new BeanDictionary(); 13 | public event Func CreateTradeHandler; 14 | 15 | public NewTradeOfferViewModel(Func closeDialogFunc) 16 | { 17 | this.closeDialogFunc = closeDialogFunc; 18 | } 19 | 20 | public async Task CreateTradeOfferAsync() 21 | { 22 | await closeDialogFunc().ConfigureAwait(false); 23 | 24 | await (CreateTradeHandler?.Invoke(new TradeOffer 25 | { 26 | Asking = BeansAsked, 27 | Offering = BeansOffered 28 | })).ConfigureAwait(false); 29 | } 30 | 31 | public async Task CancelTradeOfferAsync() 32 | { 33 | await closeDialogFunc().ConfigureAwait(false); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BeanTraderClient.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BeanTraderClient.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/Models/Trader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.Serialization; 4 | 5 | namespace BeanTrader.Models 6 | { 7 | [DataContract] 8 | public class Trader 9 | { 10 | static int[] DefaultBeans = new[] { 100, 50, 10, 1 }; 11 | 12 | public static Trader Empty = new Trader(Guid.Empty, string.Empty) 13 | { 14 | Inventory = new int[Enum.GetValues(typeof(Beans)).Cast().Max() + 1] 15 | }; 16 | 17 | public Trader(): this(Guid.NewGuid()) { } 18 | 19 | public Trader(Guid id) : this(id, $"Trader {id}") { } 20 | 21 | public Trader(string name) : this(Guid.NewGuid(), name) { } 22 | 23 | public Trader(Guid id, string name) 24 | { 25 | Id = id; 26 | Name = name; 27 | Inventory = new int[Enum.GetValues(typeof(Beans)).Cast().Max() + 1]; 28 | Array.Copy(DefaultBeans, Inventory, DefaultBeans.Length); 29 | } 30 | 31 | [DataMember] 32 | public Guid Id { get; set; } 33 | 34 | [DataMember] 35 | public string Name { get; set; } 36 | 37 | [DataMember] 38 | public int[] Inventory { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/Models/Trader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.Serialization; 4 | 5 | namespace BeanTrader.Models 6 | { 7 | [DataContract] 8 | public class Trader 9 | { 10 | static int[] DefaultBeans = new[] { 100, 50, 10, 1 }; 11 | 12 | public static Trader Empty = new Trader(Guid.Empty, string.Empty) 13 | { 14 | Inventory = new int[Enum.GetValues(typeof(Beans)).Cast().Max() + 1] 15 | }; 16 | 17 | public Trader(): this(Guid.NewGuid()) { } 18 | 19 | public Trader(Guid id) : this(id, $"Trader {id}") { } 20 | 21 | public Trader(string name) : this(Guid.NewGuid(), name) { } 22 | 23 | public Trader(Guid id, string name) 24 | { 25 | Id = id; 26 | Name = name; 27 | Inventory = new int[Enum.GetValues(typeof(Beans)).Cast().Max() + 1]; 28 | Array.Copy(DefaultBeans, Inventory, DefaultBeans.Length); 29 | } 30 | 31 | [DataMember] 32 | public Guid Id { get; set; } 33 | 34 | [DataMember] 35 | public string Name { get; set; } 36 | 37 | [DataMember] 38 | public int[] Inventory { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/App.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/App.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Samples/.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | # (Please don't specify an indent_size here; that has too many unintended consequences.) 6 | indent_style = space 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | # Code files 11 | [*.{cs,csx,vb,vbx}] 12 | indent_size = 4 13 | csharp_style_conditional_delegate_call = true:warning 14 | csharp_style_inlined_variable_declaration = true:warning 15 | csharp_style_pattern_matching_over_as_with_null_check = true:error 16 | csharp_style_pattern_matching_over_is_with_cast_check = true:error 17 | csharp_style_throw_expression = true:error 18 | csharp_style_var_elsewhere = true:suggestion 19 | csharp_style_var_for_built_in_types = true:error 20 | csharp_style_var_when_type_is_apparent = true:error 21 | dotnet_style_null_propagation = true:error 22 | dotnet_style_coalesce_expression = true:error 23 | dotnet_style_collection_initializer = true:error 24 | dotnet_style_object_initializer = true:error 25 | 26 | # Xml project files 27 | [*.{xml,csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 28 | indent_size = 2 29 | 30 | # Xml config files 31 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 32 | indent_size = 2 33 | 34 | # JSON files 35 | [*.json] 36 | indent_size = 2 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DependencyInjection/ServiceInstaller.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.Services; 2 | using Castle.MicroKernel.Registration; 3 | using Castle.MicroKernel.SubSystems.Configuration; 4 | using Castle.Windsor; 5 | using MahApps.Metro.Controls.Dialogs; 6 | 7 | namespace BeanTraderClient.DependencyInjection 8 | { 9 | public class ServiceInstaller : IWindsorInstaller 10 | { 11 | public void Install(IWindsorContainer container, IConfigurationStore store) 12 | { 13 | // MahApps dialog coordinator 14 | container.Register(Component.For().Instance(DialogCoordinator.Instance)); 15 | 16 | // BeanTrader services 17 | container.Register(Component.For() 18 | .ImplementedBy() 19 | .LifestyleSingleton()); 20 | container.Register(Component.For()); 21 | container.Register(Component.For() 22 | .UsingFactory(factory => factory.GetServiceClient())); 23 | container.Register(Component.For() 24 | .LifestyleSingleton()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DependencyInjection/ServiceInstaller.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.Services; 2 | using Castle.MicroKernel.Registration; 3 | using Castle.MicroKernel.SubSystems.Configuration; 4 | using Castle.Windsor; 5 | using MahApps.Metro.Controls.Dialogs; 6 | 7 | namespace BeanTraderClient.DependencyInjection 8 | { 9 | public class ServiceInstaller : IWindsorInstaller 10 | { 11 | public void Install(IWindsorContainer container, IConfigurationStore store) 12 | { 13 | // MahApps dialog coordinator 14 | container.Register(Component.For().Instance(DialogCoordinator.Instance)); 15 | 16 | // BeanTrader services 17 | container.Register(Component.For() 18 | .ImplementedBy() 19 | .LifestyleSingleton()); 20 | container.Register(Component.For()); 21 | container.Register(Component.For() 22 | .UsingFactory(factory => factory.GetServiceClient())); 23 | container.Register(Component.For() 24 | .LifestyleSingleton()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Converters/UIntToVisibleOnNonZeroConverter.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | using System.Windows.Data; 10 | 11 | namespace BeanTraderClient.Converters 12 | { 13 | // Converts positive uints to Visible and 0 or invalid values to Collapsed 14 | #pragma warning disable CA1812 // Unused internal class 15 | class UIntToVisibleOnNonZeroConverter : IValueConverter 16 | #pragma warning restore CA1812 // Unused internal class 17 | { 18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | if (value is Dictionary inventory && 21 | parameter is Beans beanType && 22 | inventory.ContainsKey(beanType) && 23 | inventory[beanType] > 0) 24 | { 25 | return Visibility.Visible; 26 | } 27 | 28 | return Visibility.Collapsed; 29 | } 30 | 31 | 32 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => 33 | throw new NotImplementedException(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Converters/UIntToVisibleOnNonZeroConverter.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | using System.Windows.Data; 10 | 11 | namespace BeanTraderClient.Converters 12 | { 13 | // Converts positive uints to Visible and 0 or invalid values to Collapsed 14 | #pragma warning disable CA1812 // Unused internal class 15 | class UIntToVisibleOnNonZeroConverter : IValueConverter 16 | #pragma warning restore CA1812 // Unused internal class 17 | { 18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | if (value is Dictionary inventory && 21 | parameter is Beans beanType && 22 | inventory.ContainsKey(beanType) && 23 | inventory[beanType] > 0) 24 | { 25 | return Visibility.Visible; 26 | } 27 | 28 | return Visibility.Collapsed; 29 | } 30 | 31 | 32 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => 33 | throw new NotImplementedException(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BeanTraderServer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BeanTraderServer")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c7fe70df-ef5a-4fed-91be-9f6488c17135")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BeanTraderServer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BeanTraderServer")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c7fe70df-ef5a-4fed-91be-9f6488c17135")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderInterfaces/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BeanTraderInterfaces")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BeanTraderInterfaces")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("41c7e011-840e-44ab-9b5b-caf6e7b7de65")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderInterfaces/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BeanTraderInterfaces")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BeanTraderInterfaces")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("41c7e011-840e-44ab-9b5b-caf6e7b7de65")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Controls/NewTradeOfferControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.ViewModels; 2 | using System; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Input; 6 | 7 | namespace BeanTraderClient.Controls 8 | { 9 | /// 10 | /// Interaction logic for NewTradeOfferControl.xaml 11 | /// 12 | public partial class NewTradeOfferControl : UserControl 13 | { 14 | NewTradeOfferViewModel Model => DataContext as NewTradeOfferViewModel; 15 | 16 | public NewTradeOfferControl() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | private async void CancelButton_Click(object sender, RoutedEventArgs e) => await Model.CancelTradeOfferAsync().ConfigureAwait(false); 22 | private async void CreateButton_Click(object sender, RoutedEventArgs e) => await Model.CreateTradeOfferAsync().ConfigureAwait(false); 23 | 24 | // Select text in the bean count text boxes so that users can easily replace the initial '0' 25 | private void BeanTextBox_GotFocus(object sender, EventArgs e) 26 | { 27 | if (sender is TextBox textBox) 28 | { 29 | textBox.SelectAll(); 30 | } 31 | } 32 | 33 | private void IgnoreIfUnfocused(object sender, MouseEventArgs e) 34 | { 35 | if (sender is TextBox textBox) 36 | { 37 | if (!textBox.IsKeyboardFocusWithin) 38 | { 39 | textBox.Focus(); 40 | e.Handled = true; 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Controls/NewTradeOfferControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.ViewModels; 2 | using System; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Input; 6 | 7 | namespace BeanTraderClient.Controls 8 | { 9 | /// 10 | /// Interaction logic for NewTradeOfferControl.xaml 11 | /// 12 | public partial class NewTradeOfferControl : UserControl 13 | { 14 | NewTradeOfferViewModel Model => DataContext as NewTradeOfferViewModel; 15 | 16 | public NewTradeOfferControl() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | private async void CancelButton_Click(object sender, RoutedEventArgs e) => await Model.CancelTradeOfferAsync().ConfigureAwait(false); 22 | private async void CreateButton_Click(object sender, RoutedEventArgs e) => await Model.CreateTradeOfferAsync().ConfigureAwait(false); 23 | 24 | // Select text in the bean count text boxes so that users can easily replace the initial '0' 25 | private void BeanTextBox_GotFocus(object sender, EventArgs e) 26 | { 27 | if (sender is TextBox textBox) 28 | { 29 | textBox.SelectAll(); 30 | } 31 | } 32 | 33 | private void IgnoreIfUnfocused(object sender, MouseEventArgs e) 34 | { 35 | if (sender is TextBox textBox) 36 | { 37 | if (!textBox.IsKeyboardFocusWithin) 38 | { 39 | textBox.Focus(); 40 | e.Handled = true; 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderServer/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderServer/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Themes/Default.Accent.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | #E8E4DB 6 | #99897A 7 | #685d53 8 | #BAD3DB 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Themes/Default.Accent.xaml: -------------------------------------------------------------------------------- 1 | 4 | 5 | #E8E4DB 6 | #99897A 7 | #685d53 8 | #BAD3DB 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderServer/Program.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.IO; 4 | using System.Security.Cryptography.X509Certificates; 5 | using System.ServiceModel; 6 | using System.ServiceModel.Security; 7 | 8 | namespace BeanTraderServer 9 | { 10 | class Program 11 | { 12 | static void Main() 13 | { 14 | ConfigureLogging(); 15 | 16 | using (var host = new ServiceHost(typeof(BeanTrader))) 17 | { 18 | // For demo purposes, just load the key from disk so that no one needs to install an untrustworthy self-signed cert 19 | var certPath = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BeanTrader.pfx"); 20 | host.Credentials.ServiceCertificate.Certificate = new X509Certificate2(certPath, "password"); 21 | host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 22 | host.Open(); 23 | Log.Information("Bean Trader Service listening"); 24 | WaitForExitSignal(); 25 | Log.Information("Shutting down..."); 26 | host.Close(); 27 | } 28 | } 29 | 30 | private static void WaitForExitSignal() 31 | { 32 | Console.WriteLine("Press enter to exit"); 33 | Console.ReadLine(); 34 | } 35 | 36 | private static void ConfigureLogging() 37 | { 38 | Log.Logger = new LoggerConfiguration() 39 | .WriteTo.Console() 40 | .CreateLogger(); 41 | 42 | Log.Information("Logging initialized"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderServer/Program.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | using System; 3 | using System.IO; 4 | using System.Security.Cryptography.X509Certificates; 5 | using System.ServiceModel; 6 | using System.ServiceModel.Security; 7 | 8 | namespace BeanTraderServer 9 | { 10 | class Program 11 | { 12 | static void Main() 13 | { 14 | ConfigureLogging(); 15 | 16 | using (var host = new ServiceHost(typeof(BeanTrader))) 17 | { 18 | // For demo purposes, just load the key from disk so that no one needs to install an untrustworthy self-signed cert 19 | // or load from KeyVault (which would complicate the sample) 20 | var certPath = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "BeanTrader.pfx"); 21 | host.Credentials.ServiceCertificate.Certificate = new X509Certificate2(certPath, "password"); 22 | host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 23 | host.Open(); 24 | Log.Information("Bean Trader Service listening"); 25 | WaitForExitSignal(); 26 | Log.Information("Shutting down..."); 27 | host.Close(); 28 | } 29 | } 30 | 31 | private static void WaitForExitSignal() 32 | { 33 | Console.WriteLine("Press enter to exit"); 34 | Console.ReadLine(); 35 | } 36 | 37 | private static void ConfigureLogging() 38 | { 39 | Log.Logger = new LoggerConfiguration() 40 | .WriteTo.Console() 41 | .CreateLogger(); 42 | 43 | Log.Information("Logging initialized"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.DependencyInjection; 2 | using BeanTraderClient.Views; 3 | using MahApps.Metro; 4 | using System; 5 | using System.Configuration; 6 | using System.IO; 7 | using System.Windows; 8 | 9 | namespace BeanTraderClient 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | private const string AccentThemeExtension = ".Accent.xaml"; 17 | private static readonly string ThemesRelativePath = Path.Combine("Resources", "Themes"); 18 | 19 | protected override void OnStartup(StartupEventArgs e) 20 | { 21 | 22 | // Dynamically load a custom MahApps theme from disk as an exercise in using a few more Framework APIs 23 | var themesDirectory = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ThemesRelativePath); 24 | foreach (var accentFile in Directory.GetFiles(themesDirectory, $"*{AccentThemeExtension}")) 25 | { 26 | var fileName = Path.GetFileName(accentFile); 27 | ThemeManager.AddAccent(fileName.Substring(0, fileName.Length - AccentThemeExtension.Length), new Uri(accentFile)); 28 | } 29 | 30 | // In the future, we could have multiple themes and store preferences in the registry 31 | var (currentTheme, _) = ThemeManager.DetectAppStyle(Application.Current); 32 | ThemeManager.ChangeAppStyle(Application.Current, 33 | ThemeManager.GetAccent(ConfigurationManager.AppSettings["DefaultTheme"]), 34 | currentTheme); 35 | 36 | Bootstrapper.Container.Resolve().Show(); 37 | 38 | base.OnStartup(e); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.DependencyInjection; 2 | using BeanTraderClient.Views; 3 | using MahApps.Metro; 4 | using System; 5 | using System.Configuration; 6 | using System.IO; 7 | using System.Windows; 8 | 9 | namespace BeanTraderClient 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | private const string AccentThemeExtension = ".Accent.xaml"; 17 | private static readonly string ThemesRelativePath = Path.Combine("Resources", "Themes"); 18 | 19 | protected override void OnStartup(StartupEventArgs e) 20 | { 21 | 22 | // Dynamically load a custom MahApps theme from disk as an exercise in using a few more Framework APIs 23 | var themesDirectory = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ThemesRelativePath); 24 | foreach (var accentFile in Directory.GetFiles(themesDirectory, $"*{AccentThemeExtension}")) 25 | { 26 | var fileName = Path.GetFileName(accentFile); 27 | ThemeManager.AddAccent(fileName.Substring(0, fileName.Length - AccentThemeExtension.Length), new Uri(accentFile)); 28 | } 29 | 30 | // In the future, we could have multiple themes and store preferences in the registry 31 | var (currentTheme, _) = ThemeManager.DetectAppStyle(Application.Current); 32 | ThemeManager.ChangeAppStyle(Application.Current, 33 | ThemeManager.GetAccent(ConfigurationManager.AppSettings["DefaultTheme"]), 34 | currentTheme); 35 | 36 | Bootstrapper.Container.Resolve().Show(); 37 | 38 | base.OnStartup(e); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/BeanTraderClient.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | netcoreapp3.0 6 | true 7 | BeanTraderClient 8 | BeanTraderClient 9 | BeanTrader.ico 10 | false 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Designer 24 | MSBuild:Compile 25 | PreserveNewest 26 | 27 | 28 | 29 | PreserveNewest 30 | 31 | 32 | 33 | 34 | 35 | 4.1.1 36 | 37 | 38 | 1.6.5 39 | 40 | 41 | 2.6.3 42 | runtime; build; native; contentfiles; analyzers 43 | all 44 | 45 | 46 | 47 | 5.0.0-pre-05 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Views/TradingPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.ViewModels; 2 | using System; 3 | using System.Threading.Tasks; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Navigation; 7 | 8 | namespace BeanTraderClient.Views 9 | { 10 | /// 11 | /// Interaction logic for TradingPage.xaml 12 | /// 13 | public partial class TradingPage : Page 14 | { 15 | public TradingViewModel Model { get; } 16 | 17 | public TradingPage(TradingViewModel viewModel) 18 | { 19 | InitializeComponent(); 20 | Model = viewModel; 21 | this.DataContext = this.Model; 22 | } 23 | 24 | private async void Load(object sender, RoutedEventArgs e) 25 | { 26 | // Make sure that this page's model is 27 | // cleaned up if the app closes 28 | Application.Current.MainWindow.Closing += Unload; 29 | 30 | await Model.LoadAsync().ConfigureAwait(false); 31 | } 32 | 33 | private async void Unload(object sender, EventArgs e) 34 | { 35 | Application.Current.MainWindow.Closing -= Unload; 36 | 37 | // In the case of the app closing, it's possible that 38 | // UnloadAsync won't have a chance to finish. 39 | // I think it's better to preserve the 'fast exit' user 40 | // experience and just harden the backend against possible 41 | // abandoned sessions. 42 | // The alternative would be to wrap this in Task.Run and wait 43 | // for it to finish. 44 | await Model.UnloadAsync().ConfigureAwait(false); 45 | } 46 | 47 | private void LogoutButton_Click(object sender, RoutedEventArgs e) 48 | { 49 | NavigationService.GoBack(); 50 | } 51 | 52 | private async void NewTradeButton_Click(object sender, RoutedEventArgs e) 53 | { 54 | await Model.ShowNewTradeOfferDialog().ConfigureAwait(false); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Views/TradingPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using BeanTraderClient.ViewModels; 2 | using System; 3 | using System.Threading.Tasks; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Navigation; 7 | 8 | namespace BeanTraderClient.Views 9 | { 10 | /// 11 | /// Interaction logic for TradingPage.xaml 12 | /// 13 | public partial class TradingPage : Page 14 | { 15 | public TradingViewModel Model { get; } 16 | 17 | public TradingPage(TradingViewModel viewModel) 18 | { 19 | InitializeComponent(); 20 | Model = viewModel; 21 | this.DataContext = this.Model; 22 | } 23 | 24 | private async void Load(object sender, RoutedEventArgs e) 25 | { 26 | // Make sure that this page's model is 27 | // cleaned up if the app closes 28 | Application.Current.MainWindow.Closing += Unload; 29 | 30 | await Model.LoadAsync().ConfigureAwait(false); 31 | } 32 | 33 | private async void Unload(object sender, EventArgs e) 34 | { 35 | Application.Current.MainWindow.Closing -= Unload; 36 | 37 | // In the case of the app closing, it's possible that 38 | // UnloadAsync won't have a chance to finish. 39 | // I think it's better to preserve the 'fast exit' user 40 | // experience and just harden the backend against possible 41 | // abandoned sessions. 42 | // The alternative would be to wrap this in Task.Run and wait 43 | // for it to finish. 44 | await Model.UnloadAsync().ConfigureAwait(false); 45 | } 46 | 47 | private void LogoutButton_Click(object sender, RoutedEventArgs e) 48 | { 49 | NavigationService.GoBack(); 50 | } 51 | 52 | private async void NewTradeButton_Click(object sender, RoutedEventArgs e) 53 | { 54 | await Model.ShowNewTradeOfferDialog().ConfigureAwait(false); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Resources/Styles.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 12 | 13 | 16 | 17 | 22 | 23 | 27 | 28 | 31 | 32 | 33 | #772827 34 | #672827 35 | #10388D 36 | #2D6A3F 37 | #8D864A 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/Resources/Styles.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 12 | 13 | 16 | 17 | 22 | 23 | 27 | 28 | 31 | 32 | 33 | #772827 34 | #672827 35 | #10388D 36 | #2D6A3F 37 | #8D864A 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/ViewModels/OldUnusedViewModel.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using BeanTraderClient.Controls; 3 | using BeanTraderClient.Resources; 4 | using BeanTraderClient.Services; 5 | using MahApps.Metro.Controls.Dialogs; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.ObjectModel; 10 | using System.ComponentModel; 11 | using System.Globalization; 12 | using System.Linq; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using System.Windows; 16 | using System.Windows.Media; 17 | 18 | namespace BeanTraderClient.ViewModels 19 | { 20 | // This class is unused. It's not even part of the BeanTraderClient project. 21 | // It exists here as a demonstrating of how old, unused source can introduce errors when 22 | // porting to .NET Core since the new project system defaults to including all source 23 | // files under its directory. 24 | public class TradingViewModel2 : INotifyPropertyChanged 25 | { 26 | private Trader trader; 27 | private string statusText; 28 | private Brush statusBrush; 29 | private string userName; 30 | private IList tradeOffers; 31 | 32 | private IDialogCoordinator DialogCoordinator { get; } 33 | private TradingService TradingService { get; } 34 | private BeanTraderCallback CallbackHandler { get; } 35 | private Timer StatusClearTimer { get; } 36 | 37 | // Initialized by ListenForTradeOffers, this field caches trader names (indexed by ID) 38 | private ConcurrentDictionary traderNames; 39 | 40 | public TradingViewModel2(IDialogCoordinator dialogCoordinator, TradingService tradingService, BeanTraderCallback callbackHandler) 41 | { 42 | DialogCoordinator = dialogCoordinator; 43 | TradingService = tradingService; 44 | CallbackHandler = callbackHandler; 45 | StatusClearTimer = new Timer(ClearStatus); 46 | traderNames = new ConcurrentDictionary(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/ViewModels/OldUnusedViewModel.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using BeanTraderClient.Controls; 3 | using BeanTraderClient.Resources; 4 | using BeanTraderClient.Services; 5 | using MahApps.Metro.Controls.Dialogs; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Collections.ObjectModel; 10 | using System.ComponentModel; 11 | using System.Globalization; 12 | using System.Linq; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using System.Windows; 16 | using System.Windows.Media; 17 | 18 | namespace BeanTraderClient.ViewModels 19 | { 20 | // This class is unused. It's not even part of the BeanTraderClient project. 21 | // It exists here as a demonstrating of how old, unused source can introduce errors when 22 | // porting to .NET Core since the new project system defaults to including all source 23 | // files under its directory. 24 | public class TradingViewModel2 : INotifyPropertyChanged 25 | { 26 | private Trader trader; 27 | private string statusText; 28 | private Brush statusBrush; 29 | private string userName; 30 | private IList tradeOffers; 31 | 32 | private IDialogCoordinator DialogCoordinator { get; } 33 | private TradingService TradingService { get; } 34 | private BeanTraderCallback CallbackHandler { get; } 35 | private Timer StatusClearTimer { get; } 36 | 37 | // Initialized by ListenForTradeOffers, this field caches trader names (indexed by ID) 38 | private ConcurrentDictionary traderNames; 39 | 40 | public TradingViewModel2(IDialogCoordinator dialogCoordinator, TradingService tradingService, BeanTraderCallback callbackHandler) 41 | { 42 | DialogCoordinator = dialogCoordinator; 43 | TradingService = tradingService; 44 | CallbackHandler = callbackHandler; 45 | StatusClearTimer = new Timer(ClearStatus); 46 | traderNames = new ConcurrentDictionary(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/README.md: -------------------------------------------------------------------------------- 1 | # Bean Trader 2 | 3 | ## About the App 4 | 5 | This sample application is used to demonstrate migrating a WPF app to .NET Core. It is a simple client for an Azure-hosted service which allows users to propose and complete trades for different colors of virtual beans. To keep the sample simple, there is no authentication (as that would require user management). Instead, users may log in by simply providing a user name and users who don't yet exist will be created automatically. 6 | 7 | This app is not meant to demonstrate WPF best practices (in fact, some of the code is intentionally not optimal to demonstrate migration challenges). Instead, the sample is meant to illustrate common migration challenges. 8 | 9 | ## Directory Contents 10 | 11 | The BeanTrader solution is comprised of three projects: 12 | 13 | * BeanTraderServer is the backend WCF service (console app) that keeps track of outstanding trade offers and user bean counts. 14 | * BeanTraderInterfaces contains the service interfaces that BeanTraderServer implements. 15 | * BeanTraderClient is the front-end WPF application that enables users to interact with the backend service. Although it obviously depends on the backend service to be available at runtime, this project has no build-time dependency on either of the other services. If you are only interested in seeing (and maybe porting) the WPF app, this is the only portion of the sample you need to concern yourself with. 16 | 17 | ## Building and Running the Sample 18 | 19 | Building the sample is as easy as using MSBuild to compile the solution (or project) and running the sample only requires launching the generated app (though the app's config file may need updated to point at a valid backend server). To make testing the WPF app easier, an instance of the BeanTrader backend service is running in Azure at net.tcp://beantrader.eastus.cloudapp.azure.com:8090/BeanTraderService, though this may not always be available in the future. 20 | 21 | If you wish to run against a local backend service (or if the Azure service is unavailable in the future), simply run the BeanTraderServer project prior to launching the client and update App.Config to refer to `localhost` in place of `beantrader.eastus.cloudapp.azure.com`. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Windows Desktop Application Modernization Guidance 2 | 3 | This repo contains information to help you modernize your .NET desktop applications. We are prioriizing the following *high level* topics to document and provide samples, but feel free to suggest new topics in our [issues](https://github.com/dotnet/windows-desktop/issues) section. 4 | 5 | ### Porting WPF and WinForms apps to .NET Core 3 6 | 7 | Samples, options, tips and tricks to convert WPF and WinForms projects based on .NET Framework to .NET Core 3. 8 | 9 | - [How to: Port a Windows Forms desktop app to .NET Core](https://docs.microsoft.com/en-us/dotnet/core/porting/winforms) 10 | - [How to: Port a WPF desktop app to .NET Core](https://docs.microsoft.com/en-us/dotnet/core/porting/wpf) 11 | 12 | 13 | ### Using Windows 10 features in WPF and WinForms apps 14 | 15 | Windows 10 include a number of APIs that are accessible from Windows 10 SDKs. You can use these APIs in .NET apps by using the Microsoft.Windows.SDK.Contracts NuGet package. [More information](/docs/win10apis/README.md) 16 | 17 | ### Data Access 18 | 19 | ADO.NET can be used in .NET Core 3 applications, however not all data source providers are available. 20 | 21 | We have plans to support Entity Framework 6 in .NET Core, and Entity Framework Core is already supported. 22 | 23 | Other non-relational data stores (such as CosmosDB) are also available to .NET Core. 24 | 25 | ### Connecting to Services 26 | 27 | WCF has been partially ported to .NET Core 3; however, there is no support for WCF server. WCF clients features are documented here. Additional services that support .NET Core will be included as well. 28 | 29 | ### Deployment 30 | 31 | .NET Desktop applications can be deployed with [MSIX](https://docs.microsoft.com/windows/msix/). To create MSIX packages you can use the [Windows Application Packaging Project](https://aka.ms/wapproj) available in Visual Studio 2019. 32 | 33 | >Note: To package .NET Core 3 applications you must use Visual Studio 2019 Update 1 Preview or later. 34 | 35 | ### Known issues 36 | 37 | - AppDomains 38 | - Remoting 39 | - WCF Server 40 | - WCF Client supported features 41 | - Non-String Resources 42 | 43 | 44 | ## Samples 45 | 46 | - BeanTraders 47 | - WPF Concepts 48 | - Memory Game 49 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetCore/BeanTraderClient/DesignTimeData/DesignTimeContexts.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using BeanTraderClient.ViewModels; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Windows.Media; 6 | 7 | namespace BeanTraderClient.DesignTimeData 8 | { 9 | public static class DesignTimeContexts 10 | { 11 | public static TradingViewModel DesignTimeTradingViewModel => 12 | new TradingViewModel(null, null, null) 13 | { 14 | CurrentTrader = new Trader 15 | { 16 | Name = "Test User", 17 | Id = Guid.Empty, 18 | Inventory = new[] { 100, 50, 10, 1 } 19 | }, 20 | TradeOffers = new List 21 | { 22 | new TradeOffer 23 | { 24 | Id = Guid.Empty, 25 | SellerId = Guid.Empty, 26 | Asking = new Dictionary 27 | { 28 | { Beans.Red, 5 }, 29 | { Beans.Blue, 5 } 30 | }, 31 | Offering = new Dictionary 32 | { 33 | { Beans.Yellow, 1 } 34 | } 35 | }, 36 | new TradeOffer 37 | { 38 | Id = Guid.Empty, 39 | SellerId = Guid.Empty, 40 | Asking = new Dictionary 41 | { 42 | { Beans.Green, 20 } 43 | }, 44 | Offering = new Dictionary 45 | { 46 | { Beans.Red, 10 }, 47 | { Beans.Yellow, 1 }, 48 | { Beans.Blue, 5 }, 49 | { Beans.Green, 10 } 50 | } 51 | } 52 | }, 53 | StatusText = "Test message", 54 | StatusBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)) 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTrader.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28407.52 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeanTraderServer", "BeanTraderServer\BeanTraderServer.csproj", "{C7FE70DF-EF5A-4FED-91BE-9F6488C17135}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeanTraderClient", "BeanTraderClient\BeanTraderClient.csproj", "{995E758F-D656-4D2C-B679-69B81E58672F}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeanTraderCommon", "BeanTraderInterfaces\BeanTraderCommon.csproj", "{41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {995E758F-D656-4D2C-B679-69B81E58672F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {995E758F-D656-4D2C-B679-69B81E58672F}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {995E758F-D656-4D2C-B679-69B81E58672F}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {995E758F-D656-4D2C-B679-69B81E58672F}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {BCCDA9FB-5EA7-4020-9924-40BC53FB268E} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/DesignTimeData/DesignTimeContexts.cs: -------------------------------------------------------------------------------- 1 | using BeanTrader.Models; 2 | using BeanTraderClient.ViewModels; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Windows.Media; 6 | 7 | namespace BeanTraderClient.DesignTimeData 8 | { 9 | public static class DesignTimeContexts 10 | { 11 | public static TradingViewModel DesignTimeTradingViewModel => 12 | new TradingViewModel(null, null, null) 13 | { 14 | CurrentTrader = new Trader 15 | { 16 | Name = "Test User", 17 | Id = Guid.Empty, 18 | Inventory = new[] { 100, 50, 10, 1 } 19 | }, 20 | TradeOffers = new List 21 | { 22 | new TradeOffer 23 | { 24 | Id = Guid.Empty, 25 | SellerId = Guid.Empty, 26 | Asking = new Dictionary 27 | { 28 | { Beans.Red, 5 }, 29 | { Beans.Blue, 5 } 30 | }, 31 | Offering = new Dictionary 32 | { 33 | { Beans.Yellow, 1 } 34 | } 35 | }, 36 | new TradeOffer 37 | { 38 | Id = Guid.Empty, 39 | SellerId = Guid.Empty, 40 | Asking = new Dictionary 41 | { 42 | { Beans.Green, 20 } 43 | }, 44 | Offering = new Dictionary 45 | { 46 | { Beans.Red, 10 }, 47 | { Beans.Yellow, 1 }, 48 | { Beans.Blue, 5 }, 49 | { Beans.Green, 10 } 50 | } 51 | } 52 | }, 53 | StatusText = "Test message", 54 | StatusBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)) 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Samples/BeanTrader/NetFx/BeanTraderClient/Views/WelcomePage.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |