Exemplo n.º 1
0
        public void ShowBuild(IBuild build, Func <IBuild, String> iconProvider, Action <IBuild> notificationClickAction)
        {
            // Get a toast XML template
            var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

            // Fill in the text elements
            var stringElements = toastXml.GetElementsByTagName("text");

            stringElements[0].AppendChild(toastXml.CreateTextNode(GetTitle(build)));
            stringElements[1].AppendChild(toastXml.CreateTextNode(build.GenerateStatus()));
            stringElements[2].AppendChild(toastXml.CreateTextNode(build.GenerateUsername()));

            // Specify the absolute path to an image
            var imagePath = "file:///" + Path.GetFullPath(iconProvider.Invoke(build));

            var imageElements = toastXml.GetElementsByTagName("image");
            var src           = imageElements[0].Attributes.GetNamedItem("src");

            if (src != null)
            {
                src.NodeValue = imagePath;
            }

            // Create the toast and attach event listeners
            var toast = new ToastNotification(toastXml);

            if (notificationClickAction != null)
            {
                toast.Activated += (sender, args) => { notificationClickAction.Invoke(build); };
            }

            // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
            ToastNotificationManager.CreateToastNotifier(AppId).Show(toast);
        }
        public void ShowBuild(IBuild build, Func <IBuild, String> iconProvider, Action <IBuild> notificationClickAction)
        {
            if (build == null)
            {
                return;
            }

            var sb = new StringBuilder();

            sb.AppendLine(GetTitle(build));
            sb.AppendLine(build.GenerateStatus());
            sb.AppendLine(build.GenerateUsername());
            var displayOptions = new MessageOptions
            {
                NotificationClickAction = n =>
                {
                    notificationClickAction?.Invoke(build);
                    n.Close();
                }
            };

            switch (build.Status)
            {
            case BuildStatus.PartiallySucceeded:
                this.notifier.ShowWarning(sb.ToString(), displayOptions);
                break;

            case BuildStatus.Running:
            case BuildStatus.Stopped:
            case BuildStatus.Queued:
            case BuildStatus.Unknown:
                this.notifier.ShowInformation(sb.ToString(), displayOptions);
                break;

            case BuildStatus.Succeeded:
                this.notifier.ShowSuccess(sb.ToString(), displayOptions);
                break;

            case BuildStatus.Failed:
                this.notifier.ShowError(sb.ToString(), displayOptions);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }