private void Create_Click(object sender, RoutedEventArgs e) { var name = NewSnippetName.Text; if (!name.EndsWith(FileExtensions.TypeExtension)) { name += FileExtensions.TypeExtension; } var newType = new POSHToolbeltType(); newType.HasMultipleValues = true; newType.Name = name.Substring(0, name.LastIndexOf(FileExtensions.TypeExtension)); var fileText = JsonConvert.SerializeObject(newType, Formatting.Indented); var fileAttributes = File.GetAttributes(_Path); if (fileAttributes.HasFlag(FileAttributes.Directory)) { File.WriteAllText(Path.Combine(_Path, name), fileText); } else { var directory = Path.GetDirectoryName(_Path); File.WriteAllText(Path.Combine(directory, name), fileText); } FileBrowserService.RefreshTreeView(); Close(); }
private void Open_Click(object sender, RoutedEventArgs e) { var dialog = new CommonOpenFileDialog(); dialog.Title = "My Title"; dialog.Filters.Add(new CommonFileDialogFilter("POSH Toolbelt Project", ".ptproj")); dialog.AddToMostRecentlyUsedList = false; dialog.AllowNonFileSystemItems = false; dialog.EnsureFileExists = true; dialog.EnsurePathExists = true; dialog.EnsureReadOnly = false; dialog.EnsureValidNames = true; dialog.Multiselect = false; dialog.ShowPlacesList = true; var result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { var projectPath = dialog.FileName; FolderTree.Items.Add(FileBrowserService.Open(projectPath)); var historyService = new ApplicationHistoryService(); var history = historyService.GetApplicationHistory(); history.MostRecentOpenedProject = projectPath; historyService.SaveApplicationHistory(history); } }
public async void OpenFileBrowserTest() { var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(); FileBrowserService service = new FileBrowserService(); var openParams = new FileBrowserOpenParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ExpandPath = "", FileFilters = new[] { "*" } }; var efv = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserOpenedNotification.Type, eventParams => { Assert.True(eventParams.Succeeded); Assert.NotNull(eventParams.FileTree); Assert.NotNull(eventParams.FileTree.RootNode); Assert.NotNull(eventParams.FileTree.RootNode.Children); Assert.True(eventParams.FileTree.RootNode.Children.Count > 0); }) .Complete(); await service.RunFileBrowserOpenTask(openParams, efv.Object); efv.Validate(); }
private void Create_Click(object sender, RoutedEventArgs e) { var directoryName = NewFolderName.Text; Directory.CreateDirectory(Path.Join(_Path, directoryName)); FileBrowserService.RefreshTreeView(); Close(); }
private void selectImage_Click(object sender, RoutedEventArgs e) { var service = new FileBrowserService(); if (service.GetImageFile(out file)) { tb4Path.Text = file; } }
public AdminViewModel(PageManager pageservice, AllDbContext dbContext, Validator validator, OrderService orderService, FileBrowserService fileBrowser, MapperService mapper) : base(pageservice) { this.dbContext = dbContext; this.validator = validator; this.orderService = orderService; this.fileBrowser = fileBrowser; this.mapper = mapper; Init(); }
public MainWindow() { InitializeComponent(); MainWindowHelper.MainWindow = this; var historyService = new ApplicationHistoryService(); var history = historyService.GetApplicationHistory(); if (!String.IsNullOrEmpty(history.MostRecentOpenedProject)) { if (File.Exists(history.MostRecentOpenedProject)) { FolderTree.Items.Add(FileBrowserService.Open(history.MostRecentOpenedProject)); } } }
public async void HandleFileBrowserCloseRequestTest() { var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(); FileBrowserService service = new FileBrowserService(); var requestContext = new Mock <RequestContext <FileBrowserCloseResponse> >(); requestContext.Setup(x => x.SendResult(It.IsAny <FileBrowserCloseResponse>())).Returns(Task.FromResult(new object())); var inputParams = new FileBrowserCloseParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri }; await service.HandleFileBrowserCloseRequest(inputParams, requestContext.Object); requestContext.Verify(x => x.SendResult(It.Is <FileBrowserCloseResponse>(p => p.Succeeded == true))); }
public async void HandleFileBrowserValidateRequestTest() { var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(); FileBrowserService service = new FileBrowserService(); var requestContext = new Mock <RequestContext <bool> >(); requestContext.Setup(x => x.SendResult(It.IsAny <bool>())).Returns(Task.FromResult(new object())); var inputParams = new FileBrowserValidateParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ServiceType = "" }; await service.HandleFileBrowserValidateRequest(inputParams, requestContext.Object); requestContext.Verify(x => x.SendResult(It.Is <bool>(p => p == true))); }
public async void HandleFileBrowserOpenRequestTest() { var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(); FileBrowserService service = new FileBrowserService(); var openRequestContext = new Mock <RequestContext <bool> >(); openRequestContext.Setup(x => x.SendResult(It.IsAny <bool>())) .Returns(Task.FromResult(new object())); var openParams = new FileBrowserOpenParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ExpandPath = "", FileFilters = new string[1] { "*" } }; await service.HandleFileBrowserOpenRequest(openParams, openRequestContext.Object); openRequestContext.Verify(x => x.SendResult(It.Is <bool>(p => p == true))); }
public async void ValidateSelectedFilesWithNullValidatorTest() { var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(); FileBrowserService service = new FileBrowserService(); var validateParams = new FileBrowserValidateParams { // Do not pass any service so that the file validator will be null ServiceType = "", OwnerUri = liveConnection.ConnectionInfo.OwnerUri, SelectedFiles = new[] { "" } }; var efv = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.True(eventParams.Succeeded)) .Complete(); // Validate files with null file validator await service.RunFileBrowserValidateTask(validateParams, efv.Object); efv.Validate(); }
private void Create_Click(object sender, RoutedEventArgs e) { var name = NewProjectName.Text; if (!name.EndsWith(".ptproj")) { name = name + ".ptproj"; } var newProject = new POSHToolbeltProject(); newProject.Name = name.Substring(0, name.LastIndexOf(".ptproj")); var newFilePath = Path.Combine(_Path, name); File.WriteAllText(newFilePath, ""); var rootNode = FileBrowserService.Open(newFilePath); MainWindowHelper.SetRootTreeNode(rootNode); Close(); }
public async void InvalidFileValidationTest() { FileBrowserService service = new FileBrowserService(); service.RegisterValidatePathsCallback("TestService", ValidatePaths); var validateParams = new FileBrowserValidateParams { // Do not pass any service so that the file validator will be null ServiceType = "TestService", SelectedFiles = new[] { "" } }; var efv = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.False(eventParams.Succeeded)) .Complete(); // Validate files with null file validator await service.RunFileBrowserValidateTask(validateParams, efv.Object); // Verify complete notification event was fired and the result efv.Validate(); }
//[Fact] public async void BackupFileBrowserTest() { string databaseName = "testfilebrowser_" + new Random().Next(10000000, 99999999); SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName); // Initialize backup service var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName); DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true); SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo); DisasterRecoveryService disasterRecoveryService = new DisasterRecoveryService(); BackupConfigInfo backupConfigInfo = disasterRecoveryService.GetBackupConfigInfo(helper.DataContainer, sqlConn, sqlConn.Database); // Create backup file string backupPath = Path.Combine(backupConfigInfo.DefaultBackupFolder, databaseName + ".bak"); string query = $"BACKUP DATABASE [{databaseName}] TO DISK = N'{backupPath}' WITH NOFORMAT, NOINIT, NAME = N'{databaseName}-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"; await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, "master", query); FileBrowserService service = new FileBrowserService(); string[] backupFilters = new string[2] { "*.bak", "*.trn" }; var openParams = new FileBrowserOpenParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ExpandPath = backupConfigInfo.DefaultBackupFolder, FileFilters = backupFilters }; var openBrowserEventFlowValidator = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserOpenedNotification.Type, eventParams => { Assert.True(eventParams.Succeeded); Assert.NotNull(eventParams.FileTree); Assert.NotNull(eventParams.FileTree.RootNode); Assert.NotNull(eventParams.FileTree.RootNode.Children); Assert.True(eventParams.FileTree.RootNode.Children.Count > 0); Assert.True(ContainsFileInTheFolder(eventParams.FileTree.SelectedNode, backupPath)); }) .Complete(); await service.RunFileBrowserOpenTask(openParams, openBrowserEventFlowValidator.Object); // Verify complete notification event was fired and the result openBrowserEventFlowValidator.Validate(); var expandParams = new FileBrowserExpandParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ExpandPath = backupConfigInfo.DefaultBackupFolder }; var expandEventFlowValidator = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserExpandedNotification.Type, eventParams => { Assert.True(eventParams.Succeeded); Assert.NotNull(eventParams.Children); Assert.True(eventParams.Children.Length > 0); }) .Complete(); // Expand the node in file browser await service.RunFileBrowserExpandTask(expandParams, expandEventFlowValidator.Object); // Verify result expandEventFlowValidator.Validate(); var validateParams = new FileBrowserValidateParams { OwnerUri = liveConnection.ConnectionInfo.OwnerUri, ServiceType = FileValidationServiceConstants.Backup, SelectedFiles = new[] { backupPath } }; var validateEventFlowValidator = new EventFlowValidator <bool>() .AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.True(eventParams.Succeeded)) .Complete(); // Validate selected files in the browser await service.RunFileBrowserValidateTask(validateParams, validateEventFlowValidator.Object); // Verify complete notification event was fired and the result validateEventFlowValidator.Validate(); // Remove the backup file if (File.Exists(backupPath)) { File.Delete(backupPath); } }