• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IStorageFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IStorageFile的典型用法代码示例。如果您正苦于以下问题:C# IStorageFile类的具体用法?C# IStorageFile怎么用?C# IStorageFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IStorageFile类属于命名空间,在下文中一共展示了IStorageFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Hash

        public static async Task<string> Hash(IStorageFile file)
        {
            string res = string.Empty;

            using(var streamReader = await file.OpenAsync(FileAccessMode.Read))
            {
                var alg = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
                var algHash = alg.CreateHash();

                using(BinaryReader reader = new BinaryReader(streamReader.AsStream(), Encoding.UTF8))
                {
                    byte[] chunk;

                    chunk = reader.ReadBytes(CHUNK_SIZE);
                    while(chunk.Length > 0)
                    {
                        algHash.Append(CryptographicBuffer.CreateFromByteArray(chunk));
                        chunk = reader.ReadBytes(CHUNK_SIZE);
                    }
                }

                res = CryptographicBuffer.EncodeToHexString(algHash.GetValueAndReset());
                return res;
            }
        }
开发者ID:Lukasss93,项目名称:AuraRT,代码行数:25,代码来源:MD5.cs


示例2: GenerateThumbnail

        private static async Task<Uri> GenerateThumbnail(IStorageFile file)
        {
            using (var fileStream = await file.OpenReadAsync())
            {
                // decode the file using the built-in image decoder
                var decoder = await BitmapDecoder.CreateAsync(fileStream);

                // create the output file for the thumbnail
                var thumbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    string.Format("thumbnail{0}", file.FileType),
                    CreationCollisionOption.GenerateUniqueName);

                // create a stream for the output file
                using (var outputStream = await thumbFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    // create an encoder from the existing decoder and set the scaled height
                    // and width 
                    var encoder = await BitmapEncoder.CreateForTranscodingAsync(
                        outputStream,
                        decoder);
                    encoder.BitmapTransform.ScaledHeight = 100;
                    encoder.BitmapTransform.ScaledWidth = 100;
                    await encoder.FlushAsync();
                }

                // create the URL
                var storageUrl = string.Format(URI_LOCAL, thumbFile.Name);

                // return it
                return new Uri(storageUrl, UriKind.Absolute);
            }
        }
开发者ID:griffinfujioka,项目名称:Archive,代码行数:32,代码来源:ThumbnailMaker.cs


示例3: GameRouletteModelLogic

 public GameRouletteModelLogic(IStorageFolder folder, IStorage storage, IStorageFile file, IImage image)
 {
     _folder = folder;
     _storage = storage;
     _file = file;
     _image = image;
 }
开发者ID:nzall,项目名称:GameRoulette,代码行数:7,代码来源:GameRouletteModelLogic.cs


示例4: LoadDatabase

        public async static Task<PwDatabase> LoadDatabase(IStorageFile database, string password, string keyPath)
        {
            var userKeys = new List<IUserKey>();
            var hasher = new SHA256HasherRT();
            if (!string.IsNullOrEmpty(password))
            {
                userKeys.Add(await KcpPassword.Create(password, hasher));
            }

            if (!string.IsNullOrEmpty(keyPath))
            {
                var keyfile = await Helpers.Helpers.GetKeyFile(keyPath);
                userKeys.Add(await KcpKeyFile.Create(new WinRTFile(keyfile), hasher));
            }

            var readerFactory = new KdbReaderFactory(
                new WinRTCrypto(),
                new MultiThreadedBouncyCastleCrypto(),
                new SHA256HasherRT(),
                new GZipFactoryRT());

            var file = await FileIO.ReadBufferAsync(database);
            MemoryStream kdbDataReader = new MemoryStream(file.AsBytes());

            return await readerFactory.LoadAsync(kdbDataReader, userKeys);
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:26,代码来源:Scenarios.cs


示例5: LaunchFileAsync

        /// <summary>
        /// Starts the app associated with the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>The launch operation.</returns>
        /// <remarks>    
        /// <list type="table">
        /// <listheader><term>Platform</term><description>Version supported</description></listheader>
        /// <item><term>iOS</term><description>iOS 9.0 and later</description></item>
        /// <item><term>Windows UWP</term><description>Windows 10</description></item>
        /// <item><term>Windows Store</term><description>Windows 8.1 or later</description></item>
        /// <item><term>Windows Phone Store</term><description>Windows Phone 8.1 or later</description></item>
        /// <item><term>Windows Phone Silverlight</term><description>Windows Phone 8.0 or later</description></item>
        /// <item><term>Windows (Desktop Apps)</term><description>Windows Vista or later</description></item></list></remarks>
        public static Task<bool> LaunchFileAsync(IStorageFile file)
        {
#if __IOS__
            return Task.Run<bool>(() =>
            {
                bool success = false;
                UIKit.UIApplication.SharedApplication.InvokeOnMainThread(() =>
                {
                    UIDocumentInteractionController c = UIDocumentInteractionController.FromUrl(global::Foundation.NSUrl.FromFilename(file.Path));
                    c.ViewControllerForPreview = ViewControllerForPreview;
                    success = c.PresentPreview(true);
                });

                return success;
            });
#elif __MAC__
            return Task.Run<bool>(() =>
            {
                bool success = NSWorkspace.SharedWorkspace.OpenFile(file.Path);
                return success;
            });
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return Windows.System.Launcher.LaunchFileAsync((Windows.Storage.StorageFile)((StorageFile)file)).AsTask();
#elif WIN32
            return Task.FromResult<bool>(Launch(file.Path, null));
#else
            throw new PlatformNotSupportedException();
#endif
        }
开发者ID:inthehand,项目名称:Charming,代码行数:43,代码来源:Launcher.cs


示例6: WriteBytesAsync

 internal async static Task WriteBytesAsync(IStorageFile storageFile, byte[] bytes)
 {
   using (Stream stream = await storageFile.OpenStreamForWriteAsync())
   {
     await stream.WriteAsync(bytes, 0, bytes.Length);
   }
 }
开发者ID:KateGridina,项目名称:Q42.WinRT,代码行数:7,代码来源:FileIO.cs


示例7: OpenSpider

        public async Task<bool> OpenSpider( IStorageFile ISF )
        {
            try
            {
                SpiderBook SBook = await SpiderBook.ImportFile( await ISF.ReadString(), true );

                List<LocalBook> NData;
                if( Data != null )
                {
                    NData = new List<LocalBook>( Data.Cast<LocalBook>() );
                    if ( NData.Any( x => x.aid == SBook.aid ) )
                    {
                        Logger.Log( ID, "Already in collection, updating the data", LogType.DEBUG );
                        NData.Remove( NData.First( x => x.aid == SBook.aid ) );
                    }
                }
                else
                {
                    NData = new List<LocalBook>();
                }

                NData.Add( SBook );
                Data = NData;
                NotifyChanged( "SearchSet" );
                return SBook.CanProcess || SBook.ProcessSuccess;
            }
            catch( Exception ex )
            {
                Logger.Log( ID, ex.Message, LogType.ERROR );
            }

            return false;
        }
开发者ID:tgckpg,项目名称:wenku10,代码行数:33,代码来源:SpiderScope.cs


示例8: SaveToFile

        public static async Task SaveToFile(
            this WriteableBitmap writeableBitmap,
            IStorageFile outputFile,
            Guid encoderId)
        {
            try
            {
                Stream stream = writeableBitmap.PixelBuffer.AsStream();
                byte[] pixels = new byte[(uint)stream.Length];
                await stream.ReadAsync(pixels, 0, pixels.Length);

                using (var writeStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(encoderId, writeStream);
                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Premultiplied,
                        (uint)writeableBitmap.PixelWidth,
                        (uint)writeableBitmap.PixelHeight,
                        96,
                        96,
                        pixels);
                    await encoder.FlushAsync();

                    using (var outputStream = writeStream.GetOutputStreamAt(0))
                    {
                        await outputStream.FlushAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
        }
开发者ID:liquidboy,项目名称:X,代码行数:35,代码来源:WriteableBitmapExtensions.cs


示例9: DownLoadSingleFileAsync

        /// <summary>
        /// download a file 
        /// </summary>
        /// <param name="fileUrl">fileUrl</param>
        /// <param name="destinationFile">file's destination</param>
        /// <param name="downloadProgress">a action that can show the download progress</param>
        /// <param name="priority">background transfer priority </param>
        /// <param name="requestUnconstrainedDownload"></param>
        /// <returns></returns>
        public static async Task DownLoadSingleFileAsync(string fileUrl, IStorageFile destinationFile, Action<DownloadOperation> downloadProgress =null
        , BackgroundTransferPriority priority = BackgroundTransferPriority.Default, bool requestUnconstrainedDownload = false)
        {
            Uri source;
            if (!Uri.TryCreate(fileUrl, UriKind.Absolute, out source))
            {
                // Logger.Info("File Url:" + fileUrl + "is not valid URIs");
                Debug.WriteLine("File Url:" + fileUrl + "is not valid URIs");
                return;
            }
            BackgroundDownloader downloader = new BackgroundDownloader();
            DownloadOperation download = downloader.CreateDownload(source, destinationFile);
            download.Priority = priority;

            Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Downloading {0} to {1} with {2} priority, {3}",
                source.AbsoluteUri, destinationFile.Name, priority, download.Guid));

            if (!requestUnconstrainedDownload)
            {
                // Attach progress and completion handlers.
                await HandleDownloadAsync(download, true, downloadProgress);
                return;

            }
        }
开发者ID:Neilxzn,项目名称:NeilSoft.UWP,代码行数:34,代码来源:DownLoadHelper.cs


示例10: YandexGetFileProgressEventArgs

 public YandexGetFileProgressEventArgs(IStorageFile file, byte[] buffer, int bytesRead, long totalBytesDowloaded)
 {
     File = file;
     Buffer = buffer;
     BytesRead = bytesRead;
     TotalBytesDowloaded = totalBytesDowloaded;
 }
开发者ID:quadgod,项目名称:breader,代码行数:7,代码来源:YandexGetFileProgressEventArgs.cs


示例11: WriteTextToFileCore

 protected override async Task WriteTextToFileCore(IStorageFile file, string contents)
 {
     using (var sw = new StreamWriter(file.Path, true))
     {
         await sw.WriteLineAsync(contents);
     }
 }
开发者ID:mqmanpsy,项目名称:MetroLog,代码行数:7,代码来源:Wp8FileStreamingTarget.cs


示例12: CreateUploadOperationForCreateImage

        private static async Task<UploadOperation> CreateUploadOperationForCreateImage(
            IStorageFile file, string token, BackgroundUploader uploader)
        {
            const string boundary = "imgboundary";

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();

            BackgroundTransferContentPart metadataPart = new BackgroundTransferContentPart("token");

            metadataPart.SetText(token);
            //metadataPart.SetText("iamatoken");
            parts.Add(metadataPart);

            BackgroundTransferContentPart imagePart = new BackgroundTransferContentPart("photo", file.Name);
            imagePart.SetFile(file);
            imagePart.SetHeader("Content-Type", file.ContentType);
            parts.Add(imagePart);

            return
                await uploader.CreateUploadAsync(
                    new Uri(HttpFotosSapoPtUploadpostHtmlUri),
                    parts,
                    "form-data",
                    boundary);
        }
开发者ID:sapo,项目名称:sapo-services-sdk,代码行数:25,代码来源:PhotosServiceClient.cs


示例13: UploadFile

 public async Task UploadFile(string name,IStorageFile storageFile)
 {            
     var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
     var transferUtilityConfig = new TransferUtilityConfig
     {                
         ConcurrentServiceRequests = 5,                
         MinSizeBeforePartUpload = 20 * MB_SIZE,
     };
     try
     {
         using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
         {
             var uploadRequest = new TransferUtilityUploadRequest
             {
                 BucketName = ExistingBucketName,
                 Key = name,
                 StorageFile = storageFile,
                 // Set size of each part for multipart upload to 10 MB
                 PartSize = 10 * MB_SIZE
             };
             uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
             await transferUtility.UploadAsync(uploadRequest);
         }
     }
     catch (AmazonServiceException ex)
     {
       //  oResponse.OK = false;
      //   oResponse.Message = "Network Error when connecting to AWS: " + ex.Message;
     }
 }
开发者ID:prashanthganathe,项目名称:PersonalProjects,代码行数:30,代码来源:AmazonFileBucketTransferUtil.cs


示例14: CreateUploadOperationForCreateVideo

        private static async Task<UploadOperation> CreateUploadOperationForCreateVideo(
            IStorageFile file, string token, BackgroundUploader uploader)
        {
            const string boundary = "videoboundary";

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();

            BackgroundTransferContentPart metadataPart = new BackgroundTransferContentPart("token");

            metadataPart.SetText(token);
            //metadataPart.SetText("iamatoken");
            parts.Add(metadataPart);

            BackgroundTransferContentPart videoPart = new BackgroundTransferContentPart("content_file", file.Name);
            videoPart.SetFile(file);
            videoPart.SetHeader("Content-Type", file.ContentType);
            parts.Add(videoPart);

            return
                await uploader.CreateUploadAsync(
                    new Uri(AddVideoPostUri),
                    parts,
                    "form-data",
                    boundary);
        }
开发者ID:sapo,项目名称:sapo-services-sdk,代码行数:25,代码来源:VideosServiceClient.cs


示例15: UploadFromAsync

 public Task UploadFromAsync(IStorageFile sourceFile, CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new Amazon.S3.Transfer.TransferUtilityUploadRequest();
     request.BucketName = this.linker.s3.bucket;
     request.Key = this.linker.s3.key;
     request.StorageFile = sourceFile;
     return GetTransferUtility().UploadAsync(request, cancellationToken);
 }
开发者ID:rossmas,项目名称:aws-sdk-net,代码行数:8,代码来源:S3Link.storagefile.cs


示例16: CreateAsync

        public static async Task<FlacMediaSourceAdapter> CreateAsync(IStorageFile file)
        {
            var fileStream = await file.OpenAsync(FileAccessMode.Read);
            var adapter = new FlacMediaSourceAdapter();
            adapter.Initialize(fileStream);

            return adapter;
        }
开发者ID:jayharry28,项目名称:Audiotica,代码行数:8,代码来源:FlacMediaSourceAdapter.cs


示例17: CreateBackgroundDownloadOperation

 /// <summary>
 /// Creates a new TailoredDownloadOperation instance.
 /// </summary>
 public CreateBackgroundDownloadOperation(
     LiveConnectClient client, 
     Uri url, 
     IStorageFile outputFile)
     : base(client, url, ApiMethod.Download, null, null)
 {
     this.OutputFile = outputFile;
 }
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:11,代码来源:CreateBackgroundDownloadOperation.cs


示例18: WriteTextAsync

 internal async static Task WriteTextAsync(IStorageFile storageFile, string text)
 {
   using (Stream stream = await storageFile.OpenStreamForWriteAsync())
   {
     byte[] content = Encoding.UTF8.GetBytes(text);
     await stream.WriteAsync(content, 0, content.Length);
   }
 }
开发者ID:KateGridina,项目名称:Q42.WinRT,代码行数:8,代码来源:FileIO.cs


示例19: EmailAttachment

        public EmailAttachment(IStorageFile file)
        {
            if (file == null)
                throw new ArgumentNullException("file");

            FileName = file.Name;
            Content = RandomAccessStreamReference.CreateFromFile(file);
        }
开发者ID:kryz,项目名称:Xamarin.Plugins,代码行数:8,代码来源:EmailAttachment.cs


示例20: StartDownloadAsync

 public IAsyncOperationWithProgress<DownloadOperation, DownloadOperation> StartDownloadAsync(Uri uri, IStorageFile storageFile)
 {
     return AsyncInfo.Run<DownloadOperation, DownloadOperation>((token, progress) =>
       Task.Run<DownloadOperation>(() =>
       {
          return (DownloadOperation)null;
       }, token));
 }
开发者ID:iinteractive,项目名称:jira-win8-client,代码行数:8,代码来源:IBackgroundDownloader.cs



注:本文中的IStorageFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IStorageProvider类代码示例发布时间:2022-05-24
下一篇:
C# IStorageBlobManagement类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap