Esempio n. 1
0
        /// <summary>
        /// Reloads the tree.
        /// </summary>
        /// <param name="fsId">The fs id.</param>
        /// <param name="caps">The caps.</param>
        public void ReloadTree(string fsId, IFdoProviderCapabilities caps)
        {
            currentFsId = fsId;
            _caps       = caps;
            ClearPreviewPanes();
            trvSchema.Nodes.Clear();

            BusyWaitDialog.Run(Strings.FetchingSchemaNames, () =>
            {
                return(_edSvc.CurrentConnection.FeatureService.GetSchemas(currentFsId));
            }, (res, ex) =>
            {
                if (ex != null)
                {
                    ErrorDialog.Show(ex);
                }
                else
                {
                    string[] schemaNames = (string[])res;
                    foreach (var s in schemaNames)
                    {
                        var schemaNode        = new TreeNode(s);
                        schemaNode.Tag        = new SchemaNodeTag(s);
                        schemaNode.ImageIndex = schemaNode.SelectedImageIndex = IDX_SCHEMA;
                        schemaNode.Nodes.Add(Strings.TextLoading);
                        trvSchema.Nodes.Add(schemaNode);
                    }
                }
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the dialog.
        /// </summary>
        /// <param name="edSvc">The editor service.</param>
        /// <param name="caps">The provider capabilities.</param>
        /// <param name="cls">The class definition.</param>
        /// <param name="featureSourceId">The FeatureSource id.</param>
        /// <param name="mode">The editor mode</param>
        /// <param name="attachStylizationFunctions">if set to <c>true</c> stylization functions are also attached</param>
        public void Initialize(IEditorService edSvc, IFdoProviderCapabilities caps, ClassDefinition cls, string featureSourceId, ExpressionEditorMode mode, bool attachStylizationFunctions)
        {
            try
            {
                _mode  = mode;
                _cls   = cls;
                _edSvc = edSvc;
                if (_edSvc != null)
                {
                    _featSvc = _edSvc.CurrentConnection.FeatureService;
                    insertThemeExpressionToolStripMenuItem.Enabled = true;
                }
                else
                {
                    insertThemeExpressionToolStripMenuItem.Enabled = false;
                }
                m_featureSource = featureSourceId;
                _caps           = caps;

                btnTools.Enabled = attachStylizationFunctions;

                SortedList <string, PropertyDefinition> sortedCols = new SortedList <string, PropertyDefinition>();
                foreach (var col in _cls.Properties)
                {
                    sortedCols.Add(col.Name, col);
                }

                ColumnName.Items.Clear();
                ColumnName.Tag = sortedCols;

                foreach (var col in sortedCols.Values)
                {
                    string          name = col.Name;
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = name;
                    btn.Text   = name;
                    btn.Click += delegate
                    {
                        InsertText(name);
                    };
                    btnProperties.DropDown.Items.Add(btn);

                    ColumnName.Items.Add(name);
                }

                if (ColumnName.Items.Count > 0)
                {
                    ColumnName.SelectedIndex = 0;
                }

                LoadFunctions(caps, attachStylizationFunctions);
            }
            catch
            {
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes the FDO expression editor
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="cls"></param>
        /// <param name="featureSourceId"></param>
        /// <param name="mode"></param>
        public void Initialize(IServerConnection conn, ClassDefinition cls, string featureSourceId, ExpressionEditorMode mode)
        {
            IFeatureSource           fs   = (IFeatureSource)conn.ResourceService.GetResource(featureSourceId);
            IFdoProviderCapabilities caps = conn.FeatureService.GetProviderCapabilities(fs.Provider);

            //This is normally set by the Editor Service, but we don't have that so do it here
            _featSvc = conn.FeatureService;

            this.Initialize(null, caps, cls, featureSourceId, mode, false);
        }
 public FdoExpressionCompletionDataProvider(ClassDefinition cls, IFdoProviderCapabilities caps)
 {
     _klass            = cls;
     _caps             = caps;
     this.DefaultIndex = 0;
     this.PreSelection = null;
     this.ImageList    = new System.Windows.Forms.ImageList();
     this.ImageList.Images.Add(Properties.Resources.block);
     this.ImageList.Images.Add(Properties.Resources.property);
     this.ImageList.Images.Add(Properties.Resources.funnel);
 }
 public override void Bind(IEditorService service)
 {
     //Only available on MGOS 2.2 and above
     this.LocalPreviewEnabled = service.SiteVersion >= new Version(2, 2);
     _fs    = (IFeatureSource)service.GetEditedResource();
     _fsvc  = service.CurrentConnection.FeatureService;
     _caps  = _fsvc.GetProviderCapabilities(_fs.Provider);
     _rsvc  = service.CurrentConnection.ResourceService;
     _edsvc = service;
     _edsvc.RegisterCustomNotifier(this);
     this.ConfigEnabled = _caps.Connection.SupportsConfiguration;
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardQueryCtrl"/> class.
 /// </summary>
 /// <param name="fsId">The fs id.</param>
 /// <param name="edSvc">The editor service.</param>
 /// <param name="cls">The CLS.</param>
 /// <param name="caps">The caps.</param>
 public StandardQueryCtrl(string fsId, IEditorService edSvc, ClassDefinition cls, IFdoProviderCapabilities caps)
     : this()
 {
     _fsId  = fsId;
     _edSvc = edSvc;
     _cls   = cls;
     _caps  = caps;
     foreach (var prop in cls.Properties)
     {
         chkProperties.Items.Add(prop.Name, true);
     }
 }
        /// <summary>
        /// Validates the given FDO expression
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="cls"></param>
        /// <param name="caps"></param>
        public void ValidateExpression(FdoExpression expr, ClassDefinition cls, IFdoProviderCapabilities caps)
        {
            switch (expr.ExpressionType)
            {
            case ExpressionType.BinaryExpression:
            {
                var binExpr = (FdoBinaryExpression)expr;
                ValidateExpression(binExpr.Left, cls, caps);
                ValidateExpression(binExpr.Right, cls, caps);
            }
            break;

            case ExpressionType.UnaryExpression:
            {
                var unExpr = (FdoUnaryExpression)expr;
                ValidateExpression(unExpr.Expression, cls, caps);
            }
            break;

            case ExpressionType.Identifier:
            {
                ValidateIdentifier(((FdoIdentifier)expr), cls);
            }
            break;

            case ExpressionType.Function:
            {
                var    func = ((FdoFunction)expr);
                string name = func.Identifier.Name;
                if (!IsStylizationFunc(name) && !caps.Expression.SupportedFunctions.Any(f => f.Name.ToUpper() == name.ToUpper()))
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidExpressionUnsupportedFunction, name), name);
                }

                foreach (var arg in func.Arguments)
                {
                    ValidateExpression(arg, cls, caps);
                }
            }
            break;
            }
        }
Esempio n. 8
0
        private void LoadFunctions(IFdoProviderCapabilities caps, bool attachStylizationFunctions)
        {
            //Functions
            foreach (var func in caps.Expression.SupportedFunctions)
            {
                _functions.Add(func.Name, func);
            }

            if (attachStylizationFunctions)
            {
                foreach (var func in Utility.GetStylizationFunctions())
                {
                    _functions.Add(func.Name, func);
                }
            }

            foreach (var func in _functions.Values)
            {
                string name = func.Name;
                string desc = func.Description;

                ToolStripItemCollection parent = btnFunctions.DropDown.Items;
                var sigs = MakeUniqueSignatures(func);
                if (sigs.Length > 1)
                {
                    ToolStripMenuItem btn = new ToolStripMenuItem();
                    btn.Name        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                    btn.Text        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                    btn.ToolTipText = desc;

                    btnFunctions.DropDown.Items.Add(btn);
                    parent = btn.DropDown.Items;
                }

                foreach (var sig in sigs)
                {
                    ToolStripMenuItem btn = new ToolStripMenuItem();
                    btn.Name        = name;
                    btn.ToolTipText = desc;

                    List <string> args = new List <string>();
                    foreach (var argDef in sig.Arguments)
                    {
                        args.Add(argDef.Name.Trim());
                    }
                    string expr = $"{name}({FdoExpressionCompletionDataProvider.StringifyFunctionArgs(args)})";
                    btn.Text   = expr;
                    btn.Click += (s, e) =>
                    {
                        InsertText(expr);
                    };
                    parent.Add(btn);
                }
            }

            //Spatial Operators
            foreach (var op in caps.Filter.SpatialOperations)
            {
                string          name = op.ToUpper();
                ToolStripButton btn  = new ToolStripButton();
                btn.Name   = btn.Text = btn.ToolTipText = op;
                btn.Click += (s, e) =>
                {
                    InsertSpatialFilter(name);
                };
                btnSpatial.DropDown.Items.Add(btn);
            }

            //Distance Operators
            foreach (var op in caps.Filter.DistanceOperations)
            {
                string          name = op.ToUpper();
                ToolStripButton btn  = new ToolStripButton();
                btn.Name   = btn.Text = btn.ToolTipText = op;
                btn.Click += (s, e) =>
                {
                    InsertSpatialFilter(name);
                };
                btnDistance.DropDown.Items.Add(btn);
            }

            //Conditional Operators
            foreach (var op in caps.Filter.ConditionTypes)
            {
                string          name = op.ToUpper();
                ToolStripButton btn  = new ToolStripButton();
                btn.Name   = btn.Text = btn.ToolTipText = op;
                btn.Click += (s, e) =>
                {
                    InsertSpatialFilter(name);
                };
                btnCondition.DropDown.Items.Add(btn);
            }
        }
        /// <summary>
        /// Initializes the dialog.
        /// </summary>
        /// <param name="edSvc">The editor service.</param>
        /// <param name="caps">The provider capabilities.</param>
        /// <param name="cls">The class definition.</param>
        /// <param name="featureSourceId">The features source id.</param>
        /// <param name="mode">The editor mode</param>
        /// <param name="attachStylizationFunctions">If true, Stylization FDO functions will be included</param>
        public void Initialize(IEditorService edSvc, IFdoProviderCapabilities caps, ClassDefinition cls, string featureSourceId, ExpressionEditorMode mode, bool attachStylizationFunctions)
        {
            try
            {
                _caps  = caps;
                _mode  = mode;
                _cls   = cls;
                _edSvc = edSvc;
                if (_edSvc != null)
                {
                    _featSvc = _edSvc.CurrentConnection.FeatureService;
                    insertThemeExpressionToolStripMenuItem.Enabled = true;
                }
                else
                {
                    insertThemeExpressionToolStripMenuItem.Enabled = false;
                }
                m_featureSource = featureSourceId;

                insertThemeExpressionToolStripMenuItem.Enabled = attachStylizationFunctions;

                //TODO: Perhaps add column type and indication of primary key
                SortedList <string, PropertyDefinition> sortedCols = new SortedList <string, PropertyDefinition>();
                foreach (var col in _cls.Properties)
                {
                    sortedCols.Add(col.Name, col);
                }

                ColumnName.Items.Clear();
                ColumnName.Tag = sortedCols;

                foreach (var col in sortedCols.Values)
                {
                    string          name = col.Name;
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = name;
                    btn.Text   = name;
                    btn.Click += delegate
                    {
                        InsertText(name);
                    };
                    btnProperties.DropDown.Items.Add(btn);

                    ColumnName.Items.Add(name);
                }

                if (ColumnName.Items.Count > 0)
                {
                    ColumnName.SelectedIndex = 0;
                }

                LoadCompletableProperties(_cls.Properties);

                //TODO: Figure out how to translate the enums into something usefull

                //Functions
                var sortedFuncs = new SortedList <string, IFdoFunctionDefintion>();
                foreach (var func in caps.Expression.SupportedFunctions)
                {
                    sortedFuncs.Add(func.Name, func);
                }

                if (attachStylizationFunctions)
                {
                    foreach (var func in Utility.GetStylizationFunctions())
                    {
                        sortedFuncs.Add(func.Name, func);
                    }
                }

                foreach (var func in sortedFuncs.Values)
                {
                    string name = func.Name;
                    string desc = func.Description;

                    ToolStripItemCollection parent = btnFunctions.DropDown.Items;
                    var sigs = ExpressionEditor.MakeUniqueSignatures(func);
                    if (sigs.Length > 1)
                    {
                        ToolStripMenuItem btn = new ToolStripMenuItem();
                        btn.Name        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                        btn.Text        = string.Format(Strings.MultiSigFunction, name, sigs.Length);
                        btn.ToolTipText = desc;

                        btnFunctions.DropDown.Items.Add(btn);
                        parent = btn.DropDown.Items;
                    }

                    foreach (var sig in sigs)
                    {
                        ToolStripMenuItem btn = new ToolStripMenuItem();
                        btn.Name        = name;
                        btn.ToolTipText = desc;

                        List <string> args = new List <string>();
                        foreach (var argDef in sig.Arguments)
                        {
                            args.Add(argDef.Name.Trim());
                        }
                        string expr = $"{name}({FdoExpressionCompletionDataProvider.StringifyFunctionArgs(args)})"; //NOXLATE
                        btn.Text   = $"{expr} : {sig.ReturnType}";                                                  //NOXLATE
                        btn.Click += (s, e) =>
                        {
                            InsertText(expr);
                        };
                        parent.Add(btn);
                    }
                }
                LoadCompletableFunctions(caps.Expression.SupportedFunctions);
                if (attachStylizationFunctions)
                {
                    LoadCompletableFunctions(Utility.GetStylizationFunctions());
                }

                //Spatial Operators
                foreach (var op in caps.Filter.SpatialOperations)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnSpatial.DropDown.Items.Add(btn);
                }

                //Distance Operators
                foreach (var op in caps.Filter.DistanceOperations)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnDistance.DropDown.Items.Add(btn);
                }

                //Conditional Operators
                foreach (var op in caps.Filter.ConditionTypes)
                {
                    string          name = op.ToUpper();
                    ToolStripButton btn  = new ToolStripButton();
                    btn.Name   = btn.Text = btn.ToolTipText = op;
                    btn.Click += delegate
                    {
                        InsertFilter(name);
                    };
                    btnCondition.DropDown.Items.Add(btn);
                }

                /*try
                 * {
                 *  /*FdoProviderCapabilities cap = m_connection.GetProviderCapabilities(m_providername);
                 *  foreach (FdoProviderCapabilitiesFilterType cmd in cap.Filter.Condition)
                 *      FunctionCombo.Items.Add(cmd.ToString());
                 *
                 *  FunctionLabel.Enabled = FunctionCombo.Enabled = true;
                 * }
                 * catch
                 * {
                 *  FunctionLabel.Enabled = FunctionCombo.Enabled = false;
                 * }*/
            }
            catch
            {
            }
        }
        /// <summary>
        /// Validates the given FDO filter
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="cls"></param>
        /// <param name="caps"></param>
        public void ValidateFilter(FdoFilter filter, ClassDefinition cls, IFdoProviderCapabilities caps)
        {
            switch (filter.FilterType)
            {
            case FilterType.BinaryLogicalOperator:
            {
                var binOp = (FdoBinaryLogicalOperator)filter;
                ValidateFilter(binOp.Left, cls, caps);
                ValidateFilter(binOp.Right, cls, caps);
            }
            break;

            case FilterType.ComparisonCondition:
            {
                var compCond = (FdoComparisonCondition)filter;
                if (compCond.Operator != ComparisonOperations.Like)
                {
                    if (!caps.Filter.ConditionTypes.Select(o => o.ToUpper()).Contains("COMPARISON"))         //NOXLATE
                    {
                        throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedConditionType, compCond.Operator), compCond.Operator.ToString());
                    }
                }
                else         //Like
                {
                    if (!caps.Filter.ConditionTypes.Select(o => o.ToUpper()).Any(o => o == compCond.Operator.ToString().ToUpper()))
                    {
                        throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedConditionType, compCond.Operator), compCond.Operator.ToString());
                    }
                }
                ValidateExpression(compCond.Left, cls, caps);
                ValidateExpression(compCond.Right, cls, caps);
            }
            break;

            case FilterType.DistanceCondition:
            {
                var distCond = (FdoDistanceCondition)filter;
                if (!caps.Filter.DistanceOperations.Select(o => o.ToUpper()).Any(o => o == distCond.Operator.ToString().ToUpper()))
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedDistanceOperator, distCond.Operator), distCond.Operator.ToString());
                }
                ValidateIdentifier(distCond.Identifier, cls);
                ValidateExpression(distCond.Expression, cls, caps);
            }
            break;

            case FilterType.InCondition:
            {
                if (!caps.Filter.ConditionTypes.Select(o => o.ToUpper()).Contains("IN"))                                                  //NOXLATE
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedConditionType, "IN"), "IN"); //NOXLATE
                }
                var inCond = (FdoInCondition)filter;
                ValidateIdentifier(inCond.Identifier, cls);
                foreach (var val in inCond.ValueList)
                {
                    ValidateExpression(val, cls, caps);
                }
            }
            break;

            case FilterType.NullCondition:
            {
                if (!caps.Filter.ConditionTypes.Select(o => o.ToUpper()).Contains("NULL"))                                                    //NOXLATE
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedConditionType, "NULL"), "NULL"); //NOXLATE
                }
                var nullCond = (FdoNullCondition)filter;
                ValidateIdentifier(nullCond.Identifier, cls);
            }
            break;

            case FilterType.SpatialCondition:
            {
                var spFilter = (FdoSpatialCondition)filter;
                if (!caps.Filter.ConditionTypes.Select(o => o.ToUpper()).Contains("SPATIAL"))                                                                          //NOXLATE
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedConditionType, "SPATIAL"), spFilter.Operator.ToString()); //NOXLATE
                }
                if (!caps.Filter.SpatialOperations.Select(o => o.ToUpper()).Any(o => o == spFilter.Operator.ToString().ToUpper()))
                {
                    throw new FdoExpressionValidationException(string.Format(Strings.InvalidFilterUnsupportedSpatialOperator, spFilter.Operator), spFilter.Operator.ToString());
                }

                ValidateIdentifier(spFilter.Identifier, cls);
                ValidateExpression(spFilter.Expression, cls, caps);
            }
            break;

            case FilterType.UnaryLogicalOperator:
            {
                var negatedFilter = ((FdoUnaryLogicalOperator)filter).NegatedFilter;
                ValidateFilter(negatedFilter, cls, caps);
            }
            break;
            }
        }
        public PreviewPane(string fsId, QueryMode mode, ClassDefinition cls, IEditorService edSvc, IFdoProviderCapabilities caps)
            : this()
        {
            _fsId    = fsId;
            _mode    = mode;
            _cls     = cls;
            _featSvc = edSvc.CurrentConnection.FeatureService;

            IQueryControl ctrl = null;

            switch (_mode)
            {
            case QueryMode.SQL:
                ctrl   = new SqlQueryCtrl(fsId, edSvc);
                _inner = ctrl;
                break;

            case QueryMode.Standard:
                ctrl   = new StandardQueryCtrl(fsId, edSvc, cls, caps);
                _inner = ctrl;
                break;
            }

            if (ctrl == null)
            {
                throw new ArgumentException(Strings.UnknownQueryMode);
            }

            ctrl.Content.Dock = DockStyle.Fill;
            queryPane.Controls.Add(ctrl.Content);
        }