diff --git a/SampleApplications/Samples/GDS/ConsoleServer/Opc.Ua.GlobalDiscoveryServer.Config.xml b/SampleApplications/Samples/GDS/ConsoleServer/Opc.Ua.GlobalDiscoveryServer.Config.xml index 3f3394d168..c2f07abcc2 100644 --- a/SampleApplications/Samples/GDS/ConsoleServer/Opc.Ua.GlobalDiscoveryServer.Config.xml +++ b/SampleApplications/Samples/GDS/ConsoleServer/Opc.Ua.GlobalDiscoveryServer.Config.xml @@ -140,7 +140,8 @@ 5 - + gdsdb.json + diff --git a/SampleApplications/Samples/GDS/ConsoleServer/Program.cs b/SampleApplications/Samples/GDS/ConsoleServer/Program.cs index 5512c9116d..4fc758e90a 100644 --- a/SampleApplications/Samples/GDS/ConsoleServer/Program.cs +++ b/SampleApplications/Samples/GDS/ConsoleServer/Program.cs @@ -240,8 +240,12 @@ namespace Opc.Ua.Gds.Server config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation); } + // get the DatabaseStorePath configuration parameter. + GlobalDiscoveryServerConfiguration gdsConfiguration = config.ParseExtension(); + string databaseStorePath = gdsConfiguration.DatabaseStorePath; + // start the server. - server = new GlobalDiscoveryServer(BinaryApplicationsDatabase.Load("gdsdb.bin")); + server = new GlobalDiscoveryServer(JsonApplicationsDatabase.Load(databaseStorePath)); await application.Start(server); // start the status thread diff --git a/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServer.cs b/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServer.cs index eb1476c40b..fede035e72 100644 Binary files a/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServer.cs and b/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServer.cs differ diff --git a/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServerConfiguration.cs b/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServerConfiguration.cs index d949748961..86b9dd0ad9 100644 --- a/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServerConfiguration.cs +++ b/SampleApplications/Samples/GDS/ServerCommon/GlobalDiscoveryServerConfiguration.cs @@ -82,6 +82,9 @@ namespace Opc.Ua.Gds.Server [DataMember(Order = 6)] public uint ShutdownDelay { get; set; } + + [DataMember(Order = 7)] + public string DatabaseStorePath { get; set; } #endregion #region Private Members diff --git a/SampleApplications/Samples/GDS/ServerCommon/JsonApplicationsDatabase.cs b/SampleApplications/Samples/GDS/ServerCommon/JsonApplicationsDatabase.cs new file mode 100644 index 0000000000..aa4b12069d --- /dev/null +++ b/SampleApplications/Samples/GDS/ServerCommon/JsonApplicationsDatabase.cs @@ -0,0 +1,71 @@ +/* ======================================================================== + * Copyright (c) 2005-2017 The OPC Foundation, Inc. All rights reserved. + * + * OPC Foundation MIT License 1.00 + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * The complete license agreement can be found here: + * http://opcfoundation.org/License/MIT/1.00/ + * ======================================================================*/ + +using System.IO; +using Newtonsoft.Json; + +namespace Opc.Ua.Gds.Server.Database +{ + public class JsonApplicationsDatabase : LinqApplicationsDatabase + { + #region Constructors + public JsonApplicationsDatabase(string fileName) + { + m_fileName = fileName; + } + static public JsonApplicationsDatabase Load(string fileName) + { + try + { + string json = File.ReadAllText(fileName); + JsonApplicationsDatabase db = JsonConvert.DeserializeObject(json); + db.FileName = fileName; + return db; + } + catch + { + return new JsonApplicationsDatabase(fileName); + } + } + #endregion + #region Public Members + public override void Save() + { + string json = JsonConvert.SerializeObject(this, Formatting.Indented); + File.WriteAllText(m_fileName, json); + } + [JsonIgnore] + public string FileName { get { return m_fileName; } private set { m_fileName = value; } } + #endregion + #region Private Fields + [JsonIgnore] + string m_fileName; + #endregion + } +} diff --git a/SampleApplications/Samples/GDS/ServerCommon/LinqApplicationsDatabase.cs b/SampleApplications/Samples/GDS/ServerCommon/LinqApplicationsDatabase.cs index e13b8af20f..820a2655c2 100644 --- a/SampleApplications/Samples/GDS/ServerCommon/LinqApplicationsDatabase.cs +++ b/SampleApplications/Samples/GDS/ServerCommon/LinqApplicationsDatabase.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using Newtonsoft.Json; namespace Opc.Ua.Gds.Server.Database { @@ -113,18 +114,18 @@ namespace Opc.Ua.Gds.Server.Database if (record != null) { - var endpoints = from ii in ServerEndpoints + var endpoints = (from ii in ServerEndpoints where ii.ApplicationId == record.ApplicationId - select ii; + select ii).ToList(); foreach (var endpoint in endpoints) { ServerEndpoints.Remove(endpoint); } - var names = from ii in ApplicationNames + var names = (from ii in ApplicationNames where ii.ApplicationId == record.ApplicationId - select ii; + select ii).ToList(); foreach (var name in names) { @@ -706,14 +707,21 @@ namespace Opc.Ua.Gds.Server.Database queryCounterResetTime = DateTime.UtcNow; } #endregion - #region Private Fields - [NonSerialized] object Lock = new object(); - [NonSerialized] DateTime queryCounterResetTime = DateTime.UtcNow; - ICollection Applications = new HashSet(); - ICollection ApplicationNames = new HashSet(); - ICollection ServerEndpoints = new HashSet(); - ICollection CertificateRequests = new HashSet(); - ICollection CertificateStores = new HashSet(); + #region Internal Fields + [NonSerialized] + internal object Lock = new object(); + [NonSerialized] + internal DateTime queryCounterResetTime = DateTime.UtcNow; + [JsonProperty] + internal ICollection Applications = new HashSet(); + [JsonProperty] + internal ICollection ApplicationNames = new HashSet(); + [JsonProperty] + internal ICollection ServerEndpoints = new HashSet(); + [JsonProperty] + internal ICollection CertificateRequests = new HashSet(); + [JsonProperty] + internal ICollection CertificateStores = new HashSet(); #endregion } }