public static void ShowWindow() { try { // TODO: Perf optimisation: First time, use hard-coded tip. if (IsFirstTime()) { // TODO: Set nextTip to hard-coded First-Tip. // Avoid loading tip parser if user is going to close and never run it again. } _tipManager = new TipManager(); _tipHistoryManager = VSTipHistoryManager.GetInstance(); _tipCalculator = new TipCalculator(_tipHistoryManager, _tipManager); TipInfo nextTip = GetNewTip(); if (nextTip == null) { // There's no tip to show. Don't show the Tip of the Day window. Debug.WriteLine("Tip of the Day: There's no tip to show. Will not launch TotD dialog."); return; } // We have a tip! Let's create the Tip of the Day UI. TipOfTheDayWindow tipOfTheDayWindow = new TipOfTheDayWindow(_tipCalculator); // Attempt to navigate to the chose tip var success = tipOfTheDayWindow.NavigateToTip(nextTip); if (!success) { // Failed to navigate to tip URI Debug.WriteLine("Tip of the Day: Failed to navigate to tip URI. Will not launch TotD dialog."); return; } // Now show the dialog tipOfTheDayWindow.Show(); // Mark tip as seen _tipHistoryManager.MarkTipAsSeen(nextTip.globalTipId); } catch (Exception e) { // Fail gracefully when window will now show Debug.WriteLine("Unable to open Tip of the Day: " + e.Message); return; } }
//-------- Helper functions -------- internal bool NavigateToTip(TipInfo nextTip) { if (nextTip == null || string.IsNullOrEmpty(nextTip.contentUri)) { // Unable to navigate. No tip content URI. return(false); } // Update currentTip. Used later when looking up tip index in tip history. currentTip = nextTip.globalTipId; // Perform all UI rendering RenderAllTipUIElements(nextTip); // Mark tip as seen in Tip History _tipHistoryManager.MarkTipAsSeen(currentTip); return(true); }
//-------- Helper functions -------- internal bool NavigateToTip(TipInfo nextTip, bool markAsSeen = true) { if (nextTip == null || string.IsNullOrEmpty(nextTip.contentUri)) { // Unable to navigate. No tip content URI. return(false); } currentTip = nextTip.globalTipId; // Render the new tip content in the tip viewer ShowTipContent(nextTip); // Display Group settings UpdateGroupDisplayElements(nextTip); // Mark tip as shown if (markAsSeen) { _tipHistoryManager.MarkTipAsSeen(currentTip); } return(true); }