// TODO: Refactor! private void Init(bool connectSession) { var counter = 0; Exception lastException = null; var retryDelay = _settings.StartingRetryDelay; //ms while (counter < _settings.MaxRetryAttempts) { lock (this) { if (_isClosing) { _service = null; IsConnected = false; return; } } try { if (connectSession) { _sessionContainer.ReleaseSession(); } _service = _sessionContainer.Session.GetService("UnifiedDataAPI"); if (_service == null) { _logger.Fatal("Udapi Service proxy could not be created"); } else { _service.IsServiceCacheEnabled = _settings.IsSdkServiceCacheEnabled; _service.ServiceCacheInvalidationInterval = _settings.FixtureCheckerFrequency / 1000 - 2; } IsConnected = true; return; } catch (Exception ex) { lastException = ex; counter++; string message = $"{ex.GetType().Name}: Failed to init Udapi service on attempt {counter}."; if (counter == _settings.MaxRetryAttempts) { _logger.Error(message + Environment.NewLine + $"Stack Trace:{ex.StackTrace}"); } else { _logger.Warn(message); } if (ex as NotAuthenticatedException != null) { connectSession = true; } } retryDelay = 2 * retryDelay; if (retryDelay > _settings.MaxRetryDelay) { retryDelay = _settings.MaxRetryDelay; } _logger.DebugFormat("Retrying Sporting Solutions API in {0} ms", retryDelay); Thread.Sleep(retryDelay); } throw lastException ?? new Exception(); }
// TODO: Refactor! private void Init(bool connectSession) { var counter = 0; Exception lastException = null; var retryDelay = _settings.StartingRetryDelay; //ms while (counter < _settings.MaxRetryAttempts) { lock (this) { if (_isClosing) { _service = null; IsConnected = false; return; } } try { if (connectSession) { _sessionContainer.ReleaseSession(); } _service = _sessionContainer.Session.GetService("UnifiedDataAPI"); if (_service == null) { _logger.Fatal("Udapi Service proxy could not be created"); } IsConnected = true; return; } catch (NotAuthenticatedException wex) { lastException = wex; counter++; if (counter == _settings.MaxRetryAttempts) { _logger.Error( String.Format("Failed to successfully execute Sporting Solutions method after all {0} attempts", _settings.MaxRetryAttempts), wex); } else { _logger.WarnFormat("Failed to successfully execute Sporting Solutions method on attempt {0}. Stack Trace:{1}", counter, wex.StackTrace); } connectSession = true; } catch (Exception ex) { counter++; if (counter == _settings.MaxRetryAttempts) { _logger.Error( String.Format("Failed to successfully execute Sporting Solutions method after all {0} attempts", _settings.MaxRetryAttempts), ex); } else { _logger.WarnFormat("Failed to successfully execute Sporting Solutions method on attempt {0}. Stack Trace:{1}", counter, ex.StackTrace); } } retryDelay = 2 * retryDelay; if (retryDelay > _settings.MaxRetryDelay) { retryDelay = _settings.MaxRetryDelay; } _logger.DebugFormat("Retrying Sporting Solutions API in {0} ms", retryDelay); Thread.Sleep(retryDelay); } throw lastException ?? new Exception(); }