本文整理匯總了C#中Windows.Data.Xml.Dom.XmlDocument.AppendChild方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.AppendChild方法的具體用法?C# XmlDocument.AppendChild怎麽用?C# XmlDocument.AppendChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.Data.Xml.Dom.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.AppendChild方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SetTileImageButtonClick
/// <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);
}
示例2: CreateTileTemplate
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;
}
示例3: doAuditing
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));
}
}
}
}
示例4: getList
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;
}
示例5: CheckGoodsFile
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);
}
}
示例6: SendToast
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);
}
示例7: NotificationImageButton_Click
/// <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);
}
示例8: InitDataBase
/// <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();
}
}
示例9: AppendTileWithLargePictureAndTextAsync
/// <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);
}
示例10: AppendTileWithBlockTextAndLines
/// <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);
}
}
示例11: Save
// 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;
}
}
示例12: GetHtmlContent
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);
}
示例13: AppendTileWithBlockTextAndLines
/// <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);
//.........這裏部分代碼省略.........
示例14: LoadLocalMetadata
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 { }
}
}
示例15: DownloadPDFAssetsAsync
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;
}