Resource Helper Class
using AI_Portal_Cloud.Infrastructure;
using AI_Portal_Cloud.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using AI_Portal_Cloud.Framework;
namespace AI_Portal_Cloud.Helpers
{
public class ResourceHelper
{
#region public Members
public static ResourceList resourceList;
public static StringDictionary resources;
public static StringDictionary fwResourceList;
#endregion
#region Private Methods
/// <summary>
/// Loads the application resources.
/// </summary>
public static void LoadAppResources()
{
try
{
int intLgCnt = 0;
string strLangList = null;
string strResourcesList = null;
strLangList = ConfigurationHelper.GetFWConfiguration("MIND.Web.FilePath.Application.Language");
strResourcesList = ConfigurationHelper.GetFWConfiguration("MIND.Web.FilePath.Application.Resources");
resourceList = new ResourceList();
string baseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; ///HttpContext.Current.Session["ServerPath"].ToString(); ///HttpContext.Current.Server.MapPath("");
for (intLgCnt = 0; intLgCnt <= strLangList.Split(',').Length - 1; intLgCnt++)
{
try
{
// resources = null;
resources = new StringDictionary();
if ((resources != null))
resources.Clear();
String resourceFileCompletePath = string.Format("{0}\\{1}\\Resource_{2}.xml", baseDirectoryPath, strResourcesList, strLangList.Split(',')[intLgCnt]);
resources = LoadXML.LoadFiles(resourceFileCompletePath);
}
catch (Exception ex)
{
}
resourceList.Addobject(resources);
}
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
/// Loads the Framework resources.
/// </summary>
private static void LoadFWResources()
{
try
{
string strServerpath = null;/// HttpContext.Current.Session["ServerPath"].ToString(); ///HttpContext.Current.Server.MapPath("");
fwResourceList = LoadXML.LoadFiles(strServerpath + "\\" + ConfigurationHelper.GetFWConfiguration("MIND.Web.FilePath.FW.Resources"));
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Public Static Methods
/// <summary>
/// Get Resource Accordiing to ID
/// </summary>
/// <param name="id">The identifier.</param>
public static string GetFWResource(string id)
{
// Getting resources as defined in FWResources.XML in the language as defined by Session["_language"] / Session["_languageResourceIDBegining"] variables
//string strID = Convert.ToInt32(ID);
string strId = id;
string strValue = null;
try
{
strId = strId + Convert.ToInt32(HttpContext.Current.Session["_languageResourceIDBegining"]); //need to ask BS
}
catch (Exception ex)
{
}
try
{
if ((fwResourceList == null) == true)
{
LoadFWResources();
}
strValue = fwResourceList[strId];
if (strValue == null)
{
if (ServerInformation.ApplicationDebug)
{
throw new AllExceptions.InvalidResourceException(strId);
}
else
{
return "";
}
}
else
{
return strValue;
}
}
catch
{
return ""; //need to ask : BS
/* if (ServerInformation.ApplicationDebug)
{
throw new AllExceptions.InvalidResourceException(strID);
}*/
}
}
/// <summary>
/// Gets the application resource.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns></returns>
/// <exception cref="System.Exception"></exception>
public static string GetAppResource(string id)
{
string strID = "";
int intLangId = 0;
string strValue = null;
try
{
strID = id;
if ((HttpContext.Current.Session["Language"] == null))
{
HttpContext.Current.Session["Language"] = ConfigurationHelper.GetFWConfiguration("MIND.Web.FilePath.Application.DefaultLanguage");
}
string strLan = ConfigurationHelper.GetFWConfiguration("MIND.Web.FilePath.Application.Language");
var langueges = strLan.Split(',');
string CurrentLang = HttpContext.Current.Session["Language"].ToString();
for (var i = 0; i < langueges.Length; i++)
{
if (langueges[i].ToLower() == CurrentLang.ToLower())
{
intLangId = i;
}
}
}
catch (Exception ex)
{
intLangId = 0;
}
try
{
resourceList = null;
if (resourceList == null)
{
LoadAppResources();
}
strValue = resourceList.GetstringValue(intLangId, strID);
if (strValue == null)
{
if (ServerInformation.ApplicationDebug)
{
throw new Exception();
}
else
{
return "";
}
}
else
{
return strValue;
}
}
catch
{
return "";
}
}
#endregion
}
}
Comments
Post a Comment