static void VerifyService(ISaveFileDialogService service) { if (service == null) { throw new ArgumentNullException("service"); } }
public void DefaultValues() { SaveFileDialogService service = new SaveFileDialogService(); Assert.AreEqual(true, service.AddExtension); Assert.AreEqual(true, service.AutoUpgradeEnabled); Assert.AreEqual(false, service.CheckFileExists); Assert.AreEqual(true, service.CheckPathExists); Assert.AreEqual(false, service.CreatePrompt); Assert.AreEqual(true, service.DereferenceLinks); Assert.AreEqual(string.Empty, service.InitialDirectory); Assert.AreEqual(true, service.OverwritePrompt); Assert.AreEqual(false, service.RestoreDirectory); Assert.AreEqual(false, service.ShowHelp); Assert.AreEqual(false, service.SupportMultiDottedExtensions); Assert.AreEqual(string.Empty, service.Title); Assert.AreEqual(true, service.ValidateNames); Assert.AreEqual(string.Empty, service.DefaultExt); Assert.AreEqual(string.Empty, service.DefaultFileName); Assert.AreEqual(string.Empty, service.Filter); Assert.AreEqual(1, service.FilterIndex); ISaveFileDialogService iService = service; Assert.IsNull(iService.File); Assert.AreEqual(string.Empty, iService.SafeFileName()); }
/// <summary> /// Constructor using dependency injection /// </summary> public MainWindowViewModel( ICustomerRepository customerRepository, IProductRepository productRepository, IUpdateService updateService, IMessageBoxService messageBoxService, IAppDialogService appDialogService, IOpenFileDialogService openFileDialogService, ISaveFileDialogService saveFileDialogService, ILocalizationService localizationService) : base(localizationService) { _customerRepository = customerRepository; _productRepository = productRepository; _updateService = updateService; _messageBoxService = messageBoxService; _appDialogService = appDialogService; _openFileDialogService = openFileDialogService; _saveFileDialogService = saveFileDialogService; OpenFileCommand = new RelayCommand(OpenFileDialog); SaveFileCommand = new RelayCommand(SaveFileDialog); CloseCommand = new RelayCommand(OnRequestClose); OpenAboutCommand = new RelayCommand(OpenAboutDialog); OpenLanguageOptionsCommand = new RelayCommand(OpenLanguageOptions); UpdateCommand = new RelayCommand(Update); }
public CashGameViewModel(ICashGameService cashGameService, ISessionRepository sessionRepository, IOpenFileDialogService openFileDialogService, ISaveFileDialogService saveFileDialogService, IWaitDialogService waitDialogService, IFilterWindowService filterWindowService, IInfoDialogService infoDialogService) { _cashGameService = cashGameService; _sessionRepository = sessionRepository; _openFileDialogService = openFileDialogService; _saveFileDialogService = saveFileDialogService; _waitDialogService = waitDialogService; _filterWindowService = filterWindowService; _infoDialogService = infoDialogService; OpenFileCommand = new RelayCommand(OpenFile); FetchFromServerCommand = new RelayCommand(FetchFromServer); ClearCommand = new RelayCommand(() => UserSessionId = ""); SaveSessionsCommand = new RelayCommand(SaveSessions); ClearSessionsCommand = new RelayCommand(ClearSessions); ShowSessionsOnlyCommand = new RelayCommand <bool>(ShowSessionsOnly); FilterCommand = new RelayCommand(FilterSessions); UserSessionId = "Liitä wcusersessionid tähän"; Messenger.Default.Register <UserSessionIdChangedMessage>(this, message => { if (message.Sender != this && message.NewUserSessionId != _userSessionId) { UserSessionId = message.NewUserSessionId; } }); LoadStoredSessions(); if (_sessionRepository.GetAll().Count > 0) { StartDate = PlayingSessions.Max(s => s.StartTime); FilterViewModel = new FilterViewModel(_sessionRepository.GetAll().Min(s => s.StartTime), _sessionRepository.GetAll().Max(s => s.EndTime)); } else { StartDate = new DateTime(2010, 11, 1); FilterViewModel = new FilterViewModel(); } EndDate = DateTime.Now; Filter = new CashGameFilter(); }
public static string GetFullFileName(this ISaveFileDialogService service) { VerifyService(service); if (service.File == null) { return(string.Empty); } string directory = service.File.DirectoryName; if (!directory.EndsWith(@"\")) { directory += @"\"; } return(directory + service.File.Name); }
/// <summary> /// Save results into a file /// </summary> /// <param name = "param">Parameter</param> private void SaveResults(object param) { if (Sets.Length > 0) { int totalItems = Sets.Sum(set => set.Count) + 1; object[][] array = new object[totalItems][]; int i = 0; int setId = 0; array[i] = new object[4]; array[i][0] = "Set ID"; array[i][1] = "Path"; array[i][2] = "Artist"; array[i][3] = "Title"; i++; foreach (HashSet <TrackData> set in Sets) { foreach (TrackData track in set) { array[i] = new object[4]; array[i][0] = setId; array[i][1] = track.Album; array[i][2] = track.Artist; array[i][3] = track.Title; i++; } setId++; } ISaveFileDialogService sfd = GetService <ISaveFileDialogService>(); if (sfd != null) { if (sfd.SaveFile("Save result", "results.csv", "(*.csv)|*.csv") == DialogResult.OK) { string path = sfd.Filename; if (!string.IsNullOrEmpty(path)) { CSVWriter writer = new CSVWriter(path); writer.Write(array); } } } } }
public TournamentViewModel(ITournamentService tournamentService, ITournamentRepository tournamentRepository, IOpenFileDialogService openFileDialogService, ISaveFileDialogService saveFileDialogService, IWaitDialogService waitDialogService, IInfoDialogService infoDialogService) { _tournamentService = tournamentService; _tournamentRepository = tournamentRepository; _openFileDialogService = openFileDialogService; _saveFileDialogService = saveFileDialogService; _waitDialogService = waitDialogService; _infoDialogService = infoDialogService; FetchFromServerCommand = new RelayCommand(FetchFromServer); ClearTournamentsCommand = new RelayCommand(ClearTournaments); ClearCommand = new RelayCommand(() => UserSessionId = ""); SaveTournamentsCommand = new RelayCommand(SaveTournaments); UserSessionId = "Liitä wcusersessionid tähän"; Messenger.Default.Register <UserSessionIdChangedMessage>(this, message => { if (message.Sender != this && message.NewUserSessionId != _userSessionId) { UserSessionId = message.NewUserSessionId; } }); LoadStoredTournaments(); if (_tournamentRepository.GetAll().Count > 0) { StartDate = Tournaments.Max(t => t.StartTime); } else { StartDate = new DateTime(2010, 11, 1); } EndDate = DateTime.Now; }
/// <summary> /// Exports data grid to Excel /// </summary> /// <param name="type"></param> public void ExportAction(object parameter, object view, object dialogService = null, object exService = null) //ExportCommand { string fn; try { if (dialogService is ISaveFileDialogService) { ISaveFileDialogService saveFileDialogService = dialogService as ISaveFileDialogService; IExportService exportService = exService as IExportService; TableView tv = view as TableView; Enum.TryParse(parameter.ToString(), out ExportType type); switch (type) { case ExportType.PDF: saveFileDialogService.Filter = "PDF files|*.pdf"; if (saveFileDialogService.ShowDialog()) { fn = saveFileDialogService.GetFullFileName(); } exportService.ExportToPDF(tv, saveFileDialogService.GetFullFileName()); break; case ExportType.XLSX: saveFileDialogService.Filter = "Excel 2007 files|*.xlsx"; if (saveFileDialogService.ShowDialog()) { exportService.ExportToXLSX(tv, saveFileDialogService.GetFullFileName()); } break; } } } catch (Exception ex) { MessageBox.Show("Error exporting data:" + ex.Message); } }
public static Stream OpenFile(this ISaveFileDialogService service) { VerifyService(service); return(service.File.Return(x => x.Open(FileMode.Create, FileAccess.Write), () => null)); }
public static string SafeFileName(this ISaveFileDialogService service) { VerifyService(service); return(service.File.Return(x => x.Name, () => string.Empty)); }
public static bool ShowDialog(this ISaveFileDialogService service, Action <CancelEventArgs> fileOK = null, IFileInfo fileInfo = null) { VerifyService(service); return(service.ShowDialog(fileOK, fileInfo.With(x => x.DirectoryName), fileInfo.With(x => x.Name))); }
static void VerifyService(ISaveFileDialogService service) { if(service == null) throw new ArgumentNullException("service"); }