#region Disclaimer / License // Copyright (C) 2009, Kenneth Skovhede // http://www.hexad.dk, opensource@hexad.dk // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Text; using System.IO; using ObjCommon = OSGeo.MapGuide.ObjectModels.Common; using AppDef = OSGeo.MapGuide.ObjectModels.ApplicationDefinition; using OSGeo.MapGuide.ObjectModels.Capabilities; using OSGeo.MapGuide.MaestroAPI.Resource; using OSGeo.MapGuide.MaestroAPI.Commands; using OSGeo.MapGuide.ObjectModels.LoadProcedure; using OSGeo.MapGuide.MaestroAPI.Mapping; namespace OSGeo.MapGuide.MaestroAPI { /// /// Base class of all MapGuide connection classes. Covers functionality encompassed by /// the MapGuide Geospatial Platform API and the MapGuide-specific services (Site, Rendering, /// Mapping, Tile, Drawing) /// public abstract class MgServerConnectionBase : PlatformConnectionBase { /// /// A flag that indicates if a session will be automatically restarted /// protected bool m_autoRestartSession = false; /// /// The username used to open this connection, if any /// protected string m_username; /// /// The password used to open this connection, if any /// protected string m_password; /// /// cached user list /// protected ObjCommon.UserList m_cachedUserList = null; /// /// cached group list /// protected ObjCommon.GroupList m_cachedGroupList = null; /// /// Initializes a new instance of the class. /// protected MgServerConnectionBase() : base() { m_username = null; m_password = null; } #region Session Management /// /// Gets or sets a value indicating if the session should automatically be restarted if it expires /// virtual public bool AutoRestartSession { get { return m_autoRestartSession; } set { m_autoRestartSession = value; } } /// /// Determines if an exception is a "Session Expired" exception. /// /// The exception to evaluate /// True if the exception is a session expired exception abstract public bool IsSessionExpiredException(Exception ex); /// /// Restarts the server session, and creates a new session ID /// public void RestartSession() { RestartSession(true); } /// /// Restarts the server session, and creates a new session ID /// /// If set to true, the call throws an exception if the call failed /// True if the creation succeed, false otherwise abstract public bool RestartSession(bool throwException); #endregion #region Site /// /// Gets the site info. /// /// public abstract ObjCommon.SiteInformation GetSiteInfo(); /// /// Gets a list of all users on the server /// /// The list of users public virtual ObjCommon.UserList EnumerateUsers() { return this.EnumerateUsers(null); } /// /// Gets a list of users in a group /// /// The group to retrieve the users from /// The list of users abstract public ObjCommon.UserList EnumerateUsers(string group); /// /// Gets a list of all groups on the server /// /// The list of groups abstract public ObjCommon.GroupList EnumerateGroups(); #endregion #region Rendering /// /// Renders a minature bitmap of the layers style /// /// The scale for the bitmap to match /// The layer the image should represent /// If the layer is themed, this gives the theme index, otherwise set to 0 /// The geometry type, 1 for point, 2 for line, 3 for area, 4 for composite /// The minature bitmap abstract public System.Drawing.Image GetLegendImage(double scale, string layerdefinition, int themeIndex, int type); /// /// Renders the runtime map. /// /// The resource id. /// The x. /// The y. /// The scale. /// The width. /// The height. /// The dpi. /// public virtual System.IO.Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi) { return this.RenderRuntimeMap(resourceId, x, y, scale, width, height, dpi, "PNG", false); } /// /// Renders the runtime map. /// /// The resource id. /// The x1. /// The y1. /// The x2. /// The y2. /// The width. /// The height. /// The dpi. /// public virtual System.IO.Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi) { return this.RenderRuntimeMap(resourceId, x1, y1, x2, y2, width, height, dpi, "PNG", false); } /// /// Renders the runtime map. /// /// The resource id. /// The x. /// The y. /// The scale. /// The width. /// The height. /// The dpi. /// The format. /// public virtual System.IO.Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format) { return this.RenderRuntimeMap(resourceId, x, y, scale, width, height, dpi, format, false); } /// /// Renders the runtime map. /// /// The resource id. /// The x1. /// The y1. /// The x2. /// The y2. /// The width. /// The height. /// The dpi. /// The format. /// public virtual System.IO.Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format) { return this.RenderRuntimeMap(resourceId, x1, y1, x2, y2, width, height, dpi, format, false); } /// /// Renders the runtime map. /// /// The resource id. /// The x. /// The y. /// The scale. /// The width. /// The height. /// The dpi. /// The format. /// if set to true [clip]. /// public abstract System.IO.Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format, bool clip); /// /// Renders the runtime map. /// /// The resource id. /// The x1. /// The y1. /// The x2. /// The y2. /// The width. /// The height. /// The dpi. /// The format. /// if set to true [clip]. /// public abstract System.IO.Stream RenderRuntimeMap(string resourceId, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip); /// /// Renders a dynamic overlay image of the map /// /// /// /// /// public System.IO.Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format) { return RenderDynamicOverlay(map, selection, format, true); } /// /// Renders a dynamic overlay image of the map /// /// /// /// /// /// public abstract System.IO.Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, bool keepSelection); #endregion #region Tile /// /// Gets the tile. /// /// The mapdefinition. /// The baselayergroup. /// The col. /// The row. /// The scaleindex. /// The format. /// public abstract System.IO.Stream GetTile(string mapdefinition, string baselayergroup, int col, int row, int scaleindex, string format); #endregion #region Load Procedure /// /// Executes the load procedure. /// /// The load proc. /// The callback. /// if set to true [ignore unsupported]. /// public virtual string[] ExecuteLoadProcedure(ILoadProcedure loadProc, OSGeo.MapGuide.MaestroAPI.LengthyOperationProgressCallBack callback, bool ignoreUnsupported) { var cmd = new ExecuteLoadProcedure(GetInterface()); cmd.IgnoreUnsupportedFeatures = ignoreUnsupported; return cmd.Execute(loadProc, callback); } /// /// Executes the load procedure. /// /// The resource ID. /// The callback. /// if set to true [ignore unsupported]. /// public virtual string[] ExecuteLoadProcedure(string resourceID, OSGeo.MapGuide.MaestroAPI.LengthyOperationProgressCallBack callback, bool ignoreUnsupported) { var cmd = new ExecuteLoadProcedure(GetInterface()); cmd.IgnoreUnsupportedFeatures = ignoreUnsupported; return cmd.Execute(resourceID, callback); } #endregion } }