-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEntry.cs
More file actions
50 lines (43 loc) · 2.58 KB
/
Entry.cs
File metadata and controls
50 lines (43 loc) · 2.58 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using AXSharp.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AXSharp.Connector.S71500.WebApi;
using System.Net.Security;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
namespace abstractions_app
{
public class ConnectionConfig
{
public string TargetIp { get; set; } = string.Empty;
public string UserName { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>? CertificateValidationCallback { get; set; }
public bool IgnoreSslErrors { get; set; } = true;
}
public class TwinConnectorSelector
{
// Do not commit any changes to the following variables. You may modify them locally, but committing the changes will mess up the nightly build. =>
public static string TargetIp { get; } = "192.168.100.120";//Environment.GetEnvironmentVariable("AXTARGET"); // <- replace by your IP
private static string Pass => @"123ABCDabcd$#!"; //Environment.GetEnvironmentVariable("AX_TARGET_PWD"); //Environment.GetEnvironmentVariable("AX_TARGET_PWD"); // <- Pass in the password that you have set up for the user. NOT AS PLAIN TEXT! Use user secrets instead.
private static string UserName = "adm"; //Environment.GetEnvironmentVariable("AX_USERNAME"); //<- replace by user name you have set up in your WebAPI settings
private const bool IgnoreSslErrors = true; // <- When you have your certificates in order set this to false.
private static string CertificatePath = "..\\..\\certs\\plc_line\\plc_line.cer"; //NFI why, but it works
// <= Do not commit any changes to the following variables. You may modify them locally, but committing the changes will mess up the nightly build.
static readonly X509Certificate2 Certificate = new X509Certificate2(CertificatePath);
private static bool CertificateValidation(HttpRequestMessage requestMessage, X509Certificate2 certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return certificate.Thumbprint == Certificate.Thumbprint;
}
public static abstractions_appTwinController SecurePlc { get; }
= new(ConnectorAdapterBuilder.Build()
.CreateWebApi(TargetIp, UserName, Pass, CertificateValidation, IgnoreSslErrors));
}
public static class Entry
{
public static abstractions_appTwinController Plc { get; } = TwinConnectorSelector.SecurePlc;
}
}