private LightStackColor Get() { LightStackColor color = LightStackColor.Off; bool[] values = _bits.Get().ToArray(); if (values[0]) { color |= LightStackColor.Red; } if (values[1]) { color |= LightStackColor.Yellow; } if (values[2]) { color |= LightStackColor.Green; } if (values[3]) { color |= LightStackColor.Blue; } return(color); }
/// <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="ex">The exception.</param> /// <param name="blinkColor">Light stack colors that should blink until this popup is dismissed.</param> public static void PopUpError(string title, Exception ex, LightStackColor blinkColor) { string message = ex.Message; if (ex.InnerException != null) { message += Environment.NewLine + Environment.NewLine + ex.InnerException.Message; } PopUpError(title, message, blinkColor, ex.ToString()); }
/// <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); }
private void NotifyBanner_Load(object sender, EventArgs e) { try { if (Notify.LightTower != null && LightStackColor != LightStackColor.Off) { _prevColor = Notify.LightTower.GetBlink(); Notify.LightTower.Off(LightStackColor.All); Notify.LightTower.Blink(LightStackColor); } } catch (Exception) { } }
/// <summary> /// Sets the specified colors to blink at every half-second interval. /// </summary> /// <param name="colors">The colors.</param> public void Blink(LightStackColor colors) { if (colors.HasFlag(LightStackColor.Red)) { _steady &= ~LightStackColor.Red; } if (colors.HasFlag(LightStackColor.Yellow)) { _steady &= ~LightStackColor.Yellow; } if (colors.HasFlag(LightStackColor.Green)) { _steady &= ~LightStackColor.Green; } if (colors.HasFlag(LightStackColor.Blue)) { _steady &= ~LightStackColor.Blue; } _blinking |= colors; }
private void Set(LightStackColor colors) { int[] values = new int[4]; if (colors.HasFlag(LightStackColor.Red)) { values[0] = 1; } if (colors.HasFlag(LightStackColor.Yellow)) { values[1] = 1; } if (colors.HasFlag(LightStackColor.Green)) { values[2] = 1; } if (colors.HasFlag(LightStackColor.Blue)) { values[3] = 1; } _bits.SetValues(values); }
private void BlinkTimer_Elapsed(object sender, ElapsedEventArgs e) { _blinkTimer.Elapsed -= BlinkTimer_Elapsed; try { // // Set light stack // if (!_blinkOn) { Set(_steady); } else { Set(_blinking | _steady); } // Get current light stack (use GetOutWordCached to get all light output bits in one set) _current = Get(); EventHandler <LightStackEventArgs> stackUpdate = StackUpdate; if (stackUpdate != null) { stackUpdate(this, new LightStackEventArgs(_current)); } } finally { _blinkOn = !_blinkOn; _blinkTimer.Elapsed += BlinkTimer_Elapsed; } }
/// <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) { } } }); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="LightStackEventArgs"/> class. /// </summary> /// <param name="colors">The colors.</param> public LightStackEventArgs(LightStackColor colors) { Colors = colors; }
/// <summary> /// Turns off the specified colors. /// </summary> /// <param name="colors">The colors.</param> public void Off(LightStackColor colors) { _steady &= ~colors; _blinking &= ~colors; }
/// <summary> /// Sets the specified colors to steady on. /// </summary> /// <param name="colors">The colors.</param> public void Steady(LightStackColor colors) { _steady |= colors; }