├── 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 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Views/WelcomePage.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/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 | * This directory contains two C# projects after migration - BeanTraderClient.csproj builds for .NET Framework and is useful for using WPF designers in Visual Studio. BeanTraderClient.Core.csproj builds for .NET Core 3.0.
17 |
18 | ## Building and Running the Sample
19 |
20 | Building the sample is as easy as using MSBuild (or the dotnet CLI) 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.
21 |
22 | 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`.
23 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Views/WelcomePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.ServiceModel;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using System.Windows.Navigation;
6 | using Microsoft.Win32;
7 |
8 | namespace BeanTraderClient.Views
9 | {
10 | ///
11 | /// Interaction logic for Welcome.xaml
12 | ///
13 | public partial class WelcomePage : Page
14 | {
15 | private const string BeanTraderClientRegistryKey = @"Software\BeanTraderClient";
16 | private const string PreferredNameRegistryValueName = "PreferredUsername";
17 | private readonly TradingPage tradingPage;
18 |
19 | public WelcomePage(TradingPage tradingPage)
20 | {
21 | InitializeComponent();
22 | this.tradingPage = tradingPage;
23 | }
24 |
25 | private void Page_Loaded(object sender, RoutedEventArgs e)
26 | {
27 | NameTextBox.Text = GetPreferredUserName();
28 | NameTextBox.Focus();
29 | }
30 |
31 | private void StartButton_Click(object sender, RoutedEventArgs e)
32 | {
33 | var userName = NameTextBox.Text;
34 | SetPreferredUserName(userName);
35 |
36 | StartButton.IsEnabled = false;
37 |
38 | // This would be simpler with Task.Run, but I want to
39 | // use APIs that would have been more common in older WPF apps
40 | var worker = new BackgroundWorker();
41 | worker.DoWork += Login;
42 | worker.RunWorkerCompleted += CompleteLogin;
43 | worker.RunWorkerAsync(userName);
44 | }
45 |
46 | private void Login(object sender, DoWorkEventArgs e)
47 | {
48 | tradingPage.Model.UserName = e.Argument as string;
49 | }
50 |
51 | private void CompleteLogin(object sender, RunWorkerCompletedEventArgs e)
52 | {
53 | StartButton.IsEnabled = true;
54 | NavigationService.Navigate(tradingPage);
55 | }
56 |
57 | private string GetPreferredUserName()
58 | {
59 | var regKey = Registry.CurrentUser.CreateSubKey(BeanTraderClientRegistryKey);
60 | return regKey.GetValue(PreferredNameRegistryValueName)?.ToString() ?? string.Empty;
61 | }
62 |
63 | private void SetPreferredUserName(string userName)
64 | {
65 | var regKey = Registry.CurrentUser.CreateSubKey(BeanTraderClientRegistryKey);
66 | regKey.SetValue(PreferredNameRegistryValueName, userName);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Views/WelcomePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.ServiceModel;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using System.Windows.Navigation;
6 | using Microsoft.Win32;
7 |
8 | namespace BeanTraderClient.Views
9 | {
10 | ///
11 | /// Interaction logic for Welcome.xaml
12 | ///
13 | public partial class WelcomePage : Page
14 | {
15 | private const string BeanTraderClientRegistryKey = @"Software\BeanTraderClient";
16 | private const string PreferredNameRegistryValueName = "PreferredUsername";
17 | private readonly TradingPage tradingPage;
18 |
19 | public WelcomePage(TradingPage tradingPage)
20 | {
21 | InitializeComponent();
22 | this.tradingPage = tradingPage;
23 | }
24 |
25 | private void Page_Loaded(object sender, RoutedEventArgs e)
26 | {
27 | NameTextBox.Text = GetPreferredUserName();
28 | NameTextBox.Focus();
29 | }
30 |
31 | private void StartButton_Click(object sender, RoutedEventArgs e)
32 | {
33 | var userName = NameTextBox.Text;
34 | SetPreferredUserName(userName);
35 |
36 | StartButton.IsEnabled = false;
37 |
38 | // This would be simpler with Task.Run, but I want to
39 | // use APIs that would have been more common in older WPF apps
40 | var worker = new BackgroundWorker();
41 | worker.DoWork += Login;
42 | worker.RunWorkerCompleted += CompleteLogin;
43 | worker.RunWorkerAsync(userName);
44 | }
45 |
46 | private void Login(object sender, DoWorkEventArgs e)
47 | {
48 | tradingPage.Model.UserName = e.Argument as string;
49 | }
50 |
51 | private void CompleteLogin(object sender, RunWorkerCompletedEventArgs e)
52 | {
53 | StartButton.IsEnabled = true;
54 | NavigationService.Navigate(tradingPage);
55 | }
56 |
57 | private string GetPreferredUserName()
58 | {
59 | var regKey = Registry.CurrentUser.CreateSubKey(BeanTraderClientRegistryKey);
60 | return regKey.GetValue(PreferredNameRegistryValueName)?.ToString() ?? string.Empty;
61 | }
62 |
63 | private void SetPreferredUserName(string userName)
64 | {
65 | var regKey = Registry.CurrentUser.CreateSubKey(BeanTraderClientRegistryKey);
66 | regKey.SetValue(PreferredNameRegistryValueName, userName);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.InteropServices;
4 | using System.Windows;
5 |
6 | // Choose neutral resource language culture
7 | [assembly: NeutralResourcesLanguageAttribute("en")]
8 |
9 | // General Information about an assembly is controlled through the following
10 | // set of attributes. Change these attribute values to modify the information
11 | // associated with an assembly.
12 | [assembly: AssemblyTitle("BeanTraderClient")]
13 | [assembly: AssemblyDescription("")]
14 | [assembly: AssemblyConfiguration("")]
15 | [assembly: AssemblyCompany("")]
16 | [assembly: AssemblyProduct("BeanTraderClient")]
17 | [assembly: AssemblyCopyright("Copyright © 2019")]
18 | [assembly: AssemblyTrademark("")]
19 | [assembly: AssemblyCulture("")]
20 |
21 | // Setting ComVisible to false makes the types in this assembly not visible
22 | // to COM components. If you need to access a type in this assembly from
23 | // COM, set the ComVisible attribute to true on that type.
24 | [assembly: ComVisible(false)]
25 |
26 | //In order to begin building localizable applications, set
27 | //CultureYouAreCodingWith in your .csproj file
28 | //inside a . For example, if you are using US english
29 | //in your source files, set the to en-US. Then uncomment
30 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
31 | //the line below to match the UICulture setting in the project file.
32 |
33 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
34 |
35 |
36 | [assembly: ThemeInfo(
37 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
38 | //(used if a resource is not found in the page,
39 | // or application resource dictionaries)
40 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
41 | //(used if a resource is not found in the page,
42 | // app, or any theme specific resource dictionaries)
43 | )]
44 |
45 |
46 | // Version information for an assembly consists of the following four values:
47 | //
48 | // Major Version
49 | // Minor Version
50 | // Build Number
51 | // Revision
52 | //
53 | // You can specify all the values or you can default the Build and Revision Numbers
54 | // by using the '*' as shown below:
55 | // [assembly: AssemblyVersion("1.0.*")]
56 | [assembly: AssemblyVersion("1.0.0.0")]
57 | [assembly: AssemblyFileVersion("1.0.0.0")]
58 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.InteropServices;
4 | using System.Windows;
5 |
6 | // Choose neutral resource language culture
7 | [assembly: NeutralResourcesLanguageAttribute("en")]
8 |
9 | // General Information about an assembly is controlled through the following
10 | // set of attributes. Change these attribute values to modify the information
11 | // associated with an assembly.
12 | [assembly: AssemblyTitle("BeanTraderClient")]
13 | [assembly: AssemblyDescription("")]
14 | [assembly: AssemblyConfiguration("")]
15 | [assembly: AssemblyCompany("")]
16 | [assembly: AssemblyProduct("BeanTraderClient")]
17 | [assembly: AssemblyCopyright("Copyright © 2019")]
18 | [assembly: AssemblyTrademark("")]
19 | [assembly: AssemblyCulture("")]
20 |
21 | // Setting ComVisible to false makes the types in this assembly not visible
22 | // to COM components. If you need to access a type in this assembly from
23 | // COM, set the ComVisible attribute to true on that type.
24 | [assembly: ComVisible(false)]
25 |
26 | //In order to begin building localizable applications, set
27 | //CultureYouAreCodingWith in your .csproj file
28 | //inside a . For example, if you are using US english
29 | //in your source files, set the to en-US. Then uncomment
30 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
31 | //the line below to match the UICulture setting in the project file.
32 |
33 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
34 |
35 |
36 | [assembly: ThemeInfo(
37 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
38 | //(used if a resource is not found in the page,
39 | // or application resource dictionaries)
40 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
41 | //(used if a resource is not found in the page,
42 | // app, or any theme specific resource dictionaries)
43 | )]
44 |
45 |
46 | // Version information for an assembly consists of the following four values:
47 | //
48 | // Major Version
49 | // Minor Version
50 | // Build Number
51 | // Revision
52 | //
53 | // You can specify all the values or you can default the Build and Revision Numbers
54 | // by using the '*' as shown below:
55 | // [assembly: AssemblyVersion("1.0.*")]
56 | [assembly: AssemblyVersion("1.0.0.0")]
57 | [assembly: AssemblyFileVersion("1.0.0.0")]
58 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderInterfaces/BeanTraderCommon.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}
8 | Library
9 | Properties
10 | BeanTraderInterfaces
11 | BeanTraderInterfaces
12 | v4.7.2
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderInterfaces/BeanTraderCommon.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}
8 | Library
9 | Properties
10 | BeanTraderInterfaces
11 | BeanTraderInterfaces
12 | v4.7.2
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Samples/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/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 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeanTraderClient.Core", "BeanTraderClient\BeanTraderClient.Core.csproj", "{2AECFB26-B510-46D0-91BC-790A9215767E}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1146285B-A501-4031-93B8-13EA921CC2C3}"
15 | ProjectSection(SolutionItems) = preProject
16 | BeanTraderClient\Directory.Build.Props = BeanTraderClient\Directory.Build.Props
17 | EndProjectSection
18 | EndProject
19 | Global
20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
21 | Debug|Any CPU = Debug|Any CPU
22 | Release|Any CPU = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
25 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {995E758F-D656-4D2C-B679-69B81E58672F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {995E758F-D656-4D2C-B679-69B81E58672F}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {995E758F-D656-4D2C-B679-69B81E58672F}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {995E758F-D656-4D2C-B679-69B81E58672F}.Release|Any CPU.Build.0 = Release|Any CPU
33 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Debug|Any CPU.Build.0 = Debug|Any CPU
35 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Release|Any CPU.ActiveCfg = Release|Any CPU
36 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}.Release|Any CPU.Build.0 = Release|Any CPU
37 | {2AECFB26-B510-46D0-91BC-790A9215767E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38 | {2AECFB26-B510-46D0-91BC-790A9215767E}.Debug|Any CPU.Build.0 = Debug|Any CPU
39 | {2AECFB26-B510-46D0-91BC-790A9215767E}.Release|Any CPU.ActiveCfg = Release|Any CPU
40 | {2AECFB26-B510-46D0-91BC-790A9215767E}.Release|Any CPU.Build.0 = Release|Any CPU
41 | EndGlobalSection
42 | GlobalSection(SolutionProperties) = preSolution
43 | HideSolutionNode = FALSE
44 | EndGlobalSection
45 | GlobalSection(ExtensibilityGlobals) = postSolution
46 | SolutionGuid = {BCCDA9FB-5EA7-4020-9924-40BC53FB268E}
47 | EndGlobalSection
48 | EndGlobal
49 |
--------------------------------------------------------------------------------
/docs/win10apis/README.md:
--------------------------------------------------------------------------------
1 | # Microsoft.Windows.SDK.Contracts
2 |
3 | The [Microsoft.Windows.SDK.Contracts](https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts) NuGet packages are designed to allow you to quickly and easily add the latest Windows 10 Runtime APIs to your .NET libraries and applications. For the complete list of the APIs, see: [Windows UWP Namespaces](https://docs.microsoft.com/uwp/api/).
4 |
5 | ### Requirements
6 |
7 | The Microsoft.Windows.SDK.Contracts NuGet packages are designed for .NET Framework 4.6+ or .NET Core 3.0 and only support projects configured using [Package Reference](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files) as their package management format.
8 |
9 | ## Getting Started
10 |
11 | ### Step1 : Configure your project to support [Package Reference](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files):
12 |
13 | > [!Information]
14 | > .NET Core and .NET Standard projects already use the `PackageReference` format
15 |
16 | #### New Projects
17 |
18 | For new projects, follow these steps to configure **NuGet Settings** in Visual Studio 2017 or Visual Studio 2019 to default to PackageReference:
19 |
20 | 1. From the Tools menu of Visual Studio, choose **NuGet Package Manager -> Package Manager Settings**.
21 | 2. Under **Package Management**, make sure the **“Default package management format:”** specifies **PackageReference**.
22 |
23 | #### Existing Projects
24 |
25 | To change an existing project from Packages.Config to use Package Reference in VS2017, right-click on the Packages.config file and choose
26 | **Migrate packages.config to Package Reference...** For more information refer to [Migrate packages config to package reference](https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference).
27 |
28 | ### Step 2: Add the Microsoft.Windows.SDK.Contracts NuGet package to your project
29 |
30 | 1. Open the [NuGet Package Manager Console](https://docs.microsoft.com/nuget/tools/package-manager-console)
31 | 2. Install the package that includes the Windows 10 Contracts you want to target. Currently the following are supported:
32 |
33 |
34 | - Windows 10 version 1803
35 | `Install-Package Microsoft.Windows.SDK.Contracts -Version 10.0.17134.1000-preview`
36 | - Windows 10 version 1809
37 | `Install-Package Microsoft.Windows.SDK.Contracts -Version 10.0.17763.1000-preview`
38 | - Windows 10 version 1903 – preview
39 | `Install-Package Microsoft.Windows.SDK.Contracts -Version 10.0.18362.2002-preview`
40 |
41 |
42 |
43 | ## Get Coding
44 |
45 | If you want to try it out, this sample shows how to access the Geolocation APIs with a button click, and output the values to a text box.
46 |
47 | ```cs
48 | private async void button1_Click_1(object sender, EventArgs e)
49 | {
50 | var locator = new Windows.Devices.Geolocation.Geolocator();
51 | var location = await locator.GetGeopositionAsync();
52 | var position = location.Coordinate.Point.Position;
53 | var latlong = string.Format("lat:{0}, long:{1}", position.Latitude, position.Longitude);
54 | textBox1.Text = latlong;
55 | }
56 | ```
57 | ## Feedback / Contributions
58 | This repo can be used for the reporting of issues found with the Windows SDK NuGet packages.
59 |
60 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderServer/BeanTraderServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}
8 | Exe
9 | BeanTraderServer
10 | BeanTraderServer
11 | v4.7.2
12 | 512
13 | true
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll
38 |
39 |
40 | ..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | PreserveNewest
62 |
63 |
64 |
65 |
66 |
67 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}
68 | BeanTraderCommon
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderServer/BeanTraderServer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {C7FE70DF-EF5A-4FED-91BE-9F6488C17135}
8 | Exe
9 | BeanTraderServer
10 | BeanTraderServer
11 | v4.7.2
12 | 512
13 | true
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\packages\Serilog.2.8.0\lib\net46\Serilog.dll
38 |
39 |
40 | ..\packages\Serilog.Sinks.Console.3.1.1\lib\net45\Serilog.Sinks.Console.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | PreserveNewest
62 |
63 |
64 |
65 |
66 |
67 | {41C7E011-840E-44AB-9B5B-CAF6E7B7DE65}
68 | BeanTraderCommon
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Controls/TradeOfferControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using BeanTrader.Models;
2 | using BeanTraderClient.Resources;
3 | using BeanTraderClient.ViewModels;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 |
7 | namespace BeanTraderClient.Controls
8 | {
9 | ///
10 | /// Interaction logic for TradeOfferControl.xaml
11 | ///
12 | public partial class TradeOfferControl : UserControl
13 | {
14 | public static readonly DependencyProperty TradeOfferProperty =
15 | DependencyProperty.Register("TradeOffer", typeof(TradeOffer), typeof(TradeOfferControl), new PropertyMetadata(new PropertyChangedCallback(UpdateTradeOffer)));
16 |
17 | public static readonly DependencyProperty TradingModelProperty =
18 | DependencyProperty.Register("TradingModel", typeof(TradingViewModel), typeof(TradeOfferControl));
19 |
20 | public static readonly DependencyProperty SellerNameProperty =
21 | DependencyProperty.Register("SellerName", typeof(string), typeof(TradeOfferControl));
22 |
23 | private static async void UpdateTradeOffer(DependencyObject d, DependencyPropertyChangedEventArgs e)
24 | {
25 | // Update these on TradeOffer so that the BeanDictionaries are available for
26 | // data binding without having to construct them each time they're needed
27 | if (e.NewValue is TradeOffer newTradeOffer && d is TradeOfferControl control)
28 | {
29 | control.Offering = new BeanDictionary(newTradeOffer.Offering);
30 | control.Asking = new BeanDictionary(newTradeOffer.Asking);
31 |
32 | // Temporary name while looking up the friendly name
33 | control.SellerName = newTradeOffer.SellerId.ToString();
34 | if (control.TradingModel != null)
35 | {
36 | control.SellerName = await control.TradingModel.GetTraderNameAsync(newTradeOffer.SellerId).ConfigureAwait(true);
37 | }
38 | }
39 | }
40 |
41 |
42 | private async void TradeOfferControl_Loaded(object sender, RoutedEventArgs e)
43 | {
44 | var sellerId = TradeOffer?.SellerId.ToString();
45 |
46 | // If the seller name hasn't been loaded yet, look it up
47 | if (sellerId != null && sellerId == SellerName && TradingModel != null)
48 | {
49 | SellerName = await TradingModel.GetTraderNameAsync(TradeOffer.SellerId).ConfigureAwait(true);
50 | }
51 | }
52 |
53 | public TradeOffer TradeOffer
54 | {
55 | get => (TradeOffer)GetValue(TradeOfferProperty);
56 | set => SetValue(TradeOfferProperty, value);
57 | }
58 |
59 | // Access parent trading model (if any) to allow making trades, etc.
60 | public TradingViewModel TradingModel
61 | {
62 | get => (TradingViewModel)GetValue(TradingModelProperty);
63 | set => SetValue(TradingModelProperty, value);
64 | }
65 |
66 | public string SellerName
67 | {
68 | get => (string)GetValue(SellerNameProperty);
69 | set => SetValue(SellerNameProperty, value);
70 | }
71 |
72 | public BeanDictionary Offering { get; private set; }
73 |
74 | public BeanDictionary Asking { get; private set; }
75 |
76 | public string CompleteTradeDescription =>
77 | TradeOffer?.SellerId == TradingModel?.CurrentTrader.Id ?
78 | StringResources.CancelTradeDescription :
79 | StringResources.AcceptTradeDescription;
80 |
81 | public TradeOfferControl()
82 | {
83 | InitializeComponent();
84 |
85 | // Set LayoutRoot's data context so that data binding within this
86 | // control uses this object as the context but data binding by
87 | // this control's users won't have their context's changed.
88 | LayoutRoot.DataContext = this;
89 | }
90 |
91 | private async void CompleteTradeButton_Click(object sender, RoutedEventArgs e)
92 | {
93 | CompleteTradeButton.IsEnabled = false;
94 | if (!await (TradingModel?.CompleteTrade(TradeOffer)).ConfigureAwait(true))
95 | {
96 | CompleteTradeButton.IsEnabled = true;
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Controls/TradeOfferControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using BeanTrader.Models;
2 | using BeanTraderClient.Resources;
3 | using BeanTraderClient.ViewModels;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 |
7 | namespace BeanTraderClient.Controls
8 | {
9 | ///
10 | /// Interaction logic for TradeOfferControl.xaml
11 | ///
12 | public partial class TradeOfferControl : UserControl
13 | {
14 | public static readonly DependencyProperty TradeOfferProperty =
15 | DependencyProperty.Register("TradeOffer", typeof(TradeOffer), typeof(TradeOfferControl), new PropertyMetadata(new PropertyChangedCallback(UpdateTradeOffer)));
16 |
17 | public static readonly DependencyProperty TradingModelProperty =
18 | DependencyProperty.Register("TradingModel", typeof(TradingViewModel), typeof(TradeOfferControl));
19 |
20 | public static readonly DependencyProperty SellerNameProperty =
21 | DependencyProperty.Register("SellerName", typeof(string), typeof(TradeOfferControl));
22 |
23 | private static async void UpdateTradeOffer(DependencyObject d, DependencyPropertyChangedEventArgs e)
24 | {
25 | // Update these on TradeOffer so that the BeanDictionaries are available for
26 | // data binding without having to construct them each time they're needed
27 | if (e.NewValue is TradeOffer newTradeOffer && d is TradeOfferControl control)
28 | {
29 | control.Offering = new BeanDictionary(newTradeOffer.Offering);
30 | control.Asking = new BeanDictionary(newTradeOffer.Asking);
31 |
32 | // Temporary name while looking up the friendly name
33 | control.SellerName = newTradeOffer.SellerId.ToString();
34 | if (control.TradingModel != null)
35 | {
36 | control.SellerName = await control.TradingModel.GetTraderNameAsync(newTradeOffer.SellerId).ConfigureAwait(true);
37 | }
38 | }
39 | }
40 |
41 |
42 | private async void TradeOfferControl_Loaded(object sender, RoutedEventArgs e)
43 | {
44 | var sellerId = TradeOffer?.SellerId.ToString();
45 |
46 | // If the seller name hasn't been loaded yet, look it up
47 | if (sellerId != null && sellerId == SellerName && TradingModel != null)
48 | {
49 | SellerName = await TradingModel.GetTraderNameAsync(TradeOffer.SellerId).ConfigureAwait(true);
50 | }
51 | }
52 |
53 | public TradeOffer TradeOffer
54 | {
55 | get => (TradeOffer)GetValue(TradeOfferProperty);
56 | set => SetValue(TradeOfferProperty, value);
57 | }
58 |
59 | // Access parent trading model (if any) to allow making trades, etc.
60 | public TradingViewModel TradingModel
61 | {
62 | get => (TradingViewModel)GetValue(TradingModelProperty);
63 | set => SetValue(TradingModelProperty, value);
64 | }
65 |
66 | public string SellerName
67 | {
68 | get => (string)GetValue(SellerNameProperty);
69 | set => SetValue(SellerNameProperty, value);
70 | }
71 |
72 | public BeanDictionary Offering { get; private set; }
73 |
74 | public BeanDictionary Asking { get; private set; }
75 |
76 | public string CompleteTradeDescription =>
77 | TradeOffer?.SellerId == TradingModel?.CurrentTrader.Id ?
78 | StringResources.CancelTradeDescription :
79 | StringResources.AcceptTradeDescription;
80 |
81 | public TradeOfferControl()
82 | {
83 | InitializeComponent();
84 |
85 | // Set LayoutRoot's data context so that data binding within this
86 | // control uses this object as the context but data binding by
87 | // this control's users won't have their context's changed.
88 | LayoutRoot.DataContext = this;
89 | }
90 |
91 | private async void CompleteTradeButton_Click(object sender, RoutedEventArgs e)
92 | {
93 | CompleteTradeButton.IsEnabled = false;
94 | if (!await (TradingModel?.CompleteTrade(TradeOffer)).ConfigureAwait(true))
95 | {
96 | CompleteTradeButton.IsEnabled = true;
97 | }
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/README.md:
--------------------------------------------------------------------------------
1 | # Bean Trader Demo App
2 |
3 | Bean Trader is a sample app used to demonstrate porting a .NET Framework WPF app to .NET Core 3.
4 |
5 | The app is designed to be simple to port while using some interesting functionality, representative of real-world apps developers are likely to want to port to .NET Core.
6 |
7 | The app makes use of:
8 |
9 | * WCF client APIs
10 | * Including a NetTcp duplex binding and cert-secured transport security for communication with an Azure-hosted WCF service.
11 | * [MahApps.Metro](https://mahapps.com/) APIs
12 | * Including custom dialogs and app theming
13 | * Dependency injection with [Castle.Windsor](http://www.castleproject.org/projects/windsor/)
14 | * Azure Key Vault SDK
15 | * Settings retrieved from registry and ConfigurationManager APIs
16 | * Resources and embedded resources (resx files, as well as images and icons)
17 |
18 | 
19 |
20 | ## .NET Core 3 Migration
21 |
22 | The [NetFx](./NetFx) directory contains the .NET Framework app in its original state. The [NetCore](./NetCore) branch contains the solution in its final state after porting the application to .NET Core (while also leaving the .NET Framework project working correctly).
23 |
24 | A full writeup of the migration process is available in the [migration steps](MigrationSteps.md) doc and a [video walkthrough](https://www.youtube.com/watch?v=5MomsgkWkVw&list=PLS__JrkRveTMiWxG-Lv4cBwYfMQ6m2gmt) of the porting process is available on YouTube.
25 |
26 | The general steps to port from .NET Framework to .NET Core include:
27 |
28 | 1. Prepare for migration.
29 | 1. Use the [.NET Portability Analyzer](https://docs.microsoft.com/dotnet/standard/analyzers/portability-analyzer) to understand what .NET Framework APIs the project uses in order to understand where there may be porting challenges.
30 | 1. Review library and NuGet dependencies which may introduce challenges if they do not support .NET Standard or .NET Core.
31 | 1. Migrate the existing project file to reference NuGet packages with [``](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files) syntax instead of using a packages.config file.
32 | 1. Migrate the project file.
33 | 1. Create a new project file either:
34 | 1. Replacing the current project file (which has the drawback of not working with the VS designer)
35 | 1. Next to the existing project file (which has the drawback of needing to address shared output and intermediate output paths)
36 | 1. In a separate directory from the existing project file (which has the drawback of needing to explicitly reference source, xaml, and resx files from the original directory and make sure they have proper paths within the new project using Link attributes)
37 | 1. Update the new project file to have relevant elements from the old project file, such as resources, properties, and project/package references.
38 | 1. Update NuGet package versions to versions supporting .NET Standard or .NET Core.
39 | 1. In some cases, packages won't support .NET Core or .NET Standard and it will be necessary to find alternative packages or use existing .NET Framework-targeted packages and test that relevant code paths work as expected on .NET Core.
40 | 1. Fix source code to work on .NET Core.
41 | 1. API-level differences between .NET Framework and .NET Core APIs will be needed.
42 | 1. Generated code (such as [WCF clients](https://docs.microsoft.com/dotnet/core/additional-tools/wcf-web-service-reference-guide)) may need to be regenerated.
43 | 1. If necessary, be sure that the original project continues to build despite source code changes.
44 | 1. Run and test.
45 | 1. Beware of NotSupportedExceptions. [Analyzers](https://github.com/dotnet/platform-compat) exist to identify APIs that may fail.
46 | 1. Look for any other differences that manifest at runtime (such as outdated app.config sections).
47 |
48 | ## Useful Links
49 |
50 | * [Intro to .NET Core 3](https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0)
51 | * [.NET Core 3 Migration Guidance](https://github.com/dotnet/samples/tree/master/wpf)
52 | * [.NET Portability Analyzer](https://docs.microsoft.com/dotnet/standard/analyzers/portability-analyzer)
53 | * [Platform Compatibility Analyzers](https://github.com/dotnet/platform-compat)
54 | * [Add WCF clients to .NET Core projects](https://docs.microsoft.com/dotnet/core/additional-tools/wcf-web-service-reference-guide)
55 | * [Bean Trader Migration Video](https://youtu.be/5MomsgkWkVw)
56 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Controls/TradeOfferControl.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Controls/TradeOfferControl.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Views/TradingPage.xaml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Views/TradingPage.xaml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Controls/NewTradeOfferControl.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
59 |
60 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Controls/NewTradeOfferControl.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
59 |
60 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Services/TradingService.cs:
--------------------------------------------------------------------------------
1 | using BeanTrader.Models;
2 | using BeanTraderClient.DependencyInjection;
3 | using Nito.AsyncEx;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Security.Cryptography.X509Certificates;
8 | using System.ServiceModel;
9 | using System.ServiceModel.Security;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 | using System.Windows;
13 |
14 | namespace BeanTraderClient.Services
15 | {
16 | public sealed class TradingService : IDisposable
17 | {
18 | private readonly AsyncLock clientSyncLock = new AsyncLock();
19 | private BeanTraderServiceClient client;
20 |
21 | private CancellationTokenSource CancellationSource { get; }
22 | private BeanTraderServiceClientFactory ClientFactory { get; }
23 |
24 | private async Task GetOrOpenClientAsync()
25 | {
26 | // If the client does not exist or is in a bad state, re-create it
27 | if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted)
28 | {
29 | try
30 | {
31 | using (await clientSyncLock.LockAsync())
32 | {
33 | if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted)
34 | {
35 | var newClient = ClientFactory.GetServiceClient();
36 | SetClientCredentials(newClient);
37 | newClient.Open();
38 | client = newClient;
39 | }
40 | }
41 |
42 | Connected?.Invoke();
43 | }
44 | catch (EndpointNotFoundException)
45 | {
46 | MessageBox.Show("Failed to connect to Bean Trader service. Make sure BeanTraderServer.exe is running");
47 | throw;
48 | }
49 | }
50 |
51 | return client;
52 | }
53 |
54 | // Used by callers to be notified when the BeanTraderService connection is (re)-established
55 | // If the connection was dropped, callers may want to use this event to be notified
56 | // that they should query for any data that may have been missed while disconnected.
57 | public event Func Connected;
58 |
59 | public TradingService(BeanTraderServiceClientFactory clientFactory)
60 | {
61 | ClientFactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory));
62 | CancellationSource = new CancellationTokenSource();
63 |
64 | // Begin monitoring the connection for faults or disconnects
65 | Task.Run(() => CheckForHeartbeatAsync(CancellationSource.Token));
66 | }
67 |
68 | public Task AcceptTradeAsync(Guid id) =>
69 | SafeServiceCallAsync(async () =>
70 | {
71 | var client = await GetOrOpenClientAsync();
72 | return await client.AcceptTradeAsync(id);
73 | });
74 |
75 | public Task CancelTradeOfferAsync(Guid id) =>
76 | SafeServiceCallAsync(async () =>
77 | {
78 | var client = await GetOrOpenClientAsync();
79 | return await client.CancelTradeOfferAsync(id);
80 | });
81 |
82 | public Task GetCurrentTraderInfoAsync() =>
83 | SafeServiceCallAsync(async () =>
84 | {
85 | var client = await GetOrOpenClientAsync();
86 | return await client.GetCurrentTraderInfoAsync();
87 | });
88 |
89 | public Task> GetTraderNamesAsync(Guid[] ids) =>
90 | SafeServiceCallAsync(async () =>
91 | {
92 | var client = await GetOrOpenClientAsync();
93 | return await client.GetTraderNamesAsync(ids);
94 | });
95 |
96 | public Task ListenForTradeOffersAsync() =>
97 | SafeServiceCallAsync(async () =>
98 | {
99 | var client = await GetOrOpenClientAsync();
100 | return await client.ListenForTradeOffersAsync();
101 | });
102 |
103 | public Task LoginAsync(string name) =>
104 | SafeServiceCallAsync(async () =>
105 | {
106 | var client = await GetOrOpenClientAsync();
107 | await client.LoginAsync(name);
108 | });
109 |
110 | public Task LogoutAsync() =>
111 | SafeServiceCallAsync(async () =>
112 | {
113 | var client = await GetOrOpenClientAsync();
114 | await client.LogoutAsync();
115 | });
116 |
117 | public Task OfferTradeAsync(TradeOffer trade) =>
118 | SafeServiceCallAsync(async () =>
119 | {
120 | var client = await GetOrOpenClientAsync();
121 | return await client.OfferTradeAsync(trade);
122 | });
123 |
124 | public Task StopListeningAsync() =>
125 | SafeServiceCallAsync(async () =>
126 | {
127 | var client = await GetOrOpenClientAsync();
128 | await client.StopListeningAsync();
129 | });
130 |
131 | private async Task CheckForHeartbeatAsync(CancellationToken ct)
132 | {
133 | var emptyInput = Array.Empty();
134 | while (!ct.IsCancellationRequested)
135 | {
136 | try
137 | {
138 | await GetTraderNamesAsync(emptyInput).ConfigureAwait(false);
139 | await Task.Delay(5000, ct).ConfigureAwait(false);
140 | }
141 | catch (OperationCanceledException) { }
142 | }
143 | }
144 |
145 | private async Task SafeServiceCallAsync(Func> action)
146 | {
147 | try
148 | {
149 | return await action().ConfigureAwait(false);
150 | }
151 | catch (CommunicationException)
152 | {
153 | client?.Abort();
154 | client = null;
155 | return default;
156 | }
157 | }
158 |
159 | private async Task SafeServiceCallAsync(Func action)
160 | {
161 | try
162 | {
163 | await action().ConfigureAwait(false);
164 | }
165 | catch (CommunicationException)
166 | {
167 | client?.Abort();
168 | client = null;
169 | }
170 | }
171 |
172 | private static void SetClientCredentials(BeanTraderServiceClient client)
173 | {
174 | client.ClientCredentials.ClientCertificate.Certificate = GetCertificate();
175 | client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
176 | }
177 |
178 | private static X509Certificate2 GetCertificate()
179 | {
180 | var certPath = Path.Combine(Path.GetDirectoryName(typeof(TradingService).Assembly.Location), "BeanTrader.pfx");
181 | return new X509Certificate2(certPath, "password");
182 | }
183 |
184 | public void Dispose()
185 | {
186 | CancellationSource.Cancel();
187 | try
188 | {
189 | client?.Close();
190 | }
191 | catch (CommunicationException)
192 | {
193 | client?.Abort();
194 | }
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/StringResources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Accept Trade
122 |
123 |
124 | A .NET Core 3 WPF Sample
125 |
126 |
127 | Bean Trader
128 |
129 |
130 | Asking
131 |
132 |
133 | Cancel
134 |
135 |
136 | Cancel Trade
137 |
138 |
139 | Create
140 |
141 |
142 | Signing in...
143 |
144 |
145 | Welcome, {0}
146 |
147 |
148 | Start
149 |
150 |
151 | Sign out
152 |
153 |
154 | New trade
155 |
156 |
157 | New Trade Offer
158 |
159 |
160 | Offering
161 |
162 |
163 | Name
164 |
165 |
166 | Choose a user name to get started
167 |
168 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetFx/BeanTraderClient/Resources/StringResources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Accept Trade
122 |
123 |
124 | A .NET Core 3 WPF Sample
125 |
126 |
127 | Bean Trader
128 |
129 |
130 | Asking
131 |
132 |
133 | Cancel
134 |
135 |
136 | Cancel Trade
137 |
138 |
139 | Create
140 |
141 |
142 | Signing in...
143 |
144 |
145 | Welcome, {0}
146 |
147 |
148 | Start
149 |
150 |
151 | Sign out
152 |
153 |
154 | New trade
155 |
156 |
157 | New Trade Offer
158 |
159 |
160 | Offering
161 |
162 |
163 | Name
164 |
165 |
166 | Choose a user name to get started
167 |
168 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Services/TradingService.cs:
--------------------------------------------------------------------------------
1 | using BeanTrader.Models;
2 | using BeanTraderClient.DependencyInjection;
3 | using Nito.AsyncEx;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Security.Cryptography.X509Certificates;
8 | using System.ServiceModel;
9 | using System.ServiceModel.Security;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 | using System.Windows;
13 |
14 | namespace BeanTraderClient.Services
15 | {
16 | public sealed class TradingService : IDisposable
17 | {
18 | private readonly AsyncLock clientSyncLock = new AsyncLock();
19 | private BeanTraderServiceClient client;
20 |
21 | private CancellationTokenSource CancellationSource { get; }
22 | private BeanTraderServiceClientFactory ClientFactory { get; }
23 |
24 | private async Task GetOrOpenClientAsync()
25 | {
26 | // If the client does not exist or is in a bad state, re-create it
27 | if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted)
28 | {
29 | try
30 | {
31 | using (await clientSyncLock.LockAsync())
32 | {
33 | if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted)
34 | {
35 | var newClient = ClientFactory.GetServiceClient();
36 | SetClientCredentials(newClient);
37 | #if NETCOREAPP
38 | await newClient.OpenAsync().ConfigureAwait(false);
39 | #else
40 | newClient.Open();
41 | #endif // NETCOREAPP
42 | client = newClient;
43 | }
44 | }
45 |
46 | Connected?.Invoke();
47 | }
48 | catch (EndpointNotFoundException)
49 | {
50 | MessageBox.Show("Failed to connect to Bean Trader service. Make sure BeanTraderServer.exe is running");
51 | throw;
52 | }
53 | }
54 |
55 | return client;
56 | }
57 |
58 | // Used by callers to be notified when the BeanTraderService connection is (re)-established
59 | // If the connection was dropped, callers may want to use this event to be notified
60 | // that they should query for any data that may have been missed while disconnected.
61 | public event Func Connected;
62 |
63 | public TradingService(BeanTraderServiceClientFactory clientFactory)
64 | {
65 | ClientFactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory));
66 | CancellationSource = new CancellationTokenSource();
67 |
68 | // Begin monitoring the connection for faults or disconnects
69 | Task.Run(() => CheckForHeartbeatAsync(CancellationSource.Token));
70 | }
71 |
72 | public Task AcceptTradeAsync(Guid id) =>
73 | SafeServiceCallAsync(async () =>
74 | {
75 | var client = await GetOrOpenClientAsync();
76 | return await client.AcceptTradeAsync(id);
77 | });
78 |
79 | public Task CancelTradeOfferAsync(Guid id) =>
80 | SafeServiceCallAsync(async () =>
81 | {
82 | var client = await GetOrOpenClientAsync();
83 | return await client.CancelTradeOfferAsync(id);
84 | });
85 |
86 | public Task GetCurrentTraderInfoAsync() =>
87 | SafeServiceCallAsync(async () =>
88 | {
89 | var client = await GetOrOpenClientAsync();
90 | return await client.GetCurrentTraderInfoAsync();
91 | });
92 |
93 | public Task> GetTraderNamesAsync(Guid[] ids) =>
94 | SafeServiceCallAsync(async () =>
95 | {
96 | var client = await GetOrOpenClientAsync();
97 | return await client.GetTraderNamesAsync(ids);
98 | });
99 |
100 | public Task ListenForTradeOffersAsync() =>
101 | SafeServiceCallAsync(async () =>
102 | {
103 | var client = await GetOrOpenClientAsync();
104 | return await client.ListenForTradeOffersAsync();
105 | });
106 |
107 | public Task LoginAsync(string name) =>
108 | SafeServiceCallAsync(async () =>
109 | {
110 | var client = await GetOrOpenClientAsync();
111 | await client.LoginAsync(name);
112 | });
113 |
114 | public Task LogoutAsync() =>
115 | SafeServiceCallAsync(async () =>
116 | {
117 | var client = await GetOrOpenClientAsync();
118 | await client.LogoutAsync();
119 | });
120 |
121 | public Task OfferTradeAsync(TradeOffer trade) =>
122 | SafeServiceCallAsync(async () =>
123 | {
124 | var client = await GetOrOpenClientAsync();
125 | return await client.OfferTradeAsync(trade);
126 | });
127 |
128 | public Task StopListeningAsync() =>
129 | SafeServiceCallAsync(async () =>
130 | {
131 | var client = await GetOrOpenClientAsync();
132 | await client.StopListeningAsync();
133 | });
134 |
135 | private async Task CheckForHeartbeatAsync(CancellationToken ct)
136 | {
137 | var emptyInput = Array.Empty();
138 | while (!ct.IsCancellationRequested)
139 | {
140 | try
141 | {
142 | await GetTraderNamesAsync(emptyInput).ConfigureAwait(false);
143 | await Task.Delay(5000, ct).ConfigureAwait(false);
144 | }
145 | catch (OperationCanceledException) { }
146 | }
147 | }
148 |
149 | private async Task SafeServiceCallAsync(Func> action)
150 | {
151 | try
152 | {
153 | return await action().ConfigureAwait(false);
154 | }
155 | catch (CommunicationException)
156 | {
157 | client?.Abort();
158 | client = null;
159 | return default;
160 | }
161 | }
162 |
163 | private async Task SafeServiceCallAsync(Func action)
164 | {
165 | try
166 | {
167 | await action().ConfigureAwait(false);
168 | }
169 | catch (CommunicationException)
170 | {
171 | client?.Abort();
172 | client = null;
173 | }
174 | }
175 |
176 | private static void SetClientCredentials(BeanTraderServiceClient client)
177 | {
178 | client.ClientCredentials.ClientCertificate.Certificate = GetCertificate();
179 | client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
180 | }
181 |
182 | // For demo purposes, just load the key from disk so that no one needs to install an untrustworthy self-signed cert
183 | // or load from KeyVault (which would complicate the sample)
184 | private static X509Certificate2 GetCertificate()
185 | {
186 | var certPath = Path.Combine(Path.GetDirectoryName(typeof(TradingService).Assembly.Location), "BeanTrader.pfx");
187 | return new X509Certificate2(certPath, "password");
188 | }
189 |
190 | public void Dispose()
191 | {
192 | CancellationSource.Cancel();
193 | try
194 | {
195 | client?.Close();
196 | }
197 | catch (CommunicationException)
198 | {
199 | client?.Abort();
200 | }
201 | }
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/Samples/BeanTrader/NetCore/BeanTraderClient/Resources/StringResources.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.Resources {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class StringResources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal StringResources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BeanTraderClient.Resources.StringResources", typeof(StringResources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to Accept Trade.
65 | ///
66 | public static string AcceptTradeDescription {
67 | get {
68 | return ResourceManager.GetString("AcceptTradeDescription", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to A .NET Core 3 WPF Sample.
74 | ///
75 | public static string ApplicationSubtitle {
76 | get {
77 | return ResourceManager.GetString("ApplicationSubtitle", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Bean Trader.
83 | ///
84 | public static string ApplicationTitle {
85 | get {
86 | return ResourceManager.GetString("ApplicationTitle", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to Asking.
92 | ///
93 | public static string Asking {
94 | get {
95 | return ResourceManager.GetString("Asking", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// Looks up a localized string similar to Cancel.
101 | ///
102 | public static string Cancel {
103 | get {
104 | return ResourceManager.GetString("Cancel", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// Looks up a localized string similar to Cancel Trade.
110 | ///
111 | public static string CancelTradeDescription {
112 | get {
113 | return ResourceManager.GetString("CancelTradeDescription", resourceCulture);
114 | }
115 | }
116 |
117 | ///
118 | /// Looks up a localized string similar to Create.
119 | ///
120 | public static string Create {
121 | get {
122 | return ResourceManager.GetString("Create", resourceCulture);
123 | }
124 | }
125 |
126 | ///
127 | /// Looks up a localized string similar to Signing in....
128 | ///
129 | public static string DefaultGreeting {
130 | get {
131 | return ResourceManager.GetString("DefaultGreeting", resourceCulture);
132 | }
133 | }
134 |
135 | ///
136 | /// Looks up a localized string similar to Welcome, {0}.
137 | ///
138 | public static string Greeting {
139 | get {
140 | return ResourceManager.GetString("Greeting", resourceCulture);
141 | }
142 | }
143 |
144 | ///
145 | /// Looks up a localized string similar to Start.
146 | ///
147 | public static string Login {
148 | get {
149 | return ResourceManager.GetString("Login", resourceCulture);
150 | }
151 | }
152 |
153 | ///
154 | /// Looks up a localized string similar to Sign out.
155 | ///
156 | public static string Logout {
157 | get {
158 | return ResourceManager.GetString("Logout", resourceCulture);
159 | }
160 | }
161 |
162 | ///
163 | /// Looks up a localized string similar to New trade.
164 | ///
165 | public static string NewTradeOffer {
166 | get {
167 | return ResourceManager.GetString("NewTradeOffer", resourceCulture);
168 | }
169 | }
170 |
171 | ///
172 | /// Looks up a localized string similar to New Trade Offer.
173 | ///
174 | public static string NewTradeOfferTitle {
175 | get {
176 | return ResourceManager.GetString("NewTradeOfferTitle", resourceCulture);
177 | }
178 | }
179 |
180 | ///
181 | /// Looks up a localized string similar to Offering.
182 | ///
183 | public static string Offering {
184 | get {
185 | return ResourceManager.GetString("Offering", resourceCulture);
186 | }
187 | }
188 |
189 | ///
190 | /// Looks up a localized string similar to Name.
191 | ///
192 | public static string UsernameLabel {
193 | get {
194 | return ResourceManager.GetString("UsernameLabel", resourceCulture);
195 | }
196 | }
197 |
198 | ///
199 | /// Looks up a localized string similar to Choose a user name to get started.
200 | ///
201 | public static string UsernamePrompt {
202 | get {
203 | return ResourceManager.GetString("UsernamePrompt", resourceCulture);
204 | }
205 | }
206 | }
207 | }
208 |
--------------------------------------------------------------------------------