private void ParseThreadCulture() { if (string.IsNullOrEmpty(ThreadCulture)) { threadCulture = CultureInfo.InvariantCulture; return; } try { switch (ThreadCulture.ToLowerInvariant()) { case "iv": case "ivl": case "invariantculture": case "invariant culture": case "invariant language": case "invariant language (invariant country)": { threadCulture = CultureInfo.InvariantCulture; break; } default: { threadCulture = CultureInfo.CreateSpecificCulture(ThreadCulture); break; } } } catch { throw new ArgumentException("Thread Culture: " + ThreadCulture + " is invalid.", "ThreadCulture"); } }
private void RestoreCulture(ThreadCulture threadCulture) { Thread currentThread = Thread.CurrentThread; currentThread.CurrentCulture = threadCulture.Culture; currentThread.CurrentUICulture = threadCulture.UICulture; }
public void CalculateAge_UseActualMethod_ShouldBeGreaterThan() { using (ThreadCulture.EnZa()) { var age = new DateTime(2000, 04, 09).CalculateAge(); age.ShouldBeGreaterThan(10); } }
public void CalculateAge_OnBirthDay_ShouldMatch() { using (ThreadCulture.EnZa()) { //var age = DateExtensions.CalculateAge(new DateTime(2014, 04, 09), new DateTime(2000, 04, 09)); //age.ShouldBe(14); } }
public void FromEpochDate_SupplyValidDate_IsCorrect() { using (ThreadCulture.EnZa()) { var date = 1389865750L.FromEpochDate(); date.ToString("dd/MM/yyyy HH:mm:ss tt").ShouldBe("16/01/2014 09:49:10 AM"); } }
private ThreadCulture NormalizeCulture() { Thread currentThread = Thread.CurrentThread; ThreadCulture result = new ThreadCulture(currentThread.CurrentCulture, currentThread.CurrentUICulture); currentThread.CurrentCulture = CultureInfo.InvariantCulture; currentThread.CurrentUICulture = CultureInfo.InvariantCulture; return(result); }
public void ToCurrencyWithZeroValue_CorrectResult() { using (ThreadCulture.EnZa()) { var value = -0m; var result = value.ToCurrency(); result.ShouldBe("R 0.00"); } }
public void ToCurrencyWithNegativeValue_CorrectResult() { using (ThreadCulture.EnZa()) { var value = -3456212.334m; var result = value.ToCurrency(); result.ShouldBe("-R 3 456 212.33"); } }
public void FromEpochDate_SupplyFutureDate_IsCorrect() { using (ThreadCulture.EnZa()) { var testDate = new DateTime(3022, 12, 13, 22, 59, 58); var epoch = testDate.ToEpochDate(); var date = epoch.FromEpochDate(); date.ToString("dd/MM/yyyy HH:mm:ss tt").ShouldBe("13/12/3022 22:59:58 PM"); } }
public void Initialize(string productId, BrokerSettings settings) { try { if (_Authenticator != null) { throw new Exception("Loader has already been initialized."); } if (settings == null) { throw new ArgumentNullException("settings"); } ThreadCulture threadCulture = NormalizeCulture(); if (settings.VerifyRuntimeIntegrity) { _StrongNameVerifier = new StrongNameVerifierLite(); CheckFrameworkStrongNames(); } InitializeWebHandling(); InitializeComponentTransform(); _ProductDirectory = GetProductDirectory(); string[] metadata = GetMetadata(); ParseMetadata(metadata); if (!Directory.Exists(_ProductDirectory)) { Directory.CreateDirectory(_ProductDirectory); } InitializeLzmaLib(); InitializeAuthenticator(); VerifyAuthenticator(); _AuthenticatorType = Assembly.Load(_AuthenticatorData).GetType("Controller"); _Authenticator = Activator.CreateInstance(_AuthenticatorType); MethodInfo method = _AuthenticatorType.GetMethod("UpdateValue"); method.Invoke(_Authenticator, new object[2] { "ProductId", productId }); method.Invoke(_Authenticator, new object[2] { "CatchUnhandledExceptions", settings.CatchUnhandledExceptions }); method.Invoke(_Authenticator, new object[2] { "DeferAutomaticUpdates", settings.DeferAutomaticUpdates }); method.Invoke(_Authenticator, new object[2] { "SilentAuthentication", settings.SilentAuthentication }); method.Invoke(_Authenticator, new object[2] { "DialogTheme", Convert.ToInt32(settings.DialogTheme) }); method.Invoke(_Authenticator, new object[2] { "LoaderVersion", _Version }); method.Invoke(_Authenticator, new object[2] { "ProductVersion", new Version(Application.ProductVersion) }); method.Invoke(_Authenticator, new object[2] { "Metadata", metadata }); method.Invoke(_Authenticator, new object[2] { "AuthorizedCallback", new CallbackDelegate(AuthorizedCallback) }); method.Invoke(_Authenticator, new object[2] { "RefreshedCallback", new CallbackDelegate(RefreshedCallback) }); method.Invoke(_Authenticator, new object[2] { "SuspendedCallback", new CallbackDelegate(SuspendedCallback) }); _AuthenticatorType.GetMethod("Initialize").Invoke(_Authenticator, null); DisposeMembers(); RestoreCulture(threadCulture); } catch (Exception ex) { HandleException(ex); } }