Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationcustom resource provider compile time errorscustom resource provider compile time errors
Previous
 
Next
New Post
2/21/2008 12:33 AM
 

Hi
i have created custom resource provider and getting the resources from xml file...appliction is not building ... i am getting compile time errors...'the resource object with key is not found'... Plz Provide me solution... here is my code

using System;
using System.Web.Compilation;
using System.Globalization;
using System.Resources;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Xml;
using System.Web;
using System.Web.Hosting;
using System.Web.Caching;

namespace Hydra.Providers
{

public sealed class XmlResourceProviderFactory : ResourceProviderFactory
{
public static ListDictionary resourceList = new ListDictionary();
public XmlResourceProviderFactory()
{
}

public override IResourceProvider CreateGlobalResourceProvider(string classKey)
{
return new XmlResourceProvider(null, classKey);
}

public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
{
//virtualPath = this.GetVirtualPath(virtualPath);
return new XmlResourceProvider(virtualPath, null);
}

public class XmlResourceProvider : IResourceProvider
{
private string _virtualPath;
private string _className;
private IDictionary _resource;
private static object CultureNeutralKey = new object();

public XmlResourceProvider(string virtualPath, string className)
{
_virtualPath = virtualPath;
_className = className;
}

//private IDictionary GetResource(string cultureName)
//{
// _resource = new ListDictionary();

// IDictionary resourceDict = _resource as IDictionary;

// resourceDict = XmlResourceHelper.GetResources(_virtualPath, _className, cultureName, true, null);
// _resource = resourceDict;

// return resourceDict;
//}



private IDictionary GetResource(string cultureName)
{

object cultureKey;
if (cultureName != null)
{
cultureKey = cultureName;
}
else
{
cultureKey = CultureNeutralKey;
}
if (_resource == null)
_resource = new ListDictionary();

IDictionary resourceDict = _resource[cultureKey] as IDictionary;
if (resourceDict == null)
{
resourceDict = XmlResourceHelper.GetResources(_virtualPath, _className, cultureName, true, null);
_resource = resourceDict;
}

return resourceDict;
}
object IResourceProvider.GetObject(string resourceKey, CultureInfo culture)
{
if (string.IsNullOrEmpty(resourceKey))
{
throw new ArgumentNullException("resourceKey");
}

if (culture == null || culture == CultureInfo.InvariantCulture)
culture = CultureInfo.CurrentUICulture;

object value = GetResource(culture.Name)[resourceKey];

return value;
}





public System.Resources.IResourceReader ResourceReader
{
get
{
return new XmlResourceReader(GetResource(null));
}
}
}

private sealed class XmlResourceReader : IResourceReader
{
private IDictionary _resources;

public XmlResourceReader(IDictionary resources)
{
_resources = resources;
}

IDictionaryEnumerator IResourceReader.GetEnumerator()
{
return _resources.GetEnumerator();
}

void IResourceReader.Close()
{
}

IEnumerator IEnumerable.GetEnumerator()
{
return _resources.GetEnumerator();
}

void IDisposable.Dispose()
{
}
}

internal static class XmlResourceHelper
{
public static IDictionary GetResources(string virtualPath, string className, string cultureName, bool designMode, IServiceProvider serviceProvider)
{
//ListDictionary resources = new ListDictionary();
string xmlFilePath;
string strCompanyId = "1";
//string strLayoutId = "1";
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string aspxPage = oInfo.Name;
string[] aspxPage1 = aspxPage.Split('.');
//HttpContext.Current.Handler
object obj = HttpContext.Current.Request;


//try
//{
// if (HttpContext.Current.Session["CompanyId"] != null)
// strCompanyId = HttpContext.Current.Session["CompanyId"].ToString();

// if (HttpContext.Current.Session["LayoutId"] != null)
// strLayoutId = HttpContext.Current.Session["LayoutId"].ToString();
//}
//catch {}

if (!String.IsNullOrEmpty(virtualPath))
{

// Get Local resources
XmlDocument configurationFile = new XmlDocument();
// xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + strLayoutId + "_en-US.xml");
xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + aspxPage1[0].ToLower() + "_en-US.xml");

//configurationFile.Load(xmlFilePath);

XmlReader reader;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
reader = XmlReader.Create(xmlFilePath, settings);
reader.Read();
configurationFile.Load(reader);
XmlNode node = configurationFile.DocumentElement;
parseResourcefile(node);

}
else if (!String.IsNullOrEmpty(className))
{
// Get Global resources
XmlDocument configurationFile = new XmlDocument();
// xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + className + "_en-US.xml");
xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + aspxPage1[0].ToLower() +"_en-US.xml");
configurationFile.Load(xmlFilePath);
XmlNode node = configurationFile.DocumentElement;
parseResourcefile(node);
}
return resourceList;
}
public static void parseResourcefile(XmlNode node)
{

foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name.StartsWith("resources"))
{
parseResourcefile(childNode);
}
else
{
if (childNode.Attributes["name"] != null && childNode.InnerText != string.Empty)
{
string rn = childNode.Attributes.Item(0).Value.ToString();
string rv = childNode.InnerText.ToString();
if (!resourceList.Contains(rn))
{
resourceList.Add(rn, rv);
}

}
}
}

}
}
}
}

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsAuthenticationAuthenticationcustom resource provider compile time errorscustom resource provider compile time errors


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out