Exemplo n.º 1
0
        public static bool Setup()
        {
            if (isInited)
            {
                return(true);
            }

            isInited = true;
            bool ret = false;

            lock (logTable)
            {
                ret = NAdvLogWrapper.Init();
                if (ret)
                {
                    DefaultLogger = GetLogger(dafaultLogName);
                }
            }

            if (DefaultLogger != null)
            {
                DefaultLogger.Debug("==================================================");
                DefaultLogger.Debug("############### Application Started ###############");
                DefaultLogger.Debug("==================================================");
            }
            LogFile = NAdvLogWrapper.GetLogFile();
            return(ret);
        }
Exemplo n.º 2
0
        public async Task <(bool, ConnectionState?)> Wait(TimeSpan timeout)
        {
            if (DefaultLogger.IsDebug)
            {
                DefaultLogger.Debug($"[{_id}] Waiting for state change for {timeout.TotalSeconds} seconds");
            }

            TaskCompletionSource <(bool, ConnectionState?)> taskCompletionSource =
                new TaskCompletionSource <(bool, ConnectionState?)>();

            try
            {
                _connection.InternalStateChanged += ChangeListener;
                var tResult = taskCompletionSource.Task;
                return(await tResult.TimeoutAfter(timeout, (false, null)));
            }
            finally
            {
                _connection.InternalStateChanged -= ChangeListener;
            }

            void ChangeListener(object sender, ConnectionStateChange change)
            {
                _currentState = change.Current;
                taskCompletionSource.SetResult((true, _currentState));
            }
        }
Exemplo n.º 3
0
        public async Task <TimeSpan> Wait(TimeSpan timeout)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (DefaultLogger.IsDebug)
            {
                DefaultLogger.Debug($"[{_id}] Waiting for state {string.Join(",", _awaitedStates)} for {timeout.TotalSeconds} seconds");
            }

            if (_awaitedStates.Contains(Connection.State))
            {
                DefaultLogger.Debug($"Current state is {Connection.State}. Desired state reached.");
                return(TimeSpan.Zero);
            }

            Connection.InternalStateChanged += conn_StateChanged;
            var tResult    = _taskCompletionSource.Task;
            var tCompleted = await Task.WhenAny(tResult, Task.Delay(timeout)).ConfigureAwait(true);

            if (tCompleted == tResult)
            {
                stopwatch.Stop();
                return(stopwatch.Elapsed);
            }

            DefaultLogger.Debug($"[{_id} Timeout exceeded. Throwing TimeoutException");
            RemoveListener();
            throw new TimeoutException();
        }
Exemplo n.º 4
0
        public async Task <TimeSpan> Wait(TimeSpan timeout)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (DefaultLogger.IsDebug)
            {
                DefaultLogger.Debug(
                    $"[{_id}] Waiting for state {string.Join(",", _awaitedStates)} for {timeout.TotalSeconds} seconds");
            }

            if (_awaitedStates.Contains(_connection.State))
            {
                DefaultLogger.Debug($"Current state is {_connection.State}. Desired state reached.");
                return(TimeSpan.Zero);
            }

            _connection.On(Conn_StateChanged);
            var resultTask    = _taskCompletionSource.Task;
            var completedTask = await Task.WhenAny(resultTask, Task.Delay(timeout)).ConfigureAwait(false);

            if (completedTask == resultTask)
            {
                stopwatch.Stop();
                return(stopwatch.Elapsed);
            }

            DefaultLogger.Debug($"[{_id} Timeout exceeded. Throwing TimeoutException");
            RemoveListener();
            throw new TimeoutException(
                      $"Expected ''{_awaitedStates.Select(x => x.ToString()).JoinStrings()}' but current state was '{_connection.State}'");
        }
Exemplo n.º 5
0
 private void conn_StateChanged(object sender, ConnectionStateChange e)
 {
     if (_awaitedStates.Contains(e.Current))
     {
         DefaultLogger.Debug($"[{_id}] Desired state was reached.");
         RemoveListener();
         _taskCompletionSource.SetResult(true);
     }
 }
Exemplo n.º 6
0
        public void Connect()
        {
            DefaultLogger.Debug("Connecting using: " + Parameters.GetUri().ToString());

            ConnectCalled = true;
            if (OnConnectChangeStateToConnected)
            {
                Listener?.OnTransportEvent(TransportState.Connected);
                State = TransportState.Connected;
            }
        }
Exemplo n.º 7
0
        public static void Debug(object message)
        {
            switch (LogEngineType)
            {
            case LogEngineTypeEnum.DefaultLogger:
                DefaultLogger.Debug(message);
                break;

            case LogEngineTypeEnum.FlashLogger:
                FlashLogger.Debug(message);
                break;
            }
        }
        public void Debug_RandomString_Void()
        {
            // arrange.

            var test = new DefaultLogger();

            // act.
            test.Debug("yay", this);

            // assert.
            Assert.IsNotNull(test);

        }
Exemplo n.º 9
0
 public void Close(bool suppressClosedEvent = true)
 {
     DefaultLogger.Debug("Closing test transport!");
     _wrappedTransport.Close(suppressClosedEvent);
 }
Exemplo n.º 10
0
 private void RemoveListener()
 {
     DefaultLogger.Debug($"[{_id}] Removing Connection listener");
     Connection.InternalStateChanged -= conn_StateChanged;
 }
Exemplo n.º 11
0
 private void RemoveListener()
 {
     DefaultLogger.Debug($"[{_id}] Removing Connection listener");
     _connection.Off(Conn_StateChanged);
 }