public void SaveLoadAsyncTest() { Device.Info = new MockDeviceInfo(); Device.PlatformServices = new MockPlatformServices(); IUnityContainer myContainer = new UnityContainer(); myContainer.RegisterType <MockResourcesProvider>(); myContainer.RegisterType <MockDeserializer>(); myContainer.RegisterType <ILogManager, LogManager_UWP_audit_memory>(); var logManager = myContainer.Resolve <LogManager_UWP_audit_memory>(); NLog.GlobalDiagnosticsContext.Set("user", "UnitTest"); //fileHelper.FileSystemStorage = MockFileSystemStorage.MockFileSystem; Windows.Storage.StorageFolder appDataFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var repository = new FileRepository(logManager, MockFileSystemStorage.MockFileSystem, appDataFolder.Path); var device = new MyTagPocket.Repository.Files.Entities.Devices.Device(); device.Name = "Test device ěščřžýáíé"; device.FolderId = "2d2740d9ac634bed83050879ce0a1018"; repository.SaveAsync(device, System.IO.Path.Combine(appDataFolder.Path, "files")).Wait(); MyTagPocket.Repository.Files.Entities.Devices.Device testDevice = repository.LoadAsync(device).Result; Assert.Equal(device.Hash, testDevice.Hash); Assert.Equal(device.EntityId, testDevice.EntityId); Assert.Equal(device.CreatedWhen, testDevice.CreatedWhen); Assert.Equal(device.CommitId, testDevice.CommitId); Assert.Equal(device.Name, testDevice.Name); Assert.Equal(device.Version, testDevice.Version); repository.DeleteAsync(device).Wait(); logManager.FlushBuffer(); }
private async Task ProcessRemotelyDeletedFiles() { var remotelyDeleted = await FileRepository.FindAllAsync(x => x.Status == FileStatus.RemotelyDeleted); var roots = remotelyDeleted.Where(x => remotelyDeleted.All(y => y.Id != x.ParentId)); foreach (var fileEntity in roots) { var path = await FileRepository.GetPathAsync(fileEntity.Id); var fullPath = Path.Combine(AccountObject.Path, path); try { if (fileEntity.IsFolder && Directory.Exists(fullPath)) { Directory.Delete(fullPath, true); } if (!fileEntity.IsFolder && File.Exists(fullPath)) { File.Delete(fullPath); } await FileRepository.DeleteAsync(x => x.Id == fileEntity.Id); } catch (IOException) { //cannot delete await FileRepository.UpdateBranchStatusAsync(fileEntity, FileStatus.UserActionRequired); } } }
private async Task ProcessRemotelyMoved() { var movedFrom = await FileRepository.FindAllAsync(x => x.Status == FileStatus.RemotelyMovedFrom); var movedTo = await FileRepository.FindAllAsync(x => x.Status == FileStatus.RemotelyMovedTo); foreach (var fileFrom in movedFrom) { var fileTo = movedTo.FirstOrDefault(x => x.MovedId == fileFrom.Id); if (fileTo == null) { fileFrom.Status = FileStatus.Conflict; continue; } if (fileFrom.IsFolder) { //move children to new dir await FileRepository.UpdateAsync(x => x.ParentId == fileFrom.Id, e => new FileEntity { ParentId = fileTo.Id }); } var oldPath = await FileRepository.GetPathAsync(fileFrom.Id); var newPath = await FileRepository.GetPathAsync(fileTo.Id); var oldFullPath = Path.Combine(AccountObject.Path, oldPath); var newFullPath = Path.Combine(AccountObject.Path, newPath); try { if (fileFrom.IsFolder) { Directory.Move(oldFullPath, newFullPath); } else { File.Move(oldFullPath, newFullPath); } await FileRepository.DeleteAsync(x => x.Id == fileFrom.Id); fileTo.MovedId = null; fileTo.Status = FileStatus.Synchronized; } catch (IOException) { fileFrom.Status = FileStatus.Conflict; fileTo.Status = FileStatus.Conflict; } } }
private async Task ProcessLocallyDeletedFiles() { var locallyDeleted = await FileRepository.FindAllAsync(x => x.Status == FileStatus.LocallyDeleted); var roots = locallyDeleted.Where(x => locallyDeleted.All(y => y.Id != x.ParentId)); foreach (var fileEntity in roots) { await Connection.DeleteFileAsync(AccountObject.Token, fileEntity.UploadId); await FileRepository.DeleteAsync(x => x.Id == fileEntity.Id); } }
public async Task <bool> DeleteFile(string id) { try { ObjectId _id = ObjectId.Parse(id); await repository.DeleteAsync(_id); return(true); } catch (Exception ex) { Serilog.Log.Error(ex.Message); return(false); } }
static async Task Main(string[] args) { var repository = new FileRepository<TestModel, int>("123.jsondb"); var model = new TestModel { Id = 1, Name = "Name 1", Date = DateTime.Now, Description = new string('A', 1024) }; var model2 = new TestModel { Id = 2, Name = "Name 2", Date = DateTime.Now, Description = new string('B', 2048) }; var model3 = new TestModel { Id = 3, Name = "Name 3", Date = DateTime.Now, Description = new string('C', 96056) }; var model4 = new TestModel { Id = 4, Name = "Name 4", Date = DateTime.Now, Description = new string('C', 96056) }; var model5 = new TestModel { Id = 5, Name = "Name 5", Date = DateTime.Now, Description = new string('C', 96056) }; await repository.CreateAsync(model); await repository.CreateRangeAsync(new[] { model2, model3, model4, model5 }); var m = await repository.GetAsync(1); var all = await repository.GetAll(); model2.Name = "Updated name"; var uModel = await repository.UpdateAsync(model2); var dModel = await repository.DeleteAsync(model3.Id); var getDModel = await repository.GetAsync(model3.Id); var query = repository.GetQuery().Where(_ => _.Name.StartsWith("N")); Console.ReadLine(); }