Serializing mapxtreme objects in the proper order – Pitney Bowes MapXtreme User Manual

Page 119

Advertising
background image

Chapter 6: Understanding State Management

A Detailed Look at Manual State Management

MapXtreme v7.1

119

Developer Guide

3. At the end of the request processing cycle the Page_Unload method calls SaveState. SaveState

is also called after a map tool is used on the client.
The SaveState method saves the map's latest state, so that when and if the user submits yet
another request, that request will be able to call RestoreState again. Each call to SaveState is
performed in anticipation of a possible subsequent call to RestoreState, the next time a request
is received.

Private Sub Page_UnLoad(ByVal sender As Object, ByVal e As _

EventArgs) Handles MyBase.Unload

MapInfo.WebControls.StateManager.GetStateManagerFromSession()_

.SaveState()

End Sub

Serializing MapXtreme Objects in the Proper Order

In the AppStateManager class provided with the Thematics sample, the SaveState method calls the
ManualSerializer.SaveMapXtremeObjectIntoHttpSession method several times. The objects are
saved (serialized) in the following order:

ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Sessio
n.Current.Catalog(SampleConstants.EWorldAlias), "mdb_table")

ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Sessio
n.Current.Catalog(SampleConstants.ThemeTableAlias), "theme_table")

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

ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers(SampleCons
tants.GroupLayerAlias), "group_layer")

It is important that these SaveMapXtremeObjectIntoHttpSession calls occur in the correct order,
because some objects are dependent on other objects.

In this example, first we save tables (which are referenced through the Catalog). Next, we save
layers (which are referenced through the map's Layers collection). That is the appropriate order,
because most types of layers are dependent on tables.

For example, each FeatureLayer is associated with a table. The table must be open before you can
instantiate (or de-serialize) a FeatureLayer that uses that table. Therefore, this AppStateManager
class saves the tables first, and then saves the layers.

Similarly, in the RestoreState method, the data objects are restored first, followed by calls to restore
the layers:

ManualSerializer.RestoreMapXtremeObjectFromHttpSession("mdb_table")
ManualSerializer.RestoreMapXtremeObjectFromHttpSession("theme_table")
ManualSerializer.RestoreMapXtremeObjectFromHttpSession("theme_layer")
ManualSerializer.RestoreMapXtremeObjectFromHttpSession("group_layer")

Advertising