public MainWindowViewModel() { DisplayMessageCommand = new MessageCommand(DisplayMessage); CloseAppCommand = new CloseAppCommand(ShutdownApp); AddInstructionCommand = new AddInstructionCommand(AddInstruction); VerifyProgramCommand = new VerifyProgramCommand(VerifyProgram); ConsoleInputCommand = new ConsoleInputCommand(ConsoleInput); ArduinoHandler = new ArduinoHandler(); SaveFileCommand = new SaveFileCommand(SaveFile); LoadProgramCommand = new LoadProgramCommand(LoadProgramFile); ibm = new InstructionBlockModel(); }
private void GameFilePropertyChanged(object sender, PropertyChangedEventArgs e) { if ("IsModified".Equals(e.PropertyName)) { RaisePropertyChanged(() => IsModified); RaisePropertyChanged(() => Title); SaveFileCommand.RaiseCanExecuteChanged(); } else if ("FileName".Equals(e.PropertyName)) { RaisePropertyChanged(() => Title); } }
public void SaveCommand_Executed(object sender, RoutedEventArgs e) { SaveFileDialog mSaveFileDialog = new SaveFileDialog(); mSaveFileDialog.Filter = "XML Files (*.xml)|*.xml|All files (*.*)|*.*"; //mSaveFileDialog.InitialDirectory = @ToDoApplication.FOLDER_LOCATION; if (mSaveFileDialog.ShowDialog() == true) { string path = mSaveFileDialog.FileName; SaveFileCommand SaveFileCommand = new SaveFileCommand(this, path); SaveFileCommand.Execute(); this.ViewableTasks.View.Refresh(); } }
public async Task SaveFile(SaveFileCommand command) { EnsureArg.IsNotNull(command); var dirpath = Path.Combine(settings.FileStorageRootPath, command.Username); Directory.CreateDirectory(dirpath); using (var fileStream = new FileStream(Path.Combine(dirpath, command.DataFileId.ToString()), FileMode.Create)) { command.Content.Position = 0; await command.Content.CopyToAsync(fileStream); } }
/// <summary> /// Handles UI buttons and activates the command pattern /// </summary> private async void UserActionClick(object sender, RoutedEventArgs e) { if (sender is AppBarButton button) { IUserActionCommand cmd = null; switch (button.Name) { case "OpenButton": cmd = new OpenFileCommand(this); break; case "SaveButton": cmd = new SaveFileCommand(); break; case "RedoButton": cmd = new RedoCommand(this); break; case "UndoButton": cmd = new UndoCommand(this); break; case "GroupButton": cmd = new GroupCommand(this); break; case "UnGroupButton": cmd = new UnGroupCommand(this); break; case "DeleteButton": cmd = new DeleteItemCommand(this); break; } if (cmd != null) { cmd.RedoStack = _redoStack; cmd.UndoStack = _undoStack; cmd.ShapeList = _shapeList; await _userInvoker.InvokeUserActionAsync(cmd); } } }
public ScriptPageViewModel(string filePath) { FilePath = filePath; RunOptions = new RunOptions(); SaveFileCommand = new SaveFileCommand(SaveFile); RunScriptCommand = new RunScriptCommand(RunScript); SetOutputTextFileCommand = new SetOutputTextFileCommand(SetOutputTextFilePath); SetOutputImageDirectoryCommand = new SetOutputImageDirectoryCommand(SetOutputImageDirectoryPath); SetWebDriverPathCommand = new SetWebDriverPathCommand(SetWebDriverPath); ClearOutputTextFilePathCommand = new ClearInputStringCommand(ClearOutputTextFilePath); ClearOutputImageDirectoryPathCommand = new ClearInputStringCommand(ClearOutputImageDirectoryPath); ClearWebDriverPathCommand = new ClearInputStringCommand(ClearWebDriverPath); StopScriptCommand = new StopScriptCommand(StopScript); TryOpenSelf(); }
private void ToolbarButton_Click(object sender, RoutedEventArgs e) { try { switch ((sender as FrameworkElement).Tag.ToString().Replace("toolbar.", "")) { case "new": NewFileCommand.Execute(null); break; case "open": OpenFileCommand.Execute(null); break; case "save": SaveFileCommand.Execute(null); break; case "cut": CutCommand.Execute(null); break; case "copy": CopyCommand.Execute(null); break; case "paste": PasteCommand.Execute(null); break; case "build": BuildRunCommand.Execute(false); break; case "buildrun": BuildRunCommand.Execute(true); break; case "close": CloseTabCommand.Execute(null); break; } } catch (Exception ex) { Debug.Fail(ex.Message); } }
bool OrganizerHasChanged() { if (OrganizerVM != null && OrganizerVM.HasChanged) { var r = System.Windows.MessageBox.Show("Save changes?", "There are unsaved changes. Save first?", System.Windows.MessageBoxButton.YesNoCancel); if (r == System.Windows.MessageBoxResult.Yes) { SaveFileCommand.Execute(null); if (OrganizerVM.HasChanged) { return(true); } } else if (r == System.Windows.MessageBoxResult.Cancel) { return(true); } } return(false); }
/// <summary> /// Checks wether or not the currently loaded Controller has changes. If it does, /// the method offers the user to save them. /// </summary> /// <returns>True if there are unsaved changes, false if there are not or if /// the user decides to discard them.</returns> public bool ControllerHasChanged() { if (ControllerVM != null && ControllerVM.HasChanged) { System.Windows.MessageBoxResult r = System.Windows.MessageBox.Show("Wijzigingen opslaan?", "De regeling is gewijzigd. Opslaan?", System.Windows.MessageBoxButton.YesNoCancel); if (r == System.Windows.MessageBoxResult.Yes) { SaveFileCommand.Execute(null); if (ControllerVM.HasChanged) { return(true); } } else if (r == System.Windows.MessageBoxResult.Cancel) { return(true); } } return(false); }
public void SaveCommand_Executed(object sender, RoutedEventArgs e) { SaveFileDialog mSaveFileDialog = new SaveFileDialog(); mSaveFileDialog.Filter = "XML Files (*.xml)|*.xml|All files (*.*)|*.*"; if (mSaveFileDialog.ShowDialog() == true) { string path = mSaveFileDialog.FileName; System.Threading.Tasks.Task.Factory.StartNew(() => { try { SaveFileCommand SaveFileCommand = new SaveFileCommand(this, path); SaveFileCommand.Execute(); } catch (AggregateException error) { MessageBox.Show(error.Message); } }).Wait(); MessageBox.Show("Save Completed!", "Save", MessageBoxButton.OK, MessageBoxImage.Information); } }
public async Task <SaveFileCommandResponse> SaveAsync(SaveFileCommand command) { var user = await userContext.GetCurrentUserAsync(); var dataSize = await dbContext.Files.Where(x => x.UserId == user.Id).SumAsync(x => (double)x.Size / 1048576); if (dataSize + (double)command.Stream.Length / 1048576 > 100) { return(null); } var putResult = await objectStorage.PutAsync( new Models.ObjectPutParams { ContentType = command.ContentType, FileName = command.Name }, command.Stream); var file = new File { Address = putResult.Key, Name = command.Name, Size = (int)command.Stream.Length, ContentType = command.ContentType, UserId = user.Id }; await dbContext.Files.AddAsync(file); await dbContext.SaveChangesAsync(); return(new SaveFileCommandResponse { Id = file.Id, ContentType = file.ContentType, Name = file.Name, Size = file.Size }); }
public async Task <BaseResponse <SaveFileCommandResponse> > UpdloadFileAsync(IFormFile file) { using var command = new SaveFileCommand { Name = file.FileName, ContentType = file.ContentType, Stream = file.OpenReadStream() }; var result = await fileService.SaveAsync(command); if (result == null) { return new BaseResponse <SaveFileCommandResponse> { Error = "Превышен допустимый лимит занимаемого пространства" } } ; return(new BaseResponse <SaveFileCommandResponse> { Result = result }); }
public void SaveMappingsFile(object sender, RoutedEventArgs arguments) { var saveCommand = new SaveFileCommand(_current); saveCommand.Execute(arguments); }
public void Init(IModuleData moduleData) { parentData = moduleData; /* * if (File.Exists(DefaultFilePath)) * { * DefaultEditorText = File.ReadAllText(DefaultFilePath); * } * else if(FileCommands.IsValidPath(DefaultFilePath) && !String.IsNullOrEmpty(DefaultEditorText)) * { * File.WriteAllText(DefaultFilePath, DefaultEditorText); * } */ if (String.IsNullOrWhiteSpace(FilePath)) { InitialDirectory = DefaultPaths.ModuleTemplatesFolder(parentData); FilePath = Path.Combine(InitialDirectory, DefaultFileName); } else { InitialDirectory = Directory.GetParent(FilePath).FullName + @"\"; } if (DefaultEditorText == null) { DefaultEditorText = ""; } if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(DefaultFileName)) { Name = DefaultFileName; } if (File.Exists(FilePath)) { EditorText = File.ReadAllText(FilePath); Log.Here().Important("Loaded {0} template file at {1}", Name, FilePath); } else { EditorText = DefaultEditorText; Log.Here().Warning("Template file {0} not found at {1}. Using default template.", Name, FilePath); } if (String.IsNullOrEmpty(OpenFileText)) { OpenFileText = "Select " + LabelText; } SaveAsText = "Save " + Name + " As..."; OpenCommand = new ParameterCommand((object param) => { if (param is string FileLocationText) { FilePath = FileLocationText; FileCommands.Save.SaveModuleSettings(parentData); EditorText = FileCommands.ReadFile(FilePath); } }); SaveCommand = new SaveFileCommand(OnSave, OnSaveAs); SaveAsCommand = new SaveFileAsCommand(OnSaveAs); if (!File.Exists(FilePath) && FileCommands.IsValidPath(FilePath) && !String.IsNullOrWhiteSpace(EditorText)) { FileCommands.WriteToFile(filePath, EditorText); } }
public GlobalViewModel() { LoadFileCommand = new LoadFileCommand(this); SaveFileCommand = new SaveFileCommand(); }