Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

WURFL ASP.NET Implementations

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
15 Jan 2009CPOL5 min read 81.1K   797   23  
A comparison of three WURFL ASP.NET Implementations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Diagnostics;


namespace emx.tcp.app.wurfl.testharness1
{
    public partial class wurflApiWebForm : System.Web.UI.Page
    {

        Utility.Log mo_log = Utility.Log.logItem(Utility.wurfl.Implementation.WURFL_API.ToString());
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // bind capabilities to static enum
                cboCapabilities.DataSource = Utility.wurfl.capabilities;
                cboCapabilities.DataBind();
                // set state of capabilities list
                if (Request["cboCapabilities"] != null)
                {
                    cboCapabilities.Text = Request["cboCapabilities"].ToString();
                }
                // bind devices to arbitary list
                cboUserAgent.DataSource = Utility.wurfl.devices;
                cboUserAgent.DataBind();
                // set state of device list
                if (Request["cboDevice"] != null)
                {
                    cboUserAgent.Text = Request["cboDevice"].ToString();
                }
            }
        }

        protected void butGetCapability_Click(object sender, EventArgs e)
        {
            // start the timer
            Stopwatch o_stopwatch = new Stopwatch();
            o_stopwatch.Start();
            // check state of deviceFileProcessor
            if (Application["wurflFileProcessor"] == null)
            {
                string s_path = HttpContext.Current.Request.MapPath("WURFL_Data\\wurfl.xml");
                Application["wurflFileProcessor"] = new wurflApi.deviceFileProcessor(s_path);
            }
            wurflApi.deviceFileProcessor o_deviceFileProcessor = (Application["wurflFileProcessor"] as wurflApi.deviceFileProcessor);
            // prepare capability getter
            wurflApi.capabilitiesGetter o_capabilityGetter = new wurflApi.capabilitiesGetter(ref o_deviceFileProcessor);
            if (cboUserAgent.SelectedItem.Text == Utility.wurfl.devices[0])
            {
                // current device
                o_capabilityGetter.prepareNavigatorModelCapabilities(Request);
            }
            else
            {
                o_capabilityGetter.prepareNavigatorModelCapabilities(cboUserAgent.Text);
            }
            // output result to label
            string s_result = o_capabilityGetter.getCapability(cboCapabilities.Text);
            lblResponse.Text = cboCapabilities.Text + ": " + s_result;
            o_capabilityGetter.destroy();
            // stop the timer
            o_stopwatch.Stop();
            // show result in log
            mo_log.appendLog(Utility.wurfl.formatLog(o_stopwatch.Elapsed.TotalMilliseconds, cboUserAgent.SelectedItem.Text, lblResponse.Text));
            txtLog.Text = mo_log.logString;
        }

        protected void butClearLog_Click(object sender, EventArgs e)
        {
            mo_log.clearLog();
            txtLog.Text = string.Empty;
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Encore Software
Australia Australia
Contractor in Desktop and Web applications.
Gold Coast, Queensland.

Comments and Discussions