本文整理汇总了C#中IStorageFile类的典型用法代码示例。如果您正苦于以下问题:C# IStorageFile类的具体用法?C# IStorageFile怎么用?C# IStorageFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IStorageFile类属于命名空间,在下文中一共展示了IStorageFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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);
}
}
示例3: GameRouletteModelLogic
public GameRouletteModelLogic(IStorageFolder folder, IStorage storage, IStorageFile file, IImage image)
{
_folder = folder;
_storage = storage;
_file = file;
_image = image;
}
示例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);
}
示例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
}
示例6: WriteBytesAsync
internal async static Task WriteBytesAsync(IStorageFile storageFile, byte[] bytes)
{
using (Stream stream = await storageFile.OpenStreamForWriteAsync())
{
await stream.WriteAsync(bytes, 0, bytes.Length);
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例10: YandexGetFileProgressEventArgs
public YandexGetFileProgressEventArgs(IStorageFile file, byte[] buffer, int bytesRead, long totalBytesDowloaded)
{
File = file;
Buffer = buffer;
BytesRead = bytesRead;
TotalBytesDowloaded = totalBytesDowloaded;
}
示例11: WriteTextToFileCore
protected override async Task WriteTextToFileCore(IStorageFile file, string contents)
{
using (var sw = new StreamWriter(file.Path, true))
{
await sw.WriteLineAsync(contents);
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}