private void UploadFile (string name) { try { using (var storage = IsolatedStorageFile.GetUserStoreForApplication ()) { var fileStream = storage.OpenFile (name + ".wav", FileMode.Open); var uploadClient = new LiveConnectClient (Utilities.SkyDriveSession); uploadClient.UploadCompleted += UploadClient_UploadCompleted; uploadClient.UploadAsync ("me/skydrive", name + ".wav", fileStream, OverwriteOption.Rename); _progressIndicatror = new ProgressIndicator { IsVisible = true, IsIndeterminate = true, Text = "Uploading file..." }; SystemTray.SetProgressIndicator (this, _progressIndicatror); } } catch (Exception) { ShowError (); NavigationService.GoBack (); } }
/// <summary> /// Upload a file to the server. /// </summary> /// <param name="client">the LiveConnectClient object this method is attached to.</param> /// <param name="path">relative or absolute uri to the location where the file should be uploaded to.</param> /// <param name="fileName">name for the uploaded file.</param> /// <param name="inputStream">Stream that contains the file content.</param> /// <param name="overwriteExisting">true to overwrite an existing file.</param> /// <param name="progress">a delegate that is called to report the upload progress.</param> public static Task <LiveOperationResult> Upload(this LiveConnectClient client, string path, string fileName, Stream inputStream, bool overwriteExisting, IProgress <LiveOperationProgress> progress) { client.UploadCompleted += OnOperationCompleted; var tcs = new TaskCompletionSource <LiveOperationResult>(); client.UploadAsync( path, fileName, overwriteExisting, inputStream, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Upload) { Progress = progress }); return(tcs.Task); }
private void signInButton_SessionChanged_1(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e) { if (e.Status != LiveConnectSessionStatus.Connected) return; manager.AllRoadMapsReceived += (o, eventAllRoadMaps) => { if (eventAllRoadMaps.RoadMaps.Count == 0) { Debug.WriteLine("Aucun rendez-vous n'existe pour les jours sélectionnés"); return; } try { //SaveTableur(); SpreadSheetRoadmapGenerator.GenerateXLS("feuilles-de-route.xlsx", eventAllRoadMaps.RoadMaps, 5.5f, 1.6f); if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected) { myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); fileStream = myIsolatedStorage.OpenFile("feuilles-de-route.xlsx", FileMode.Open, FileAccess.Read); reader = new StreamReader(fileStream); App.Session = e.Session; LiveConnectClient client = new LiveConnectClient(e.Session); client.UploadCompleted += client_UploadCompleted; client.UploadAsync("me/skydrive", "feuilles-de-route.xlsx", reader.BaseStream, OverwriteOption.Overwrite); } } catch (Exception exception) { Debug.WriteLine(exception.Message); } }; ReferenceMeeting start = new ReferenceMeeting(new DateTime(2013, 1, 2, 8, 30, 0), new Location() { Latitude = 48.85693, Longitude = 2.3412 }) { City = "Paris", Subject = "Start" }; ReferenceMeeting end = start; end.Subject = "End"; manager.GetAllRoadMapsAsync(new DateTime(2013, 1, 2), new DateTime(2013, 2, 10), start, end); }
public void uploadFile(string filename, System.IO.Stream file, string skydrivePath = "folder.559920a76be10760.559920A76BE10760!162") { LiveConnectClient client = new LiveConnectClient(App.Session); client.UploadAsync(skydrivePath, filename, file, OverwriteOption.Overwrite); client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(UploadCompleted); }
private async void romList_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { ROMDBEntry entry = this.romList.SelectedItem as ROMDBEntry; if (entry == null) { return; } if (this.uploading) { MessageBox.Show(AppResources.BackupWaitForUpload, AppResources.ErrorCaption, MessageBoxButton.OK); this.romList.SelectedItem = null; return; } var indicator = new ProgressIndicator() { IsIndeterminate = true, IsVisible = true, Text = String.Format(AppResources.BackupUploadProgressText, entry.DisplayName) }; SystemTray.SetProgressIndicator(this, indicator); this.uploading = true; try { LiveConnectClient client = new LiveConnectClient(this.session); String folderID = await this.CreateExportFolder(client); IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); bool errors = false; foreach (var savestate in entry.Savestates) { String path = FileHandler.ROM_DIRECTORY + "/" + FileHandler.SAVE_DIRECTORY + "/" + savestate.FileName; try { using (IsolatedStorageFileStream fs = iso.OpenFile(path, System.IO.FileMode.Open)) { await client.UploadAsync(folderID, savestate.FileName, fs, OverwriteOption.Overwrite); } } catch (FileNotFoundException) { errors = true; } catch (LiveConnectException ex) { MessageBox.Show(String.Format(AppResources.BackupErrorUpload, ex.Message), AppResources.ErrorCaption, MessageBoxButton.OK); errors = true; } } int index = entry.FileName.LastIndexOf('.'); int diff = entry.FileName.Length - 1 - index; String sramName = entry.FileName.Substring(0, entry.FileName.Length - diff) + "sav"; String sramPath = FileHandler.ROM_DIRECTORY + "/" + FileHandler.SAVE_DIRECTORY + "/" + sramName; try { if (iso.FileExists(sramPath)) { using (IsolatedStorageFileStream fs = iso.OpenFile(sramPath, FileMode.Open)) { await client.UploadAsync(folderID, sramName, fs, OverwriteOption.Overwrite); } } } catch (Exception) { errors = true; } if (errors) { MessageBox.Show(AppResources.BackupUploadUnsuccessful, AppResources.ErrorCaption, MessageBoxButton.OK); } else { MessageBox.Show(AppResources.BackupUploadSuccessful); } } catch (NullReferenceException) { MessageBox.Show(AppResources.CreateBackupFolderError, AppResources.ErrorCaption, MessageBoxButton.OK); } catch (LiveConnectException) { MessageBox.Show(AppResources.CreateBackupFolderError, AppResources.ErrorCaption, MessageBoxButton.OK); } finally { SystemTray.GetProgressIndicator(this).IsVisible = false; this.uploading = false; } }
/// <summary> /// Appel une fois que l'utilisateur est connecté à Skydrive /// Génère et Upload le fichier XLS /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void auth_LoginCompleted(object sender, LoginCompletedEventArgs e) { if (!App.IsConnected()) { MessageBox.Show("Vous n'êtes pas connecté à internet"); return; } try { List<RoadMap> _roadmaps = new List<RoadMap>(); _roadmaps.Add(this.myRoadM); string filename = "rapport-planmyway-" + myRoadM.Date.ToShortDateString().Replace("/", "-") + ".xlsx"; Debug.WriteLine(filename); //SaveTableur(); SpreadSheetRoadmapGenerator.GenerateXLS(filename, _roadmaps, (double)settings["ConsoCarburant"], (double)settings["PrixCarburant"]); if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected) { myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); fileStream = myIsolatedStorage.OpenFile(filename, FileMode.Open, FileAccess.Read); reader = new StreamReader(fileStream); App.Session = e.Session; LiveConnectClient client = new LiveConnectClient(e.Session); client.UploadCompleted += client_UploadCompleted; client.UploadAsync("me/skydrive", filename, reader.BaseStream, OverwriteOption.Overwrite); } } catch (Exception exception) { Debug.WriteLine(exception.Message); MessageBox.Show(exception.Message); //this.enableInterface(); } }
void task_Completed(object sender, PhotoResult e) { if (e.ChosenPhoto == null) return; LiveConnectClient uploadClient = new LiveConnectClient(App.Session); uploadClient.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(uploadClient_UploadCompleted); uploadClient.UploadAsync(SelectedAlbum.ID, "Image"+DateTime.Now.Millisecond+".jpg", e.ChosenPhoto); }
private async void BackupFilesAndUpload(string _backupFileName) { if (_backupFileName == null) throw new ArgumentNullException("_backupFileName"); // // string filename = _backupFileName; //byte[] b = new byte[0x16] {0x50,0x4b,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; var b = new byte[0x16]; b[0] = 0x50; b[1] = 0x4b; b[2] = 0x05; b[4] = 0x06; using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream f = store.OpenFile(filename, FileMode.Create)) { f.Write(b, 0, b.Length); } } using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = new IsolatedStorageFileStream(filename, FileMode.Create, store)) { var zz = new ZipOutputStream(file); foreach (string f in store.GetFileNames()) { if (f.Equals(filename)) continue; var ze = new ZipEntry(f); zz.PutNextEntry(ze); using (IsolatedStorageFileStream ss = store.OpenFile(f, FileMode.Open)) { var bytes = new byte[100]; int x = ss.Read(bytes, 0, 100); while (x > 0) { zz.Write(bytes, 0, x); bytes = new byte[100]; x = ss.Read(bytes, 0, 100); } } } zz.Finish(); } try { pbProgress.Value = 0; bBackup.IsEnabled = false; bRestore.IsEnabled = false; var progressHandler = new Progress<LiveOperationProgress>( (e) => { pbProgress.Value = e.ProgressPercentage; pbProgress.Visibility = Visibility.Visible; lblLastBackup.Text = string.Format( StringResources .BackupAndRestorePage_Messages_Progress, e.BytesTransferred, e.TotalBytes); }); _ctsUpload = new CancellationTokenSource(); _client = new LiveConnectClient(App.LiveSession); using ( var file = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, IsolatedStorageFile.GetUserStoreForApplication())) { await _client.UploadAsync("me/skydrive", filename, file, OverwriteOption.Overwrite, _ctsUpload.Token, progressHandler); } pbProgress.Visibility = Visibility.Collapsed; } catch (TaskCanceledException) { App.ToastMe("Upload Cancelled"); } catch (LiveConnectException ee) { lblLastBackup.Text = string.Format("Error uploading File:{0}", ee.Message); } finally { bBackup.IsEnabled = true; bRestore.IsEnabled = true; lblLastBackup.Text = DateTime.Now.ToString("MM/dd/yyyy"); } } }
/// <summary> /// uplaods a picture to sky drive. /// </summary> /// <param name="e"></param> private async void UploadPicture(PhotoResult e) { LiveConnectClient uploadClient = new LiveConnectClient(App.Session); if (e.OriginalFileName == null) { return; } // file name is the current datetime stapm string ext = e.OriginalFileName.Substring(e.OriginalFileName.LastIndexOf('.')); DateTime dt = DateTime.Now; string fileName = String.Format("{0:d_MM_yyy_HH_mm_ss}", dt); fileName = fileName + ext; string progMsgUpPic = SkyPhoto.Resources.Resources.progMsgUpPic; ShowProgressBar(progMsgUpPic); try { LiveOperationResult result = await uploadClient.UploadAsync(App.CurrentAlbum.ID, fileName, e.ChosenPhoto, OverwriteOption.Overwrite); ISFile_UploadCompleted(result); } catch (Exception) { string upFaild = SkyPhoto.Resources.Resources.upFaild; MessageBox.Show(upFaild); HideProgressBar(); } }
private void ApplicationBarIconButton_Done_Click(object sender, EventArgs e) { this.progressIndicator = new ProgressIndicator(); ProgressIndicatorHelper.showProgressIndicator("Saving...", this, this.progressIndicator); string fileName = this.filenameInput.Text.Trim(); byte[] byteArray = Encoding.UTF8.GetBytes(this.contentInput.Text.Trim()); MemoryStream fileStream = new MemoryStream(byteArray); LiveConnectClient uploadClient = new LiveConnectClient(App.Current.LiveSession); uploadClient.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(uploadClient_UploadCompleted); uploadClient.UploadAsync(this.folderPath, fileName, true, fileStream, null); }
private async Task<bool> ExportToSkyDrive(string filename) { Exception exception = null; ApplicationBar.IsVisible = false; SystemTray.ProgressIndicator.IsVisible = true; SystemTray.ProgressIndicator.Text = "Exporting data to SkyDrive"; this.IsEnabled = false; this.Opacity = 0.25; try { LiveConnectSession session = await this.InitializeSkyDrive(); LiveConnectClient client = new LiveConnectClient(session); using (MemoryStream stream = new MemoryStream()) using (TextWriter writer = new StreamWriter(stream)) using (CsvWriter csvWriter = new CsvWriter(writer)) { var entries = from geocoordinate in App.MainViewModel.Geocoordinates join obdUpdate in App.MainViewModel.MapObdUpdates on geocoordinate.GeoCoordinate equals obdUpdate.GeoCoordinate into all from obd in all.DefaultIfEmpty() select (obd == null ? new ObdModel() { GeoCoordinate = geocoordinate.GeoCoordinate, When = geocoordinate.Timestamp } : obd); var csv = from obd in entries orderby obd.When select new { Latitude = obd.Latitude, Longitude = obd.Longitude, Elevation = obd.Elevation, Ascent = obd.Ascent, Descent = obd.Descent, Speed = obd.MilesPerHour, Distance = obd.Distance, SoC = obd.SoC, Capacity = obd.Capacity, RawCapacity = obd.RawCapacity, UsableKiloWattHours = obd.UsableKiloWattHours, AvailableKiloWattHours = obd.AvailableKiloWattHours, KiloWattHoursUsed = obd.KiloWattHoursUsed, AverageEnergyEconomy = obd.AverageEnergyEconomy, Range = obd.Range, Timestamp = obd.When, Temperature1 = obd.Temperature1, Temperature2 = obd.Temperature2, Temperature3 = obd.Temperature3, Temperature4 = obd.Temperature4 }; csvWriter.WriteRecords(csv); writer.Flush(); stream.Flush(); stream.Position = 0; LiveOperationResult result = await client.UploadAsync("me/skydrive", filename, stream, OverwriteOption.Rename); } } catch (Exception ex) { exception = ex; } finally { ApplicationBar.IsVisible = true; SystemTray.ProgressIndicator.IsVisible = false; SystemTray.ProgressIndicator.Text = string.Empty; this.IsEnabled = true; this.Opacity = 1; if (exception != null) { MessageBox.Show("Unable to export to SkyDrive\n" + exception.Message, "Error", MessageBoxButton.OK); } } return exception == null; }
public static async Task<string> upload(string filename) { string res = ""; //diagLog("Uploading " + file); try { string[] requiredScope = { "wl.offline_access", "wl.skydrive_update" }; LiveAuthClient auth = new LiveAuthClient(Secrets.ClientID); await auth.InitializeAsync(requiredScope); if (auth.Session == null) { await auth.LoginAsync(requiredScope); } LiveConnectClient liveClient = new LiveConnectClient(auth.Session); string folderid = await GetSkyDriveFolderID(FOLDER, liveClient); if (folderid == null) { folderid = await createSkyDriveFolder(FOLDER, liveClient); res = "Created folder: " + FOLDER + "\n"; // , "ID:", folderid); } var store = IsolatedStorageFile.GetUserStoreForApplication(); if (store.FileExists(filename)) { var file = store.OpenFile(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); LiveOperationResult operationResult = await liveClient.UploadAsync(folderid, filename, file, OverwriteOption.Overwrite); dynamic result = operationResult.Result; res += "Uploaded :" + result.name; //, "ID:", result.id); } else throw new Exception("file does not exist"); } catch (Exception exception) { res = "Error uploading file: " + exception.Message; } return res; }
void client_GetCompleted(object sender, LiveOperationCompletedEventArgs e) { try { if (e.Result.ContainsKey("available")) { Int64 available = Convert.ToInt64(e.Result["available"]); byte[] data = RecordManager.GetRecordByteArray(MainPageViewModel.Instance.CurrentlyUploading); if (available >= data.Length) { MemoryStream stream = new MemoryStream(data); client = new LiveConnectClient(App.MicrosoftAccountSession); client.UploadCompleted += MicrosoftAccountClient_UploadCompleted; client.UploadProgressChanged += MicrosoftAccountClient_UploadProgressChanged; client.UploadAsync("me/skydrive", MainPageViewModel.Instance.CurrentlyUploading, stream, OverwriteOption.Overwrite); grdUpload.Visibility = System.Windows.Visibility.Visible; ApplicationBar.IsVisible = false; } else { MessageBox.Show("Looks like you don't have enough space on your SkyDrive. Go to http://skydrive.com and either purchase more space or clean up the existing storage.", "Upload", MessageBoxButton.OK); } } } catch { FailureAlert(); } }
public static async void Upload( MainPage MainPage, LiveConnectSession Session, string filename ) { if ( UploadStream != null ) { return; }; if ( Storage.FileExists( filename + ".gpx" ) ) { UploadStream = Storage.OpenFile( filename + ".gpx", System.IO.FileMode.Open ); } else { UploadStream = Storage.OpenFile( filename + ".incomplete", System.IO.FileMode.Open ); } LiveConnectClient client = new LiveConnectClient( Session ); var progressHandler = new Progress<LiveOperationProgress>( ( progress ) => { MainPage.TransferStatus( progress.ProgressPercentage ); } ); LiveOperationResult x = await client.UploadAsync( "me/skydrive/", filename + ".gpx", UploadStream, OverwriteOption.Overwrite, CancellationToken.None, progressHandler ); MainPage.TransferStatus( 0 ); MainPage.Uploads.Clear(); UploadStream.Close(); UploadStream = null; }
private void UploadFile() { //Creating byte array from 'fileBody' string byte[] byteArray = Encoding.Unicode.GetBytes(fileBody); MemoryStream fileStream = new MemoryStream(byteArray); //Set SystemTray.ProgressIndicator ProgressIndicator prog = new ProgressIndicator(); prog.IsIndeterminate = true; prog.IsVisible = true; prog.Text = "File uploading..."; SystemTray.SetProgressIndicator(this, prog); //Uploading the file to SkyDrive storage LiveConnectClient uploadClient = new LiveConnectClient(LiveSession); uploadClient.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(uploadClient_UploadCompleted); uploadClient.UploadAsync(folder_id, fileName + ".txt", fileStream); }
void auth_LoginCompleted(object sender, LoginCompletedEventArgs e) { try { IsolatedStorageFile myIsolatedStorage; IsolatedStorageFileStream fileStream; StreamReader reader; //SaveTableur(); SpreadSheetRoadmapGenerator.GenerateXLS("feuilles-de-route.xlsx", _roadmaps, 5.5f, 1.6f); if (e.Session != null && e.Status == LiveConnectSessionStatus.Connected) { myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); fileStream = myIsolatedStorage.OpenFile("feuilles-de-route.xlsx", FileMode.Open, FileAccess.Read); reader = new StreamReader(fileStream); App.Session = e.Session; LiveConnectClient client = new LiveConnectClient(e.Session); client.UploadCompleted += client_UploadCompleted; client.UploadAsync("me/skydrive", "feuilles-de-route.xlsx", reader.BaseStream, OverwriteOption.Overwrite); //myIsolatedStorage.Dispose(); //fileStream.Dispose(); //reader.Dispose(); } } catch (Exception exception) { Debug.WriteLine(exception.Message); } }