private async void btnMakeNewPhoto_Click(object sender, RoutedEventArgs e) { if (!txtPhotoName.Text.Equals("") && !txtPhotoDescription.Text.Equals("")) { var randomAccessStream = await file.OpenReadAsync(); Stream stream = randomAccessStream.AsStreamForRead(); Windows.Storage.Streams.IInputStream inStream = stream.AsInputStream(); //Create BLOBClient //CloudBlobClient blobClient = _storageAccount.CreateCloudBlobClient(); //Retrieve a reference to a container that we want to use //CloudBlobContainer container = blobClient.GetContainerReference("pictures"); //CloudBlockBlob blockBlob = container.GetBlockBlobReference(file.Name); await blockBlob.UploadFromStreamAsync(inStream); Picture p = new Picture(); p.Title = txtPhotoName.Text; p.Description = txtPhotoDescription.Text; p.UserId = _vm.ActiveUser.UserId; p.PlaceId = _vm.ActivePlace.PlaceId; p.Url = "http://shredder.blob.core.windows.net/pictures/" + file.Name; p.Rating = 0; _vm.SavePicture(p); NewPictureLayOver.Visibility = Visibility.Collapsed; } }
public ImageSource GetImageSourceFromPath(string filePath) { var file = this.localFolder.GetFileAsync(filePath).AsTask().Result; Windows.Storage.Streams.IInputStream stream = file.OpenReadAsync().AsTask().Result; return(ImageSource.FromStream(() => stream.AsStreamForRead())); }
// Construct and issue a REST request and return the response. public HttpRequestMessage CreateRESTRequest(string method, string resource, string requestBody = null, Dictionary <string, string> headers = null, string ifMatch = "", string md5 = "") { byte[] byteArray = null; DateTime now = DateTime.UtcNow; Uri uri = new Uri(Endpoint + resource); HttpMethod httpMethod = new HttpMethod(method); int contentLength = 0; var httpClient = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(httpMethod, uri); request.Headers.Add("x-ms-date", now.ToString("R", System.Globalization.CultureInfo.InvariantCulture)); request.Headers.Add("x-ms-version", "2009-09-19"); //Debug.WriteLine(now.ToString("R", System.Globalization.CultureInfo.InvariantCulture)); if (IsTableStorage) { request.Content.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/atom+xml"); request.Headers.Add("DataServiceVersion", "1.0;NetFx"); request.Headers.Add("MaxDataServiceVersion", "1.0;NetFx"); } if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { request.Headers.Add(header.Key, header.Value); } } if (!String.IsNullOrEmpty(requestBody)) { request.Headers.Add("Accept-Charset", "UTF-8"); byteArray = Encoding.UTF8.GetBytes(requestBody); MemoryStream stream = new MemoryStream(byteArray); Windows.Storage.Streams.IInputStream streamContent = stream.AsInputStream(); HttpStreamContent content = new HttpStreamContent(streamContent); request.Content = content; contentLength = byteArray.Length; } var authorizationHeader = AuthorizationHeader(method, now, request, contentLength, ifMatch, md5); request.Headers.Authorization = authorizationHeader; return(request); }
public static async Task Save(Windows.Storage.Streams.IInputStream inputStream, string filename) { var pictureLib = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures); var defaultFolder = await pictureLib.SaveFolder.GetFolderAsync("Imgur"); if (defaultFolder == null) { defaultFolder = await pictureLib.SaveFolder.CreateFolderAsync("Imgur"); } var file = await defaultFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.GenerateUniqueName); using (var fileStream = (await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))) { await Windows.Storage.Streams.RandomAccessStream.CopyAsync(inputStream, fileStream); } }
private void OnPickSingleFile(IAsyncOperation <StorageFile> info, AsyncStatus status) { var storageFile = info.GetResults(); file = storageFile; storageFile.OpenReadAsync() .Completed = (openReadInfo, openReadStatus) => { Windows.Storage.Streams.IInputStream inputStream = openReadInfo.GetResults(); System.IO.Stream stream = inputStream.AsStreamForRead(); System.IO.StreamReader reader = new StreamReader(stream); this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => txtbox.Text = reader.ReadToEnd()); }; }
public MainPage() { this.sensor = KinectSensor.GetDefault(); this.multiFrameReader = this.sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Body | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.BodyIndex); this.multiFrameReader.MultiSourceFrameArrived += this.AllFrameAvailable; FrameDescription colorFrameDescription = this.sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); this.bytesPerPixel = colorFrameDescription.BytesPerPixel; this.colorPixels = new byte[colorFrameDescription.Width * colorFrameDescription.Height * this.bytesPerPixel]; this.wBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height); this.stream = this.wBitmap.PixelBuffer.AsStream(); this.bodies = new Body[this.sensor.BodyFrameSource.BodyCount]; this.coordinateMapper = this.sensor.CoordinateMapper; FrameDescription frameDescription = this.sensor.DepthFrameSource.FrameDescription; FrameDescription irFrameDescription = this.sensor.InfraredFrameSource.FrameDescription; this.irData = new ushort[irFrameDescription.Width * irFrameDescription.Height]; this.sensor.Open(); this.DataContext = this; this.InitializeComponent(); m_heartRate = new HeartRate(); this.matrices = new IRMatrix[maxSeconds, 7]; this.irAverages = new float[maxSeconds, 7]; //this. .Children.Add(this.drawingCanvas); // grab the audio stream IReadOnlyList <AudioBeam> audioBeamList = this.sensor.AudioSource.AudioBeams; this.audioStream = audioBeamList[0].OpenInputStream(); // create the convert stream this.convertStream = new KinectAudioStream(audioStream); Window.Current.Activated += Window_Activated; }
public IAsyncOperation <SAP.Supportability.IUploadResult> SendAsync(IReadOnlyDictionary <string, string> headers, Windows.Storage.Streams.IInputStream payload) { return(Task.Run <SAP.Supportability.IUploadResult>(async() => { var result = await this.clientRef.SendAsync(() => { var request = new HttpRequestMessage(HttpMethod.Post, "http://smpqa-win12-03.sybase.com:8080/" + this.urlPostfix) { Content = new StreamContent(payload.AsStreamForRead()) }; foreach (var header in headers) { request.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); } return request; }); return new UploadResult() { ResponseStatusCode = (int)result.StatusCode, Hint = await result.Content.ReadAsStringAsync() }; }).AsAsyncOperation()); }