예제 #1
0
 protected virtual void OnSessionRegistrationCompletedEvent(SessionRegistrationCompletedEventArgs e)
 {
     SessionRegistrationCompletedEvent?.Invoke(this, e);
 }
예제 #2
0
파일: Program.cs 프로젝트: Quilt4/Quilt4Net
 private static void SessionSessionRegistrationCompletedEvent(object sender, SessionRegistrationCompletedEventArgs e)
 {
     if (e.Result.IsSuccess)
     {
         var message = $"Session {e.Result.ErrorMessage ?? "registered in"} {e.Result.Elapsed.TotalMilliseconds.ToString("0")}ms.";
         _rootCommand.OutputEvent(message);
     }
     else
     {
         _rootCommand.OutputError(e.Result.Exception);
     }
 }
예제 #3
0
        private async Task<SessionResult> RegisterEx(string projectApiKey)
        {
            if (!Client.Configuration.Enabled)
            {
                return null;
            }

            var result = new SessionResult();
            SessionRequest request = null;
            SessionResponse response = null;

            lock (_syncRoot)
            {
                if (_ongoingSessionRegistration)
                {
                    var waitTime = new TimeSpan(0, 0, 3, 0);
                    if (!_sessionRegistered.WaitOne(waitTime))
                    {
                        if (string.IsNullOrEmpty(_sessionKey))
                        {
                            throw new TimeoutException("Done waiting for another thread trying to get the session registered.").AddData("WaitSeconds", waitTime.TotalSeconds.ToString("0"));
                        }
                    }
                }
                _ongoingSessionRegistration = true;
            }

            try
            {
                if (!string.IsNullOrEmpty(_sessionKey))
                {
                    result.SetAlreadyRegistered();
                }
                else
                {
                    try
                    {
                        request = new SessionRequest
                        {
                            ProjectApiKey = projectApiKey,
                            ClientStartTime = DateTime.UtcNow,
                            Environment = Environment,
                            Application = Client.Information.Application.GetApplicationData(),
                            Machine = Client.Information.Machine.GetMachineData(),
                            User = Client.Information.User.GetDataUser(),
                        };

                        OnSessionRegistrationStartedEvent(new SessionRegistrationStartedEventArgs(request));

                        response = await Client.WebApiClient.CreateAsync<SessionRequest, SessionResponse>("Client/Session", request);

                        if (response.SessionKey == null) throw new InvalidOperationException("No session key returned from the server.");
                        _sessionKey = response.SessionKey;
                        _sessionUrl = response.SessionUrl;
                    }
                    catch (Exception exception)
                    {
                        result.SetException(exception);
                        throw;
                    }
                    finally
                    {
                        result.SetCompleted(response);
                        LastSessionRegistrationCompletedEventArgs = new SessionRegistrationCompletedEventArgs(request, result);
                        OnSessionRegistrationCompletedEvent(LastSessionRegistrationCompletedEventArgs);
                    }
                }
            }
            finally
            {
                _ongoingSessionRegistration = false;
                _sessionRegistered.Set();
            }

            return result;
        }