private async Task GetFiles(SkyDriveFolder folder, int depth) { //at this point we don't have folder contents. We need to make calls to get folder contents: SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); try { folder = await source.GetGroups(folder.UniqueId, false, true); }catch (Exception ex) { string exp = ex.ToString(); } //list of files in a folder foreach (SkyDriveFile file in folder.Items) { //add to shared link collection sharedLinkCollection.Add(new SharedLinkData(file.Title, file.URL, file.ImagePath, depth + 1)); } foreach (SkyDriveFolder subFolder in folder.Subalbums) { sharedLinkCollection.Add(new SharedLinkData(subFolder.Title, string.Empty, localImage, depth)); await GetFiles(subFolder, depth + 1); } }
//recursively populate data from source private async Task FetchData(SkyDriveFolder folder) { //at this point we don't have folder contents. We need to make calls to get folder contents: SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); Task <SkyDriveFolder> [] asyncOps = (from item in folder.Subalbums select source.GetGroups(item.UniqueId)).ToArray(); try { SkyDriveFolder[] folders = await Task.WhenAll(asyncOps); foreach (var fldr in folders) { FolderCollection[fldr.UniqueId] = fldr; } //folder.Subalbums = new ObservableCollection<SkyDriveFolder>(folders); for (int i = 0; i < folder.Subalbums.Count; i++) { await FetchData(folder.Subalbums[i]); } } catch (Exception exc) { foreach (Task <SkyDriveFolder> faulted in asyncOps.Where(t => t.IsFaulted)) { // work with faulted and faulted.Exception throw faulted.Exception; //faulted.Start(); //faulted.Result } } }
private async void PopupCreateFolder_Click(object sender, RoutedEventArgs e) { this.CreateFolderPopUP.IsOpen = false; //this.BottomAppBar.IsOpen = false; this.ProgressBar.Visibility = System.Windows.Visibility.Visible; var source = await SkyDriveDataSource.GetInstance(); if (this.CreateFolderName.Text.Trim() != string.Empty) { var skFolder = source.CurrentFolder.Subalbums.FirstOrDefault(sf => sf.Title.ToLower() == this.CreateFolderName.Text.Trim().ToLower()); if (object.Equals(skFolder, null)) { SkyDriveFolder folder = new SkyDriveFolder(this.CreateFolderName.Text.Trim()); folder.Parent_id = source.CurrentFolder.UniqueId; folder.UniqueId = await source.CreateFolder(folder); source.CurrentFolder.Subalbums.Add(folder); } this.CreateFolderName.Text = string.Empty; } await UIRefreshWithoutFetch(); this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed; //mySearchBox.FocusOnKeyboardInput = true; }
private async void ListItemSelected(object sender, ItemClickEventArgs e) { this.DefaultViewModel["Sharing"] = true; SemListView.ItemsSource = null; this.DefaultViewModel["FolderName"] = ((SkyDriveFolder)e.ClickedItem).Title; SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); itemSelected = await source.GetGroups(((SkyDriveFolder)e.ClickedItem).UniqueId, true); SemListView.ItemsSource = itemSelected.AllItems; FolderStack.Add(itemSelected); this.DefaultViewModel["Sharing"] = false; //this.DefaultViewModel["Sharing"] = true; //SemListView.ItemsSource = null; //itemSelected = ((SkyDriveFolder)e.ClickedItem); //this.DefaultViewModel["FolderName"] = itemSelected.Title; //FolderStack.Add(itemSelected); //if (itemSelected.Subalbums.Count == 0) //{ // SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); // var sampleDataGroups = await source.GetGroups(itemSelected.UniqueId, true); // SemListView.ItemsSource = sampleDataGroups.AllItems; //} //this.DefaultViewModel["Sharing"] = false; }
static void DisplayFolder(SkyDriveFolder folder) { Console.WriteLine("{0}/ - {1} children", folder.FullName, folder.Count); foreach(var subfolder in folder.GetFolders()) DisplayFolder(subfolder); foreach(var file in folder.GetFiles()) Console.WriteLine("{0} - {1} bytes", file.FullName, file.Length); }
private SkyDriveFolder CreateSkyDriveFolderFromJson(FavoritesFolder folder) { var skyFolder = new SkyDriveFolder(folder.UniqueId, folder.Title, folder.Description, folder.Size, folder.Parent_id, SkyDriveItemType.Folder, folder.Updated_time, folder.Count); skyFolder.ImagePath = folder.ImagePath; skyFolder.SyncState = folder.SyncState; return(skyFolder); }
private async void ListItemSelected(object sender, ItemClickEventArgs e) { itemSelected = ((SkyDriveFolder)e.ClickedItem); Selection.Text = itemSelected.Title; SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); var sampleDataGroups = await source.GetGroups(itemSelected.UniqueId, true); SemListView.ItemsSource = sampleDataGroups.AllItems; }
public override async Task <ICloudFolder> GetRootDirectoryAsync() { dynamic result = await _liveClient.GetAsync(RootDirectory); dynamic childrenResult = await _liveClient.GetAsync(RootDirectory + "/files"); ICloudFolder cloudObject = new SkyDriveFolder(null, result.Result, childrenResult.Result.data); return(cloudObject); }
public override async Task CreateDataStore() { if (this.location == DocumentLocation.Local) { var rootFavoritesFolder = new SkyDriveFolder(constants.bookmark); FolderCollection.Add(rootFavoritesFolder.UniqueId, rootFavoritesFolder); } else { await this.GetFavoritesFromServer(); } }
public async Task LoadFolder() { var source = await FavoritesDataSyncManager.GetInstance(DocumentLocation.Roaming); var sampleDataGroups = await source.GetRoot(); FolderStack.Add(sampleDataGroups); itemSelected = sampleDataGroups; this.FolderName.Text = itemSelected.Title; SemListView.ItemsSource = sampleDataGroups.Subalbums; Sharing = false; }
public async Task LoadFolder() { SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); var sampleDataGroups = await source.GetGroups(source.Root, true); FolderStack.Add(sampleDataGroups); itemSelected = sampleDataGroups; this.FolderName.Text = itemSelected.Title; SemListView.ItemsSource = sampleDataGroups.AllItems; Sharing = false; }
public async Task <string> AddFolder(SkyDriveFolder folder) { var source = await SkyDriveDataSource.GetInstance(); folder.UniqueId = await source.CreateFolder(folder); FolderCollection.Add(folder.UniqueId, folder); FolderCollection[folder.Parent_id].Subalbums.Add((SkyDriveFolder)folder); await RecursivelyUpdateParent(folder); return(folder.UniqueId); }
private async void ListItemSelected(object sender, ItemClickEventArgs e) { Sharing = true; SemListView.ItemsSource = null; this.FolderName.Text = ((SkyDriveFolder)e.ClickedItem).Title; var source = await FavoritesDataSyncManager.GetInstance(DocumentLocation.Roaming); itemSelected = await source.GetCollection(((SkyDriveFolder)e.ClickedItem).UniqueId); SemListView.ItemsSource = itemSelected.Subalbums; FolderStack.Add(itemSelected); Sharing = false; }
private void CopySkyDriveFolderToJson(SkyDriveFolder source, FavoritesFolder destination) { destination.Title = source.Title; destination.UniqueId = source.UniqueId; destination.Updated_time = source.Updated_time; destination.Size = source.Size; destination.Count = source.Count; destination.ImagePath = source.ImagePath; destination.Parent_id = source.Parent_id; destination.Description = source.Description; destination.ImageDominantColor = source.ImageDominantColor.ToString(); destination.SyncState = source.SyncState; }
/// <summary> /// Invoked when another application wants to share content through this application. /// </summary> /// <param name="args">Activation data used to coordinate the process with Windows.</param> public async void Activate(ShareTargetActivatedEventArgs args) { this._shareOperation = args.ShareOperation; if (this._shareOperation.Data.Contains(StandardDataFormats.Uri)) { Uri uri = await this._shareOperation.Data.GetUriAsync(); if (uri != null) { // To output text from this example, you need a TextBlock control // with a name of "contentValue". this.url = uri.AbsoluteUri; } } // Communicate metadata about the shared content through the view model var shareProperties = this._shareOperation.Data.Properties; var thumbnailImage = new BitmapImage(); this.DefaultViewModel["Title"] = this.title = shareProperties.Title; this.DefaultViewModel["Description"] = this.url;// = shareProperties.Description; this.DefaultViewModel["Image"] = thumbnailImage; this.DefaultViewModel["Sharing"] = true; this.DefaultViewModel["ShowImage"] = false; this.DefaultViewModel["Comment"] = String.Empty; this.DefaultViewModel["SupportsComment"] = true; Window.Current.Content = this; Window.Current.Activate(); SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); // itemSelected = await source.GetFolder(source.Root); var sampleDataGroups = await source.GetGroups(source.Root, true); FolderStack.Add(sampleDataGroups); itemSelected = sampleDataGroups; this.DefaultViewModel["FolderName"] = itemSelected.Title; SemListView.ItemsSource = sampleDataGroups.AllItems; this.DefaultViewModel["Sharing"] = false; // Update the shared content's thumbnail image in the background if (shareProperties.Thumbnail != null) { var stream = await shareProperties.Thumbnail.OpenReadAsync(); thumbnailImage.SetSource(stream); this.DefaultViewModel["ShowImage"] = true; } }
public override async Task Sync() { SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); SkyDriveFolder folderAtSource = await source.GetFolder(source.Root); var isDataChanged = await Sync(source.Root, FolderCollection[source.Root].Updated_time, folderAtSource); if (isDataChanged) { var cachedFolder = FolderCollection[source.Root]; cachedFolder.Title = folderAtSource.Title; cachedFolder.Updated_time = folderAtSource.Updated_time; cachedFolder.Count = folderAtSource.Count; cachedFolder.Size = folderAtSource.Size; } }
private async void ListItemSelected(object sender, System.Windows.Input.GestureEventArgs e) { Sharing = true; try { this.FolderName.Text = ((SkyDriveFolder)((ListBox)sender).SelectedItem).Title; } catch { return; }; //SemListView.ItemsSource = null; SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); itemSelected = await source.GetGroups(((SkyDriveFolder)((ListBox)sender).SelectedItem).UniqueId, true); SemListView.ItemsSource = itemSelected.AllItems; FolderStack.Add(itemSelected); Sharing = false; }
private async void FolderUp(object sender, RoutedEventArgs e) { SemListView.ItemsSource = null; //this.mainProgressBar.Visibility = Windows.UI.Xaml.Visibility.Visible; SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); // Use the navigation frame to return to the previous page if (FolderStack.Count > 1) { this.DefaultViewModel["Sharing"] = true; SemListView.ItemsSource = FolderStack[FolderStack.Count - 2].AllItems; itemSelected = FolderStack[FolderStack.Count - 2]; FolderStack.RemoveAt(FolderStack.Count - 1); this.DefaultViewModel["FolderName"] = itemSelected.Title; this.DefaultViewModel["Sharing"] = false; } if (FolderStack.Count == 1) { SemListView.ItemsSource = FolderStack[0].AllItems; itemSelected = FolderStack[0]; this.DefaultViewModel["FolderName"] = itemSelected.Title; } //SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); //// Use the navigation frame to return to the previous page //if (FolderStack.Count > 1) //{ // this.DefaultViewModel["Sharing"] = true; // SemListView.ItemsSource = null; // var matches = await source.GetGroups((FolderStack[FolderStack.Count - 2]).UniqueId, true); // itemSelected = FolderStack[FolderStack.Count - 2]; // this.DefaultViewModel["FolderName"] = itemSelected.Title; // SemListView.ItemsSource = matches.AllItems; // FolderStack.RemoveAt(FolderStack.Count - 1); // this.DefaultViewModel["Sharing"] = false; //} //if (FolderStack.Count == 1) //{ // var sampleDataGroups = await source.GetGroups(source.Root, true); // //var matches = sampleDataGroups.Where((item) => item.ParentID.Equals(string.Empty)); // SemListView.ItemsSource = sampleDataGroups.AllItems; //} // FolderBack.IsEnabled = CanGoBack; }
private async Task <SkyDriveDataCommon> UpdateItem(SkyDriveDataCommon item) { var updatedItem = await GetUpdatedMetadata(item); if (updatedItem != null) { if (item.Type == SkyDriveItemType.File) { //file var file = FolderCollection[item.Parent_id].Items.FirstOrDefault(a => a.UniqueId == item.UniqueId); if (file != null) { //update file information from server file.Size = updatedItem.Size; file.Updated_time = updatedItem.Updated_time; file.Parent_id = updatedItem.Parent_id; file.Description = updatedItem.Description; //update parent await RecursivelyUpdateParent(FolderCollection[updatedItem.Parent_id]); } } else { //folder var cachedFolder = FolderCollection[item.UniqueId]; var cachedFolderParent = FolderCollection[item.Parent_id]; SkyDriveFolder folderToUpdate = cachedFolderParent.Subalbums.FirstOrDefault(a => a.UniqueId == item.UniqueId); if (folderToUpdate != null) { int index = cachedFolderParent.Subalbums.IndexOf(folderToUpdate); cachedFolderParent.Subalbums.RemoveAt(index); cachedFolderParent.Subalbums.Insert(index, (SkyDriveFolder)updatedItem); } cachedFolder.Title = updatedItem.Title; cachedFolder.Updated_time = updatedItem.Updated_time; cachedFolder.Count = ((SkyDriveFolder)updatedItem).Count; cachedFolder.Size = ((SkyDriveFolder)updatedItem).Size; cachedFolder.Parent_id = updatedItem.Parent_id; } } return(updatedItem); }
public async Task <bool> MoveItem(IList <SkyDriveDataCommon> items, SkyDriveFolder destination) { var source = await SkyDriveDataSource.GetInstance(); bool result = false; string parentid = items[0].Parent_id; foreach (var item in items) { result = await source.MoveItem(item.UniqueId, destination.UniqueId); if (result) { // remove moved items from present view // and add them to destination. this addition will not work until we append all results/data to root skydrivefolder switch (item.Type) { case SkyDriveItemType.Folder: FolderCollection[item.Parent_id].Subalbums.Remove((SkyDriveFolder)item); FolderCollection[item.UniqueId].Parent_id = destination.UniqueId; item.Parent_id = destination.UniqueId; FolderCollection[destination.UniqueId].Subalbums.Add((SkyDriveFolder)item); //destination.Subalbums.Add((SkyDriveFolder)item); break; case SkyDriveItemType.File: FolderCollection[item.Parent_id].Items.Remove((SkyDriveFile)item); item.Parent_id = destination.UniqueId; FolderCollection[destination.UniqueId].Items.Add((SkyDriveFile)item); break; } await UpdateItem(item); } } // update tree of source folder await RecursivelyUpdateParent(FolderCollection[parentid]); // update tree of destination folder await RecursivelyUpdateParent(destination); return(result); }
private void PopulateJsonFromRootFavoritesFolder(SkyDriveFolder skyFolder, FavoritesFolder folder) { folder.Subalbums = new List <FavoritesFolder>(skyFolder.Subalbums.Count); folder.Items = new List <FavoritesFile>(skyFolder.Items.Count); foreach (var item in skyFolder.Items) { var favFile = new FavoritesFile(); CopySkyDriveFileToJson(item, favFile); folder.Items.Add(favFile); } foreach (var item in skyFolder.Subalbums) { var favFolder = new FavoritesFolder(); SkyDriveFolder itemfolder; if (FolderCollection.TryGetValue(item.UniqueId, out itemfolder)) { CopySkyDriveFolderToJson(itemfolder, favFolder); folder.Subalbums.Add(favFolder); PopulateJsonFromRootFavoritesFolder(itemfolder, favFolder); } } }
private async void FolderUp(object sender, RoutedEventArgs e) { SemListView.ItemsSource = null; //this.mainProgressBar.Visibility = Windows.UI.Xaml.Visibility.Visible; SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); // Use the navigation frame to return to the previous page if (FolderStack.Count > 1) { //Sharing = true; Sharing = true; SemListView.ItemsSource = FolderStack[FolderStack.Count - 2].Subalbums; itemSelected = FolderStack[FolderStack.Count - 2]; FolderStack.RemoveAt(FolderStack.Count - 1); this.FolderName.Text = itemSelected.Title; Sharing = false; } if (FolderStack.Count == 1) { SemListView.ItemsSource = FolderStack[0].Subalbums; itemSelected = FolderStack[0]; this.FolderName.Text = itemSelected.Title; } }
private async Task<IEnumerable<CatalogItemModel>> ReadAsync(string path) { List<CatalogItemModel> items = null; try { if (_skyDrive == null) _skyDrive = await _liveLogin.Login(); if (_skyDrive == null) { throw new CatalogAuthorizationException(CatalogType.SkyDrive, path); } ChangeAccessToCatalog(); _cancelSource = new CancellationTokenSource(); var e = await _skyDrive.GetAsync(path, _cancelSource.Token); var skyDriveItems = new List<SkyDriveItem>(); var data = (List<object>) e.Result["data"]; foreach (IDictionary<string, object> content in data) { var type = (string) content["type"]; SkyDriveItem item; if (type == "folder") { item = new SkyDriveFolder { Id = (string) content["id"], Name = (string) content["name"] }; } else if (type == "file") { var name = (string) content["name"]; if (string.IsNullOrEmpty(_downloadController.GetBookType(name))) continue; item = new SkyDriveFile { Id = (string) content["id"], Name = name }; } else { continue; } skyDriveItems.Add(item); } var folders = skyDriveItems .OfType<SkyDriveFolder>() .Select(i => new CatalogItemModel { Title = i.Name, OpdsUrl = i.Id }); var files = skyDriveItems .OfType<SkyDriveFile>() .Select(file => new CatalogBookItemModel { Title = file.Name, OpdsUrl = file.Id, Links = new List<BookDownloadLinkModel> { new BookDownloadLinkModel { Url = file.Id, Type = file.Name } }, Id = file.Id }); items = Enumerable.Union(folders, files).ToList(); } catch (OperationCanceledException) { } catch (LiveAuthException e) { if (e.ErrorCode == "access_denied") { throw new CatalogAuthorizationException(e.Message, e, CatalogType.SkyDrive); } throw new ReadCatalogException(e.Message, e); } catch (Exception e) { throw new ReadCatalogException(e.Message, e); } return items ?? new List<CatalogItemModel>(); }
public async Task <SkyDriveFolder> GetCollection(SkyDriveFolder folder) { return(await GetCollection(folder.UniqueId)); }
void OnFolderSelectedEvent(SkyDriveFolder e) { FolderSelectedEvent(this, e); }
private async void FolderSelected_Click(object sender, SkyDriveFolder e) { SkyDriveFolder destination = null; if (e != null) { //move items destination = e; this.SelectDestinationPopup.IsOpen = false; this.ProgressBar.Visibility = System.Windows.Visibility.Visible; var source = await SkyDriveDataSource.GetInstance(); foreach (SkyDriveDataCommon item in selectedItems) { try { await source.MoveItem(item.UniqueId, destination.UniqueId); // remove moved items from present view // and add them to destination. this addition will not work until we append all results/data to root skydrivefolder switch (item.Type) { case SkyDriveItemType.Folder: source.CurrentFolder.Subalbums.Remove((SkyDriveFolder)item); destination.Subalbums.Add((SkyDriveFolder)item); break; case SkyDriveItemType.File: source.CurrentFolder.Items.Remove((SkyDriveFile)item); destination.Items.Add((SkyDriveFile)item); break; } //fallback until we do item 2 mentioned in above comment // check if destination is in our back list. if it exists then add moved items to destination foreach (SkyDriveFolder folder in App.FolderStack) { if (folder.UniqueId == destination.UniqueId) { switch (item.Type) { case SkyDriveItemType.Folder: folder.Subalbums.Add((SkyDriveFolder)item); break; case SkyDriveItemType.File: folder.Items.Add((SkyDriveFile)item); break; } break; } foreach (SkyDriveFolder skItem in folder.Subalbums) { if (skItem.UniqueId == destination.UniqueId) { switch (item.Type) { case SkyDriveItemType.Folder: skItem.Subalbums.Add((SkyDriveFolder)item); break; case SkyDriveItemType.File: skItem.Items.Add((SkyDriveFile)item); break; } break; } } } } catch (Exception) { // ignore any exception becuase of wrong destination folder selection by user //throw ex; } } await UIRefreshWithoutFetch(); this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed; } }
private void SelectFolderUserCntl_CancelEvent(object sender, SkyDriveFolder e) { this.SelectDestinationPopup.IsOpen = false; }
private async Task <IEnumerable <CatalogItemModel> > ReadAsync(string path) { List <CatalogItemModel> items = null; try { if (_skyDrive == null) { _skyDrive = await _liveLogin.Login(); } if (_skyDrive == null) { throw new CatalogAuthorizationException(CatalogType.SkyDrive, path); } ChangeAccessToCatalog(); _cancelSource = new CancellationTokenSource(); var e = await _skyDrive.GetAsync(path, _cancelSource.Token); var skyDriveItems = new List <SkyDriveItem>(); var data = (List <object>)e.Result["data"]; foreach (IDictionary <string, object> content in data) { var type = (string)content["type"]; SkyDriveItem item; if (type == "folder") { item = new SkyDriveFolder { Id = (string)content["id"], Name = (string)content["name"] }; } else if (type == "file") { var name = (string)content["name"]; if (string.IsNullOrEmpty(_downloadController.GetBookType(name))) { continue; } item = new SkyDriveFile { Id = (string)content["id"], Name = name }; } else { continue; } skyDriveItems.Add(item); } var folders = skyDriveItems .OfType <SkyDriveFolder>() .Select(i => new CatalogItemModel { Title = i.Name, OpdsUrl = i.Id }); var files = skyDriveItems .OfType <SkyDriveFile>() .Select(file => new CatalogBookItemModel { Title = file.Name, OpdsUrl = file.Id, Links = new List <BookDownloadLinkModel> { new BookDownloadLinkModel { Url = file.Id, Type = file.Name } }, Id = file.Id }); items = Enumerable.Union(folders, files).ToList(); } catch (OperationCanceledException) { } catch (LiveAuthException e) { if (e.ErrorCode == "access_denied") { throw new CatalogAuthorizationException(e.Message, e, CatalogType.SkyDrive); } throw new ReadCatalogException(e.Message, e); } catch (Exception e) { throw new ReadCatalogException(e.Message, e); } return(items ?? new List <CatalogItemModel>()); }
private async Task <bool> Sync(string folderId, string updated_time, SkyDriveFolder folderAtServer) { bool dataChanaged = false; //case 1 SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); SkyDriveFolder folderAtSource = folderAtServer; if (folderAtSource == null) { folderAtSource = await source.GetFolder(folderId); } if ((updated_time == folderAtSource.Updated_time) && (FolderCollection[folderId].Items.Count + FolderCollection[folderId].Subalbums.Count + FolderCollection[folderId].OtherFileItems.Count == folderAtSource.Count)) { //no change at root, return the cached folder dataChanaged = false; //int count = FolderCollection[folderId].Items.Count; foreach (var folder in FolderCollection[folderId].Subalbums) { //check if there is any child folder which is not being loaded fully if (folder.Count != (folder.Items.Count + folder.Subalbums.Count + folder.OtherFileItems.Count)) { SkyDriveFolder itemAtServer = await source.GetFolder(folder.UniqueId); dataChanaged = await Sync(folder.UniqueId, folder.Updated_time, itemAtServer); if (dataChanaged) { var cachedFolder = FolderCollection[folder.UniqueId]; cachedFolder.Title = itemAtServer.Title; cachedFolder.Updated_time = itemAtServer.Updated_time; cachedFolder.Count = itemAtServer.Count; cachedFolder.Size = itemAtServer.Size; } } } } else { Dictionary <string, bool> itemTobeDeleted = new Dictionary <string, bool>(FolderCollection[folderAtSource.UniqueId].Count); foreach (var item in FolderCollection[folderAtSource.UniqueId].AllItems) { if (item.Type == SkyDriveItemType.File || item.Type == SkyDriveItemType.Folder) { itemTobeDeleted.Add(item.UniqueId, true); } } // there are changes...determine which folder/file to sync or delete // result of GetChangedFolderAndFiles return a tuple which contains list of changed and unchanged files var changedItems = await source.GetChangedFolderAndFiles(folderAtSource.UniqueId, updated_time); foreach (var item in changedItems.Item1) { dataChanaged = true; //exclude items which were changed from list of items to be deleted if (itemTobeDeleted.ContainsKey(item.UniqueId)) { itemTobeDeleted[item.UniqueId] = false; } if (item.Type == SkyDriveItemType.Folder) { if (!FolderCollection.ContainsKey(item.UniqueId)) { //add Folder to parent container FolderCollection[item.Parent_id].Subalbums.Add((SkyDriveFolder)item); FolderCollection.Add(item.UniqueId, (SkyDriveFolder)item); } else { // sync changed folder await Sync(item.UniqueId, updated_time, (SkyDriveFolder)item); //update changed folder properties at both parent and itself var cachedFolder = FolderCollection[item.UniqueId]; var cachedFolderParent = FolderCollection[item.Parent_id]; SkyDriveFolder folderToUpdate = cachedFolderParent.Subalbums.FirstOrDefault(a => a.UniqueId == item.UniqueId); if (folderToUpdate != null) { int index = cachedFolderParent.Subalbums.IndexOf(folderToUpdate); cachedFolderParent.Subalbums.RemoveAt(index); cachedFolderParent.Subalbums.Insert(index, (SkyDriveFolder)item); } cachedFolder.Title = item.Title; cachedFolder.Updated_time = item.Updated_time; cachedFolder.Count = ((SkyDriveFolder)item).Count; cachedFolder.Size = ((SkyDriveFolder)item).Size; cachedFolder.Parent_id = item.Parent_id; } } else { source.LoadFavicons((SkyDriveFile)item); SkyDriveFolder parent = FolderCollection[item.Parent_id]; SkyDriveFile fileitem = parent.Items.FirstOrDefault(a => a.UniqueId == item.UniqueId); if (fileitem != null) { int index = parent.Items.IndexOf(fileitem); parent.Items.RemoveAt(index); parent.Items.Insert(index, (SkyDriveFile)item); } else { parent.Items.Add((SkyDriveFile)item); } } } //exclude unchanged items from the list of tobedeleted items foreach (string s in changedItems.Item2) { itemTobeDeleted[s] = false; } SkyDriveFolder folder = FolderCollection[folderAtSource.UniqueId]; foreach (var item in itemTobeDeleted) { if (item.Value) { var t = folder.AllItems.FirstOrDefault(a => a.UniqueId == item.Key); if (t != null) { if (t.Type == SkyDriveItemType.Folder) { folder.Subalbums.Remove((SkyDriveFolder)t); } else { folder.Items.Remove((SkyDriveFile)t); } } } } } return(dataChanaged); }
private async Task <ICloudObject> _GetCloudObjectFromSkyDriveObjectIdAsync(string skyDriveObjectId, bool fetchChildren = true) { ICloudObject cloudObject = null; //TODO: Validate if session requires renewal. Skydrive does not supports unique paths with sub directories. //do some recursive calls to construct sub directory paths with some caching so that the path can be optimized. //do make sure that the path exists aka is not deleted or moved. LiveOperationResult operationResult = await _liveClient.GetAsync(skyDriveObjectId); dynamic result = operationResult.Result; ICloudFolder parent = FindParent(_rootCloudObject, result.id); if (result.type == "folder") { if (fetchChildren) { LiveOperationResult childrenResult = await _liveClient.GetAsync(skyDriveObjectId + "/files"); cloudObject = new SkyDriveFolder(parent, result, ((dynamic)childrenResult.Result).data); } else { cloudObject = new SkyDriveFolder(parent, result, null); } } else if (result.type == "album") { if (fetchChildren) { LiveOperationResult childrenResult = await _liveClient.GetAsync(skyDriveObjectId + "/files"); cloudObject = new SkyDriveAlbum(parent, result, ((dynamic)childrenResult.Result).data); } else { cloudObject = new SkyDriveAlbum(parent, result, null); } } else if (result.type == "file") { cloudObject = new SkyDriveFile(parent, result); } else if (result.type == "photo") { cloudObject = new SkyDrivePhoto(parent, result); } //Replace the oldChildRef with the new ref. We need to do it everytime to keep the offline cache updated. if (cloudObject != null && parent != null) { ICloudObject oldChildRef = parent.Children.FirstOrDefault(obj => obj.Id == cloudObject.Id); if (oldChildRef != null) { int index = parent.Children.IndexOf(oldChildRef); parent.Children.Remove(oldChildRef); parent.Children.Insert(index, cloudObject); } } return(cloudObject); }
void OnCancelEvent(SkyDriveFolder e) { CancelEvent(this, e); }