-
-
Save TomW-Skyline/805c689e62f0362d845ced2829a91aa1 to your computer and use it in GitHub Desktop.
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
namespace QAction_1 | |
{ | |
using System; | |
using System.Collections.Concurrent; | |
using Skyline.DataMiner.Scripting; | |
public class ElementInstanceManager | |
{ | |
private static readonly ConcurrentDictionary<string, ElementInstance> Instances = new ConcurrentDictionary<string, ElementInstance>(); | |
public static ElementInstance GetInstance(SLProtocol protocol) | |
{ | |
string key = GetKey(protocol); | |
return Instances.GetOrAdd(key, k => new ElementInstance(k)); | |
} | |
public static ElementInstance CreateNewInstance(SLProtocol protocol) | |
{ | |
string key = GetKey(protocol); | |
var instance = new ElementInstance(key); | |
Instances[key] = instance; | |
return instance; | |
} | |
public static void RemoveInstance(SLProtocol protocol) | |
{ | |
string key = GetKey(protocol); | |
Instances.TryRemove(key, out _); | |
} | |
private static string GetKey(SLProtocol protocol) | |
{ | |
if (protocol == null) | |
throw new ArgumentNullException(nameof(protocol)); | |
return String.Join("/", protocol.DataMinerID, protocol.ElementID); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment