FDO Connection wrapper class
Inheritance: IDisposable
 public FdoAggregateQueryCtl(FdoConnection conn)
     : this()
 {
     _conn = conn;
     _presenter = new FdoAggregateQueryPresenter(this, conn);
     joinCriteriaCtrl.Connection = conn;
 }
Ejemplo n.º 2
0
        /// <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));
        }
 public FdoBulkUpdatePresenter(IFdoBulkUpdateView view, FdoConnection conn, string className)
 {
     _view = view;
     _conn = conn;
     _className = className;
     _view.Title = ICSharpCode.Core.ResourceService.GetString("TITLE_BULK_UPDATE_FEATURE");
 }
        /// <summary>
        /// Copies the spatial contexts given in the list
        /// </summary>
        /// <param name="source">The source connection</param>
        /// <param name="target">The target connection</param>
        /// <param name="overwrite">If true will overwrite any existing spatial contexts</param>
        /// <param name="spatialContextNames">The list of spatial contexts to copy</param>
        public override void Execute(FdoConnection source, FdoConnection target, bool overwrite, string[] spatialContextNames)
        {
            if (spatialContextNames.Length == 0)
                return;

            FdoFeatureService srcService = source.CreateFeatureService();
            FdoFeatureService destService = target.CreateFeatureService();
            ReadOnlyCollection<SpatialContextInfo> srcContexts = srcService.GetSpatialContexts();
            ReadOnlyCollection<SpatialContextInfo> destContexts = destService.GetSpatialContexts();
            foreach (SpatialContextInfo ctx in srcContexts)
            {
                if (SpatialContextInSpecifiedList(ctx, spatialContextNames))
                {
                    try
                    {
                        //Find target spatial context of the same name
                        SpatialContextInfo sci = destService.GetSpatialContext(ctx.Name);
                        if (sci != null && overwrite)
                        {
                            //If found, destroy then create
                            destService.DestroySpatialContext(ctx.Name);
                            destService.CreateSpatialContext(ctx, false);
                        }
                        else
                        {
                            destService.CreateSpatialContext(ctx, false);
                        }
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
 /// <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;
 }
        /// <summary>
        /// Copies all spatial contexts
        /// </summary>
        /// <param name="spatialContexts">The spatial contexts.</param>
        /// <param name="target">The target.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        public override void Execute(ICollection<SpatialContextInfo> spatialContexts, FdoConnection target, bool overwrite)
        {
            //MySQL supports multiple spatial contexts and IDestorySpatialContext
            //so in this case if overwrite == true, we want to destroy any ones that
            //already exist in the target before creating new ones in its place. This does not
            //prevent creating a series of spatial contexts if overwrite == false and one of
            //the spatial contexts being copied already exists. This is an unfortunate leaky 
            //abstraction in the FDO API.

            using (FdoFeatureService service = target.CreateFeatureService())
            {
                if (overwrite)
                {
                    ReadOnlyCollection<SpatialContextInfo> targetContexts = service.GetSpatialContexts();

                    foreach (SpatialContextInfo sc in spatialContexts)
                    {
                        //Only destroy spatial context if it exists in target connection
                        if (SpatialContextExists(targetContexts, sc))
                            service.DestroySpatialContext(sc);
                    }
                }

                foreach (SpatialContextInfo sc in spatialContexts)
                {
                    service.CreateSpatialContext(sc, false);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="connStr">The connection string.</param>
        /// <param name="configPath">The configuration path</param>
        /// <param name="name">The name that will be assigned to the connection.</param>
        /// <returns></returns>
        protected override FdoConnection CreateConnection(string provider, string connStr, string configPath, ref string name)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
            //Try to find by name first
            FdoConnection conn = null;
            conn = connMgr.GetConnection(name);
            //Named connection matches all the details
            if (conn != null)
            {
                if (conn.Provider == provider && conn.ConnectionString == connStr)
                    return conn;
            }

            //Then to find matching open connection
            foreach (string connName in connMgr.GetConnectionNames())
            {
                FdoConnection c = connMgr.GetConnection(connName);
                if (c.Provider == provider && c.ConnectionString == connStr)
                {
                    name = connName;
                    return c;
                }
            }

            //Make a new connection
            LoggingService.Info(ResourceService.GetString("INFO_REFERENCED_CONNECTION_NOT_FOUND"));
            conn = new FdoConnection(provider, connStr);
            if (!string.IsNullOrEmpty(configPath) && System.IO.File.Exists(configPath))
                conn.SetConfiguration(configPath);
            connMgr.AddConnection(name, conn);
            return conn;
        }
Ejemplo n.º 8
0
        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();
        }
        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();
            }
        }
Ejemplo n.º 10
0
 public DumpFeatureClassCtl(FdoConnection source, string schemaName, string className)
 {
     InitializeComponent();
     this.Title = "Dump Feature Class";
     _source = source;
     _schemaName = schemaName;
     _className = className;
 }
Ejemplo n.º 11
0
 public FdoSqlOutputOperation(FdoConnection conn, string className, NameValueCollection propertyMappings)
     : base(conn, className, propertyMappings)
 {
     if (!conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsSQL))
     {
         throw new ArgumentException("Only providers that support SQL can be used");
     }
 }
 public FdoAggregateQueryPresenter(IFdoAggregateQueryView view, FdoConnection conn)
 {
     _view = view;
     _conn = conn;
     _service = _conn.CreateFeatureService();
     _view.OrderingEnabled = false;
     _walker = SchemaWalker.GetWalker(conn);
 }
 public FdoSpatialContextBrowserDlg(FdoConnection conn)
     : this()
 {
     using (FdoFeatureService service = conn.CreateFeatureService())
     {
         grdSpatialContexts.DataSource = service.GetSpatialContexts();
     }
 }
Ejemplo n.º 14
0
        public void TestCopyTaskMsSql()
        {
            MockRepository mocks = new MockRepository();
            FdoConnection conn = new FdoConnection("OSGeo.SQLServerSpatial", "");

            ICopySpatialContext ctx = CopySpatialContextOverrideFactory.GetCopySpatialContextOverride(conn);
            Assert.IsTrue(ctx is MsSqlCopySpatialContextOverride);
        }
Ejemplo n.º 15
0
 public FdoJoinDialog(FdoConnection conn, string primarySchemaName, string primaryClassName, string primaryClassAlias)
 {
     InitializeComponent();
     _conn = conn;
     _primarySchemaName = primarySchemaName;
     _primaryClassName = primaryClassName;
     _primaryClassAlias = primaryClassAlias;
 }
 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);
 }
Ejemplo n.º 17
0
 public ConnectArcSdePresenter(IConnectArcSdeView view, IFdoConnectionManager connMgr)
 {
     _view = view;
     _connMgr = connMgr;
     _conn = new FdoConnection("OSGeo.ArcSDE");
     _view.DataStoreEnabled = false;
     _view.SubmitEnabled = false; 
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Parses the type of the expression.
        /// </summary>
        /// <param name="exprStr">The expr STR.</param>
        /// <param name="conn">The conn.</param>
        /// <returns></returns>
        public static FdoPropertyType? ParseExpressionType(string exprStr, FdoConnection conn)
        {
            Expression expr = null;
            try
            {
                expr = Expression.Parse(exprStr);
            }
            catch (OSGeo.FDO.Common.Exception)
            {
                return null;
            }

            if (expr.GetType() == typeof(Function))
            {
                Function func = expr as Function;
                FunctionDefinitionCollection funcDefs = (FunctionDefinitionCollection)conn.Capability.GetObjectCapability(CapabilityType.FdoCapabilityType_ExpressionFunctions);
                FunctionDefinition funcDef = null;

                //Try to get the return type
                foreach (FunctionDefinition fd in funcDefs)
                {
                    if (fd.Name == func.Name)
                    {
                        funcDef = fd;
                        break;
                    }
                }

                if (funcDef == null)
                    return null;

                switch (funcDef.ReturnPropertyType)
                {
                    case PropertyType.PropertyType_AssociationProperty:
                        return FdoPropertyType.Association;
                    case PropertyType.PropertyType_GeometricProperty:
                        return FdoPropertyType.Geometry;
                    case PropertyType.PropertyType_ObjectProperty:
                        return FdoPropertyType.Object;
                    case PropertyType.PropertyType_RasterProperty:
                        return FdoPropertyType.Raster;
                    case PropertyType.PropertyType_DataProperty:
                        {
                            return ValueConverter.GetPropertyType(funcDef.ReturnType);
                        }
                }
            }
            else if (expr.GetType() == typeof(BinaryExpression))
            {
                return FdoPropertyType.Boolean;
            }
            else if (expr.GetType() == typeof(DataValue))
            {
                DataValue dv = (DataValue)expr;
                return ValueConverter.GetPropertyType(dv.DataType);
            }
            return null;
        }
 public FdoBulkDeleteCtlPresenter(IFdoBulkDeleteView view, FdoConnection conn, string className)
 {
     _view = view;
     _conn = conn;
     _className = className;
     _view.ClassName = className;
     _view.Title = ICSharpCode.Core.ResourceService.GetString("TITLE_BULK_DELETE");
     _view.TransactionEnabled = (_conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsTransactions));
 }
 /// <summary>
 /// Gets the registered override object
 /// </summary>
 /// <param name="targetConn"></param>
 /// <returns></returns>
 public static ICopySpatialContext GetCopySpatialContextOverride(FdoConnection targetConn)
 {
     string providerName = targetConn.Provider;
     if (_CopySpatialContextOverrides.ContainsKey(providerName))
     {
         return (ICopySpatialContext)Activator.CreateInstance(_CopySpatialContextOverrides[providerName]);
     }
     return new CopySpatialContext();
 }
Ejemplo n.º 21
0
        public bool DependsOnConnection(FdoToolbox.Core.Feature.FdoConnection conn)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
            FdoConnection         left    = connMgr.GetConnection(this.SelectedLeftConnection);
            FdoConnection         right   = connMgr.GetConnection(this.SelectedRightConnection);
            FdoConnection         target  = connMgr.GetConnection(this.SelectedTargetConnection);

            return(conn == left || conn == right || conn == target);
        }
 public static SpatialContextInfo GetSpatialContext(FdoConnection conn)
 {
     FdoSpatialContextBrowserDlg diag = new FdoSpatialContextBrowserDlg(conn);
     if (diag.ShowDialog() == DialogResult.OK)
     {
         return diag.SelectedSpatialContext;
     }
     return null;
 }
Ejemplo n.º 23
0
 public static SchemaWalker GetWalker(FdoConnection conn)
 {
     using (var svc = conn.CreateFeatureService())
     {
         if (svc.SupportsPartialSchemaDiscovery())
             return new PartialSchemaWalker(conn);
         else
             return new FullSchemaWalker(conn);
     }
 }
 public FdoUpdateScaffoldPresenter(IFdoUpdateView view, FdoFeature feat, FdoConnection conn, string filter)
 {
     _view = view;
     _conn = conn;
     _className = feat.Table.TableName;
     _view.Title = ICSharpCode.Core.ResourceService.GetString("TITLE_UPDATE_FEATURE");
     _view.UpdateFilter = filter;
     _filter = filter;
     _feature = feat;
 }
Ejemplo n.º 25
0
 public static OSGeo.FDO.Schema.PropertyValueConstraint GetConstraint(PropertyValueConstraint constraint, FdoConnection conn)
 {
     ValueConstraintDialog dlg = new ValueConstraintDialog(conn);
     dlg.Constraint = constraint;
     if (dlg.ShowDialog() == DialogResult.OK)
     {
         return dlg.Constraint;
     }
     return null;
 }
Ejemplo n.º 26
0
        internal Capability(FdoConnection conn)
        {
            IConnection internalConn = conn.InternalConnection;

            commandCaps = internalConn.CommandCapabilities;
            connCaps    = internalConn.ConnectionCapabilities;
            exprCaps    = internalConn.ExpressionCapabilities;
            filterCaps  = internalConn.FilterCapabilities;
            geomCaps    = internalConn.GeometryCapabilities;
            rasterCaps  = internalConn.RasterCapabilities;
            schemaCaps  = internalConn.SchemaCapabilities;
            topoCaps    = internalConn.TopologyCapabilities;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Copies all spatial contexts
        /// </summary>
        /// <param name="spatialContexts">The spatial contexts.</param>
        /// <param name="target">The target.</param>
        /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
        public virtual void Execute(ICollection<SpatialContextInfo> spatialContexts, FdoConnection target, bool overwrite)
        {
            bool supportsMultipleScs = target.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsMultipleSpatialContexts);
            bool supportsDestroySc = target.Capability.HasArrayCapability(CapabilityType.FdoCapabilityType_CommandList, (int)OSGeo.FDO.Commands.CommandType.CommandType_DestroySpatialContext);

            using (FdoFeatureService service = target.CreateFeatureService())
            {
                if (supportsMultipleScs)
                {
                    if (overwrite && supportsDestroySc)
                    {
                        ReadOnlyCollection<SpatialContextInfo> targetContexts = service.GetSpatialContexts();

                        foreach (SpatialContextInfo sc in spatialContexts)
                        {
                            //Only destroy spatial context if it exists in target connection
                            if(SpatialContextExists(targetContexts, sc))
                                service.DestroySpatialContext(sc);
                        }
                    }
                    foreach (SpatialContextInfo sc in spatialContexts)
                    {
                        service.CreateSpatialContext(sc, overwrite);
                    }
                }
                else
                {
                    List<SpatialContextInfo> contexts = new List<SpatialContextInfo>(spatialContexts);
                    //Copy either the active spatial context in the list or the first
                    //spatial context (if no active one is found)
                    SpatialContextInfo active = null;
                    if (contexts.Count > 0)
                    {
                        foreach (SpatialContextInfo sc in contexts)
                        {
                            if (sc.IsActive)
                            {
                                active = sc;
                                break;
                            }
                        }
                        if (active == null)
                            active = contexts[0];
                    }
                    if(active != null)
                        service.CreateSpatialContext(active, overwrite);
                }
            }
        }
        public ValueConstraintDialog(FdoConnection conn)
        {
            InitializeComponent();
            bool supportsList = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsValueConstraintsList);
            bool supportsRange = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsExclusiveValueRangeConstraints);

            if (supportsList)
                cmbConstraintType.Items.Add(PropertyValueConstraintType.PropertyValueConstraintType_List);
            if (supportsRange)
                cmbConstraintType.Items.Add(PropertyValueConstraintType.PropertyValueConstraintType_Range);

            if (cmbConstraintType.Items.Count > 0)
                cmbConstraintType.SelectedIndex = 0;
            //cmbConstraintType_SelectedIndexChanged(null, null);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Adds a FDO connection.
        /// </summary>
        /// <param name="name">The name of the connection.</param>
        /// <param name="conn">The connection.</param>
        public void AddConnection(string name, FdoToolbox.Core.Feature.FdoConnection conn)
        {
            if (_ConnectionDict.ContainsKey(name))
            {
                throw new FdoConnectionException("Unable to add connection named " + name + " to the connection manager");
            }

            if (conn.State != FdoConnectionState.Open)
            {
                conn.Open();
            }

            _ConnectionDict.Add(name, conn);
            this.ConnectionAdded(this, new EventArgs <string>(name));
        }
 /// <summary>
 /// Copies all spatial contexts
 /// </summary>
 /// <param name="spatialContexts">The spatial contexts.</param>
 /// <param name="target">The target.</param>
 /// <param name="overwrite">if set to <c>true</c> [overwrite].</param>
 public override void Execute(ICollection<SpatialContextInfo> spatialContexts, FdoConnection target, bool overwrite)
 {
     List<SpatialContextInfo> contexts = new List<SpatialContextInfo>(spatialContexts);
     foreach (SpatialContextInfo sc in contexts)
     {
         //Make sure that CSName != Spatial Context Name
         WKTParser parser = new WKTParser(sc.CoordinateSystemWkt);
         if (!string.IsNullOrEmpty(parser.CSName))
         {
             sc.CoordinateSystem = parser.CSName;
             sc.Name = parser.CSName;
         }
     }
     base.Execute(contexts, target, overwrite);
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Copies all spatial contexts
        /// </summary>
        /// <param name="source">The source connection</param>
        /// <param name="target">The target connection</param>
        /// <param name="overwrite">If true will overwrite any existing spatial contexts</param>
        public virtual void Execute(FdoConnection source, FdoConnection target, bool overwrite)
        {
            List<string> names = new List<string>();
            using (FdoFeatureService service = source.CreateFeatureService())
            {   
                ReadOnlyCollection<SpatialContextInfo> contexts = service.GetSpatialContexts();
                if (contexts.Count == 0)
                    return;

                foreach (SpatialContextInfo ctx in contexts)
                {
                    names.Add(ctx.Name);
                }
            }
            Execute(source, target, overwrite, names.ToArray());
        }
        /// <summary>
        /// Copies the spatial contexts given in the list
        /// </summary>
        /// <param name="source">The source connection</param>
        /// <param name="target">The target connection</param>
        /// <param name="overwrite">If true will overwrite any existing spatial contexts</param>
        /// <param name="spatialContextNames">The list of spatial contexts to copy</param>
        public override void Execute(FdoConnection source, FdoConnection target, bool overwrite, string [] spatialContextNames)
        {
            if (spatialContextNames.Length == 0)
                return;

            string srcName = spatialContextNames[0];
            FdoFeatureService srcService = source.CreateFeatureService();
            FdoFeatureService destService = target.CreateFeatureService();
            SpatialContextInfo context = srcService.GetSpatialContext(srcName);
            if (context != null)
            {
                //Make sure that CSName != Spatial Context Name
                WKTParser parser = new WKTParser(context.CoordinateSystemWkt);
                if (!string.IsNullOrEmpty(parser.CSName))
                {
                    context.CoordinateSystem = parser.CSName;
                    context.Name = parser.CSName;
                    destService.CreateSpatialContext(context, overwrite);
                }
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Handles the file drop
        /// </summary>
        /// <param name="file">The file being dropped</param>
        public void HandleDrop(string file)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
            NamingService namer = ServiceManager.Instance.GetService<NamingService>();
            FdoConnection conn = null;
            try
            {
#if X64
                conn = new FdoConnection("OSGeo.ODBC", "ConnectionString=\"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq="+file+"\"");
#else
                conn = new FdoConnection("OSGeo.ODBC", "ConnectionString=\"Driver={Microsoft Access Driver (*.mdb)};Dbq="+file+"\"");
#endif
            }
            catch (Exception ex)
            {
                LoggingService.Error("Failed to load connection", ex);
                return;
            }

            string name = namer.GetDefaultConnectionName(conn.Provider, System.IO.Path.GetFileNameWithoutExtension(file));
            connMgr.AddConnection(name, conn);
        }