private static InfoExport GetCoronaInfo() { string infoJSON = ""; WebRequest request = WebRequest.Create(feedUrl); WebResponse response = request.GetResponse(); Debug.WriteLine(((HttpWebResponse)response).StatusDescription); using (Stream dataStream = response.GetResponseStream()) { // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); infoJSON = responseFromServer; // Display the content. Debug.WriteLine(responseFromServer); } response.Close(); ReceivedInfo infObj = JsonConvert.DeserializeObject <ReceivedInfo>(infoJSON); InfoExport export = new InfoExport { Countries = int.Parse(infObj.Results[0].Total_affected_countries), New_cases_today = int.Parse(infObj.Results[0].Total_new_cases_today), New_deaths_today = int.Parse(infObj.Results[0].Total_new_deaths_today), Total_cases = int.Parse(infObj.Results[0].Total_cases), Total_deaths = int.Parse(infObj.Results[0].Total_deaths) }; return(export); }
public async void Run(IBackgroundTaskInstance taskInstance) { // Get a deferral, to prevent the task from closing prematurely // while asynchronous code is still running. BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); // Download the feed. InfoExport info = GetCoronaInfo(); //var feed = await GetCoronaData(); // Update the live tile with the feed items. await UpdateAsync(info); CoronaSpeakAsync(); // Inform the system that the task is finished. deferral.Complete(); }
//多条打码机的数据可以写到一个文件上发送过去,不过每次发送的明细不能超过一万条 private void export(string synseq, string groupno, string linetype)//lineno打码机编号 { this.btn_export.Enabled = false; panel2.Visible = true; label2.Visible = true; progressBar1.Visible = true; label2.Text = "数据查询中,准备进行数据导出..."; label2.Refresh(); int taskseq = 0, seq = 1; String tasknum = "", cuscode = "", cusname = "", itemno = "", itemname = "", quantity = "", regioncode = "", orderdate = "", cuscodetmp = ""; List <InfoExport> list = new List <InfoExport>(); list = ExportClass.Export(Convert.ToDecimal(synseq)); //取批次号 //String batchcodesql = "select SEQ_ONEHAOGONGCHENG.Nextval from dual"; int len = list.Count; String onesynseq = "0";//一号工程批次号 //DataTable table = Db.Query(sql); //int len = table.Rows.Count; //String[] infostr = new String[len]; if (len > 0) { InitSocket(); //DataRow row = new DataRow(); //创建到处目录 String folder = "HighSpeedExportData"; if (!Directory.Exists("D:\\" + folder)) { Directory.CreateDirectory("D:\\" + folder); } int count = 0, fileSeq = 1, rowCcount = 0, bz = 0, succCount = 0; String fileNameStr = ""; String info = "", tmpInfo = "", tempCode = "", unSuccFile = ""; for (int i = 0; i < len; i++) { progressBar1.Value = ((i + 1) * 100 / len); progressBar1.Refresh(); InfoExport infos = new InfoExport(); infos = list[i]; tasknum = infos.SortNum.ToString(); cuscode = infos.CustomerCode.ToString(); cusname = infos.CustomerName.ToString(); itemno = infos.CigaretteCode.ToString(); itemname = infos.CigaretteName.ToString(); quantity = infos.PokeNum.ToString(); regioncode = infos.RegionCode.ToString(); orderdate = infos.Orderdate.ToString(); //lineno = row["SORTNAME"].ToString(); taskseq++; rowCcount = rowCcount + 1; label2.Text = "正在导出第" + fileSeq + "个文件..."; label2.Refresh(); //取下条记录比较车组与零售户 if (i + 1 < len) { cuscodetmp = list[i + 1].CustomerCode.ToString(); tempCode = list[i + 1].RegionCode.ToString(); } else { cuscodetmp = ""; tempCode = ""; } //infostr[i] = tasknum + taskseq + "," + tasknum + "," + cuscode + "," + cusname + "," + itemno + "," + itemname + "," + quantity + ",2," + seq + "," + regioncode + "," + regioncode + "," + orderdate + "," + orderdate + ",S1001,1"; tmpInfo = tmpInfo + tasknum + "," + tasknum + "," + cuscode + "," + cusname + "," + itemno + "," + itemname + "," + quantity + "," + onesynseq + "," + seq + "," + regioncode + "," + regioncode + "," + orderdate + "," + orderdate + ",1;\r\n"; if (cuscode != cuscodetmp) { taskseq = 0; seq++; } //当下个车组与当前不同时 if (!tempCode.Equals(regioncode)) { //判断累计记录数是否大于10000,大于则将之前的记录数导出,否则将记录数合并 if (rowCcount + count > 1000000000) { label2.Text = "正在压缩第" + fileSeq + "个文件..."; label2.Refresh(); //将之前的记录信息导出 DateTime dt = DateTime.Now; String time = string.Format("{0:yyyyMMddHHmmssfff}", dt); String filename = "RetailerOrder-" + time + "-" + synseq + "-" + fileSeq; fileNameStr = fileNameStr + "," + filename + ".zip"; StreamWriter sw = new StreamWriter("D:\\HighSpeedExportData\\" + filename + ".Order", false, Encoding.UTF8); sw.WriteLine(info.Substring(0, info.Length - 1)); sw.Close();//写入 //CompressFile("D:\\" + filename + ".Order"); GetFileToZip("D:\\HighSpeedExportData\\" + filename + ".Order", "D:\\HighSpeedExportData\\" + filename + ".zip", filename + ".Order"); //发送数据 label2.Text = "正在发送第" + fileSeq + "个文件"; label2.Refresh(); bz = sendFile("D:\\HighSpeedExportData\\" + filename + ".zip"); //记录发送成功数量和失败文件信息 if (bz == 0) { succCount = succCount + 1; label2.Text = "第" + fileSeq + "个文件发送完毕!"; } else { unSuccFile = unSuccFile + "," + filename + ".zip"; label2.Text = "第" + fileSeq + "个文件发送失败!"; } label2.Refresh(); //记录新车组的信息 fileSeq = fileSeq + 1; count = rowCcount; info = tmpInfo; } else { count = rowCcount + count; info = info + tmpInfo; } //判断循环是否完成(是否为最后一条记录),如果是最后一条,则将剩余记录导出 if ("".Equals(tempCode)) { //fileSeq = fileSeq + 1; label2.Text = "正在压缩第" + fileSeq + "个文件"; label2.Refresh(); DateTime dt = DateTime.Now; String time = string.Format("{0:yyyyMMddHHmmssfff}", dt); String filename = "RetailerOrder-" + time + "-" + synseq + "-" + fileSeq; fileNameStr = fileNameStr + "," + filename + ".zip"; StreamWriter sw = new StreamWriter("D:\\HighSpeedExportData\\" + filename + ".Order", false, Encoding.UTF8); sw.WriteLine(info.Substring(0, info.Length - 1)); sw.Close();//写入 //CompressFile("D:\\" + filename + ".Order"); GetFileToZip("D:\\HighSpeedExportData\\" + filename + ".Order", "D:\\HighSpeedExportData\\" + filename + ".zip", filename + ".Order"); //发送数据 //sendFile("D:\\HighSpeedExportData\\" + filename + ".zip"); label2.Text = "正在发送第" + fileSeq + "个文件"; label2.Refresh(); bz = sendFile("D:\\HighSpeedExportData\\" + filename + ".zip"); //记录发送成功数量和失败文件信息 if (bz == 0) { succCount = succCount + 1; label2.Text = "第" + fileSeq + "个文件发送完毕!"; } else { unSuccFile = unSuccFile + "," + filename + ".zip"; label2.Text = "第" + fileSeq + "个文件发送失败!"; } label2.Refresh(); } tmpInfo = ""; rowCcount = 0; } } //在弹窗前关闭控件 panel2.Visible = false; label2.Visible = false; progressBar1.Visible = false; String msg = "成功导出" + fileSeq + "个文件,成功发送" + succCount + "个文件!"; //导出的文件的所有文件名 if (!"".Equals(fileNameStr)) { fileNameStr = fileNameStr.Substring(1); } //发送失败的所有文件名 if (!"".Equals(unSuccFile)) { unSuccFile = unSuccFile.Substring(1); msg = msg + "其中发送失败文件为(" + unSuccFile + ")!"; } else { msg = msg + "文件名为(" + fileNameStr + ")!"; } MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); socketClient.Disconnect(false); socketClient.Close(); } this.btn_export.Enabled = true; }
private static async Task UpdateAsync(InfoExport info) { string number_of_gc = info.Total_cases.ToString(); string number_of_gd = info.Total_deaths.ToString(); string number_of_tc = info.New_cases_today.ToString(); string number_of_td = info.Total_deaths.ToString(); string global_c = "Global infections: " + number_of_gc; string global_d = "Global deaths: " + number_of_gd; string todays_c = "Today's infections: " + number_of_tc; string todays_d = "Today's deaths: " + number_of_td; text2Speech = global_c + global_d + todays_c + todays_d; // Construct the tile content TileContent content = new TileContent() { Visual = new TileVisual() { TileMedium = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new AdaptiveText() { Text = global_c }, new AdaptiveText() { Text = global_d, HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = todays_c, HintStyle = AdaptiveTextStyle.CaptionSubtle } } } }, TileWide = new TileBinding() { Content = new TileBindingContentAdaptive() { Children = { new AdaptiveText() { Text = global_c, HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = global_d, HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = todays_c, HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = todays_d, HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } } }; var notification = new TileNotification(content.GetXml()); // And send the notification TileUpdateManager.CreateTileUpdaterForApplication().Update(notification); //Task returnedTask = GetTaskAsync(); }