Exemplo n.º 1
0
        // This function allows worker classes to write something that can be signaled to observers.
        public void SendMessage(string message, string reason)
        {
            // Here we can perform some tests before sending the message
            if (string.IsNullOrEmpty(reason))
            {
                throw new ArgumentNullException(nameof(reason));
            }

            if (MessageReceived == null)
            {
                return;
            }

            var printMessageArgs = new MessageArgs(message, reason);

            OnMessageReceived(printMessageArgs);
        }
Exemplo n.º 2
0
 protected virtual void OnMessageReceived(MessageArgs e)
 {
     // This raises our event observers listen to.
     MessageReceived?.Invoke(this, e);
 }
Exemplo n.º 3
0
 private static void PrinterOnMessageReceived(object sender, MessageArgs messageArgs)
 {
     Console.WriteLine($"Sender: {sender}{Environment.NewLine}" +
                       $"Message: {messageArgs.Message}{Environment.NewLine}" +
                       $"Reason: {messageArgs.Reason}{Environment.NewLine} ");
 }