public SchemaDesignContext(FdoConnection conn) { _spatialContexts = new BindingList <SpatialContextInfo>(); if (conn == null) { _schemas = new FeatureSchemaCollection(null); _mappings = new PhysicalSchemaMappingCollection(); } else { using (var svc = conn.CreateFeatureService()) { _schemas = svc.DescribeSchema(); _mappings = svc.DescribeSchemaMapping(true); if (_mappings == null) { _mappings = new PhysicalSchemaMappingCollection(); } var spatialContexts = svc.GetSpatialContexts(); foreach (var sc in spatialContexts) { _spatialContexts.Add(sc); } } } this.Connection = conn; EvaluateCapabilities(); }
/// <summary> /// Initializes a new instance of the <see cref="FdoInsertScaffoldPresenter"/> class. /// </summary> /// <param name="view">The view.</param> /// <param name="conn">The conn.</param> /// <param name="className">Name of the class.</param> public FdoInsertScaffoldPresenter(IFdoInsertView view, FdoConnection conn, string className) { _view = view; _conn = conn; _className = className; _view.Title = ICSharpCode.Core.ResourceService.GetString("TITLE_INSERT_FEATURE"); }
public FdoDataPreviewPresenter(IFdoDataPreviewView view, FdoConnection conn) { _timer = new Timer(); _view = view; _connection = conn; _service = conn.CreateFeatureService(); _queryViews = new Dictionary <QueryMode, IQuerySubView>(); _queryWorker = new BackgroundWorker(); _queryWorker.WorkerReportsProgress = true; _queryWorker.WorkerSupportsCancellation = true; _queryWorker.DoWork += new DoWorkEventHandler(DoWork); //_queryWorker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); _queryWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted); _view.ElapsedMessage = string.Empty; _view.CancelEnabled = false; _view.ExecuteEnabled = true; insertSupported = (Array.IndexOf(conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList), OSGeo.FDO.Commands.CommandType.CommandType_Insert) >= 0); updateSupported = (Array.IndexOf(conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList), OSGeo.FDO.Commands.CommandType.CommandType_Update) >= 0); deleteSupported = (Array.IndexOf(conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList), OSGeo.FDO.Commands.CommandType.CommandType_Delete) >= 0); _view.DeleteEnabled = deleteSupported; _view.UpdateEnabled = updateSupported; _timer.Interval = 1000; _timer.Elapsed += new ElapsedEventHandler(OnTimerElapsed); }
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(); } }
private static void SetConnectionToolTip(TreeNode connNode, FdoConnection conn) { using (FdoFeatureService service = conn.CreateFeatureService()) { List <string> ctxStrings = new List <string>(); try { ICollection <SpatialContextInfo> contexts = service.GetSpatialContexts(); foreach (SpatialContextInfo sci in contexts) { if (sci.IsActive) { ctxStrings.Add("- " + sci.Name + " (Active)"); } else { ctxStrings.Add("- " + sci.Name); } } } catch { ctxStrings.Add("Could not retrieve spatial contexts"); } string configStatus = conn.HasConfiguration ? "(This connection has custom configuration applied)" : string.Empty; connNode.ToolTipText = string.Format( "Provider: {0}{4}Type: {1}{4}Connection String: {2}{4}Spatial Contexts:{4}{3}{4}{5}", conn.Provider, conn.DataStoreType, conn.SafeConnectionString, ctxStrings.Count > 0 ? string.Join("\n", ctxStrings.ToArray()) : "none", Environment.NewLine, configStatus); } }
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); }
public void CopySpatialContexts() { List <SpatialContextInfo> contexts = new List <SpatialContextInfo>(); FdoConnection srcConn = _connMgr.GetConnection(_view.SourceConnectionName); FdoConnection targetConn = _connMgr.GetConnection(_view.SelectedTargetConnectionName); using (FdoFeatureService service = srcConn.CreateFeatureService()) { foreach (string ctxName in _view.SpatialContexts) { SpatialContextInfo sc = service.GetSpatialContext(ctxName); if (sc != null) { contexts.Add(sc); } } } if (contexts.Count == 0) { _view.ShowMessage(null, ResourceService.GetString("MSG_NO_SPATIAL_CONTEXTS_COPIED")); return; } ExpressUtility.CopyAllSpatialContexts(contexts, targetConn, _view.Overwrite); _view.ShowMessage(null, ResourceService.GetString("MSG_SPATIAL_CONTEXTS_COPIED")); _view.Close(); }
/// <summary> /// Gets all class names from the specified flat-file data source /// </summary> /// <param name="sourceFile"></param> /// <returns></returns> public static string[] GetClassNames(string sourceFile) { List <string> classnames = new List <string>(); FdoConnection source = null; try { source = CreateFlatFileConnection(sourceFile); source.Open(); using (FdoFeatureService svc = source.CreateFeatureService()) { using (FeatureSchemaCollection schemas = svc.DescribeSchema()) { foreach (FeatureSchema sch in schemas) { foreach (ClassDefinition cd in sch.Classes) { classnames.Add(cd.Name); } } } } } catch (Exception ex) { } finally { if (source != null) { source.Dispose(); } } return(classnames.ToArray()); }
public bool CreateSqlite() { if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName)) { _view.ShowError("Specify a connection name"); return(false); } if (ExpressUtility.CreateFlatFileDataSource("OSGeo.SQLite", _view.SQLiteFile)) { FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SQLite", _view.SQLiteFile); if (FileService.FileExists(_view.FeatureSchemaDefinition)) { conn.Open(); using (FdoFeatureService service = conn.CreateFeatureService()) { service.LoadSchemasFromXml(_view.FeatureSchemaDefinition, _view.FixIncompatibilities); } } if (_view.CreateConnection) { _connMgr.AddConnection(_view.ConnectionName, conn); } else { conn.Dispose(); } } return(true); }
public override int Execute() { CommandStatus retCode = CommandStatus.E_OK; bool create = ExpressUtility.CreateFlatFileDataSource(_file); if (!create) { WriteLine("Failed to create file {0}", _file); retCode = CommandStatus.E_FAIL_CREATE_DATASTORE; return((int)retCode); } WriteLine("File {0} created", _file); if (_schema != null) { try { FdoConnection conn = ExpressUtility.CreateFlatFileConnection(_file); conn.Open(); using (FdoFeatureService service = conn.CreateFeatureService()) { service.LoadSchemasFromXml(_schema); WriteLine("Schema applied to {0}", _file); } retCode = CommandStatus.E_OK; } catch (Exception ex) { WriteException(ex); retCode = CommandStatus.E_FAIL_APPLY_SCHEMA; } } return((int)retCode); }
public FdoAggregateQueryCtl(FdoConnection conn) : this() { _conn = conn; _presenter = new FdoAggregateQueryPresenter(this, conn); joinCriteriaCtrl.Connection = conn; }
/// <summary> /// Loads a saved connection, the name of the connection will be the name of the /// file (without the file extension) /// </summary> /// <param name="path"></param> public static void LoadConnection(string path) { FdoConnection conn = FdoConnection.LoadFromFile(path); string name = Path.GetFileNameWithoutExtension(path); ConnectionManager.AddConnection(name, conn); }
/// <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)); }
/// <summary> /// Removes all connections /// </summary> public void Clear() { List <string> names = new List <string>(GetConnectionNames()); foreach (string name in names) { //Yes we're inlining RemoveConnection(), but we want any cancel action to cancel //the Clear() method if (_ConnectionDict.ContainsKey(name)) { ConnectionBeforeRemoveEventArgs e = new ConnectionBeforeRemoveEventArgs(name); this.BeforeConnectionRemove(this, e); if (e.Cancel) { return; } FdoConnection conn = _ConnectionDict[name]; conn.Close(); _ConnectionDict.Remove(name); conn.Dispose(); if (this.ConnectionRemoved != null) { this.ConnectionRemoved(this, new EventArgs <string>(name)); } } } }
internal void ConnectionChanged(JoinSourceType type) { if (type != JoinSourceType.Target) { _view.ClearJoins(); } FdoConnection conn = GetConnection(type); if (conn != null) { using (FdoFeatureService service = conn.CreateFeatureService()) { switch (type) { case JoinSourceType.Left: _view.LeftSchemas = service.GetSchemaNames(); SchemaChanged(type); break; case JoinSourceType.Right: _view.RightSchemas = service.GetSchemaNames(); SchemaChanged(type); break; case JoinSourceType.Target: _view.TargetSchemas = service.GetSchemaNames(); SchemaChanged(type); break; } } } }
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); }
/// <summary> /// Refreshes the connection. /// </summary> /// <param name="name">The name of the connection.</param> public void RefreshConnection(string name) { if (NameExists(name)) { FdoConnection conn = this.GetConnection(name); conn.Close(); //HACK: FDO #660 workaround if (conn.Provider.ToUpper().StartsWith("OSGEO.POSTGRESQL")) { conn.ConnectionString = conn.ConnectionString; } conn.Open(); /* * //TODO: I got a bad feeling that this may break something * //which may rely on the old connection. Verify this. * FdoConnection oldConn = this.GetConnection(name); * string provider = oldConn.Provider; * string connStr = oldConn.ConnectionString; * oldConn.Close(); * oldConn.Dispose(); * * FdoConnection newConn = new FdoConnection(provider, connStr); * newConn.Open(); * _ConnectionDict[name] = newConn; */ ConnectionRefreshed(this, new EventArgs <string>(name)); } }
/// <summary> /// Validates this instance. /// </summary> public void Validate() { foreach (FdoClassCopyOptions copt in this.ClassCopyOptions) { FdoConnection src = GetConnection(copt.SourceConnectionName); FdoConnection dst = GetConnection(copt.TargetConnectionName); if (src == null) { throw new TaskValidationException("The specified source connection name does not exist"); } if (dst == null) { throw new TaskValidationException("The specified target connection name does not exist"); } using (FdoFeatureService srcSvc = src.CreateFeatureService()) using (FdoFeatureService dstSvc = dst.CreateFeatureService()) { ClassDefinition srcCls = srcSvc.GetClassByName(copt.SourceSchema, copt.SourceClassName); ClassDefinition dstCls = dstSvc.GetClassByName(copt.TargetSchema, copt.TargetClassName); if (srcCls == null) { throw new TaskValidationException("The specified source feature class does not exist"); } if (dstCls == null) { throw new TaskValidationException("The specified target feature class does not exist"); } } } }
/// <summary> /// Initializes a new instance of the <see cref="FdoCopySpatialContextOperation"/> class. /// </summary> /// <param name="src">The source connection.</param> /// <param name="dst">The target connection.</param> /// <param name="sourceSpatialContextNames">The source spatial context names.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite].</param> public FdoCopySpatialContextOperation(FdoConnection src, FdoConnection dst, string[] sourceSpatialContextNames, bool overwrite) { _source = src; _target = dst; _scNames = sourceSpatialContextNames; _overwrite = overwrite; }
public override void Run() { string file = FileService.OpenFile(Res.GetString("TITLE_CONNECT_SQLITE"), Res.GetString("FILTER_SQLITE")); if (FileService.FileExists(file)) { FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SQLite", file); FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); NamingService namer = ServiceManager.Instance.GetService <NamingService>(); string name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), namer.GetDefaultConnectionName("OSGeo.SQLite")); if (name == null) { return; } while (name == string.Empty || mgr.NameExists(name)) { Msg.ShowError(Res.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS")); name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), name); if (name == null) { return; } } mgr.AddConnection(name, conn); } }
public void Init() { var conn = new FdoConnection(_view.Provider); _view.AvailableExtentTypes = conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_SpatialContextTypes); _view.WKTEnabled = this.RequiresWKT = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsCSysWKTFromCSysName); }
public static SpatialContextInfo Edit(FdoConnection conn, SpatialContextInfo ctx) { FdoSpatialContextDialog diag = new FdoSpatialContextDialog(conn, ctx); if (diag.ShowDialog() == DialogResult.OK) { SpatialContextInfo sci = new SpatialContextInfo(); sci.Name = diag.ContextName; sci.Description = diag.Description; sci.CoordinateSystem = diag.CoordinateSystem; sci.CoordinateSystemWkt = diag.CoordinateSystemWkt; sci.XYTolerance = Convert.ToDouble(diag.XYTolerance); sci.ZTolerance = Convert.ToDouble(diag.ZTolerance); sci.ExtentType = diag.SelectedExtentType; //Only consider extent if all 4 values are defined if (diag.IsExtentDefined) { string wktfmt = "POLYGON (({0} {1}, {2} {3}, {4} {5}, {6} {7}, {0} {1}))"; double llx = Convert.ToDouble(diag.LowerLeftX); double lly = Convert.ToDouble(diag.LowerLeftY); double urx = Convert.ToDouble(diag.UpperRightX); double ury = Convert.ToDouble(diag.UpperRightY); sci.ExtentGeometryText = string.Format(wktfmt, llx, lly, urx, lly, urx, ury, llx, ury, llx, lly); } return(sci); } return(null); }
public FdoBulkUpdatePresenter(IFdoBulkUpdateView view, FdoConnection conn, string className) { _view = view; _conn = conn; _className = className; _view.Title = ICSharpCode.Core.ResourceService.GetString("TITLE_BULK_UPDATE_FEATURE"); }
public override void Run() { string dir = FileService.GetDirectory(Res.GetString("TITLE_CONNECT_SHP_DIR")); if (FileService.DirectoryExists(dir)) { FdoConnection conn = new FdoConnection("OSGeo.SHP", "DefaultFileLocation=" + dir); FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); NamingService namer = ServiceManager.Instance.GetService <NamingService>(); string name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), namer.GetDefaultConnectionName("OSGeo.SHP")); if (name == null) { return; } while (string.IsNullOrEmpty(name) || mgr.NameExists(name)) { Msg.ShowError(Res.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS")); name = Msg.ShowInputBox(Res.GetString("TITLE_CONNECTION_NAME"), Res.GetString("PROMPT_ENTER_CONNECTION"), name); if (name == null) { return; } } mgr.AddConnection(name, conn); } }
public override void Run() { string path = FileService.SaveFile(Res.GetString("TITLE_EXPORT_DATASTORE_XML"), Res.GetString("FILTER_XML_FILES")); if (!string.IsNullOrEmpty(path)) { TreeNode connNode = Workbench.Instance.ObjectExplorer.GetSelectedNode(); FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); FdoConnection conn = mgr.GetConnection(connNode.Name); using (new TempCursor(Cursors.WaitCursor)) { using (var svc = conn.CreateFeatureService()) { var scs = new List <SpatialContextInfo>(svc.GetSpatialContexts()).ToArray(); var schemas = svc.DescribeSchema(); var mappings = svc.DescribeSchemaMapping(true); var dstore = new FdoDataStoreConfiguration(schemas, scs, mappings); dstore.Save(path); Log.InfoFormatted("Connection saved to: {0}", path); } } } }
public override void Run() { Workbench wb = Workbench.Instance; if (wb != null) { TreeNode node = wb.ObjectExplorer.GetSelectedNode(); TreeNode connNode = wb.ObjectExplorer.GetSelectedNode(); while (connNode.Level > 1) { connNode = connNode.Parent; } FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); FdoConnection conn = mgr.GetConnection(connNode.Name); FdoDataPreviewCtl ctl = null; if (node.Level > 1) //Class node { ctl = new FdoDataPreviewCtl(conn, node.Parent.Name, node.Name); } else { ctl = new FdoDataPreviewCtl(conn); } wb.ShowContent(ctl, ViewRegion.Document); } }
public override void Run() { string path = FileService.OpenFile(Res.GetString("TITLE_LOAD_CONNECTION"), Res.GetString("FILTER_CONNECTION_FILE")); if (FileService.FileExists(path)) { FdoConnection conn = FdoConnection.LoadFromFile(path); FdoConnectionManager mgr = ServiceManager.Instance.GetService <FdoConnectionManager>(); string name = string.Empty; name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name); if (name == null) { return; } while (name == string.Empty || mgr.NameExists(name)) { name = Msg.ShowInputBox(Res.GetString("TITLE_NEW_CONNECTION"), Res.GetString("PROMPT_ENTER_NEW_CONNECTION_NAME"), name); if (name == null) { return; } } using (TempCursor cur = new TempCursor(Cursors.WaitCursor)) { mgr.AddConnection(name, conn); } } }
internal void SchemaChanged(JoinSourceType type) { if (type == JoinSourceType.Target) { return; } _view.ClearJoins(); FdoConnection conn = GetConnection(type); if (conn != null) { using (FdoFeatureService service = conn.CreateFeatureService()) { switch (type) { case JoinSourceType.Left: _view.LeftClasses = service.GetClassNames(_view.SelectedLeftSchema); ClassChanged(type); break; case JoinSourceType.Right: _view.RightClasses = service.GetClassNames(_view.SelectedRightSchema); ClassChanged(type); break; } } } }
public FdoStandardQueryPresenter(IFdoStandardQueryView view, FdoConnection conn) { _view = view; _conn = conn; _service = _conn.CreateFeatureService(); _view.OrderingEnabled = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsSelectOrdering); _walker = SchemaWalker.GetWalker(conn); }
public ConnectArcSdePresenter(IConnectArcSdeView view, IFdoConnectionManager connMgr) { _view = view; _connMgr = connMgr; _conn = new FdoConnection("OSGeo.ArcSDE"); _view.DataStoreEnabled = false; _view.SubmitEnabled = false; }