Esempio n. 1
0
        public void OnTriggerNotification(string result)
        {
            if (Notifications == null || !Notifications.Any() || NotifyCondition == NotifyCondition.None)
            {
                return;
            }

            var subject = $"{(Debugger.IsAttached ? "`DEBUG MODE`" : "")} **{Name}**\n" +
                          $"----------------------------------------";
            var body = $"\nResult: `{result}` " +
                       $"\nAction: `{ActionName}` \n";

            if (ActionParameters?.Any() == true)
            {
                body += "Arguments: ```\n";
                foreach (var arg in ActionParameters.Where((k, v) => !String.IsNullOrEmpty(v.ToString())))
                {
                    var val = string.Concat(arg.Value.ToString()
                                            .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                            .Select(x => $"{x}\n\t"));
                    val   = val.Remove(val.LastIndexOf('\t'));
                    body += $"  • {arg.Key}: {val}";
                }

                body = body.Replace("\"", "") + "\n```";
            }

            foreach (var notify in Notifications.Where(n => CompareByNotifyCondition(result)))
            {
                try
                {
#if !TestWithoutNotify
                    notify.Notify(body, subject);
#endif
                }
                catch (Exception exp)
                {
                    Nlogger.Error(exp);
                }
            }
        }