Example #1
0
        /// <summary>
        /// Writes a message to the instantiated Windows pipe.
        /// </summary>
        /// <param name="message">IPC message to write.</param>
        /// <param name="promptRestartBrokerServiceOnFail">Prompt the user to restart a stopped broker service.</param>
        /// <returns>True on success.</returns>
        public bool WriteToPipe(IPCMessage message, bool promptRestartBrokerServiceOnFail = true)
        {
            try
            {
                var buffer = Encoding.UTF8.GetBytes(message.ToString());
                pipe.Write(buffer, 0, buffer.Length);
                pipe.Flush();
            }
            catch (Exception e)
            {
                if (pipe is NamedPipeClientStream && (e is InvalidOperationException || e is IOException))
                {
                    if (promptRestartBrokerServiceOnFail)
                    {
                        Broker.PromptRestartBrokerService();
                    }
                }

                ErrorHandling.ErrorHandler.Handle(e, ErrorHandling.LogLevel.Error);
                return(false);
            }

            return(true);
        }