/// <summary> /// Checks and installs a shortcut file in Start menu. /// </summary> /// <param name="request">Toast request</param> private static async Task CheckInstallShortcut(ToastRequest request) { var shortcutFilePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), // Not CommonStartMenu "Programs", request.ShortcutFileName); var shortcut = new Shortcut(); if (!shortcut.CheckShortcut( shortcutPath: shortcutFilePath, targetPath: request.ShortcutTargetFilePath, arguments: request.ShortcutArguments, comment: request.ShortcutComment, workingFolder: request.ShortcutWorkingFolder, windowState: request.ShortcutWindowState, iconPath: request.ShortcutIconFilePath, appId: request.AppId, activatorId: request.ActivatorId)) { shortcut.InstallShortcut( shortcutPath: shortcutFilePath, targetPath: request.ShortcutTargetFilePath, arguments: request.ShortcutArguments, comment: request.ShortcutComment, workingFolder: request.ShortcutWorkingFolder, windowState: request.ShortcutWindowState, iconPath: request.ShortcutIconFilePath, appId: request.AppId, activatorId: request.ActivatorId); await Task.Delay((TimeSpan.Zero < request.WaitingDuration)?request.WaitingDuration : _waitingDuration); } }
/// <summary> /// Show a toast. /// </summary> /// <param name="headline">A toast's headline</param> /// <param name="body1st">A toast's body (1st line)</param> /// <param name="body2nd">A toast's body (2nd line, optional)</param> /// <returns>Result of showing a toast</returns> internal static async Task <ToastResult> ShowAsync(string headline, string body1st, string body2nd) { if (!OsVersion.IsEightOrNewer) { return(ToastResult.Unavailable); } // Read from Settings.settings. var shortcutFile = Properties.Settings.Default.ShortcutFile; var appId = Properties.Settings.Default.AppId; var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), // Not CommonStartMenu "Programs", shortcutFile); var targetPath = Assembly.GetExecutingAssembly().Location; try { var s = new Shortcut(); if (!s.CheckShortcut(shortcutPath, targetPath, String.Empty, appId)) { s.InstallShortcut(shortcutPath, targetPath, String.Empty, appId, targetPath); await Task.Delay(waitingLength); } return(await ShowBaseAsync(headline, body1st, body2nd)); } catch (Exception ex) { Debug.WriteLine("Failed to show a toast {0}", ex); throw; } }
/// <summary> /// Checks and installs a shortcut file in Start menu. /// </summary> /// <param name="shortcutModel">Toast shortcutModel</param> public static void CheckInstallShortcut(ShortcutModel shortcutModel) { var shortcutFilePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), // Not CommonStartMenu "Programs", shortcutModel.ShortcutFileName); var shortcut = new Shortcut(); if (!shortcut.CheckShortcut( shortcutPath: shortcutFilePath, targetPath: shortcutModel.ShortcutTargetFilePath, arguments: shortcutModel.ShortcutArguments, comment: shortcutModel.ShortcutComment, workingFolder: shortcutModel.ShortcutWorkingFolder, windowState: shortcutModel.ShortcutWindowState, iconPath: shortcutModel.ShortcutIconFilePath, appId: shortcutModel.AppId, activatorId: shortcutModel.ActivatorId)) { shortcut.InstallShortcut( shortcutPath: shortcutFilePath, targetPath: shortcutModel.ShortcutTargetFilePath, arguments: shortcutModel.ShortcutArguments, comment: shortcutModel.ShortcutComment, workingFolder: shortcutModel.ShortcutWorkingFolder, windowState: shortcutModel.ShortcutWindowState, iconPath: shortcutModel.ShortcutIconFilePath, appId: shortcutModel.AppId, activatorId: shortcutModel.ActivatorId); System.Threading.Thread.Sleep(_waitingDuration); //await Task.Delay(_waitingDuration); } }