25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using Models.Identity;
  9. namespace BlazorPages.Tools
  10. {
  11. public static class Statics
  12. {
  13. public const string TableClass = "table table-striped table-bordered border";
  14. public enum CultureType
  15. {
  16. En,
  17. Fa
  18. }
  19. public static CultureType Culture = CultureType.Fa;
  20. public static string LoginTokenKey = "SignIn";
  21. public static string RefreshTokenKey = "RefreshToken";
  22. public static string Agent = "";
  23. public static string FcmToken = "RefreshToken";
  24. public static CheckLoginResponse CurrentLoginInfo { get; set; }
  25. public static DateTime? LastCheck { set; get; }
  26. public static bool IsFromMobileApp { get; internal set; }
  27. public static string BaseAddress = "https://api.senso.farm/";
  28. //linux:
  29. //public static string BaseAddress = "https://localhost:5001/";
  30. public static string ReplaceNewLineWithBr(this string text)
  31. {
  32. var result = Regex.Replace(text, @"\r\n?|\n", "<br/>");
  33. result = result.Replace("<br/><br/><br/>", "<br/>").Replace("<br/><br/>", "<br/>");
  34. return result;
  35. }
  36. public static CultureInfo GetPersianCulture()
  37. {
  38. var culture = new CultureInfo("fa-IR");
  39. DateTimeFormatInfo formatInfo = culture.DateTimeFormat;
  40. formatInfo.AbbreviatedDayNames = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
  41. formatInfo.DayNames = new[] { "یکشنبه", "دوشنبه", "سه شنبه", "چهار شنبه", "پنجشنبه", "جمعه", "شنبه" };
  42. var monthNames = new[]
  43. {
  44. "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن",
  45. "اسفند",
  46. "",
  47. };
  48. formatInfo.AbbreviatedMonthNames =
  49. formatInfo.MonthNames =
  50. formatInfo.MonthGenitiveNames = formatInfo.AbbreviatedMonthGenitiveNames = monthNames;
  51. formatInfo.AMDesignator = "ق.ظ";
  52. formatInfo.PMDesignator = "ب.ظ";
  53. formatInfo.ShortDatePattern = "yyyy/MM/dd";
  54. formatInfo.LongDatePattern = "dddd, dd MMMM,yyyy";
  55. formatInfo.FirstDayOfWeek = DayOfWeek.Saturday;
  56. Calendar cal = new PersianCalendar();
  57. FieldInfo fieldInfo = culture.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance);
  58. if (fieldInfo != null)
  59. fieldInfo.SetValue(culture, cal);
  60. FieldInfo info = formatInfo.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance);
  61. if (info != null)
  62. info.SetValue(formatInfo, cal);
  63. culture.NumberFormat.NumberDecimalSeparator = "/";
  64. culture.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
  65. culture.NumberFormat.NumberNegativePattern = 0;
  66. return culture;
  67. }
  68. }
  69. }