public CreateElement ( [ tagName ) : |
||
tagName | [ | |
return |
public static ToastNotification PopToast(string title, string content, string tag, string group) { string xml = $@"<toast activationType='foreground'> <visual> <binding template='ToastGeneric'> </binding> </visual> </toast>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); var binding = doc.SelectSingleNode("//binding"); var el = doc.CreateElement("text"); el.InnerText = title; binding.AppendChild(el); el = doc.CreateElement("text"); el.InnerText = content; binding.AppendChild(el); return PopCustomToast(doc, tag, group); }
/// <summary> /// Set the application's tile to display a local image file. /// After clicking, go back to the start screen to watch your application's tile update. /// </summary> private void SetTileImageButtonClick(object sender, RoutedEventArgs e) { // It is possible to start from an existing template and modify what is needed. // Alternatively you can construct the XML from scratch. var tileXml = new XmlDocument(); var title = tileXml.CreateElement("title"); var visual = tileXml.CreateElement("visual"); visual.SetAttribute("version", "1"); visual.SetAttribute("lang", "en-US"); // The template is set to be a TileSquareImage. This tells the tile update manager what to expect next. var binding = tileXml.CreateElement("binding"); binding.SetAttribute("template", "TileSquareImage"); // An image element is then created under the TileSquareImage XML node. The path to the image is specified var image = tileXml.CreateElement("image"); image.SetAttribute("id", "1"); image.SetAttribute("src", @"ms-appx:///Assets/DemoImage.png"); // All the XML elements are chained up together. title.AppendChild(visual); visual.AppendChild(binding); binding.AppendChild(image); tileXml.AppendChild(title); // The XML is used to create a new TileNotification which is then sent to the TileUpdateManager var tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
private async void doAuditing(Order order) { List<OrderItem> ageRestrictedItems = findAgeRestrictedItems(order); if (ageRestrictedItems.Count > 0) { try { StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("audit-" + order.OrderID.ToString() + ".xml"); if (file != null) { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("Order"); root.SetAttribute("ID", order.OrderID.ToString()); root.SetAttribute("Date", order.Date.ToString()); foreach (OrderItem orderItem in ageRestrictedItems) { XmlElement itemElement = doc.CreateElement("Item"); itemElement.SetAttribute("Product", orderItem.Item.Name); itemElement.SetAttribute("Description", orderItem.Item.Description); root.AppendChild(itemElement); } doc.AppendChild(root); await doc.SaveToFileAsync(file); } else { MessageDialog dlg = new MessageDialog(String.Format("Unable to save to file: {0}", file.DisplayName), "Not saved"); dlg.ShowAsync(); } } catch (Exception ex) { MessageDialog dlg = new MessageDialog(ex.Message, "Exception"); dlg.ShowAsync(); } finally { if (this.AuditProcessingComplete != null) { this.AuditProcessingComplete(String.Format( "Audit record written for Order {0}", order.OrderID)); } } } }
private static void SetToatAudio(XmlDocument xml) { var node = xml.SelectSingleNode("/toast"); var audio = xml.CreateElement("audio"); audio.SetAttribute("src", "ms-winsoundevent:Notification.IM"); node.AppendChild(audio); }
protected virtual async Task <XmlDocument> GetCategoryXml(string blogId) { // Get the service document Login(); FixupBlogId(ref blogId); XmlRestRequestHelper.XmlRequestResult result = new XmlRestRequestHelper.XmlRequestResult(); result.uri = FeedServiceUrl; var xmlDoc = await xmlRestRequestHelper.Get(RequestFilter, result); foreach (XmlElement entryEl in xmlDoc.SelectNodesNS("app:service/app:workspace/app:collection", _nsMgr.ToNSMethodFormat())) { string href = XmlHelper.GetUrl(entryEl, "@href", result.uri); if (blogId == href) { XmlDocument results = new XmlDocument(); XmlElement rootElement = results.CreateElement("categoryInfo"); results.AppendChild(rootElement); foreach (XmlElement categoriesNode in entryEl.SelectNodesNS("app:categories", _nsMgr.ToNSMethodFormat())) { await AddCategoriesXml(categoriesNode, rootElement, result); } return(results); } } //Debug.Fail("Couldn't find collection in service document:\r\n" + xmlDoc.OuterXml); return(new XmlDocument()); }
public static void Toast(string msg) { //1. create element ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); //2.设置消息文本 XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(msg)); //3. 图标 Windows.Data.Xml.Dom.XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); ((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///Assets/StoreLogo.png"); ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo"); // 4. duration IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((XmlElement)toastNode).SetAttribute("duration", "short"); // 5. audio XmlElement audio = toastXml.CreateElement("audio"); audio.SetAttribute("src", $"ms-winsoundevent:Notification.SMS"); toastNode.AppendChild(audio); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public static void CompleteTemplate(XmlDocument xml, string[] text, string[] images = null, string sound = null) { XmlNodeList slots = xml.SelectNodes("descendant-or-self::image"); int index = 0; if ((images != null) && (slots != null)) { while ((index < images.Length) && (index < slots.Length)) { ((XmlElement)slots[index]).SetAttribute("src", images[index]); index++; } } if (text != null) { slots = xml.SelectNodes("descendant-or-self::text"); index = 0; while ((slots != null) && ((index < text.Length) && (index < slots.Length))) { slots[index].AppendChild(xml.CreateTextNode(text[index])); index++; } } if (!string.IsNullOrEmpty(sound)) { var audioElement = xml.CreateElement("audio"); audioElement.SetAttribute("src", sound); xml.DocumentElement.AppendChild(audioElement); } }
public static ToastNotification DisplayToast(string content) { string xml = $@"<toast activationType='foreground'> <visual> <binding template='ToastGeneric'> <text>Extended Execution</text> </binding> </visual> </toast>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); var binding = doc.SelectSingleNode("//binding"); var el = doc.CreateElement("text"); el.InnerText = content; binding.AppendChild(el); //Add content to notification var toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); //Show the toast return toast; }
public static XmlDocument CreateTileTemplate(Wallpaper wallpaper) { XmlDocument document = new XmlDocument(); // tile 根节点。 XmlElement tile = document.CreateElement("tile"); document.AppendChild(tile); // visual 元素。 XmlElement visual = document.CreateElement("visual"); tile.AppendChild(visual); // Medium,150x150。 { // binding XmlElement binding = document.CreateElement("binding"); binding.SetAttribute("template", "TileMedium"); visual.AppendChild(binding); // image XmlElement image = document.CreateElement("image"); image.SetAttribute("src", wallpaper.GetOriginalUrl(new WallpaperSize(150, 150))); image.SetAttribute("placement", "background"); binding.AppendChild(image); // text XmlElement text = document.CreateElement("text"); text.AppendChild(document.CreateTextNode(wallpaper.Archive.Info)); text.SetAttribute("hint-wrap", "true"); binding.AppendChild(text); } // Wide,310x150。 { // binding XmlElement binding = document.CreateElement("binding"); binding.SetAttribute("template", "TileWide"); visual.AppendChild(binding); // image XmlElement image = document.CreateElement("image"); image.SetAttribute("src", wallpaper.GetOriginalUrl(new WallpaperSize(310, 150))); image.SetAttribute("placement", "background"); binding.AppendChild(image); // text XmlElement text = document.CreateElement("text"); text.AppendChild(document.CreateTextNode(wallpaper.Archive.Info)); text.SetAttribute("hint-wrap", "true"); binding.AppendChild(text); } return document; }
protected virtual XmlElement GetParentElement(XmlDocument toastContent, string parentName) { var root = toastContent.DocumentElement; var parentElement = root.SelectSingleNode(parentName) as XmlElement; if (parentElement == null) { parentElement = toastContent.CreateElement(parentName); root.AppendChild(parentElement); } return parentElement; }
private XmlElement CreateCommandElement(XmlDocument toastContent) { var commandElement = toastContent.CreateElement("command"); if (CommandId != ToastCommandId.None) { commandElement.SetAttribute("id", CommandId.ToString().ToLower()); } if (!string.IsNullOrWhiteSpace(Arguments)) { commandElement.SetAttribute("arguments", Arguments); } return commandElement; }
public static async Task SaveOPMLFile(StorageFile libraryFile) { var document = new Windows.Data.Xml.Dom.XmlDocument(); var rootNode = document.CreateElement("opml"); rootNode.AddAttribute("version", "1.1"); document.AppendChild(rootNode); var headNode = document.CreateElement("head"); headNode.AddChildWithInnerText("title", "Generated by Cast"); headNode.AddChildWithInnerText("dateCreated", DateTime.Now.ToString(CultureInfo.InvariantCulture)); rootNode.AppendChild(headNode); var bodyNode = document.CreateElement("body"); rootNode.AppendChild(bodyNode); foreach (var category in Categories) { var categoryNode = document.CreateElement("outline"); bodyNode.AppendChild(categoryNode); categoryNode.AddAttribute("text", category); foreach (var podcast in Podcasts.Where(p => p.Category == category)) { var podcastNode = document.CreateElement("outline"); categoryNode.AppendChild(podcastNode); podcastNode.AddAttribute("title", podcast.Title); podcastNode.AddAttribute("type", "rss"); podcastNode.AddAttribute("text", podcast.FeedUrl); podcastNode.AddAttribute("xmlUrl", podcast.FeedUrl); } } await document.SaveToFileAsync(libraryFile); }
public static void SendToast(string txt, string imgurl = "") { if (toaster.Setting != NotificationSetting.Enabled) return; // It is possible to start from an existing template and modify what is needed. // Alternatively you can construct the XML from scratch. var toastXml = new Windows.Data.Xml.Dom.XmlDocument(); var title = toastXml.CreateElement("toast"); var visual = toastXml.CreateElement("visual"); visual.SetAttribute("version", "1"); visual.SetAttribute("lang", "en-US"); // The template is set to be a ToastImageAndText01. This tells the toast notification manager what to expect next. var binding = toastXml.CreateElement("binding"); binding.SetAttribute("template", "ToastImageAndText01"); // An image element is then created under the ToastImageAndText01 XML node. The path to the image is specified var image = toastXml.CreateElement("image"); image.SetAttribute("id", "1"); image.SetAttribute("src", imgurl); // A text element is created under the ToastImageAndText01 XML node. var text = toastXml.CreateElement("text"); text.SetAttribute("id", "1"); text.InnerText = txt; // All the XML elements are chained up together. title.AppendChild(visual); visual.AppendChild(binding); binding.AppendChild(image); binding.AppendChild(text); toastXml.AppendChild(title); // Create a ToastNotification from our XML, and send it to the Toast Notification Manager var toast = new ToastNotification(toastXml); toaster.Show(toast); }
/// <summary> /// Init the Connector. Create the File if not exist, or open and load it. /// </summary> public async void InitDataBase() { var localFolder = ApplicationData.Current.LocalFolder; _rootDocument = new XmlDocument(); _databaseXmlFile = await localFolder.CreateFileAsync("TaskTimeRecorder.xml", CreationCollisionOption.OpenIfExists); var fileContent = await FileIO.ReadTextAsync(_databaseXmlFile); if (fileContent == "") { var rootElement = _rootDocument.CreateElement("TaskTimeRecorder"); var tasksElement = _rootDocument.CreateElement("Tasks"); rootElement.AppendChild(tasksElement); _rootDocument.AppendChild(rootElement); _rootDocument.SaveToFileAsync(_databaseXmlFile); } else { _rootDocument.LoadXml(fileContent); LoadAllTasks(); } }
/// <summary> /// Raises a image toast notification locally. /// IMPORTANT: if copying this into your own application, ensure that "Toast capable" is enabled in the application manifest /// </summary> private void NotificationImageButton_Click(object sender, RoutedEventArgs e) { // It is possible to start from an existing template and modify what is needed. // Alternatively you can construct the XML from scratch. var toastXml = new XmlDocument(); var title = toastXml.CreateElement("toast"); var visual = toastXml.CreateElement("visual"); visual.SetAttribute("version", "1"); visual.SetAttribute("lang", "en-US"); // The template is set to be a ToastImageAndText01. This tells the toast notification manager what to expect next. var binding = toastXml.CreateElement("binding"); binding.SetAttribute("template", "ToastImageAndText01"); // An image element is then created under the ToastImageAndText01 XML node. The path to the image is specified var image = toastXml.CreateElement("image"); image.SetAttribute("id", "1"); image.SetAttribute("src", @"Assets/DemoImage.png"); // A text element is created under the ToastImageAndText01 XML node. var text = toastXml.CreateElement("text"); text.SetAttribute("id", "1"); text.InnerText = "Another sample toast. This time with an image"; // All the XML elements are chained up together. title.AppendChild(visual); visual.AppendChild(binding); binding.AppendChild(image); binding.AppendChild(text); toastXml.AppendChild(title); // Create a ToastNotification from our XML, and send it to the Toast Notification Manager var toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); }
public List<string> getList(string franchUserID, string password, string userID, string userKey, string username, string userrole, string userstatus, string usertype) { List<string> servicesNames = new List<string>(); XmlDocument doc = new XmlDocument(); XmlElement el = (XmlElement)doc.AppendChild(doc.CreateElement("soapenv:Header")); el.SetAttribute("Bar", "some & value"); return servicesNames; }
private void ShowToastNotification() { for (int i = 0; i < ViewModel.AllItems.Count; i++) { if (ViewModel.AllItems[i].date.Day == DateTime.Now.Day) { ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); Windows.Data.Xml.Dom.XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); toastTextElements[0].AppendChild(toastXml.CreateTextNode(ViewModel.AllItems[i].title + "\n" + ViewModel.AllItems[i].description)); Windows.Data.Xml.Dom.XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image"); IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); ((Windows.Data.Xml.Dom.XmlElement)toastImageAttributes[0]).SetAttribute("src", "Assets//2015071504.jpg"); Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio"); ((Windows.Data.Xml.Dom.XmlElement)toastNode).SetAttribute("duration", "long"); audio.SetAttribute("silent", "true"); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); } } }
public Toast(string header, string body) { XmlDocument doc = new XmlDocument(); ; doc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var test = doc.DocumentElement; XmlElement audio = doc.CreateElement("audio"); if (!string.IsNullOrEmpty(sound.FileCheck(header))) audio.SetAttribute("silent", "true"); test.AppendChild(audio); doc = test.OwnerDocument; var toastXml = doc; var stringElements = toastXml.GetElementsByTagName("text"); if (stringElements.Length == 2) { stringElements[0].AppendChild(toastXml.CreateTextNode(header)); stringElements[1].AppendChild(toastXml.CreateTextNode(body)); } this.toast = new ToastNotification(toastXml); }
private async void CheckGoodsFile() { try { Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync("Goods.xml"); } catch(IOException e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = await storageFolder.CreateFileAsync("Goods.xml", CreationCollisionOption.ReplaceExisting); XmlDocument doc = new XmlDocument(); XmlElement ele = doc.CreateElement("orders"); ele.InnerText = ""; doc.AppendChild(ele); await doc.SaveToFileAsync(storageFile); } try { Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync("ShoppingCart.xml"); } catch (IOException e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = await storageFolder.CreateFileAsync("ShoppingCart.xml", CreationCollisionOption.ReplaceExisting); XmlDocument doc = new XmlDocument(); XmlElement ele = doc.CreateElement("goods"); ele.InnerText = ""; doc.AppendChild(ele); await doc.SaveToFileAsync(storageFile); } }
private static void SetSilent(bool useSound, XmlDocument toastXml) { var audio = toastXml.GetElementsByTagName("audio").FirstOrDefault(); if (audio == null) { audio = toastXml.CreateElement("audio"); var toastNode = ((XmlElement)toastXml.SelectSingleNode("/toast")); if (toastNode != null) { toastNode.AppendChild(audio); } } var attribute = toastXml.CreateAttribute("silent"); attribute.Value = (!useSound).ToString().ToLower(); audio.Attributes.SetNamedItem(attribute); }
private async void GenerateGpx(LondonBicycles.Data.Models.Point myLocation, LondonBicycles.Data.Models.Point destination) { if (this.route.RoutePoints.Count() > 0) { XmlDocument doc = new XmlDocument(); XmlElement gpx = doc.CreateElement("gpx"); gpx.SetAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); gpx.SetAttribute("version", "1.1"); gpx.SetAttribute("creator", "London Bicycles"); gpx.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); XmlElement wptStart = doc.CreateElement("wpt"); wptStart.SetAttribute("lon", myLocation.Longitude.ToString()); wptStart.SetAttribute("lat", myLocation.Latitude.ToString()); gpx.AppendChild(wptStart); XmlElement wptEnd = doc.CreateElement("wpt"); wptEnd.SetAttribute("lon", destination.Longitude.ToString()); wptEnd.SetAttribute("lat", destination.Latitude.ToString()); gpx.AppendChild(wptEnd); XmlElement track = doc.CreateElement("trk"); XmlElement trackSegment = doc.CreateElement("trkseg"); foreach (var point in this.route.RoutePoints) { XmlElement trackPoint = doc.CreateElement("trkpt"); XmlAttribute lonTrack = doc.CreateAttribute("lon"); lonTrack.Value = point.Longitude.ToString(); XmlAttribute latTrack = doc.CreateAttribute("lat"); latTrack.Value = point.Latitude.ToString(); trackPoint.SetAttribute("lon", point.Longitude.ToString()); trackPoint.SetAttribute("lat", point.Latitude.ToString()); trackSegment.AppendChild(trackPoint); } track.AppendChild(trackSegment); gpx.AppendChild(track); doc.AppendChild(gpx); string text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; text += doc.GetXml(); StorageFolder sf = Windows.Storage.ApplicationData.Current.RoamingFolder; StorageFile file = await sf.CreateFileAsync("route.gpx", CreationCollisionOption.ReplaceExisting); Windows.Storage.FileIO.WriteTextAsync(file, text); this.gpxFile = file; this.RegisterForShare(); } }
public XmlElement ToXmlElement(XmlDocument doc) { XmlElement el = doc.CreateElement("Utterance"); XmlElement transcriptEl = doc.CreateElement("Transcript"); transcriptEl.InnerText = Transcript; XmlElement fileEl = doc.CreateElement("File"); fileEl.InnerText = AudioFile.Path; el.AppendChild(fileEl); el.AppendChild(transcriptEl); return el; }
/// <summary> /// Appends a wide tile with a big block of text. Used to display up-coming buses. /// </summary> public void AppendTileWithBlockTextAndLines(DateTimeOffset scheduledTime, string blockText, string statusText, string busName, string tripHeadsign, string stopName, string scheduledArrivalTime, string predictedArrivalTime) { //<tile> // <visual> // <binding template="TileWideBlockAndText01"> // <text id="1">Text Field 1</text> // <text id="2">Text Field 2</text> // <text id="3">Text Field 3</text> // <text id="4">Text Field 4</text> // <text id="5">T5</text> // <text id="6">Text Field 6</text> // </binding> // </visual> //</tile> var document = new XmlDocument(); var rootElement = document.CreateElement("tile"); document.AppendChild(rootElement); XmlElement visualElement = document.CreateElement("visual"); visualElement.SetAttribute("version", "2"); rootElement.AppendChild(visualElement); // Support large tiles for Win 8.1 and higher: //<visual version="2"> // <binding template="TileSquare310x310BlockAndText01"> // <text id="1">Text Field 1 (large text)</text> // <text id="2">Text Field 2</text> // <text id="3">Text Field 3</text> // <text id="4">Text Field 4</text> // <text id="5">Text Field 5</text> // <text id="6">Text Field 6</text> // <text id="7">Text Field 7</text> // <text id="8">Text Field 8 (block text)</text> // <text id="9">Text Field 9</text> // </binding> //</visual> XmlElement largeBindingElement = document.CreateElement("binding"); largeBindingElement.SetAttribute("template", "TileSquare310x310BlockAndText01"); AddSubTextElements(largeBindingElement, new string[] { busName, tripHeadsign, stopName, "SCHED / ETA", string.Format("{0} / {1}", scheduledArrivalTime, predictedArrivalTime), string.Empty, string.Empty, blockText, statusText, }); visualElement.AppendChild(largeBindingElement); XmlElement wideBindingElement = document.CreateElement("binding"); wideBindingElement.SetAttribute("template", "TileWide310x150BlockAndText01"); wideBindingElement.SetAttribute("fallback", "TileWideBlockAndText01"); visualElement.AppendChild(wideBindingElement); AddSubTextElements(wideBindingElement, new string[] { busName, tripHeadsign, stopName, string.Format("{0} / {1}", scheduledArrivalTime, predictedArrivalTime), blockText, statusText, }); // Unfortunately, there is only one small tile template that supports block text. //<tile> // <visual> // <binding template="TileSquareBlock"> // <text id="1">Text Field 1</text> // <text id="2">Text Field 2</text> // </binding> // </visual> //</tile> XmlElement smallBindingElement = document.CreateElement("binding"); smallBindingElement.SetAttribute("template", "TileSquare150x150Block"); smallBindingElement.SetAttribute("fallback", "TileSquareBlock"); visualElement.AppendChild(smallBindingElement); XmlElement smallBlockTextElement = document.CreateElement("text"); smallBlockTextElement.SetAttribute("id", "1"); smallBlockTextElement.InnerText = blockText; smallBindingElement.AppendChild(smallBlockTextElement); XmlElement smallSubTextElement = document.CreateElement("text"); smallSubTextElement.SetAttribute("id", "2"); smallSubTextElement.InnerText = busName; smallBindingElement.AppendChild(smallSubTextElement); if ((scheduledTime - DateTime.Now).TotalMinutes < 1) { var notification = new TileNotification(document); notification.ExpirationTime = scheduledTime.AddMinutes(1); notification.Tag = (busName + tripHeadsign + stopName + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X"); this.tileUpdater.Update(notification); } else { var notification = new ScheduledTileNotification(document, scheduledTime); notification.ExpirationTime = scheduledTime.AddMinutes(1); notification.Tag = (busName + tripHeadsign + stopName + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X"); this.tileUpdater.AddToSchedule(notification); } }
public static WeatherData XmlAnalytical(string xmlString) { XmlDocument document = new XmlDocument( ); document.CreateElement("Employees"); // XmlRootAttribute Root = new XmlRootAttribute(); // Root.ElementName = "weatherDatas"; XmlSerializer sr = new XmlSerializer(typeof(WeatherData)); ///StringReader strReader = new StringReader(xmlString); //System.Xml.XmlReader r = new System.Xml(); //weatherData = (WeatherData)sr.Deserialize(r); //return weatherData; DataContractSerializer obj = new DataContractSerializer(typeof(WeatherData)); weatherData = (WeatherData)obj.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(xmlString))); return weatherData; }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e != null && e.Parameter != null) { CurrentCode = e.Parameter as Code; if (CurrentCode != null) { Report = new XmlDocument(); CodeElement = Report.CreateElement("Code"); CodeElement.SetAttribute("CPRStartTime", CurrentCode.CPRStartTime.ToString()); CodeElement.SetAttribute("CPREndTime", CurrentCode.CPREndTime.ToString()); DefibElement = Report.CreateElement("Defibrillation"); PatientInfoElement = Report.CreateElement("PatientInformation"); CodeElement.AppendChild(DefibElement); CodeElement.AppendChild(PatientInfoElement); Report.AppendChild(CodeElement); } } if (CurrentDefibrillation == null) { CurrentDefibrillation = new Defibrillation(); } if (CurrentPatientInfo == null) { CurrentPatientInfo = new PatientInformation(); } base.OnNavigatedTo(e); }
private async Task LoadLocalMetadataDownloaded() { if (localDownloadedXml == null) { var file = await _folder.CreateFileAsync("magazines_downloaded.metadata", CreationCollisionOption.OpenIfExists); Task task = null; try { localDownloadedXml = await XmlDocument.LoadFromFileAsync(file); } catch { localDownloadedXml = new XmlDocument(); var root = localDownloadedXml.CreateElement("root"); localDownloadedXml.AppendChild(root); task = localDownloadedXml.SaveToFileAsync(file).AsTask(); } if (task != null) await task; } _magazinesLocalUrlDownloaded.Clear(); var mags = localDownloadedXml.SelectNodes("/root/mag"); bool error = false; foreach (var mag in mags) { try { _magazinesLocalUrlDownloaded.Add(DownloadManager.GetLocalUrl(mag)); } catch { error = true; break; } } if (error) { var file = await _folder.CreateFileAsync("magazines_downloaded.metadata", CreationCollisionOption.ReplaceExisting); localDownloadedXml = new XmlDocument(); var root = localDownloadedXml.CreateElement("root"); localDownloadedXml.AppendChild(root); var task = localDownloadedXml.SaveToFileAsync(file).AsTask(); _magazinesLocalUrlDownloaded.Clear(); } foreach (var item in _magazinesLocalUrlDownloaded) { var items = _magazinesLocalUrl.Where(magazine => magazine.FullName.Equals(item.FullName)); if (items != null && items.Count() > 0) { var magazine = items.First(); var index = _magazinesLocalUrl.IndexOf(magazine); if (index == -1) continue; _magazinesLocalUrl[index] = item; } } }
// Write project to project xml file public async void Save() { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("TranscriberProject"); root.SetAttribute("Name", Name); XmlElement utterancesEl = doc.CreateElement("Utterances"); foreach (Utterance u in Utterances) { XmlElement utteranceEl = u.ToXmlElement(doc); utterancesEl.AppendChild(utteranceEl); } root.AppendChild(utterancesEl); doc.AppendChild(root); await doc.SaveToFileAsync(ProjectFile); foreach (Utterance u in Utterances) { u.Modified = false; } }
private async Task GetHtmlContent(DataPackage requestData, Empresa empresa, Item item) { var xml = new XmlDocument(); var body = xml.CreateElement("DIV"); xml.AppendChild(body); //Dados da empresa string Telefones = Utils.GetTelefoneNumeros(empresa.Telefones); string empresaShareText = empresa.ShareTexto.Replace("#TELEFONE#", Telefones).Replace("#URL#", empresa.Website); var empresaData = xml.CreateElement("P"); empresaData.InnerText = empresaShareText; body.AppendChild(empresaData); body.AppendChild(xml.CreateElement("HR")); //Dados do Item compartilhado var Image = xml.CreateElement("IMG"); Image.SetAttribute("SRC", new Uri(_baseUri, item.ImageUrl).ToString()); body.AppendChild(Image); var Itemtipo = xml.CreateElement("H2"); Itemtipo.InnerText = item.SubTitulo; var breakline = xml.CreateElement("BR"); Itemtipo.AppendChild(breakline); var bold = xml.CreateElement("b"); bold.InnerText = string.Format("R$ {0}", item.Valor); Itemtipo.AppendChild(bold); body.AppendChild(Itemtipo); var ImageDescription = xml.CreateElement("P"); ImageDescription.InnerText = item.Descricao; body.AppendChild(ImageDescription); var localImage = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(item.ImageUrl.Replace("/", "\\")); requestData.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(xml.GetXml())); requestData.ResourceMap[new Uri(_baseUri, item.ImageUrl).ToString()] = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(localImage); }
private async Task<StorageFile> DownloadPDFAssetsAsync(LibrelioLocalUrl magUrl, IList<string> list, IProgress<int> progress = null, CancellationToken cancelToken = default(CancellationToken)) { var folder = await StorageFolder.GetFolderFromPathAsync(magUrl.FolderPath.Substring(0, magUrl.FolderPath.Length-1)); var file = await folder.CreateFileAsync(magUrl.MetadataName, CreationCollisionOption.ReplaceExisting); var xml = new XmlDocument(); var root = xml.CreateElement("root"); var name = xml.CreateElement("name"); name.InnerText = magUrl.FullName; var date = xml.CreateElement("date"); date.InnerText = DateTime.Today.Month.ToString() + "/" + DateTime.Today.Day.ToString() + "/" + DateTime.Today.Year.ToString(); xml.AppendChild(root); root.AppendChild(name); root.AppendChild(date); await xml.SaveToFileAsync(file); cancelToken.ThrowIfCancellationRequested(); for (int i = 0; i < list.Count; i++) { var loader = new ResourceLoader(); StatusText = loader.GetString("downloading") + " " + (i + 2) + "/" + (list.Count + 1); var url = list[i]; cancelToken.ThrowIfCancellationRequested(); string absLink = url; var pos = absLink.IndexOf('?'); if (pos >= 0) absLink = url.Substring(0, pos); string fileName = absLink.Replace("http://localhost/", ""); string linkString = ""; linkString = folder.Path + "\\" + absLink.Replace("http://localhost/", ""); pos = magUrl.Url.LastIndexOf('/'); var assetUrl = magUrl.Url.Substring(0, pos + 1); absLink = absLink.Replace("http://localhost/", assetUrl); var sampleFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); await DownloadFileAsyncWithProgress(absLink, sampleFile, progress, cancelToken); var asset = xml.CreateElement("asset"); asset.InnerText = linkString; root.AppendChild(asset); await xml.SaveToFileAsync(file); } return file; }
/// <summary> /// Appends a wide tile with a big block of text. Used to display up-coming buses. /// </summary> public void AppendTileWithBlockTextAndLines(DateTimeOffset scheduledTime, string blockText, string subBlockText, string text1 = null, string text2 = null, string text3 = null, string text4 = null) { //<tile> // <visual> // <binding template="TileWideBlockAndText01"> // <text id="1">Text Field 1</text> // <text id="2">Text Field 2</text> // <text id="3">Text Field 3</text> // <text id="4">Text Field 4</text> // <text id="5">T5</text> // <text id="6">Text Field 6</text> // </binding> // </visual> //</tile> var document = new XmlDocument(); var rootElement = document.CreateElement("tile"); document.AppendChild(rootElement); XmlElement visualElement = document.CreateElement("visual"); rootElement.AppendChild(visualElement); XmlElement wideBindingElement = document.CreateElement("binding"); wideBindingElement.SetAttribute("template", "TileWideBlockAndText01"); visualElement.AppendChild(wideBindingElement); string[] wideTexts = new string[] { text1, text2, text3, text4, blockText, subBlockText, }; for (int i = 0; i < wideTexts.Length; i++) { string text = wideTexts[i]; if (!string.IsNullOrEmpty(text)) { XmlElement textElement = document.CreateElement("text"); textElement.SetAttribute("id", (i + 1).ToString()); textElement.InnerText = text; wideBindingElement.AppendChild(textElement); } } // Unfortunately, there is only one small tile template that supports block text. //<tile> // <visual> // <binding template="TileSquareBlock"> // <text id="1">Text Field 1</text> // <text id="2">Text Field 2</text> // </binding> // </visual> //</tile> XmlElement smallBindingElement = document.CreateElement("binding"); smallBindingElement.SetAttribute("template", "TileSquareBlock"); visualElement.AppendChild(smallBindingElement); XmlElement smallBlockTextElement = document.CreateElement("text"); smallBlockTextElement.SetAttribute("id", "1"); smallBlockTextElement.InnerText = blockText; smallBindingElement.AppendChild(smallBlockTextElement); XmlElement smallSubTextElement = document.CreateElement("text"); smallSubTextElement.SetAttribute("id", "2"); smallSubTextElement.InnerText = text1; smallBindingElement.AppendChild(smallSubTextElement); if ((scheduledTime - DateTime.Now).TotalMinutes < 1) { var notification = new TileNotification(document); notification.ExpirationTime = scheduledTime.AddMinutes(1); notification.Tag = (text1 + text2 + text3 + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X"); this.tileUpdater.Update(notification); } else { var notification = new ScheduledTileNotification(document, scheduledTime); notification.ExpirationTime = scheduledTime.AddMinutes(1); notification.Tag = (text1 + text2 + text3 + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X"); this.tileUpdater.AddToSchedule(notification); } }
private async void Button_Click(object sender, RoutedEventArgs e) { StorageFile localFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("usersettings.xml", CreationCollisionOption.ReplaceExisting); XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("Categories"); xmlDoc.AppendChild(root); foreach (Bill bill in selectedBills) { XmlElement xmlElement = xmlDoc.CreateElement("Bill"); xmlElement.SetAttribute("Type", bill.BillType.ToString()); xmlElement.SetAttribute("Title", bill.Title); xmlElement.SetAttribute("SubTitle", bill.SubTitle); xmlElement.SetAttribute("ImagePath", bill.ImagePath); xmlElement.SetAttribute("PortalUrl", bill.PortalUrl); XmlElement dueDate = xmlDoc.CreateElement("DueDate"); dueDate.InnerText = bill.DueDate.ToString(); XmlElement isPaid = xmlDoc.CreateElement("IsPaid"); isPaid.InnerText = bill.IsPaid.ToString(); xmlElement.AppendChild(dueDate); xmlElement.AppendChild(isPaid); root.AppendChild(xmlElement); } await xmlDoc.SaveToFileAsync(localFile); this.Frame.Navigate(typeof(HomePage)); }
/// <summary> /// Appends TileWideImageAndText01 to the document. /// </summary> public async Task AppendTileWithLargePictureAndTextAsync(string tileId, double latitude, double longitude, string text) { string wideTileImageFile = await CreateTileMapImageAsync(tileId, latitude, longitude, 310, 160, true); //<visual> // <binding template="TileWideImageAndText01"> // <image id="1" src="image1.png" alt="alt text"/> // <text id="1">Text Field 1</text> // </binding> //</visual> var document = new XmlDocument(); var rootElement = document.CreateElement("tile"); document.AppendChild(rootElement); XmlElement visualElement = document.CreateElement("visual"); rootElement.AppendChild(visualElement); XmlElement wideBindingElement = document.CreateElement("binding"); wideBindingElement.SetAttribute("template", "TileWideImageAndText01"); visualElement.AppendChild(wideBindingElement); XmlElement wideImageElement = document.CreateElement("image"); wideImageElement.SetAttribute("id", "1"); wideImageElement.SetAttribute("src", string.Format(@"ms-appdata:///local/Tiles/{0}", wideTileImageFile)); wideImageElement.SetAttribute("alt", text); wideBindingElement.AppendChild(wideImageElement); XmlElement wideTextElement = document.CreateElement("text"); wideTextElement.SetAttribute("id", "1"); wideTextElement.InnerText = text; wideBindingElement.AppendChild(wideTextElement); // Also add the small tile image: //<tile> // <visual> // <binding template="TileSquareImage"> // <image id="1" src="image1" alt="alt text"/> // </binding> // </visual> //</tile> string smallTileImageFile = await CreateTileMapImageAsync(tileId, latitude, longitude, 160, 160, false); XmlElement smallBindingElement = document.CreateElement("binding"); smallBindingElement.SetAttribute("template", "TileSquareImage"); visualElement.AppendChild(smallBindingElement); XmlElement smallImageElement = document.CreateElement("image"); smallImageElement.SetAttribute("id", "1"); smallImageElement.SetAttribute("src", string.Format(@"ms-appdata:///local/Tiles/{0}", smallTileImageFile)); smallImageElement.SetAttribute("alt", text); smallBindingElement.AppendChild(smallImageElement); TileNotification notification = new TileNotification(document); notification.Tag = tileId.GetHashCode().ToString("X"); this.tileUpdater.Update(notification); }
//private void Button_Holding(object sender, HoldingRoutedEventArgs e) //{ // Button btn = (Button) sender; // TextBlock tb = new TextBlock(); // tb.Text ="删除"; // Flyout flyout = new Flyout(); // flyout.Content = tb; // flyout.ShowAt(btn); //} async private void DeleteAppBarButton_Click(object sender, RoutedEventArgs e) { foreach (Citys city2 in Files.SelectedItems) { cityName.Remove(city2); } //获取记事本的文件夹对象NoteList StorageFolder storage1 = await ApplicationData.Current.LocalFolder.CreateFolderAsync("CityList",CreationCollisionOption.ReplaceExisting); foreach (Citys city3 in cityName) { //创建一个XML对象 XmlDocument _doc = new XmlDocument(); //使用记事本名字创建一个XML元素作为根节点 XmlElement _item = _doc.CreateElement(city3.city.ToString ()); //使用属性来作为信息的标识符,使用属性值来存储相关的信息 //_item.SetAttribute("city", t.Text ); _doc.AppendChild(_item); //创建一个应用文件 StorageFile file = await storage1.CreateFileAsync(city3.city.ToString() + ".xml", CreationCollisionOption.ReplaceExisting); //把XML的信息保存到文件中去 await _doc.SaveToFileAsync(file); } (Window.Current.Content as Frame).Navigate(typeof(CollectionCity)); }
private async Task LoadLocalMetadata() { if (localXml == null) { var file = await _folder.CreateFileAsync("magazines.metadata", CreationCollisionOption.OpenIfExists); Task task = null; try { localXml = await XmlDocument.LoadFromFileAsync(file); } catch { localXml = new XmlDocument(); var root = localXml.CreateElement("root"); localXml.AppendChild(root); task = localXml.SaveToFileAsync(file).AsTask(); } if (task != null) await task; } _magazinesLocalUrl.Clear(); var mags = localXml.SelectNodes("/root/mag"); bool error = false; foreach (var mag in mags) { try { _magazinesLocalUrl.Add(DownloadManager.GetLocalUrl(mag)); } catch { error = true; break; } } if (error) { var file = await _folder.CreateFileAsync("magazines.metadata", CreationCollisionOption.ReplaceExisting); localXml = new XmlDocument(); var root = localXml.CreateElement("root"); localXml.AppendChild(root); var task = localXml.SaveToFileAsync(file).AsTask(); _magazinesLocalUrl.Clear(); } if (_magazinesLocalUrl.Count == 0) { var fileHandle = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"CustomizationAssets\Magazines.plist"); var stream = await fileHandle.OpenReadAsync(); var dataReader = new DataReader(stream.GetInputStreamAt(0)); var size = await dataReader.LoadAsync((uint)stream.Size); var str = dataReader.ReadString(size); dataReader.DetachStream(); stream.Dispose(); stream = null; if (str.Contains("<!DOCTYPE")) { var pos = str.IndexOf("<!DOCTYPE"); var end = str.IndexOf(">", pos + 7); if (end >= 0) str = str.Remove(pos, end - pos + 1); } XmlDocument xml = new XmlDocument(); xml.LoadXml(str); await ReadPList(xml); var folder = ApplicationData.Current.LocalFolder; try { // Set query options to create groups of files within result var queryOptions = new QueryOptions(Windows.Storage.Search.CommonFolderQuery.DefaultQuery); queryOptions.UserSearchFilter = "System.FileName:=Covers"; // Create query and retrieve result StorageFolderQueryResult queryResult = folder.CreateFolderQueryWithOptions(queryOptions); IReadOnlyList<StorageFolder> folders = await queryResult.GetFoldersAsync(); if (folders.Count != 1) { await Utils.Utils.LoadDefaultData(); } } catch { } } }