本文整理汇总了C#中IRandomAccessStream.AsStream方法的典型用法代码示例。如果您正苦于以下问题:C# IRandomAccessStream.AsStream方法的具体用法?C# IRandomAccessStream.AsStream怎么用?C# IRandomAccessStream.AsStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRandomAccessStream
的用法示例。
在下文中一共展示了IRandomAccessStream.AsStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadImgur
public static async Task<ImgurEntity> UploadImgur(IRandomAccessStream fileStream)
{
try
{
var imageData = new byte[fileStream.Size];
for (int i = 0; i < imageData.Length; i++)
{
imageData[i] = (byte)fileStream.AsStreamForRead().ReadByte();
}
var theAuthClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.imgur.com/3/image");
request.Headers.Authorization = new AuthenticationHeaderValue("Client-ID", "e5c018ac1f4c157");
var form = new MultipartFormDataContent();
var t = new StreamContent(fileStream.AsStream());
// TODO: See if this is the correct way to use imgur's v3 api. I can't see why we would still need to convert images to base64.
string base64Img = Convert.ToBase64String(imageData);
t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
form.Add(new StringContent(base64Img), @"image");
form.Add(new StringContent("file"), "type");
request.Content = form;
HttpResponseMessage response = await theAuthClient.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
if (responseString == null) return null;
var imgurEntity = JsonConvert.DeserializeObject<ImgurEntity>(responseString);
return imgurEntity;
}
catch (WebException)
{
}
catch (IOException)
{
return null;
}
return null;
}
示例2: ExportToFile
public static String ExportToFile(IRandomAccessStream exportStream)
{
StringBuilder exportResults = new StringBuilder();
using (AppStreamWriter sw = new AppStreamWriter(exportStream.AsStream()))
{
LoadLessonsUnsorted();
//write Number of Lessons
sw.WriteLine(AppData.Lessons.Length.ToString());
int exportedLessons = 0;
int exportedWords = 0;
int exportedSentences = 0;
int exportedKanjis = 0;
foreach (Lesson lesson in AppData.Lessons)
{
sw.WriteLine(lesson.ToExportString());
switch (lesson.type)
{
case 0: exportedWords += WriteVocabLesson(sw, lesson); break;
case 1: exportedSentences += WriteInsertLesson(sw, lesson); break;
case 2: break;
case 3: exportedKanjis += WriteKanjiLesson(sw, lesson); break;
case 4: break;
}
++exportedLessons;
}
exportResults.AppendLine("Datenbank erfolgreich exportiert!");
exportResults.AppendLine("Exportierte Lektionen\t: " + exportedLessons);
exportResults.AppendLine("Exportierte Wörter\t: " + exportedWords);
exportResults.AppendLine("Exportierte Lückentexte\t: " + exportedSentences);
exportResults.AppendLine("Exportierte Kanjis\t\t: " + exportedKanjis);
}
AppData.Lessons = null;
AppData.Words = null;
AppData.Sentences = null;
AppData.Kanjis = null;
return exportResults.ToString();
}
示例3: addImages
public static async Task<bool> addImages(IRandomAccessStream filestream)
{
bool success = false;
string serviceURL = "http://40.76.6.186:8888/member_register/shin";
string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
success = false;
//Rest request
HttpClient restClient = new HttpClient();
restClient.BaseAddress = new Uri("http://40.76.6.186:8888/member_register/shin");
restClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary);
//falta la autenticacion
// setAuthorization(restClient, service, WEBSERVICE_REQUEST_TYPE_POST);
// This is the postdata
MultipartFormDataContent content = new MultipartFormDataContent(boundary);
content.Add(new StringContent(boundary));
StringContent textPart = new StringContent("1234", Encoding.UTF8);
content.Add(textPart, "project");
StreamContent imagePart = new StreamContent(filestream.AsStream());
imagePart.Headers.Add("Content-Type", "image/jpeg");
content.Add(imagePart, "profile_picture", "111");
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, serviceURL);
req.Content = content;
HttpResponseMessage response = null;
string responseBodyAsText = "";
try
{
response = await restClient.SendAsync(req);
response.EnsureSuccessStatusCode();
responseBodyAsText = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.Created)
{
success = true;
}
}
catch (Exception e)
{
string err = e.Message;
}
return success;
}
示例4: Open
public async void Open(string fileName)
{
var file = await KnownFolders.MusicLibrary.CreateFileAsync( fileName, CreationCollisionOption.ReplaceExisting );
stream = await file.OpenAsync( FileAccessMode.ReadWrite );
binaryWriter = new BinaryWriter( stream.AsStream() );
dataSize = 0;
WriteWaveHeader( 0 );
disposed = false;
}
示例5: GetJournal
public static Journal GetJournal(IRandomAccessStream stream)
{
if ( stream == null )
{
return null;
}
else
{
var Reader=new StreamReader(stream . AsStream());
var Doc=XDocument . Parse(Reader . ReadToEnd());
Journal journal;
try
{
journal = (from Jou in Doc . Descendants("Journal")
select new Journal
{
Name = ( string ) Jou . Attribute("Name") ,
ListOfAuthor = from Aut in Jou . Descendants("Author")
select new Author
{
FirstName = ( string ) Aut . Attribute("FirstName") ,
FamilyName = ( string ) Aut . Attribute("FamilyName") ,
EmailAddress = ( string ) Aut . Attribute("EmailAddress") ,
Introduction = ( string ) Aut . Attribute("Introduction")
} ,
ListOfIssue = from Iss in Jou . Descendants("Issue")
select new Issue
{
Number = ( long ) Iss . Attribute("Number") ,
PublishTime = Convert . ToDateTime(( string ) Iss . Attribute("PublishTime")) ,
Price = ( decimal ) Iss . Attribute("Price") ,
ListOfArticle = from Art in Iss . Descendants("Article")
select new Article
{
Title = ( string ) Art . Attribute("Title") ,
TextLine = from Lin in Art . Descendants("Text") . FirstOrDefault() . Descendants("Line")
select ( string ) Lin . Attribute("Run") ,
ListOfAuthorName = from Aut in Art . Descendants("AuthorName")
select ( string ) Aut . Attribute("FirstName") + " " + ( string ) Aut . Attribute("FamilyName") ,
}
}
}) . First();
}
catch ( System . Exception )
{
return null;
}
foreach ( var Aut in journal . ListOfAuthor )
{
foreach ( var Iss in journal . ListOfIssue )
{
foreach ( var Art in Iss . ListOfArticle )
{
foreach ( var aut in Art . ListOfAuthor )
{
if ( Aut == aut )
{
Aut . ArticleHaveContribute . Add(Art);
}
}
}
}
}
return journal;
}
}
示例6: CreateTempFile
private async Task CreateTempFile()
{
tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(Guid.NewGuid() + ".tmp", CreationCollisionOption.GenerateUniqueName);
rtStream = await tempFile.OpenAsync(FileAccessMode.ReadWrite);
var newStream = rtStream.AsStream();
var position = currentStream.Position;
currentStream.Position = 0;
await currentStream.CopyToAsync(newStream);
newStream.Position = position;
currentStream.Dispose();
currentStream = newStream;
}
示例7: ImportFromFile
public static String ImportFromFile(IRandomAccessStream importStream)
{
StringBuilder importResults = new StringBuilder();
using (AppStreamReader sr = new AppStreamReader(importStream.AsStream()))
{
try
{
String line = sr.ReadLine();
do
{
String[] parts = line.Split('|');
int operation = Convert.ToInt32(parts[0]);
int itemCount = Convert.ToInt32(parts[1]);
String results = "";
switch (operation)
{
case 0: results = AddLessons(sr, itemCount); break;
case 1: results = UpdateLessons(sr, itemCount); break;
case 2: results = UpdateWords(sr, itemCount); break;
case 3: results = UpdateKanjis(sr, itemCount); break;
case 4: results = AddWords(sr, itemCount); break;
case 5: results = AddKanjis(sr, itemCount); break;
}
importResults.Append(results);
line = sr.ReadLine();
}
while (line != null);
context.SubmitChanges();
}
catch (Exception e)
{
importResults.Clear();
importResults.AppendLine("Import Fehlgeschlagen in Zeile: " + sr.CurrentLine);
importResults.AppendLine("System: " + e.Message);
}
}
return importResults.ToString();
}
示例8: FileSummary
public FileSummary(BitmapImage image, StorageFile file, IDictionary<string, object> properties, IRandomAccessStream stream)
{
JpegInfo exifInfo = ExifReader.ReadJpeg(stream.AsStream());
this.BasicData = new List<ExifDatum>
{
new ExifDatum("Name", file.Name),
new ExifDatum("Path", file.Path),
new ExifDatum("Created", file.DateCreated.ToString()),
new ExifDatum("Dimensions", image.PixelWidth.ToString() + "px by " + image.PixelHeight.ToString() + "px")
};
if (properties.ContainsKey("size"))
{
double num = double.Parse(properties["size"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
this.BasicData.Add(new ExifDatum("Size", ConvertBitSize(num)));
}
this.ExifData = exifInfo
.GetType()
.GetRuntimeFields()
.Select(field => new ExifDatum(field, field.GetValue(exifInfo)))
.Where(datum => datum.DisplayValue != null)
.OrderBy(datum => datum.Name)
.ToList();
this.FullData = properties
.Where(field => field.Value != null && field.Key[0] != '{')
.Select(field => ConvertPairToDatum(field))
.OrderBy(datum => datum.Name)
.ToList();
}