本文整理汇总了C#中Windows.Storage.StorageFile.OpenStreamForReadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.OpenStreamForReadAsync方法的具体用法?C# StorageFile.OpenStreamForReadAsync怎么用?C# StorageFile.OpenStreamForReadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.OpenStreamForReadAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFromFile
public async Task<FavoriteRoute> LoadFromFile(StorageFile file)
{
var serializer = new XmlSerializer(typeof(gpxType));
Stream stream = await file.OpenStreamForReadAsync();
gpxType objectFromXml = (gpxType)serializer.Deserialize(stream);
stream.Dispose();
Name = (objectFromXml.metadata.name == null) ? "" : objectFromXml.metadata.name;
Description = (objectFromXml.metadata.desc == null) ? "" : objectFromXml.metadata.desc;
Timestamp = (objectFromXml.metadata.time == null) ? DateTime.Now : objectFromXml.metadata.time;
Symbol = (objectFromXml.metadata.extensions.symbol == null) ? "" : objectFromXml.metadata.extensions.symbol;
/*Address = (objectFromXml.metadata.extensions.address == null) ? "" : objectFromXml.metadata.extensions.address;*/
StartPoint = new BasicLocation()
{
Location = new Geopoint(new BasicGeoposition()
{
Latitude = (double)objectFromXml.wpt[0].lat,
Longitude = (double)objectFromXml.wpt[0].lon,
Altitude = (double)objectFromXml.wpt[0].ele
})
};
Track = objectFromXml.trk[0].trkseg[0].trkpt.Select(pos => new BasicGeoposition()
{
Latitude = (double)pos.lat,
Longitude = (double)pos.lon,
Altitude = (double)pos.ele
}).ToList();
return this;
}
示例2: UnZipFile
async public static Task UnZipFile(StorageFile file, StorageFolder extractFolder = null)
{
using (var zipStream = await file.OpenStreamForReadAsync())
{
using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
{
await zipStream.CopyToAsync(zipMemoryStream);
using (var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.Name != "")
{
using (Stream fileData = entry.Open())
{
StorageFile outputFile = await extractFolder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);
using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
{
await fileData.CopyToAsync(outputFileStream);
await outputFileStream.FlushAsync();
}
}
}
}
}
}
}
}
示例3: CreateFlightRawDataExtractor
public static IFlightRawDataExtractor CreateFlightRawDataExtractor(StorageFile file, FlightParameters parameters)
{
if (file == null)
return null;
var readStreamTask = file.OpenStreamForReadAsync();
readStreamTask.Wait();
MemoryStream stream = new MemoryStream(102400);
byte[] bytes = new byte[readStreamTask.Result.Length];
readStreamTask.Result.Read(bytes, 0, Convert.ToInt32(readStreamTask.Result.Length));
stream.Write(bytes, 0, Convert.ToInt32(readStreamTask.Result.Length));
//Task temp1 = readStreamTask.AsTask();
//temp1.Wait();
//var temp2 = readStreamTask.GetResults();
BinaryReader reader = new BinaryReader(stream); //temp2.AsStreamForRead(1024000)); //readStreamTask.Result);
var handler = new FlightDataReadingHandler(reader);
//if (parameters != null)
//{
// handler.Definition = CreateDefinition(handler.Definition, parameters);
//}
return handler;
}
示例4: UnzipFromStorage
public static async Task UnzipFromStorage(StorageFile pSource, StorageFolder pDestinationFolder, IEnumerable<string> pIgnore)
{
using (var stream = await pSource.OpenStreamForReadAsync())
{
await UnzipFromStream(stream, pDestinationFolder,pIgnore.ToList());
}
}
示例5: Deserialise
/// <summary>
/// Deserialises the XML file contents and loads the instance of the Im-Memory Context
/// It is called from the <see cref="Infrastructure.Repositories.PersistenceRepository"/>.
/// </summary>
/// <param name="UnitOfWork">The instance of the Music Collection being loaded</param>
/// <param name="datafile">The instance of the XML source file.</param>
/// <returns>A Task so that the call can be awaited.</returns>
/// <remarks>
/// The UnitOfWork which represents the Music Collection is passed by reference so updats
/// reflect in the supplied instance. This instance is injected by the IoC container
/// therefore no new instances of it should be created.
/// </remarks>
public static async Task Deserialise(IUnitOfWork UnitOfWork, StorageFile datafile)
{
// Deserialise the data from the file.
using (StreamReader reader = new StreamReader(await datafile.OpenStreamForReadAsync()))
{
// Check for an empty stream, exceptions will occur if it is.
if (!reader.EndOfStream)
{
// Set up the types for deserialising
Type[] extraTypes = new Type[11];
extraTypes[0] = typeof(List<Album>);
extraTypes[1] = typeof(List<Track>);
extraTypes[2] = typeof(List<Artist>);
extraTypes[3] = typeof(List<Genre>);
extraTypes[4] = typeof(List<PlayList>);
extraTypes[5] = typeof(Track);
extraTypes[6] = typeof(Artist);
extraTypes[7] = typeof(Genre);
extraTypes[8] = typeof(PlayList);
extraTypes[9] = typeof(Wiki);
extraTypes[10] = typeof(Image);
// Create the XMLSerialiser instance
XmlSerializer serializer = new XmlSerializer(typeof(List<Album>), extraTypes);
// Deserialise the Albums collection, that's the only collection persisted as
// it contains the complete object graph.
UnitOfWork.Albums = (List<Album>)serializer.Deserialize(reader);
}
}
}
示例6: InitLoadSet
public static async void InitLoadSet() {
string fileContent;
Uri uri = new Uri("ms-appx:///Data/Sets.txt");
file = await StorageFile.GetFileFromApplicationUriAsync(uri);
StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync());
fileContent = await sRead.ReadLineAsync();
KeyValuePair<int, object> res = Type(fileContent);
ListWords currentListWords = new ListWords();
while (res.Key != -1)
{
if (res.Key == 0)
{
currentListWords.Name = (string)res.Value;
SetsNames.Add((string)res.Value);
}
if (res.Key == 1)
{
currentListWords.Add((Word)res.Value);
}
if (res.Key == 2)
{
SetsWords.Add(currentListWords.Name, currentListWords);
currentListWords = new ListWords();
}
fileContent = sRead.ReadLineAsync().Result;
res = Type(fileContent);
}
MainPage.CurrentListWords = SetsWords["None"];
sRead.Dispose();
}
示例7: UploadImageToBlobStorage
public static async Task<string> UploadImageToBlobStorage(StorageFile image, string targetUrl)
{
//Upload image with HttpClient to the blob service using the generated item.SAS
// TODO - add BusyDisposer
using (new BusyDisposer())
using (var client = new HttpClient())
{
//Get a stream of the media just captured
using (var fileStream = await image.OpenStreamForReadAsync())
{
var content = new StreamContent(fileStream);
content.Headers.Add("Content-Type", image.ContentType);
content.Headers.Add("x-ms-blob-type", "BlockBlob");
using (var uploadResponse = await client.PutAsync(new Uri(targetUrl), content))
{
if (uploadResponse.StatusCode != HttpStatusCode.Created)
{
throw new Exception(string.Format("Upload Failed {0}", uploadResponse.ToString()));
}
// remove the SAS querystring from the insert result
return targetUrl.Substring(0, targetUrl.IndexOf('?'));
}
}
}
}
示例8: Inflate
private static async Task Inflate(StorageFile zipFile, StorageFolder destFolder)
{
if (zipFile == null)
{
throw new Exception("StorageFile (zipFile) passed to Inflate is null");
}
else if (destFolder == null)
{
throw new Exception("StorageFolder (destFolder) passed to Inflate is null");
}
Stream zipStream = await zipFile.OpenStreamForReadAsync();
using (ZipArchive zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read))
{
//Debug.WriteLine("Count = " + zipArchive.Entries.Count);
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
//Debug.WriteLine("Extracting {0} to {1}", entry.FullName, destFolder.Path);
try
{
await InflateEntryAsync(entry, destFolder);
}
catch (Exception ex)
{
Debug.WriteLine("Exception: " + ex.Message);
}
}
}
}
示例9: CopyToMemoryStream
private async static Task<MemoryStream> CopyToMemoryStream(StorageFile file)
{
var memoryStream = new MemoryStream();
using (var stream = await file.OpenStreamForReadAsync())
{
stream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
}
return memoryStream;
}
示例10: CreatePageWithImage
public static async Task<String> CreatePageWithImage(string token, string apiRoute, string content, StorageFile file)
{
// This is the file that was saved by the user as a gif (see previous blog post)
Stream fileStream = await file.OpenStreamForReadAsync();
var client = new HttpClient();
// Note: API only supports JSON return type.
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// I'm passsing in the token here because I get it when the user logs in but you can easily get it using the LiveIdAuth class:
// await LiveIdAuth.GetAuthToken()
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
string imageName = file.DisplayName;
string date = DateTime.Now.ToString();
string simpleHtml = "<html>" +
"<head>" +
"<title>" + date + ": " + imageName + "</title>" +
"<meta name=\"created\" content=\"" + date + "\" />" +
"</head>" +
"<body>" +
"<p>" + content + "<p>" +
"<img src=\"name:" + imageName +
"\" alt=\"" + imageName + "\" width=\"700\" height=\"700\" />" +
"</body>" +
"</html>";
HttpResponseMessage response;
// Create the image part - make sure it is disposed after we've sent the message in order to close the stream.
using (var imageContent = new StreamContent(fileStream))
{
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/gif");
// Post request to create a page in the Section "Jots" https://www.onenote.com/api/v1.0/pages?sectionName=Jots
var createMessage = new HttpRequestMessage(HttpMethod.Post, apiRoute + "pages?sectionName=" + WebUtility.UrlEncode("Jots"))
{
Content = new MultipartFormDataContent
{
{new StringContent(simpleHtml, Encoding.UTF8, "text/html"), "Presentation"},
{imageContent, imageName}
}
};
// Must send the request within the using block, or the image stream will have been disposed.
response = await client.SendAsync(createMessage);
imageContent.Dispose();
}
return response.StatusCode.ToString();
}
示例11: ReadFile
/// <summary>
/// Implements reading ini data from a file.
/// </summary>
/// <param name="file">
/// Path to the file
/// </param>
/// <param name="fileEncoding">
/// File's encoding.
/// </param>
public async Task<IniData> ReadFile(StorageFile file, Encoding fileEncoding) {
try {
var stream = await file.OpenStreamForReadAsync();
using (StreamReader sr = new StreamReader(stream, fileEncoding)) {
return ReadData(sr);
}
} catch (IOException ex) {
throw new ParsingException(String.Format("Could not parse file {0}", file), ex);
}
}
示例12: CreateFlightRawDataExtractor
public static IFlightRawDataExtractor CreateFlightRawDataExtractor(StorageFile file)
{
if (file == null)
return null;
var readStreamTask = file.OpenStreamForReadAsync();
readStreamTask.Wait();
BinaryReader reader = new BinaryReader(readStreamTask.Result);
return new FlightDataReadingHandler(reader);
}
示例13: GetStreamBasedOnDirection
protected static async Task<Stream> GetStreamBasedOnDirection(StorageFile file, TransferDirection direction)
{
switch (direction)
{
case TransferDirection.Up:
return await file.OpenStreamForReadAsync();
case TransferDirection.Down:
return await file.OpenStreamForWriteAsync();
}
return null;
}
示例14: LoadAsync
public async Task<LibraryPropertyFile> LoadAsync(StorageFile libraryFile)
{
if (libraryFile == null)
{
return null;
}
Stream libraryFileStream = await libraryFile.OpenStreamForReadAsync();
XmlSerializer libraryXmlSerializer = new XmlSerializer(typeof(LibraryPropertyFile));
LibraryPropertyFile libraryPropertyFile = libraryXmlSerializer.Deserialize(libraryFileStream) as LibraryPropertyFile;
libraryFileStream.Dispose();
return libraryPropertyFile;
}
示例15: LoadCBRComic
private async Task LoadCBRComic(StorageFile storageFile)
{
try
{
using (var zipStream = await storageFile.OpenStreamForReadAsync())
using (var memoryStream = new MemoryStream((int)zipStream.Length))
{
await zipStream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
var rarArchive = RarArchive.Open(memoryStream);
if (rarArchive == null) return;
var comic = new DisplayComic
{
File = storageFile,
FullPath = storageFile.Name,
Name = storageFile.DisplayName,
Pages = rarArchive.Entries.Count
};
foreach(var entry in rarArchive.Entries)
{
if (IsValidEntry(entry)) continue;
using (var entryStream = new MemoryStream((int)entry.Size))
{
entry.WriteTo(entryStream);
entryStream.Position = 0;
using (var binaryReader = new BinaryReader(entryStream))
{
var bytes = binaryReader.ReadBytes((int)entryStream.Length);
comic.CoverageImageBytes = bytes;
break;
}
}
}
comics.Add(comic);
}
}
catch (Exception ex)
{
// Do nothing
}
}