public async Task <HttpRequestMessage> Create(string uri) { // TODO: ETag support required?? // TODO: choose rational timeout values var request = HttpRequestHelper.CreateHttpWebRequest(uri, false); //request.AllowWriteStreamBuffering = _allowWriteStreamBuffering; if (_etag != null && _etag.Length != 0) { request.Headers["If-match"] = _etag; } await _parent._requestFilter(request); using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { var streamContent = new HttpStreamContent(inS.AsInputStream()); streamContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(MimeHelper.GetContentType(Path.GetExtension(_filename))); if (_parent._options != null && _parent._options.SupportsSlug) { request.Headers["Slug"] = Path.GetFileNameWithoutExtension(_filename); } request.Method = new HttpMethod(_method); } return(request); }
/// <summary> /// Add ink to the InkCanvas, based on the contents of the supplied ISF file. /// </summary> private async void AddInkFromFile(string filename) { if (string.IsNullOrEmpty(filename)) { return; } // Remove any existing ink first. inkCanvas.InkPresenter.StrokeContainer.Clear(); // Assume the file is valid and accessible /* TODO :: parse the incoming filename and replace "Signature.isf" */ //Windows.Storage.StorageFile file = await // Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Signature.isf")); // TODO :: Unable to load ink from a file onto the inkCanvas. // Have tried several ways to load a .isf file onto the canvas, // I am thinking of not support .isf files and just using .gif files. // GIF files are the UWP standard for loading and saving inkCanvases. It // does say that LoadAsync() is backwasrd compatible to .isf,but no luck yet. var file = new FileStream(filename, FileMode.Open, FileAccess.Read); // new FileStream(filename, FileMode.Open, FileAccess.Read); var stream = file.AsInputStream(); await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); //file.Close(); //if (file != null) //{ // var stream = await file.OpenReadAsync(); // using (var inputStream = stream.GetInputStreamAt(0)) // { // await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(inputStream); // } // stream.Dispose(); //} //else //{ // // opeartion cancelled //} //if (strokeCollection.Count > 0) //{ // // Add ink to the InkCanvas, similar to the ink loaded from the supplied file, // // but with evenly distributed points along the strokes. // GenerateStrokesWithEvenlyDistributedPoints(strokeCollection); // ApplySettingsToInk(); //} }
public void fSha256(int refId, IPromise promise) { DispatcherHelpers.RunOnDispatcher(() => { Task.Run(async() => { try { FileWrapper fileWrapper; if (!files.TryGetValue(refId, out fileWrapper)) { throw new Exception("Invalid refId"); } FileStream fileStream = fileWrapper.fileStream; if (!fileStream.CanRead) { throw new Exception("File is not readable"); } uint capacity = 8192; Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(capacity); HashAlgorithmProvider alg = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256); CryptographicHash hash = alg.CreateHash(); IInputStream inputStream = fileStream.AsInputStream(); while (true) { await inputStream.ReadAsync(buffer, capacity, InputStreamOptions.None); if (buffer.Length > 0) { hash.Append(buffer); } else { break; } } promise.Resolve(CryptographicBuffer.EncodeToBase64String(hash.GetValueAndReset())); } catch (Exception e) { promise.Reject(ERROR_FATAL, e); } }); }); }