Exemple #1
0
        public bool Close(IMachine coreMachine, bool prompt)
        {
            if (coreMachine == null)
            {
                return(false);
            }

            IPersistableMachine pm = coreMachine as IPersistableMachine;
            bool remove            = pm == null;

            if (pm != null && pm.PersistantFilepath == null)
            {
                if (prompt)
                {
                    ConfirmCloseEventArgs args = new ConfirmCloseEventArgs(String.Format("Are you sure you want to close the \"{0}\" machine without persisting it?", coreMachine.Name));
                    ConfirmClose?.Invoke(this, args);

                    if (!args.Result)
                    {
                        return(false);
                    }
                }

                remove = true;
            }

            if (remove)
            {
                _model.RemoveMachine(coreMachine);
            }

            coreMachine.Close();

            return(true);
        }
Exemple #2
0
        public void Persist(IPersistableMachine machine)
        {
            if (machine == null)
            {
                throw new ArgumentNullException(nameof(machine));
            }

            if (!String.IsNullOrEmpty(machine.PersistantFilepath))
            {
                // Should throw exception here?
                return;
            }

            PromptForFileEventArgs args = new PromptForFileEventArgs(FileTypes.Machine, false);

            PromptForFile?.Invoke(this, args);

            string filepath = args.Filepath;

            machine.Persist(_fileSystem, filepath);
        }
Exemple #3
0
        public MainViewModel(ISettings settings, IFileSystem fileSystem)
        {
            _settings   = settings;
            _fileSystem = fileSystem;

            InitModel(new MainModel(settings, fileSystem));

            _machineServer = new MachineServerListener(Machines.Where(m => m.Core != null));

            LoadRecentServersSetting();

            ActiveMachine = null;

            _openMachineCommand = new Command(
                p => OpenMachine(),
                p => true
                );

            _newMachineCommand = new Command(
                p => NewMachine(),
                p => true
                );

            _startServerCommand = new Command(
                p => StartServer(6128),
                p => true
                );

            _stopServerCommand = new Command(
                p => StopServer(),
                p => true
                );

            _connectCommand = new Command(
                p => Connect(p as ServerInfo),
                p => true
                );

            _removeCommand = new Command(
                p =>
            {
                IMachine machine = p as IMachine;
                if (Close(machine, true))
                {
                    _model.RemoveMachine(machine);
                }
            },
                p =>
            {
                IPersistableMachine pm = p as IPersistableMachine;
                return(pm?.PersistantFilepath != null);
            }
                );

            _closeCommand = new Command(
                p => Close(p as IMachine, true),
                p => (p as IMachine)?.CanClose ?? false
                );

            _openCommand = new Command(
                p => (p as IPersistableMachine)?.OpenFromFile(_fileSystem),
                p => !(p as IPersistableMachine)?.IsOpen ?? false
                );

            _persistCommand = new Command(
                p => Persist(p as IPersistableMachine),
                p =>
            {
                IPersistableMachine pm = p as IPersistableMachine;
                if (pm != null)
                {
                    return(pm.PersistantFilepath == null);
                }

                return(false);
            });

            _pauseCommand = new Command(
                p => (p as IPausableMachine)?.Stop(),
                p => (p as IPausableMachine)?.CanStop ?? false
                );

            _resumeCommand = new Command(
                p => (p as IPausableMachine)?.Start(),
                p => (p as IPausableMachine)?.CanStart ?? false
                );

            _resetCommand = new Command(
                p => (p as IInteractiveMachine)?.Reset(),
                p => p is IInteractiveMachine
                );

            _driveACommand = new Command(
                p => LoadDisc(p as IInteractiveMachine, 0),
                p => p is IInteractiveMachine
                );

            _driveAEjectCommand = new Command(
                p => (p as IInteractiveMachine)?.LoadDisc(0, null),
                p => p is IInteractiveMachine
                );

            _driveBCommand = new Command(
                p => LoadDisc(p as IInteractiveMachine, 1),
                p => p is IInteractiveMachine
                );

            _driveBEjectCommand = new Command(
                p => (p as IInteractiveMachine)?.LoadDisc(1, null),
                p => p is IInteractiveMachine
                );

            _tapeCommand = new Command(
                p => LoadTape(p as IInteractiveMachine),
                p => p is IInteractiveMachine
                );

            _tapeEjectCommand = new Command(
                p => (p as IInteractiveMachine)?.LoadTape(null),
                p => p is IInteractiveMachine
                );

            _toggleRunningCommand = new Command(
                p => (p as IPausableMachine)?.ToggleRunning(),
                p => p is IPausableMachine
                );

            _addBookmarkCommand = new Command(
                p => (p as IBookmarkableMachine)?.AddBookmark(false),
                p => p is IBookmarkableMachine
                );

            _jumpToMostRecentBookmarkCommand = new Command(
                p => (p as IJumpableMachine)?.JumpToMostRecentBookmark(),
                p => p is IJumpableMachine
                );

            _browseBookmarksCommand = new Command(
                p => SelectBookmark(p as IJumpableMachine),
                p => p is IJumpableMachine
                );

            _compactCommand = new Command(
                p => (p as ICompactableMachine)?.Compact(_fileSystem),
                p => (p as ICompactableMachine)?.CanCompact() ?? false
                );

            _renameCommand = new Command(
                p => RenameMachine(p as IMachine),
                p => p is IMachine
                );

            _seekToNextBookmarkCommand = new Command(
                p => (p as IPrerecordedMachine)?.SeekToNextBookmark(),
                p => p is IPrerecordedMachine
                );

            _seekToPrevBookmarkCommand = new Command(
                p => (p as IPrerecordedMachine)?.SeekToPreviousBookmark(),
                p => p is IPrerecordedMachine
                );

            _seekToStartCommand = new Command(
                p => (p as IPrerecordedMachine)?.SeekToStart(),
                p => p is IPrerecordedMachine
                );

            _reverseStartCommand = new Command(
                p => (p as IReversibleMachine)?.Reverse(),
                p => p is IReversibleMachine
                );

            _reverseStopCommand = new Command(
                p => (p as IReversibleMachine)?.ReverseStop(),
                p => p is IReversibleMachine
                );

            _toggleSnapshotCommand = new Command(
                p => (p as IReversibleMachine)?.ToggleReversibilityEnabled(),
                p => p is IReversibleMachine
                );
        }