/// <summary> /// Get all dictionary items /// </summary> /// <param name="itemKey">DictionaryItemKey</param> /// <param name="cultureCode">Culture Code</param> /// <returns>Collection of DictionaryItem</returns> public List<DictionaryItem> GetAllItems(DictionaryItemKey itemKey, string cultureCode) { var dictionaryItemKey = itemKey; List<DictionaryItem> dictionaryItems = null; switch (itemKey) { // To see if the item is using ID or Code look at the corresponding database table case DictionaryItemKey.CommonTimezone: case DictionaryItemKey.Titles: dictionaryItems = dictionaryDao.GetAllItemsWithId(dictionaryItemKey, cultureCode); break; default: dictionaryItems = dictionaryDao.GetAllItemsWithCode(dictionaryItemKey, cultureCode); break; } return dictionaryItems; }
/// <summary> /// Get all dictionary items where primary key is code /// </summary> /// <param name="itemKey">Dictionary Item to get</param> /// <param name="cultureCode">culture code</param> /// <returns>Collection of DictionaryItems</returns> public List<DictionaryItem> GetAllItemsWithCode(DictionaryItemKey itemKey, string cultureCode) { if (itemKey == DictionaryItemKey.Unknown) { return null; } if (string.IsNullOrEmpty(cultureCode)) { cultureCode = ConfigHelper.DefaultCultureCode; } const string sqlStatement = @"SELECT Code, Dictionary.GetItem(@CultureCode, DctName) AS Name FROM {0} {1}"; string whereClause = string.Empty; if (itemKey == DictionaryItemKey.CommonContractCurrency) { whereClause = " WHERE IsContract = 1 "; } var sbSqlStatement = string.Format(sqlStatement, itemKey.GetCode(), whereClause); var parameters = new List<SqlParameter> { DbHelper.CreateParameter(DictionaryItemMapper.Parameters.CultureCode, cultureCode), }; try { var dictionaryItems = DbHelper.CreateInstanceList(sbSqlStatement, DictionaryItemMapper.MapRecord, parameters: parameters); // get proper item enum values DictionaryItemMapper.MapEnums(dictionaryItems, GetEnumTypeFromDictionaryKey(itemKey)); return dictionaryItems; } catch (SqlException ex) { throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30096, "DictionaryDao.GetAllItemsWithCode", additionalDescriptionParameters: new object[] { "DictionaryDao", cultureCode }, arguments: new object[] { "DictionaryDao", cultureCode }, exception: ex)); } }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <param name="sourceCulture"></param> /// <param name="sourceText"></param> /// <param name="targetCulture"></param> /// <param name="objParams"></param> /// <returns></returns> public string Translate(string category, CultureInfo sourceCulture, string sourceText, CultureInfo targetCulture, params object[] objParams) { string targetText = sourceText; if (targetCulture.Name != sourceCulture.Name && string.IsNullOrEmpty(category) == false) { DictionaryItemKey key = new DictionaryItemKey() { SourceText = sourceText, SourceCultureName = sourceCulture.Name, TargetCultureName = targetCulture.Name, Category = category }; if (DictionaryCache.Instance.TryGetValue(key, out targetText) == false) { string fileName = GetCultureFilePath(category, targetCulture) + ".xml"; string physicalFileName = string.Empty; try { if (EnvironmentHelper.Mode != InstanceMode.Web) { return sourceText; } XmlDocument xmlDoc = WebXmlDocumentCache.GetXmlDocument(fileName); XmlElement item = FindMatchedItem(sourceText, xmlDoc.DocumentElement.SelectNodes("Item")); if (item != null) targetText = item.GetAttribute("target"); else targetText = sourceText; physicalFileName = HttpContext.Current.Server.MapPath(fileName); } catch (System.IO.FileNotFoundException) { targetText = sourceText; } catch (System.IO.DirectoryNotFoundException) { targetText = sourceText; } if (string.IsNullOrEmpty(physicalFileName) == false) { FileCacheDependency dependency = new FileCacheDependency(physicalFileName); DictionaryCache.Instance.Add(key, targetText, dependency); } else { DictionaryCache.Instance.Add(key, targetText); } } } return targetText; }
/// <summary> /// Get the enum type from the dictionary key /// Note: only does the cancellation request action at the moment /// </summary> /// <param name="dictKey">enum type to use</param> /// <returns>typeof(enumType)</returns> private Type GetEnumTypeFromDictionaryKey(DictionaryItemKey dictKey) { switch (dictKey) { case DictionaryItemKey.BookingCancellationRequestAction: { return typeof(CancellationRequestAction); } default: { return typeof(CancellationRequestAction); } } }