public static async Task HandleIncomingConnections() { bool runServer = true; // While a user hasn't visited the `shutdown` url, keep on handling requests while (runServer) { // Will wait here until we hear from a connection HttpListenerContext ctx = await listener.GetContextAsync(); // Peel out the requests and response objects HttpListenerRequest req = ctx.Request; HttpListenerResponse resp = ctx.Response; //Receive Json var context = listener.GetContext(); var request = context.Request; string json; using (var reader = new StreamReader(request.InputStream, request.ContentEncoding)) { json = reader.ReadToEnd(); } Console.WriteLine(json); ToastManager.ShowAsync(json) .ContinueWith(result => Console.WriteLine(result.Result)) .Wait(); } }
private static int ShowToast(RequestType type, ref IntPtr data) { string input = Utilities.GetData(ref data); if (String.IsNullOrWhiteSpace(input)) { return(ReturnType.Continue); } ToastRequest request; switch (type) { case RequestType.Xml: request = new ToastRequest { Xml = input, AppId = AppId, ActivatorId = typeof(NotificationActivator).GUID }; break; case RequestType.Json: request = new ToastRequest(input) { AppId = AppId, ActivatorId = typeof(NotificationActivator).GUID }; break; default: return(ReturnType.Continue); } if (string.IsNullOrWhiteSpace(request.Group)) { request.Group = Instance.NextGroup; } if (string.IsNullOrWhiteSpace(request.Tag)) { request.Tag = Instance.NextTag; } const string Format = "/.timer 1 0 if ($isalias({0})) {{ noop ${0}($unsafe({1}).undo,{2}) }}"; ToastManager.ShowAsync(request). ContinueWith(result => { Instance.mIRC.Exec(String.Format(Format, Instance.OnCompleteCallback, Utilities.Base64Encode(request.Tag), result.Result)); }); Utilities.SetData(ref data, request.Tag); return(ReturnType.Return); }
private async Task <string> ShowToastAsync() { var request = new ToastRequest { ToastTitle = "DesktopToast WinForms Sample", ToastBodyList = new[] { "This is a toast test.", "Looping sound will be played." }, AppId = "DesktopToast.WinForms", }; var result = await ToastManager.ShowAsync(request); return(result.ToString()); }
public void Show() { ToastManager.ShowAsync(this.request) .ContinueWith(t => { if (t.Result == ToastResult.Activated) { this.Activated?.Invoke(); } if (t.Result == ToastResult.Failed) { this.ToastFailed?.Invoke(); } }); }
private async Task <string> ShowInteractiveToastAsync() { var request = new ToastRequest { ToastXml = ComposeInteractiveToast(), ShortcutFileName = "Lucid Dream.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "Lucid Dream", ActivatorId = typeof(NotificationActivator).GUID }; var result = await ToastManager.ShowAsync(request); return(result.ToString()); }
/// <summary> /// 创建一个Toast Notification并显示 /// </summary> /// <param name="Body">第一行文本</param> /// <param name="BodyExtra">第二行文本</param> public static void CreateToastNotification(string Body, string BodyExtra = "") { var request = new ToastRequest { ToastHeadline = "EPIC", ToastBody = Body, ToastBodyExtra = BodyExtra, ToastAudio = ToastAudio.Default, ShortcutFileName = "EPIC.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "pw.baka.epic", }; var result = ToastManager.ShowAsync(request); }
private async Task <string> ShowInteractiveToastAsync(int expire) { var request = new ToastRequest { ToastXml = ComposeInteractiveToast(), ShortcutFileName = "NWS Alerts.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, ShortcutWorkingFolder = AppDomain.CurrentDomain.BaseDirectory, AppId = "NWS Alerts", ActivatorId = typeof(NotificationActivator).GUID }; var result = await ToastManager.ShowAsync(request, expire); return(result.ToString()); }
private async Task <string> ShowToastAsync() { var request = new ToastRequest { ToastTitle = "DesktopToast WinForms Sample", ToastBodyList = new[] { "This is a toast test.", "Looping sound will be played." }, ToastAudio = DesktopToast.ToastAudio.LoopingCall, ShortcutFileName = "DesktopToast.WinForms.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "DesktopToast.WinForms", }; var result = await ToastManager.ShowAsync(request); return(result.ToString()); }
private async Task <string> ShowToastAsync(string HeadLine, string Body) { var request = new ToastRequest { ToastHeadline = HeadLine, ToastBody = Body, ShortcutFileName = "DejizoToaster.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "DejizoToaster.WinForms", ToastAudio = ToastAudio.Silent }; var result = await ToastManager.ShowAsync(request); return(result.ToString()); }
public static void SendToastAsync(string body, NoticeType type) { var audio = GetAudioFromType(type); var title = GetTitleFromType(type); var request = new ToastRequest { ToastAudio = audio, ToastTitle = title, ToastBody = body, ShortcutFileName = "zRageAdminMain.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "zRageAdminMain", }; ToastManager.ShowAsync(request).RunSynchronously(); }
private async Task <string> ShowToastAsync() { var request = new ToastRequest { ToastTitle = "DesktopToast WPF Sample", ToastBody = "This is a toast test.", ToastLogoFilePath = string.Format("file:///{0}", Path.GetFullPath("Resources/toast128.png")), ShortcutFileName = "DesktopToast.Wpf.lnk", ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = "DesktopToast.Wpf", ActivatorId = typeof(NotificationActivator).GUID // For Action Center of Windows 10 }; var result = await ToastManager.ShowAsync(request); return(result.ToString()); }
public static async Task <string> ShowNotification(Slot slot) { var body = string.Format(Resources.NoticeSlotRsvBody, slot.Title); var result = ""; if (NormaConstants.IsSupportedToast) { var toastXml = ComposeInteractiveToast(Resources.NoticeSlotRsvTitle, body, slot); var toastRequest = new ToastRequest { ToastXml = toastXml, ShortcutFileName = NormaConstants.IpsilonLinkName, #if DEBUG ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, #else ShortcutTargetFilePath = NormaConstants.IpsilonExecutableFile, #endif AppId = NormaConstants.IpsilonAppId, ToastLogoFilePath = $"file:///{Path.GetFullPath("Resources/128.png")}" }; if (NormaConstants.IsSupportedNewToast) { toastRequest.ActivatorId = typeof(NotificationActivator).GUID; } var rs = await ToastManager.ShowAsync(toastRequest); result = rs.ToString(); } else { Dispatcher.CurrentDispatcher.Invoke(() => { // Shell.TaskbarIcon.ShowBalloonTip(Resources.NoticeSlotRsvTitle, body, BalloonIcon.Info); }); } return(result); }
/// <summary> /// Show a toast to notify copy completed. /// </summary> private async Task ShowToastAsync() { if (!OsVersion.IsEightOrNewer) { return; } if ((countFileCopied <= 0) || (DateTime.Now - CopyStartTime < toastThresholdLength)) { return; } var result = await ToastManager.ShowAsync( Resources.ToastHeadline_CopyCompleted, Resources.ToastBody_CopyCompleted1st, String.Format(Resources.ToastBody_CopyCompleted2nd, countFileCopied, (int)(DateTime.Now - CopyStartTime).TotalSeconds)); if (result == ToastResult.Activated) { IsWindowActivateRequested = true; // Activating Window is requested. } }
static void Main(string[] args) { // Create a Http server and start listening for incoming connections listener = new HttpListener(); listener.Prefixes.Add(url); listener.Start(); Console.WriteLine("Listening for connections on {0}", url); // Handle requests Task listenTask = HandleIncomingConnections(); listenTask.GetAwaiter().GetResult(); // Close the listener listener.Close(); var requestString = args.Any() ? args[0] : null; if (requestString == null) { #if DEBUG requestString = @"{ ""ShortcutFileName"":""DesktopToast.Proxy.lnk"", ""ShortcutTargetFilePath"":""C:\\DesktopToast.Proxy.exe"", ""ToastTitle"":""DesktopToast Proxy Sample"", ""ToastBody"":""This is a toast test."", ""AppId"":""DesktopToast.Proxy"", }" ; #endif #if !DEBUG return; #endif } ToastManager.ShowAsync(requestString) .ContinueWith(result => Console.WriteLine(result.Result)) .Wait(); }
/// <summary> /// Shows a toast to notify completion of copying. /// </summary> private async Task ShowToastAsync() { if (!OsVersion.IsEightOrNewer || (_copyFileCount <= 0) || (DateTime.Now - CopyStartTime < _copyToastShortestDuration)) { return; } var request = new ToastRequest { ToastHeadline = Resources.ToastHeadline_CopyCompleted, ToastBody = Resources.ToastBody_CopyCompleted, ToastBodyExtra = string.Format(Resources.ToastBodyExtra_CopyCompleted, _copyFileCount, (int)(DateTime.Now - CopyStartTime).TotalSeconds), ShortcutFileName = Properties.Settings.Default.ShortcutFileName, ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location, AppId = Properties.Settings.Default.AppId }; var result = await ToastManager.ShowAsync(request); if (result == ToastResult.Activated) { ActivateRequested?.Invoke(this, EventArgs.Empty); } }
static void Main(string[] args) { var requestString = args.Any() ? args[0] : null; if (requestString == null) { #if DEBUG requestString = @"{ ""ShortcutFileName"":""DesktopToast.Proxy.lnk"", ""ShortcutTargetFilePath"":""C:\\DesktopToast.Proxy.exe"", ""ToastTitle"":""DesktopToast Proxy Sample"", ""ToastBody"":""This is a toast test."", ""AppId"":""DesktopToast.Proxy"", }"; #endif #if !DEBUG return; #endif } ToastManager.ShowAsync(requestString) .ContinueWith(result => Console.WriteLine(result.Result)) .Wait(); }