/// <summary>
        /// Opens a random-access stream over the specified file.
        /// </summary>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>When this method completes, it returns an IRandomAccessStream that contains the
        ///     requested random-access stream.</returns>
        public async Task <IRandomAccessStream> OpenAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            IRandomAccessStream contentStream = null;

            try
            {
                System.IO.Stream content = null;
                content = await RequestBuilder.Content.Request().GetAsync(cancellationToken).ConfigureAwait(false);

                if (content != null)
                {
                    contentStream = content.AsRandomAccessStream();
                }
            }
            catch (Microsoft.Graph.ServiceException ex)
            {
                // Swallow error in case of no content found
                if (!ex.Error.Code.Equals("ErrorItemNotFound"))
                {
                    throw;
                }
            }

            return(contentStream);
        }
        /// <summary>
        /// Retrieve current connected user's photo.
        /// </summary>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>A stream containing the user"s photo</returns>
        public async Task <IRandomAccessStream> GetPhotoAsync(CancellationToken cancellationToken)
        {
            IRandomAccessStream windowsPhotoStream = null;

            try
            {
                System.IO.Stream photo = null;
                photo = await _graphProvider.Me.Photo.Content.Request().GetAsync(cancellationToken);

                if (photo != null)
                {
                    windowsPhotoStream = photo.AsRandomAccessStream();
                }
            }
            catch (Microsoft.Graph.ServiceException ex)
            {
                // Swallow error in case of no photo found
                if (!ex.Error.Code.Equals("ErrorItemNotFound"))
                {
                    throw;
                }
            }

            return(windowsPhotoStream);
        }
 public static BitmapImage ToBitmapImage(Stream stream)
 {
     var bitmapImage = new BitmapImage();
     bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
     return bitmapImage;
 }