/* * 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); }
/// <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); }
/// <summary> /// Gets the attribute or child (in this order) of the given <see cref="XmlElement"/> with the given name. /// </summary> private static string GetAttributeOrChild(this XmlElement element, string name) { var attribute = element.GetAttribute(name); if (attribute.HasValue()) { return(attribute); } return(element.SelectNode(name)?.InnerText); }
protected virtual void ParseResponse(XmlDocument xmlDoc, PostNewImageResult result) { XmlElement contentEl = xmlDoc.SelectSingleNodeNS("/atom:entry/atom:content", _nsMgr.ToNSMethodFormat()) as XmlElement; result.srcUrl = XmlHelper.GetUrl(contentEl, "@src", null); result.editUri = AtomEntry.GetLink(xmlDoc.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()) as XmlElement, _nsMgr, "edit-media", null, null, null); result.editEntryUri = AtomEntry.GetLink(xmlDoc.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()) as XmlElement, _nsMgr, "edit", null, null, null); result.selfPage = AtomEntry.GetLink(xmlDoc.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()) as XmlElement, _nsMgr, "alternate", null, null, null); }
async void IDownloadImage.CopyImage(ZXingBarcodeImageView image) { EmailMessage emailMessage = new EmailMessage(); string messageBody = "Hello World"; emailMessage.Body = messageBody; var writer = new ZXing.Mobile.BarcodeWriter(); if (image != null && image.BarcodeOptions != null) { writer.Options = image.BarcodeOptions; } if (image != null) { writer.Format = image.BarcodeFormat; } var value = image != null ? image.BarcodeValue : string.Empty; var wb = writer.Write(value); StorageFile tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Barcode_Temp.jpeg", CreationCollisionOption.ReplaceExisting); if (tempFile != null) { CachedFileManager.DeferUpdates(tempFile); await ConvertToJPEGFileAsync(tempFile, wb); var status = await CachedFileManager.CompleteUpdatesAsync(tempFile); var dataPackage = new DataPackage(); dataPackage.SetStorageItems(new List <IStorageItem>() { tempFile }); dataPackage.RequestedOperation = DataPackageOperation.Copy; Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage); ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Image Copied")); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode("Image Copied Successfully")); 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); toast.ExpirationTime = DateTime.Now.AddSeconds(4); ToastNotifier.Show(toast); } }
// Method to display Toast messages, mostly Errors, with sound and 4 seconds duration. private void ShowToastNotification(string title, string stringContent) { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title)); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent)); 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); toast.ExpirationTime = DateTime.Now.AddSeconds(4); ToastNotifier.Show(toast); }
//Show toast notification with retrieved string content: private void DoToast(string stringContent) { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Background tasks Sample")); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent)); 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); }
public async void SaveSearchTerm(string SearchTerm) { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("settings.xml"); var doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(file); var elementHistory = doc.GetElementsByTagName("history"); Windows.Data.Xml.Dom.XmlElement elem = doc.CreateElement("searchedterm"); Windows.Data.Xml.Dom.XmlText text = doc.CreateTextNode(SearchTerm); elementHistory[0].AppendChild(elem); elementHistory[0].LastChild.AppendChild(text); await doc.SaveToFileAsync(file); }
private void OtherDeviceToastNotification(string DeviceName) { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(DeviceName)); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode("The charge on this device is greater than 90%. You can remove the charger now!")); 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); toast.ExpirationTime = DateTime.Now.AddSeconds(15); ToastNotifier.Show(toast); }
/// <summary> /// Sets the attribute or child (in this order) of the given <see cref="XmlElement"/> with the given name. /// </summary> private static void SetAttributeOrChild(this XmlElement element, string name, string value) { var attribute = element.GetAttribute(name); if (attribute.HasValue()) { element.SetAttribute(name, value); } else { var node = element.SelectNode(name); if (node != null) { node.InnerText = value; } } }
public void AddNotification(DateTime startDate, string content) { Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Zadanie do wykonania\n")); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(content)); 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"); var diffrence = (startDate - DateTime.Now).TotalSeconds; DateTime EventDate = DateTime.Now.AddSeconds(diffrence); TimeSpan NotTime = EventDate.Subtract(DateTime.Now); DateTime dueTime = DateTime.Now.Add(NotTime); ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime); ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast); }
private void SetBadgeNumber(int num) { // Get the blank badge XML payload for a badge number XmlDocument badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); // Set the value of the badge in the XML to our number Windows.Data.Xml.Dom.XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as Windows.Data.Xml.Dom.XmlElement; badgeElement.SetAttribute("value", num.ToString()); // Create the badge notification BadgeNotification badge = new BadgeNotification(badgeXml); // Create the badge updater for the application BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication(); // And update the badge badgeUpdater.Update(badge); }
public void SetBadge(int num) { if (0 < num) { //https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-badges var badgeXml = BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber); Windows.Data.Xml.Dom.XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as Windows.Data.Xml.Dom.XmlElement; if (null != badgeElement) { badgeElement.SetAttribute("value", num.ToString()); //XmlDocument badgeXml = new XmlDocument(); //badgeXml.LoadXml(string.Format("<badge value='{0}'/>", badgeNumber)); var badge = new BadgeNotification(badgeXml); BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge); } } else { BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear(); } }
public void messageflex() { ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Уведомление")); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode("Файл успешно создан.")); Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS"); ToastNotification toast = new ToastNotification(toastXml); toast.ExpirationTime = DateTime.Now.AddSeconds(4); toastNotifier.Show(toast); }
public Task <INotificationResult> Notify(INotificationOptions options) { return(Task.Run(() => { ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier(); Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text"); toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(options.Title)); toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(options.Description)); Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); var id = _count.ToString(); var root = toastXml.DocumentElement; root.SetAttribute("launch", id.ToString()); if (!string.IsNullOrEmpty(options.WindowsOptions.LogoUri)) { Windows.Data.Xml.Dom.XmlElement image = toastXml.CreateElement("image"); image.SetAttribute("placement", "appLogoOverride"); var imageUri = options.WindowsOptions.LogoUri; if (!options.WindowsOptions.LogoUri.Contains("//")) { imageUri = $"ms-appx:///{options.WindowsOptions.LogoUri}"; } image.SetAttribute("src", imageUri); toastXml.GetElementsByTagName("binding")[0].AppendChild(image); toastXml.GetElementsByTagName("binding")[0].Attributes[0].InnerText = "ToastGeneric"; } if (options.DelayUntil.HasValue) { ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, options.DelayUntil.Value); ToastNotifier.AddToSchedule(toast); return new NotificationResult() { Action = NotificationAction.NotApplicable }; } else { Windows.UI.Notifications.ToastNotification toast = new Windows.UI.Notifications.ToastNotification(toastXml); toast.Tag = id; _count++; toast.Dismissed += Toast_Dismissed; toast.Activated += Toast_Activated; toast.Failed += Toast_Failed; _notificationOptions.Add(id, options); var waitEvent = new ManualResetEvent(false); _resetEvents.Add(id, waitEvent); ToastNotifier.Show(toast); waitEvent.WaitOne(); INotificationResult result = _eventResult[id]; if (!options.IsClickable && result.Action == NotificationAction.Clicked) // A click is transformed to manual dismiss { result = new NotificationResult() { Action = NotificationAction.Dismissed } } ; if (_resetEvents.ContainsKey(id)) { _resetEvents.Remove(id); } if (_eventResult.ContainsKey(id)) { _eventResult.Remove(id); } if (_notificationOptions.ContainsKey(id)) { _notificationOptions.Remove(id); } return result; } })); }