Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

telerik -- supercharge your DNN websites
  Ads  
 


  Sponsors  

Meet Our Sponsors

CrystalTech Web Hosting™
Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
AspDotNetStoreFront - E-Commerce by Design - The Leading ASP.NET shopping cart platform for developers!
SteadyRain
DataSprings - Great Ideas. Always Flowing.
 


DotNetNuke Forums
 
  Forum  DotNetNuke® Pro...  Authentication ...  custom resource provider compile time errors
Previous Previous
 
Next Next
New Post 2/20/2008 9:33 PM
Unresolved
User is offline charan
1 posts
10th Ranked


custom resource provider compile time errors 

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 Previous
 
Next Next
  Forum  DotNetNuke® Pro...  Authentication ...  custom resource provider compile time errors
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Convert Visitors to Customers
In order to bring value to your users, we must first understand them. VIVIDSITES will help you build a custom web application and interactive marketing tools that your users will thank you for. We marry high-end creative with head banging technology to entertain and convert visitors into paying customers. Call 314.514.0505 or visit us at http://www.vividsites.com to find out how.
- V I V I D S I T E S -
Gearworx Web Hosting
As a premier provider of Web Hosting, Private/White Label hosting, Server Colocation, Dedicated Server, and other Managed Services, Gearworx offers an array of services designed to more effectively manage strategies driving businesses on the Web. Headquartered in Fremont, California our state of the art tier one data centers and distributed managed services environment enables Gearworx to offer your business enterprise level solutions through simplified processes.
Gearworx Web Hosting
Glanton: Enterprise Intranet Specialists Using DNN
Glanton Solutions are a premier provider of sevices for large corporates lloking to outsource Intranet sites.
www.glanton.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP