Persistence – Pitney Bowes MapXtreme User Manual

Page 201

Advertising
background image

Chapter 9: Working with Core MapXtreme Classes

Opening and Saving a Workspace Containing Named Resources

MapXtreme v7.1

208

Developer Guide

Persistence

Persistence in MapXtreme is the is the process of storing application objects to MapInfo Workspace
(.MWS) files, which exist in XML format. Persisting and de-persisting ISession objects is done using
the WorkSpacePersistence and WorkSpaceLoader classes. These two classes will write out and
read in .MWS files. The application can write out the workspace (a copy of the Session), and apply
the contents of the workspace file to a new Session object, creating a clone of the Session.

VB example:

Public Shared Sub MapInfo_Persistence_WorkSpacePersistenceSave()
' Create a named connection point to "D:\data\version2"

Dim info As NamedConnectionInfo = New NamedConnectionInfo("file",_

ConnectionMethod.FilePath, "D:\data\version2")

Session.Current.Catalog.NamedConnections.Add("MyDataFolder",_

info)

' Create a map

Dim map As Map =
Session.Current.MapFactory.CreateEmptyMap("MyMap",_

"MyMapAlias", New Size(400, 400))

Dim table As Table =
Session.Current.Catalog.OpenTable("MyDataFolder", _

"myTableAlias", "Seamless\Lines - NYALBA\SeamCapDist.TAB")

map.Layers.Add(New FeatureLayer(table))

' Save the Session to a workspace file

Dim w As WorkSpacePersistence = New WorkSpacePersistence

w.Save("c:\workspace\mySeamless.mws")
End Sub

Note that adding a workspace (using the WorkSpaceLoader class) is an cumulative process. To
ensure the Mapxtreme Session only contains the contents of the new workspace file, call Reload()
method on the ISession object first. This method clears the Session state and reloads pre-defined
workspaces in the application’s Web.config file.

For more information on persistence and the XML schema, see

Appendix C: Understanding the

MapInfo Workspace

.

Opening and Saving a Workspace Containing Named Resources

MapXtreme supports named resources for map definitions, map layers, data source definitions and
styles. Previously MapXtreme supported named connections. Named resources are references to a
resource in another location and identified by a name.

MapInfo Workspace format files (.MWS) containing named resources can be opened and saved
programmatically through the INamedResourceResolver interface in the MapInfo.Engine
namespace. This interface contains the functions to resolve the named resources while parsing the
MWS file and also to generate the named resources xml node when saving the MWS file.

Advertising