d4231c4a6d
ci / windows-x86 (push) Failing after 15m0s
ci / java (push) Failing after 15m13s
ci / portable (push) Failing after 15m21s
An OnDataChange/OnWriteComplete already queued on the STA is dispatched after RemoveItem evicted the handle and re-created the cache entry; item handles are never reused within a registration, so it leaked until Unregister. MxAccessSession.Create now binds its handle registry to the production sink, which only caches callbacks for handles the registry still holds. The event is still forwarded. EvictStaleHandleState stays as the backstop for unbound sinks.
1795 lines
68 KiB
C#
1795 lines
68 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Worker.MxAccess;
|
|
|
|
public sealed class MxAccessSession : IDisposable
|
|
{
|
|
private readonly object mxAccessComObject;
|
|
private readonly IMxAccessServer mxAccessServer;
|
|
private readonly IMxAccessEventSink eventSink;
|
|
private readonly MxAccessHandleRegistry handleRegistry;
|
|
private readonly MxAccessValueCache valueCache;
|
|
private readonly MxAccessWriteCompletionCache writeCompletionCache;
|
|
private bool disposed;
|
|
|
|
private MxAccessSession(
|
|
object mxAccessComObject,
|
|
IMxAccessServer mxAccessServer,
|
|
IMxAccessEventSink eventSink,
|
|
MxAccessHandleRegistry handleRegistry,
|
|
MxAccessValueCache valueCache,
|
|
MxAccessWriteCompletionCache writeCompletionCache,
|
|
int creationThreadId)
|
|
{
|
|
this.mxAccessComObject = mxAccessComObject ?? throw new ArgumentNullException(nameof(mxAccessComObject));
|
|
this.mxAccessServer = mxAccessServer ?? throw new ArgumentNullException(nameof(mxAccessServer));
|
|
this.eventSink = eventSink ?? throw new ArgumentNullException(nameof(eventSink));
|
|
this.handleRegistry = handleRegistry ?? throw new ArgumentNullException(nameof(handleRegistry));
|
|
this.valueCache = valueCache ?? throw new ArgumentNullException(nameof(valueCache));
|
|
this.writeCompletionCache = writeCompletionCache ?? throw new ArgumentNullException(nameof(writeCompletionCache));
|
|
CreationThreadId = creationThreadId;
|
|
}
|
|
|
|
/// <summary>The thread ID where this session was created.</summary>
|
|
public int CreationThreadId { get; }
|
|
|
|
/// <summary>The registry for tracking opened handles.</summary>
|
|
public MxAccessHandleRegistry HandleRegistry => handleRegistry;
|
|
|
|
/// <summary>
|
|
/// Per-session last-value cache populated by the event sink. ReadBulk
|
|
/// consults this cache before falling back to its own snapshot
|
|
/// lifecycle so it can serve a "current value" for an already-advised
|
|
/// tag without touching the existing subscription.
|
|
/// </summary>
|
|
public MxAccessValueCache ValueCache => valueCache;
|
|
|
|
/// <summary>
|
|
/// Per-session OnWriteComplete completion cache populated by the event
|
|
/// sink. The write command executor consults it after a
|
|
/// WriteSecured/WriteSecured2 COM call so the unary reply can carry
|
|
/// the correlated completion outcome.
|
|
/// </summary>
|
|
public MxAccessWriteCompletionCache WriteCompletionCache => writeCompletionCache;
|
|
|
|
/// <summary>Creates a WorkerReady message with session metadata.</summary>
|
|
/// <param name="workerProcessId">Process ID of the worker.</param>
|
|
/// <returns>The populated <see cref="WorkerReady"/> message.</returns>
|
|
public WorkerReady CreateWorkerReady(int workerProcessId)
|
|
{
|
|
return new WorkerReady
|
|
{
|
|
WorkerProcessId = workerProcessId,
|
|
MxaccessProgid = MxAccessInteropInfo.ProgId,
|
|
MxaccessClsid = MxAccessInteropInfo.Clsid,
|
|
ReadyTimestamp = Timestamp.FromDateTime(DateTime.UtcNow),
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test-only seam: constructs a session that bypasses the live COM
|
|
/// factory. The caller supplies the <see cref="IMxAccessServer"/> and
|
|
/// <see cref="IMxAccessEventSink"/> directly so tests can exercise
|
|
/// session methods without touching MXAccess COM. This is exposed via
|
|
/// <c>InternalsVisibleTo("ZB.MOM.WW.MxGateway.Worker.Tests")</c>; production code
|
|
/// must use the <see cref="Create"/> factory.
|
|
///
|
|
/// A runtime guard rejects an <see cref="MxAccessBaseEventSink"/> —
|
|
/// the production sink wired by <see cref="Create"/> — because the
|
|
/// <c>new object()</c> stand-in this factory uses for the COM object
|
|
/// would silently bypass <see cref="System.Runtime.InteropServices.Marshal.IsComObject(object)"/>
|
|
/// during disposal and mask lifetime regressions.
|
|
/// </summary>
|
|
/// <param name="mxAccessServer">The server abstraction to drive.</param>
|
|
/// <param name="eventSink">The event sink to attach to the session.</param>
|
|
/// <param name="handleRegistry">Optional handle registry; a fresh one is created when null.</param>
|
|
/// <param name="valueCache">Optional value cache; a fresh one is created when null.</param>
|
|
/// <param name="creationThreadId">Optional creation thread id; defaults to the current managed thread id.</param>
|
|
/// <returns>A test-only <see cref="MxAccessSession"/> backed by the supplied test doubles.</returns>
|
|
/// <exception cref="ArgumentException">
|
|
/// Thrown when <paramref name="eventSink"/> is the production
|
|
/// <see cref="MxAccessBaseEventSink"/>. Tests must pass a test
|
|
/// double sink — production code must use <see cref="Create"/>.
|
|
/// </exception>
|
|
internal static MxAccessSession CreateForTesting(
|
|
IMxAccessServer mxAccessServer,
|
|
IMxAccessEventSink eventSink,
|
|
MxAccessHandleRegistry? handleRegistry = null,
|
|
MxAccessValueCache? valueCache = null,
|
|
int? creationThreadId = null)
|
|
{
|
|
if (eventSink is MxAccessBaseEventSink)
|
|
{
|
|
throw new ArgumentException(
|
|
"CreateForTesting must not be used with the production MxAccessBaseEventSink. "
|
|
+ "Use MxAccessSession.Create for production code; pass a test-double IMxAccessEventSink here.",
|
|
nameof(eventSink));
|
|
}
|
|
|
|
return new MxAccessSession(
|
|
new object(),
|
|
mxAccessServer,
|
|
eventSink,
|
|
handleRegistry ?? new MxAccessHandleRegistry(),
|
|
valueCache ?? new MxAccessValueCache(),
|
|
eventSink is IWriteCompletionCacheProvider provider
|
|
? provider.WriteCompletionCache
|
|
: new MxAccessWriteCompletionCache(),
|
|
creationThreadId ?? Environment.CurrentManagedThreadId);
|
|
}
|
|
|
|
/// <summary>Creates and initializes an MXAccess COM session.</summary>
|
|
/// <param name="factory">Factory to create the MXAccess COM object.</param>
|
|
/// <param name="eventSink">Event sink to attach to the COM object.</param>
|
|
/// <param name="sessionId">Identifier of the session.</param>
|
|
/// <returns>The initialized <see cref="MxAccessSession"/>.</returns>
|
|
public static MxAccessSession Create(
|
|
IMxAccessComObjectFactory factory,
|
|
IMxAccessEventSink eventSink,
|
|
string sessionId)
|
|
{
|
|
if (factory is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(factory));
|
|
}
|
|
|
|
if (eventSink is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(eventSink));
|
|
}
|
|
|
|
object? mxAccessComObject = null;
|
|
|
|
try
|
|
{
|
|
mxAccessComObject = factory.Create();
|
|
if (mxAccessComObject is null)
|
|
{
|
|
throw new InvalidOperationException("MXAccess COM factory returned null.");
|
|
}
|
|
|
|
eventSink.Attach(mxAccessComObject, sessionId);
|
|
|
|
// Share the event sink's value cache when one is wired (the
|
|
// production MxAccessBaseEventSink path) so OnDataChange writes and
|
|
// ReadBulk reads both see the same instance. Fall back to a fresh
|
|
// cache for test fakes that supply their own sink — ReadBulk simply
|
|
// never serves cached values in that case.
|
|
MxAccessHandleRegistry handleRegistry = new();
|
|
MxAccessValueCache valueCache;
|
|
if (eventSink is MxAccessBaseEventSink baseSink)
|
|
{
|
|
valueCache = baseSink.ValueCache;
|
|
// Late callbacks for removed handles must not re-create cache
|
|
// entries nothing would ever evict (MXA-004).
|
|
baseSink.BindHandleRegistry(handleRegistry);
|
|
}
|
|
else
|
|
{
|
|
valueCache = new MxAccessValueCache();
|
|
}
|
|
|
|
// Share the sink's completion cache the same way (the production
|
|
// sink and completion-aware test sinks implement the provider
|
|
// seam); fall back to a fresh cache for other fakes — the write
|
|
// executor then simply never observes a completion and replies
|
|
// unconfirmed.
|
|
MxAccessWriteCompletionCache writeCompletionCache = eventSink is IWriteCompletionCacheProvider provider
|
|
? provider.WriteCompletionCache
|
|
: new MxAccessWriteCompletionCache();
|
|
|
|
return new MxAccessSession(
|
|
mxAccessComObject,
|
|
new MxAccessComServer(mxAccessComObject),
|
|
eventSink,
|
|
handleRegistry,
|
|
valueCache,
|
|
writeCompletionCache,
|
|
Environment.CurrentManagedThreadId);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
try
|
|
{
|
|
eventSink.Detach();
|
|
}
|
|
catch
|
|
{
|
|
// Preserve the creation failure while still releasing the COM object below.
|
|
}
|
|
|
|
if (mxAccessComObject is not null && Marshal.IsComObject(mxAccessComObject))
|
|
{
|
|
Marshal.FinalReleaseComObject(mxAccessComObject);
|
|
}
|
|
|
|
throw MxAccessCreationException.From(exception);
|
|
}
|
|
}
|
|
|
|
/// <summary>Registers a client with MXAccess and returns the server handle.</summary>
|
|
/// <param name="clientName">Name of the client to register.</param>
|
|
/// <returns>The server handle assigned to the registered client.</returns>
|
|
public int Register(string clientName)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
int serverHandle = mxAccessServer.Register(clientName);
|
|
handleRegistry.RegisterServerHandle(serverHandle, clientName);
|
|
|
|
return serverHandle;
|
|
}
|
|
|
|
/// <summary>Unregisters a client from MXAccess.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
public void Unregister(int serverHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.Unregister(serverHandle);
|
|
handleRegistry.UnregisterServerHandle(serverHandle);
|
|
// Unregister drops every item under the server in one call, so the
|
|
// per-item evictions in RemoveItem never run for them. Evict both
|
|
// per-handle caches by server so a long-lived worker that registers
|
|
// and unregisters clients does not accumulate one entry per item it
|
|
// ever wrote or read, and a reused server handle id starts clean.
|
|
valueCache.RemoveServer(serverHandle);
|
|
writeCompletionCache.RemoveServer(serverHandle);
|
|
}
|
|
|
|
/// <summary>Adds an item to an MXAccess server and returns the item handle.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemDefinition">Definition or address of the item to add.</param>
|
|
/// <returns>The item handle assigned to the added item.</returns>
|
|
public int AddItem(
|
|
int serverHandle,
|
|
string itemDefinition)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
int itemHandle = mxAccessServer.AddItem(serverHandle, itemDefinition);
|
|
EvictStaleHandleState(serverHandle, itemHandle);
|
|
handleRegistry.RegisterItemHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
itemDefinition,
|
|
string.Empty,
|
|
hasItemContext: false);
|
|
|
|
return itemHandle;
|
|
}
|
|
|
|
/// <summary>Adds an item with context to an MXAccess server and returns the item handle.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemDefinition">Definition or address of the item to add.</param>
|
|
/// <param name="itemContext">Context string for the item.</param>
|
|
/// <returns>The item handle assigned to the added item.</returns>
|
|
public int AddItem2(
|
|
int serverHandle,
|
|
string itemDefinition,
|
|
string itemContext)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
int itemHandle = mxAccessServer.AddItem2(serverHandle, itemDefinition, itemContext);
|
|
EvictStaleHandleState(serverHandle, itemHandle);
|
|
handleRegistry.RegisterItemHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
itemDefinition,
|
|
itemContext,
|
|
hasItemContext: true);
|
|
|
|
return itemHandle;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Drops cached per-handle state left over from a previous lifetime of
|
|
/// a handle id MXAccess just handed out again. RemoveItem and Unregister
|
|
/// already evict, but an OnDataChange or OnWriteComplete that was
|
|
/// queued on the STA when they ran is dispatched afterwards (the loop
|
|
/// pumps between work items) and recreates the entry. Without this, a
|
|
/// reused id would let ReadBulk's cached fast path serve that stale
|
|
/// value as <c>was_cached = true</c>. A handle the registry still
|
|
/// tracks is a live item (MXAccess returned an existing handle), so its
|
|
/// current entries are kept. The production sink now skips cache
|
|
/// writes for handles the registry no longer holds (MXA-004), so this
|
|
/// is the backstop for sinks that are not bound to the registry.
|
|
/// </summary>
|
|
private void EvictStaleHandleState(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
if (handleRegistry.ContainsItemHandle(serverHandle, itemHandle))
|
|
{
|
|
return;
|
|
}
|
|
|
|
valueCache.Remove(serverHandle, itemHandle);
|
|
writeCompletionCache.Remove(serverHandle, itemHandle);
|
|
}
|
|
|
|
/// <summary>Removes an item from an MXAccess server.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
public void RemoveItem(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.RemoveItem(serverHandle, itemHandle);
|
|
handleRegistry.RemoveItemHandle(serverHandle, itemHandle);
|
|
// Evict the last-value entry so a future AddItem + Advise on the
|
|
// same handle id (which MXAccess may reuse) does not serve a stale
|
|
// OnDataChange snapshot from the previous lifetime.
|
|
valueCache.Remove(serverHandle, itemHandle);
|
|
// Same for the OnWriteComplete completion entry: the event sink records
|
|
// one per written handle pair, so without this an AddItem -> Write ->
|
|
// RemoveItem churn grows the cache by one entry per cycle for the life
|
|
// of the worker.
|
|
writeCompletionCache.Remove(serverHandle, itemHandle);
|
|
}
|
|
|
|
/// <summary>Advises on item changes with plain subscription.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
public void Advise(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.Advise(serverHandle, itemHandle);
|
|
handleRegistry.RegisterAdviceHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
MxAccessAdviceKind.Plain);
|
|
}
|
|
|
|
/// <summary>Removes plain advice subscription from an item.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
public void UnAdvise(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.UnAdvise(serverHandle, itemHandle);
|
|
handleRegistry.RemoveAdviceHandles(serverHandle, itemHandle);
|
|
}
|
|
|
|
/// <summary>Advises on item changes with supervisory subscription.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
public void AdviseSupervisory(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.AdviseSupervisory(serverHandle, itemHandle);
|
|
handleRegistry.RegisterAdviceHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
MxAccessAdviceKind.Supervisory);
|
|
}
|
|
|
|
/// <summary>Suspends data acquisition for an advised item and returns the native MXAccess status.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <returns>The boxed native MXAccess status produced by the call.</returns>
|
|
public object Suspend(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
return mxAccessServer.Suspend(serverHandle, itemHandle);
|
|
}
|
|
|
|
/// <summary>Reactivates data acquisition for a suspended item and returns the native MXAccess status.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <returns>The boxed native MXAccess status produced by the call.</returns>
|
|
public object Activate(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
return mxAccessServer.Activate(serverHandle, itemHandle);
|
|
}
|
|
|
|
/// <summary>Authenticates an MXAccess user and returns its user id.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="verifyUser">MXAccess user name to authenticate.</param>
|
|
/// <param name="verifyUserPassword">Raw MXAccess credential; never logged.</param>
|
|
/// <returns>The MXAccess user id for the authenticated user.</returns>
|
|
public int AuthenticateUser(
|
|
int serverHandle,
|
|
string verifyUser,
|
|
string verifyUserPassword)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
return mxAccessServer.AuthenticateUser(serverHandle, verifyUser, verifyUserPassword);
|
|
}
|
|
|
|
/// <summary>Resolves an ArchestrA user GUID to an MXAccess user id.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="userIdGuid">ArchestrA user GUID to resolve.</param>
|
|
/// <returns>The MXAccess user id for the resolved user.</returns>
|
|
public int ArchestrAUserToId(
|
|
int serverHandle,
|
|
string userIdGuid)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
return mxAccessServer.ArchestrAUserToId(serverHandle, userIdGuid);
|
|
}
|
|
|
|
/// <summary>Adds a buffered item to an MXAccess server and returns the item handle.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemDefinition">Definition or address of the item to add.</param>
|
|
/// <param name="itemContext">Context string for the item.</param>
|
|
/// <returns>The item handle assigned to the added item.</returns>
|
|
public int AddBufferedItem(
|
|
int serverHandle,
|
|
string itemDefinition,
|
|
string itemContext)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
int itemHandle = mxAccessServer.AddBufferedItem(serverHandle, itemDefinition, itemContext);
|
|
EvictStaleHandleState(serverHandle, itemHandle);
|
|
handleRegistry.RegisterItemHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
itemDefinition,
|
|
itemContext,
|
|
hasItemContext: true);
|
|
|
|
return itemHandle;
|
|
}
|
|
|
|
/// <summary>Sets the buffered-update interval for an MXAccess server.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="updateIntervalMilliseconds">Buffered update interval in milliseconds.</param>
|
|
public void SetBufferedUpdateInterval(
|
|
int serverHandle,
|
|
int updateIntervalMilliseconds)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.SetBufferedUpdateInterval(serverHandle, updateIntervalMilliseconds);
|
|
}
|
|
|
|
/// <summary>Writes a value to an item.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <param name="value">COM-marshalable value to write.</param>
|
|
/// <param name="userId">MXAccess user id (security classification) for the write.</param>
|
|
public void Write(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
object? value,
|
|
int userId)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.Write(serverHandle, itemHandle, value, userId);
|
|
}
|
|
|
|
/// <summary>Writes a value with an explicit source timestamp to an item.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <param name="value">COM-marshalable value to write.</param>
|
|
/// <param name="timestamp">COM-marshalable source timestamp for the write.</param>
|
|
/// <param name="userId">MXAccess user id (security classification) for the write.</param>
|
|
public void Write2(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
object? value,
|
|
object? timestamp,
|
|
int userId)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.Write2(serverHandle, itemHandle, value, timestamp, userId);
|
|
}
|
|
|
|
/// <summary>Performs a secured/verified write to an item.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <param name="currentUserId">MXAccess user id of the operator performing the write.</param>
|
|
/// <param name="verifierUserId">MXAccess user id of the verifier authorizing the write.</param>
|
|
/// <param name="value">COM-marshalable value to write.</param>
|
|
public void WriteSecured(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
int currentUserId,
|
|
int verifierUserId,
|
|
object? value)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.WriteSecured(serverHandle, itemHandle, currentUserId, verifierUserId, value);
|
|
}
|
|
|
|
/// <summary>Performs a secured/verified write with an explicit source timestamp.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandle">Handle returned by the worker.</param>
|
|
/// <param name="currentUserId">MXAccess user id of the operator performing the write.</param>
|
|
/// <param name="verifierUserId">MXAccess user id of the verifier authorizing the write.</param>
|
|
/// <param name="value">COM-marshalable value to write.</param>
|
|
/// <param name="timestamp">COM-marshalable source timestamp for the write.</param>
|
|
public void WriteSecured2(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
int currentUserId,
|
|
int verifierUserId,
|
|
object? value,
|
|
object? timestamp)
|
|
{
|
|
ThrowIfDisposed();
|
|
|
|
mxAccessServer.WriteSecured2(serverHandle, itemHandle, currentUserId, verifierUserId, value, timestamp);
|
|
}
|
|
|
|
/// <summary>Adds multiple items in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="tagAddresses">Enumerable of item definitions to add.</param>
|
|
/// <returns>The per-item success/failure results, in the order the tags were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> AddItemBulk(
|
|
int serverHandle,
|
|
IEnumerable<string> tagAddresses)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (tagAddresses is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(tagAddresses));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (string? tagAddress in tagAddresses)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(tagAddress))
|
|
{
|
|
results.Add(Failed(serverHandle, tagAddress ?? string.Empty, itemHandle: 0, "Tag address is required."));
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
int itemHandle = AddItem(serverHandle, tagAddress);
|
|
results.Add(Succeeded(serverHandle, tagAddress, itemHandle));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
results.Add(Failed(serverHandle, tagAddress, itemHandle: 0, exception.Message));
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Advises on multiple items in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandles">Enumerable of item handles to advise on.</param>
|
|
/// <returns>The per-item success/failure results, in the order the handles were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> AdviseItemBulk(
|
|
int serverHandle,
|
|
IEnumerable<int> itemHandles)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (itemHandles is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(itemHandles));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (int itemHandle in itemHandles)
|
|
{
|
|
try
|
|
{
|
|
Advise(serverHandle, itemHandle);
|
|
results.Add(Succeeded(serverHandle, string.Empty, itemHandle));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
results.Add(Failed(serverHandle, string.Empty, itemHandle, exception.Message));
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Removes multiple items in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandles">Enumerable of item handles to remove.</param>
|
|
/// <returns>The per-item success/failure results, in the order the handles were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> RemoveItemBulk(
|
|
int serverHandle,
|
|
IEnumerable<int> itemHandles)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (itemHandles is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(itemHandles));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (int itemHandle in itemHandles)
|
|
{
|
|
try
|
|
{
|
|
RemoveItem(serverHandle, itemHandle);
|
|
results.Add(Succeeded(serverHandle, string.Empty, itemHandle));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
results.Add(Failed(serverHandle, string.Empty, itemHandle, exception.Message));
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Removes advice subscriptions from multiple items in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandles">Enumerable of item handles to unadvise.</param>
|
|
/// <returns>The per-item success/failure results, in the order the handles were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> UnAdviseItemBulk(
|
|
int serverHandle,
|
|
IEnumerable<int> itemHandles)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (itemHandles is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(itemHandles));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (int itemHandle in itemHandles)
|
|
{
|
|
try
|
|
{
|
|
UnAdvise(serverHandle, itemHandle);
|
|
results.Add(Succeeded(serverHandle, string.Empty, itemHandle));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
results.Add(Failed(serverHandle, string.Empty, itemHandle, exception.Message));
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Adds multiple items and subscribes to them in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="tagAddresses">Enumerable of item definitions to add and subscribe to.</param>
|
|
/// <returns>The per-item success/failure results, in the order the tags were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> SubscribeBulk(
|
|
int serverHandle,
|
|
IEnumerable<string> tagAddresses)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (tagAddresses is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(tagAddresses));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (string? tagAddress in tagAddresses)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(tagAddress))
|
|
{
|
|
results.Add(Failed(serverHandle, tagAddress ?? string.Empty, itemHandle: 0, "Tag address is required."));
|
|
continue;
|
|
}
|
|
|
|
int itemHandle = 0;
|
|
try
|
|
{
|
|
itemHandle = AddItem(serverHandle, tagAddress);
|
|
Advise(serverHandle, itemHandle);
|
|
results.Add(Succeeded(serverHandle, tagAddress, itemHandle));
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
string errorMessage = exception.Message;
|
|
if (itemHandle != 0)
|
|
{
|
|
errorMessage = AppendRemoveItemCleanup(serverHandle, itemHandle, errorMessage);
|
|
}
|
|
|
|
results.Add(Failed(serverHandle, tagAddress, itemHandle, errorMessage));
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Unsubscribes from multiple items in bulk, returning success/failure results.</summary>
|
|
/// <param name="serverHandle">Handle returned by the worker.</param>
|
|
/// <param name="itemHandles">Enumerable of item handles to unsubscribe from.</param>
|
|
/// <returns>The per-item success/failure results, in the order the handles were provided.</returns>
|
|
public IReadOnlyList<SubscribeResult> UnsubscribeBulk(
|
|
int serverHandle,
|
|
IEnumerable<int> itemHandles)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (itemHandles is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(itemHandles));
|
|
}
|
|
|
|
List<SubscribeResult> results = new();
|
|
foreach (int itemHandle in itemHandles)
|
|
{
|
|
List<string> errors = new();
|
|
|
|
try
|
|
{
|
|
UnAdvise(serverHandle, itemHandle);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
errors.Add($"UnAdvise failed: {exception.Message}");
|
|
}
|
|
|
|
try
|
|
{
|
|
RemoveItem(serverHandle, itemHandle);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
errors.Add($"RemoveItem failed: {exception.Message}");
|
|
}
|
|
|
|
results.Add(errors.Count == 0
|
|
? Succeeded(serverHandle, string.Empty, itemHandle)
|
|
: Failed(serverHandle, string.Empty, itemHandle, string.Join("; ", errors)));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulk write — runs <see cref="Write"/> sequentially for each entry.
|
|
/// Each entry's <paramref name="convertValue"/> turns the protobuf
|
|
/// MxValue into a COM-marshalable variant. Per-item failures are
|
|
/// captured as <see cref="BulkWriteResult"/> entries with
|
|
/// <c>was_successful = false</c>; the loop never throws.
|
|
/// </summary>
|
|
/// <param name="serverHandle">The MXAccess server handle.</param>
|
|
/// <param name="entries">The write entries to process.</param>
|
|
/// <param name="convertValue">Converts protobuf MxValue to COM-compatible variant.</param>
|
|
/// <returns>The per-entry write results, in the order the entries were provided.</returns>
|
|
public IReadOnlyList<BulkWriteResult> WriteBulk(
|
|
int serverHandle,
|
|
IReadOnlyList<WriteBulkEntry> entries,
|
|
Func<MxValue, object?> convertValue)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (entries is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(entries));
|
|
}
|
|
|
|
if (convertValue is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertValue));
|
|
}
|
|
|
|
List<BulkWriteResult> results = new(entries.Count);
|
|
foreach (WriteBulkEntry entry in entries)
|
|
{
|
|
results.Add(ExecuteBulkWriteEntry(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
() => Write(serverHandle, entry.ItemHandle, convertValue(entry.Value), entry.UserId)));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Bulk Write2 — sequential MXAccess <see cref="Write2"/> per entry.</summary>
|
|
/// <param name="serverHandle">The MXAccess server handle.</param>
|
|
/// <param name="entries">The write2 entries to process.</param>
|
|
/// <param name="convertValue">Converts protobuf MxValue to COM-compatible variant.</param>
|
|
/// <param name="convertTimestamp">
|
|
/// Converts the per-entry time argument; it differs from
|
|
/// <paramref name="convertValue"/> because MXAccess reads the time argument as box-local time (#228).
|
|
/// </param>
|
|
/// <returns>The per-entry write results, in the order the entries were provided.</returns>
|
|
public IReadOnlyList<BulkWriteResult> Write2Bulk(
|
|
int serverHandle,
|
|
IReadOnlyList<Write2BulkEntry> entries,
|
|
Func<MxValue, object?> convertValue,
|
|
Func<MxValue, object?> convertTimestamp)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (entries is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(entries));
|
|
}
|
|
|
|
if (convertValue is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertValue));
|
|
}
|
|
|
|
if (convertTimestamp is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertTimestamp));
|
|
}
|
|
|
|
List<BulkWriteResult> results = new(entries.Count);
|
|
foreach (Write2BulkEntry entry in entries)
|
|
{
|
|
results.Add(ExecuteBulkWriteEntry(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
() => Write2(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
convertValue(entry.Value),
|
|
convertTimestamp(entry.TimestampValue),
|
|
entry.UserId)));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Bulk WriteSecured — sequential MXAccess <see cref="WriteSecured"/> per entry.</summary>
|
|
/// <param name="serverHandle">The MXAccess server handle.</param>
|
|
/// <param name="entries">The WriteSecured entries to process.</param>
|
|
/// <param name="convertValue">Converts protobuf MxValue to COM-compatible variant.</param>
|
|
/// <returns>The per-entry write results, in the order the entries were provided.</returns>
|
|
public IReadOnlyList<BulkWriteResult> WriteSecuredBulk(
|
|
int serverHandle,
|
|
IReadOnlyList<WriteSecuredBulkEntry> entries,
|
|
Func<MxValue, object?> convertValue)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (entries is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(entries));
|
|
}
|
|
|
|
if (convertValue is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertValue));
|
|
}
|
|
|
|
List<BulkWriteResult> results = new(entries.Count);
|
|
foreach (WriteSecuredBulkEntry entry in entries)
|
|
{
|
|
results.Add(ExecuteBulkWriteEntry(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
() => WriteSecured(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
entry.CurrentUserId,
|
|
entry.VerifierUserId,
|
|
convertValue(entry.Value))));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>Bulk WriteSecured2 — sequential MXAccess <see cref="WriteSecured2"/> per entry.</summary>
|
|
/// <param name="serverHandle">The MXAccess server handle.</param>
|
|
/// <param name="entries">The WriteSecured2 entries to process.</param>
|
|
/// <param name="convertValue">Converts protobuf MxValue to COM-compatible variant.</param>
|
|
/// <param name="convertTimestamp">
|
|
/// Converts the per-entry time argument; it differs from
|
|
/// <paramref name="convertValue"/> because MXAccess reads the time argument as box-local time (#228).
|
|
/// </param>
|
|
/// <returns>The per-entry write results, in the order the entries were provided.</returns>
|
|
public IReadOnlyList<BulkWriteResult> WriteSecured2Bulk(
|
|
int serverHandle,
|
|
IReadOnlyList<WriteSecured2BulkEntry> entries,
|
|
Func<MxValue, object?> convertValue,
|
|
Func<MxValue, object?> convertTimestamp)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (entries is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(entries));
|
|
}
|
|
|
|
if (convertValue is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertValue));
|
|
}
|
|
|
|
if (convertTimestamp is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(convertTimestamp));
|
|
}
|
|
|
|
List<BulkWriteResult> results = new(entries.Count);
|
|
foreach (WriteSecured2BulkEntry entry in entries)
|
|
{
|
|
results.Add(ExecuteBulkWriteEntry(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
() => WriteSecured2(
|
|
serverHandle,
|
|
entry.ItemHandle,
|
|
entry.CurrentUserId,
|
|
entry.VerifierUserId,
|
|
convertValue(entry.Value),
|
|
convertTimestamp(entry.TimestampValue))));
|
|
}
|
|
|
|
return results;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulk read snapshot. For each requested tag, returns the most recent
|
|
/// OnDataChange value if the tag is already advised AND a cached value
|
|
/// exists (no subscription side effects); otherwise waits for the first
|
|
/// OnDataChange. A tag the caller already advised is waited on through
|
|
/// the caller's own subscription, untouched; a tag the caller added but
|
|
/// did not advise is advised temporarily and unadvised afterwards, its
|
|
/// item kept; any other tag takes the AddItem + Advise + wait +
|
|
/// UnAdvise + RemoveItem snapshot lifecycle itself. ReadBulk never
|
|
/// unadvises or removes anything the caller created.
|
|
/// <paramref name="timeout"/> bounds the wait for every snapshot tag;
|
|
/// <paramref name="pumpStep"/> is invoked on every poll iteration so the
|
|
/// worker's STA can dispatch the incoming MXAccess message that carries
|
|
/// the value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The snapshot tags are processed in phases rather than one at a time:
|
|
/// every cache probe runs first, then every uncached tag is added and
|
|
/// advised, then one wait with a single shared deadline collects the
|
|
/// first OnDataChange per handle, then every snapshot handle is torn
|
|
/// down. A serial lifecycle held the STA for up to N x timeout when N
|
|
/// tags never produced a value; the phased form holds it for at most
|
|
/// one timeout. Each tag's result is still its own: a tag that never
|
|
/// delivered fails with the same timed-out diagnostic and its own item
|
|
/// handle, an AddItem or Advise failure fails only that tag, and results
|
|
/// keep request order. The cache probes run before any snapshot AddItem
|
|
/// so a later tag can never be served from an earlier tag's own
|
|
/// snapshot subscription.
|
|
/// </remarks>
|
|
/// <param name="serverHandle">The MXAccess server handle.</param>
|
|
/// <param name="tagAddresses">The tag addresses to read.</param>
|
|
/// <param name="timeout">The timeout bounding the shared snapshot wait.</param>
|
|
/// <param name="pumpStep">Action invoked on each poll iteration.</param>
|
|
/// <returns>The per-tag read results, in the order the tags were provided.</returns>
|
|
public IReadOnlyList<BulkReadResult> ReadBulk(
|
|
int serverHandle,
|
|
IReadOnlyList<string> tagAddresses,
|
|
TimeSpan timeout,
|
|
Action pumpStep)
|
|
{
|
|
ThrowIfDisposed();
|
|
if (tagAddresses is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(tagAddresses));
|
|
}
|
|
|
|
if (pumpStep is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(pumpStep));
|
|
}
|
|
|
|
int tagCount = tagAddresses.Count;
|
|
BulkReadResult?[] results = new BulkReadResult?[tagCount];
|
|
List<SnapshotRead> snapshots = new();
|
|
|
|
// Phase 1: validation and the cached-and-advised fast path. A tag
|
|
// already advised by the caller with a cached value is answered without
|
|
// touching the existing subscription — the caller didn't create it, so
|
|
// ReadBulk must not tear it down.
|
|
for (int index = 0; index < tagCount; index++)
|
|
{
|
|
string? tagAddress = tagAddresses[index];
|
|
if (string.IsNullOrWhiteSpace(tagAddress))
|
|
{
|
|
results[index] = FailedRead(serverHandle, tagAddress ?? string.Empty, itemHandle: 0, wasCached: false, "Tag address is required.");
|
|
continue;
|
|
}
|
|
|
|
if (TryGetCachedReadFor(serverHandle, tagAddress!, out int cachedItemHandle, out MxAccessValueCache.CachedValue cachedValue))
|
|
{
|
|
results[index] = SucceededRead(serverHandle, tagAddress!, cachedItemHandle, wasCached: true, cachedValue);
|
|
continue;
|
|
}
|
|
|
|
// A tag the caller already added (advised or not) is read through
|
|
// the caller's own item handle rather than a fresh AddItem (#238).
|
|
// The installed MXAccess hands out a new handle per AddItem even
|
|
// for an address already added, so a separate snapshot item does
|
|
// not disturb the caller's; but it costs an extra item plus four
|
|
// COM calls per tag, and the snapshot teardown would destroy the
|
|
// caller's item and advice on any build or address form that hands
|
|
// back the existing handle. Phase 2 only advises the caller's
|
|
// handle when the caller has not, and phase 4 never removes it.
|
|
SnapshotRead snapshot = new(index, tagAddress!);
|
|
if (TryGetRegisteredHandleFor(serverHandle, tagAddress!, out int registeredItemHandle, out bool callerAdvised))
|
|
{
|
|
snapshot.ItemHandle = registeredItemHandle;
|
|
if (callerAdvised)
|
|
{
|
|
// Capture the baseline now, before any phase-2 pump can
|
|
// dispatch the caller's first OnDataChange; a later capture
|
|
// would count that value as already seen and wait for a
|
|
// second one.
|
|
snapshot.Baseline = valueCache.CurrentVersion(serverHandle, registeredItemHandle);
|
|
snapshot.BaselineCaptured = true;
|
|
}
|
|
}
|
|
|
|
snapshots.Add(snapshot);
|
|
}
|
|
|
|
if (snapshots.Count > 0)
|
|
{
|
|
try
|
|
{
|
|
ReadSnapshots(serverHandle, snapshots, results, timeout, pumpStep);
|
|
}
|
|
finally
|
|
{
|
|
TearDownSnapshots(serverHandle, snapshots, pumpStep);
|
|
}
|
|
}
|
|
|
|
List<BulkReadResult> ordered = new(tagCount);
|
|
for (int index = 0; index < tagCount; index++)
|
|
{
|
|
ordered.Add(results[index]!);
|
|
}
|
|
|
|
return ordered;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Number of snapshot items ReadBulk adds/advises (phase 2) or tears
|
|
/// down (phase 4) between pump steps. Those phases make one or two COM
|
|
/// calls per tag without waiting, so a large batch would otherwise hold
|
|
/// the STA with no pump and no activity mark for its whole length; a
|
|
/// pump every <see cref="ReadBulkPumpInterval"/> items keeps inbound
|
|
/// callbacks flowing and keeps the STA heartbeat fresh, so a big batch
|
|
/// cannot drift toward <c>HeartbeatStuckCeiling</c>.
|
|
/// </summary>
|
|
internal const int ReadBulkPumpInterval = 16;
|
|
|
|
private void ReadSnapshots(
|
|
int serverHandle,
|
|
List<SnapshotRead> snapshots,
|
|
BulkReadResult?[] results,
|
|
TimeSpan timeout,
|
|
Action pumpStep)
|
|
{
|
|
// Phase 2: make sure every uncached tag has an advised item handle to
|
|
// wait on. A per-tag AddItem/Advise failure fails only that tag.
|
|
// - A tag the caller never added gets ReadBulk's own AddItem and
|
|
// Advise; ReadBulk owns both and phase 4 undoes both.
|
|
// - A tag the caller added but did not advise (phase 1 resolved its
|
|
// handle, or AddItem handed back a handle the registry already
|
|
// tracked) is advised temporarily; phase 4 undoes only the advice.
|
|
// - A tag the caller already advised is waited on through the
|
|
// caller's own subscription; ReadBulk makes no COM call for it and
|
|
// phase 4 leaves it alone.
|
|
// When a handle is already in play earlier in this batch (a duplicate
|
|
// address), the later tag shares the earlier tag's wait instead of
|
|
// touching the handle a second time, and gets the same outcome fanned
|
|
// out to it after the wait.
|
|
List<SnapshotRead> waiting = new(snapshots.Count);
|
|
Dictionary<int, SnapshotRead> waitingByHandle = new();
|
|
List<SnapshotRead> sharing = new();
|
|
for (int position = 0; position < snapshots.Count; position++)
|
|
{
|
|
SnapshotRead snapshot = snapshots[position];
|
|
try
|
|
{
|
|
if (position > 0 && position % ReadBulkPumpInterval == 0)
|
|
{
|
|
pumpStep();
|
|
}
|
|
|
|
if (snapshot.ItemHandle == 0)
|
|
{
|
|
snapshot.ItemHandle = AddSnapshotItem(serverHandle, snapshot.TagAddress, out bool ownsItem);
|
|
snapshot.OwnsItem = ownsItem;
|
|
}
|
|
|
|
if (waitingByHandle.TryGetValue(snapshot.ItemHandle, out SnapshotRead? owner))
|
|
{
|
|
snapshot.SharedWith = owner;
|
|
sharing.Add(snapshot);
|
|
continue;
|
|
}
|
|
|
|
if (!snapshot.BaselineCaptured)
|
|
{
|
|
snapshot.Baseline = valueCache.CurrentVersion(serverHandle, snapshot.ItemHandle);
|
|
snapshot.BaselineCaptured = true;
|
|
}
|
|
|
|
if (!IsAdvised(serverHandle, snapshot.ItemHandle))
|
|
{
|
|
Advise(serverHandle, snapshot.ItemHandle);
|
|
snapshot.Advised = true;
|
|
}
|
|
|
|
waitingByHandle[snapshot.ItemHandle] = snapshot;
|
|
waiting.Add(snapshot);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
results[snapshot.Index] = FailedRead(serverHandle, snapshot.TagAddress, snapshot.ItemHandle, wasCached: false, exception.Message);
|
|
}
|
|
}
|
|
|
|
if (waiting.Count > 0)
|
|
{
|
|
WaitForSnapshots(serverHandle, waiting, results, timeout, pumpStep);
|
|
}
|
|
|
|
foreach (SnapshotRead duplicate in sharing)
|
|
{
|
|
BulkReadResult? ownerResult = results[duplicate.SharedWith!.Index];
|
|
if (ownerResult is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
BulkReadResult fanned = ownerResult.Clone();
|
|
fanned.TagAddress = duplicate.TagAddress;
|
|
results[duplicate.Index] = fanned;
|
|
}
|
|
}
|
|
|
|
private void WaitForSnapshots(
|
|
int serverHandle,
|
|
List<SnapshotRead> waiting,
|
|
BulkReadResult?[] results,
|
|
TimeSpan timeout,
|
|
Action pumpStep)
|
|
{
|
|
// Phase 3: one shared deadline. Pump until every advised handle has
|
|
// seen its first OnDataChange since its baseline, or the deadline
|
|
// elapses.
|
|
int[] itemHandles = new int[waiting.Count];
|
|
ulong[] baselines = new ulong[waiting.Count];
|
|
for (int index = 0; index < waiting.Count; index++)
|
|
{
|
|
itemHandles[index] = waiting[index].ItemHandle;
|
|
baselines[index] = waiting[index].Baseline;
|
|
}
|
|
|
|
bool[] received = new bool[waiting.Count];
|
|
MxAccessValueCache.CachedValue[] values = new MxAccessValueCache.CachedValue[waiting.Count];
|
|
try
|
|
{
|
|
DateTime deadline = DateTime.UtcNow + timeout;
|
|
valueCache.TryWaitForUpdates(serverHandle, itemHandles, baselines, deadline, pumpStep, received, values);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
// A pump failure ends the wait for every tag still outstanding;
|
|
// tags captured before it keep their values.
|
|
for (int index = 0; index < waiting.Count; index++)
|
|
{
|
|
if (!received[index])
|
|
{
|
|
SnapshotRead failed = waiting[index];
|
|
results[failed.Index] = FailedRead(serverHandle, failed.TagAddress, failed.ItemHandle, wasCached: false, exception.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int index = 0; index < waiting.Count; index++)
|
|
{
|
|
SnapshotRead snapshot = waiting[index];
|
|
if (results[snapshot.Index] is not null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
results[snapshot.Index] = received[index]
|
|
? SucceededRead(serverHandle, snapshot.TagAddress, snapshot.ItemHandle, wasCached: false, values[index])
|
|
: FailedRead(
|
|
serverHandle,
|
|
snapshot.TagAddress,
|
|
snapshot.ItemHandle,
|
|
wasCached: false,
|
|
$"ReadBulk timed out after {timeout.TotalMilliseconds:F0} ms waiting for first OnDataChange.");
|
|
}
|
|
}
|
|
|
|
private void TearDownSnapshots(
|
|
int serverHandle,
|
|
List<SnapshotRead> snapshots,
|
|
Action pumpStep)
|
|
{
|
|
// Phase 4: snapshot teardown — best-effort, never re-throws. It undoes
|
|
// only what phase 2 did: an advice ReadBulk made is unadvised and an
|
|
// item ReadBulk added is removed, each exactly once even when MXAccess
|
|
// handed the same id to several tags in the batch. A handle the
|
|
// caller held before this call keeps its item, and keeps its advice
|
|
// unless ReadBulk was the one that advised it.
|
|
HashSet<int> unadvised = new();
|
|
HashSet<int> removed = new();
|
|
int calls = 0;
|
|
foreach (SnapshotRead snapshot in snapshots)
|
|
{
|
|
if (snapshot.Advised && unadvised.Add(snapshot.ItemHandle))
|
|
{
|
|
PumpEvery(ref calls, pumpStep);
|
|
try
|
|
{
|
|
UnAdvise(serverHandle, snapshot.ItemHandle);
|
|
if (!snapshot.OwnsItem)
|
|
{
|
|
// The caller's item outlives this call, so drop the
|
|
// value ReadBulk's temporary advice cached: a later
|
|
// caller Advise followed by a ReadBulk must wait for
|
|
// the caller's own OnDataChange instead of being served
|
|
// this snapshot as was_cached = true.
|
|
valueCache.Remove(serverHandle, snapshot.ItemHandle);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// swallow — best effort
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (SnapshotRead snapshot in snapshots)
|
|
{
|
|
if (snapshot.OwnsItem && removed.Add(snapshot.ItemHandle))
|
|
{
|
|
PumpEvery(ref calls, pumpStep);
|
|
try { RemoveItem(serverHandle, snapshot.ItemHandle); } catch { /* swallow — best effort */ }
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// AddItem for a tag phase 1 found no registered handle for. Should
|
|
/// MXAccess hand back a handle the registry already tracks (for example
|
|
/// an address it treats as the same item under a different spelling),
|
|
/// that handle is the caller's, so it is neither re-registered (which
|
|
/// would overwrite the caller's definition and context) nor owned by
|
|
/// ReadBulk.
|
|
/// </summary>
|
|
private int AddSnapshotItem(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
out bool ownsItem)
|
|
{
|
|
int itemHandle = mxAccessServer.AddItem(serverHandle, tagAddress);
|
|
if (handleRegistry.ContainsItemHandle(serverHandle, itemHandle))
|
|
{
|
|
ownsItem = false;
|
|
return itemHandle;
|
|
}
|
|
|
|
EvictStaleHandleState(serverHandle, itemHandle);
|
|
handleRegistry.RegisterItemHandle(
|
|
serverHandle,
|
|
itemHandle,
|
|
tagAddress,
|
|
string.Empty,
|
|
hasItemContext: false);
|
|
ownsItem = true;
|
|
return itemHandle;
|
|
}
|
|
|
|
private bool IsAdvised(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
return handleRegistry.ContainsAdviceHandle(serverHandle, itemHandle, MxAccessAdviceKind.Plain)
|
|
|| handleRegistry.ContainsAdviceHandle(serverHandle, itemHandle, MxAccessAdviceKind.Supervisory);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finds an item handle the caller already registered for the tag,
|
|
/// preferring one the caller has advised (its subscription will deliver
|
|
/// the value without ReadBulk touching it).
|
|
/// </summary>
|
|
private bool TryGetRegisteredHandleFor(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
out int itemHandle,
|
|
out bool advised)
|
|
{
|
|
IReadOnlyList<int> candidates = handleRegistry.GetItemHandlesForDefinition(serverHandle, tagAddress);
|
|
for (int index = 0; index < candidates.Count; index++)
|
|
{
|
|
if (IsAdvised(serverHandle, candidates[index]))
|
|
{
|
|
itemHandle = candidates[index];
|
|
advised = true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
advised = false;
|
|
if (candidates.Count > 0)
|
|
{
|
|
itemHandle = candidates[0];
|
|
return true;
|
|
}
|
|
|
|
itemHandle = 0;
|
|
return false;
|
|
}
|
|
|
|
private static void PumpEvery(ref int calls, Action pumpStep)
|
|
{
|
|
if (calls > 0 && calls % ReadBulkPumpInterval == 0)
|
|
{
|
|
try { pumpStep(); } catch { /* swallow — teardown is best effort */ }
|
|
}
|
|
|
|
calls++;
|
|
}
|
|
|
|
private bool TryGetCachedReadFor(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
out int itemHandle,
|
|
out MxAccessValueCache.CachedValue cachedValue)
|
|
{
|
|
// Dictionary probe, not a scan: the registry keeps a reverse
|
|
// (server handle, item definition) → item handle index, so a bulk read
|
|
// no longer walks the whole item table once per tag. The index matches
|
|
// the tag ordinally and hands the handles back in ascending order — the
|
|
// same order the previous linear scan over the sorted ItemHandles view
|
|
// visited them — so the first advised-and-cached candidate still wins.
|
|
IReadOnlyList<int> candidates = handleRegistry.GetItemHandlesForDefinition(serverHandle, tagAddress);
|
|
|
|
for (int index = 0; index < candidates.Count; index++)
|
|
{
|
|
int candidate = candidates[index];
|
|
|
|
if (!IsAdvised(serverHandle, candidate))
|
|
{
|
|
// Tag is added but not advised — no fresh OnDataChange will
|
|
// arrive without us advising. Fall through to the snapshot
|
|
// path, which advises this handle temporarily.
|
|
continue;
|
|
}
|
|
|
|
if (valueCache.TryGet(serverHandle, candidate, out cachedValue))
|
|
{
|
|
itemHandle = candidate;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
itemHandle = 0;
|
|
cachedValue = default;
|
|
return false;
|
|
}
|
|
|
|
private BulkWriteResult ExecuteBulkWriteEntry(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
Action invokeWrite)
|
|
{
|
|
try
|
|
{
|
|
invokeWrite();
|
|
return new BulkWriteResult
|
|
{
|
|
ServerHandle = serverHandle,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = true,
|
|
ErrorMessage = string.Empty,
|
|
};
|
|
}
|
|
catch (System.Runtime.InteropServices.COMException comException)
|
|
{
|
|
BulkWriteResult result = new()
|
|
{
|
|
ServerHandle = serverHandle,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = false,
|
|
ErrorMessage = comException.Message,
|
|
};
|
|
result.Hresult = comException.HResult;
|
|
return result;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
return new BulkWriteResult
|
|
{
|
|
ServerHandle = serverHandle,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = false,
|
|
ErrorMessage = exception.Message,
|
|
};
|
|
}
|
|
}
|
|
|
|
private static BulkReadResult SucceededRead(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
int itemHandle,
|
|
bool wasCached,
|
|
MxAccessValueCache.CachedValue snapshot)
|
|
{
|
|
BulkReadResult result = new()
|
|
{
|
|
ServerHandle = serverHandle,
|
|
TagAddress = tagAddress,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = true,
|
|
WasCached = wasCached,
|
|
Quality = snapshot.Quality,
|
|
ErrorMessage = string.Empty,
|
|
};
|
|
|
|
if (snapshot.Value is not null)
|
|
{
|
|
result.Value = snapshot.Value;
|
|
}
|
|
|
|
if (snapshot.SourceTimestamp is not null)
|
|
{
|
|
result.SourceTimestamp = snapshot.SourceTimestamp;
|
|
}
|
|
|
|
if (snapshot.Statuses is not null)
|
|
{
|
|
result.Statuses.Add(snapshot.Statuses);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static BulkReadResult FailedRead(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
int itemHandle,
|
|
bool wasCached,
|
|
string errorMessage)
|
|
{
|
|
return new BulkReadResult
|
|
{
|
|
ServerHandle = serverHandle,
|
|
TagAddress = tagAddress,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = false,
|
|
WasCached = wasCached,
|
|
ErrorMessage = errorMessage,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Optional sink for per-step shutdown diagnostics (Debug level). Defaults to
|
|
/// <see cref="System.Diagnostics.Debug.WriteLine(string)"/>. Tests substitute a collector.
|
|
/// </summary>
|
|
internal Action<string>? ShutdownStepSink { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gracefully shuts down the session. Unregister runs first (R21-K10): MXAccess
|
|
/// removes a server's items and advise subscriptions with it, so a successful
|
|
/// Unregister makes the per-item UnAdvise/RemoveItem calls redundant for that server.
|
|
/// Only for a server whose Unregister FAILED does the fallback UnAdvise then
|
|
/// RemoveItem sweep run over its remaining handles. Every step is guarded so one
|
|
/// failure never skips the rest; calling it again after completion is a no-op.
|
|
/// </summary>
|
|
/// <returns>The shutdown result, including any per-handle cleanup failures.</returns>
|
|
public MxAccessShutdownResult ShutdownGracefully()
|
|
{
|
|
if (disposed)
|
|
{
|
|
return new MxAccessShutdownResult(Array.Empty<MxAccessShutdownFailure>());
|
|
}
|
|
|
|
List<MxAccessShutdownFailure> failures = new();
|
|
|
|
HashSet<int> unregisteredFailed = CleanupServerHandles(failures);
|
|
if (unregisteredFailed.Count > 0)
|
|
{
|
|
CleanupAdviceHandles(failures, unregisteredFailed);
|
|
CleanupItemHandles(failures, unregisteredFailed);
|
|
}
|
|
|
|
DisposeCore(failures);
|
|
|
|
return new MxAccessShutdownResult(failures);
|
|
}
|
|
|
|
private void LogShutdownStep(string message)
|
|
{
|
|
try
|
|
{
|
|
if (ShutdownStepSink is { } sink)
|
|
{
|
|
sink(message);
|
|
}
|
|
else
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("MxAccessSession shutdown: " + message);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Diagnostics must never break cleanup.
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Dispose()
|
|
{
|
|
if (disposed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
DisposeCore(failures: null);
|
|
}
|
|
|
|
private void CleanupAdviceHandles(
|
|
ICollection<MxAccessShutdownFailure> failures,
|
|
HashSet<int> serverHandles)
|
|
{
|
|
HashSet<long> cleanedPairs = new();
|
|
foreach (RegisteredAdviceHandle adviceHandle in handleRegistry.AdviceHandles)
|
|
{
|
|
if (!serverHandles.Contains(adviceHandle.ServerHandle))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
long key = CreateItemKey(adviceHandle.ServerHandle, adviceHandle.ItemHandle);
|
|
if (!cleanedPairs.Add(key))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
mxAccessServer.UnAdvise(adviceHandle.ServerHandle, adviceHandle.ItemHandle);
|
|
handleRegistry.RemoveAdviceHandles(adviceHandle.ServerHandle, adviceHandle.ItemHandle);
|
|
LogShutdownStep($"UnAdvise server={adviceHandle.ServerHandle} item={adviceHandle.ItemHandle} ok (fallback)");
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
LogShutdownStep($"UnAdvise server={adviceHandle.ServerHandle} item={adviceHandle.ItemHandle} failed: {exception.GetType().Name}");
|
|
failures.Add(new MxAccessShutdownFailure(
|
|
nameof(UnAdvise),
|
|
adviceHandle.ServerHandle,
|
|
adviceHandle.ItemHandle,
|
|
exception));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CleanupItemHandles(
|
|
ICollection<MxAccessShutdownFailure> failures,
|
|
HashSet<int> serverHandles)
|
|
{
|
|
foreach (RegisteredItemHandle itemHandle in handleRegistry.ItemHandles)
|
|
{
|
|
if (!serverHandles.Contains(itemHandle.ServerHandle))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
try
|
|
{
|
|
mxAccessServer.RemoveItem(itemHandle.ServerHandle, itemHandle.ItemHandle);
|
|
handleRegistry.RemoveItemHandle(itemHandle.ServerHandle, itemHandle.ItemHandle);
|
|
LogShutdownStep($"RemoveItem server={itemHandle.ServerHandle} item={itemHandle.ItemHandle} ok (fallback)");
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
LogShutdownStep($"RemoveItem server={itemHandle.ServerHandle} item={itemHandle.ItemHandle} failed: {exception.GetType().Name}");
|
|
failures.Add(new MxAccessShutdownFailure(
|
|
nameof(RemoveItem),
|
|
itemHandle.ServerHandle,
|
|
itemHandle.ItemHandle,
|
|
exception));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Unregisters every tracked server first; returns the handles whose Unregister failed.</summary>
|
|
private HashSet<int> CleanupServerHandles(ICollection<MxAccessShutdownFailure> failures)
|
|
{
|
|
HashSet<int> failed = new();
|
|
foreach (RegisteredServerHandle serverHandle in handleRegistry.ServerHandles)
|
|
{
|
|
try
|
|
{
|
|
mxAccessServer.Unregister(serverHandle.ServerHandle);
|
|
handleRegistry.UnregisterServerHandle(serverHandle.ServerHandle);
|
|
LogShutdownStep($"Unregister server={serverHandle.ServerHandle} ok");
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
failed.Add(serverHandle.ServerHandle);
|
|
LogShutdownStep($"Unregister server={serverHandle.ServerHandle} failed: {exception.GetType().Name}");
|
|
failures.Add(new MxAccessShutdownFailure(
|
|
nameof(Unregister),
|
|
serverHandle.ServerHandle,
|
|
itemHandle: null,
|
|
exception));
|
|
}
|
|
}
|
|
|
|
return failed;
|
|
}
|
|
|
|
private static long CreateItemKey(
|
|
int serverHandle,
|
|
int itemHandle)
|
|
{
|
|
return ((long)serverHandle << 32) | (uint)itemHandle;
|
|
}
|
|
|
|
private string AppendRemoveItemCleanup(
|
|
int serverHandle,
|
|
int itemHandle,
|
|
string errorMessage)
|
|
{
|
|
try
|
|
{
|
|
RemoveItem(serverHandle, itemHandle);
|
|
return $"{errorMessage}; cleanup RemoveItem succeeded.";
|
|
}
|
|
catch (Exception cleanupException)
|
|
{
|
|
return $"{errorMessage}; cleanup RemoveItem failed: {cleanupException.Message}";
|
|
}
|
|
}
|
|
|
|
private static SubscribeResult Succeeded(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
int itemHandle)
|
|
{
|
|
return new SubscribeResult
|
|
{
|
|
ServerHandle = serverHandle,
|
|
TagAddress = tagAddress,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = true,
|
|
ErrorMessage = string.Empty,
|
|
};
|
|
}
|
|
|
|
private static SubscribeResult Failed(
|
|
int serverHandle,
|
|
string tagAddress,
|
|
int itemHandle,
|
|
string errorMessage)
|
|
{
|
|
return new SubscribeResult
|
|
{
|
|
ServerHandle = serverHandle,
|
|
TagAddress = tagAddress,
|
|
ItemHandle = itemHandle,
|
|
WasSuccessful = false,
|
|
ErrorMessage = errorMessage,
|
|
};
|
|
}
|
|
|
|
private void DisposeCore(ICollection<MxAccessShutdownFailure>? failures)
|
|
{
|
|
Exception? detachException = null;
|
|
try
|
|
{
|
|
eventSink.Detach();
|
|
LogShutdownStep("DetachEvents ok");
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
detachException = exception;
|
|
failures?.Add(new MxAccessShutdownFailure(
|
|
"DetachEvents",
|
|
serverHandle: null,
|
|
itemHandle: null,
|
|
exception));
|
|
}
|
|
|
|
try
|
|
{
|
|
if (Marshal.IsComObject(mxAccessComObject))
|
|
{
|
|
Marshal.FinalReleaseComObject(mxAccessComObject);
|
|
LogShutdownStep("ReleaseComObject ok");
|
|
}
|
|
}
|
|
catch (Exception exception) when (failures is not null)
|
|
{
|
|
failures.Add(new MxAccessShutdownFailure(
|
|
"ReleaseComObject",
|
|
serverHandle: null,
|
|
itemHandle: null,
|
|
exception));
|
|
}
|
|
|
|
disposed = true;
|
|
if (detachException is not null && failures is null)
|
|
{
|
|
throw detachException;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mutable per-tag state for one ReadBulk snapshot lifecycle. A plain
|
|
/// class with get/set properties (no records or init accessors) so it
|
|
/// compiles under the worker's net48 target.
|
|
/// </summary>
|
|
private sealed class SnapshotRead
|
|
{
|
|
public SnapshotRead(int index, string tagAddress)
|
|
{
|
|
Index = index;
|
|
TagAddress = tagAddress;
|
|
}
|
|
|
|
/// <summary>Gets the position of the tag in the request.</summary>
|
|
public int Index { get; }
|
|
|
|
/// <summary>Gets the requested tag address.</summary>
|
|
public string TagAddress { get; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the item handle the read waits on: the caller's
|
|
/// registered handle when phase 1 found one, otherwise 0 until
|
|
/// ReadBulk's AddItem succeeds.
|
|
/// </summary>
|
|
public int ItemHandle { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the value-cache version the wait compares against:
|
|
/// captured before ReadBulk's Advise, or in phase 1 for a handle the
|
|
/// caller already advised.
|
|
/// </summary>
|
|
public ulong Baseline { get; set; }
|
|
|
|
/// <summary>Gets or sets a value indicating whether <see cref="Baseline"/> has been captured.</summary>
|
|
public bool BaselineCaptured { get; set; }
|
|
|
|
/// <summary>Gets or sets a value indicating whether ReadBulk itself advised the handle (phase 4 unadvises it).</summary>
|
|
public bool Advised { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether ReadBulk's own AddItem
|
|
/// created the item (phase 4 removes it). False for a handle the
|
|
/// caller held before this call.
|
|
/// </summary>
|
|
public bool OwnsItem { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the earlier snapshot in the same batch whose
|
|
/// subscription this one shares (same item handle), or null.
|
|
/// </summary>
|
|
public SnapshotRead? SharedWith { get; set; }
|
|
}
|
|
|
|
private void ThrowIfDisposed()
|
|
{
|
|
if (disposed)
|
|
{
|
|
throw new ObjectDisposedException(nameof(MxAccessSession));
|
|
}
|
|
}
|
|
}
|