DevPartner 2018 Workshop : Maximize Your Traditional Synergy Development with Visual Studio
Exercise 5: UI/UX Improvements with .NET API
This is the fifth of a series of exercises that demonstrate the abilities of developing Traditional Synergy inside Visual Studio.
If you have not completed the previous exercises you can find the first one here.
This exercise is going to demonstrate how to build the code to wrap the Synergy .NET API to enhance the UI capabilities of our existing Synergy/DE UI Toolkit application.
To begin the exercise, follow these simple steps:
- Visual Studio should be running and the DevPartner2018 solution opened and active
- From the File menu select Add->New Project…
- In the “Add New Project” dialog locate and expand the Synergy/DE entry and select the Windows entry
- Select the WPF User Control Library entry
- In the Name entry field type the value OnVinylUX
- Click OK
This will create a WPF User Control Library project. After the project is created it will open up the UserControl1.xaml file. Close this window. We can also delete the default source file from the project:
- In the OnVinylUX project locate the UserControl1.xaml source file
- Right-click the UserControl1.xaml file and select Delete
- When prompted select the Delete button
To ensure the correct version of the software is built:
- From the Build menu, select the Configuration Manager… entry
- Against the OnVinylUX entry, under the Platform column, check the value is x64. If not:
- Against the OnVinylUX entry, under the Platform column, change the entry from Any CPU to <New…>
- For the New Platform select x64
- Uncheck the Create new solution platforms checkbox
- Click OK
- Click Close
We are going to add a WPF user control to the project. The files that make up the control are called OnVinylUIControl.xaml and OnVinylUIControl.xaml.dbl. Combined together these files define the new user interface control that we are going to utilize. We are also supplying a simple class to map the Synergy data types to native .NET types and a simple View Model class to provide the bindings between the UI and the data. The required files can be downloaded from here. Download (when prompted by the browser select “open”) and open the zip file and copy the source files to the OnVinylUX project folder you have just created. This folder will be under the DevPartner2018 solution folder.
To add the new WPF user control to the project follow these steps:
- Ensure that the OnVinylUX project is highlighted in the Solution Explorer
- From the Project menu select the Add Existing Item… entry
- At this point check that the dialog title includes the project name “OnVinylUX”. If it does not, cancel the dialog and reselect the OnVinylUX project in the Solution Explorer
- Change the File extensions dropdown list from “Synergy Files” to “All Files”
- Highlight the OnVinylUIControl.xaml, OnVinylUIControl.xaml.dbl, OnVinylMapping.dbc and OnVinylViewModel.dbc files that you placed into the folder
- Click the Add button
This will add the WPF user control to the project.
The next task is to define where our repository structures are to be loaded from. We need to define a reference between our UX Library and our Repository. To define the project reference:
- Ensure that the OnVinylUX is selected in the Solution Explorer
- From the Project menu select the Add Reference… entry
- At this point check that the dialog title includes the project name “OnVinylUX”. If it does not, cancel the dialog and reselect the OnVinylUX project in the Solution Explorer
- Select the Projects tab
- Check the OnVinylRepository
- Click OK
Finally for the OnVinylUX project will be to define a post-build script to copy the built assembly into the correct executable folder:
- Ensure that the OnVinylUX project in the solution explorer is selected
- From the Project menu select the Properties entry. This may also be named OnVinylUX Properties
- At this point check that the tab page title includes the project name “OnVinylUX”. If it does not, close the tab page and reselect the OnVinylUX project in the Solution Explorer
- In the OnVinylUX properties page select the Build Events tab
- In the Post-build event command lines entry field enter:
copy "$(SolutionDir)OnVinylUX\bin\x64\Debug\OnVinylUX.dll" "$(SolutionDir)Debug\x64"
Now we can try to execute the build process:
- From the Build menu select the Rebuild Solution entry
The project should build.
Now we need to build our .NET Interop library. This library allows us to communicate with our new UX:
- From the File menu select Add->New Project…
- In the “Add New Project” dialog locate and expand the Synergy/DE entry and select the Traditional entry
- Select the Executable Library (ELB) entry
- In the Name entry field type the value OnVinylInterop
- Click OK
This will create an Executable Library project. After the project is created it will open upthe Routine.dbl default program file. Close this window. We can also delete the default source file from the project:
- In the OnVinylInterop project locate the Routine.dbl source file
- Right-click the Routine.dbl file and select Delete
- When prompted select the Delete button
We now need to create the pre-build script to generate the .NET API wrappers. The script is quite complex so we have provided the contents for you. The script file can be downloaded from here. Download (when prompted by the browser select “open”) and open the zip file and copy the script file to the OnVinylInterop project folder you have just created. This folder will be under the DevPartner2018 solution folder.
We can now execute this script as part of the build process. To do this we will utilize a pre-build event. Please note this is a pre-build script and not a post-build script! To define the pre-build event:
- Ensure that the OnVinylInterop project in the solution explorer is selected
- From the Project menu select the Properties entry. This may also be named OnVinylInterop Properties
- At this point check that the tab page title includes the project name “OnVinylInterop”. If it does not, close the tab page and reselect the OnVinylInterop project in the Solution Explorer
- In the OnVinylInterop properties page select the Build Events tab
- In the Pre-build event command lines entry field enter:
"$(ProjectDir)\DotNetInterop.bat" "$(ProjectDir)" %TEMP%
- Now define the project references
- Ensure that the OnVinylInterop project in the solution explorer is selected
- At this point check that the tab page title includes the project name “OnVinylInterop”. If it does not, close the tab page and reselect the OnVinylInterop project in the Solution Explorer
- From the Project menu select the Add Reference… entry
- Select the Projects tab
- Check the OnVinylRepository
- Click OK
- Now define the project dependencies
- Ensure that the OnVinylInterop project in the solution explorer is selected
- At this point check that the tab page title includes the project name “OnVinylInterop”. If it does not, close the tab page and reselect the OnVinylInterop project in the Solution Explorer
- From the Project menu select the Project Dependencies… entry
- Check the OnVinylUX
- Click OK
From the Build menu select the Rebuild Solution entry to rebuild the solution
The project will fail to build because we have not specified any input files for the new OnVinylInterop project:
- Ensure that the OnVinylInterop project is highlighted in the Solution Explorer
- From the Project menu select the Add Existing Item… entry
- At this point check that the dialog title includes the project name “OnVinylInterop”. If it does not, cancel the dialog and reselect the OnVinylInterop project in the Solution Explorer
- Highlight the OnVinylNET.dbl, OnVinylNET.inc and OnVinylNET1.dbl files
- Click the Add button
This will add the required files to the project. At this point we need to change the file properties:
- Under the OnVinylInterop project select the OnVinylNET.dbl file
- In the properties window change the Build Action to Content
The final step to enable the building of the interop project is to set some additional compiler properties:
- Ensure that the OnVinylInterop project in the solution explorer is selected
- From the Project menu select the Properties entry. This may also be named OnVinylInterop Properties
- In the OnVinylInterop properties page select the Compile tab
- Check the Relax strong prototyping validation checkbox
- Check the :interop checkbox.
- In the OnVinylInterop properties page select the Build tab
- Change the Output path to ONVINYL_EXE:
- Change the Debug/Optimize code selection to Optimize
- In the OnVinylInterop properties page select the Common Properties tab
- Click inside the Name column of the properties list and enter a value of ONVINYL_IOP
- In the Value column enter a value of $(SolutionDir)OnVinylInterop
From the Build menu select the Rebuild Solution entry to rebuild the solution.
**At this point if you are prompted that files have changed after executing the build, simply close down any open edit tab pages.
We must make changes to the object library to reference the interop project:
- Ensure that the OnVinylObjectLibrary project in the solution explorer is selected
- From the Project menu select the Add Reference… entry
- At this point check that the dialog title includes the project name “OnVinylObjectLibrary”. If it does not, cancel the dialog and reselect the OnVinylObjectLibrary project in the Solution Explorer
- Select the Projects tab
- Check the OnVinylInterop
- Click OK
We also need to make changes to the way the code builds inside the object library:
- Ensure that the OnVinylObjectLibrary project in the solution explorer is selected
- From the Project menu select the Properties entry. This may also be named OnVinylObjectLibrary Properties
- At this point check that the tab page title includes the project name “OnVinylObjectLibrary”. If it does not, close the tab page and reselect the OnVinylObjectLibrary project in the Solution Explorer
- Click on the Compile tab
- Check the Set compile-time defines check box
- In the compile-time entry field enter UIWPF=1
We must make changes to the executable library to reference the interop project:
- Ensure that the OnVinylExecutableLibrary project in the solution explorer is selected
- From the Project menu select the Add Reference… entry
- At this point check that the dialog title includes the project name “OnVinylExecutableLibrary”. If it does not, cancel the dialog and reselect the OnVinylExecutableLibrary project in the Solution Explorer
- Select the Projects tab
- Check the OnVinylInterop
- Click OK
The final step is to indicate that we are running WPF mode and not UI Toolkit mode:
- Ensure that the OnVinylTKMaint project in thesolution explorer is selected
- From the Project menu select the Properties entry
- At this point check that the tab title is “OnVinylTKMaint”. If it does not, close the tab and reselect the OnVinylTKMaint project in the Solution Explorer
- Select the Debug tab
- In the Command line arguments field enter the value WPF
Now we can try to execute the build process and run the target executable:
- From the Build menu select the Rebuild Solution entry
- From the Debug menu select the Start Debugging entry
The UI Toolkit maintenance program now has an updated user experience showing the vinyl collection in a grid with images and an imbedded input form. If you would like to compare you results, click here.