Пример #1
0
        public OperationResult Operation()
        {
            // Randomize the success indicator
            // This should be real logic
            var randomNumber = new Random().Next(100);
            var success      = randomNumber % 2 == 0;

            // Some information message
            var information = new OperationResultMessage(
                "This should be very informative!",
                OperationResultSeverity.Information
                );

            // Return the operation result
            if (success)
            {
                var warning = new OperationResultMessage(
                    "Something went wrong, but we will try again later automatically until it works!",
                    OperationResultSeverity.Warning
                    );
                return(new OperationResult(information, warning)
                {
                    Value = randomNumber
                });
            }
            else
            {
                var error = new OperationResultMessage(
                    $"Something went wrong with the number '{randomNumber}'.",
                    OperationResultSeverity.Error
                    );
                return(new OperationResult(information, error)
                {
                    Value = randomNumber
                });
            }
        }
Пример #2
0
 public void AddMessage(OperationResultMessage message)
 {
     _messages.Add(message);
 }