You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

  1. using Common.Models.Confiq;
  2. using Common.Models.Enums;
  3. using log4net;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Configuration;
  7. using System.IO;
  8. using System.Linq;
  9. namespace Common.Utility
  10. {
  11. public static class Helpers
  12. {
  13. public static List<ReferenceMap> GetReferenceMaps()
  14. {
  15. List<ReferenceMap> referenceMaps = new List<ReferenceMap>();
  16. string mappingPath = mappingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["MappingFilePath"].ToString());
  17. using (StreamReader reader = File.OpenText(mappingPath))
  18. {
  19. var jsonS = reader.ReadToEnd();
  20. referenceMaps = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReferenceMap>>(jsonS);
  21. }
  22. return referenceMaps;
  23. }
  24. public static Mapping GetMapping(MappingType type, string keyValue, string lang = "en")
  25. {
  26. Mapping map = new Mapping();
  27. try
  28. {
  29. if (string.IsNullOrEmpty(keyValue))
  30. {
  31. return new Mapping();
  32. }
  33. var lstReferences = GetReferenceMaps().Where(x => x.Type.Equals(type.ToString())).SingleOrDefault();
  34. if (type == MappingType.PUSH_NOTIFY_TEMPLATE)
  35. map = lstReferences.Mappings.FirstOrDefault(x => (!String.IsNullOrEmpty(x.SValue) ? x.SValue.Trim().ToUpper() : "").Equals(keyValue.ToUpper().Trim())
  36. && (!String.IsNullOrEmpty(x.DValue) ? x.DValue.Trim().ToUpper() : "EN").Equals(lang.ToUpper().Trim()));
  37. else
  38. map = lstReferences.Mappings.FirstOrDefault(x => (!String.IsNullOrEmpty(x.SValue) ? x.SValue.Trim().ToUpper() : "").Equals(keyValue.ToUpper().Trim()));
  39. }
  40. catch (Exception e)
  41. {
  42. LogManager.GetLogger(typeof(Helpers)).Error(($"GetMapping | {type.ToString()} | {keyValue} | {e.ToString()} "));
  43. throw e;
  44. }
  45. return map != null ? map : new Mapping();
  46. }
  47. }
  48. }