Ejemplo n.º 1
0
        /// <summary>
        /// Responds to a receiver indicating an upload should occur.
        /// </summary>
        /// <param name="mediaCapture">An image capture source.</param>
        private async Task HandleUpload(MediaCapture mediaCapture)
        {
            var folderName = ((App)Application.Current).StorageFolderPath;
            var fileName   = this.GenerateFileName();

            using (var fileStore = await TemporaryCaptureFileStore.Create(fileName, mediaCapture))
            {
                await PieceOfCrap.RunAction(async (PieceOfCrap crap) =>
                {
                    await crap.PutItem(folderName, fileName, new StreamContent(fileStore.OutputStream));
                });

                await fileStore.DisposeAsync();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a <see cref="BitmapImage"/> by downloading the stored item.
        /// </summary>
        /// <returns>A newly created <see cref="BitmapImage"/>.</returns>
        public async Task <BitmapImage> GenerateBitmap()
        {
            return(await PieceOfCrap.RunAction(
                       async (PieceOfCrap crap) =>
            {
                var inputStream = await crap.GetItemContents("PassiveEyes", this.Item.Name);

                using (var outputStream = new MemoryStream())
                {
                    await inputStream.CopyToAsync(outputStream);
                    outputStream.Position = 0;

                    var bitmap = new BitmapImage();
                    await bitmap.SetSourceAsync(outputStream.AsRandomAccessStream());
                    return bitmap;
                }
            }));
        }
        private async void AuthWebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
        {
            if (!args.Uri.ToString().StartsWith(RedirectUri))
            {
                return;
            }
            var queryDictionary = new WwwFormUrlDecoder(args.Uri.Query);

            if (args.Uri.Query.Substring(1).StartsWith("error"))
            {
                await new MessageDialog("Unable to authenticate with OneDrive.", "Whoops.").ShowAsync();
                AuthWebView.Visibility = Visibility.Collapsed;
                return;
            }
            var code        = queryDictionary.GetFirstValueByName("code");
            var httpContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("client_id", (App.Current as App).AppConfig.ClientId),
                new KeyValuePair <string, string>("redirect_uri", RedirectUri),
                new KeyValuePair <string, string>("client_secret", (App.Current as App).AppConfig.ClientSecret),
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("code", code)
            });
            var httpClient = new HttpClient();
            var result     = await httpClient.PostAsync("https://login.live.com/oauth20_token.srf", httpContent);

            var contentStr = await result.Content.ReadAsStringAsync();

            if (!result.IsSuccessStatusCode)
            {
                await new MessageDialog("Unable to authenticate with OneDrive.", "Whoops.").ShowAsync();
                AuthWebView.Visibility = Visibility.Collapsed;
                return;
            }
            var response = await result.Content.ReadAsAsync <AuthResponseModel>();

            ((App)Application.Current).Crap = new PieceOfCrap(response.AccessToken);
            await PieceOfCrap.RunAction(async (PieceOfCrap crap) => await crap.GetDrive());

            Frame.Navigate(typeof(UsageChoicePage));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Directory"/> class.
        /// </summary>
        /// <param name="folderPath">The path to the folder on OneDrive.</param>
        /// <returns>An equivalent directory to the OneDrive folder.</returns>
        public static async Task <Directory> FromFolderPath(string folderPath)
        {
            var children = await PieceOfCrap.RunAction(
                async (PieceOfCrap crap)
                => await crap.GetItemChildren <Children>("PassiveEyes"));

            var items = children.Value.Select(child => Record.FromChild(child));

            var groups = items
                         .GroupBy(item => item.Webcam)
                         .ToDictionary(
                group => group.Key,
                group =>
            {
                var list = group.ToList();
                list.Sort((a, b) => (b.Timestamp - a.Timestamp).Milliseconds);
                return(list);
            });

            return(new Directory {
                Records = groups
            });
        }