public void Init(string initSchema, string initClass)
        {
            List <QueryMode> modes = new List <QueryMode>();

            if (!string.IsNullOrEmpty(initSchema) && !string.IsNullOrEmpty(initClass))
            {
                if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select))
                {
                    using (FdoFeatureService service = _connection.CreateFeatureService())
                    {
                        ClassDefinition classDef = service.GetClassByName(initSchema, initClass);
                        if (!ExpressUtility.HasRaster(classDef))
                        {
                            modes.Add(QueryMode.Standard);
                            _queryViews.Add(QueryMode.Standard, new FdoStandardQueryCtl(_connection, initSchema, initClass));
                        }
                    }
                }
                if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SelectAggregates))
                {
                    modes.Add(QueryMode.Aggregate);
                    _queryViews.Add(QueryMode.Aggregate, new FdoAggregateQueryCtl(_connection, initSchema, initClass));
                }
            }
            else
            {
                if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select))
                {
                    modes.Add(QueryMode.Standard);
                    _queryViews.Add(QueryMode.Standard, new FdoStandardQueryCtl(_connection));
                }
                if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SelectAggregates))
                {
                    modes.Add(QueryMode.Aggregate);
                    _queryViews.Add(QueryMode.Aggregate, new FdoAggregateQueryCtl(_connection));
                }
            }
            if (_service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_SQLCommand))
            {
                modes.Add(QueryMode.SQL);
                _queryViews.Add(QueryMode.SQL, new FdoSqlQueryCtl());
            }
            foreach (IQuerySubView qv in _queryViews.Values)
            {
                qv.MapPreviewStateChanged += new MapPreviewStateEventHandler(OnMapPreviewStateChanged);
                qv.SetRestrictions(_connection.Capability);
            }
            _view.QueryModes = modes;

            _view.InsertEnabled = (_view.SelectedQueryMode != QueryMode.SQL) && insertSupported;
        }
Example #2
0
        /// <summary>
        /// Validates these options
        /// </summary>
        public void Validate()
        {
            if (_Left == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_LEFT_UNDEFINED"));
            }

            if (_Right == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_RIGHT_UNDEFINED"));
            }

            if (_Target == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_UNDEFINED"));
            }

            if (string.IsNullOrEmpty(_Target.ClassName))
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_CLASS_UNDEFINED"));
            }

            if (this.JoinPairs.Count == 0)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_KEYS_UNDEFINED"));
            }

            int count = this.LeftProperties.Count + this.RightProperties.Count;

            if (string.IsNullOrEmpty(_LeftPrefix) && string.IsNullOrEmpty(_RightPrefix))
            {
                ISet <string> set = new HashSet <string>();
                foreach (var prop in this.LeftProperties)
                {
                    set.Add(prop);
                }
                foreach (var prop in this.RightProperties)
                {
                    set.Add(prop);
                }

                //If all properties are unique then the counts should be the same
                if (set.Count < count)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_PROPERTY_NAME_COLLISION"));
                }
            }

            //Verify left source filter checks out
            if (!string.IsNullOrEmpty(this.LeftFilter))
            {
                try
                {
                    using (var filter = Filter.Parse(this.LeftFilter)) { }
                }
                catch
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_INVALID_LEFT_FILTER", this.LeftFilter));
                }
            }

            //Verify right source filter checks out
            if (!string.IsNullOrEmpty(this.RightFilter))
            {
                try
                {
                    using (var filter = Filter.Parse(this.RightFilter)) { }
                }
                catch
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_INVALID_RIGHT_FILTER", this.LeftFilter));
                }
            }

            //Create target class. The schema must already exist, but the class must *not* already exist.
            using (FdoFeatureService service = this.Target.Connection.CreateFeatureService())
            {
                if (!service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_ApplySchema))
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_UNSUPPORTED_CMD", OSGeo.FDO.Commands.CommandType.CommandType_ApplySchema));
                }

                //Get target schema
                FeatureSchema schema = service.GetSchemaByName(this.Target.SchemaName);
                if (schema == null)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_SCHEMA_NOT_FOUND"));
                }

                //Check target class does not exist
                int cidx = schema.Classes.IndexOf(this.Target.ClassName);
                if (cidx >= 0)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_EXISTS"));
                }
            }
        }