#region Disclaimer / License
// Copyright (C) 2010, Jackie Ng
// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com
//
// 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 Disclaimer / License
using OSGeo.MapGuide.MaestroAPI.Exceptions;
using OSGeo.MapGuide.MaestroAPI.Services;
using OSGeo.MapGuide.ObjectModels;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OSGeo.MapGuide.MaestroAPI.Capability
{
///
/// Base connection capabilitiy class
///
public abstract class ConnectionCapabilities : IConnectionCapabilities
{
///
/// Resource types supported on *all* versions of MapGuide
///
private static readonly string[] _defaultResTypes = {
//ResourceTypes.RuntimeMap.ToString(),
//ResourceTypes.Selection.ToString(),
//ResourceTypes.Folder.ToString(),
ResourceTypes.DrawingSource.ToString(),
ResourceTypes.FeatureSource.ToString(),
ResourceTypes.LayerDefinition.ToString(),
ResourceTypes.LoadProcedure.ToString(),
ResourceTypes.MapDefinition.ToString(),
ResourceTypes.PrintLayout.ToString(),
ResourceTypes.SymbolLibrary.ToString(),
ResourceTypes.WebLayout.ToString()
};
///
/// The parent connection
///
protected IServerConnection _parent;
///
/// Initializes a new instance of the class.
///
/// The parent.
protected ConnectionCapabilities(IServerConnection parent)
{
_parent = parent;
}
///
/// Gets the highest supported resource version.
///
///
///
public virtual Version GetMaxSupportedResourceVersion(string resourceType)
{
Version ver = new Version(1, 0, 0);
switch (resourceType)
{
case nameof(ResourceTypes.ApplicationDefinition):
if (!SupportsFusion())
throw new UnsupportedResourceTypeException(nameof(ResourceTypes.ApplicationDefinition));
break;
case nameof(ResourceTypes.WatermarkDefinition):
ver = GetMaxWatermarkDefinitionVersion();
break;
case nameof(ResourceTypes.MapDefinition):
ver = GetMaxMapDefinitionVersion();
break;
case nameof(ResourceTypes.LayerDefinition):
ver = GetMaxLayerDefinitionVersion();
break;
case nameof(ResourceTypes.LoadProcedure):
ver = GetMaxLoadProcedureVersion();
break;
case nameof(ResourceTypes.WebLayout):
ver = GetMaxWebLayoutVersion();
break;
case nameof(ResourceTypes.SymbolDefinition):
if (!SupportsAdvancedSymbols())
throw new UnsupportedResourceTypeException(nameof(ResourceTypes.SymbolDefinition));
else
ver = GetMaxSymbolDefinitionVersion();
break;
}
return ver;
}
///
/// Supportses the advanced symbols.
///
///
protected virtual bool SupportsAdvancedSymbols() => (_parent.SiteVersion >= new Version(1, 2));
///
/// Supportses the fusion.
///
///
protected virtual bool SupportsFusion() => (_parent.SiteVersion >= new Version(2, 0));
///
/// Gets the max watermark definition version
///
///
protected virtual Version GetMaxWatermarkDefinitionVersion()
{
if (_parent.SiteVersion >= new Version(2, 4))
return new Version(2, 4, 0);
return new Version(2, 3, 0);
}
///
/// Gets the max load procedure version.
///
///
protected virtual Version GetMaxLoadProcedureVersion()
{
if (_parent.SiteVersion >= new Version(2, 2))
return new Version(2, 2, 0);
if (_parent.SiteVersion >= new Version(2, 0))
return new Version(1, 1, 0);
return new Version(1, 0, 0);
}
///
/// Gets the max symbol definition version.
///
///
protected virtual Version GetMaxSymbolDefinitionVersion()
{
if (_parent.SiteVersion >= new Version(2, 4))
return new Version(2, 4, 0);
if (_parent.SiteVersion >= new Version(2, 0))
return new Version(1, 1, 0);
return new Version(1, 0, 0);
}
///
/// Gets the max web layout version.
///
///
protected virtual Version GetMaxWebLayoutVersion()
{
if (_parent.SiteVersion >= new Version(2, 6))
return new Version(2, 6, 0);
if (_parent.SiteVersion >= new Version(2, 4))
return new Version(2, 4, 0);
if (_parent.SiteVersion >= new Version(2, 2))
return new Version(1, 1, 0);
return new Version(1, 0, 0);
}
///
/// Gets the max map definition version
///
///
protected virtual Version GetMaxMapDefinitionVersion()
{
if (_parent.SiteVersion >= new Version(2, 4))
return new Version(2, 4, 0);
if (_parent.SiteVersion >= new Version(2, 3))
return new Version(2, 3, 0);
return new Version(1, 0, 0);
}
///
/// Gets the max layer definition version.
///
///
protected virtual Version GetMaxLayerDefinitionVersion()
{
if (_parent.SiteVersion >= new Version(2, 4))
return new Version(2, 4, 0);
if (_parent.SiteVersion >= new Version(2, 3))
return new Version(2, 3, 0);
if (_parent.SiteVersion >= new Version(2, 1))
return new Version(1, 3, 0);
if (_parent.SiteVersion >= new Version(2, 0))
return new Version(1, 2, 0);
if (_parent.SiteVersion >= new Version(1, 2))
return new Version(1, 1, 0);
return new Version(1, 0, 0);
}
///
/// Gets an array of supported commands
///
///
public abstract int[] SupportedCommands
{
get;
}
///
/// Gets an array of supported services
///
///
public virtual int[] SupportedServices
{
get
{
if (_parent.SiteVersion >= new Version(2, 0))
{
return new int[] {
(int)ServiceType.Resource,
(int)ServiceType.Feature,
(int)ServiceType.Fusion,
(int)ServiceType.Mapping,
(int)ServiceType.Tile,
(int)ServiceType.Drawing,
(int)ServiceType.Site
};
}
else //Fusion doesn't exist pre-2.0
{
return new int[] {
(int)ServiceType.Resource,
(int)ServiceType.Feature,
(int)ServiceType.Mapping,
(int)ServiceType.Tile,
(int)ServiceType.Drawing,
(int)ServiceType.Site
};
}
}
}
///
/// Indicates whether web-based previewing capabilities are possible with this connection
///
///
public abstract bool SupportsResourcePreviews
{
get;
}
///
/// Indicates whether the current connection can be used between multiple threads
///
///
public abstract bool IsMultithreaded
{
get;
}
///
/// Indicates if this current connection supports the specified resource type
///
///
///
public virtual bool IsSupportedResourceType(string resourceType)
{
Check.ArgumentNotEmpty(resourceType, nameof(resourceType));
return Array.IndexOf(this.SupportedResourceTypes, resourceType) >= 0;
}
///
/// Gets whether this connection supports publishing resources for WFS
///
public virtual bool SupportsWfsPublishing => true;
///
/// Gets whether this connection supports publishing resources for WMS
///
public virtual bool SupportsWmsPublishing => true;
///
/// Gets whether this connection supports resource reference tracking
///
public virtual bool SupportsResourceReferences => true;
///
/// Gets whether this connection supports resource security
///
public virtual bool SupportsResourceSecurity => true;
///
/// Gets whether this connection supports the concept of resource headers
///
public virtual bool SupportsResourceHeaders => true;
///
/// Gets the array of supported resource types
///
public string[] SupportedResourceTypes
{
get
{
var ver = _parent.SiteVersion;
var types = new HashSet(_defaultResTypes);
if (ver >= new Version(1, 2))
types.Add(ResourceTypes.SymbolDefinition.ToString());
if (ver >= new Version(2, 0))
types.Add(ResourceTypes.ApplicationDefinition.ToString());
if (ver >= new Version(2, 3))
types.Add(ResourceTypes.WatermarkDefinition.ToString());
if (ver >= new Version(3, 0))
types.Add(ResourceTypes.TileSetDefinition.ToString());
//When new types are introduced to MapGuide and we wish to add such support, put the new types here
return types.OrderBy(x => x).ToArray();
}
}
}
}