示例#1
0
        private Task SendMessageInternal(
            string name, byte[] content,
            IpcBusContentType type,
            bool restoreWindow = true)
        {
            var message = WrapMessage(
                name, content, type,
                restoreWindow);

            if (message == null || message.Length == 0)
            {
                return(Task.CompletedTask);
            }

            LogManager.Debug.Info($"Send message - name = {name}, " +
                                  $"type = {type}, restoreWindow = {restoreWindow}");

            if (type == IpcBusContentType.StringUtf8)
            {
                LogManager.Debug.Info($"Send message content - " +
                                      $"{Encoding.UTF8.GetString(content)}");
            }

            return(LocalBus.PublishAsync(
                       message));
        }
 public IpcBusMessage(string name, byte[] content,
                      IpcBusContentType type, bool restoreWindow = true)
 {
     Name          = name;
     Content       = content;
     ContentType   = type;
     RestoreWindow = restoreWindow;
 }
        private static byte[] WrapMessage(string name, byte[] content,
                                          IpcBusContentType type, bool restoreWindow)
        {
            if (content == null || content.Length == 0)
            {
                return(Array.Empty <byte>());
            }

            using var memoryStream = new MemoryStream(content.Length);
            var message = new IpcBusMessage(name, content,
                                            type, restoreWindow);

            Serializer.Serialize(memoryStream, message);

            return(memoryStream.ToArray());
        }