当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.CopyToAsync方法代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:rssktt,项目名称:FairAir,代码行数:101,代码来源:airDB.cs

示例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));
 }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:10,代码来源:FullEditor.cs


注:本文中的System.IO.StreamReader.CopyToAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。