Workflow and ServiceDesk Community

 View Only

Custom C# Component - Determining the Client Browser 

Sep 28, 2015 03:17 PM

Original article is posted here.

While developing a workflow project for a customer, I noticed that some machines in the customer environment were using IE9 as the primary browser.  I also noticed that my form design worked very poorly in IE9.  Because the team I was working with had a bit of control over the business paradigm, I was able to design the form to indicate to the end user that “IE9 is an unsupported browser, please use Chrome or etc etc”.  This was fantastic, since I really didn’t want to have to go back and redesign everything to work with IE9.

In this post response by reecardo, it’s mentioned that the Get HTTP Request Value component can be configured to return the HTTP_USER_AGENT string.  So instead of doing all the work to parse that string reliably, (see this article to find out why this string response is so convoluted), I decided to instead use that time to learn some more C#.

Here’s my run at building a Code (Script) Component that returns usable values containing client browser data.  (note that I certainly do not expect all of my code or syntax to pass any par, standards tests, or peer reviews; I only dabble in coding in order to extend the capabilities of the Workflows I develop.  feel free to reply with any corrections or constructive criticisms)


In order to test this, let’s start with a clean project.  Add the components, connected as illustrated below:

  • Initialize Data
  • Code (Script) Component
  • Form Builder
  • Hanging Path Trigger
  • Exception Trigger

2015-01-17_11-48-56.png

In the Initialize Data component, declare a “Key Value Pair” variable to hold the browser data we want.

2015-01-17_11-52-46.png

On the Form Builder component, add some elements like the Label component andAsciiMergeLabel component to display the browser data.

2015-01-17_12-43-17.png

Now, for the Code (Script) Component.

We aren’t using input variables for this component, so leave Page 1 blank.

Configure the “BrowserResult” key value pair variable as the Result on Page 2.

2015-01-17_10-51-22.png

Enter the following code on Page 3, using C# as the language, and these namespaces:

  • System
  • System.Web
  • LogicBase.Core.Data.DataTypes
HttpBrowserCapabilities Prefix = HttpContext.Current.Request.Browser;
string bKey = Prefix.Browser.ToString();
string bValue = Prefix.MajorVersion.ToString();
return new KeyValueDataType(bKey,bValue);

 

While I chose to use “Prefix.Browser” (e.g. “Chrome”) and “Prefix.MajorVersion” (e.g. “39”), other output options are available.  See this article for more info.

On Page 4, ignore the tests, as the result will not be satisfactory.  The context of this component is expected to be run within a browser, and as such, the test option here will fail.

2015-01-17_10-52-17.png

Click Finish to close.


Test the project in different browsers to see the results.

2015-01-17_13-00-00.png


When compared to my original attempt at parsing the returned string from the Get HTTP Request Value, it should be apparent why I prefer this method.

Original (the Http Get component is using an API to return a translation of the HTTP_USER_AGENT string):

2015-01-17_10-47-14.png

Custom C# component:

2015-01-17_10-47-38.png

So the process has been streamlined a bit, and requires far less effort.


Featured Components

Get HTTP Request Value

Code (Script) Component

Initialize Data

Form Builder

Hanging Path Trigger

Exception Trigger

Label

Ascii Merge Label


A demo package is available for this concept, and has been attached to this article.

Other articles, demos, tips and tricks can be found at atmaworkflow.com.

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
package file
BrowserVersionDemo.package   41 KB   1 version
Uploaded - Mar 11, 2020

Tags and Keywords

Related Entries and Links

No Related Resource entered.