本文整理汇总了C#中System.IO.StreamReader.CopyToAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.CopyToAsync方法的具体用法?C# StreamReader.CopyToAsync怎么用?C# StreamReader.CopyToAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.CopyToAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getAQI
public static async Task<XDocument> getAQI()
{
XDocument xd = null;
string url = "http://data.cabq.gov/airquality/aqindex/daily/";
string day = Convert.ToString(System.DateTime.Now.Day);
string year = Convert.ToString(System.DateTime.Now.Year);
string month = Convert.ToString(System.DateTime.Now.Month);
string hour = Convert.ToString(System.DateTime.Now.Hour);
year = year.Remove(0, 2);
string urlEnd = year + month + day;
//tx1.Text = hour;
string result = null;
bool except = false;
string furl = null;
string date = null;
//gets data with furl as the target url
for (int i = System.DateTime.Now.Hour; i >= 0; i--)
{
if (i < 10)
{
furl = url + urlEnd + "0" + Convert.ToString(i) + ".NM2";
date = urlEnd;
}
else
{
furl = url + urlEnd + Convert.ToString(i) + ".NM2";
date = urlEnd;
}
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(furl);
req.Method = "GET";
WebResponse res = await req.GetResponseAsync();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
result = sr.ReadToEnd();
sr.Dispose();
res.Dispose();
}
catch (Exception ex)
{
// handle error
except = true;
}
if (except == false)
break;
}
if (except == true)// nothing was recieved, return old file or create one if it doesnt exist
{
StorageFolder sfProject = Package.Current.InstalledLocation;
StorageFolder sfLocal = ApplicationData.Current.LocalFolder;
Stream sr, sw;
bool bFileExists;
try
{
sw = await sfLocal.OpenStreamForWriteAsync(filename, CreationCollisionOption.FailIfExists);
sw.Dispose();
bFileExists = false;
}
catch
{
bFileExists = true;
}
if (bFileExists == false)
{
sr = await sfProject.OpenStreamForReadAsync(filename);
sw = await sfLocal.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting);
await sr.CopyToAsync(sw);
sr.Dispose();
sw.Dispose();
}
sr = await sfLocal.OpenStreamForReadAsync(filename);
xd = XDocument.Load(sr);
sr.Dispose();
return xd;
}
string[] param = result.Split('\n');
int ind = 0;
int ine = 0;
List<string[]> data = new List<string[]>();
while (ind != -1)
{
ind = Array.IndexOf(param, "BEGIN_GROUP");
ine = Array.IndexOf(param, "END_GROUP");
data.Add(param.Skip(ind).Take(ine - ind + 1).ToArray());
param = param.Skip(ine + 1).Take(param.Length).ToArray();
}
data.RemoveAt(data.Count - 1);
string[] final = new string[19];
int offset = 0;
for (int i = 0; i < data.Count; i++)// goes through all types, ozone, co2,ect..
{
string[] tempArray = data.ElementAt(i);
//.........这里部分代码省略.........
示例2: OpenFile
public async Task OpenFile(Stream stream)
{
var rope = new Rope<char>();
using (var reader = new StreamReader(stream))
using (var writer = new Editor.RopeWriter(rope))
{
await reader.CopyToAsync(writer);
}
Document.Replace(0, Document.TextLength, new RopeTextSource(rope));
}