#region Disclaimer / License
// Copyright (C) 2012, 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
using System;
using System.Collections.Generic;
using System.Text;
using OSGeo.MapGuide.MaestroAPI.Feature;
namespace OSGeo.MapGuide.MaestroAPI.Commands
{
///
/// A default implementation of . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultCommand : ICommand where TConn : IServerConnection
{
///
/// Gets the connection implementation.
///
public TConn ConnImpl { get { return (TConn)this.Parent; } }
///
/// Initializes a new instance of the class.
///
/// The conn.
protected DefaultCommand(TConn conn)
{
this.Parent = conn;
}
///
/// Gets the parent connection.
///
///
/// The parent connection.
///
public IServerConnection Parent
{
get;
private set;
}
///
/// Validates the core commnad parameters.
///
protected void ValidateCoreParams()
{
if (this.Parent == null)
throw new InvalidOperationException("Null parent connection"); //LOCALIZEME
}
}
///
/// A default implementation of the . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultFeatureCommand : DefaultCommand, IFeatureCommand where TConn : IServerConnection
{
///
/// Initializes a new instance of the class.
///
/// The conn.
protected DefaultFeatureCommand(TConn conn) : base(conn) { }
///
/// Gets or sets the feature source id.
///
///
/// The feature source id.
///
public string FeatureSourceId
{
get;
set;
}
///
/// Gets or sets the name of the class.
///
///
/// The name of the class.
///
public string ClassName
{
get;
set;
}
///
/// Performs basic validation of core command parameters
///
protected void ValidateParams()
{
base.ValidateCoreParams();
if (string.IsNullOrEmpty(this.FeatureSourceId))
throw new InvalidOperationException(Strings.ErrorNoFeatureSourceIdSpecified);
if (string.IsNullOrEmpty(this.ClassName))
throw new InvalidOperationException(Strings.ErrorNoFeatureSourceIdSpecified);
}
}
///
/// A default implementation of . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultInsertCommand : DefaultFeatureCommand, IInsertFeatures where TConn : IServerConnection
{
///
/// Initializes a new instance of the
///
/// The conn.
protected DefaultInsertCommand(TConn conn) : base(conn) { }
///
/// Gets or sets the record to insert.
///
///
/// The record to insert.
///
public IMutableRecord RecordToInsert
{
get;
set;
}
///
/// Performs the actual command execution
///
protected abstract void ExecuteInternal();
///
/// Executes this instance.
///
///
public InsertResult Execute()
{
var res = new InsertResult();
try
{
base.ValidateParams();
if (this.RecordToInsert == null)
throw new InvalidOperationException(Strings.ErrorNothingToInsert);
this.ExecuteInternal();
}
catch (Exception ex)
{
res.Error = ex;
}
return res;
}
}
///
/// A default implementation of . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultUpdateCommand : DefaultFeatureCommand, IUpdateFeatures where TConn : IServerConnection
{
///
/// Initializes a new instance of the class.
///
/// The parent.
public DefaultUpdateCommand(TConn parent) : base(parent) { }
///
/// Gets or sets the filter.
///
///
/// The filter.
///
public string Filter
{
get;
set;
}
///
/// Gets or sets the values to update.
///
///
/// The values to update.
///
public IMutableRecord ValuesToUpdate
{
get;
set;
}
///
/// Performs the actual execution of the command
///
///
public abstract int ExecuteInternal();
///
/// Executes this instance.
///
///
public int Execute()
{
base.ValidateParams();
if (this.ValuesToUpdate == null)
throw new InvalidOperationException(Strings.ErrorNoValuesSpecifiedForUpdating);
return ExecuteInternal();
}
}
///
/// A default implementation of . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultDeleteCommand : DefaultFeatureCommand, IDeleteFeatures where TConn : IServerConnection
{
///
/// Initializes a new instance of the class.
///
/// The conn.
protected DefaultDeleteCommand(TConn conn) : base(conn) { }
///
/// Gets or sets the filter.
///
///
/// The filter.
///
public string Filter
{
get;
set;
}
///
/// Executes this instance.
///
///
public int Execute()
{
this.ValidateParams();
return this.ExecuteInternal();
}
///
/// Performs actual execution of the command
///
///
protected abstract int ExecuteInternal();
}
///
/// A default implementation of . This class is reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultApplySchemaCommand : DefaultFeatureCommand, IApplySchema where TConn : IServerConnection
{
///
/// Initializes a new instance of the class.
///
/// The conn.
protected DefaultApplySchemaCommand(TConn conn) : base(conn) { }
///
/// Gets or sets the schema.
///
///
/// The schema.
///
public OSGeo.MapGuide.MaestroAPI.Schema.FeatureSchema Schema
{
get;
set;
}
///
/// Gets or sets the feature source id.
///
///
/// The feature source id.
///
public string FeatureSourceId
{
get;
set;
}
///
/// Executes this instance.
///
public void Execute()
{
base.ValidateCoreParams();
if (string.IsNullOrEmpty(this.FeatureSourceId))
throw new InvalidOperationException(Strings.ErrorEmptyFeatureSourceId);
if (this.Schema == null)
throw new InvalidOperationException(Strings.ErrorNoSchemaSpecifiedToApply);
this.ExecuteInternal();
}
///
/// Performs the actual command execution
///
protected abstract void ExecuteInternal();
}
///
/// A default implementation of . Reserved for connection provider use
///
/// The type of the conn.
public abstract class DefaultCreateDataStoreCommand : DefaultCommand, ICreateDataStore where TConn : IServerConnection
{
///
/// Initializes a new instance of the class.
///
/// The conn.
protected DefaultCreateDataStoreCommand(TConn conn) : base(conn) { }
///
/// Gets or sets the schema.
///
///
/// The schema.
///
public OSGeo.MapGuide.MaestroAPI.Schema.FeatureSchema Schema
{
get;
set;
}
///
/// Gets or sets the feature source id.
///
///
/// The feature source id.
///
public string FeatureSourceId
{
get;
set;
}
///
/// Gets or sets the provider.
///
///
/// The provider.
///
public string Provider
{
get;
set;
}
///
/// Gets or sets the name of the file.
///
///
/// The name of the file.
///
public string FileName
{
get;
set;
}
///
/// Executes this instance.
///
public void Execute()
{
this.ValidateCoreParams();
if (string.IsNullOrEmpty(this.FeatureSourceId))
throw new InvalidOperationException(Strings.ErrorNoFeatureSourceIdSpecified);
if (string.IsNullOrEmpty(this.CoordinateSystemWkt))
throw new InvalidOperationException(Strings.ErrorNoCoordinateSystemWktSpecified);
if (this.Extent == null && this.ExtentType != OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType.Dynamic)
throw new InvalidOperationException(Strings.ErrorNoExtentSpecifiedForStaticType);
if (string.IsNullOrEmpty(this.FileName))
throw new InvalidOperationException(Strings.ErrorNoFileNameSpecified);
if (string.IsNullOrEmpty(this.Name))
throw new InvalidOperationException(Strings.ErrorNoSpatialContextNameSpecified);
if (string.IsNullOrEmpty(this.Provider))
throw new InvalidOperationException(Strings.ErrorNoProviderSpecified);
if (this.Schema == null)
throw new InvalidOperationException(Strings.ErrorNoSchemaSpecified);
this.ExecuteInternal();
}
///
/// Performs actual execution of the command.
///
protected abstract void ExecuteInternal();
///
/// Gets or sets the name of the coordinate system.
///
///
/// The name of the coordinate system.
///
public string CoordinateSystemName
{
get;
set;
}
///
/// Gets or sets the coordinate system WKT.
///
///
/// The coordinate system WKT.
///
public string CoordinateSystemWkt
{
get;
set;
}
///
/// Gets or sets the description.
///
///
/// The description.
///
public string Description
{
get;
set;
}
///
/// Gets or sets the extent.
///
///
/// The extent.
///
public OSGeo.MapGuide.ObjectModels.Common.IEnvelope Extent
{
get;
set;
}
///
/// Gets or sets the type of the extent.
///
///
/// The type of the extent.
///
public OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType ExtentType
{
get;
set;
}
///
/// Gets or sets the name of the spatial context to create.
///
///
/// The name.
///
public string Name
{
get;
set;
}
///
/// Gets or sets the XY tolerance.
///
///
/// The XY tolerance.
///
public double XYTolerance
{
get;
set;
}
///
/// Gets or sets the Z tolerance.
///
///
/// The Z tolerance.
///
public double ZTolerance
{
get;
set;
}
///
///
///
///
///
public void WriteXml(System.Xml.XmlDocument doc, System.Xml.XmlNode currentNode)
{
throw new NotImplementedException();
}
///
///
///
///
///
public void ReadXml(System.Xml.XmlNode node, System.Xml.XmlNamespaceManager mgr)
{
throw new NotImplementedException();
}
}
}