private ServiceResult OnApproveLock( ISystemContext context, MethodState method, NodeId objectId, IList <object> inputArguments, IList <object> outputArguments) { DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState)); if (!node.EnabledState.Id.Value) { return(StatusCodes.BadConditionDisabled); } if (node.LockState.CurrentState.Id.Value != new NodeId(DsatsDemo.Objects.LockStateMachineType_WaitingForApproval, NamespaceIndex)) { return(StatusCodes.BadConditionNotShelved); } // only admins can approve locks. if (!CheckAdminAccess(context)) { return(StatusCodes.BadUserAccessDenied); } // grant the lock. GrantLockToSession(context, node.SessionId.Value, objectId); node.SetLock(context); node.ReportEvent(context, node); node.ClearChangeMasks(context, true); return(ServiceResult.Good); }
private ServiceResult OnRequestLock( ISystemContext context, MethodState method, NodeId objectId, IList <object> inputArguments, IList <object> outputArguments) { DsatsDemo.LockConditionState node = (DsatsDemo.LockConditionState)FindPredefinedNode(objectId, typeof(DsatsDemo.LockConditionState)); if (!node.EnabledState.Id.Value) { return(StatusCodes.BadConditionDisabled); } if (node.LockState.CurrentState.Id.Value != new NodeId(DsatsDemo.Objects.LockStateMachineType_Unlocked, NamespaceIndex)) { return(StatusCodes.BadConditionAlreadyShelved); } node.SessionId.Value = context.SessionId; node.ClientUserId.Value = null; node.SubjectName.Value = null; // get the current user name. if (context.UserIdentity != null) { node.ClientUserId.Value = context.UserIdentity.DisplayName; } X509Certificate2 certificate = null; // get the client certificate subject name. ServerSystemContext systemContext = context as ServerSystemContext; if (systemContext != null && systemContext.OperationContext != null && systemContext.OperationContext.Session != null && systemContext.OperationContext.Session.ClientCertificate != null) { certificate = systemContext.OperationContext.Session.ClientCertificate; node.SubjectName.Value = certificate.Subject; } node.RequestLock(context); // admins get locks immediately. if (CheckAdminAccess(context) || (certificate != null && node.HasPermission(certificate))) { GrantLockToSession(context, node.SessionId.Value, objectId); node.SetLock(context); } node.ReportEvent(context, node); node.ClearChangeMasks(context, true); return(ServiceResult.Good); }