Esempio n. 1
0
        public static LogEntry For(CloseSessionRequest request)
        {
            LogEntry entry = new LogEntry("CloseSessionRequest");

            entry.Add("RequestHeader", For(request.RequestHeader));
            entry.Add("DeleteSubscriptions", For(request.DeleteSubscriptions));
            return(entry);
        }
Esempio n. 2
0
        protected override async Task OnCloseAsync(CancellationToken token)
        {
            var closeSessionRequest = new CloseSessionRequest
            {
                DeleteSubscriptions = true
            };
            var closeSessionResponse = await this.CloseSessionAsync(closeSessionRequest).ConfigureAwait(false);

            await base.OnCloseAsync(token).ConfigureAwait(false);
        }
Esempio n. 3
0
        public override Task <CloseSessionReply> CloseSession(CloseSessionRequest request, ServerCallContext context)
        {
            Console.WriteLine($"SPRO CloseSession for {request.Username} / {request.Type}");
            string ok = "nok";

            if (_sessionsType != null && _sessionsType == request.Type &&
                RemoveUser(request.Username))
            {
                ok = "ok";
                Console.WriteLine($"SPRO CloseSession for {request.Username} / {request.Type} GRANTED");
            }
            return(Task.FromResult(new CloseSessionReply {
                Ok = ok
            }));
        }
Esempio n. 4
0
        public async Task <CloseSessionResponse> CloseSessionAsync(CloseSessionRequest closeSessionRequest)
        {
            UpdateRequestHeader(closeSessionRequest, true, "CloseSession");
            CloseSessionResponse closeSessionResponse = null;

            try
            {
                if (UseTransportChannel)
                {
                    var serviceResponse = await Task <IServiceResponse> .Factory.FromAsync(TransportChannel.BeginSendRequest, TransportChannel.EndSendRequest, closeSessionRequest, null).ConfigureAwait(false);

                    if (serviceResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    ValidateResponse(serviceResponse.ResponseHeader);
                    closeSessionResponse = (CloseSessionResponse)serviceResponse;
                }
                else
                {
                    var closeSessionResponseMessage = await Task <CloseSessionResponseMessage> .Factory.FromAsync(InnerChannel.BeginCloseSession, InnerChannel.EndCloseSession, new CloseSessionMessage(closeSessionRequest), null).ConfigureAwait(false);

                    if (closeSessionResponseMessage == null || closeSessionResponseMessage.CloseSessionResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    closeSessionResponse = closeSessionResponseMessage.CloseSessionResponse;
                    ValidateResponse(closeSessionResponse.ResponseHeader);
                }
            }
            finally
            {
                RequestCompleted(closeSessionRequest, closeSessionResponse, "CloseSession");
            }
            return(closeSessionResponse);
        }
Esempio n. 5
0
        /// <summary>
        /// Closes a session.
        /// </summary>
        /// <param name="channel">A instance of <see cref="IRequestChannel"/>.</param>
        /// <param name="request">A <see cref="CloseSessionRequest"/>.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation that returns a <see cref="CloseSessionResponse"/>.</returns>
        public static async Task <CloseSessionResponse> CloseSessionAsync(this IRequestChannel channel, CloseSessionRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            return((CloseSessionResponse)await channel.RequestAsync(request).ConfigureAwait(false));
        }
Esempio n. 6
0
        /// <summary>
        /// Closes a session.
        /// </summary>
        /// <param name="channel">A instance of <see cref="IRequestChannel"/>.</param>
        /// <param name="request">A <see cref="CloseSessionRequest"/>.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation that returns a <see cref="CloseSessionResponse"/>.</returns>
        /// <seealso href="https://reference.opcfoundation.org/v104/Core/docs/Part4/5.6.4/">OPC UA specification Part 4: Services, 5.6.4</seealso>
        internal static async Task <CloseSessionResponse> CloseSessionAsync(this IRequestChannel channel, CloseSessionRequest request, CancellationToken token = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return((CloseSessionResponse)await channel.RequestAsync(request, token).ConfigureAwait(false));
        }
Esempio n. 7
0
        /// <summary>
        /// Begins an asynchronous invocation of the CloseSession service.
        /// </summary>
        public IAsyncResult BeginCloseSession(
            RequestHeader requestHeader,
            bool          deleteSubscriptions,
            AsyncCallback callback,
            object        asyncState)
        {
            CloseSessionRequest request = new CloseSessionRequest();

            request.RequestHeader       = requestHeader;
            request.DeleteSubscriptions = deleteSubscriptions;

            UpdateRequestHeader(request, requestHeader == null, "CloseSession");

            if (UseTransportChannel)
            {
                return TransportChannel.BeginSendRequest(request, callback, asyncState);
            }

            return InnerChannel.BeginCloseSession(new CloseSessionMessage(request), callback, asyncState);
        }
Esempio n. 8
0
        /// <summary>
        /// Invokes the CloseSession service.
        /// </summary>
        public virtual ResponseHeader CloseSession(
            RequestHeader requestHeader,
            bool          deleteSubscriptions)
        {
            CloseSessionRequest request = new CloseSessionRequest();
            CloseSessionResponse response = null;

            request.RequestHeader       = requestHeader;
            request.DeleteSubscriptions = deleteSubscriptions;

            UpdateRequestHeader(request, requestHeader == null, "CloseSession");

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.SendRequest(request);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (CloseSessionResponse)genericResponse;
                }
                else
                {
                    CloseSessionResponseMessage responseMessage = InnerChannel.CloseSession(new CloseSessionMessage(request));

                    if (responseMessage == null || responseMessage.CloseSessionResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.CloseSessionResponse;
                    ValidateResponse(response.ResponseHeader);
                }

            }
            finally
            {
                RequestCompleted(request, response, "CloseSession");
            }

            return response.ResponseHeader;
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public CloseSessionMessage(CloseSessionRequest CloseSessionRequest)
 {
     this.CloseSessionRequest = CloseSessionRequest;
 }
 protected override async Task OnCloseAsync(CancellationToken token)
 {
     token.ThrowIfCancellationRequested();
     var closeSessionRequest = new CloseSessionRequest
     {
         DeleteSubscriptions = true
     };
     await this.RequestAsync(closeSessionRequest).ConfigureAwait(false);
     await base.OnCloseAsync(token).ConfigureAwait(false);
 }