Пример #1
0
        /// <summary>
        /// Sends an error banner notification to be displayed at the top of the application notification panel. This will be in red.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="details">The error details.</param>
        /// <returns></returns>
        public static ErrorBanner BannerError(string message, string details = "")
        {
            Form mainForm = null;

            if (Application.OpenForms.Count > 0)
            {
                mainForm = Application.OpenForms[0];
            }

            ErrorBanner banner = null;

            UIUtility.Invoke(mainForm, () =>
            {
                EventHandler <NotifyBannerEventArgs> bannerNotified = Instance.BannerNotified;

                if (bannerNotified == null)
                {
                    return;
                }

                banner = new ErrorBanner(message, details);

                bannerNotified(Instance, new NotifyBannerEventArgs(banner));
            });

            return(banner);
        }
Пример #2
0
        private void DoStepAction(Action action)
        {
            if (action == null)
            {
                return;
            }

            UIUtility.Invoke(this, () => this.Enabled = false);

            Task.Factory.StartNew(action).ContinueWith(task =>
            {
                UIUtility.Invoke(this, () =>
                {
                    this.Enabled = true;

                    if (task.IsFaulted)
                    {
                        Exception ex = task.Exception;

                        while (ex is AggregateException)
                        {
                            ex = ex.InnerException;
                        }

                        this.Close();
                        Notify.BannerError("Wizard Failed", ex.ToString());
                    }
                    else if (CurrentStep == null)
                    {
                        this.Close();
                    }
                });
            });
        }
Пример #3
0
        /// <summary>
        /// Starts a <see cref="WizardBanner"/> notification, which is displayed at the top of the application notification panel.
        /// </summary>
        /// <param name="steps">The steps.</param>
        /// <returns></returns>
        public static WizardBanner StartWizard(params WizardStep[] steps)
        {
            Form mainForm = null;

            if (Application.OpenForms.Count > 0)
            {
                mainForm = Application.OpenForms[0];
            }

            WizardBanner banner = null;

            UIUtility.Invoke(mainForm, () =>
            {
                EventHandler <NotifyBannerEventArgs> bannerNotified = Instance.BannerNotified;

                if (bannerNotified == null)
                {
                    return;
                }

                banner = new WizardBanner(steps);

                bannerNotified(Instance, new NotifyBannerEventArgs(banner));
            });

            return(banner);
        }
Пример #4
0
        private void btnAction_Click(object sender, EventArgs e)
        {
            Button btnAction = sender as Button;

            if (btnAction == null)
            {
                return;
            }

            Action action = btnAction.Tag as Action;

            if (action == null)
            {
                return;
            }

            btnAction.Enabled = false;
            CancelEventArgs    cancelArgs     = new CancelEventArgs();
            CancelEventHandler actionStarting = ActionStarting;

            if (actionStarting != null)
            {
                actionStarting(this, cancelArgs);
            }

            if (cancelArgs.Cancel)
            {
                return;
            }

            Task.Factory.StartNew(action).ContinueWith(t =>
            {
                UIUtility.Invoke(this, () =>
                {
                    btnAction.Enabled = true;

                    if (t.IsFaulted)
                    {
                        if (this != null)
                        {
                            lblMessage.Text = t.Exception.InnerException.Message;
                        }

                        Log.Error("Error", t.Exception.InnerException);
                        return;
                    }
                    else
                    {
                        EventHandler actionCompleted = ActionCompleted;
                        if (actionCompleted != null)
                        {
                            actionCompleted(this, new EventArgs());
                        }
                    }
                });
            });
        }
Пример #5
0
        /// <summary>
        /// Sends a pop-up dialog notification.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="buttons">The buttons.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        /// <param name="request">The operator request.</param>
        /// <param name="customButtonText">The custom button text if required.</param>
        /// <param name="customAction">The custom action if required.</param>
        /// <returns></returns>
        public static NotifyButton PopUp(string title, string message, NotifyButton buttons, LightStackColor blinkColor, string request = "", string customButtonText = "", Action customAction = null)
        {
            NotifyButton clickedButton = NotifyButton.Cancel;

            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, buttons, request, customButtonText, customAction))
                {
                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();
                        clickedButton = notify.ClickedButton;

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            return(clickedButton);
        }
Пример #6
0
 private void UpdateName()
 {
     UIUtility.Invoke(this, () =>
     {
         if (propertyGrid.SelectedObject != null)
         {
             btnMove.Text = propertyGrid.SelectedObject.ToString();
         }
         else
         {
             btnMove.Text = "(none)";
         }
     });
 }
Пример #7
0
        private void ActionAndProgress(Action action)
        {
            if (Steps.Count == 0)
            {
                UIUtility.Invoke(this, Close);
                return;
            }

            if (CurrentStep != null)
            {
                Action cleanup   = CurrentStep.Cleanup;
                Action nextSetup = null;

                PreviousStep = Steps.Dequeue();
                PreviousStep.PropertyChanged -= CurrentStep_PropertyChanged;

                if (CurrentStep != null)
                {
                    CurrentStep.PropertyChanged += CurrentStep_PropertyChanged;
                    nextSetup = CurrentStep.Setup;
                }

                DoStepAction(() =>
                {
                    if (action != null)
                    {
                        action();
                    }

                    if (cleanup != null)
                    {
                        cleanup();
                    }

                    if (CurrentStep != null)
                    {
                        UpdateStep();

                        if (nextSetup != null)
                        {
                            nextSetup();
                        }
                    }
                });
            }
        }
Пример #8
0
        /// <summary>
        /// Sends a banner notification (with 3 custom actions) to be displayed at the top of the application notification panel.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="closeText">The close text (defaults to OK).</param>
        /// <param name="action1Text">First action text.</param>
        /// <param name="action1">First action.</param>
        /// <param name="action2Text">Second action text.</param>
        /// <param name="action2">Second action.</param>
        /// <param name="action3Text">Third action text.</param>
        /// <param name="action3">Third action.</param>
        /// <returns></returns>
        public static NotifyBanner Banner(string message, string closeText, string action1Text, Action action1, string action2Text, Action action2, string action3Text, Action action3)
        {
            Form mainForm = null;

            if (Application.OpenForms.Count > 0)
            {
                mainForm = Application.OpenForms[0];
            }

            NotifyBanner banner = null;

            UIUtility.Invoke(mainForm, () =>
            {
                EventHandler <NotifyBannerEventArgs> bannerNotified = Instance.BannerNotified;

                if (bannerNotified == null)
                {
                    return;
                }

                banner           = new NotifyBanner();
                banner.Message   = message;
                banner.CloseText = closeText;

                if (!String.IsNullOrEmpty(action1Text))
                {
                    banner.AddAction(action1Text, action1);
                }

                if (!String.IsNullOrEmpty(action2Text))
                {
                    banner.AddAction(action2Text, action2);
                }

                if (!String.IsNullOrEmpty(action3Text))
                {
                    banner.AddAction(action3Text, action3);
                }

                bannerNotified(Instance, new NotifyBannerEventArgs(banner));
            });

            return(banner);
        }
Пример #9
0
        /// <summary>
        /// Sends a banner notification to be displayed at the top of the application notification panel.
        /// </summary>
        /// <param name="banner">The pre-constructed banner.</param>
        public static void Banner(NotifyBanner banner)
        {
            Form mainForm = null;

            if (Application.OpenForms.Count > 0)
            {
                mainForm = Application.OpenForms[0];
            }

            UIUtility.Invoke(mainForm, () =>
            {
                EventHandler <NotifyBannerEventArgs> bannerNotified = Instance.BannerNotified;

                if (bannerNotified == null)
                {
                    return;
                }

                bannerNotified(Instance, new NotifyBannerEventArgs(banner));
            });
        }
Пример #10
0
        private void BannerNotified(object sender, NotifyBannerEventArgs e)
        {
            if (e.Banner == null)
            {
                return;
            }

            if (e.Banner is WizardBanner)
            {
                var wizards = tableLayoutPanel.Controls.OfType <WizardBanner>();
                if (wizards.Count() > 0)
                {
                    e.Banner.Dispose();
                    return;
                }
            }

            UIUtility.Invoke(this, () =>
            {
                e.Banner.Dock    = DockStyle.Fill;
                e.Banner.Margin  = new System.Windows.Forms.Padding(0);
                e.Banner.Padding = new System.Windows.Forms.Padding(0);
                e.Banner.Closed += new EventHandler(CloseBanner);

                this.SuspendLayout();
                tableLayoutPanel.SuspendLayout();

                this.Height += e.Banner.Height;

                tableLayoutPanel.RowCount++;
                tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize, 0));
                tableLayoutPanel.Controls.Add(e.Banner, 0, tableLayoutPanel.RowCount - 1);

                tableLayoutPanel.ResumeLayout();
                this.ResumeLayout();
                this.Show();
            });
        }
Пример #11
0
        private void UpdateActionButtons()
        {
            UIUtility.Invoke(this, () =>
            {
                this.SuspendLayout();

                try
                {
                    flowLayout.Controls.Clear();

                    foreach (Tuple <string, Action> actionItem in _actionItems)
                    {
                        Button btnAction                  = new Button();
                        btnAction.AutoSize                = true;
                        btnAction.AutoSizeMode            = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
                        btnAction.ForeColor               = System.Drawing.SystemColors.ControlText;
                        btnAction.Location                = new System.Drawing.Point(2, 3);
                        btnAction.Margin                  = new System.Windows.Forms.Padding(2, 3, 2, 3);
                        btnAction.MinimumSize             = new System.Drawing.Size(29, 28);
                        btnAction.Name                    = "btn" + actionItem.Item1;
                        btnAction.Padding                 = new System.Windows.Forms.Padding(5, 0, 5, 1);
                        btnAction.Size                    = new System.Drawing.Size(64, 28);
                        btnAction.TabIndex                = 1;
                        btnAction.Tag                     = actionItem.Item2;
                        btnAction.Text                    = actionItem.Item1;
                        btnAction.UseVisualStyleBackColor = true;
                        btnAction.Click                  += new System.EventHandler(this.btnAction_Click);

                        flowLayout.Controls.Add(btnAction);
                    }
                }
                finally
                {
                    this.ResumeLayout();
                }
            });
        }
Пример #12
0
        /// <summary>
        /// Sends an error pop-up dialog notification. The border and title will be in red.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="details">The error details.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        public static void PopUpError(string title, string message, LightStackColor blinkColor, string details = "")
        {
            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            int notifyCount = 0;

            foreach (Form f in Application.OpenForms)
            {
                if (f is NotifyForm)
                {
                    notifyCount++;
                }
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, "", "Details", "Copy", "OK"))
                {
                    notify.BackColor        = Color.OrangeRed;
                    notify.CustomButtonText = details;
                    notify.FormClosing     += notify_FormClosing;

                    if (notifyCount > 0)
                    {
                        notify.StartPosition = FormStartPosition.Manual;
                        Rectangle bounds     = Screen.PrimaryScreen.Bounds;
                        Point center         = new Point((bounds.Width - notify.Width) / 2, (bounds.Height - notify.Height) / 2);
                        notify.Location      = new Point(center.X + (50 * notifyCount), center.Y + (50 * notifyCount));
                    }

                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });
        }
Пример #13
0
        /// <summary>
        /// Sends a pop-up dialog notification.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="request">The request.</param>
        /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param>
        /// <param name="buttonNames">The custom button names.</param>
        /// <returns></returns>
        public static string PopUp(string title, string message, string request, LightStackColor blinkColor, params string[] buttonNames)
        {
            string customClickedName = "";

            Form activeForm = Form.ActiveForm;

            if (activeForm == null && Application.OpenForms.Count > 0)
            {
                activeForm = Application.OpenForms[Application.OpenForms.Count - 1];
            }

            int notifyCount = 0;

            foreach (Form f in Application.OpenForms)
            {
                if (f is NotifyForm)
                {
                    notifyCount++;
                }
            }

            UIUtility.Invoke(activeForm, () =>
            {
                using (NotifyForm notify = new NotifyForm(title, message, request, buttonNames))
                {
                    if (notifyCount > 0)
                    {
                        notify.StartPosition = FormStartPosition.Manual;
                        Rectangle bounds     = Screen.PrimaryScreen.Bounds;
                        Point center         = new Point((bounds.Width - notify.Width) / 2, (bounds.Height - notify.Height) / 2);
                        notify.Location      = new Point(center.X + (50 * notifyCount), center.Y + (50 * notifyCount));
                    }

                    LightStackColor prevColor = LightStackColor.Off;
                    bool lightTowerSet        = false;

                    try
                    {
                        if (LightTower != null && blinkColor != LightStackColor.Off)
                        {
                            prevColor = LightTower.GetBlink();
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(blinkColor);
                            lightTowerSet = true;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        notify.ShowDialog();
                        customClickedName = notify.ClickedCustomName;

                        if (lightTowerSet)
                        {
                            LightTower.Off(LightStackColor.All);
                            LightTower.Blink(prevColor);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            return(customClickedName);
        }
Пример #14
0
        private void UpdateStep()
        {
            if (Steps.Count == 0)
            {
                return;
            }

            UIUtility.Invoke(this, () =>
            {
                if (CurrentStep != null)
                {
                    this.Message = CurrentStep.Instructions;
                }

                this.ClearActions();

                if (CurrentStep != Steps.Last())
                {
                    this.CloseText = "Cancel";
                }

                if (CurrentStep.Actions.Count <= 1)
                {
                    if (CurrentStep.Actions.Count == 0)
                    {
                        if (CurrentStep != Steps.Last())
                        {
                            this.AddAction("Next", null);
                        }
                        else
                        {
                            this.CloseText = "Done";
                        }
                    }
                    else
                    {
                        Tuple <string, Action> actionAndName = CurrentStep.Actions[0];

                        if (actionAndName.Item2 == null && CurrentStep == Steps.Last())
                        {
                            this.CloseText = "Done";
                        }
                        else
                        {
                            string actionText = "Next";

                            if (!String.IsNullOrEmpty(actionAndName.Item1))
                            {
                                actionText = actionAndName.Item1;
                            }
                            if (CurrentStep == Steps.Last())
                            {
                                actionText = "OK";
                            }

                            this.AddAction(actionText, () => ActionAndProgress(actionAndName.Item2));
                        }
                    }
                }
                else
                {
                    foreach (Tuple <string, Action> actionAndName in CurrentStep.Actions)
                    {
                        string actionText = "Next";

                        if (!String.IsNullOrEmpty(actionAndName.Item1))
                        {
                            actionText = actionAndName.Item1;
                        }

                        this.AddAction(actionText, () => ActionAndProgress(actionAndName.Item2));
                    }
                }
            });
        }