本文整理汇总了C#中FdoToolbox.Core.Feature.FdoConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FdoConnection.Open方法的具体用法?C# FdoConnection.Open怎么用?C# FdoConnection.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FdoToolbox.Core.Feature.FdoConnection
的用法示例。
在下文中一共展示了FdoConnection.Open方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override int Execute()
{
CommandStatus retCode;
FdoConnection conn = null;
try
{
conn = new FdoConnection(_provider, _connStr);
conn.Open();
}
catch (OSGeo.FDO.Common.Exception ex)
{
WriteException(ex);
retCode = CommandStatus.E_FAIL_CONNECT;
return (int)retCode;
}
using (conn)
{
using (FdoFeatureService service = conn.CreateFeatureService())
{
try
{
service.CreateDataStore(_dstoreStr);
WriteLine("Data Store Created!");
retCode = CommandStatus.E_OK;
}
catch (OSGeo.FDO.Common.Exception ex)
{
WriteException(ex);
retCode = CommandStatus.E_FAIL_CREATE_DATASTORE;
return (int)retCode;
}
}
if (conn.State != FdoConnectionState.Closed)
conn.Close();
}
return (int)retCode;
}
示例2: Connect
public bool Connect()
{
var builder = new System.Data.Common.DbConnectionStringBuilder();
builder["Username"] = _view.Username;
builder["Password"] = _view.Password;
builder["Service"] = _view.Service;
if (!string.IsNullOrEmpty(_view.OracleSchema))
builder["OracleSchema"] = _view.OracleSchema;
if (!string.IsNullOrEmpty(_view.KingFdoClass))
builder["KingFdoClass"] = _view.KingFdoClass;
if (!string.IsNullOrEmpty(_view.SdeSchema))
builder["SDE Schema"] = _view.SdeSchema;
FdoConnection conn = new FdoConnection("OSGeo.KingOracle", builder.ToString());
if (conn.Open() == FdoConnectionState.Open)
{
IFdoConnectionManager mgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
mgr.AddConnection(_view.ConnectionName, conn);
return true;
}
_view.ShowMessage(null, "Connection failed");
return false;
}
示例3: Connect
public bool Connect()
{
if (string.IsNullOrEmpty(_view.ConnectionName))
{
_view.ShowMessage(null, "Name required");
return false;
}
FdoConnection conn = new FdoConnection("OSGeo.ODBC", string.Format("ConnectionString=\"{0}\"", _view.BuilderObject.ToConnectionString()));
if (FileService.FileExists(_view.ConfigurationFile))
{
conn.SetConfiguration(_view.ConfigurationFile);
}
if (conn.Open() == FdoConnectionState.Open)
{
IFdoConnectionManager mgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
mgr.AddConnection(_view.ConnectionName, conn);
return true;
}
_view.ShowMessage(null, "Connection test failed");
return false;
}
示例4: TestConnection
public void TestConnection()
{
FdoConnection conn = new FdoConnection("OSGeo.ODBC", string.Format("ConnectionString=\"{0}\"", _view.BuilderObject.ToConnectionString()));
try
{
FdoConnectionState state = conn.Open();
if (state == FdoConnectionState.Open)
{
_view.ShowMessage(null, "Test successful");
conn.Close();
}
else
{
_view.ShowError("Connection test failed");
}
}
catch (FdoException ex)
{
_view.ShowError(ex.InnerException.Message);
}
}
示例5: Execute
public override int Execute()
{
CommandStatus retCode;
FdoConnection srcConn = new FdoConnection(_srcProvider, _srcConnStr);
FdoConnection destConn = null;
//Directory given, assume SHP
if (Directory.Exists(_destPath))
{
destConn = new FdoConnection("OSGeo.SHP", "DefaultFileLocation=" + _destPath);
}
else
{
if (ExpressUtility.CreateFlatFileDataSource(_destPath))
destConn = ExpressUtility.CreateFlatFileConnection(_destPath);
else
throw new FdoException("Could not create data source: " + _destPath);
}
try
{
srcConn.Open();
destConn.Open();
string srcName = "SOURCE";
string dstName = "TARGET";
FdoBulkCopyOptions options = new FdoBulkCopyOptions();
options.RegisterConnection(srcName, srcConn);
options.RegisterConnection(dstName, destConn);
using (FdoFeatureService srcService = srcConn.CreateFeatureService())
using (FdoFeatureService destService = destConn.CreateFeatureService())
{
//See if spatial context needs to be copied to target
if (!string.IsNullOrEmpty(_srcSpatialContext))
{
SpatialContextInfo srcCtx = srcService.GetSpatialContext(_srcSpatialContext);
if (srcCtx != null)
{
Console.WriteLine("Copying spatial context: " + srcCtx.Name);
ExpressUtility.CopyAllSpatialContexts(new SpatialContextInfo[] { srcCtx }, destConn, true);
}
}
else
{
//Copy all
ExpressUtility.CopyAllSpatialContexts(srcConn, destConn, true);
}
FeatureSchema srcSchema = null;
//See if partial class list is needed
if (_srcClasses.Count > 0)
{
WriteLine("Checking if partial schema discovery is supported: " + srcService.SupportsPartialSchemaDiscovery());
srcSchema = srcService.PartialDescribeSchema(_srcSchema, _srcClasses);
}
else //Full copy
{
WriteLine("No classes specified, reading full source schema");
srcSchema = srcService.GetSchemaByName(_srcSchema);
}
if (srcSchema == null)
{
WriteError("Could not find source schema: " + _srcSchema);
retCode = CommandStatus.E_FAIL_SCHEMA_NOT_FOUND;
}
else
{
WriteLine("Checking source schema for incompatibilities");
FeatureSchema targetSchema = null;
IncompatibleSchema incSchema;
if (destService.CanApplySchema(srcSchema, out incSchema))
{
int clsCount = srcSchema.Classes.Count;
WriteLine("Applying source schema (containing " + clsCount + " classes) to target");
destService.ApplySchema(srcSchema, null, true);
targetSchema = srcSchema;
}
else
{
WriteWarning("Incompatibilities were detected in source schema. Applying a modified version to target");
FeatureSchema fixedSchema = destService.AlterSchema(srcSchema, incSchema);
int clsCount = fixedSchema.Classes.Count;
WriteLine("Applying modified source schema (containing " + clsCount + " classes) to target");
destService.ApplySchema(fixedSchema, null, true);
targetSchema = fixedSchema;
}
//Now set class copy options
foreach (ClassDefinition cd in srcSchema.Classes)
{
FdoClassCopyOptions copt = new FdoClassCopyOptions(srcName, dstName, srcSchema.Name, cd.Name, targetSchema.Name, cd.Name);
copt.FlattenGeometries = _flatten;
options.AddClassCopyOption(copt);
}
if (_flatten)
{
//.........这里部分代码省略.........
示例6: TestConnection
public void TestConnection()
{
FdoProviderInfo provider = _view.SelectedProvider;
string connStr = ExpressUtility.ConvertFromNameValueCollection(_view.ConnectProperties);
FdoConnection conn = new FdoConnection(provider.Name, connStr);
try
{
FdoConnectionState state = conn.Open();
if (state == FdoConnectionState.Open || state == FdoConnectionState.Pending)
{
_view.ShowMessage(null, "Test successful");
conn.Close();
}
else
{
_view.ShowError("Connection test failed");
}
}
catch (FdoException ex)
{
_view.ShowError(ex.InnerException.Message);
}
finally
{
conn.Dispose();
}
}
示例7: Connect
public bool Connect()
{
if (string.IsNullOrEmpty(_view.ConnectionName))
{
_view.FlagNameError("Required");
return false;
}
FdoConnection conn = _manager.GetConnection(_view.ConnectionName);
if (conn != null)
{
_view.FlagNameError("A connection named " + _view.ConnectionName + " already exists");
return false;
}
FdoProviderInfo provider = _view.SelectedProvider;
//string connStr = ExpressUtility.ConvertFromNameValueCollection(_view.ConnectProperties);
NameValueCollection cp = new NameValueCollection(_view.ConnectProperties);
if (_pendingProperties.Count > 0)
{
NameValueCollection extra = new NameValueCollection();
cp.Add(extra);
}
string connStr = ExpressUtility.ConvertFromNameValueCollection(cp);
conn = new FdoConnection(provider.Name, connStr);
if (FileService.FileExists(_view.ConfigFile))
{
try
{
conn.SetConfiguration(_view.ConfigFile);
}
catch (Exception ex)
{
conn.Dispose();
_view.FlagConfigError(ex.Message);
return false;
}
}
try
{
FdoConnectionState state = conn.Open();
if (state == FdoConnectionState.Open)
{
_manager.AddConnection(_view.ConnectionName, conn);
return true;
}
else if (state == FdoConnectionState.Pending)
{
//Re-query the pending parameters and re-prompt in a new dialog
if (_pendingProperties.Count > 0)
{
List<DictionaryProperty> pend = new List<DictionaryProperty>();
foreach (DictionaryProperty p in _pendingProperties)
{
pend.Add(conn.GetConnectTimeProperty(p.Name));
}
NameValueCollection extra = PendingParameterDialog.GetExtraParameters(pend);
//Cancelled action
if (extra == null)
return false;
cp.Add(extra);
conn.ConnectionString = ExpressUtility.ConvertFromNameValueCollection(cp);
if (conn.Open() == FdoConnectionState.Open)
{
_manager.AddConnection(_view.ConnectionName, conn);
return true;
}
}
}
else
{
return false;
}
}
catch (Exception ex)
{
_view.ShowError(ex);
conn.Dispose();
return false;
}
return false;
}
示例8: Initialize
/// <summary>
/// Initializes this instance.
/// </summary>
protected override void Initialize()
{
SendMessage("Creating target data source");
if (!ExpressUtility.CreateFlatFileDataSource(_outputFile))
throw new FdoETLException(ResourceUtil.GetStringFormatted("ERR_CANNOT_CREATE_DATA_FILE", _outputFile));
_outConn = ExpressUtility.CreateFlatFileConnection(_outputFile);
_outConn.Open();
ClassDefinition cd = _table.CreateClassDefinition(true);
using (FdoFeatureService service = _outConn.CreateFeatureService())
{
SendMessage("Applying schema to target");
FeatureSchema schema = new FeatureSchema("Schema1", "Default schema");
schema.Classes.Add(cd);
service.ApplySchema(schema);
}
SendMessage("Copying any attached spatial contexts");
ExpressUtility.CopyAllSpatialContexts(_table.SpatialContexts, _outConn, true);
Register(new FdoFeatureTableInputOperation(_table));
Register(new FdoOutputOperation(_outConn, cd.Name));
}
示例9: Test
internal bool Test()
{
using (var conn = new FdoConnection(_view.Provider, GetBaseConnectionString()))
{
if (conn.Open() != FdoConnectionState.Closed)
{
conn.Close();
return true;
}
}
return false;
}
示例10: Create
public bool Create()
{
bool ok = true;
FdoConnection conn = new FdoConnection(_view.Provider, GetBaseConnectionString());
bool created = false;
bool cleanup = true;
try
{
using (var svc = conn.CreateFeatureService())
{
try
{
CreateDataStore(svc);
created = true;
}
catch (Exception ex)
{
_view.ShowError(ex);
created = false;
ok = false;
}
}
if (created)
{
//Amend the connection string to include the data store
var builder = new DbConnectionStringBuilder();
builder.ConnectionString = conn.ConnectionString;
builder[_view.DataStoreParameter] = _view.DataStoreName;
conn.ConnectionString = builder.ConnectionString;
conn.Open();
using (var svc = conn.CreateFeatureService())
{
CreateDefaultSpatialContext(svc);
}
}
}
finally
{
if (created)
{
if (File.Exists(_view.SchemaFile))
{
ApplySchemas(conn);
}
if (_view.ConnectOnCreate)
{
_connMgr.AddConnection(_view.ConnectionName, conn);
cleanup = false;
}
}
if (cleanup)
{
conn.Close();
conn.Dispose();
}
}
return ok;
}
示例11: Connect
public bool Connect()
{
if (string.IsNullOrEmpty(_view.ConnectionName))
{
_view.ShowMessage(null, "Name required");
return false;
}
FdoConnection conn = new FdoConnection("OSGeo.OGR", _view.BuilderObject.ToConnectionString());
try
{
if (conn.Open() == FdoConnectionState.Open)
{
IFdoConnectionManager mgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
mgr.AddConnection(_view.ConnectionName, conn);
return true;
}
}
catch (FdoException ex)
{
_view.ShowError(ex);
}
return false;
}