Exemplo n.º 1
0
 internal async Task HandleFileBrowserExpandRequest(FileBrowserExpandParams fileBrowserParams, RequestContext <bool> requestContext)
 {
     try
     {
         var task = Task.Run(() => RunFileBrowserExpandTask(fileBrowserParams, requestContext))
                    .ContinueWithOnFaulted(null);
         await requestContext.SendResult(true);
     }
     catch (Exception ex)
     {
         Logger.Write(TraceEventType.Error, "Unexpected exception while handling file browser expand request: " + ex.Message);
         await requestContext.SendResult(false);
     }
 }
Exemplo n.º 2
0
        public async void HandleFileBrowserExpandRequestTest()
        {
            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 FileBrowserExpandParams
            {
                OwnerUri   = liveConnection.ConnectionInfo.OwnerUri,
                ExpandPath = ""
            };

            await service.HandleFileBrowserExpandRequest(inputParams, requestContext.Object);

            requestContext.Verify(x => x.SendResult(It.Is <bool>(p => p == true)));
        }
Exemplo n.º 3
0
        internal async Task RunFileBrowserExpandTask(FileBrowserExpandParams fileBrowserParams, RequestContext <bool> requestContext)
        {
            FileBrowserExpandedParams result = new FileBrowserExpandedParams();

            try
            {
                FileBrowserOperation operation = null;
                ConnectionInfo       connInfo;
                ownerToFileBrowserMap.TryGetValue(fileBrowserParams.OwnerUri, out operation);
                this.ConnectionServiceInstance.TryFindConnection(fileBrowserParams.OwnerUri, out connInfo);

                if (operation != null && connInfo != null)
                {
                    QueueItem queueItem = fileBrowserQueue.QueueBindingOperation(
                        key: fileBrowserQueue.AddConnectionContext(connInfo, this.serviceName),
                        bindingTimeout: DefaultTimeout,
                        waitForLockTimeout: DefaultTimeout,
                        bindOperation: (bindingContext, cancelToken) =>
                    {
                        result.ExpandPath = fileBrowserParams.ExpandPath;
                        result.Children   = operation.GetChildren(fileBrowserParams.ExpandPath).ToArray();
                        result.OwnerUri   = fileBrowserParams.OwnerUri;
                        result.Succeeded  = true;
                        return(result);
                    });

                    queueItem.ItemProcessed.WaitOne();

                    if (queueItem.GetResultAsT <FileBrowserExpandedParams>() != null)
                    {
                        result = queueItem.GetResultAsT <FileBrowserExpandedParams>();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            await requestContext.SendEvent(FileBrowserExpandedNotification.Type, result);
        }
Exemplo n.º 4
0
        //[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);
            }
        }