Ejemplo n.º 1
0
        public LaunchReporter(IClientService service, IConfiguration configuration, IRequestExecuter requestExecuter, IExtensionManager extensionManager)
        {
            _service = service;

            if (configuration != null)
            {
                _configuration = configuration;
            }
            else
            {
                var jsonPath = System.IO.Path.GetDirectoryName(new Uri(typeof(LaunchReporter).Assembly.CodeBase).LocalPath) + "/ReportPortal.config.json";
                _configuration = new ConfigurationBuilder().AddJsonFile(jsonPath).AddEnvironmentVariables().Build();
            }

            _requestExecuter = requestExecuter ?? new RequestExecuterFactory(_configuration).Create();

            _extensionManager = extensionManager ?? throw new ArgumentNullException(nameof(extensionManager));

            _reportEventsSource = new ReportEventsSource();
            if (extensionManager.ReportEventObservers != null)
            {
                foreach (var reportEventObserver in extensionManager.ReportEventObservers)
                {
                    try
                    {
                        reportEventObserver.Initialize(_reportEventsSource);
                    }
                    catch (Exception initExp)
                    {
                        TraceLogger.Error($"Unhandled exception while initializing of {reportEventObserver.GetType().FullName}: {initExp}");
                    }
                }
            }

            // identify whether launch is already started by any external system
            var externalLaunchUuid = _configuration.GetValue <string>("Launch:Id", null);

            if (externalLaunchUuid != null)
            {
                _isExternalLaunchId = true;

                _launchInfo = new LaunchInfo
                {
                    Uuid = externalLaunchUuid
                };
            }

            // identify whether launch should be rerun
            _rerunOfUuid = _configuration.GetValue <string>("Launch:RerunOf", null);

            _isRerun = _configuration.GetValue("Launch:Rerun", false);
        }
Ejemplo n.º 2
0
        public void Start(StartLaunchRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            TraceLogger.Verbose($"Scheduling request to start new '{request.Name}' launch in {GetHashCode()} proxy instance");

            if (StartTask != null)
            {
                var exp = new InsufficientExecutionStackException("The launch is already scheduled for starting.");
                TraceLogger.Error(exp.ToString());
                throw exp;
            }

            if (_rerunOfUuid != null)
            {
                request.IsRerun           = true;
                request.RerunOfLaunchUuid = _rerunOfUuid;
                // start rerun launch item
                StartTask = Task.Run(async() =>
                {
                    NotifyStarting(request);

                    var launch = await _requestExecuter.ExecuteAsync(() => _service.Launch.StartAsync(request), null).ConfigureAwait(false);

                    _launchInfo = new LaunchInfo
                    {
                        Uuid      = launch.Uuid,
                        Name      = request.Name,
                        StartTime = request.StartTime
                    };

                    NotifyStarted();
                });
            }
            else if (!_isExternalLaunchId)
            {
                if (_isRerun)
                {
                    request.IsRerun = true;
                }

                // start new launch item
                StartTask = Task.Run(async() =>
                {
                    NotifyStarting(request);

                    var launch = await _requestExecuter.ExecuteAsync(() => _service.Launch.StartAsync(request), null).ConfigureAwait(false);

                    _launchInfo = new LaunchInfo
                    {
                        Uuid      = launch.Uuid,
                        Name      = request.Name,
                        StartTime = request.StartTime
                    };

                    NotifyStarted();
                });
            }
            else
            {
                // get launch info
                StartTask = Task.Run(async() =>
                {
                    var launch = await _requestExecuter.ExecuteAsync(() => _service.Launch.GetAsync(Info.Uuid), null).ConfigureAwait(false);

                    _launchInfo = new LaunchInfo
                    {
                        Uuid      = launch.Uuid,
                        Name      = launch.Name,
                        StartTime = launch.StartTime
                    };
                });
            }
        }