Category Archives: Web Development

Customized Configuration File Sections

The Microsoft .NET framework supports application figuration files for Windows applications, and web applications. An application configuration file is an XML document which contains settings specific to an application. The file contains configuration settings that the common language runtime can read. It can also contain settings that the application itself can read.

In this post I’ll show you how to create custom configuration file sections and how to access the configuration settings in an AVR.NET program. In order to demonstrate this concept, I have created an example AVR.NET application dealing with geometric shapes. In the application configuration file, I want to provide settings that an application administrator can manipulate, without modifying or rebuilding the application. For this example the settings will control the order in which geometric shapes will be drawn by the application.

Here is the XML of the App.config file

In this configuration example, everything is contained in the configuration section. Within the configSections element I describe my custom section with a sectionGroup element. On line 4 of the XML file I declare a sectionGroup named “shapeConfiguration” and a section named “shapeOrder”. I also specified that this section consists of name/value pairs by giving the type attribute a value of “System.Configuration.NameValueSectionHandler”. The type attribute is required, and specifies the name of the configuration section handler class, that handles the processing of the configuration settings that are in the section or element that is specified in the name attribute.

Accessing The Configuration File In AVR.NET

Accessing the configuration settings in an AVR.NET class will require two using statements;

The AVR.NET example will use the ConfigurationManager Class and the NameValueCollection class. The ConfigurationManager class will access the settings in the shapeOrder element of the configuration file. The NameValueCollection class will store the settings in memory as a collection of key/value pairs.

Here is the AVR.NET Code

The ConfigurationManager Class has a GetSection method that takes a string argument. Notice how the string is in file path notation for navigation to the shapeOrder element in the configuration file. The GetSection method returns a type of System.Object, so I used the AVR *As keyword to cast the name/value pairs of the shapeOrder element to a NameValueCollection. This type cast is also facilitated by the NameValueSectionHandler class I specified in the configuration file.

Now I can use the name value collection to assign a sorting rank to each instance of shape.

Here is the AVR.NET code

The NameValueCollection class has a Get method that accepts a string argument, which represents a key associated with a value in the collection. The Get method retrieves the value associated with the key. Notice how I used the Type class and the GetType method of each shape to form the key to get from the name value collection. This ensures that I retrieve the correct sort ranking associated with each shape object, no matter what the new instance of the shape class is called.

Each shape object has a RankOrder property which can be set based on the shapeOrder settings in the configuration file.

The GetShapesWithRank function in the above code snippet returns a generic list of shape objects. In my next post I’ll show you how to sort the generic list of shapes based on the RankOrder property of each shape.

Object Oriented Programming Stuff

Each shape class is derived from a shape base class which implements a shape interface. In the code snippet below, you can see that the IShape interface provides an abstraction for all shape entities referenced by the application. The interface defines only the essential elements of a shape;

  • Rank Order – a property that defines the rank of a shape in a hierarchy
  • Draw – a method for drawing a shape

The Shape class implements the IShape interface. You can see that the implementation of the Rank Order property is now concrete. However, the Draw method remains abstract and it is defined as a virtual method by the Modifier keyword with a value of *Overridable.

The concrete implementation of shape is completed in the Square class and the Circle class. They inherit from the Shape base class and override the Draw method with their own unique implementation. The Modifier keyword with a value of *Overrides facilitates the concrete implementation.

The following code sample demonstrates how well AVR.NET supports object oriented programming concepts like abstraction and inheritance. This design makes the AVR.NET code more flexible, reusable and maintainable. This design is much less vulnerable to the impact of ever changing requirements.

Here is the AVR.NET code where the shapes object model is defined

The complete source code of the application developed for this post can be downloaded here.

Controlling Browser Session Timeout

The content for today’s post was contributed by Jonathan Greenstreet, ASNA Europe Regional Manager UK/Ireland/Netherlands/Scandinavia/South Africa.

ASNA offers products and technologies that will transform the green screen user interface, of RPG based applications running on the IBM i server, into a browser based graphical user interface. One of the challenges of modernizing and migrating the user interface is to make the migration as seamless as possible for the legacy end user community. ASNA has been resolving these challenges for many years with a combination of innovative products, technologies and professional services.

In today’s post Jonathan offers a very simple and effective way of controlling browser session timeout duration, so that the modernized user interface behaves in a way that legacy application users are familiar and comfortable with.

How to stop the browser from timing out with iFrame or jQuery

Summary
To enable the browser not to time out when it is inactive and to enable the server to close down the session soon after the browser has been closed.

Reason for requirements
The default session timeout for Internet Information Server (IIS) is 20 minutes. Although this is normally fine for a typical web application it is not the expected behavior that a traditional 5250 user expects.

A 5250 user expects the application to be available while the browser is open and for the connection to be freed up as soon as the web browser is closed.

Although it is possible in some browsers using JavaScript to detect when they close down, it is not a reliable way to ensure the closing of a session in a timely manner.

Alternative approaches and problems they can cause
The session timeout time can be increased or decreased, by adjusting the time (in minutes) for the sessionState in the web.config file of the project.

The problem with having a long timeout set is that, if the browser is closed while in the application and no notification is sent to IIS about this, the session will remain open for the duration of its set timeout. This can cause problems if database connections are left open and file locks are retained, it will also not allow other resources to be released until the session ends.

The problem with having a short timeout set is that the user has to continually interact with the application to keep their session active and prevent it from timing out. This is the opposite of what a user coming from a 5250 environment expects.

Solutions
Both the following solutions allow you to set the sessionState timeout to its lowest value of 1 minute and allow the application without user interaction to notify IIS that the session should still remain open.

The limitation with both of these solutions is that the session may remain active for a least a minute after the browser has been closed.

Solution 1: iFrame
Create a new aspx page in the project for the browser to communicate with. The page does not need to have code placed in a separate file.

The page can be extremely simple. In the example below I have created a page “Reconnect.aspx” in the root of the directory.

The language could also be C# or VB.

Ensures that the page is never cashed and a new one is delivered every time

Allows the page to be refreshed at required intervals. We have set this to 55 seconds so that it is less than the 60 seconds at which the session timeout is set.

Returns the path relative to the current page. This is very important if you want to use a cookie less environment.

In all the application pages or, better yet, in the master pages add the following iFrame

Finally to ensure the session is set to timeout after 1 minute set the timeout for the sessionState to 1 minute

Solution 2: jQuery
Ensure that your pages or master pages that are required not to time out have the jQuery .js available to them.

Create a new page. In the example below I have created a page “Reconnect.aspx” in the root of the directory.

Add the following JavaScript to the required pages of master pages;

Finally to ensure the session is set to timeout after 1 minute set the timeout for the sessionState to 1 minute