/// <summary> /// Synchronization: Cloud -> Iso /// </summary> private async Task CloudToIsoSync(bool downloadAll = false) { var groupNames = (await CloudService.GetDirectoryNames(CloudRootPath)).ToList(); var groupsCount = groupNames.Count(); var progressIncrement = HalfOfProgress / (groupsCount == 0 ? 1 : groupsCount); foreach (var groupName in groupNames) { Trace.Info(_traceCategory, String.Format("synchronize group {0}", groupName)); var group = DataService.GetOrCreateGroupByName(groupName); var localFileNamesMapped = group.Tabs.Select(GetCloudName); var cloudFileNames = await CloudService.GetFileNames(String.Format("{0}/{1}", CloudRootPath, groupName)); //run group images search var groupImagesSearch = MediaSearchFactory.Create(); groupImagesSearch.MediaSearchCompleted += groupImagesSearch_MediaSearchCompleted; groupImagesSearch.RunMediaSearch(groupName, string.Empty); // get tabs which aren't present in iso var newTabs = cloudFileNames.Except(localFileNamesMapped).ToList(); // these tabs was synchronized, but deleted then. // NOTE it's possible that user reinstalled application, but had already synchronized files // just handle this situation using special option var deletedTabs = newTabs.Where(t => !downloadAll & IsMappedPath(t)).ToList(); //if (!DownloadSyncFiles) newTabs = newTabs.Except(deletedTabs).ToList(); // filter cloud synchronized files without _sync_ newTabs = newTabs.Where(name => !IsCloudName(name, group)).ToList(); // all these tabs should be downloaded from skydrive to iso foreach (var newTab in newTabs) { Trace.Info(_traceCategory, String.Format("synchronize tab {0}", newTab)); var localName = TabFileStorage.CreateTabFilePath(); OnProgressMessage(new DownloadProgressMessage(groupName, newTab)); await CloudService.DownloadFile(localName, string.Format("{0}/{1}/{2}", CloudRootPath, groupName, newTab)); DataService.InsertTab(GetTab(newTab, localName, group)); Downloaded++; } ProgressValue += progressIncrement; } DataService.SubmitChanges(); }