// 弹出 toast 通知(无 toast 通知 UI,仅放置于操作中心) private void buttonShowToast3_Click(object sender, RoutedEventArgs e) { // 清除本 app 的之前的全部 toast 通知 // ToastNotificationManager.History.Clear(); string toastXml = $@" <toast activationType='foreground' launch='Notification-Toast-Basic-Arguments 3'> <visual> <binding template='ToastGeneric'> <text>toast - title</text> <text>toast - content 3 {DateTime.Now.ToString("mm:ss")}</text> </binding> </visual> </toast>"; XmlDocument toastDoc = new XmlDocument(); toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc); toast.SuppressPopup = true; // 不会弹出 toast 通知 UI,但是会放置于操作中心 toast.Tag = "3"; toast.Activated += Toast_Activated; toast.Dismissed += Toast_Dismissed; toast.Failed += Toast_Failed; ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); }
/// <summary> /// Helper method to display a toast notification. /// </summary> public static void DisplayToast(string message) { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); // Create a two line toast and add audio reminder // Here the xml that will be passed to the // ToastNotification for the toast is retrieved XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); // Set both lines of text XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Geolocation Sample")); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(message)); // now create a xml node for the audio source IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS"); ToastNotification toast = new ToastNotification(toastXml); ToastNotifier.Show(toast); }
private void RaiseAToast(string title, string message) { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); XmlDocument xd = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var elements = xd.GetElementsByTagName("text"); if (!string.IsNullOrEmpty(title)) { elements[0].AppendChild(xd.CreateTextNode(title)); } if (!string.IsNullOrEmpty(message)) { elements[1].AppendChild(xd.CreateTextNode(message)); } ToastNotification tn = new ToastNotification(xd); try { notifier.Show(tn); } catch { } }
private async void OnReminderButtonClicked(object sender, RoutedEventArgs e) { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); if (notifier.Setting != NotificationSetting.Enabled) { var dialog = new MessageDialog("Notifications are currently disabled"); await dialog.ShowAsync(); return; } ToastTemplateType toastTemplate = ToastTemplateType.ToastText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode("Reminder! Check Friends With Paws")); var date = DateTimeOffset.Now.AddSeconds(15); var stnA = new ScheduledToastNotification(toastXml, date); notifier.AddToSchedule(stnA); ToastTemplateType toastTemplateB = ToastTemplateType.ToastText01; XmlDocument toastXmlB = ToastNotificationManager.GetTemplateContent(toastTemplateB); XmlNodeList toastTextElementsB = toastXmlB.GetElementsByTagName("text"); toastTextElementsB[0].AppendChild(toastXmlB.CreateTextNode("Please check what's new with Friends With Paws")); var dateB = DateTimeOffset.Now.AddSeconds(60); IXmlNode toastNodeB = toastXmlB.SelectSingleNode("/toast"); ((XmlElement)toastNodeB).SetAttribute("duration", "long"); var stnB = new ScheduledToastNotification(toastXmlB, dateB); notifier.AddToSchedule(stnB); }
public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails; BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId); if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected) { XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Proximity tag {0} is connect.", bleDevice.Name); ToastNotification toast = new ToastNotification(xml); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); } else { XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Proximity tag {0} is out of range.", bleDevice.Name); ToastNotification toast = new ToastNotification(xml); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); } } catch (Exception e) { } finally { deferral.Complete(); } }
public static void ToastHideOnDismiss(ToastNotifier notifier, ToastNotification sender, ToastDismissedEventArgs args) { if (args.Reason == ToastDismissalReason.UserCanceled || args.Reason == ToastDismissalReason.TimedOut) { notifier.Hide(sender); } }
public static void CreateToast(String xml) { if (!ExecutionMode.IsRunningAsUwp()) { return; } try { if (notifier == null) { notifier = ToastNotificationManager.CreateToastNotifier(); } else { notifier.Hide(toast); } XmlDocument toastXml = new XmlDocument(); toastXml.LoadXml(xml); toast = new ToastNotification(toastXml); notifier.Show(toast); } catch (Exception ex) { Debug.WriteLine("CreateToast Error:" + ex.Message); } }
private void ShowToastNotification(ToastNotification notification) { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); notification.ExpirationTime = DateTime.Now.AddSeconds(4); ToastNotifier.Show(notification); }
public static void ToastMessage(string title, string message, string launchArgument = null) { if (title == null) { throw new ArgumentNullException(nameof(title)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } try { var xmlDoc = NotificationContentBuilder.CreateSimpleToastNotification(title, message, launchArgument); if (xmlDoc != null) { ToastNotification notification = new ToastNotification(xmlDoc); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(notification); } } catch (Exception ex) { // we might have an exception if the message is too long TrackingManagerHelper.Exception(ex, string.Format("ToastMessage exception: {0}", ex.Message)); } }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); IReadOnlyList <GeofenceStateChangeReport> reports = GeofenceMonitor.Current.ReadReports(); foreach (var report in reports) { if ((report.NewState != GeofenceState.None) && (report.NewState != GeofenceState.Removed)) { await StatusFile.AddStatusEntry( report.Geofence.Id, report.NewState == GeofenceState.Entered?EntryType.EnteredZone : EntryType.ExitedZone); } } XmlDocument template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); NotificationTemplateHelper.CompleteToastOrTileTemplate( template, new string[] { "One or more of our fences has been crossed" }, null); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(new ToastNotification(template)); deferral.Complete(); }
public void CreateToastWithXML_Click(object sender, RoutedEventArgs e) { XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04); /* * <toast> * <visual> * <binding template="ToastText04"> * <text id="1"></text> * <text id="2"></text> * <text id="3"></text> * </binding> * </visual> * </toast> */ XmlNodeList nodes = toastXML.GetElementsByTagName("text"); nodes[0].InnerText = "This is my header"; nodes[1].InnerText = "Line 1"; nodes[2].InnerText = "Line 2"; //This does nothing in Toast Notifications //var binding = (XmlElement)toastXML.GetElementsByTagName("binding")[0]; //binding.SetAttribute("branding", "none"); //Add launch parameter toastXML.DocumentElement.SetAttribute("launch", "Activated from XML Toast"); ToastNotification toast = new ToastNotification(toastXML); toast.Activated += toast_Activated; ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); TextBasedXML.Text = XDocument.Parse(toastXML.GetXml()).ToString(); }
/* * Tooast notifications to show various success , progress or failures. */ private void ShowToastNotification(string title, string stringContent) { // Initialize a ToastNotifier. ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); // Add a title and a notification body. toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title)); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent)); Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); // Set audio property to play on notification. Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS"); ToastNotification toast = new ToastNotification(toastXml) { // Set the notification to disappeaar after 4 seconds. ExpirationTime = DateTime.Now.AddSeconds(4) }; // Display the toast. ToastNotifier.Show(toast); }
public LocalNotifier() { // string toastVisual = //$@"<visual> // <binding template='ToastGeneric'> // <text>{title}</text> // <text>{content}</text> // <image src='{image}'/> // <image src='{logo}' placement='appLogoOverride' hint-crop='circle'/> // </binding> //</visual>"; // string toastXmlString = $@"<toast><visual> //<binding template='ToastGeneric'> // <text></text> // <text></text> // </binding> //</visual></toast>"; toastXml = new XmlDocument(); var docElement = toastXml.AppendChild(toastXml.CreateElement("toast")); var visualElem = docElement.AppendChild(toastXml.CreateElement("visual")); var bindElem = visualElem.AppendChild(toastXml.CreateElement("binding")) as XmlElement; { bindElem.SetAttribute("template", "ToastGeneric"); } titleElem = bindElem.AppendChild(toastXml.CreateElement("text")); contentElem = bindElem.AppendChild(toastXml.CreateElement("text")); notifier = ToastNotificationManager.CreateToastNotifier(); }
/// <summary> /// </summary> /// <param name="applicationContext"></param> public WindowsNotificationManager(WindowsApplicationContext?applicationContext = null) { _applicationContext = applicationContext ?? WindowsApplicationContext.FromCurrentProcess(); _launchActionPromise = new TaskCompletionSource <string>(); #if !NETSTANDARD if (ToastNotificationManagerCompat.WasCurrentProcessToastActivated()) { ToastNotificationManagerCompat.OnActivated += OnAppActivated; if (_launchActionPromise.Task.Wait(LaunchNotificationWaitMs)) { LaunchActionId = _launchActionPromise.Task.Result; } } #endif #if NETSTANDARD _toastNotifier = ToastNotificationManager.CreateToastNotifier(_applicationContext.AppUserModelId); #else _toastNotifier = ToastNotificationManagerCompat.CreateToastNotifier(); #endif _notifications = new Dictionary <ToastNotification, Notification>(); }
private async void SaveMatch(object sender, RoutedEventArgs e) { FolderPicker folderPicker = new FolderPicker(); folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; folderPicker.FileTypeFilter.Add("*"); StorageFolder folder = await folderPicker.PickSingleFolderAsync(); ((Matchimpro)list_of_matches.SelectedItem).Save(folder); ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(resourceLoader.GetString("ExportTitle"))); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(resourceLoader.GetString("ExportMessage"))); Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ToastNotification toast = new ToastNotification(toastXml); toast.ExpirationTime = DateTime.Now.AddSeconds(1); ToastNotifier.Show(toast); }
public static async void actionsToast(string title, string content, string id) { string xml = "<toast>" + "<visual>" + "<binding template=\"ToastGeneric\">" + "<text></text>" + "<text></text>" + "</binding>" + "</visual>" + "<actions>" + "<input id=\"content\" type=\"text\" placeHolderContent=\"请输入评论\" />" + "<action content = \"确定\" arguments = \"ok" + id + "\" activationType=\"background\" />" + "<action content = \"取消\" arguments = \"cancel\" activationType=\"background\"/>" + "</actions >" + "</toast>"; // 创建并加载XML文档 XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList elements = doc.GetElementsByTagName("text"); elements[0].AppendChild(doc.CreateTextNode(title)); elements[1].AppendChild(doc.CreateTextNode(content)); // 创建通知实例 ToastNotification notification = new ToastNotification(doc); //// 显示通知 //DateTime statTime = DateTime.Now.AddSeconds(10); //指定应传递 Toast 通知的时间 //ScheduledToastNotification recurringToast = new ScheduledToastNotification(doc, statTime); //创建计划的 Toast 通知对象 //ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast); //向计划中添加 Toast 通知 ToastNotifier nt = ToastNotificationManager.CreateToastNotifier(); nt.Show(notification); }
public async Task RequestToken() { ToastNotifier.Notify(Interfaces.ToastNotificationType.Info, "Auth", "Выполняется вход", TimeSpan.Zero); var loginRequest = new RestRequest($"{restclient.BaseUrl}login", Method.POST); loginRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded"); loginRequest.AddParameter("log", "testuser"); loginRequest.AddParameter("pwd", "testuser"); // loginRequest. restclient.FollowRedirects = false; restresponse = restclient.Execute(loginRequest); loginresponse = restresponse; ToastNotifier.Notify(Interfaces.ToastNotificationType.Info, "Auth", "Cookie получены", TimeSpan.Zero); var postloginRequest = new RestRequest($"{restclient.BaseUrl}profile"); foreach (var cookie in loginresponse.Cookies) { postloginRequest.AddCookie(cookie.Name, cookie.Value); } restclient.FollowRedirects = true; restresponse = restclient.Execute(postloginRequest); postloginResponse = restresponse; await Task.Run((Action)DecodeRestResponse); }
// 弹出 toast 通知(alarm 场景) // 经测试,没有按钮的话则无法实现 alarm 场景的特性 private void buttonShowToast3_Click(object sender, RoutedEventArgs e) { // 清除本 app 的之前的全部 toast 通知 // ToastNotificationManager.History.Clear(); string toastXml = @" <toast activationType='foreground' scenario='alarm' launch='Notification-Toast-Scenario-Arguments 3'> <visual> <binding template='ToastGeneric'> <text>toast - title</text> <text>toast - content 3</text> </binding> </visual> <actions> <action content='确认' arguments='confirm' /> </actions> </toast>"; XmlDocument toastDoc = new XmlDocument(); toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toastNotification); }
// 添加指定的 ScheduledToastNotification 到计划列表中 private void btnAddScheduledToast_Click(object sender, RoutedEventArgs e) { string toastXml = $@" <toast activationType='foreground' launch='Notification-Toast-Schedule-Arguments'> <visual> <binding template='ToastGeneric'> <text>toast - title</text> <text>toast - content {DateTime.Now.ToString("mm:ss")}</text> </binding> </visual> </toast>"; // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象 XmlDocument toastDoc = new XmlDocument(); toastDoc.LoadXml(toastXml); // 实例化 ScheduledToastNotification 对象(15 秒后显示此 Toast 通知,然后每隔 60 秒再显示一次 Toast,循环显示 5 次) // 但是经测试,只会显示一次,无法循环显示,不知道为什么 // ScheduledToastNotification toastNotification = new ScheduledToastNotification(toastDoc, DateTime.Now.AddSeconds(15), TimeSpan.FromSeconds(60), 5); // 实例化 ScheduledToastNotification 对象(15 秒后显示此 Toast 通知) ScheduledToastNotification toastNotification = new ScheduledToastNotification(toastDoc, DateTime.Now.AddSeconds(15)); toastNotification.Id = new Random().Next(100000, 1000000).ToString(); toastNotification.Tag = toastDoc.GetElementsByTagName("text")[1].InnerText; // 将指定的 ScheduledToastNotification 添加进计划列表 ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.AddToSchedule(toastNotification); ShowScheduledToasts(); }
/// <summary> /// Helper method to pop a toast /// </summary> private void DoToast(int numEventsOfInterest, string eventName) { // pop a toast for each geofence event ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); // Create a two line toast and add audio reminder // Here the xml that will be passed to the // ToastNotification for the toast is retrieved Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); // Set both lines of text Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Geolocation Sample")); if (1 == numEventsOfInterest) { toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(eventName)); } else { string secondLine = "There are " + numEventsOfInterest + " new geofence events"; toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(secondLine)); } // now create a xml node for the audio source Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS"); ToastNotification toast = new ToastNotification(toastXml); ToastNotifier.Show(toast); }
private async Task SendNotificationAsync() { try { ReadRepository ReadRepository = new ReadRepository(); var events = await ReadRepository.GetNextEvents(); if (events == null && events.Count > 0) { return; } ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); XmlDocument content = ToastNotificationManager.GetTemplateContent( ToastTemplateType.ToastImageAndText01); var texts = content.GetElementsByTagName("text"); texts[0].InnerText = $"Usted tiene un evento próximo!!"; texts[1].InnerText = $"El evento {events.First().Title} , se realizara el dia {events.First().Date.ToLocalTime()}"; var image = content.GetElementsByTagName("image"); image[0].InnerText = events.First().Image; notifier.Show(new ToastNotification(content)); } catch (Exception ex) { throw; } }
// 弹出 toast 通知(ms-appx 或 ms-appdata 地址的音频文件) private void buttonShowToast2_Click(object sender, RoutedEventArgs e) { // 清除本 app 的之前的全部 toast 通知 // ToastNotificationManager.History.Clear(); string toastXml = $@" <toast activationType='foreground' launch='Notification-Toast-Audio-Arguments 1'> <visual> <binding template='ToastGeneric'> <text>audio</text> <text>演示 toast 的提示音</text> </binding> </visual> <audio src='ms-appx:///Assets/audio.aac' /> </toast>"; XmlDocument toastDoc = new XmlDocument(); toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toastNotification); }
// 弹出 toast 通知(图文按钮) private void buttonShowToast2_Click(object sender, RoutedEventArgs e) { // 清除本 app 的之前的全部 toast 通知 // ToastNotificationManager.History.Clear(); string toastXml = @" <toast activationType='foreground' launch='Notification-Toast-ActionButton-Arguments 2'> <visual> <binding template='ToastGeneric'> <text>toast - title</text> <text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text> </binding> </visual> <actions> <action content='确认' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 confirm' imageUri='Assets/StoreLogo.png' /> <action content='取消' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 cancel' imageUri='Assets/StoreLogo.png' /> </actions> </toast>"; XmlDocument toastDoc = new XmlDocument(); toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toastNotification); }
private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { var toast = args.ToastNotification; ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); ToastNotifier.Show(toast); }
public static void Show(ToastParameters parameters) { FileInfo tempIcon; if (parameters.IconUri != null && parameters.AppUserModelId != null) { tempIcon = new FileInfo(Path.Combine(Path.GetTempPath(), $"tmp_icon_{parameters.AppUserModelId}.png")); if (!tempIcon.Exists || DateTime.Now - tempIcon.LastWriteTime > TimeSpan.FromDays(7)) { using (var iconStream = Application.GetResourceStream(parameters.IconUri)?.Stream) { if (iconStream != null) { using (var file = new FileStream(tempIcon.FullName, FileMode.Create)) { iconStream.CopyTo(file); } } } } } else { tempIcon = null; } var content = new XmlDocument(); content.LoadXml(tempIcon == null ? $@"<toast> <visual> <binding template=""ToastText02""> <text id=""1"">{parameters.Title}</text> <text id=""2"">{parameters.Message}</text> </binding> </visual> </toast>" : $@"<toast> <visual> <binding template=""ToastImageAndText02""> <image id=""1"" src=""file://{tempIcon.FullName}""/> <text id=""1"">{parameters.Title}</text> <text id=""2"">{parameters.Message}</text> </binding> </visual> </toast>"); var toast = new ToastNotification(content); if (parameters.ClickCallback != null) { toast.Activated += (sender, args) => (Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher).Invoke(parameters.ClickCallback); } if (_toastNotifier == null) { _toastNotifier = parameters.BoundToCallingApplication || parameters.AppUserModelId == null? ToastNotificationManager.CreateToastNotifier() : ToastNotificationManager.CreateToastNotifier(parameters.AppUserModelId); } _toastNotifier.Show(toast); }
/// <summary> /// Initializes a new instance of the <see cref="CodeWithKemonoFriends"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private CodeWithKemonoFriends(Package package) { _package = package ?? throw new ArgumentNullException(nameof(package)); OleMenuCommandService commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) { var menuCommandId = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); commandService.AddCommand(menuItem); } // このプロジェクトのディレクトリを取得 var codebase = typeof(CodeWithKemonoFriends).Assembly.CodeBase; var uri = new Uri(codebase, UriKind.Absolute); _projectDirectory = Path.GetDirectoryName(uri.LocalPath); // イベントを初期化 var dte = (DTE)ServiceProvider.GetService(typeof(DTE)); _buildEvents = dte.Events.BuildEvents; _debuggerEvents = dte.Events.DebuggerEvents; // Notifierを初期化 var appId = "VisualStudio." + dte.RegistryRoot.Split('_').Last(); _notifier = ToastNotificationManager.CreateToastNotifier(appId); }
public void RefreshCallNotification(IEnumerable <Call> currentCalls) { IReadOnlyList <ToastNotification> notifications = ToastNotificationHistory.GetHistory(); bool badState = notifications.Count == 0 || notifications.Any(x => { if (x.Data != null) { List <uint> ids = x.Data.Values[USED_CALLS].Split(';').Where(y => !string.IsNullOrEmpty(y)).Select(y => uint.Parse(y)).ToList(); List <CallState> states = x.Data.Values[USED_CALLS_STATES].Split(';').Where(y => !string.IsNullOrEmpty(y)).Select(y => (CallState)Enum.Parse(typeof(CallState), y)).ToList(); List <Tuple <uint, CallState> > prev = ids.Join(states, y => ids.IndexOf(y), y => states.IndexOf(y), (x, y) => new Tuple <uint, CallState>(x, y)).ToList(); return(!prev.All(y => currentCalls.Any(z => z.ID == y.Item1 && z.State == y.Item2))); } else { return(false); } }); if (badState) { RemoveCallToastNotifications(notifications); ToastNotification notification = CreateCallNotification(currentCalls); if (notification != null) { ToastNotifier.Show(notification); } } }
public static void wyswietlNotyfikacje() { XmlNodeList toastTextAttributes = toastXml.GetElementsByTagName("text"); String napis; //losowanie Random r = new Random(); int x = r.Next(0, i); try { napis = dane[x]; } catch (Exception) { napis = "Pusty słownik."; }; toastTextAttributes[0].InnerText = napis; //okreslenie kiedy ma sie pojawic: Int16 odstepSek = 1; DateTime dueTime = DateTime.Now.AddSeconds(odstepSek); ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.AddToSchedule(scheduledToast); }
private static void ShowToast(string shortUserLevelMessage, Exception exception, string fullDetailedMessage, bool showSendReport = true) { var formForSynchronizing = Application.OpenForms.Cast <Form>().LastOrDefault(); if (formForSynchronizing == null) { return; // can't safely show a toast, may be on wrong thread. } if (formForSynchronizing.InvokeRequired) { formForSynchronizing.BeginInvoke(new Action(() => { ShowToast(shortUserLevelMessage, exception, fullDetailedMessage, showSendReport); })); return; } var toast = new ToastNotifier(); var callToAction = string.Empty; if (showSendReport) { toast.ToastClicked += (s, e) => { ProblemReportApi.ShowProblemDialog(formForSynchronizing, exception, fullDetailedMessage, "nonfatal"); }; callToAction = "Report"; } toast.Image.Image = ToastNotifier.WarningBitmap; toast.Show(shortUserLevelMessage, callToAction, 5); }
private void DeleteNotification() { if (NotificationListView.SelectedItem == null) { ShowMessage("Brak wybranego elementu."); } else { NotificationItem notItem = NotificationListView.SelectedItem as NotificationItem; String id = notItem.Id; ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); List <ScheduledToastNotification> initialList = new List <ScheduledToastNotification>(); initialList = notifier.GetScheduledToastNotifications().ToList(); foreach (ScheduledToastNotification item in initialList) { if (item.Id == id) { notifier.RemoveFromSchedule(item); break; } } NotificationList.Remove(notItem); } }
/// <summary> /// Creates and initializes a new instance of the ToastNotifier, which lets you display toast notifications. /// </summary> /// <returns></returns> /// <remarks> /// <para/><list type="table"> /// <listheader><term>Platform</term><description>Version supported</description></listheader> /// <item><term>Android</term><description>Android 4.4 and later</description></item> /// <item><term>iOS</term><description>iOS 9.0 and later</description></item> /// <item><term>Windows UWP</term><description>Windows 10</description></item> /// <item><term>Windows Store</term><description>Windows 8.1 or later</description></item> /// <item><term>Windows Phone Store</term><description>Windows Phone 8.1 or later</description></item> /// <item><term>Windows Phone Silverlight</term><description>Windows Phone 8.1 or later</description></item></list> /// </remarks> public static ToastNotifier CreateToastNotifierForApplication() { if(_notifier == null) { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81 _notifier = new ToastNotifier(Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier()); #else _notifier = new ToastNotifier(); #endif } return _notifier; }