Don't want to hard-code WURFL filenames in global.asax

sm_support2
Posts: 294
Joined: Mon Jun 20, 2011 5:04 pm

Don't want to hard-code WURFL filenames in global.asax

Postby sm_support2 » Tue Jun 28, 2011 10:40 am

I don’t much like to hardcode the names of the WURFL files in global.asax. I’d rather like to read them from the configuration files. The documentation seems to hint at this possibility but I haven’t found anything better than doing it myself.

sm_support2
Posts: 294
Joined: Mon Jun 20, 2011 5:04 pm

Re: Don't want to hard-code WURFL filenames in global.asax

Postby sm_support2 » Tue Jun 28, 2011 10:42 am

The WURLF API features an ApplicationConfigurer class that you can use instead of InMemoryConfigurer to pass the location of the system files. Because of this, the WURFL API also defines its own section to add to web.config. You need to have the following section defined in web.config:


<configuration>
<configSections>
<section name="wurfl"
type="WURFL.Config.WURFLConfigurationSection,wurfl" />
</configSections>

<wurfl>
<mainFile path="...\App_Data\wurfl-latest.zip" />
<patches>
<patch path="...\App_Data\web_browsers_patch.xml" />
</patches>
</wurfl>
:
</configuration>


The <wurfl> section goes below the root node; it doesn’t go under the ASP.NET <system.web> section. With this data in place, you change your code in global.asax as follows:

var configurer = new ApplicationConfigurer();
var wurflManager = WURFLManagerBuilder.Build(configurer);
if (wurflManager == null)
throw new ArgumentNullException("Null reference to WURFL manager.");

At this point, you can cache the WURFL manager for further use. An issue you might want to be aware of is that the API isn’t currently particularly smart when it comes to resolving the file names. It requires you specify the full absolute path to the files and it doesn’t support any shortcuts such as DataDirectory or the tilde operator fairly popular in the ASP.NET space. In the end, either you indicate the full path or you resort to using your own code to read from web.config and use InMemoryConfigurer. If you opt for writing your own code to access the configuration file, it is up to you whether you want to go with the WURFL sections or create your own simpler entries in AppSettings as below:

<appSettings>
:
<add key="wurfl_mainfile" value="..."/>
<add key="wurfl_patches" value="..., ..."/>
</appSettings>

It goes without saying that processing the values of the entries is up to you. For patches, you might want to use a plain comma-separated string.


Who is online

Users browsing this forum: No registered users and 43 guests