AppServerBase.Net45.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SuperSocket.SocketBase.Config;
  8. using SuperSocket.SocketBase.Protocol;
  9. namespace SuperSocket.SocketBase
  10. {
  11. public abstract partial class AppServerBase<TAppSession, TRequestInfo>
  12. where TRequestInfo : class, IRequestInfo
  13. where TAppSession : AppSession<TAppSession, TRequestInfo>, IAppSession, new()
  14. {
  15. partial void SetDefaultCulture(IRootConfig rootConfig, IServerConfig config)
  16. {
  17. var defaultCulture = config.DefaultCulture;
  18. //default culture has been set for this server instance
  19. if (!string.IsNullOrEmpty(defaultCulture))
  20. {
  21. if (rootConfig.Isolation == IsolationMode.None)
  22. {
  23. Logger.WarnFormat("The default culture '{0}' cannot be set, because you cannot set default culture for one server instance if the Isolation is None!");
  24. return;
  25. }
  26. }
  27. else if(!string.IsNullOrEmpty(rootConfig.DefaultCulture))
  28. {
  29. defaultCulture = rootConfig.DefaultCulture;
  30. //Needn't set default culture in this case, because it has been set in the bootstrap
  31. if (rootConfig.Isolation == IsolationMode.None)
  32. return;
  33. }
  34. if (string.IsNullOrEmpty(defaultCulture))
  35. return;
  36. try
  37. {
  38. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(defaultCulture);
  39. }
  40. catch (Exception e)
  41. {
  42. Logger.Error(string.Format("Failed to set default culture '{0}'.", defaultCulture), e);
  43. }
  44. }
  45. }
  46. }