Isessioneventhandlers, Serialization and persistence – Pitney Bowes MapXtreme User Manual

Page 199

Advertising
background image

Chapter 9: Working with Core MapXtreme Classes

Serialization and Persistence

MapXtreme v7.1

206

Developer Guide

ISessionEventHandlers

MapXtreme provides a MapInfo.Engine.ISessionEventHandler interface for loading custom DLLs
that extend MapXtreme’s functionality. Use this interface to autoload any extension DLLs that you
need for your application, such as extensible data providers, persistence providers, and styles that a
default workspace may use. When MapXtreme starts up, it will initialize these assemblies and carry
out the required instructions.

For example, MapXtreme provides a SpatiaLite sample implementation that, when compiled, yields
an assembly that contains code to support the SpatiaLite data provider as well as to load the data
provider when a MapXtreme session initializes.

In order for SessionEventHandler assemblies to be initialized on startup, they must be located in the
\Common Files\MapInfo\MapXtreme\7.x.x\SessionEventHandlers folder. In fact, any assembly in
this folder with the file suffix of .SessionEventHandler.DLL will be loaded.

The ISessionEventHandler interface provides two methods that can be called to load any extension
code you need for your application and provide additional initialization functionality.

void BeforeWorkspaceLoad(ISession session)

is called before any default workspaces are loaded, and could be used to set up any extensible data
providers, edp callbacks, edp persistance providers, named connections, load or create styles, open
tables, database connections etc. that might be used by a default workspace.

void AfterWorkspaceLoad(ISession session)

is called after any default workspaces (specified in app.config or web.config) are loaded. This is a
good place to do any final session initialization that your application could need.

When MapXtreme finds classes in the assembly that implement the ISessionEventHandler interface,
it constructs an instance of the class and adds it to an internal collection. Whenever a new
MapXtreme Session instance is created (once for a desktop application, can be multiple sessions for
web applications), all of the Session handlers are called with the instance of the session being
initialized.

Since there can be multiple SessionEvent handlers loaded and the order in which they are called is
indeterminate, if you are writing a handler, do not make any assumptions about what is already in
the session (ie: maps, tables, etc) .

Use this capability with caution! Any MapXtreme session created on that computer will load these
session event handlers. Adding handlers that display dialog windows or other user interface
components may cause web applications to hang as these dialogs will be displayed on the server.

Serialization and Persistence

A Map is bound to a ISession object. You cannot take a Map object from one ISession object and
use it in another. You have two options if you want to clone the entire ISession object; either by using
Serialization or by using Persistence.

Advertising