Beispiel #1
0
        public bool IsExist(string filename, string path = null)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                path = UserDirectory.Get();
            }

            var fullpath = PathProvider.Combine(path, filename);

            return(FileProvider.Exist(fullpath) ? true : false);
        }
Beispiel #2
0
 public static string Combine(string path1, string path2)
 {
     if (_provider == null)
     {
         return(Path.Combine(path1, path2));
     }
     return(_provider.Combine(path1, path2));
 }
        /// <summary>
        /// Gets the file Name
        /// </summary>
        /// <returns></returns>
        public string GetFileName()
        {
            var filePath = _pathProvider.Combine(_pathProvider.GetDirectoryPath(), _filePath);
            var fileNameWithExtenstion = _pathProvider.GetFileName(filePath);

            if (!Path.GetExtension(fileNameWithExtenstion).ToLower().Contains(Constants.AllowedFileExtensionsForLogging))
            {
                throw new FormatException(Constants.InvalidFileFormatException);
            }

            if (_frequency == 0)
            {
                return(_pathProvider.Combine(_pathProvider.GetDirectoryPath(), _filePath));
            }

            FormatAndStoreFileNameIfRequired(fileNameWithExtenstion);
            return(_providerFactory.GetPreviousFileName());
        }
Beispiel #4
0
        public async Task <string> CreateDumpAsync(string dumpLocation)
        {
            var dumpFileLocation = dumpLocation;

            if (string.IsNullOrEmpty(dumpFileLocation))
            {
                dumpFileLocation = _reflectionProvider.GetRunningAssemblyPath();
            }
            else
            {
                if (!_directoryProvider.DoesDirectoryExists(dumpLocation))
                {
                    try
                    {
                        _directoryProvider.CreateDirectory(dumpLocation);
                        _consoleProvider.WriteLine($"{dumpLocation} doesn't exists.");
                        _consoleProvider.WriteLine($"{dumpLocation} created.");
                    }
                    catch (IOException e)
                    {
                        _consoleProvider.WriteLine(e.ToString());
                        _consoleProvider.WriteLine($"{dumpLocation} cannot be created.");
                        throw;
                    }
                }
            }

            var exceptionLogs = (await _logRepository.GetAllAsync()).ToList();
            var sb            = new StringBuilder();

            foreach (var exceptionLog in exceptionLogs)
            {
                sb.AppendLine($"{exceptionLog.Date} {exceptionLog.Message} {exceptionLog.Exception}");
            }

            var uniqueFileName = string.Concat(GenerateUniqueText(), ".txt");
            var filePath       = _pathProvider.Combine(dumpFileLocation, uniqueFileName);

            _fileProvider.WriteAllText(filePath, sb.ToString());
            _consoleProvider.WriteLine($"dump file created successfully - {filePath}");

            return(filePath);
        }
Beispiel #5
0
        private IEnumerable <TPluginService> LoadPlugins <TPluginService>()
        {
            string path = _pathProvider.Combine(_reflectionProvider.GetRunningAssemblyPath(), "Plugins");

            if (!_directoryProvider.Exists(path))
            {
                _directoryProvider.CreateDirectory(path);
            }

            var allAssemblies = new List <Assembly>();

            foreach (string dll in _directoryProvider.GetFiles(path, "*.dll"))
            {
                allAssemblies.Add(_assemblyProvider.LoadFile(dll));
            }

            var configuration = new ContainerConfiguration().WithAssemblies(allAssemblies);
            var container     = configuration.CreateContainer();
            var services      = container.GetExports <TPluginService>();

            return(services);
        }
Beispiel #6
0
        private async Task ExecuteTestAgentRunAsync(TestAgentRunDto testAgentRun, int testAgentRunTimeout, CancellationTokenSource cancellationTokenSource)
        {
            _pluginService.ExecuteAllTestAgentPluginsPreTestRunLogic();

            testAgentRun.Status = TestAgentRunStatus.InProgress;
            await CreateEnvironmentVariablesForCustomArgumentsAsync(testAgentRun.TestRunId).ConfigureAwait(false);

            await _testAgentRunRepository.UpdateAsync(testAgentRun.TestAgentRunId, testAgentRun).ConfigureAwait(false);

            var testRun = await _testRunRepository.GetAsync(testAgentRun.TestRunId).ConfigureAwait(false);

            var tempExecutionFolder = _pathProvider.Combine(_pathProvider.GetTempFolderPath(), _guidService.NewGuid().ToString());
            var tempZipFileName     = _pathProvider.GetTempFileName();
            var testRunOutput       = await _testRunOutputServiceClient.GetTestRunOutputByTestRunIdAsync(testRun.TestRunId).ConfigureAwait(false);

            if (testRunOutput == null)
            {
                // DEBUG:
                await _testRunLogService.CreateTestRunLogAsync("The test run output cannot be null.", testAgentRun.TestRunId).ConfigureAwait(false);

                throw new ArgumentException("The test run output cannot be null.");
            }

            _fileProvider.WriteAllBytes(tempZipFileName, testRunOutput.TestOutputFilesPackage);
            _fileProvider.ExtractZip(tempZipFileName, tempExecutionFolder);
            var testRunTestsAssemblyPath = _pathProvider.Combine(tempExecutionFolder, testRun.TestAssemblyName);

            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            var testsResults = await _nativeTestsRunner.ExecuteTestsAsync(
                testRun.TestTechnology,
                testAgentRun.TestList,
                tempExecutionFolder,
                testAgentRun.TestRunId,
                testRunTestsAssemblyPath,
                testRun.TestAssemblyName,
                testRun.RunInParallel,
                testRun.NativeArguments,
                testAgentRunTimeout,
                testRun.IsTimeBasedBalance,
                testRun.SameMachineByClass,
                cancellationTokenSource).ConfigureAwait(false);

            var retriedTestResults = string.Empty;

            if (testRun.RetriesCount > 0)
            {
                retriedTestResults = await _nativeTestsRunner.ExecuteTestsWithRetryAsync(
                    testRun.TestTechnology,
                    testsResults,
                    testAgentRun.TestList,
                    tempExecutionFolder,
                    testAgentRun.TestRunId,
                    testRunTestsAssemblyPath,
                    testRun.TestAssemblyName,
                    testRun.RunInParallel,
                    testRun.NativeArguments,
                    testAgentRunTimeout,
                    testRun.RetriesCount,
                    testRun.Threshold,
                    testRun.IsTimeBasedBalance,
                    testRun.SameMachineByClass,
                    cancellationTokenSource).ConfigureAwait(false);
            }

            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            await CompleteTestAgentRunAsync(testAgentRun.TestAgentRunId, testsResults, retriedTestResults).ConfigureAwait(false);

            _pluginService.ExecuteAllTestAgentPluginsPostTestRunLogic();

            DeleteTempExecutionFolder(tempExecutionFolder);
        }
Beispiel #7
0
        private string BuildTestRunIdFolderPath(Guid testRunId, string sharedOutputFilesLocation)
        {
            var newTestRunDirectoryPath = _pathProvider.Combine(sharedOutputFilesLocation, testRunId.ToString());

            return(newTestRunDirectoryPath);
        }
        private string GetTestCasesHistoryFileNamePath()
        {
            var testCasesHistoryFileNamePath = _pathProvider.Combine(GetAppDataMeissaFolder(), TestCasesHistoryFileName);

            return(testCasesHistoryFileNamePath);
        }