12.01 Auxiliary C# Classes (WPF)
-
Before generating the user interface for the very first View, all auxiliary interfaces, enums, helper classes, services, custom user controls must be in place and ready for use. The list of auxiliary files includes "Home", "Page not found", "Access Denied", "Paginator" user controls, global settings service, declaration of some global routed events and routed commands and so on.
-
It’s time to note that the order of generated files is extremely important. For instance, some classes may reference others. It means that referenced files must be generated before referencing files. And this is why CS2WPF Forms project file is used by the Wizards. The information about each generated file (file type, file name, file place and so on) is saved into CS2WPF Forms project file.
-
The second point relates to script types. All scripts are divided into two large sets:
- The first one consists of the context level scripts. These scripts are used to generate interfaces, classes, services that are used across the Views and application level components.
- The second set consists of the View level scripts. They are scripts that are used to generate the code for the given view. For instance, Edit form for one View is not applicable for another one because of captions, validations and so on.
-
These two large sets are organized as follows:
- Scripts with a range of 00000-00999 are context level scripts.
- Scripts with a range of 01000-99999 are view level scripts
-
To Generate AUXILIARY C# classes
- Run Visual Studio and Open “WpfDemo” solution
- Step 1
- Right click "CommonInterfacesClassLibrary"-project node and select "Wpf Form Wizard"-menu
- Click "Next"-button
- Step 2
- Select "Dm02Context"-project
- Select "LitDbContext"-DbContext
- Click "Next"-button
- Step 3
- Select "==context==" in the combo
- Click "Next"-button
- Step 4
- Click "batch processing"-button
- Step 5
- Select "00000-ContextLevelCommonInterfacesBatch.json"-item
- Click "Start"-button
- After generation finished make sure that "Error"-panel is empty
- Close Wizard's dialogs
- Rebuild "ModelInterfacesClassLibrary"-project
- Repeat steps 1-5 for "CommonServicesPrismModule"-project and "00010-ContextLevelCommonServicesModuleBatch.json"
- Repeat steps 1-5 for "CommonWpfCustomControlLibrary"-project and "00020-ContextLevelWpfCustomControlLibraryBatch.json"
- Repeat steps 1-5 for "CommonWpfCustomControlLibrary"-project and "00030-ContextLevelCommonUserControlLibraryBatch.Xamarin.json"
- Repeat steps 1-5 for "CommonServicesPrismModule"-project and "00040-ContextLevelCommonServicesModuleBatch.json"
- Repeat steps 1-5 for "PrismDemoApp"-project and "00050-ContextLevelPrismAppBatch.json"
Open the "CommonServicesPrismModuleModule.cs"-file of CommonServicesPrismModule-project and modify "RegisterTypes()"-method as follows
...
using CommonInterfacesClassLibrary.AppGlblSettingsSrvc;
using CommonServicesPrismModule.AppGlblSettingsSrvc;
using CommonServicesPrismModule.CustomDlgWindows;
using CommonWpfUserControlLibrary.UserControls;
using CommonServicesPrismModule.ViewModels;
using CommonServicesPrismModule.UserControls;
using CommonInterfacesClassLibrary.AppGlblLoginSrvc;
using CommonServicesPrismModule.AppGlblLoginSrvc;
namespace CommonServicesPrismModule
{
public class CommonServicesPrismModuleModule : IModule
{
...
public void RegisterTypes(IContainerRegistry containerRegistry)
{
IAppGlblSettingsService s = new AppGlblSettingsService();
containerRegistry.RegisterInstance<IAppGlblSettingsService>(s);
containerRegistry.RegisterDialogWindow<CustomDlgMediumWindow>();
containerRegistry.RegisterDialogWindow<CustomDlgLargeWindow>("CustomDlgLargeWindow");
containerRegistry.RegisterDialogWindow<CustomDlgMediumWindow>("CustomDlgMediumWindow");
containerRegistry.RegisterDialogWindow<CustomDlgSmallWindow>("CustomDlgSmallWindow");
containerRegistry.RegisterDialog<ColumnSelectorDlgUserControl, ColumnSelectorDlgViewModel>("ColumnSelectorDlg");
containerRegistry.RegisterDialog<MessageDlgUserControl, MessageDlgViewModel>("MessageDlg");
containerRegistry.RegisterForNavigation<HomeUserControl, HomeViewModel>("HomeUserControl");
containerRegistry.RegisterForNavigation<PageNotFoundUserControl, PageNotFoundViewModel>("PageNotFoundUserControl");
containerRegistry.RegisterForNavigation<AccessDeniedUserControl, AccessDeniedViewModel>("AccessDeniedUserControl");
containerRegistry.Register<IAppGlblLoginService, AppGlblLoginService>();
containerRegistry.RegisterForNavigation<RegisterUserControl, RegisterViewModel>("RegisterUserControl");
containerRegistry.RegisterForNavigation<LoginUserControl, LoginViewModel>("LoginUserControl");
containerRegistry.RegisterForNavigation<ChngpswdUserControl, ChngpswdViewModel>("ChngpswdUserControl");
containerRegistry.RegisterForNavigation<LogoutUserControl, LogoutViewModel>("LogoutUserControl");
ViewModelLocationProvider.Register<ScopedRegionNavigationUserControl, ScopedRegionNavigationViewModel>();
containerRegistry.Register<IScopedRegionNavigationUserControlInterface, ScopedRegionNavigationUserControl>();
}
}
}
Open "App.xaml.cs"-file of PrismDemoApp-project and add "CreateModuleCatalog()" and "ConfigureRegionAdapterMappings()" methods as follows
...
using Prism.Regions;
using CommonWpfUserControlLibrary.UserControls;
using PrismDemoApp.Classes;
namespace PrismDemoApp
{
public partial class App
{
...
protected override IModuleCatalog CreateModuleCatalog()
{
return new ConfigurationModuleCatalog();
}
protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
{
base.ConfigureRegionAdapterMappings(regionAdapterMappings);
regionAdapterMappings.RegisterMapping<ProxyUserControl, ProxyUserControlRegionAdapter>();
regionAdapterMappings.RegisterMapping<NavigationProxyUserControl, NavigationProxyUserControlRegionAdapter>();
}
}
}
Open "App.xaml"-file of PrismDemoApp-project and modify as follows
<prism:PrismApplication x:Class="PrismDemoApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
xmlns:local="clr-namespace:PrismDemoApp">
<Application.Resources>
<ResourceDictionary Source="pack://application:,,,/CommonWpfCustomControlLibrary;component/Themes/BasicResourceDictionary.xaml"/>
</Application.Resources>
</prism:PrismApplication>
Add the "App.config"-file to PrismDemoApp-project
Modify "App.config"-file of PrismDemoApp-project as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="modules" type="Prism.Modularity.ModulesConfigurationSection, Prism.Wpf"/>
</configSections>
<modules>
<module assemblyFile="CommonServicesPrismModule.dll"
moduleType="CommonServicesPrismModule.CommonServicesPrismModuleModule, CommonServicesPrismModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
moduleName="CommonServicesPrismModule" startupLoaded="true">
<dependencies>
</dependencies>
</module>
<module assemblyFile="ModelServicesPrismModule.dll"
moduleType="ModelServicesPrismModule.ModelServicesPrismModuleModule, ModelServicesPrismModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
moduleName="ModelServicesPrismModule" startupLoaded="true">
<dependencies>
<dependency moduleName="CommonServicesPrismModule"/>
</dependencies>
</module>
</modules>
</configuration>
Rebuild all front end projects and run PrismDemoApp.
Click "Register"-menu item. Click "Home"-navigation menu again.
Click Dm04WebApp root node to get project properties visible. Copy SSL URL into clipboard.
Open "CommonServicesPrismModule/AppGlblSettingsSrvc/AppGlblSettingsService.cs"-file of the CommonServicesPrismModule-project. Modify GetWebApiPrefix() and GetSecurityWebApiPrefix() by resetting URLs.
...
public string GetWebApiPrefix(string ViewName)
{
string rslt = "";
if(!string.IsNullOrEmpty(ViewName))
{
rslt = "https://localhost:44352/";
}
return rslt;
}
public string GetSecurityWebApiPrefix()
{
return "https://localhost:44352/";
}
...
Install MS SQL Server anywhere in your network or virtual environment. Get "sa"-password, network name of the SQL server and the port (if necessary). Open Web.config-file of Dm04WebApp-project and modify "DefaultConnection"-settings. Here is example:
...
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=SVR2016SQL2017;Initial Catalog=AspNetDm04WebAppSecurity;Persist Security Info=True;User ID=sa;Password=sa_PASSWORD_HERE"
providerName="System.Data.SqlClient" />
</connectionStrings>
...
Note: You will have different "Data Source"-property in your development invoronment.
The front and back ends are ready to register user, login, logout, change password operations.
- Rebuild CommonServicesPrismModule-project
- Run Dm04WebApp
- Run PrismDemoApp
With PrismDemoApp Register new user: "testuser@gmail.com" with a password "Qq?1234". Open MS SQL Management studion and run the script
SELECT * FROM [AspNetDm04WebAppSecurity].[dbo].[AspNetUsers]
The result is on the picture below
For now Login with PrismDemoApp and "testuser@gmail.com" and password "Qq?1234". The result is on the picture below