本文整理汇总了C#中IStorageFile.OpenStreamForReadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IStorageFile.OpenStreamForReadAsync方法的具体用法?C# IStorageFile.OpenStreamForReadAsync怎么用?C# IStorageFile.OpenStreamForReadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorageFile
的用法示例。
在下文中一共展示了IStorageFile.OpenStreamForReadAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAsync
public async Task<Issue> ParseAsync(IStorageFile issueFolioFile, string pathPrefix)
{
Issue issue = new Issue(pathPrefix);
Stream stream = await issueFolioFile.OpenStreamForReadAsync();
XmlReader reader = XmlReader.Create(stream);
if (reader != null)
{
// setting up the cover images assumed to be in the root folio folder
issue.LandscapeImageUrl = "/cover_h.png";
issue.PortraitImageUrl = "/cover_v.png";
while (reader.Read())
{
if (reader.NodeType != XmlNodeType.EndElement)
{
switch (reader.Name)
{
case "folio":
//issue.RelativePath = Repository.GetIssueRelativePath(issue.Id);
issue.Date = reader.GetAttribute("date");
break;
case "magazineTitle":
reader.Read();
issue.Id = reader.Value.ToLower().Replace(" ", "") + "_";
issue.DisplayName = reader.Value;
break;
case "folioNumber":
reader.Read();
issue.Id += reader.Value.ToLower().Replace(" ", "");
break;
default:
break;
}
}
}
}
return issue;
}
示例2: Load
public async Task<BatNodeLog> Load(IStorageFile file)
{
BatNodeLog log = new BatNodeLog();
log.LogStart = DateTime.UtcNow;
using (Stream logStream = await file.OpenStreamForReadAsync())
{
using (BinaryReader reader = new BinaryReader(logStream))
{
ReadData(log, reader);
}
}
log.CallCount = log.Calls.Count;
return log;
}
示例3: GetImageKey
/// <summary>
///
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
private async Task<string> GetImageKey(IStorageFile file)
{
var key = default(string);
using (var fileStream = await file.OpenStreamForReadAsync())
{
var bytes = Core2D.Project.ReadBinary(fileStream);
key = _context.Editor.Project.AddImageFromFile(file.Path, bytes);
}
return key;
}
示例4: HandleFilePickerLaunch
internal async void HandleFilePickerLaunch(IStorageFile pickedFile)
{
if (!IsNoSyncInProgress) return;
CurrentAction = ActionType.ImportStats;
StatImportSongsFound = 0;
StatImportSongsSkipped = 0;
using (Stream stream = await pickedFile.OpenStreamForReadAsync())
{
using (StreamReader reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] parts = line.Split(new char[] { '|' });
if (parts.Count() == 6)
{
string TrackName = parts[0];
string AlbumName = parts[1];
string ArtistName = parts[2];
string Rating = parts[3];
string PlayCount = parts[4];
string LastPlayed = parts[5];
SongViewModel song = LibraryViewModel.Current.LookupSongByName(TrackName, ArtistName);
if (song != null)
{
song.Rating = uint.Parse(Rating);
// TODO: let user toggle this
song.PlayCount = uint.Parse(PlayCount);
DateTime realLastPlayed = new DateTime(long.Parse(LastPlayed));
if (song.LastPlayed < realLastPlayed)
{
song.LastPlayed = realLastPlayed;
}
StatImportSongsFound++;
}
else
{
StatImportSongsSkipped++;
}
}
}
}
}
CurrentAction = ActionType.None;
}
示例5: OpenStreamForReadAsync
public static async Task<Stream> OpenStreamForReadAsync(IStorageFile windowsRuntimeFile)
{
try
{
return await windowsRuntimeFile.OpenStreamForReadAsync();
}
catch { return null; }
}
示例6: ReadLinesAsync
/// <summary>
/// Reads the contents of the specified file using the specified character encoding and returns lines of text.
/// </summary>
/// <param name="file">The file to read.</param>
/// <param name="encoding">The character encoding of the file.</param>
/// <returns>When this method completes successfully, it returns the contents of the file as a list (type IVector) of lines of text.
/// Each line of text in the list is represented by a String object.</returns>
public static Task<IList<string>> ReadLinesAsync(IStorageFile file, UnicodeEncoding encoding)
{
#if __ANDROID__ || __IOS__ || __TVOS__ || WIN32 || TIZEN
return PathIO.ReadLinesAsync(file.Path, encoding);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return Windows.Storage.FileIO.ReadLinesAsync((Windows.Storage.StorageFile)((StorageFile)file), (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask();
#elif WINDOWS_PHONE
return Task.Run<IList<string>>(async () =>
{
String line;
List<String> lines = new List<String>();
Stream s = await file.OpenStreamForReadAsync();
using (StreamReader sr = new StreamReader(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
while ((line = sr.ReadLine()) != null)
lines.Add(line);
return lines.ToArray();
});
#else
throw new PlatformNotSupportedException();
#endif
}
示例7: getPhotoReadStreamAsync
private async Task<Stream> getPhotoReadStreamAsync(IStorageFile file)
{
return await file.OpenStreamForReadAsync();
}
示例8: ImportPathfinderSpellsCSV
private async void ImportPathfinderSpellsCSV(IStorageFile file)
{
using (var reader = new StreamReader(await file.OpenStreamForReadAsync()))
{
var csvHelper = new CsvHelper.CsvReader(reader);
var spells = csvHelper.GetRecords<PathfinderSpellsCSV>();
foreach(var spell in spells)
{
//spell.
}
}
}
示例9: LoadTransmissionFromFileAsync
private static async Task<StorageTransmission> LoadTransmissionFromFileAsync(IStorageFile file)
{
try
{
using (Stream stream = await file.OpenStreamForReadAsync().ConfigureAwait(false))
{
StorageTransmission storageTransmissionItem = await StorageTransmission.CreateFromStreamAsync(stream, file.Path).ConfigureAwait(false);
return storageTransmissionItem;
}
}
catch (Exception e)
{
string message = string.Format("Failed to load transmission from file. File path: {0}, FileName: {1}, Exception: {2}", file.Path, file.Name, e);
CoreEventSource.Log.LogVerbose(message);
throw;
}
}