예제 #1
0
        private void ShutdownPipeServer()
        {
            // Ask the named pipe server to stop itself gracefully. This is required so that a listening thread isnt waiting for connections which will prevent shutdown of this service
            // Basically this will be the last connection it will accept. Start the service to being again or call StartNamePipeServer()
            var pipeClient = new NamedPipeClientStream(".", StringConstants.TechServicePipeName, PipeDirection.InOut, PipeOptions.WriteThrough, TokenImpersonationLevel.Impersonation);

            pipeClient.Connect();
            ServiceBrokerProtocolHelper.SendRequest(new Request {
                RequestTask = RequestTask.StopNamedPipeServer
            }, pipeClient, (function, message) => LogMessage(message, EventLogEntryType.Information));
        }
예제 #2
0
        /// <summary>
        /// Sends a synchonous/blocking message to the Tech service.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <remarks>This function blocks until it can connect to the Tech service, ie it waits until the server can make the connection.</remarks>
        /// <returns>A response from the service</returns>
        public Response SendMessage(Request request)
        {
            // This lock ensures that no other client thread can connect until we're done this function(which includes this function getting a valid response first)
            lock (ThreadLock)
            {
                LogMessage(MethodBase.GetCurrentMethod().Name, "Sending message to service...");
                var pipeClient = new NamedPipeClientStream(".", StringConstants.TechServicePipeName, PipeDirection.InOut, PipeOptions.WriteThrough, TokenImpersonationLevel.Impersonation);

                LogMessage(MethodBase.GetCurrentMethod().Name, "Waiting to connect to service...");
                pipeClient.Connect();

                LogMessage(MethodBase.GetCurrentMethod().Name, "Connected to service.");
                return(ServiceBrokerProtocolHelper.SendRequest(request, pipeClient, LogMessage));
            }
        }