Example #1
0
        protected override void OnExtractSchemaHints()
        {
            DataPath textBindingPath;

            if (Control.Bindings != null)
            {
                Control.Bindings.TryGetValue(LookupIdBindingCode, out _lookupIdBindingPath);
                Control.Bindings.TryGetValue(TextBindingCode, out textBindingPath);
            }
            else
            {
                textBindingPath = null;
            }

            string lookupDef;

            if (Component.TryGetPropertyValue("Lookup", out lookupDef))
            {
                _lookup = EntityLoader.LoadLookup(lookupDef);

                if (_lookup != null)
                {
                    try
                    {
                        _idDataPath = DataPath.Parse(_lookup.IdField);
                    }
                    catch (FormatException)
                    {
                        LogError("Unable to parse '{0}' lookup id field", _lookup.IdField);
                    }

                    try
                    {
                        _nameDataPath = DataPath.Parse(_lookup.NameField);
                    }
                    catch (FormatException)
                    {
                        LogError("Unable to parse '{0}' lookup name field", _lookup.NameField);
                    }

                    DataPathTranslator.RegisterTable(_lookup.MainTable);

                    if (_idDataPath != null)
                    {
                        _columnPrefixPath = _idDataPath.Reverse();
                        DataPathTranslator.RegisterField(_idDataPath);
                        DataPathTranslator.RegisterField(_columnPrefixPath);
                    }

                    if (_nameDataPath != null)
                    {
                        DataPathTranslator.RegisterField(_nameDataPath);
                    }

                    _columns = new List<ColumnDefinition>();
                    _dataPaths = new List<DataPath>();

                    if (_lookup.Layout != null)
                    {
                        foreach (string columnString in _lookup.Layout.Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries))
                        {
                            ColumnDefinition column = ColumnDefinition.Parse(columnString);

                            if (column.Visible)
                            {
                                DataPath dataPath = null;

                                try
                                {
                                    dataPath = DataPath.Parse(column.Binding);
                                }
                                catch (FormatException)
                                {
                                    LogError("Unable to parse '{0}' column binding string", column.Binding);
                                }

                                if (dataPath != null)
                                {
                                    DataPathTranslator.RegisterField(dataPath);
                                    _columns.Add(column);
                                    _dataPaths.Add(dataPath);
                                }
                            }
                        }
                    }
                }
                else
                {
                    LogWarning("Unable to find '{0}' lookup", lookupDef);
                }
            }

            if (_lookupIdBindingPath != null && _idDataPath != null)
            {
                if (textBindingPath != null &&
                    _nameDataPath != null &&
                    textBindingPath.Joins.Count == 0)
                {
                    Debug.Assert(_lookupIdBindingPath.Joins.Count == 0);
                    Debug.Assert(_idDataPath.Joins.Count == 0);
                    Debug.Assert(_nameDataPath.Joins.Count == 0);
                    DataPathTranslator.RegisterJoin(_lookupIdBindingPath, _idDataPath);
                    Context.SecondaryJoins[
                        new DataPathJoin(_lookupIdBindingPath.TargetTable, _lookupIdBindingPath.TargetField, _idDataPath.TargetTable, _idDataPath.TargetField)] =
                        new DataPathJoin(textBindingPath.TargetTable, textBindingPath.TargetField, _nameDataPath.TargetTable, _nameDataPath.TargetField);
                    _isObject = true;
                }

                if (!_isObject)
                {
                    OrmEntity entity = EntityLoader.LoadEntity(_lookupIdBindingPath.TargetTable);

                    if (entity != null)
                    {
                        string targetField = _lookupIdBindingPath.TargetField;

                        if (targetField.StartsWith("@"))
                        {
                            targetField = targetField.Substring(1);
                        }

                        OrmEntityProperty property = entity.Properties.GetFieldPropertyByFieldName(targetField);

                        if (property != null)
                        {
                            _isObject = !property.Include;
                        }
                    }
                }

                if (_isObject)
                {
                    DataPathTranslator.RegisterJoin(_idDataPath, _lookupIdBindingPath);
                }
            }
        }
        protected override void OnExtractSchemaHints()
        {
            DelphiComponent query = Component.Components[0];

            if (query.TryGetPropertyValue("MainTable", out _tableName) && !string.IsNullOrEmpty(_tableName))
            {
                DataPathTranslator.RegisterTable(_tableName);
            }

            string bindCondition;

            if (query.TryGetPropertyValue("BindCondition", out bindCondition) && !string.IsNullOrEmpty(bindCondition))
            {
                try
                {
                    _bindConditionPath = DataPath.Parse(bindCondition);
                }
                catch (FormatException)
                {
                    LogError("Unable to parse '{0}' bind condition", bindCondition);
                }

                if (_bindConditionPath != null)
                {
                    if (_bindIdBindingPath != null)
                    {
                        DataPathTranslator.RegisterJoin(_bindIdBindingPath, _bindConditionPath);
                    }

                    _columnPrefixPath = _bindConditionPath.Reverse();
                    DataPathTranslator.RegisterField(_columnPrefixPath);
                }
            }

            _columns = new List<ColumnDefinition>();
            _dataPaths = new List<DataPath>();

            IEnumerable layouts;

            if (query.TryGetPropertyValue("Layouts.Strings", out layouts))
            {
                foreach (string layout in layouts)
                {
                    ColumnDefinition column = ColumnDefinition.Parse(layout);

                    if (column.Visible)
                    {
                        DataPath dataPath = null;

                        try
                        {
                            dataPath = DataPath.Parse(column.Binding);
                        }
                        catch (FormatException)
                        {
                            LogError("Unable to parse '{0}' column binding string", column.Binding);
                        }

                        if (dataPath != null)
                        {
                            DataPathTranslator.RegisterField(dataPath);
                            _columns.Add(column);
                            _dataPaths.Add(dataPath);
                        }
                    }
                }
            }
        }
        protected override void OnExtractSchemaHints()
        {
            if (Component.TryGetPropertyValue("TableName", out _tableName) && !string.IsNullOrEmpty(_tableName))
            {
                DataPathTranslator.RegisterTable(_tableName);
            }

            string bindCondition;

            if (Component.TryGetPropertyValue("BindCondition", out bindCondition) && !string.IsNullOrEmpty(bindCondition))
            {
                try
                {
                    _bindConditionPath = DataPath.Parse(bindCondition);
                }
                catch (FormatException)
                {
                    LogError("Unable to parse '{0}' bind condition", bindCondition);
                }

                if (_bindConditionPath != null)
                {
                    if (_bindIdBindingPath != null)
                    {
                        DataPathTranslator.RegisterJoin(_bindIdBindingPath, _bindConditionPath);
                    }

                    _columnPrefixPath = _bindConditionPath.Reverse();
                    DataPathTranslator.RegisterField(_columnPrefixPath);
                }
            }

            _columnBuilders = new List<ColumnBuilder>(Component.Components.Count);

            foreach (DelphiComponent columnComponent in Component.Components)
            {
                bool visible;

                if (!columnComponent.TryGetPropertyValue("Visible", out visible) || visible)
                {
                    ColumnBuilder builder = ColumnBuilder.CreateBuilder(columnComponent);

                    if (builder != null)
                    {
                        _workItem.BuildTransientItem(builder);
                        builder.ExtractSchemaHints();
                        _columnBuilders.Add(builder);
                    }
                    else
                    {
                        LogWarning("Legacy column type '{0}' not supported", columnComponent.Type);
                    }
                }
            }
        }