public async Task <Stream> RefreshAndDownloadContent( ItemInfoResponse model, bool refreshFirst) { var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Bearer, AccessToken); // Refresh the item's information if (refreshFirst) { var request = string.Format(RequestItem, model.Id); var uri = new Uri(RootUrl + request); var json = await client.GetStringAsync(uri); var refreshedItem = JsonConvert.DeserializeObject <ItemInfoResponse>(json); model.DownloadUrl = refreshedItem.DownloadUrl; } var response = await client.GetAsync(model.DownloadUrl); var stream = await response.Content.ReadAsStreamAsync(); return(stream); }
private async void BrowseSubfolderClick(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(FolderPathText.Text)) { var dialog = new MessageDialog("Please enter a path to a folder, for example Apps/OneDriveSample", "Error!"); await dialog.ShowAsync(); return; } Exception error = null; ItemInfoResponse subfolder = null; ShowBusy(true); try { subfolder = await _service.GetItem(FolderPathText.Text); } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(error.Message, "Error!"); await dialog.ShowAsync(); ShowBusy(false); return; } if (subfolder == null) { var dialog = new MessageDialog($"Not found: {FolderPathText.Text}"); await dialog.ShowAsync(); } else { var children = await _service.PopulateChildren(subfolder); DisplayHelper.ShowContent( "SHOW SUBFOLDER CONTENT ------------------------", subfolder, children, async message => { var dialog = new MessageDialog(message); await dialog.ShowAsync(); }); } ShowBusy(false); }
private async void uploadImageButton_Clicked(object sender, EventArgs e) { var folder = await _service.GetAppRoot(); using (var stream = this._photo.GetStream()) { this._response = await _service.SaveFile(folder.Id, System.IO.Path.GetFileName(this._photo.Path), stream); Debug.WriteLine(this._response.WebUrl); await DisplayAlert("アップロード", "ファイルを以下のURLにアップロードしました。" + this._response.WebUrl, "OK"); this.result.Text = this._response.WebUrl; } }
public async Task <IList <ItemInfoResponse> > PopulateChildren(ItemInfoResponse info) { if (string.IsNullOrEmpty(AccessToken)) { throw new InvalidOperationException(AccessTokenIsNotSet); } var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Bearer, AccessToken); var request = string.Format(RequestChildren, info.Id); var uri = new Uri(RootUrl + request); var json = await client.GetStringAsync(uri); var response = JsonConvert.DeserializeObject <ParseChildrenResponse>(json); return(response.Value); }
private async void GetRootFolderClick(object sender, RoutedEventArgs e) { Exception error = null; ItemInfoResponse folder = null; IList <ItemInfoResponse> children = null; ShowBusy(true); try { folder = await _service.GetRootFolder(); children = await _service.PopulateChildren(folder); } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(error.Message, "Error!"); await dialog.ShowAsync(); ShowBusy(false); return; } DisplayHelper.ShowContent( "SHOW ROOT FOLDER ++++++++++++++++++++++", folder, children, async message => { var dialog = new MessageDialog(message); await dialog.ShowAsync(); }); ShowBusy(false); }
public static void ShowContent( string title, ItemInfoResponse item, IList <ItemInfoResponse> children, Action <string> showDialog) { Debug.WriteLine(title); Debug.WriteLine($"Folder name: {item.Name}"); Debug.WriteLine($"Created on: {item.CreatedDateTime}"); Debug.WriteLine($"Modified on: {item.LastModifiedDateTime}"); Debug.WriteLine($"Size: {item.SizeInBytes.ConvertSize()}"); Debug.WriteLine($"Web URL: {item.WebUrl}"); if (item.Folder != null) { Debug.WriteLine($"Child count: {item.Folder.ChildCount}"); showDialog( $"The folder {item.Name} has {item.Folder.ChildCount} children. More details in the Output window!"); } else { showDialog($"Retrieved info for folder {item.Name}. More details in the Output window!"); } if (children == null) { return; } foreach (var child in children) { Debug.WriteLine("----"); Debug.WriteLine($"Child name: {child.Name}"); Debug.WriteLine($"Created on: {child.CreatedDateTime}"); Debug.WriteLine($"Modified on: {child.LastModifiedDateTime}"); Debug.WriteLine($"Size: {child.SizeInBytes.ConvertSize()}"); Debug.WriteLine($"Web URL: {child.WebUrl}"); Debug.WriteLine($"Kind: {child.Kind}"); if (child.Audio != null) { Debug.WriteLine("AUDIO INFO"); Debug.WriteLine($"Album: {child.Audio.Album}"); Debug.WriteLine($"Album Artist: {child.Audio.AlbumArtist}"); Debug.WriteLine($"Duration [ms]: {child.Audio.DurationMilliSeconds}"); } if (child.Video != null) { Debug.WriteLine("VIDEO INFO"); Debug.WriteLine($"Bitrate: {child.Video.Bitrate}"); Debug.WriteLine($"Width: {child.Video.Width}"); Debug.WriteLine($"Height: {child.Video.Height}"); } if (child.Photo != null) { Debug.WriteLine("PHOTO INFO"); Debug.WriteLine($"Camera Model: {child.Photo.CameraModel}"); Debug.WriteLine($"Camera Make: {child.Photo.CameraMake}"); } if (child.Image != null) { Debug.WriteLine("IMAGE INFO"); Debug.WriteLine($"Width: {child.Image.Width}"); Debug.WriteLine($"Height: {child.Image.Height}"); } if (child.Folder != null) { Debug.WriteLine("FOLDER INFO"); Debug.WriteLine($"Child count: {child.Folder.ChildCount}"); // At this point we would need to populate the subfolder // with PopulateChildren } } }
private async void DownloadFileClick(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(DownloadFilePathText.Text)) { var dialog = new MessageDialog("Please enter a path to an existing file, for example Apps/OneDriveSample/Test.jpg", "Error!"); await dialog.ShowAsync(); return; } Exception error = null; ItemInfoResponse foundFile = null; Stream contentStream = null; ShowBusy(true); try { foundFile = await _service.GetItem(DownloadFilePathText.Text); if (foundFile == null) { var dialog = new MessageDialog($"Not found: {DownloadFilePathText.Text}"); await dialog.ShowAsync(); ShowBusy(false); return; } // Get the file's content contentStream = await _service.RefreshAndDownloadContent(foundFile, false); if (contentStream == null) { var dialog = new MessageDialog($"Content not found: {DownloadFilePathText.Text}"); await dialog.ShowAsync(); ShowBusy(false); return; } } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(error.Message, "Error!"); await dialog.ShowAsync(); ShowBusy(false); return; } // Save the retrieved stream to the local drive var picker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = foundFile.Name }; var extension = Path.GetExtension(foundFile.Name); picker.FileTypeChoices.Add( $"{extension} files", new List <string> { extension }); var targetFile = await picker.PickSaveFileAsync(); using (var targetStream = await targetFile.OpenStreamForWriteAsync()) { using (var writer = new BinaryWriter(targetStream)) { contentStream.Position = 0; using (var reader = new BinaryReader(contentStream)) { byte[] bytes; do { bytes = reader.ReadBytes(1024); writer.Write(bytes); }while (bytes.Length == 1024); } } } var successDialog = new MessageDialog("Done saving the file!", "Success"); await successDialog.ShowAsync(); ShowBusy(false); }
private async void RestauraDB() { var folder = await _service.GetSpecialFolder(OneDriveSimple.Request.SpecialFolder.AppRoot); string rpath = "Storage.sqlite"; if (string.IsNullOrEmpty(rpath)) { var dialog = new MessageDialog("Please enter a path to an existing file, for example Apps/My Notes/Storage.sqlite", "Error!"); await dialog.ShowAsync(); return; } Exception error = null; ItemInfoResponse foundFile = null; Stream contentStream = null; ShowBusy(true); try { foundFile = await _service.GetItem(folder.Id, rpath); if (foundFile == null) { var dialog = new MessageDialog(traduce("MsgNoEncontrado") + rpath); await dialog.ShowAsync(); ShowBusy(false); return; } // Get the file's content contentStream = await _service.RefreshAndDownloadContent(foundFile, false); if (contentStream == null) { var dialog = new MessageDialog(traduce("MsgContenidoNoEncontrado") + rpath); await dialog.ShowAsync(); ShowBusy(false); return; } } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(traduce("MsgErrorGeneral") + " " + error.Message, traduce("NameApp")); await dialog.ShowAsync(); ShowBusy(false); return; } // Save the retrieved stream to the local drive IsolatedStorageFile isoFile; isoFile = IsolatedStorageFile.GetUserStoreForApplication(); // Open or create a writable file. using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(Path.Combine("", foundFile.Name), FileMode.OpenOrCreate, FileAccess.Write, isoFile)) { using (var writer = new BinaryWriter(isoStream)) { contentStream.Position = 0; using (var reader = new BinaryReader(contentStream)) { byte[] bytes; do { bytes = reader.ReadBytes(1024); writer.Write(bytes); }while (bytes.Length == 1024); } } } var successDialog = new MessageDialog(traduce("MsgRestauracionFin"), traduce("NameApp")); await successDialog.ShowAsync(); ShowBusy(false); }
private async void DownloadFile(string DownloadFilePathText) { if (string.IsNullOrEmpty(DownloadFilePathText)) { var dialog = new MessageDialog("Please enter a path to an existing file, for example MyNotes/Note1.txt", "Error!"); await dialog.ShowAsync(); return; } Exception error = null; ItemInfoResponse foundFile = null; Stream contentStream = null; ShowBusy(true); try { //T_ProgRestaura.Text = $"Downloading {_nNote} notes, please wait ..."; T_ProgRestaura.Text = traduce("MsgDescargando") + " " + _nNote + " " + traduce("MsgDescargando2Parte"); foundFile = await _service.GetItem(DownloadFilePathText); if (foundFile == null) { var dialog = new MessageDialog(traduce("MsgNoEncontrado") + " " + DownloadFilePathText); await dialog.ShowAsync(); ShowBusy(false); return; } // Get the file's content contentStream = await _service.RefreshAndDownloadContent(foundFile, false); if (contentStream == null) { var dialog = new MessageDialog(traduce("MsgContenidoNoEncontrado") + DownloadFilePathText); await dialog.ShowAsync(); ShowBusy(false); return; } } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(traduce("MsgErrorGeneral") + " " + error.Message, traduce("NameApp")); await dialog.ShowAsync(); ShowBusy(false); return; } // Save the retrieved stream to the local drive IsolatedStorageFile isoFile; isoFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!isoFile.DirectoryExists("MyNotes")) { isoFile.CreateDirectory("MyNotes"); } // Open or create a writable file. using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(Path.Combine("MyNotes", foundFile.Name), FileMode.OpenOrCreate, FileAccess.Write, isoFile)) { using (var writer = new BinaryWriter(isoStream)) { contentStream.Position = 0; using (var reader = new BinaryReader(contentStream)) { byte[] bytes; do { bytes = reader.ReadBytes(1024); writer.Write(bytes); }while (bytes.Length == 1024); } } } //var successDialog = new MessageDialog("Done saving the file!", "Success"); //await successDialog.ShowAsync(); CreaNotasDeArchivosTextoAlmacenamientoAislado(); // ShowBusy(false); }
private async void BrowseSubfolder(string FolderPathText) { if (string.IsNullOrEmpty(FolderPathText)) { var dialog = new MessageDialog("Please enter a path to a folder, for example Apps/My Notes", "Error!"); await dialog.ShowAsync(); return; } Exception error = null; ItemInfoResponse subfolder = null; ShowBusy(true); try { subfolder = await _service.GetItem(FolderPathText); } catch (Exception ex) { error = ex; } if (error != null) { var dialog = new MessageDialog(traduce("MsgErrorGeneral") + " " + error.Message, traduce("NameApp")); await dialog.ShowAsync(); ShowBusy(false); return; } if (subfolder == null) { var dialog = new MessageDialog(traduce("MsgNoEncontrado") + " " + FolderPathText); await dialog.ShowAsync(); } else { var children = await _service.PopulateChildren(subfolder); //DisplayHelper.ShowContent( // "SHOW SUBFOLDER CONTENT ------------------------", // subfolder, // children, // async message => // { // var dialog = new MessageDialog(message); // await dialog.ShowAsync(); // }); _numNotes = children.Count; T_Info.Text = _numNotes + " " + traduce("MsgCantNotasEncontradas"); foreach (var child in children) { _nNote += 1; DownloadFile("MyNotes/" + child.Name); } //ShowBusy(false); } }