private async void SignButton_Tap(object sender, GestureEventArgs e) { if (IsLoggedIn) { IsLoggedIn = false; LiveConnectHelper.Logout(); } else { PerformingAction = true; ActionTextBlock.Text = AppResources.SigningIn; IsLoggedIn = await LiveConnectHelper.LoginAsync(); if (IsLoggedIn) { ActionTextBlock.Text = AppResources.BackupDownloadingList; await RefreshBackupList(); } else { Toast.Show(AppResources.UnknownError, App.IconStyle("CloudUpload")); } PerformingAction = false; } }
private async void BackupMenuItem_Click(object sender, EventArgs eventArgs) { try { SyncIndicator.IsVisible = true; if (await LiveConnectHelper.SilentLoginAsync()) { string message; if (await BackupPage.Backup()) { message = AppResources.BackupOk; } else { message = AppResources.UnknownError; } Toast.Show(message, App.IconStyle("CloudUpload")); } else { Toast.Show(AppResources.SignedInNo, App.IconStyle("CloudUpload")); } } finally { SyncIndicator.IsVisible = false; } }
private async Task <BackupData> GetBackupData() { BackupData backupData = null; RestoreListPickerItem selectedItem = RestorePicker.SelectedItem as RestoreListPickerItem; if (selectedItem != null && selectedItem.Value1 != null) { // Stáhnutí souboru string data = await LiveConnectHelper.DownloadAsync(selectedItem.Value1.Id); if (data != null) { try { backupData = JsonConvert.DeserializeObject <BackupData>(data, new JsonSerializerSettings()); } catch { backupData = null; } } } return(backupData); }
public static async Task <bool> Backup(string fileName = null) { // Získání id složky string folderId = await LiveConnectHelper.SearchFolderIdAsync(BackupFolderName); if (folderId == null) { folderId = await LiveConnectHelper.CreateFolderAsync(LiveConnectHelper.Root, BackupFolderName); } // Nahrajeme soubor a získáme jeho id string fileId = null; if (folderId != null) { // Vytvoření dat BackupData backupData = new BackupData(); backupData.Version = App.VersionString; backupData.Created = DateTime.UtcNow; backupData.Settings = Settings.Current; backupData.Tasks = App.Tasks.Tasks; #if DEBUG Formatting formatting = Formatting.Indented; #else Formatting formatting = Formatting.None; #endif string json = JsonConvert.SerializeObject(backupData, formatting); // Nahrání fileName = string.Format("{0}{1}", fileName ?? DateTime.Now.ToFileName(), BackupFileExtension); fileId = await LiveConnectHelper.UploadAsync(folderId, fileName, json); } return(fileId != null); }
private async Task RefreshBackupList() { // Získání souborů List <OneDriveFileInfo> files = new List <OneDriveFileInfo>(); if (IsLoggedIn) { // Získání složky string folderId = await LiveConnectHelper.SearchFolderIdAsync(BackupFolderName); // Získání seznamu souborů se zálohami if (folderId != null) { files = await LiveConnectHelper.GetFilesInfoAsync(folderId, BackupFileExtension); } } // Vytvoření seznamu List <RestoreListPickerItem> list = new List <RestoreListPickerItem>(); foreach (OneDriveFileInfo fileInfo in files) { string fileName = fileInfo.Name.Replace(BackupFileExtension, ""); try { DateTime createdDate = DateTimeExtensions.FromFileName(fileName); list.Add(new RestoreListPickerItem(createdDate.ToString(), fileInfo, createdDate)); } catch (FormatException) { // Při parsování datumu, takže } } // Seřazení podle vytvoření list.Sort((f1, f2) => { return(f2.Value2.CompareTo(f1.Value2)); }); if (list.Count > _maxBackupsInList) { list.RemoveRange(_maxBackupsInList, list.Count - _maxBackupsInList); } // Naplnění pickeru if (list.Count > 0) { list[0].Label += string.Format(" ({0})", AppResources.BackupLatest); BackupList = new ObservableCollection <RestoreListPickerItem>(list); } else { BackupList.Clear(); BackupList.Add(new RestoreListPickerItem(AppResources.NoBackups, null, DateTime.MinValue)); } }
private void DoLogout() { if (_liveConnectHelper == null) { _liveConnectHelper = new LiveConnectHelper(); } _liveConnectHelper.DoLogout(Win32Wnd); UserSettings.Default.RefreshToken = null; UserSettings.Default.Save(); // Terminate app this.Close(); }
public static async Task SilentBackup(string fileName = null) { Debug.WriteLine("SilentBackup: start"); if (await LiveConnectHelper.SilentLoginAsync()) { Debug.WriteLine("SilentBackup: backup success: {0}", await Backup(fileName)); } else { Debug.WriteLine("SilentBackup: Not signed in"); } }
private void DoLogin() { //if (_liveConnectHelper == null) { _liveConnectHelper = new LiveConnectHelper(); { // Notify about Session changes... _liveConnectHelper.SessionChanged += delegate(string accessToken, string refreshToken) { Traces.Main_TraceEvent(TraceEventType.Information, 1, "Authenticated: Session changed! AccessToken: {0}, RefreshToken: {1}", accessToken, refreshToken); AccessToken = accessToken; RefreshToken = refreshToken; }; } } _liveConnectHelper.DoLogin(Win32Wnd); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.NavigationMode == NavigationMode.New || !e.IsNavigationInitiator) { IsLoggedIn = false; PerformingAction = true; ActionTextBlock.Text = AppResources.SigningIn; IsLoggedIn = await LiveConnectHelper.SilentLoginAsync(); ActionTextBlock.Text = AppResources.BackupDownloadingList; await RefreshBackupList(); PerformingAction = false; } }