Ejemplo n.º 1
0
 private static void ValidateBookmakerDetailsFromXml(IBookmakerDetails details)
 {
     Assert.AreEqual(TestData.BookmakerId, details.BookmakerId);
     Assert.AreEqual(TestData.VirtualHost, details.VirtualHost);
     Assert.IsNull(details.Message);
     Assert.AreEqual(HttpStatusCode.OK, details.ResponseCode);
     Assert.AreEqual(DateTime.Parse("2016-07-26T17:44:24Z").ToUniversalTime(), details.ExpireAt.ToUniversalTime());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the whoami endpoint data
        /// </summary>
        /// <param name="hostName">The host name</param>
        /// <param name="useSsl">Value indicating whether a secure connection should be attempted</param>
        /// <param name="rethrow">Value indicating whether caught exceptions should be rethrown</param>
        /// <returns>True if data was successfully retrieved. False otherwise. May throw <see cref="CommunicationException"/></returns>
        private bool LoadWhoamiData(string hostName, bool useSsl, bool rethrow)
        {
            Guard.Argument(hostName, nameof(hostName)).NotNull().NotEmpty();

            var hostUrl = useSsl
                              ? "https://" + hostName
                              : "http://" + hostName;

            try
            {
                ExecutionLog.Info($"Attempting to retrieve whoami data. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), Environment)}");
                var bookmakerDetailsDTO = _bookmakerDetailsProvider.GetData(hostUrl);
                _bookmakerDetails = new BookmakerDetails(bookmakerDetailsDTO);
                ApiHost           = hostName;
                ExecutionLog.Info($"Whoami data successfully retrieved. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), Environment)}");

                if (_bookmakerDetails.ServerTimeDifference > TimeSpan.FromSeconds(5))
                {
                    ExecutionLog.Error($"Machine time is out of sync for {_bookmakerDetails.ServerTimeDifference.TotalSeconds} sec. It may produce unwanted results with time sensitive operations within sdk.");
                }
                else if (_bookmakerDetails.ServerTimeDifference > TimeSpan.FromSeconds(2))
                {
                    ExecutionLog.Warn($"Machine time is out of sync for {_bookmakerDetails.ServerTimeDifference.TotalSeconds} sec. It may produce unwanted results with time sensitive operations within sdk.");
                }

                return(true);
            }
            catch (Exception ex)
            {
                ExecutionLog.Info($"Failed to retrieve whoami data. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), Environment)}, Error message={ex.Message}");
                if (rethrow)
                {
                    throw;
                }
                return(false);
            }
        }