-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
311 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/GodSharpOpcUaDiscoveryServer/GodSharpOpcUaDiscoveryServer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\GodSharp.Opc.Ua.Common\GodSharp.Opc.Ua.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using GodSharp.Opc.Ua; | ||
|
||
using Opc.Ua; | ||
|
||
Console.WriteLine("Hello, GodSharpOpcUaDiscoveryServer!"); | ||
// Auto Generate ApplicationConfigurationFile | ||
// GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; | ||
|
||
// Configuration for UA Discovery Server | ||
ApplicationConfiguration? configuration = null; | ||
configuration = await GodSharp.Opc.Ua.OpcUaHelper.DiscoveryServerConfigurationAsync( | ||
"GodSharpOpcUaDiscoveryServer", | ||
"GodSharp Opc Ua Discovery Server", | ||
new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } | ||
//,(s, e) => CertificateValidationHandler(configuration, s, e) | ||
, CertificateValidationHandler | ||
); | ||
|
||
// Instance UA Server | ||
var ds = new OpcUaDiscoveryServer(TimeSpan.FromSeconds(15)); | ||
|
||
// Start UA Discovery Server | ||
ds.Start(configuration); | ||
Console.WriteLine("GodSharpOpcUaDiscoveryServer Started!"); | ||
Console.ReadLine(); | ||
|
||
// Start UA Discovery Server | ||
ds.Stop(); | ||
|
||
static void CertificateValidationHandler( | ||
//ApplicationConfiguration configuration, | ||
CertificateValidator sender, CertificateValidationEventArgs e) | ||
{ | ||
if (e.Error.StatusCode.Code == StatusCodes.BadCertificateUntrusted) | ||
{ | ||
e.Accept = true; | ||
//return; | ||
//if (!Directory.Exists(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath)) | ||
//{ | ||
// Directory.CreateDirectory(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath); | ||
//} | ||
|
||
//if (configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates) | ||
//{ | ||
// using (var store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore()) | ||
// { | ||
// store.Add(e.Certificate); | ||
// } | ||
// e.Accept = true; | ||
// return; | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# GodSharp.Opc.Ua.DiscoveryServer | ||
|
||
![Azure DevOps builds (main)](https://img.shields.io/azure-devops/build/godsharp/public/4/main?label=azure%20pipelines&style=flat-square) | ||
|
||
## Package Version | ||
|
||
|Name|NuGet|MyGet| | ||
|---|---|---| | ||
| GodSharp.Opc.Ua.Common | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Common?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Common) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Common?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Common) | | ||
| GodSharp.Opc.Ua.Client | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Client?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Client) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Client?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Client) | | ||
| GodSharp.Opc.Ua.ProxyServer | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ProxyServer) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ProxyServer) | | ||
| GodSharp.Opc.Ua.Server | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server) | | ||
| GodSharp.Opc.Ua.Server.AspNetCore | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server.AspNetCore) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server.AspNetCore) | | ||
| GodSharp.Opc.Ua.ComplexTypes | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ComplexTypes) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ComplexTypes) | | ||
|
||
## Introduction | ||
|
||
|Package|Uasge| | ||
|---:|:---| | ||
| GodSharp.Opc.Ua.Common | a opc ua common lib | | ||
| GodSharp.Opc.Ua.Client | a opc ua client | | ||
| GodSharp.Opc.Ua.ProxyServer | a proxy for opc ua server | | ||
| GodSharp.Opc.Ua.Server | a opc ua server | | ||
| GodSharp.Opc.Ua.Server.AspNetCore | opc ua server for asp.net core | | ||
| GodSharp.Opc.Ua.ComplexTypes | custom generate encode/decode method for `EncodeableObject` class | | ||
|
||
## Getting Started | ||
|
||
```ps | ||
PM> Install-Package GodSharp.Opc.Ua.Common | ||
``` | ||
|
||
### Configuration | ||
|
||
```csharp | ||
// Auto Generate ApplicationConfigurationFile | ||
// GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; | ||
// Configuration for UA Discovery Server | ||
ApplicationConfiguration? configuration = null; | ||
configuration = await GodSharp.Opc.Ua.OpcUaHelper.DiscoveryServerConfigurationAsync( | ||
"GodSharpOpcUaDiscoveryServer", | ||
"GodSharp Opc Ua Discovery Server", | ||
new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } | ||
//,(s, e) => CertificateValidationHandler(configuration, s, e) | ||
, CertificateValidationHandler | ||
); | ||
``` | ||
|
||
### Instance | ||
|
||
```csharp | ||
// Instance UA Discovery Server | ||
var ds = new OpcUaDiscoveryServer(TimeSpan.FromSeconds(15)); | ||
|
||
// Start UA Discovery Server | ||
ds.Start(configuration); | ||
|
||
// Start UA Discovery Server | ||
ds.Stop(); | ||
``` | ||
|
||
## License | ||
|
||
**Free!** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\GodSharp.Opc.Ua.Server\GodSharp.Opc.Ua.Server.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using GodSharp.Opc.Ua.Server; | ||
|
||
using Opc.Ua; | ||
|
||
Console.WriteLine("Hello, GodSharpOpcUaServer!"); | ||
|
||
// Auto Generate ApplicationConfigurationFile | ||
GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; | ||
|
||
// Configuration for UA Server | ||
ApplicationConfiguration? configuration = null; | ||
configuration = await GodSharp.Opc.Ua.OpcUaHelper.ServerConfigurationAsync( | ||
"GodSharpOpcUaServer", | ||
"GodSharp Opc Ua Server", | ||
new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } | ||
//,(s, e) => CertificateValidationHandler(configuration, s, e) | ||
, CertificateValidationHandler | ||
); | ||
|
||
// Instance UA Server | ||
var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter()); | ||
|
||
// Start server | ||
server.Start(configuration); | ||
|
||
Console.WriteLine("GodSharpOpcUaServer Started!"); | ||
string? input = null; | ||
|
||
do | ||
{ | ||
input = Console.ReadLine(); | ||
|
||
if (input == null) continue; | ||
} while (input != "q"); | ||
|
||
// Stop server | ||
server.Stop(); | ||
|
||
static void CertificateValidationHandler( | ||
//ApplicationConfiguration configuration, | ||
CertificateValidator sender, CertificateValidationEventArgs e) | ||
{ | ||
if (e.Error.StatusCode.Code == StatusCodes.BadCertificateUntrusted) | ||
{ | ||
e.Accept = true; | ||
//return; | ||
//if (!Directory.Exists(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath)) | ||
//{ | ||
// Directory.CreateDirectory(configuration.SecurityConfiguration.RejectedCertificateStore.StorePath); | ||
//} | ||
|
||
//if (configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates) | ||
//{ | ||
// using (var store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore()) | ||
// { | ||
// store.Add(e.Certificate); | ||
// } | ||
// e.Accept = true; | ||
// return; | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# GodSharp.Opc.Ua.Server | ||
|
||
![Azure DevOps builds (main)](https://img.shields.io/azure-devops/build/godsharp/public/4/main?label=azure%20pipelines&style=flat-square) | ||
|
||
## Package Version | ||
|
||
|Name|NuGet|MyGet| | ||
|---|---|---| | ||
| GodSharp.Opc.Ua.Common | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Common?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Common) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Common?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Common) | | ||
| GodSharp.Opc.Ua.Client | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Client?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Client) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Client?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Client) | | ||
| GodSharp.Opc.Ua.ProxyServer | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ProxyServer) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ProxyServer?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ProxyServer) | | ||
| GodSharp.Opc.Ua.Server | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server) | | ||
| GodSharp.Opc.Ua.Server.AspNetCore | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.Server.AspNetCore) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.Server.AspNetCore?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.Server.AspNetCore) | | ||
| GodSharp.Opc.Ua.ComplexTypes | [![NuGet](https://img.shields.io/nuget/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square)](https://www.nuget.org/packages/GodSharp.Opc.Ua.ComplexTypes) | [![MyGet](https://img.shields.io/myget/godsharp/v/GodSharp.Opc.Ua.ComplexTypes?style=flat-square&label=myget)](https://www.myget.org/feed/godsharp/package/nuget/GodSharp.Opc.Ua.ComplexTypes) | | ||
|
||
## Introduction | ||
|
||
|Package|Uasge| | ||
|---:|:---| | ||
| GodSharp.Opc.Ua.Common | a opc ua common lib | | ||
| GodSharp.Opc.Ua.Client | a opc ua client | | ||
| GodSharp.Opc.Ua.ProxyServer | a proxy for opc ua server | | ||
| GodSharp.Opc.Ua.Server | a opc ua server | | ||
| GodSharp.Opc.Ua.Server.AspNetCore | opc ua server for asp.net core | | ||
| GodSharp.Opc.Ua.ComplexTypes | custom generate encode/decode method for `EncodeableObject` class | | ||
|
||
## Getting Started | ||
|
||
```ps | ||
PM> Install-Package GodSharp.Opc.Ua.Server | ||
``` | ||
|
||
### Configuration | ||
|
||
```csharp | ||
// Auto Generate ApplicationConfigurationFile | ||
GodSharp.Opc.Ua.OpcUaHelper.GenerateApplicationConfigurationFile = true; | ||
|
||
// Configuration for UA Server | ||
ApplicationConfiguration? configuration = null; | ||
configuration = await GodSharp.Opc.Ua.OpcUaHelper.ServerConfigurationAsync( | ||
"GodSharpOpcUaServer", | ||
"GodSharp Opc Ua Server", | ||
new string[] { Utils.Format(@"opc.tcp://{0}:4840", "localhost") } | ||
//,(s, e) => CertificateValidationHandler(configuration, s, e) | ||
, CertificateValidationHandler | ||
); | ||
|
||
// Instance UA Server | ||
var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter ()); | ||
|
||
// Start server | ||
server.Start(configuration); | ||
``` | ||
|
||
### Instance | ||
|
||
```csharp | ||
// Instance UA Server | ||
var server = new OpcUaStandardServer(new SampleServerAuthorizationFilter ()); | ||
|
||
// Start server | ||
server.Start(configuration); | ||
|
||
// Stop server | ||
server.Stop(); | ||
``` | ||
|
||
### ServerAuthorizationFilter | ||
|
||
Used to authorized user token. | ||
|
||
```csharp | ||
public class SampleServerAuthorizationFilter : IServerAuthorizationFilter | ||
{ | ||
public ServerAuthorizationResult Verify(UserNameIdentityToken token) | ||
{ | ||
string userName = token.UserName; | ||
string decryptedPassword = token.DecryptedPassword; | ||
if (userName == "admin" && decryptedPassword == "admin@password") | ||
{ | ||
return new ServerAuthorizationResult(Authorized: true, Administrator: true); | ||
} | ||
|
||
if (userName == "user" && decryptedPassword == "user@password") | ||
{ | ||
return new ServerAuthorizationResult(Authorized: true); | ||
} | ||
|
||
return new ServerAuthorizationResult(Authorized: false); | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
**Free!** |