Automatically deserializing mapxtreme objects, Handling initial requests – Pitney Bowes MapXtreme User Manual

Page 120

Advertising
background image

Chapter 6: Understanding State Management

A Detailed Look at Manual State Management

MapXtreme v7.1

120

Developer Guide

Automatically Deserializing MapXtreme Objects

In the SaveState method, we identify the objects to be saved using specific references, such as a
specific layer in the map:

ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers(SampleCons
tants.ThemeLayerAlias), "theme_layer")

The RestoreState method, however, does not reference the Catalog or the map.Layers collection. In
the RestoreState method, we call methods on the ManualSerializer class, but we do not do anything
with the results from that call, and there is no reference to a map.Layers collection: They are de-
serialized automatically to the appropriate place in the Catalog or Layers collection, or wherever
necessary.

ManualSerializer.RestoreMapXtremeObjectFromHttpSession("theme_layer")

L

Use the ManualSerializer class to carry out saving and restoring objects. Do not store
MapXtreme objects directly into the HttpSessionState using syntax such as:

HttpContext.Current.Session.Item("myTable") = _

MapInfo.Engine.Session.Current.Catalog("myTable")

Handling Initial Requests

Application state is a server-side state management mechanism that is used to store information
that is common, or global, to all user sessions. Application state is initialized when
Session.IsNewSession is true. Application state is an important element when handling initial
requests.

In the case of MapXtreme, Application state holds the initial state of a background map so that any
user’s initial request will receive the map in this default state.

The MapXtreme Thematics sample demonstrates the steps to take to handle initial requests.

There are two different types of "first" requests that your application must handle: 1) the first request
from the very first user to access the web application, and 2) first requests from all subsequent
users.

The very first time any user uses the application, a clean MapXtreme Session is retrieved from the
pool with a background map in its initial state. This initial state is stored in Application state and used
like a template. This happens in the SaveDefaultState method.

The first request from all subsequent users makes a call to RestoreDefaultState, which retrieves the
initial state of the map from Application state.

The following are the steps related to initial requests.

1. In the Page_Load method, check to see if the current session is new. If it is, instantiate your

StateManager and add the MapAlias into the state manager's ParamsDictionary property. This is
mandatory when using Manual state management.

2. Next in the Page_Load method, since this is a new session, we initialize application data by

calling the InitState method. In the InitState method, we prepare the initial state of the map.

Advertising