當前位置: 首頁>>代碼示例>>C#>>正文


C# StorageFile.GetBasicPropertiesAsync方法代碼示例

本文整理匯總了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;
        }
開發者ID:C-C-D-I,項目名稱:Windows-universal-samples,代碼行數:33,代碼來源:FileItem.cs

示例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);
 }
開發者ID:Mordonus,項目名稱:MALClient,代碼行數:8,代碼來源:CachedEntryItem.xaml.cs

示例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();
 }
開發者ID:lorenzofar,項目名稱:filenotes-win10,代碼行數:9,代碼來源:NoteAdapter.cs

示例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;
        }
開發者ID:Snail34,項目名稱:MobileScanner,代碼行數:10,代碼來源:ImageCapturedData.cs

示例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;
            }
        }
開發者ID:Appverse,項目名稱:appverse-mobile,代碼行數:45,代碼來源:WindowsPhoneMedia.cs

示例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;
            }

        }
開發者ID:Lukasss93,項目名稱:AuraRT,代碼行數:22,代碼來源:StorageHelper.cs

示例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;
        }
開發者ID:david-wb,項目名稱:Transcriber,代碼行數:38,代碼來源:WaveFile.cs

示例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);
        }
開發者ID:jadeiceman,項目名稱:securitysystem-1,代碼行數:81,代碼來源:OneDrive.cs

示例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);
            }
        }
開發者ID:mbin,項目名稱:Win81App,代碼行數:25,代碼來源:S3_GetFromStorage.xaml.cs

示例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;
        }
開發者ID:mdavidov,項目名稱:searchfiles-winstore,代碼行數:49,代碼來源:Util.cs

示例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;
            }
        }
開發者ID:JoshuaKGoldberg,項目名稱:Photo-Data-Viewer,代碼行數:15,代碼來源:MainPage.xaml.cs

示例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;
        }
開發者ID:Mordonus,項目名稱:MALClient,代碼行數:10,代碼來源:ImageCache.cs

示例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);
         }
     }
 }
開發者ID:nidzo732,項目名稱:FileTransfer,代碼行數:28,代碼來源:MainPage.cs

示例14: GetFileSize

 private async Task<long> GetFileSize(StorageFile file)
 {
     BasicProperties props = await file.GetBasicPropertiesAsync();
     return (long)props.Size;
 }
開發者ID:GSDan,項目名稱:Speeching_Client,代碼行數:5,代碼來源:Win8PCLHelper.cs

示例15: CalculateFileSize

 private async Task CalculateFileSize(StorageFile file)
 {
     BasicProperties p = await file.GetBasicPropertiesAsync();
     m_size = (long) p.Size;
 }
開發者ID:hoangduit,項目名稱:ndupfinder,代碼行數:5,代碼來源:File.cs


注:本文中的Windows.Storage.StorageFile.GetBasicPropertiesAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。