Brockmann: "Creating Rich Web
Applications Gets a Ton Easier"

e-grou chooses Visual WebGui
over standard ASP.NET

Quick migration of VB 6.0
Applications to the Web

Fully functional software versions
for 30 days evaluation period

Download the free edition of the
Visual WebGui Studio
 

Code Snippets

globalservices posted on March 17, 2009 :: 849 views

(Special thanks to AlexGoga for the base code.  I enhanced it with the warning and close events, I hope it helps!)

SessionTimeout.cs

#region

Using

using

System;

using

System.Text;

using

System.Data;

using

System.Drawing;

using

System.ComponentModel;

using

System.Collections.Generic;

using

Gizmox.WebGUI;

using

Gizmox.WebGUI.Forms;

using

Gizmox.WebGUI.Common;

using

Gizmox.WebGUI.Forms.Design;

using

Gizmox.WebGUI.Common.Interfaces;

using

Gizmox.WebGUI.Common.Extensibility;

#endregion

namespace

{

 

[

[

[

 

Ccp.Shared.WebGui.Forms[ToolboxItem(true)]ToolboxBitmapAttribute(typeof(SessionTimeout), "Ccp.Shared.WebGui.Forms.Source.SessionTimeout.bmp")]DesignTimeController("Gizmox.WebGUI.Forms.Design.PlaceHolderController, Gizmox.WebGUI.Forms.Design, Version=2.0.5701.0, Culture=neutral, PublicKeyToken=dd2a1fd4d120c769")]ClientController("Gizmox.WebGUI.Client.Controllers.PlaceHolderController, Gizmox.WebGUI.Client, Version=2.0.5701.0, Culture=neutral, PublicKeyToken=0fb8f99bd6cd7e23")]public partial class SessionTimeout : Gizmox.WebGUI.Forms.Component

{

 

 

 

int _warningMinutes = 0;int _logoutMinutes = 0;/// <summary>

 

/// Fired when a logout is issued.

 

/// </summary>

 

 

public event EventHandler LogOutEvent;/// <summary>

 

/// Fired when a user is warned of an impending logout

 

/// </summary>

 

 

public event EventHandler WarningEvent;/// <summary>

 

/// Fired when the user closes the browser.

 

/// </summary>

 

 

public event EventHandler CloseEvent;/// <summary>

 

/// Ctor

 

/// </summary>

 

{

InitializeComponent();

 

}

 

public SessionTimeout()this.RegisterSelf();/// <summary>

 

/// Sets the auto logout and warning time thresholds

 

/// </summary>

 

/// <param name="warningMinutes">The number of idle minutes a session must set before the user is warned.</param>

 

/// <param name="logoutMinutes">The number of idle minutes a session must set before the user is logged out. Must be greater than warningMinutes.</param>

 

{

 

 

_warningMinutes = warningMinutes;

_logoutMinutes = logoutMinutes;

 

 

 

 

 

}

 

public void SetTimeout(int warningMinutes, int logoutMinutes)if (warningMinutes > logoutMinutes)throw new Exception("warningMinutes cannot be greater than logoutMinutes.");int warningSeconds = warningMinutes * 60;int logoutSeconds = logoutMinutes * 60;this.InvokeMethodWithId("InitSessTimeOut", warningSeconds, logoutSeconds);if (LogOutEvent == null)throw new Exception("The LogOutEvent is not wired. You may also want to wire the WarningEvent.");/// <summary>

 

/// The difference between logoutMinutes and warningMinutes.

 

/// </summary>

 

{

 

public int MinutesLeadTimeget

{

 

}

}

 

return _logoutMinutes - _warningMinutes;/// <summary>

 

///

 

/// </summary>

 

/// <param name="objEvent"></param>

 

{

 

{

 

 

LogOutEvent(

 

 

 

WarningEvent(

 

 

 

CloseEvent(

 

 

 

 

}

}

}

}

protected override void FireEvent(IEvent objEvent)switch (objEvent.Type)case "Logout":if (LogOutEvent != null)this, new EventArgs());break;case "LogoutWarning":if (WarningEvent != null)this, new EventArgs());break;case "Close":if (CloseEvent != null)this, new EventArgs());break;default:base.FireEvent(objEvent);break;

 

SessionTimeout.js

var

_warningSeconds = 0;

var

_logoutSeconds = 0;

var

_intervalSeconds = 15;

var

_warningRaised = false;

var

_guid;

var

_timer;

var

 

_timerCounter = 0;

function

_warningSeconds = warningSeconds;

_logoutSeconds = logoutSeconds;

_guid = guid;

_timer = setTimeout(

document.body.onmouseover =

document.body.onkeypress =

window.onunload =

}

InitSessTimeOut(guid, warningSeconds, logoutSeconds) {"checkWarningTimerValues()", _intervalSeconds * 1000);function() { OnMove() };function() { OnMove() };function() { OnClose() };

function

_timerCounter += _intervalSeconds;

 

Events_CreateEvent(_guid,

Events_RaiseEvents();

clearTimeout(_timer);

_timer = setTimeout(

_warningRaised =

 

}

_timer = setTimeout(

}

checkWarningTimerValues() {if (_timerCounter >= _warningSeconds) {"LogoutWarning", true);"checkLogoutTimerValues()", _intervalSeconds * 1000);true;return;"checkWarningTimerValues()", _intervalSeconds * 1000);

function

_timerCounter += _intervalSeconds;

 

Events_CreateEvent(_guid,

Events_RaiseEvents();

clearTimeout(_timer);

 

}

_timer = setTimeout(

}

checkLogoutTimerValues() {if (_timerCounter >= _logoutSeconds) {"Logout", true);return;"checkLogoutTimerValues()", _intervalSeconds * 1000);

function

 

_timerCounter = 0;

 

clearTimeout(_timer);

_timer = setTimeout(

_warningRaised =

}

}

}

 

OnMove() {if (_timerCounter != 0) {if (_warningRaised) {"checkWarningTimerValues()", _intervalSeconds * 1000);false;

function

Events_CreateEvent(_guid,

Events_RaiseEvents();

}

OnClose() {"Close", true);

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.
Most promising startups
Top 3 most promising startups in 2009
   AJAX Framework | Web Development | Cloud applications | RIA Development | Silverlight Applications | Legacy Migration
The most popular open source Ajax applications framework for enterprises | Sitemap | Terms Of Use | Privacy Statement
Copyright © 2005-2009 Visual WebGui®    Design By: Template World
   
Visual Studio Partners