// update skydrive object if there is an entry in the xml otherwise add the file entry in xml public bool IsFileExists(ref SkyDriveFile file) { bool bFileExists = false; XElement node = null; try { string fileid = file.UniqueId; node = document.Root.Descendants("File").Where(x => (string)x.Attribute("id") == fileid).FirstOrDefault(); //(@"Favorites/File[@id= """ + file.UniqueId + @"""]"); } catch (Exception ex) { ex.ToString(); } if (node != null) { // if (!string.IsNullOrEmpty(file.URL)) { node.Attribute("source").Value = file.Source; node.Attribute("url").Value = file.URL; node.Attribute("Updated_time").Value = file.Updated_time; node.Attribute("iconid").Value = file.ImagePath; node.Attribute("iconTileColor").Value = file.ImageDominantColor.ToString(); bFileExists = false; } else { // file.Source = node.Attributes[3].NodeValue.ToString(); file.URL = node.Attribute("url").Value; file.ImagePath = node.Attribute("iconid").Value; file.ImageDominantColor = Utility.ColorFromString(node.Attribute("iconTileColor").Value); bFileExists = true; // file.Updated_time = node.Attributes[2].NodeValue.ToString(); } } else { try { document.Root.Add(new XElement("File", new XAttribute("name", file.Title), new XAttribute("id", file.UniqueId), new XAttribute("Updated_time", file.Updated_time), new XAttribute("source", file.Source), new XAttribute("url", file.URL), new XAttribute("description", file.Description), new XAttribute("size", Convert.ToString(file.Size)), new XAttribute("iconid", file.ImagePath), new XAttribute("iconTileColor", file.ImageDominantColor.ToString()))); } catch (Exception ex) { ex.ToString(); } } return(bFileExists); }
private async void PopupAddBookmark_Click(object sender, RoutedEventArgs e) { this.ProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible; this.AddBookmarkPopup.IsOpen = false; var source = await FavoritesDataSyncManager.GetInstance(DocumentLocation.Roaming); if (this.AddBookmarkURL.Text.Trim() != string.Empty) { SkyDriveFile file = null; file = source.CurrentFolder.Items.FirstOrDefault(sf => sf.Title == AddBookmarkName.Text.Trim()); // add url only if does not already exisits if (object.Equals(file, null)) { file = new SkyDriveFile(AddBookmarkName.Text.Trim(), AddBookmarkURL.Text.Trim(), string.Empty); file.Parent_id = source.CurrentFolder.UniqueId; await source.AddFile(file); item = file; //source.CurrentFolder.Items.Add(file); } this.AddBookmarkName.Text = string.Empty; this.AddBookmarkURL.Text = string.Empty; this.ProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } }
public async Task <bool> EditFile(SkyDriveFile file) { var source = await SkyDriveDataSource.GetInstance(); bool result = await source.UpdateFile(file); if (result) { await RecursivelyUpdateParent(file); } return(result); }
public async Task <bool> AddFile(SkyDriveFile file) { var source = await SkyDriveDataSource.GetInstance(); bool result = await source.UploadFile(file); if (result) { FolderCollection[file.Parent_id].Items.Add((SkyDriveFile)file); await RecursivelyUpdateParent(file); } return(result); }
private SkyDriveFile CreateSkyDriveFileFromJson(FavoritesFile item) { var skyFile = new SkyDriveFile(item.UniqueId, item.Title, item.Description, item.Size, item.Parent_id, SkyDriveItemType.File, item.Updated_time, item.Source); skyFile.ImageDominantColor = Utility.ColorFromString(item.ImageDominantColor); skyFile.TileBackground = new SolidColorBrush(skyFile.ImageDominantColor); skyFile.ImagePath = item.ImagePath; skyFile.URL = item.URL; skyFile.FileExtenstion = item.FileExtenstion; skyFile.IsInternetShortcut = item.IsInternetShortcut; skyFile.SyncState = item.SyncState; return(skyFile); }
public CredentialSettingsFlyout(SkyDriveFile skydriveFile, string url) { this.InitializeComponent(); var credentialMgr = CredentialManager.GetInstance(); credentialMgr.UserPinEvent += credentialMgr_UserPinEvent; browserurl = url; item = skydriveFile; // determine if browserurl is same as file url // user might come here with a favorite url but browsed away from favorite url // in that case don't show add notes option if (!string.IsNullOrEmpty(item.UniqueId)) { if (new Uri(item.URL).Host == new Uri(browserurl).Host) { this.NoteBox.Text = this.item.Description; if (!this.item.Description.Equals(string.Empty)) { this.showAddNotes = false; this.showNotes = true; } else { this.showAddNotes = true; } } } SetVisibility(); var creds = credentialMgr.GetCredential(browserurl); if (creds != null) { this.UserName.IsReadOnly = true; this.UserName.Text = creds.UserName; this.password.Password = creds.Password; this.password.IsEnabled = false; this.txtPassword.IsReadOnly = true; this.BtnAdd.Visibility = Windows.UI.Xaml.Visibility.Collapsed; this.BtnEdit.Visibility = Windows.UI.Xaml.Visibility.Visible; bcredentialPresent = true; SetVisibility(); } else if (!credentialMgr.IsPinSetForCredentials) { this.CreatePin.Visibility = Windows.UI.Xaml.Visibility.Visible; this.CredentialPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } }
public async void SearchBoxEventsQuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args) { searchQuery = args.QueryText; if (string.IsNullOrEmpty(searchQuery)) { return; } ((SearchBox)MainFrameHost.Current.FindName("_FavouritesSearchBox")).QueryText = string.Empty; ((SearchBox)MainFrameHost.Current.FindName("_FavouritesSearchBox")).PlaceholderText = searchQuery; ((SearchBox)MainFrameHost.Current.FindName("_FavouritesSearchBox")).InvalidateArrange(); var source = await FavoritesDataSyncManager.GetInstance(DocumentLocation.Roaming); SkyDriveFile fileCollection = source.GetSelectedFile(args.QueryText); try { //SkyDriveFolder result = await source.Search(queryText); if (object.Equals(fileCollection, null)) { Uri url = Utility.IsInternetURL(searchQuery); if (url != null) { //its internet url fileCollection = new SkyDriveFile(searchQuery, url.AbsoluteUri, ""); if (string.IsNullOrEmpty(item.UniqueId)) { item.URL = fileCollection.URL; } } else { fileCollection = new SkyDriveFile(searchQuery, selectedSearchEngine + Uri.EscapeUriString(searchQuery), ""); } } else { if (string.IsNullOrEmpty(fileCollection.URL)) { await source.LoadFile(fileCollection); } } ((SearchBox)MainFrameHost.Current.FindName("_FavouritesSearchBox")).QueryText = fileCollection.URL; NavigateBrowser(fileCollection.URL); } catch { }; }
private async Task NavigateToSelectedText(string searchText) { //reset titlebar state before navigate this.SearchBox.Visibility = System.Windows.Visibility.Collapsed; this.FoldersList.Visibility = System.Windows.Visibility.Visible; if (string.IsNullOrEmpty(searchText.Trim())) { return; } string url = searchText; Uri urlToBrowse = Utility.IsInternetURL(url, true); if (urlToBrowse == null) { SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); SkyDriveFile fileCollection = SkyDriveDataSource.searchResultContainer.Items.FirstOrDefault(sf => sf.Title.ToLower().Contains(url.ToLower())); try { if (object.Equals(fileCollection, null)) { url = selectedSearchEngine + Uri.EscapeUriString(url); } else { if (string.IsNullOrEmpty(fileCollection.URL)) { await source.LoadFile(fileCollection); url = fileCollection.URL; } else { url = fileCollection.URL; } //fileCollection.URL = System.Net.WebUtility.UrlEncode(fileCollection.URL); } } catch { url = "http://www.bing.com"; }; } WebBrowserTask webBrowserTask = new WebBrowserTask(); webBrowserTask.Uri = new Uri(url, UriKind.Absolute); webBrowserTask.Show(); //this.NavigationService.Navigate(new Uri("/View/ContentViewerWithAppBar.xaml?msg=" + searchText, UriKind.Relative)); }
private void CopySkyDriveFileToJson(SkyDriveFile source, FavoritesFile destination) { destination.Title = source.Title; destination.UniqueId = source.UniqueId; destination.Updated_time = source.Updated_time; destination.Size = source.Size; destination.ImagePath = source.ImagePath; destination.Parent_id = source.Parent_id; destination.Description = source.Description; destination.ImageDominantColor = source.ImageDominantColor.ToString(); destination.FileExtenstion = source.FileExtenstion; destination.IsInternetShortcut = source.IsInternetShortcut; destination.Source = source.Source; destination.URL = source.URL; destination.SyncState = source.SyncState; }
// fullPath is any number of directories then filename // eg. dir1/dir2/dir3/myfile.txt public static SkyDriveFile GetSkyDriveEntryByFileNameAndDirectory(string fullPath) { if (string.IsNullOrEmpty(fullPath)) { return(null); } List <SkyDriveDirectory> skydriveListing; SkyDriveDirectory selectedEntry = null; SkyDriveFile selectedFile = null; // root listing. skydriveListing = SkyDriveHelper.ListSkyDriveDirectoryWithUrl(""); var fileFound = false; var sp = fullPath.Split('/'); var searchDir = ""; foreach (var entry in sp) { var foundEntry = (from e in skydriveListing where e.Name == entry select e).FirstOrDefault(); if (foundEntry != null && foundEntry.Type == "folder") { searchDir = foundEntry.Id + "/"; skydriveListing = ListSkyDriveDirectoryWithUrl(searchDir); } // cant have == "file", since "photos" etc come up as different types. if (foundEntry != null && foundEntry.Type != "folder") { fileFound = true; var l = ListSkyDriveFileWithUrl(foundEntry.Id); if (l != null) { selectedFile = l; } } selectedEntry = foundEntry; } if (!fileFound) { selectedFile = null; } return(selectedFile); }
/// <summary> /// Override the OnNavigatedFrom event of LayoutAwarePage /// </summary> /// <param name="e">Evernt arguments.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested; item = (SkyDriveFile)e.Parameter; if (item == null) { item = new SkyDriveFile(tabObject.PageTitle, tabObject.Url, tabObject.ImagePath); } else { tabObject.ImagePath = item.ImagePath; tabObject.PageTitle = item.Title; tabObject.Url = item.URL;; } string url = item.URL; // Register the current page as a share source. this.dataTransferManager = DataTransferManager.GetForCurrentView(); this.dataTransferManager.DataRequested += new TypedEventHandler <DataTransferManager, DataRequestedEventArgs> (this.OnDataRequested); if (url != null) { searchQuery = url; ((SearchBox)MainFrameHost.Current.FindName("_FavouritesSearchBox")).QueryText = url; Uri urlToBrowse = Utility.IsInternetURL(url); if (urlToBrowse != null) { //its internet url url = urlToBrowse.AbsoluteUri; //update item item.URL = url; } else { url = selectedSearchEngine + Uri.EscapeUriString(url); } this.FavoriteBrowser.Navigate(new Uri(url)); this.DataContext = url; } base.OnNavigatedTo(e); }
public SkyDriveFile GetSelectedFile(string searchString) { SkyDriveFile file = null; if (searchString != "") { string[] col = searchString.Split('|'); foreach (var folder in FolderCollection) { file = folder.Value.Items. FirstOrDefault(sf => (sf.Title.myContains(col[0].Trim(), StringComparison.OrdinalIgnoreCase) && sf.URL.myContains(col[1].Trim(), StringComparison.OrdinalIgnoreCase))); if (file != null) { break; } } } return(file); }
public async void loadXML() { Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("XML"); // you can get the specific folder from KnownFolders or other folders via FolderPicker as well Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync("FavoriteSuggestionList.xml"); Windows.Data.Xml.Dom.XmlLoadSettings loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings(); loadSettings.ProhibitDtd = false; // sample loadSettings.ResolveExternals = false; // sample XmlDocument doc = await XmlDocument.LoadFromFileAsync(storageFile, loadSettings); XmlNodeList groups = doc.SelectNodes("//FavoriteList/FavoriteItem"); foreach (var group in groups) { SkyDriveFile favoriteItem = new SkyDriveFile(group.Attributes[0].NodeValue.ToString(), group.Attributes[1].NodeValue.ToString(), group.Attributes[2].NodeValue.ToString()); favoriteItem.IsChecked = true; favoriteItem.ShowCheckBox = true; favoriteList.Add(favoriteItem); } }
protected override async void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { string url; NavigationContext.QueryString.TryGetValue("msg", out url); Uri urlToBrowse = Utility.IsInternetURL(url); if (urlToBrowse != null) { this.SearchBox.Text = url; this.BrowserControl.Navigate(new Uri(url)); } else { SkyDriveDataSource source = await SkyDriveDataSource.GetInstance(); SkyDriveFile fileCollection = SkyDriveDataSource.searchResultContainer.Items.FirstOrDefault(sf => sf.Title.ToLower().Contains(url.ToLower())); try { if (object.Equals(fileCollection, null)) { url = selectedSearchEngine + Uri.EscapeUriString(url); } else { if (string.IsNullOrEmpty(fileCollection.URL)) { await source.LoadFile(fileCollection); url = fileCollection.URL; } //fileCollection.URL = System.Net.WebUtility.UrlEncode(fileCollection.URL); } this.SearchBox.Text = url; this.BrowserControl.Navigate(new Uri(url)); } catch { }; } base.OnNavigatedTo(e); }
public async void loadXML() { Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("XML"); // you can get the specific folder from KnownFolders or other folders via FolderPicker as well var storageFile = await storageFolder.OpenStreamForReadAsync("FavoriteSuggestionList.xml"); //Windows.Data.Xml.Dom.XmlLoadSettings loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings(); //loadSettings.ProhibitDtd = false; // sample //loadSettings.ResolveExternals = false; // sample XDocument doc = XDocument.Load(storageFile); // XmlDocument doc = await XmlDocument.LoadFromFileAsync(storageFile, loadSettings); // XmlNodeList groups = doc.Elements;//.SelectNodes("//FavoriteList/FavoriteItem"); foreach (var group in doc.Root.Elements("FavoriteItem")) { SkyDriveFile favoriteItem = new SkyDriveFile((string)group.Attribute("Title"), (string)group.Attribute("URL"), (string)group.Attribute("ImagePath")); favoriteItem.IsChecked = true; favoriteItem.ShowCheckBox = true; favoriteList.Add(favoriteItem); } }
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>()); }
// update skydrive object if there is an entry in the xml otherwise add the file entry in xml public bool IsFileExists(ref SkyDriveFile file) { bool bFileExists = false; IXmlNode node = null; try { node = document.SelectSingleNode(@"Favorites/File[@id= """ + file.UniqueId + @"""]"); } catch (Exception ex) { ex.ToString(); } if (node != null) { // if (!string.IsNullOrEmpty(file.URL)) { node.Attributes[3].NodeValue = file.Source; node.Attributes[4].NodeValue = file.URL; node.Attributes[2].NodeValue = file.Updated_time; node.Attributes[7].NodeValue = file.ImagePath; node.Attributes[8].NodeValue = file.ImageDominantColor.ToString(); bFileExists = false; } else { // file.Source = node.Attributes[3].NodeValue.ToString(); file.URL = node.Attributes[4].NodeValue.ToString(); file.ImagePath = node.Attributes[7].NodeValue.ToString(); file.ImageDominantColor = Utility.ColorFromString(node.Attributes[8].NodeValue.ToString()); bFileExists = true; // file.Updated_time = node.Attributes[2].NodeValue.ToString(); } } else { try { XmlElement childnode = document.CreateElement("File"); XmlAttribute nameAttribute = document.CreateAttribute("name"); nameAttribute.Value = file.Title; XmlAttribute idAttribute = document.CreateAttribute("id"); idAttribute.Value = file.UniqueId; XmlAttribute timeAttribute = document.CreateAttribute("Updated_time"); timeAttribute.Value = file.Updated_time; XmlAttribute sourceAttribute = document.CreateAttribute("source"); sourceAttribute.Value = file.Source; XmlAttribute urlAttribute = document.CreateAttribute("url"); urlAttribute.Value = file.URL; XmlAttribute descAttribute = document.CreateAttribute("description"); descAttribute.Value = file.Description; XmlAttribute sizeAttribute = document.CreateAttribute("size"); sizeAttribute.Value = Convert.ToString(file.Size); XmlAttribute iconidAttribute = document.CreateAttribute("iconid"); iconidAttribute.Value = file.ImagePath; XmlAttribute iconTileAttribute = document.CreateAttribute("iconTileColor"); iconTileAttribute.Value = file.ImageDominantColor.ToString(); childnode.SetAttributeNode(nameAttribute); childnode.SetAttributeNode(idAttribute); childnode.SetAttributeNode(timeAttribute); childnode.SetAttributeNode(sourceAttribute); childnode.SetAttributeNode(urlAttribute); childnode.SetAttributeNode(descAttribute); childnode.SetAttributeNode(sizeAttribute); childnode.SetAttributeNode(iconidAttribute); childnode.SetAttributeNode(iconTileAttribute); document.SelectSingleNode("Favorites").AppendChild(childnode); } catch (Exception ex) { ex.ToString(); } } return(bFileExists); }
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 string GetDownloadUserState(SkyDriveFile file) { return file.Id + "|" + file.Name; }
private void BeginDownloadCartridge(SkyDriveFile file) { // Adds the file id to the list of currently downloading files. lock (_syncRoot) { _dlFiles.Add(file); } // The emulator has no support for background download. // Peform a direct download instead. bool shouldDirectDownload = !IsBackgroundDownloadAllowed || Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator; // Starts downloading the cartridge to the isostore. string fileAttribute = file.Id + "/content"; if (shouldDirectDownload) { // Direct download. _liveClient.DownloadAsync(fileAttribute, GetDownloadUserState(file)); } else { try { // Tries to perform a background download. _liveClient.BackgroundDownloadAsync( fileAttribute, new Uri(GetTempIsoStorePath(file.Name), UriKind.RelativeOrAbsolute), GetDownloadUserState(file) ); } catch (Exception) { // Tries the direct download method. _liveClient.DownloadAsync(fileAttribute, GetDownloadUserState(file)); } } }
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); }
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); }
public async Task LoadFile(SkyDriveFile file) { var source = await SkyDriveDataSource.GetInstance(); await source.LoadFile(file); }