diff --git a/SampleApplications/SDK/Opc.Ua.Configuration/ConfigUtils.cs b/SampleApplications/SDK/Opc.Ua.Configuration/ConfigUtils.cs index 0cda22fa25..e803347827 100644 --- a/SampleApplications/SDK/Opc.Ua.Configuration/ConfigUtils.cs +++ b/SampleApplications/SDK/Opc.Ua.Configuration/ConfigUtils.cs @@ -261,7 +261,7 @@ namespace Opc.Ua.Configuration { application.RejectedCertificatesStore = new Opc.Ua.Security.CertificateStoreIdentifier(); application.RejectedCertificatesStore.StoreType = CertificateStoreType.Directory; - application.RejectedCertificatesStore.StorePath = ApplicationData.Current.LocalFolder.Path + "\\OPC Foundation\\CertificateStores\\RejectedCertificates"; + application.RejectedCertificatesStore.StorePath = ApplicationData.Current.LocalFolder.Path + Path.DirectorySeparatorChar + "Rejected"; } if (application.RejectedCertificatesStore.StoreType == CertificateStoreType.Directory) diff --git a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs index 56d9583aa3..b1c56436cc 100644 --- a/SampleApplications/Samples/NetCoreConsoleClient/Program.cs +++ b/SampleApplications/Samples/NetCoreConsoleClient/Program.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Opc.Ua; using Opc.Ua.Client; -using System.Net; namespace NetCoreConsoleClient { @@ -16,7 +15,7 @@ namespace NetCoreConsoleClient if (args.Length == 0) { // use OPC UA .Net Sample server - endpointURL = "opc.tcp://" + Dns.GetHostName() + ":51210/UA/SampleServer"; + endpointURL = "opc.tcp://" + Utils.GetHostName() + ":51210/UA/SampleServer"; } else { @@ -46,18 +45,18 @@ namespace NetCoreConsoleClient ApplicationCertificate = new CertificateIdentifier { StoreType = @"Directory", - StorePath = @".", - SubjectName = Utils.Format(@"CN={0}, DC={1}", "UA Sample Client", Dns.GetHostName()) + StorePath = @"", + SubjectName = Utils.Format(@"CN={0}, DC={1}", "UA Sample Client", Utils.GetHostName()) }, TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Directory", - StorePath = @".", + StorePath = @"", }, TrustedIssuerCertificates = new CertificateTrustList { StoreType = @"Directory", - StorePath = @".", + StorePath = @"", }, NonceLength = 32, AutoAcceptUntrustedCertificates = true @@ -152,7 +151,6 @@ namespace NetCoreConsoleClient Console.WriteLine("8 - Running...Press any key to exit..."); Console.ReadKey(true); - } private static void OnNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e) diff --git a/Stack/Opc.Ua.Core/Schema/ApplicationConfiguration.cs b/Stack/Opc.Ua.Core/Schema/ApplicationConfiguration.cs index 1c0325ca58..7cb07ebeff 100644 --- a/Stack/Opc.Ua.Core/Schema/ApplicationConfiguration.cs +++ b/Stack/Opc.Ua.Core/Schema/ApplicationConfiguration.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; @@ -1976,7 +1977,11 @@ namespace Opc.Ua } else { - m_storePath = ApplicationData.Current.LocalFolder.Path + "\\" + value; + m_storePath = ApplicationData.Current.LocalFolder.Path; + if (!String.IsNullOrEmpty(value)) + { + m_storePath += Path.DirectorySeparatorChar + value; + } } if (!String.IsNullOrEmpty(m_storePath)) @@ -2239,7 +2244,11 @@ namespace Opc.Ua } else { - m_storePath = ApplicationData.Current.LocalFolder.Path + "\\" + value; + m_storePath = ApplicationData.Current.LocalFolder.Path; + if (!String.IsNullOrEmpty(value)) + { + m_storePath += Path.DirectorySeparatorChar + value; + } } if (!String.IsNullOrEmpty(m_storePath)) diff --git a/Stack/Opc.Ua.Core/Security/Certificates/DirectoryCertificateStore.cs b/Stack/Opc.Ua.Core/Security/Certificates/DirectoryCertificateStore.cs index 156c4467a4..4b90816ed8 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/DirectoryCertificateStore.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/DirectoryCertificateStore.cs @@ -114,8 +114,8 @@ namespace Opc.Ua { location = Utils.ReplaceSpecialFolderNames(location); m_directory = new DirectoryInfo(location); - m_certificateSubdir = new DirectoryInfo(m_directory.FullName + "\\certs"); - m_privateKeySubdir = new DirectoryInfo(m_directory.FullName + "\\private"); + m_certificateSubdir = new DirectoryInfo(m_directory.FullName + Path.DirectorySeparatorChar + "certs"); + m_privateKeySubdir = new DirectoryInfo(m_directory.FullName + Path.DirectorySeparatorChar + "private"); } } } @@ -418,7 +418,7 @@ namespace Opc.Ua StringBuilder filePath = new StringBuilder(); filePath.Append(m_privateKeySubdir.FullName); - filePath.Append("\\"); + filePath.Append(Path.DirectorySeparatorChar); filePath.Append(fileRoot); FileInfo privateKeyFile = new FileInfo(filePath.ToString() + ".pfx"); @@ -470,7 +470,7 @@ namespace Opc.Ua } // check for CRL. - DirectoryInfo info = new DirectoryInfo(this.Directory.FullName + "\\crl"); + DirectoryInfo info = new DirectoryInfo(this.Directory.FullName + Path.DirectorySeparatorChar + "crl"); if (info.Exists) { @@ -547,7 +547,7 @@ namespace Opc.Ua StringBuilder filePath = new StringBuilder(); filePath.Append(m_privateKeySubdir.FullName); - filePath.Append("\\"); + filePath.Append(Path.DirectorySeparatorChar); filePath.Append(fileRoot); entry.PrivateKeyFile = new FileInfo(filePath.ToString() + ".pfx"); @@ -689,7 +689,7 @@ namespace Opc.Ua filePath.Append(m_certificateSubdir.FullName); } - filePath.Append("\\"); + filePath.Append(Path.DirectorySeparatorChar); filePath.Append(fileName); if (includePrivateKey) diff --git a/Stack/Opc.Ua.Core/Security/Certificates/SecurityConfiguration.cs b/Stack/Opc.Ua.Core/Security/Certificates/SecurityConfiguration.cs index 56f56e9a2e..b17559bc11 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/SecurityConfiguration.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/SecurityConfiguration.cs @@ -12,6 +12,8 @@ +using System.IO; + namespace Opc.Ua { #region SecurityConfiguration Class @@ -47,7 +49,7 @@ namespace Opc.Ua { RejectedCertificateStore = new CertificateStoreIdentifier(); RejectedCertificateStore.StoreType = CertificateStoreType.Directory; - RejectedCertificateStore.StorePath = ApplicationData.Current.LocalFolder.Path + "\\OPC Foundation\\CertificateStores\\RejectedCertificates"; + RejectedCertificateStore.StorePath = ApplicationData.Current.LocalFolder.Path + Path.DirectorySeparatorChar + "Rejected"; } } diff --git a/Stack/Opc.Ua.Core/Stack/Configuration/ApplicationConfiguration.cs b/Stack/Opc.Ua.Core/Stack/Configuration/ApplicationConfiguration.cs index 9edc655560..8008689d99 100644 --- a/Stack/Opc.Ua.Core/Stack/Configuration/ApplicationConfiguration.cs +++ b/Stack/Opc.Ua.Core/Stack/Configuration/ApplicationConfiguration.cs @@ -367,8 +367,9 @@ namespace Opc.Ua // choose a default configuration file. filePath = Utils.Format( - "{0}\\{1}.Config.xml", + "{0}{1}{2}.Config.xml", file.DirectoryName, + Path.DirectorySeparatorChar, file.Name); // convert to absolute file path (expands environment strings). @@ -516,11 +517,11 @@ namespace Opc.Ua if (filePath == null) { filePath = m_clientConfiguration.EndpointCacheFilePath; - + // TODO: //// if (!filePath.StartsWith("\\\\", StringComparison.Ordinal) && filePath.IndexOf(":", StringComparison.Ordinal) != 1) { FileInfo sourceFile = new FileInfo(this.SourceFilePath); - filePath = Utils.Format("{0}\\{1}", sourceFile.DirectoryName, filePath); + filePath = Utils.Format("{0}{1}{2}", sourceFile.DirectoryName, Path.DirectorySeparatorChar, filePath); } } diff --git a/Stack/Opc.Ua.Core/Types/Utils/Utils.cs b/Stack/Opc.Ua.Core/Types/Utils/Utils.cs index 470fd8d7fd..53886f5b95 100644 --- a/Stack/Opc.Ua.Core/Types/Utils/Utils.cs +++ b/Stack/Opc.Ua.Core/Types/Utils/Utils.cs @@ -28,6 +28,7 @@ using System.Diagnostics; using System.Security.Cryptography; using System.Xml.Linq; using System.Runtime.InteropServices; +using Microsoft.Extensions.PlatformAbstractions; namespace Opc.Ua { @@ -84,7 +85,7 @@ namespace Opc.Ua private static int s_traceMasks = (int)TraceMasks.None; #endif - private static string s_traceFileName = null; + private static string s_traceFileName = PlatformServices.Default.Application.ApplicationName + ".log"; private static long s_BaseLineTicks = DateTime.UtcNow.Ticks; private static object s_traceFileLock = new object(); @@ -798,7 +799,7 @@ namespace Opc.Ua } // keep first path segment. - int start = filePath.IndexOf('\\'); + int start = filePath.IndexOf(Path.DirectorySeparatorChar); if (start == -1) { @@ -806,15 +807,15 @@ namespace Opc.Ua } // keep file name. - int end = filePath.LastIndexOf('\\'); + int end = filePath.LastIndexOf(Path.DirectorySeparatorChar); while (end > start && filePath.Length - end < maxLength) { - end = filePath.LastIndexOf('\\', end-1); + end = filePath.LastIndexOf(Path.DirectorySeparatorChar, end-1); if (filePath.Length - end > maxLength) { - end = filePath.IndexOf('\\', end+1); + end = filePath.IndexOf(Path.DirectorySeparatorChar, end+1); break; } } @@ -909,7 +910,7 @@ namespace Opc.Ua public static string GetHostName() { - return Dns.GetHostName(); + return Dns.GetHostName().Split('.')[0].ToLowerInvariant(); } ///