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.
|
|
using Common.Models.Confiq; using Common.Models.Enums; using log4net; using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq;
namespace Common.Utility {
public static class Helpers {
public static List<ReferenceMap> GetReferenceMaps() {
List<ReferenceMap> referenceMaps = new List<ReferenceMap>();
string mappingPath = mappingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["MappingFilePath"].ToString());
using (StreamReader reader = File.OpenText(mappingPath)) { var jsonS = reader.ReadToEnd(); referenceMaps = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReferenceMap>>(jsonS); }
return referenceMaps; }
public static Mapping GetMapping(MappingType type, string keyValue, string lang = "en") {
Mapping map = new Mapping(); try { if (string.IsNullOrEmpty(keyValue)) { return new Mapping(); }
var lstReferences = GetReferenceMaps().Where(x => x.Type.Equals(type.ToString())).SingleOrDefault();
if (type == MappingType.PUSH_NOTIFY_TEMPLATE) map = lstReferences.Mappings.FirstOrDefault(x => (!String.IsNullOrEmpty(x.SValue) ? x.SValue.Trim().ToUpper() : "").Equals(keyValue.ToUpper().Trim()) && (!String.IsNullOrEmpty(x.DValue) ? x.DValue.Trim().ToUpper() : "EN").Equals(lang.ToUpper().Trim())); else map = lstReferences.Mappings.FirstOrDefault(x => (!String.IsNullOrEmpty(x.SValue) ? x.SValue.Trim().ToUpper() : "").Equals(keyValue.ToUpper().Trim()));
} catch (Exception e) { LogManager.GetLogger(typeof(Helpers)).Error(($"GetMapping | {type.ToString()} | {keyValue} | {e.ToString()} ")); throw e; } return map != null ? map : new Mapping(); }
} }
|