Message Aggregate
Message.Aggregate(glue, messages) aggregates multiple message into one. Optional 'glue' can be provided to be appended between texts.
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.");
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.");
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.");
// Create messages
IMessage msg1 = userNotFound.New("0001");
IMessage msg2 = userNotFound.New("0002");
IMessage msg3 = userNotAuthenticated.New();
IMessage msg4 = userNotConfirmedEmail.New("0004");
// Aggregate messages
IMessage aggregate = Message.Aggregate(glue: "\n", msg1, msg2, msg3, msg4);
// Print message
WriteLine(aggregate.Print());
// User '0001' is not found
// User '0002' is not found
// User is not authenticated.
// E-mail of user '0004' is not verified.
Localization is also applied to aggregate (with Avalanche.Localization).
// Create localization
ILocalization localization = new Localization()
.AddLine("fi", "UserNotAuthenticated", "Detect", "Käyttäjä ei ole kirjautunut")
.AddLine("fi", "UserNotConfirmedEmail", "Detect", "Käyttäjän '{user}' sähköpostia ei ole varmistettu.")
.AddLine("fi", "UserNotFound", "Detect", "Käyttäjää '{channel}' ei löytyny");
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.").Localize(localization);
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.").Localize(localization);
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.").Localize(localization);
// Create messages
IMessage msg1 = userNotFound.New("0001");
IMessage msg2 = userNotFound.New("0002");
IMessage msg3 = userNotAuthenticated.New();
IMessage msg4 = userNotConfirmedEmail.New("0004");
// Aggregate messages
IMessage aggregate = Message.Aggregate(glue: "\n", msg1, msg2, msg3, msg4);
// Print message with default values
WriteLine(aggregate.Print());
// User '0001' is not found
// User '0002' is not found
// User is not authenticated.
// E-mail of user '0004' is not verified.
// Get culture 'fi'
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
// Print message in 'fi'
WriteLine(aggregate.Print(fi));
// Käyttäjää '0001' ei löytyny
// Käyttäjää '0002' ei löytyny
// Käyttäjä ei ole kirjautunut
// Käyttäjän '0004' sähköpostia ei ole varmistettu.
MessageDescription Aggregate
MessageDescription.Aggregate(glue, messageDescriptions) aggregates multiple message descriptions into one. Optional 'glue' can be provided to be appended between texts.
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.");
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.");
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.");
// Aggregate descriptions
IMessageDescription aggregate = MessageDescription.Aggregate(glue: "\n", userNotFound, userNotAuthenticated, userNotConfirmedEmail);
// Print message
WriteLine(aggregate.New("0001", "0002", "0003").Print());
// User '0001' is not found
// User is not authenticated.
// User's '0003' e-mail is not verified.
Localization is also applied to aggregate (with Avalanche.Localization).
// Create localization
ILocalization localization = new Localization()
.AddLine("fi", "UserNotAuthenticated", "Detect", "Käyttäjä ei ole kirjautunut")
.AddLine("fi", "UserNotConfirmedEmail", "Detect", "Käyttäjän '{user}' sähköpostia ei ole varmistettu.")
.AddLine("fi", "UserNotFound", "Detect", "Käyttäjää '{channel}' ei löytyny");
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.").Localize(localization);
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.").Localize(localization);
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.").Localize(localization);
// Aggregate descriptions
IMessageDescription aggregate = MessageDescription.Aggregate(glue: "\n", userNotFound, userNotAuthenticated, userNotConfirmedEmail);
// Get culture 'fi'
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
// Print message
WriteLine(aggregate.New("0001", "0002", "0003").Print(fi));
// Käyttäjää '0001' ei löytyny
// Käyttäjä ei ole kirjautunut
// Käyttäjän '0003' sähköpostia ei ole varmistettu.
Full Example
Full example
using System.Globalization;
using Avalanche.Localization;
using Avalanche.Message;
using Avalanche.Template;
using static System.Console;
public class aggregate
{
public static void Run()
{
{
// <01>
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.");
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.");
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.");
// Aggregate descriptions
IMessageDescription aggregate = MessageDescription.Aggregate(glue: "\n", userNotFound, userNotAuthenticated, userNotConfirmedEmail);
// Print message
WriteLine(aggregate.New("0001", "0002", "0003").Print());
// User '0001' is not found
// User is not authenticated.
// User's '0003' e-mail is not verified.
// </01>
}
{
// <02>
// Create localization
ILocalization localization = new Localization()
.AddLine("fi", "UserNotAuthenticated", "Detect", "Käyttäjä ei ole kirjautunut")
.AddLine("fi", "UserNotConfirmedEmail", "Detect", "Käyttäjän '{user}' sähköpostia ei ole varmistettu.")
.AddLine("fi", "UserNotFound", "Detect", "Käyttäjää '{channel}' ei löytyny");
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.").Localize(localization);
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.").Localize(localization);
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.").Localize(localization);
// Aggregate descriptions
IMessageDescription aggregate = MessageDescription.Aggregate(glue: "\n", userNotFound, userNotAuthenticated, userNotConfirmedEmail);
// Get culture 'fi'
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
// Print message
WriteLine(aggregate.New("0001", "0002", "0003").Print(fi));
// Käyttäjää '0001' ei löytyny
// Käyttäjä ei ole kirjautunut
// Käyttäjän '0003' sähköpostia ei ole varmistettu.
// </02>
}
{
// <03>
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.");
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.");
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.");
// Create messages
IMessage msg1 = userNotFound.New("0001");
IMessage msg2 = userNotFound.New("0002");
IMessage msg3 = userNotAuthenticated.New();
IMessage msg4 = userNotConfirmedEmail.New("0004");
// Aggregate messages
IMessage aggregate = Message.Aggregate(glue: "\n", msg1, msg2, msg3, msg4);
// Print message
WriteLine(aggregate.Print());
// User '0001' is not found
// User '0002' is not found
// User is not authenticated.
// E-mail of user '0004' is not verified.
// </03>
}
{
// <04>
// Create localization
ILocalization localization = new Localization()
.AddLine("fi", "UserNotAuthenticated", "Detect", "Käyttäjä ei ole kirjautunut")
.AddLine("fi", "UserNotConfirmedEmail", "Detect", "Käyttäjän '{user}' sähköpostia ei ole varmistettu.")
.AddLine("fi", "UserNotFound", "Detect", "Käyttäjää '{channel}' ei löytyny");
// Create descriptions
IMessageDescription userNotAuthenticated = new MessageDescription("UserNotAuthenticated", null, "User is not authenticated.").Localize(localization);
IMessageDescription userNotConfirmedEmail = new MessageDescription("UserNotConfirmedEmail", null, "E-mail of user '{user}' is not verified.").Localize(localization);
IMessageDescription userNotFound = new MessageDescription("UserNotFound", null, "User '{user}' is not found.").Localize(localization);
// Create messages
IMessage msg1 = userNotFound.New("0001");
IMessage msg2 = userNotFound.New("0002");
IMessage msg3 = userNotAuthenticated.New();
IMessage msg4 = userNotConfirmedEmail.New("0004");
// Aggregate messages
IMessage aggregate = Message.Aggregate(glue: "\n", msg1, msg2, msg3, msg4);
// Print message with default values
WriteLine(aggregate.Print());
// User '0001' is not found
// User '0002' is not found
// User is not authenticated.
// E-mail of user '0004' is not verified.
// Get culture 'fi'
CultureInfo fi = CultureInfo.GetCultureInfo("fi");
// Print message in 'fi'
WriteLine(aggregate.Print(fi));
// Käyttäjää '0001' ei löytyny
// Käyttäjää '0002' ei löytyny
// Käyttäjä ei ole kirjautunut
// Käyttäjän '0004' sähköpostia ei ole varmistettu.
// </04>
}
}
}