Developing your first Visual WebGui gateway

Page 2 of 2
  1. Introduction and Setting Up
  2. Finishing Up and Conclusion

Finishing Up and Conclusion

Step 3 - Creating a gateway handler

A gateway handler is actually a class that inherits from IGatewayHandler, which has one method called ProcessGatewayRequest. The ProcessGatewayRequest method handles the request just as an IHTTPHanlder inherited class. In the ProcessGatewayRequest method you can actually write any thing you want into the response and in this case the handler take the path it got in the constructor and writes that file to the response. Create this class in your project.

 

using System;
using System.Web;
using Gizmox.WebGUI.Common.Interfaces;

namespace WebGUIGatway
{
    publicclass FileHandler : IGatewayHandler
    {
        private string _path;

        public FileHandler(string path)
        {
            _path = path;
        }

        #region IGatewayHandler Memberspublicvoid ProcessGatewayRequest_
(IContext objContext, IRegisteredComponent objComponent) { HttpContext.Current.Response.WriteFile(_path); } #endregion } }

Step 4 - Creating a gateway

In order to use gateways you need to have a control inherit the IGatewayControl interface which is under the namespace Gizmox.WebGUI.Common.Interfaces. A single control can expose multiple gateways. The control gateways are identified by an action code. The action code serves as a page name allowing gateways to be referenced by name. In order to reference to a gateway you need to create a GatewayReference object. GatewayReference can be constructed using a component and an action code that together will provide a unique gateway reference. So let's go ahead and make our form a gateway by implementing the IGatewayControl interface. The IGatewayControl has one method called GetGatewayHandler that has an action argument. Using the action parameter we can return different gateway handlers for different actions. So let's go and use the gateway handler we created before on an action named "OpenFile". Notice that in the path constructor we use the current selected item Tag property to get the path of the selected file.

  public IGatewayHandler GetGatewayHandler(IContext objContext, string strAction)
{
    IGatewayHandler handler = null;

    switch(strAction)
    {
        case"OpenFile":
            if(listView1.SelectedItem!=null)
            {
                handler = new FileHandler((string)listView1.SelectedItem.Tag);
            }
            break;
    }

    return handler;
}

Step 5 - Using the gateway

Go back to the designer and select the list view control. From the properties of the list view go to the event section and double click the SelectedIndexChanged event. In the SelectedIndexChanged event handler let's create a GatewayReference object that can be found in the Gizmox.WebGUI.Common.Gateways namespace. Pass the constructor of the GatewayReference a reference to the form control and specify the action code of the gateway. When calling upon the ToString method of the GatewayReference class we get a relative path to the specified gateway. Use the relative path to set the htmlbox to show the current gateway. Calling the Update method on the HtmlBox will cause it to reload the control.

  private
  void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
    GatewayReference reference = new GatewayReference(this,"OpenFile");
    htmlBox1.Url = reference.ToString();
    htmlBox1.Update();
}

Conclusion

As you can see from this example gateways extend the WinForms object and bridge the environment differences. Using gateways come in handy in places that traditional web development concepts are required and can be used in order to provide interapobility between legacy resources and Visual WebGui. For an example a third party control that was designed for ASP.NET can easily be used through the use of a gateway, but that's for another tutorial.

History

Created on 5/5/2006 by Guy Peled.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan