Pitney Bowes MapXtreme User Manual
Page 516

Appendix D: Extensible Data Providers
Advanced Topics / Important Considerations
MapXtreme v7.1
523
Developer Guide
DataProviderCallback cb = new DataProviderCallback();
cb.DataSourceDefinitionCallback = InvalidCredentialsCb;
// Associate the IDataProviderCallback with the EDP definition data type
Session.Current.Catalog.DataProviderCallbacksCollection.AddProviderCallba
ck(
typeof(EDPDataSourceDefinition), cb);
// Create an initially invalid Data Source Definition
EDPDataSourceDefinition dsd = new
EDPDataSourceDefinition("badpassword");
// open table
EDPTableDefinition tableDef = new EDPTableDefinition (dsd);
Table t = Session.Current.Catalog.OpenTable(tableDef, "TESTTABLE");
}
Implementing IDataProviderCallback usage in the Data Provider
The OpenDataSource and OpenTable methods on IDataProvider include an enumerator of
IDataProviderCallback instances. This enumerator is supplied by the Catalog automatically.
The DataProvider implementation is responsible for iterating over and invoking the callbacks if
necessary to attempt to complete the OpenDataSource|OpenTable operation.
An example DataProvider implementation might proceed along the following lines, to ensure that a
valid open data source is constructed:
public override IDataSource OpenDataSource(
IDataSourceDefinition definition,
CustomProperties customProperties,
IEnumerator
{
EDPDataSourceDefinition dsDef = definition as EDPDataSourceDefinition;
if (dsDef == null)
{
// invalid definition
// throw exception
}
EDPDataSourceDefinition tmpDsDef = dsDef;
EDPDataSource ds = null;
bool needDS = true;
while (needDS)
{
needDS = false;
DataProviderCallbackExceptionInfo cbinfo = null;
try
{
// Data Source ctor will fail if data source definition is invalid,
e.g., invalid credentials
ds = new EDPDataSource (tmpDsDef, customProperties);