public void Init()
        {
            _view.InitializeGrid();
            _view.UseTransactionEnabled = (_conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsTransactions));

            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                ClassDefinition cd = service.GetClassByName(_className);
                if (cd != null)
                {
                    _view.ClassName = cd.Name;
                    foreach (PropertyDefinition pd in cd.Properties)
                    {
                        switch (pd.PropertyType)
                        {
                        case PropertyType.PropertyType_DataProperty:
                            _view.AddDataProperty((DataPropertyDefinition)pd);
                            break;

                        case PropertyType.PropertyType_GeometricProperty:
                            _view.AddGeometricProperty((GeometricPropertyDefinition)pd);
                            break;
                        }
                    }
                }
            }
        }
 private void GetDataStores()
 {
     using (FdoFeatureService service = _conn.CreateFeatureService())
     {
         ReadOnlyCollection <DataStoreInfo> dstores = service.ListDataStores(true);
         _view.DataStores     = dstores;
         _view.DestroyEnabled = (dstores.Count > 0) && canDestroy;
     }
 }
 public void ComputeExtents(IEnumerable <ClassDefinition> classes)
 {
     using (FdoFeatureService service = _conn.CreateFeatureService())
     {
         IEnvelope env = service.ComputeEnvelope(classes);
         if (env != null)
         {
             _view.LowerLeftX  = env.MinX.ToString();
             _view.LowerLeftY  = env.MinY.ToString();
             _view.UpperRightX = env.MaxX.ToString();
             _view.UpperRightY = env.MaxY.ToString();
         }
     }
 }
Example #4
0
        protected override void OnLoad(EventArgs e)
        {
            cmbJoinType.DataSource = _conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_JoinTypes);
            using (var svc = _conn.CreateFeatureService())
            {
                cmbSchema.DataSource    = svc.DescribeSchema();
                cmbSchema.SelectedIndex = 0;
            }

            if (this.Criteria != null)
            {
                foreach (FeatureSchema fs in (FeatureSchemaCollection)cmbSchema.DataSource)
                {
                    if (fs.Name == this.Criteria.JoinSchema)
                    {
                        cmbSchema.SelectedIndex = cmbSchema.Items.IndexOf(fs);
                        foreach (ClassDefinition cls in fs.Classes)
                        {
                            if (cls.Name == this.Criteria.JoinClass)
                            {
                                cmbClass.SelectedIndex = cmbClass.Items.IndexOf(cls);

                                txtJoinClassAlias.Text = this.Criteria.JoinClassAlias;
                                txtJoinFilter.Text     = this.Criteria.JoinFilter;
                                txtPrefix.Text         = this.Criteria.JoinPrefix;

                                cmbJoinType.SelectedItem = this.Criteria.JoinType;
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        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;
                    }
                }
            }
        }
Example #6
0
        /// <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());
        }
        /// <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);
                }
            }
        }
Example #8
0
 public override void ExecuteAction()
 {
     using (FdoFeatureService svc = _conn.CreateFeatureService())
     {
         using (IDelete del = svc.CreateCommand <IDelete>(OSGeo.FDO.Commands.CommandType.CommandType_Delete))
         {
             try
             {
                 del.SetFeatureClassName(_className);
                 if (!string.IsNullOrEmpty(_filter))
                 {
                     del.SetFilter(_filter);
                     Info("Deleting everything from class " + _className + " with filter: " + _filter);
                 }
                 else
                 {
                     Info("Deleting everything from class: " + _className);
                 }
                 int result = del.Execute();
                 Info(result + " features deleted from class: " + _className);
             }
             catch (OSGeo.FDO.Common.Exception ex)
             {
                 Error(ex, "Error occured executing delete");
             }
         }
     }
 }
Example #9
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 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();
        }
Example #11
0
        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;
                    }
                }
            }
        }
Example #12
0
        /// <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");
                        }
                    }
            }
        }
        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 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();
        }
Example #15
0
        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);
        }
Example #16
0
        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 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);
        }
 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 FdoSpatialContextBrowserDlg(FdoConnection conn)
     : this()
 {
     using (FdoFeatureService service = conn.CreateFeatureService())
     {
         grdSpatialContexts.DataSource = service.GetSpatialContexts();
     }
 }
 public FdoAggregateQueryPresenter(IFdoAggregateQueryView view, FdoConnection conn)
 {
     _view    = view;
     _conn    = conn;
     _service = _conn.CreateFeatureService();
     _view.OrderingEnabled = false;
     _walker = SchemaWalker.GetWalker(conn);
 }
 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);
 }
Example #22
0
        internal void ClassChanged(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:
                    {
                        string schema    = _view.SelectedLeftSchema;
                        string className = _view.SelectedLeftClass;

                        ClassDefinition cd = service.GetClassByName(schema, className);
                        if (cd != null)
                        {
                            List <string> properties = new List <string>();
                            foreach (PropertyDefinition pd in cd.Properties)
                            {
                                properties.Add(pd.Name);
                            }
                            _view.LeftProperties = properties;
                        }
                    }
                    break;

                    case JoinSourceType.Right:
                    {
                        string schema    = _view.SelectedRightSchema;
                        string className = _view.SelectedRightClass;

                        ClassDefinition cd = service.GetClassByName(schema, className);
                        if (cd != null)
                        {
                            List <string> properties = new List <string>();
                            foreach (PropertyDefinition pd in cd.Properties)
                            {
                                properties.Add(pd.Name);
                            }
                            _view.RightProperties = properties;
                        }
                    }
                    break;
                    }
                }
            }

            SetTargetGeometries();
        }
        internal void Delete()
        {
            if (_view.Confirm("Bulk Delete", "Bulk deletes can be very lengthy. Are you sure you want to do this?"))
            {
                using (FdoFeatureService service = _conn.CreateFeatureService())
                {
                    int deleted = service.DeleteFeatures(_className, _view.Filter.Trim(), _view.UseTransaction);
                    _view.ShowMessage(null, deleted + " feature(s) deleted");
                }

                if (_conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsFlush))
                {
                    _conn.Flush();
                }

                _view.Close();
            }
        }
Example #24
0
        /// <summary>
        /// Executes the operation
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows)
        {
            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                using (FdoFeatureReader reader = service.SelectFeatures(this.Query))
                {
                    ClassDefinition cd = reader.GetClassDefinition();
                    foreach (PropertyDefinition pd in cd.Properties)
                    {
                        if (pd.PropertyType == PropertyType.PropertyType_RasterProperty)
                        {
                            ignoreProperties.Add(pd.Name);
                        }
                        else if (pd.PropertyType == PropertyType.PropertyType_DataProperty)
                        {
                            DataPropertyDefinition dp = pd as DataPropertyDefinition;
                            if (dp.IsAutoGenerated || dp.ReadOnly)
                            {
                                ignoreProperties.Add(pd.Name);
                            }
                        }
                        else if (pd.PropertyType == PropertyType.PropertyType_GeometricProperty)
                        {
                            GeometricPropertyDefinition gp = pd as GeometricPropertyDefinition;
                            if (gp.ReadOnly)
                            {
                                ignoreProperties.Add(gp.Name);
                            }
                        }
                    }

                    while (reader.ReadNext())
                    {
                        FdoRow row = null;
                        try
                        {
                            row = CreateRowFromReader(reader);
                        }
                        catch (Exception ex)
                        {
                            if (row != null)
                            {
                                RaiseFailedFeatureProcessed(row, ex);
                            }
                            else
                            {
                                RaiseFailedReadFeature(ex.Message, ex);
                            }
                        }
                        if (row != null)
                        {
                            yield return(row);
                        }
                    }
                }
            }
        }
Example #25
0
        /// <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 virtual void Execute(FdoConnection source, FdoConnection target, bool overwrite, string[] spatialContextNames)
        {
            if (spatialContextNames.Length == 0)
            {
                return;
            }

            using (FdoFeatureService sService = source.CreateFeatureService())
                using (FdoFeatureService tService = target.CreateFeatureService())
                {
                    bool supportsMultipleScs = target.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsMultipleSpatialContexts);
                    bool supportsDestroySc   = target.Capability.HasArrayCapability(CapabilityType.FdoCapabilityType_CommandList, (int)OSGeo.FDO.Commands.CommandType.CommandType_DestroySpatialContext);
                    if (supportsMultipleScs)
                    {
                        //Get all contexts in target
                        ReadOnlyCollection <SpatialContextInfo> contexts = tService.GetSpatialContexts();

                        List <string> updated = new List <string>();
                        //Destroy any clashing ones
                        if (overwrite && supportsDestroySc)
                        {
                            foreach (SpatialContextInfo c in contexts)
                            {
                                if (SpatialContextInSpecifiedList(c, spatialContextNames))
                                {
                                    tService.DestroySpatialContext(c);
                                }
                            }
                        }

                        //Then overwrite them
                        foreach (SpatialContextInfo c in contexts)
                        {
                            if (SpatialContextInSpecifiedList(c, spatialContextNames))
                            {
                                tService.CreateSpatialContext(c, overwrite);
                                updated.Add(c.Name);
                            }
                        }

                        //Now create the rest
                        var sourceScs = sService.GetSpatialContexts();
                        foreach (var sc in sourceScs)
                        {
                            if (!updated.Contains(sc.Name))
                            {
                                tService.CreateSpatialContext(sc, overwrite);
                            }
                        }
                    }
                    else
                    {
                        tService.CreateSpatialContext(sService.GetActiveSpatialContext(), true);
                    }
                }
        }
Example #26
0
        private void bgExecutor_DoWork(object sender, DoWorkEventArgs e)
        {
            string sql = e.Argument.ToString();

            using (var svc = _conn.CreateFeatureService())
            {
                int affected = svc.ExecuteSQLNonQuery(sql);
                e.Result = affected;
            }
        }
Example #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);
                    }
                }
            }
        }
        void CreateSchemaNodes(TreeNode connNode)
        {
            Action <TimeSpan> act  = (ts) => LoggingService.Info("Connection " + connNode.Name + ": Schema population completed in " + ts.TotalMilliseconds + "ms");
            FdoConnection     conn = _connMgr.GetConnection(connNode.Name);

            if (conn != null)
            {
                using (FdoFeatureService service = conn.CreateFeatureService())
                {
                    if (service.SupportsPartialSchemaDiscovery())
                    {
                        using (var measure = new TimeMeasurement(act))
                        {
                            List <string> schemaNames = service.GetSchemaNames();

                            //Pre-sort
                            SortedList <string, string> sorted = new SortedList <string, string>();
                            foreach (string name in schemaNames)
                            {
                                sorted.Add(name, name);
                            }

                            foreach (string name in schemaNames)
                            {
                                TreeNode schemaNode = CreateSchemaNode(name, true);
                                connNode.Nodes.Add(schemaNode);
                                schemaNode.Nodes.Add(ResourceService.GetString("TEXT_LOADING"));
                            }
                        }
                    }
                    else
                    {
                        using (var measure = new TimeMeasurement(act))
                        {
                            FeatureSchemaCollection schemas = service.DescribeSchema();

                            //Pre-sort
                            SortedList <string, FeatureSchema> sorted = new SortedList <string, FeatureSchema>();
                            foreach (FeatureSchema schema in schemas)
                            {
                                sorted.Add(schema.Name, schema);
                            }

                            foreach (FeatureSchema schema in schemas)
                            {
                                TreeNode schemaNode = CreateSchemaNode(schema.Name, false);
                                GetClassNodesFull(schema, schemaNode);
                                connNode.Nodes.Add(schemaNode);
                                schemaNode.Expand();
                            }
                        }
                    }
                }
            }
        }
        public FdoStandardQueryPresenter(IFdoStandardQueryView view, FdoConnection conn)
        {
            _view    = view;
            _conn    = conn;
            _service = _conn.CreateFeatureService();
            _view.UseExtendedSelectForOrdering = false;
            bool bExtended = Array.IndexOf(conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList), CommandType.CommandType_ExtendedSelect) >= 0;

            _view.OrderingEnabled = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsSelectOrdering) || bExtended;
            _view.UseExtendedSelectForOrdering = bExtended;
            _walker = SchemaWalker.GetWalker(conn);
        }
Example #30
0
        /// <summary>
        /// Executes the operation
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public override IEnumerable <FdoRow> Execute(IEnumerable <FdoRow> rows)
        {
            //We fetch the class def here instead of the ctor as the class in question
            //may have to be created by a pre-copy operation
            _clsDef = _service.GetClassByName(this.ClassName);

            IInsert insert = null;

            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                insert = service.CreateCommand <IInsert>(CommandType.CommandType_Insert);
            }
            this.Info("Set feature class to: {0}", this.ClassName);
            insert.SetFeatureClassName(this.ClassName);
            PropertyValueCollection propVals = insert.PropertyValues;

            Prepare(propVals);
            foreach (FdoRow row in rows)
            {
                Bind(row);
                insert.Prepare();
                try
                {
                    using (IFeatureReader reader = insert.Execute())
                    {
                        reader.Close();
                    }
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    ex.Data["Class/Table"] = this.ClassName;
                    RaiseFailedFeatureProcessed(row, ex);
                    RePrepare(propVals);
                }
                yield return(row);
            }
            insert.Dispose();
            //yield break;
        }