private void LoadFile() { if (!_openFileService.DetermineFile()) { return; } if (_openFileService.File.Extension.ToLower().Equals(".pdf")) { _pdfService.Init(_openFileService.File.FullName); } else { _pdfService.Init(_openFileService.Files .OrderBy(f => f.Name) .Select(f => f.OpenRead()) .ToArray() ); } _characterSheet.SetSheetPreview(); NotifyOfPropertyChange(() => CanExportTemplate); NotifyOfPropertyChange(() => CanImportTemplate); NotifyOfPropertyChange(() => CanSavePdf); //_characterSheet.UpdateFormFields(); ActivateItem(_characterSheet); }
private void SelectSettingsFile() { if (_openFileService.DetermineFile()) { ConfigFilePath = _openFileService.FileName; } }
protected override async Task ExecuteAsync(object parameter) { try { var location = parameter as string; if (string.IsNullOrWhiteSpace(location) || !_fileService.Exists(location)) { _openFileService.Filter = "Text Files (*.csv)|*csv"; _openFileService.IsMultiSelect = false; if (_openFileService.DetermineFile()) { location = _openFileService.FileName; } } if (!string.IsNullOrWhiteSpace(location)) { using (_pleaseWaitService.PushInScope()) { await _projectManager.LoadAsync(location); } } } catch (Exception ex) { Log.Error(ex, "Failed to open file"); } }
private void OnOpenExecute() { if (_openFileService.DetermineFile()) { _recentlyUsedItemsService.AddItem(new RecentlyUsedItem(_openFileService.FileName, DateTime.Now)); } }
private void OpenDocumentCommandEvecute() { try { openFileService.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileService.FileName = ""; openFileService.Filter = "Text|*.txt|All files|*.*"; if (!openFileService.DetermineFile()) { return; } string path = openFileService.FileName; if (string.IsNullOrWhiteSpace(path)) { return; } var document = CreateDocumentViewModel(path); documents.Add(document); SelectedDocument = document; } catch (Exception ex) { messageService.ShowErrorAsync(ex.Message); } }
protected override void Execute(object parameter) { _openFileService.Filter = Commands.DrawingFileFilter; if (_openFileService.DetermineFile()) { _drawingHostServices.PasteFrom(_openFileService.FileName); } }
/// <summary> /// Method to invoke when the SelectFile command is executed. /// </summary> private void OnSelectFileExecute() { if (!string.IsNullOrEmpty(SelectedFile)) { _selectFileService.InitialDirectory = Path.GetFullPath(SelectedFile); } if (_selectFileService.DetermineFile()) { SelectedFile = _selectFileService.FileName; } }
/// <summary> /// Method to invoke when the OpenFile command is executed. /// </summary> private void OpenFile() { _openFileService.Filter = "*.csv|*.csv"; if (!_openFileService.DetermineFile()) { return; } ObservableCollection <Row> items = Items; ObservableCollection <TableViewColumn> columns = Columns; Debug.Assert(items != null); Debug.Assert(columns != null); items.Clear(); columns.Clear(); var reader = new CsvReader(new StreamReader(_openFileService.FileName)); if (!reader.Read()) { return; } for (int i = 0; i < reader.FieldHeaders.Length; i++) { string fieldHeader = reader.FieldHeaders[i]; Columns.Add( new TableViewColumn { Title = fieldHeader, ContextBindingPath = string.Format("Cells[{0}]", i), Padding = new Thickness(0) }); } do { if (reader.CurrentRecord == null) { continue; } var row = new Row(); for (int i = 0; i < Columns.Count; i++) { row.Cells.Add(new StringCell(reader.CurrentRecord[i])); } Items.Add(row); }while (reader.Read()); }
/// <summary> /// Method to invoke when the SelectFile command is executed. /// </summary> private void OnSelectFileExecute() { var initialDirectory = GetInitialDirectory(); if (!string.IsNullOrEmpty(initialDirectory)) { _selectFileService.InitialDirectory = initialDirectory; } if (!string.IsNullOrEmpty(Filter)) { _selectFileService.Filter = Filter; } if (_selectFileService.DetermineFile()) { SelectedFile = _selectFileService.FileName; } }
public void OpenDocument() { try { openFileService.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileService.Filter = "Text|*.txt|All files|*.*"; if (!openFileService.DetermineFile()) { return; } var path = openFileService.File.FullName; var document = documentViewModelFactory(path); Items.Add(document); ActivateItem(document); } catch (Exception ex) { messageService.Show(ex.Message, "Error", icon: MessageImage.Error); } }
private async Task OnLoadConfigurationExecuteAsync() { try { _openFileService.Filter = "Kflop Plot File|*.kfp"; if (!string.IsNullOrEmpty(Config.SavePath)) { _openFileService.InitialDirectory = Path.GetDirectoryName(Config.SavePath); _saveFileService.FileName = Path.GetFileNameWithoutExtension(Config.SavePath); } else { _openFileService.InitialDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Data")); } if (_openFileService.DetermineFile()) { using (var fileStream = File.Open(_openFileService.FileName, FileMode.Open)) { var configuration = new SerializationConfiguration { Culture = new System.Globalization.CultureInfo("en-US") }; Config = PlotConfigurationModel.Load(fileStream, SerializationMode.Xml, configuration); } Config.SavePath = _openFileService.FileName; this.ClearIsDirtyOnAllChilds(); this.IsDirty = false; ViewModelCommandManager.InvalidateCommands(true); LogTo.Info("Loaded Plot configuration from: {0}", Config.SavePath); } } catch (Exception ex) { string errmsg = string.Format("Error loading Plot configuration: {0}", ex.Message); LogTo.Error(errmsg); await Shared.Utility.ShowErrorMsgAsync(this, errmsg); } }