Exemplo n.º 1
0
        public async Task RoamFile(IBindableStorageFile file)
        {
            using (await f_lock.Acquire())
            {
                if (!RoamedFiles.Contains(file))
                {
                    //Backing values
                    string oldPath = GetParentFolder(file.BackingFile);
                    string value   = await _ivService.GetValue(oldPath, FileLocation.Local);

                    await _ivService.Remove(oldPath, FileLocation.Local);

                    await file.BackingFile.MoveAsync(_roamingFolder, file.BackingFile.Name, NameCollisionOption.GenerateUniqueName);

                    await _ivService.Add(GetParentFolder(file.BackingFile), value, FileLocation.Roamed);

                    LocalFiles.Remove(file);

                    //UI
                    file.IsRoamed = true;

                    RoamedFiles.Add(file);
                }
            }
        }
Exemplo n.º 2
0
        private async void OnRoamingDataChanged(ApplicationData sender, object args)
        {
            using (await f_lock.Acquire())
            {
                var roamingFiles = await Task.WhenAll((await sender.RoamingFolder.GetFilesAsync())
                                                      .Where(f => f.Name != Constants.IV_FILE_NAME)
                                                      .Select(async x => await BindableStorageFile.Create(x)));

                var newDictionary = (await sender.RoamingFolder.GetFilesAsync()).First(f => f.Name == Constants.IV_FILE_NAME);
                await newDictionary.CopyAsync(_roamingFolder, Constants.IV_FILE_NAME, NameCollisionOption.ReplaceExisting);

                //Remove no-longer-synced-files
                foreach (var file in RoamedFiles)
                {
                    if (!await ContainsBindableStorageFile(file, roamingFiles))
                    {
                        await DeleteFileAsync(file.BackingFile, FileLocation.Roamed);
                    }
                }

                foreach (var file in roamingFiles.Where(f => f.Name != Constants.IV_FILE_NAME))
                {
                    if (!(await ContainsBindableStorageFile(file, RoamedFiles)))
                    {
                        file.IsRoamed = true;
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                                                      () => RoamedFiles.Add(file));
                    }
                }
            }
        }