mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-22 17:50:03 +08:00
add json as db storage
This commit is contained in:
+2
-1
@@ -140,7 +140,8 @@
|
||||
</CertificateGroups>
|
||||
<KnownHostNames/>
|
||||
<ShutdownDelay>5</ShutdownDelay>
|
||||
</GlobalDiscoveryServerConfiguration>
|
||||
<DatabaseStorePath>gdsdb.json</DatabaseStorePath>
|
||||
</GlobalDiscoveryServerConfiguration>
|
||||
</ua:XmlElement>
|
||||
</Extensions>
|
||||
|
||||
|
||||
@@ -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<GlobalDiscoveryServerConfiguration>();
|
||||
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
|
||||
|
||||
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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<JsonApplicationsDatabase>(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
|
||||
}
|
||||
}
|
||||
@@ -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<ServerEndpoint>();
|
||||
|
||||
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<ApplicationName>();
|
||||
|
||||
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<Application> Applications = new HashSet<Application>();
|
||||
ICollection<ApplicationName> ApplicationNames = new HashSet<ApplicationName>();
|
||||
ICollection<ServerEndpoint> ServerEndpoints = new HashSet<ServerEndpoint>();
|
||||
ICollection<CertificateRequest> CertificateRequests = new HashSet<CertificateRequest>();
|
||||
ICollection<CertificateStore> CertificateStores = new HashSet<CertificateStore>();
|
||||
#region Internal Fields
|
||||
[NonSerialized]
|
||||
internal object Lock = new object();
|
||||
[NonSerialized]
|
||||
internal DateTime queryCounterResetTime = DateTime.UtcNow;
|
||||
[JsonProperty]
|
||||
internal ICollection<Application> Applications = new HashSet<Application>();
|
||||
[JsonProperty]
|
||||
internal ICollection<ApplicationName> ApplicationNames = new HashSet<ApplicationName>();
|
||||
[JsonProperty]
|
||||
internal ICollection<ServerEndpoint> ServerEndpoints = new HashSet<ServerEndpoint>();
|
||||
[JsonProperty]
|
||||
internal ICollection<CertificateRequest> CertificateRequests = new HashSet<CertificateRequest>();
|
||||
[JsonProperty]
|
||||
internal ICollection<CertificateStore> CertificateStores = new HashSet<CertificateStore>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user