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); }
public bool CloseAll() { lock (Machines) { foreach (IMachine machine in Machines) { if (!(machine is IPersistableMachine persistableMachine) || persistableMachine.PersistantFilepath != null) { continue; } ConfirmCloseEventArgs args = new ConfirmCloseEventArgs("There are machines which haven't been persisted yet. Are you sure you want to exit?"); ConfirmClose?.Invoke(this, args); if (!args.Result) { return(false); } break; } List <IMachine> machines = Machines.ToList(); foreach (IMachine machine in machines) { Close(machine, false); } } return(true); }