本文整理汇总了C#中Windows.Storage.StorageFile.GetBasicPropertiesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.GetBasicPropertiesAsync方法的具体用法?C# StorageFile.GetBasicPropertiesAsync怎么用?C# StorageFile.GetBasicPropertiesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.GetBasicPropertiesAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: fromStorageFile
// Fetches all the data for the specified file
public async static Task<FileItem> fromStorageFile(StorageFile f, CancellationToken ct)
{
FileItem item = new FileItem();
item.Filename = f.DisplayName;
// Block to make sure we only have one request outstanding
await gettingFileProperties.WaitAsync();
BasicProperties bp = null;
try
{
bp = await f.GetBasicPropertiesAsync().AsTask(ct);
}
catch (Exception) { }
finally
{
gettingFileProperties.Release();
}
ct.ThrowIfCancellationRequested();
item.Size = (int)bp.Size;
item.Key = f.FolderRelativeId;
StorageItemThumbnail thumb = await f.GetThumbnailAsync(ThumbnailMode.SingleItem).AsTask(ct);
ct.ThrowIfCancellationRequested();
BitmapImage img = new BitmapImage();
await img.SetSourceAsync(thumb).AsTask(ct);
item.ImageData = img;
return item;
}
示例2: SetDetails
private async void SetDetails(StorageFile file)
{
var data = await file.GetBasicPropertiesAsync();
_fileName = file.Name;
_saveTime = data.DateModified.LocalDateTime;
TxtDate.Text = _saveTime.ToString("dd/MM/yyyy HH:mm");
TxtSize.Text = Utilities.SizeSuffix((long) data.Size);
}
示例3: MergeFileIntoNote
private static async Task MergeFileIntoNote(StorageFile file, Note note)
{
note.DateCreated = file.DateCreated.LocalDateTime;
BasicProperties properties = await file.GetBasicPropertiesAsync();
note.DateModified = properties.DateModified.LocalDateTime;
note.Name = file.Name;
note.Text = await FileIO.ReadTextAsync(file);
note.MarkAsClean();
}
示例4: CreatePhotoCapturedDataAsync
public static async Task<PhotoCapturedData> CreatePhotoCapturedDataAsync(StorageFile imageFile, string categoryName)
{
var photoData = new PhotoCapturedData(categoryName);
photoData.ImageFile = imageFile;
photoData.ImageFileSize = (await imageFile.GetBasicPropertiesAsync()).Size;
return photoData;
}
示例5: GetMetadata
internal async Task<MediaMetadata> GetMetadata(StorageFile targetFile)
{
if (targetFile == null) return null;
var fileMetaData = new MediaMetadata();
try
{
fileMetaData.ReferenceUrl = targetFile.Path.StartsWith(WindowsPhoneUtils.DocumentsFolder.Path) ? targetFile.Path.Replace(WindowsPhoneUtils.DocumentsFolder.Path, String.Empty) : String.Empty;
fileMetaData.Size = (long)(await targetFile.GetBasicPropertiesAsync()).Size;
fileMetaData.MimeType = targetFile.ContentType;
fileMetaData.Type = MediaType.NotSupported;
if (targetFile.ContentType.Contains("audio/"))
{
var musicProperties = await targetFile.Properties.GetMusicPropertiesAsync();
fileMetaData.Album = musicProperties.Album;
fileMetaData.Artist = musicProperties.Artist;
fileMetaData.Category = musicProperties.Genre.Aggregate(new StringBuilder(), (sb, a) => sb.Append(String.Join(",", a)), sb => sb.ToString());
fileMetaData.Duration = (long)musicProperties.Duration.TotalSeconds;
fileMetaData.Title = musicProperties.Title;
fileMetaData.Type = MediaType.Audio;
}
else if (targetFile.ContentType.Contains("video/"))
{
var videoProperties = await targetFile.Properties.GetVideoPropertiesAsync();
fileMetaData.Duration = (long)videoProperties.Duration.TotalSeconds;
fileMetaData.Artist = videoProperties.Directors.Aggregate(new StringBuilder(), (sb, a) => sb.Append(String.Join(",", a)), sb => sb.ToString());
fileMetaData.Title = videoProperties.Title;
fileMetaData.Category = videoProperties.Keywords.Aggregate(new StringBuilder(), (sb, a) => sb.Append(String.Join(",", a)), sb => sb.ToString());
fileMetaData.Type = MediaType.Video;
}
else if (targetFile.ContentType.Contains("image/"))
{
var imgProperties = await targetFile.Properties.GetImagePropertiesAsync();
fileMetaData.Title = imgProperties.Title;
fileMetaData.Category = imgProperties.Keywords.Aggregate(new StringBuilder(), (sb, a) => sb.Append(String.Join(",", a)), sb => sb.ToString());
fileMetaData.Type = MediaType.Photo;
}
return fileMetaData;
}
catch (Exception ex)
{
WindowsPhoneUtils.Log(ex.Message);
return null;
}
}
示例6: isThereFreeSpace
/// <summary>
/// Restituisce true se c'è abbastanza spazio nel folder per salvare il filesize
/// </summary>
public static async Task<bool> isThereFreeSpace(StorageFile file, StorageFolder folder)
{
BasicProperties bp = await file.GetBasicPropertiesAsync();
ulong filesize = bp.Size;
var retrivedProperties = await folder.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
ulong sizefree = (ulong)retrivedProperties["System.FreeSpace"];
if(filesize<sizefree)
{
return true;
}
else
{
return false;
}
}
示例7: Initialize
private async Task<bool> Initialize(StorageFile file)
{
BinaryReader reader = new BinaryReader((await file.OpenAsync(FileAccessMode.Read)).AsStreamForRead());
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32() + 8;
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
Windows.Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync();
System.Diagnostics.Debug.Assert(fileSize == (int)basicProperties.Size);
Debug.Assert(fmtSize == 16);
Debug.Assert(channels == 1);
while (reader.BaseStream.Position != reader.BaseStream.Length)
{
Samples.Add(reader.ReadInt16() / Math.Pow(2.0, 15.0));
}
return true;
}
示例8: SendFileAsync
private async Task SendFileAsync(String url, StorageFile sFile, HttpMethod httpMethod)
{
//Log data for upload attempt
Windows.Storage.FileProperties.BasicProperties fileProperties = await sFile.GetBasicPropertiesAsync();
Dictionary<string, string> properties = new Dictionary<string, string> { { "File Size", fileProperties.Size.ToString() } };
App.Controller.TelemetryClient.TrackEvent("OneDrive picture upload attempt", properties);
HttpStreamContent streamContent = null;
try
{
//Open file to send as stream
Stream stream = await sFile.OpenStreamForReadAsync();
streamContent = new HttpStreamContent(stream.AsInputStream());
Debug.WriteLine("SendFileAsync() - sending: " + sFile.Path);
}
catch (FileNotFoundException ex)
{
Debug.WriteLine(ex.Message);
// Log telemetry event about this exception
var events = new Dictionary<string, string> { { "OneDrive", ex.Message } };
App.Controller.TelemetryClient.TrackEvent("FailedToOpenFile", events);
}
catch (Exception ex)
{
// Log telemetry event about this exception
var events = new Dictionary<string, string> { { "OneDrive", ex.Message } };
App.Controller.TelemetryClient.TrackEvent("FailedToOpenFile", events);
throw new Exception("SendFileAsync() - Cannot open file. Err= " + ex.Message);
}
if (streamContent == null)
{
//Throw exception if stream is not created
Debug.WriteLine(" File Path = " + (sFile != null ? sFile.Path : "?"));
throw new Exception("SendFileAsync() - Cannot open file.");
}
try
{
Uri resourceAddress = new Uri(url);
//Create requst to upload file
using (HttpRequestMessage request = new HttpRequestMessage(httpMethod, resourceAddress))
{
request.Content = streamContent;
// Do an asynchronous POST.
using (HttpResponseMessage response = await httpClient.SendRequestAsync(request).AsTask(cts.Token))
{
await DebugTextResultAsync(response);
if (response.StatusCode != HttpStatusCode.Created)
{
throw new Exception("SendFileAsync() - " + response.StatusCode);
}
}
}
}
catch (TaskCanceledException ex)
{
// Log telemetry event about this exception
var events = new Dictionary<string, string> { { "OneDrive", ex.Message } };
App.Controller.TelemetryClient.TrackEvent("CancelledFileUpload", events);
throw new Exception("SendFileAsync() - " + ex.Message);
}
catch (Exception ex)
{
// This failure will already be logged in telemetry in the enclosing UploadPictures function. We don't want this to be recorded twice.
throw new Exception("SendFileAsync() - Error: " + ex.Message);
}
finally
{
streamContent.Dispose();
Debug.WriteLine("SendFileAsync() - final.");
}
App.Controller.TelemetryClient.TrackEvent("OneDrive picture upload success", properties);
}
示例9: DisplayImageAsync
/// <summary>
/// Displays an image file in the 'ScenarioOutputImage' element.
/// </summary>
/// <param name="imageFile">The image file to display.</param>
async private Task DisplayImageAsync(StorageFile imageFile)
{
var imageProperties = await imageFile.GetBasicPropertiesAsync();
if (imageProperties.Size > 0)
{
rootPage.NotifyUser("Displaying: " + imageFile.Name + ", date modified: " + imageProperties.DateModified + ", size: " + imageProperties.Size + " bytes", NotifyType.StatusMessage);
var stream = await imageFile.OpenAsync(FileAccessMode.Read);
// BitmapImage.SetSource needs to be called in the UI thread
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var bitmap = new BitmapImage();
bitmap.SetSource(stream);
ScenarioOutputImage.SetValue(Image.SourceProperty, bitmap);
});
}
else
{
rootPage.NotifyUser("Cannot display " + imageFile.Name + " because its size is 0", NotifyType.ErrorMessage);
}
}
示例10: CreatePropertiesFlyout
public static async Task<SettingsFlyout> CreatePropertiesFlyout(StorageFile file, StorageFolder topFolder, string fileSubPath)
{
if (file == null) return null;
SettingsFlyout flyout = null;
try
{
BasicProperties basicProps = null;
try { basicProps = await file.GetBasicPropertiesAsync(); }
catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
if (file.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
{
var flyoutImg = new PropertiesFlyoutImage();
flyout = flyoutImg;
ImageProperties imageProps = await file.Properties.GetImagePropertiesAsync();
if (imageProps != null)
FillImageProperties(flyoutImg, imageProps, file, basicProps);
}
else if (file.ContentType.ToLower().StartsWith("audio"))
{
var flyoutAud = new PropertiesFlyoutAudio();
flyout = flyoutAud;
MusicProperties musicProps = await file.Properties.GetMusicPropertiesAsync();
if (musicProps != null)
await FillAudioProperties(flyoutAud, musicProps, file);
}
else if (file.ContentType.ToLower().StartsWith("video"))
{
var flyoutVdo = new PropertiesFlyoutVideo();
flyout = flyoutVdo;
VideoProperties videoProps = await file.Properties.GetVideoPropertiesAsync();
if (videoProps != null)
FillVideoProperties(flyoutVdo, videoProps);
}
else
{
var flyoutGen = new PropertiesFlyoutGeneral();
flyout = flyoutGen;
await FillGeneralProperties(flyoutGen, file, basicProps);
}
Debug.Assert(flyout != null, "Flyout object must exist.");
if (flyout != null)
await FillFileProperties((IFileProperties)flyout, file, topFolder, fileSubPath, basicProps);
}
catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
return flyout;
}
示例11: SetDataContext
private async void SetDataContext(BitmapImage image, StorageFile file)
{
var stream = await file.OpenAsync(FileAccessMode.Read);
var properties = await (await file.GetBasicPropertiesAsync()).RetrievePropertiesAsync(new string[] { });
DataContext = new FileSummary(image, file, properties, stream);
// Show the relevant sub-headers
if (SubHeaderBasic.Visibility != Visibility.Visible)
{
SubHeaderBasic.Visibility = Visibility.Visible;
SubHeaderExif.Visibility = Visibility.Visible;
SubHeaderFull.Visibility = Visibility.Visible;
}
}
示例12: IsFileOutOfDate
private static async Task<bool> IsFileOutOfDate(StorageFile file, DateTime expirationDate)
{
if (file != null)
{
var properties = await file.GetBasicPropertiesAsync();
return properties.DateModified < expirationDate;
}
return true;
}
示例13: uploadFile
private async Task uploadFile(StorageFile file, string peer)
{
if (file == null) return;
if (shareOperation != null) shareOperation.ReportStarted();
var fileSize = (await file.GetBasicPropertiesAsync()).Size;
if ( fileSize> 20 * 1024 * 1024)
{
await DialogBoxes.AskForConfirmation("File may be too big to handle. The file size is "+(fileSize/1024/1024).ToString()+"MB. Files bigger than 20 MB may cause the application to crash. Proceed at your own risk?",
async () =>
{
byte[] fileContents = (await FileIO.ReadBufferAsync(file)).ToArray();
if (shareOperation != null) shareOperation.ReportDataRetrieved();
await Communicator.SendFile(file.Name, fileContents, peer);
});
}
else
{
byte[] fileContents = (await FileIO.ReadBufferAsync(file)).ToArray();
if ((bool)enableEncryption.IsChecked)
{
await Communicator.SendFile(file.Name, fileContents, peer);
}
else
{
await Communicator.SendFileNoCrypt(file.Name, fileContents, peer);
}
}
}
示例14: GetFileSize
private async Task<long> GetFileSize(StorageFile file)
{
BasicProperties props = await file.GetBasicPropertiesAsync();
return (long)props.Size;
}
示例15: CalculateFileSize
private async Task CalculateFileSize(StorageFile file)
{
BasicProperties p = await file.GetBasicPropertiesAsync();
m_size = (long) p.Size;
}