// GET: Drive public ActionResult Index() { var dbFiles = db.APKs.ToList(); var files = Global.GoogleClient.FetchedFiles; if (files == null) { return(View()); } var Ids = new HashSet <string>(dbFiles.Select(x => x.FileID)); var Versions = new HashSet <string>(dbFiles.Select(x => x.Version)); var model = new DriveModel { NonRoot = new List <DriveFile>(files["NONROOT"]), NonRoot_Beta = new List <DriveFile>(files["NONROOT_BETA"]), Root = new List <DriveFile>(files["ROOT"]), Root_Beta = new List <DriveFile>(files["ROOT_BETA"]), Magisk = new List <DriveFile>(files["MAGISK"]), Magisk_Beta = new List <DriveFile>(files["MAGISK_BETA"]) }; model.NonRoot.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); model.NonRoot_Beta.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); model.Root.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); model.Root_Beta.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); model.Magisk.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); model.Magisk_Beta.RemoveAll(p => Ids.Contains(p.FileID) && Versions.Contains(p.Version)); return(View(model)); }
public void TestOpenCommand() { var driveModel = new DriveModel { Name = "Test", RootDirectory = "/test", TotalSpaceBytes = 42, FreeSpaceBytes = 21 }; var fileSizeFormatterMock = new Mock <IFileSizeFormatter>(); var pathServiceMock = new Mock <IPathService>(); var filePanelViewModelMock = new Mock <IFilesPanelViewModel>(); filePanelViewModelMock .SetupSet(m => m.CurrentDirectory = driveModel.RootDirectory) .Verifiable(); var fileOperationsMediatorMock = new Mock <IFilesOperationsMediator>(); fileOperationsMediatorMock .SetupGet(m => m.ActiveFilesPanelViewModel) .Returns(filePanelViewModelMock.Object); var viewModel = new DriveViewModel(fileSizeFormatterMock.Object, pathServiceMock.Object, fileOperationsMediatorMock.Object, driveModel); Assert.True(viewModel.OpenCommand.CanExecute(null)); viewModel.OpenCommand.Execute(null); filePanelViewModelMock .VerifySet(m => m.CurrentDirectory = driveModel.RootDirectory, Times.Once); }
public void TestRemoveMountedDrive() { var model = new DriveModel(); _autoMocker .Setup <IMountedDriveService, IReadOnlyList <DriveModel> >(m => m.MountedDrives) .Returns(new[] { model }); _autoMocker .Setup <IUnmountedDriveService, IReadOnlyList <UnmountedDriveModel> >(m => m.UnmountedDrives) .Returns(new UnmountedDriveModel[0]); _autoMocker .Setup <IDriveViewModelFactory, IDriveViewModel>(m => m.Create(model)) .Returns(new Mock <IDriveViewModel>().Object); var viewModel = _autoMocker.CreateInstance <DrivesListViewModel>(); Assert.NotNull(viewModel.Drives); Assert.NotEmpty(viewModel.Drives); _autoMocker .GetMock <IMountedDriveService>() .Raise(m => m.DriveRemoved += null, new MountedDriveEventArgs(model)); Assert.NotNull(viewModel.Drives); Assert.Empty(viewModel.Drives); }
public void TestOpenCommand() { var driveModel = new DriveModel { Name = "Test", RootDirectory = "/test", TotalSpaceBytes = 42, FreeSpaceBytes = 21 }; _autoMocker.Use(driveModel); var filePanelViewModelMock = new Mock <IFilesPanelViewModel>(); _autoMocker .GetMock <IFilesPanelViewModel>() .SetupSet(m => m.CurrentDirectory = driveModel.RootDirectory) .Verifiable(); _autoMocker .Setup <IFilesOperationsMediator, IFilesPanelViewModel>(m => m.ActiveFilesPanelViewModel) .Returns(filePanelViewModelMock.Object); var viewModel = _autoMocker.CreateInstance <DriveViewModel>(); Assert.True(viewModel.OpenCommand.CanExecute(null)); viewModel.OpenCommand.Execute(null); filePanelViewModelMock .VerifySet(m => m.CurrentDirectory = driveModel.RootDirectory, Times.Once); }
public void TestAddMountedDrive() { _autoMocker .Setup <IMountedDriveService, IReadOnlyList <DriveModel> >(m => m.MountedDrives) .Returns(new DriveModel[0]); _autoMocker .Setup <IUnmountedDriveService, IReadOnlyList <UnmountedDriveModel> >(m => m.UnmountedDrives) .Returns(new UnmountedDriveModel[0]); var viewModel = _autoMocker.CreateInstance <DrivesListViewModel>(); var model = new DriveModel(); var driveViewModel = new Mock <IDriveViewModel>().Object; _autoMocker .Setup <IDriveViewModelFactory, IDriveViewModel>(m => m.Create(model)) .Returns(driveViewModel); _autoMocker .GetMock <IMountedDriveService>() .Raise(m => m.DriveAdded += null, new MountedDriveEventArgs(model)); Assert.NotNull(viewModel.Drives); Assert.Single(viewModel.Drives); Assert.Equal(driveViewModel, viewModel.Drives.Single()); }
public async Task ScanAsync(string[] folders) { if (folders != null) { foreach (string path in folders) { DirectoryInfo root = new DirectoryInfo(path).Root; Computer computer; bool isNetworkShare = Drive.IsNetworkPath(path); if (isNetworkShare) { string machineName = Drive.GetMachineName(path); computer = Computers.SingleOrDefault(c => c.NameEquals(machineName)); if (computer == null) { computer = new Computer() { Name = machineName }; computer.Folders = new List <Folder>(); Computers.Add(computer); } } else { computer = _localComputer; } bool isDrive = root.FullName.Equals(path, StringComparison.OrdinalIgnoreCase); DriveModel drive = computer.Drives.SingleOrDefault(f => f.NameEquals(root.Name)); bool isNew = drive == null; if (isNew) { string name; DriveType driveType; if (isNetworkShare) { name = Drive.GetDriveLetter(path); driveType = Drive.NETWORK_SHARE; } else { name = root.Name; driveType = DriveType.Network; } drive = new DriveModel(computer, name, DateTime.UtcNow, driveType); drive.Folders.Clear(); computer.Folders.Add(drive); computer.Folders = new List <Folder>(computer.Folders); computer.RaiseItemChanges(); } if (!isDrive) { drive.Load(); } await ScanAsync(path, isDrive, drive, computer); } } }
public void CreateDrive(DriveModel drive) { if (drive.Capacity <= 0) { throw new Exception("Invalid capacity!"); } this._database.GetCollection <DriveModel>(DRIVE).InsertOne(drive); }
private void AddDrive(DriveModel driveModel) { var driveViewModel = CreateFrom(driveModel); _mountedDrivesDictionary[driveModel] = driveViewModel; UpdateDrivesList(); }
public void GetDriveModelPercentage() { var model = new DriveModel { TotalFreeSpace = 1024, TotalSize = 2048 }; Assert.That(model.PercentageFilled, Is.EqualTo(50)); }
public int Delete(DriveModel model) { string sqlDelete = "DELETE FROM Drive WHERE Id = @Id"; using (_connection) { return(_connection.Execute(sqlDelete, model)); } }
public int Insert(DriveModel model) { string sqlInsert = "INSERT INTO Drive (Id, Name) Values (@Id, @Name)"; using (_connection) { return(_connection.Execute(sqlInsert, model)); } }
public int Update(DriveModel model) { string sqlUpdate = "UPDATE Drive SET Name = @Name WHERE Id = @Id"; using (_connection) { return(_connection.Execute(sqlUpdate, model)); } }
private void UpdateDrive(DriveModel driveModel) { if (_mountedDrivesDictionary[driveModel] is IMountedDriveViewModel viewModel) { viewModel.Name = driveModel.Name; viewModel.FreeSpaceBytes = driveModel.FreeSpaceBytes; viewModel.TotalSpaceBytes = driveModel.TotalSpaceBytes; } }
public void TestCreateMounted() { var driveModel = new DriveModel(); var factory = _autoMocker.CreateInstance <DriveViewModelFactory>(); var viewModel = factory.Create(driveModel); Assert.NotNull(viewModel); Assert.IsType <DriveViewModel>(viewModel); }
private void LoadIfDrive(object item) { if (item is DriveModel) { DriveModel drive = (DriveModel)item; bool loaded = VM.BusyWith("Loading {0} ...".FormatWith(drive.Name), Task.Run(() => drive.Load())); if (!loaded) { MessageBox.Show(this, "You need to scan this drive first."); } } }
public DriveViewModel( IFileSizeFormatter fileSizeFormatter, IPathService pathService, IFilesOperationsMediator filesOperationsMediator, DriveModel driveModel) { _fileSizeFormatter = fileSizeFormatter; _pathService = pathService; _filesOperationsMediator = filesOperationsMediator; _driveModel = driveModel; OpenCommand = ReactiveCommand.Create(Open); }
public async new Task <int> LoadChildrenAsync() { var drives = await DriveModel.GetLogicalDrivesAsync(); await Application.Current.Dispatcher.BeginInvoke(new Action(() => { foreach (var drive in drives) { base.Children.Add(new DriveViewModel(drive, this)); } }), DispatcherPriority.Background, new object[0]); return(drives.Count()); }
public void TestCreate() { var driveModel = new DriveModel(); var fileSizeFormatterMock = new Mock <IFileSizeFormatter>(); var pathServiceMock = new Mock <IPathService>(); var fileOperationsMediatorMock = new Mock <IFilesOperationsMediator>(); var factory = new DriveViewModelFactory(fileSizeFormatterMock.Object, pathServiceMock.Object, fileOperationsMediatorMock.Object); var viewModel = factory.Create(driveModel); Assert.NotNull(viewModel); Assert.IsType <DriveViewModel>(viewModel); }
/// <summary> /// Initialize the treeview with a set of local drives /// currently available on the computer. /// </summary> private void SetInitialDrives(CancellationTokenSource cts = null) { foreach (var item in DriveModel.GetLogicalDrives()) { if (cts != null) { cts.Token.ThrowIfCancellationRequested(); } var vmItem = CreateFolderItem(item.Model); Application.Current.Dispatcher.Invoke(new Action(() => { Folders.Add(item.Model.Name.ToLower(), vmItem); })); } }
public void TestUpdateMountedDrive() { var model = new DriveModel { Name = FirstName }; _autoMocker .Setup <IMountedDriveService, IReadOnlyList <DriveModel> >(m => m.MountedDrives) .Returns(new[] { model }); _autoMocker .Setup <IUnmountedDriveService, IReadOnlyList <UnmountedDriveModel> >(m => m.UnmountedDrives) .Returns(new UnmountedDriveModel[0]); var driveViewModelMock = new Mock <IDriveViewModel>(); var mountedDriveViewModelMock = driveViewModelMock.As <IMountedDriveViewModel>(); mountedDriveViewModelMock .SetupSet(m => m.Name = SecondName) .Verifiable(); var driveViewModel = driveViewModelMock.Object; _autoMocker .Setup <IDriveViewModelFactory, IDriveViewModel>(m => m.Create(It.Is <DriveModel>(dm => dm.Name == FirstName))) .Returns(driveViewModel); var viewModel = _autoMocker.CreateInstance <DrivesListViewModel>(); Assert.NotNull(viewModel.Drives); Assert.Single(viewModel.Drives); Assert.Equal(driveViewModel, viewModel.Drives.Single()); model.Name = SecondName; _autoMocker .GetMock <IMountedDriveService>() .Raise(m => m.DriveUpdated += null, new MountedDriveEventArgs(model)); Assert.NotNull(viewModel.Drives); Assert.Single(viewModel.Drives); Assert.Equal(driveViewModel, viewModel.Drives.Single()); mountedDriveViewModelMock .VerifySet(m => m.Name = SecondName, Times.Once); }
public void TestEjectCommand() { var driveModel = new DriveModel { RootDirectory = "/test" }; _autoMocker.Use(driveModel); var viewModel = _autoMocker.CreateInstance <DriveViewModel>(); Assert.True(viewModel.EjectCommand.CanExecute(null)); viewModel.EjectCommand.Execute(null); _autoMocker .Verify <IMountedDriveService>(m => m.EjectAsync(driveModel.RootDirectory), Times.Once); }
/// <summary> /// Gets the drives. /// </summary> public IEnumerable <DriveModel> GetDrives() { var drives = GetDriveInfo(); var model = new List <DriveModel>(); foreach (var drive in drives) { if (!drive.IsReady) { continue; } var driveModel = new DriveModel(); var mapped = driveModel.InjectFrom(drive); model.Add((DriveModel)mapped); } return(model); }
public void TestProperties(bool isEjectAvailable, Platform platform) { const string name = "tst"; var driveModel = new DriveModel { Name = "Test", RootDirectory = "/test", TotalSpaceBytes = 42, FreeSpaceBytes = 21 }; _autoMocker.Use(driveModel); _autoMocker .Setup <IFileSizeFormatter, string>(m => m.GetSizeAsNumber(It.IsAny <long>())) .Returns <long>((bytes) => bytes.ToString()); _autoMocker .Setup <IFileSizeFormatter, string>(m => m.GetFormattedSize(It.IsAny <long>())) .Returns <long>((bytes) => bytes + " B"); _autoMocker .Setup <IPathService, string>(m => m.GetFileName(driveModel.Name)) .Returns(name); var filePanelViewModelMock = new Mock <IFilesPanelViewModel>(); _autoMocker .Setup <IFilesOperationsMediator, IFilesPanelViewModel>(m => m.ActiveFilesPanelViewModel) .Returns(filePanelViewModelMock.Object); _autoMocker .Setup <IPlatformService, Platform>(m => m.GetPlatform()) .Returns(platform); var viewModel = _autoMocker.CreateInstance <DriveViewModel>(); Assert.Equal(name, viewModel.DriveName); Assert.Equal("21", viewModel.AvailableSizeAsNumber); Assert.Equal("21 B", viewModel.AvailableFormattedSize); Assert.Equal("42", viewModel.TotalSizeAsNumber); Assert.Equal("42 B", viewModel.TotalFormattedSize); Assert.Equal(isEjectAvailable, viewModel.IsEjectAvailable); Assert.Equal(driveModel.Name, viewModel.Name); Assert.Equal(driveModel.TotalSpaceBytes, viewModel.TotalSpaceBytes); Assert.Equal(driveModel.FreeSpaceBytes, viewModel.FreeSpaceBytes); Assert.Equal(driveModel.RootDirectory, viewModel.RootDirectory); }
public void TestDrivesUpdate() { var driveServiceMock = new Mock <IDriveService>(); driveServiceMock .SetupGet(m => m.MountedDrives) .Returns(new List <DriveModel>()); var driveViewModelFactoryMock = new Mock <IDriveViewModelFactory>(); var applicationDispatcherMock = new Mock <IApplicationDispatcher>(); applicationDispatcherMock .Setup(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => action()); driveServiceMock .SetupGet(m => m.UnmountedDrives) .Returns(new UnmountedDriveModel[0]); var viewModel = new DrivesListViewModel(driveServiceMock.Object, driveViewModelFactoryMock.Object, applicationDispatcherMock.Object); Assert.NotNull(viewModel.Drives); Assert.Empty(viewModel.Drives); var driveModel = new DriveModel { RootDirectory = "B" }; driveServiceMock .SetupGet(m => m.MountedDrives) .Returns(new[] { driveModel }); var driveViewModelMock = new Mock <IDriveViewModel>(); driveViewModelFactoryMock .Setup(m => m.Create(driveModel)) .Returns(driveViewModelMock.Object); driveServiceMock .Raise(m => m.DrivesListChanged += null, EventArgs.Empty); Assert.NotNull(viewModel.Drives); Assert.Single(viewModel.Drives); }
/// <summary> /// Initialize the treeview with a set of local drives /// currently available on the computer. /// </summary> private void SetInitialDrives(CancellationToken ct = default(CancellationToken)) { ClearFoldersCollections(); var items = DriveModel.GetLogicalDrives().ToList(); foreach (var item in items) { if (ct != null) { ct.ThrowIfCancellationRequested(); } Application.Current.Dispatcher.Invoke(() => { var vmItem = new DriveViewModel(item.Model, null); _Root.AddItem(vmItem); }); } }
private async Task ScanAsync(string path, bool scanDrive, DriveModel drive, Computer computer) { string folderName = scanDrive ? path : Path.GetFileName(path); await BusyWithAsync("Scanning {0} ...".FormatWith(folderName), Task.Run(() => { if (scanDrive) { Drive d = App.Scanner.Scan(path); drive.Load(d); } else { Folder parent = drive.GetDrive(path); App.Scanner.ScanUpdate(path, drive); drive.HasLoaded = true; parent.RaiseItemChanges(); } drive.IsChanged = true; return(true); })); }
public void TestProperties() { const string name = "tst"; var driveModel = new DriveModel { Name = "Test", RootDirectory = "/test", TotalSpaceBytes = 42, FreeSpaceBytes = 21 }; var fileSizeFormatterMock = new Mock <IFileSizeFormatter>(); fileSizeFormatterMock .Setup(m => m.GetSizeAsNumber(It.IsAny <long>())) .Returns <long>((bytes) => bytes.ToString()); fileSizeFormatterMock .Setup(m => m.GetFormattedSize(It.IsAny <long>())) .Returns <long>((bytes) => bytes + " B"); var pathServiceMock = new Mock <IPathService>(); pathServiceMock .Setup(m => m.GetFileName(driveModel.Name)) .Returns(name); var filePanelViewModelMock = new Mock <IFilesPanelViewModel>(); var fileOperationsMediatorMock = new Mock <IFilesOperationsMediator>(); fileOperationsMediatorMock .SetupGet(m => m.ActiveFilesPanelViewModel) .Returns(filePanelViewModelMock.Object); var viewModel = new DriveViewModel(fileSizeFormatterMock.Object, pathServiceMock.Object, fileOperationsMediatorMock.Object, driveModel); Assert.Equal(name, viewModel.DriveName); Assert.Equal("21", viewModel.AvailableSizeAsNumber); Assert.Equal("21 B", viewModel.AvailableFormattedSize); Assert.Equal("42", viewModel.TotalSizeAsNumber); Assert.Equal("42 B", viewModel.TotalFormattedSize); }
private static MountedDriveEventArgs CreateFrom(DriveModel driveModel) => new MountedDriveEventArgs(driveModel);
// ============================================= // File Import / Copy Functions // ============================================= public void ReportDrives(DriveModel[] driveModels) { var client = InitializeClient(); client.ReportDrives(_serverKey, driveModels); }
private static bool CheckIfDiffer(DriveModel oldDriveModel, DriveModel newDriveModel) => oldDriveModel.Name != newDriveModel.Name || oldDriveModel.FreeSpaceBytes != newDriveModel.FreeSpaceBytes || oldDriveModel.TotalSpaceBytes != newDriveModel.TotalSpaceBytes;
private static void Update(DriveModel driveModel, DriveModel newDriveModel) { driveModel.Name = newDriveModel.Name; driveModel.FreeSpaceBytes = newDriveModel.FreeSpaceBytes; driveModel.TotalSpaceBytes = newDriveModel.TotalSpaceBytes; }