... | ... | @@ -21,21 +21,24 @@ git checkout -b my_first_sila_server |
|
|
1. Open the solution file `sila_csharp/sila_csharp.sln` with VisualStudio 2017 (or higher)
|
|
|
|
|
|
2. Create a new subfolder e.g. 'MyFirstServer' within the 'examples' project folder
|
|
|
![1_create_folder](uploads/beeddfa10d6a50c7caa0b6bce4b3a588/1_create_folder.png)
|
|
|
|
|
|
![1_create_folder](uploads/2632e168bd7dc68d4b49f56b122edb39/1_create_folder.png)
|
|
|
![2_name_folder](uploads/50cb9f337b3dce205913d0453031c036/2_name_folder.png)
|
|
|
|
|
|
3. Create a new .NET core console application e.g. 'MyFirstServer.ServerApp' within the created subfolder (`MyFirstServer`)
|
|
|
![3_create_project](uploads/f73429b7abe7a7d8e215b42c63ba99fe/3_create_project.png)
|
|
|
|
|
|
![3_create_project](uploads/f30c67e9557bf6deaed2b5aced005ee7/3_create_project.png)
|
|
|
|
|
|
***NOTE:*** Pay attention to add the `examples\MyFirstServer` folder to the `Location:` entry
|
|
|
![4_name_project](uploads/23cef09130a2a839a46450899c76c701/4_name_project.png)
|
|
|
|
|
|
![4_name_project](uploads/c37abcb67f09e855f865786820617546/4_name_project.png)
|
|
|
|
|
|
4. Add the SiLA project dependencies `Sila2` and `Sila2.Utils`
|
|
|
|
|
|
*Option 1: Adding package source references:*
|
|
|
|
|
|
![5_add_dependencies](uploads/676f474f672c1647adf2e8b253136a64/5_add_dependencies.png)
|
|
|
![6_select_dependencies](uploads/36a87f922e5614341785211782e34c15/6_select_dependencies.png)
|
|
|
![5_add_dependencies](uploads/c2c57642321448cb98662ffd7f824b67/5_add_dependencies.png)
|
|
|
![6_select_dependencies](uploads/464edcd67a82000bf7bc1d4b3a4ad10a/6_select_dependencies.png)
|
|
|
|
|
|
*Option 2: Add the dependencies as NuGet packages*
|
|
|
|
... | ... | @@ -59,16 +62,19 @@ Instead of adding the project to the existing C# repo, you can start with a fres |
|
|
### It all starts with SiLA 2 Features (create the first Feature)
|
|
|
|
|
|
1. Create a `features` sub folder within the `MyFirstServer.App`project
|
|
|
![7_create_features_folder](uploads/071f240b267a49e9bd8fe7c0ec2d3ec0/7_create_features_folder.png)
|
|
|
|
|
|
![7_create_features_folder](uploads/f317e292a3fffa89445da6db27af00d8/7_create_features_folder.png)
|
|
|
![8_name_features_folder](uploads/834f7befe6a0c96fcb1ae36bcf83a662/8_name_features_folder.png)
|
|
|
|
|
|
2. Create a feature definiton XML file e.g. `MyFirstFeature.sila.xml`
|
|
|
![9_add_xml_file](uploads/bd94f4b8c1f59af6d64e597ff1172115/9_add_xml_file.png)
|
|
|
![10_name_feature_file](uploads/6c97aacd40132afa59b4e4841d35ef92/10_name_feature_file.png)
|
|
|
|
|
|
![9_add_xml_file](uploads/f0624ad264a65597d740694e6c193ad0/9_add_xml_file.png)
|
|
|
![10_name_feature_file](uploads/83289bdb77a6bcf4aab5279f908a850d/10_name_feature_file.png)
|
|
|
|
|
|
**Note**: The extension of the SiLA 2 feature definition files must always be `.sila.xml`.
|
|
|
|
|
|
3. Open the created file and add the following XML tag
|
|
|
|
|
|
```xml
|
|
|
<Feature SiLA2Version="1.0" FeatureVersion="1.0" MaturityLevel="Draft" Originator="org.silastandard" Category="examples"
|
|
|
xmlns="http://www.sila-standard.org"
|
... | ... | @@ -79,15 +85,19 @@ Instead of adding the project to the existing C# repo, you can start with a fres |
|
|
(Modify the `Originator` attribute according to your company/organization, e.g. `de.equicon`.)
|
|
|
|
|
|
This immediately enables intellisense according to the referenced SiLA 2 Feature Definition schema
|
|
|
|
|
|
![11_fd_intellisense](uploads/3a8f236070591e7fa75a8ebbc70ff3b5/11_fd_intellisense.png)
|
|
|
|
|
|
**Note**: You may have to enable downloading XML schema in the Visual Studio options.
|
|
|
|
|
|
![12_fd_intellisense_diabled](uploads/85d8ec09101d66ab966da5e1f1790124/12_fd_intellisense_diabled.png)
|
|
|
|
|
|
To do that, open the `Options` dialog under `Tools|Options` and go to `Text Editor | XML | Miscellanious` and activate the `Automatically download DTDs and schemas` option.
|
|
|
![12a_intellisense_options](uploads/5f5bc6a81b9a106d4cfce3c23d7833c4/12a_intellisense_options.png)
|
|
|
|
|
|
![12a_intellisense_options](uploads/8adefa82940e94ae71f687289ca07a7b/12a_intellisense_options.png)
|
|
|
|
|
|
4. Now we can develop a simple feature with one command which counts characters of a string and one property which provides the day of the week as a string:
|
|
|
|
|
|
```xml
|
|
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
|
<Feature SiLA2Version="1.0" FeatureVersion="1.0" MaturityLevel="Draft" Originator="org.silastandard" Category="examples"
|
... | ... | @@ -134,7 +144,8 @@ To do that, open the `Options` dialog under `Tools|Options` and go to `Text Edit |
|
|
### Generate Protos and Stubs from Features
|
|
|
|
|
|
1. To Generate the protobuf file as well as the C# stubs, open the MyFirstServer.csproj file for editing
|
|
|
![13_edit_project_file](uploads/75ceee6c6cf15c63e14c000920eef4d9/13_edit_project_file.png)
|
|
|
|
|
|
![13_edit_project_file](uploads/66b7a96f141f455d41bb847980081060/13_edit_project_file.png)
|
|
|
|
|
|
2. Add the following code:
|
|
|
```xml
|
... | ... | @@ -187,8 +198,8 @@ message Get_DayOfWeek_Responses { |
|
|
|
|
|
1. Create a new implementation class `MyFirstFeatureImpl.cs` of the MyFirstFeature gRPC calls
|
|
|
|
|
|
![15_create_impl_class](uploads/fd525764fa54dd25637ef8a912ba71e1/15_create_impl_class.png)
|
|
|
![16_create_impl_class_options](uploads/55d152dd74790f3f0d71b218bf2c8fe6/16_create_impl_class_options.png)
|
|
|
![15_add_impl_class](uploads/e4271ea52e707748ad8277abce44c87b/15_add_impl_class.png)
|
|
|
![16_name_impl_class](uploads/e16c862eac268994425f684080ab98c6/16_name_impl_class.png)
|
|
|
|
|
|
2. Add the required usings
|
|
|
|
... | ... | @@ -199,7 +210,7 @@ using Sila2.Org.Silastandard.Examples.Myfirstfeature.V1; |
|
|
using SilaFramework = Sila2.Org.Silastandard;
|
|
|
```
|
|
|
|
|
|
3. First lets inspect the important contents of the `MyFirstFeatureGrpc.cs` file, containing the interfaces
|
|
|
3. First lets inspect the important content of the `MyFirstFeatureGrpc.cs` file, containing the interfaces
|
|
|
which you will override in your `MyFirstFeatureImpl`
|
|
|
|
|
|
```csharp
|
... | ... | @@ -231,31 +242,29 @@ The relevant part of all the generated code is the `virtual` methods of the `MyF |
|
|
|
|
|
4. Derive the class from the generated C# gRPC stub class `MyFirstFeatureBase`
|
|
|
|
|
|
![17_derive_impl_from_stub](uploads/c7417855c0c6849bb298510047d41eb1/17_derive_impl_from_stub.png)
|
|
|
![17_derive_impl_class](uploads/0dceb6173c00c839128a03dcacee77a7/17_derive_impl_class.png)
|
|
|
|
|
|
5. Now that you know the virtual methods of `MyFirstFeatureBase`, you can overrride them.
|
|
|
|
|
|
If you are on VisualStudio or any other IDE then you can let it do the rest for you :)
|
|
|
|
|
|
![18_override_command_call](uploads/125747f9f995b340408a2fb7efd6bb1e/18_override_command_call.png)
|
|
|
![18_override_base_methods](uploads/9fbba4e45a1d4ccf40c1a884b1a00900/18_override_base_methods.png)
|
|
|
|
|
|
When you've overridden the `CountCharacters` and `DayOfWeek` methods should just call the base class methods,
|
|
|
When you've overridden the `CountCharacters` and `DayOfWeek` methods, they just call the base class methods
|
|
|
and should look like this:
|
|
|
|
|
|
![19_overriden_calls](uploads/dddfa5fde1d96baa477edba491f9d240/19_overriden_calls.png)
|
|
|
![19_overwritten_methods](uploads/2436f78a4d0575c1f6b44e03991c31da/19_overwritten_methods.png)
|
|
|
|
|
|
6. Now lets implement the `CountCharacters` command
|
|
|
|
|
|
First, get the input parameters from the `request` parameter:
|
|
|
```csharp
|
|
|
...
|
|
|
|
|
|
public override Task<CountCharacters_Responses> CountCharacters(CountCharacters_Parameters request, ServerCallContext context)
|
|
|
{
|
|
|
var inputStr = request.InputString.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
...
|
|
|
```
|
|
|
|
... | ... | @@ -270,7 +279,7 @@ public override Task<CountCharacters_Responses> CountCharacters(CountCharacters_ |
|
|
...
|
|
|
```
|
|
|
|
|
|
For sending back the result we have to assemble a `CountCharacters_Responses`object and pass it to the return result object:
|
|
|
For sending back the result we have to assemble a `CountCharacters_Responses` object and pass it to the return result object:
|
|
|
```csharp
|
|
|
...
|
|
|
public override Task<CountCharacters_Responses> CountCharacters(CountCharacters_Parameters request, ServerCallContext context)
|
... | ... | @@ -281,7 +290,6 @@ public override Task<CountCharacters_Responses> CountCharacters(CountCharacters_ |
|
|
}
|
|
|
...
|
|
|
```
|
|
|
|
|
|
|
|
|
7. Lets implement the `DayOfWeek` property:
|
|
|
|
... | ... | @@ -297,7 +305,7 @@ public override Task<Get_DayOfWeek_Responses> Get_DayOfWeek(Get_DayOfWeek_Parame |
|
|
...
|
|
|
```
|
|
|
|
|
|
And we have finished the Feature implementation :)
|
|
|
And we have finished the feature implementation :)
|
|
|
|
|
|
### Implement Server application (bind it all together)
|
|
|
|
... | ... | |