Beispiel #1
0
        private void slyceGrid1_NewRowAdded(out object newObject)
        {
            ComponentPropertyImpl property = new ComponentPropertyImpl("NewProperty")
            {
                Type = "System.String"
            };

            property.ValidationOptions.FractionalDigits = 0;
            property.ValidationOptions.FutureDate       = false;
            property.ValidationOptions.IntegerDigits    = 0;
            property.ValidationOptions.MaximumLength    = 0;
            property.ValidationOptions.MaximumValue     = 0;
            property.ValidationOptions.MinimumLength    = 0;
            property.ValidationOptions.MinimumValue     = 0;
            property.ValidationOptions.NotEmpty         = false;
            property.ValidationOptions.Nullable         = false;
            property.ValidationOptions.PastDate         = false;
            property.ValidationOptions.RegexPattern     = "";
            property.ValidationOptions.Validate         = false;

            ComponentSpecification.AddProperty(property);
            newObject = property;

            AddPropertyToPropertiesGrid(property);

            if (ComponentChanged != null)
            {
                ComponentChanged(ComponentSpecification, null);
            }
        }
Beispiel #2
0
        public FormRefactorToComponent(EntityImpl entity, List <Property> properties)
        {
            InitializeComponent();

            SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer, true);

            FontItem = new Font(Font.FontFamily.Name, 8F, FontStyle.Regular);
            FontType = new Font(Font.FontFamily.Name, 7F, FontStyle.Regular);

            FocusHelper  = new Slyce.Common.TextBoxFocusHelper(new TextBox[] { textBoxComponentEntityName, textBoxNewComponentName });
            NewComponent = new ComponentSpecificationImpl(NewComponentText);

            foreach (Property prop in properties)
            {
                NewComponent.AddProperty(ComponentPropertyImpl.CreateFromProperty(prop));
            }

            textBoxNewComponentName.Text = NewComponentText;
            Entity     = entity;
            Properties = properties;
            int maxHeight = Populate();

            ResizeForm(maxHeight);
        }
Beispiel #3
0
        private SlyceTreeGridCellItem CreateNewNullableCell(ComponentPropertyImpl property, object value, ApplicableOptions options)
        {
            ApplicableOptions     applicableOptions = ValidationOptions.GetApplicableValidationOptionsForType(property.Type);
            SlyceTreeGridCellItem cell = new SlyceTreeGridCellItem(value, (applicableOptions & options) != options);

            cell.IsNullable = true;
            return(cell);
        }
        public void It_Should_Serialise_To_This()
        {
            const string expectedXML = BasicPropertyXml;

            ComponentProperty property = new ComponentPropertyImpl("Street");

            string outputXML = new EntitySetSerialisationScheme().SerialiseComponentProperty(property);
            outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
            Assert.That(outputXML, Is.EqualTo(expectedXML));
        }
Beispiel #5
0
        private void Populate()
        {
            Slyce.Common.Utility.SuspendPainting(slyceGrid1);
            slyceGrid1.Clear();
            // Populate Columns from Component
            slyceGrid1.Columns.Add(new ColumnItem("Name", ColumnItem.ColumnTypes.Textbox, "NewProp", "General"));
            slyceGrid1.Columns.Add(new ColumnItem("Type", ColumnItem.ColumnTypes.Textbox, "System.String", "General"));

            ComponentPropertyImpl prop = new ComponentPropertyImpl();

            foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in prop.Ex)
            {
                if (uo.DataType == typeof(bool?))
                {
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.NullableCheckBox, null, "General"));
                }
                else if (uo.DataType == typeof(string))
                {
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"));
                }
                else if (uo.DataType == typeof(int))
                {
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"));
                }
                else if (uo.DataType == typeof(bool))
                {
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Checkbox, null, "General"));
                }
                else
                {
                    throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name);
                }
            }
            #region Validation options
            slyceGrid1.Columns.Add(new ColumnItem("Fractional Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Future Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Integer Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Max Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Min Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Max Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Min Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Not Empty", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Nullable", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Past Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Regex", ColumnItem.ColumnTypes.NullableTextBox, "", "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Validate", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            #endregion

            foreach (ComponentPropertyImpl property in ComponentSpecification.Properties)
            {
                AddPropertyToPropertiesGrid(property);
            }
            slyceGrid1.Populate();
            Slyce.Common.Utility.ResumePainting(slyceGrid1);
        }
Beispiel #6
0
        public void It_Should_Serialise_To_This()
        {
            const string expectedXML = BasicPropertyXml;

            ComponentProperty property = new ComponentPropertyImpl("Street");

            string outputXML = new EntitySetSerialisationScheme().SerialiseComponentProperty(property);

            outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
            Assert.That(outputXML, Is.EqualTo(expectedXML));
        }
Beispiel #7
0
        private void AddPropertyToPropertiesGrid(ComponentPropertyImpl property)
        {
            SlyceTreeGridItem gridItem = new SlyceTreeGridItem();

            gridItem.Tag = property;
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.Name));
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.Type));

            foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in property.Ex)
            {
                if (uo.DataType == typeof(bool?))
                {
                    bool?nullableBoolValue = (bool?)uo.Value;
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem(false, true, nullableBoolValue.HasValue ? nullableBoolValue.Value : false));
                }
                else if (uo.DataType == typeof(string))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((string)uo.Value));
                }
                else if (uo.DataType == typeof(int))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((int)uo.Value));
                }
                else if (uo.DataType == typeof(bool))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((bool)uo.Value));
                }
                else
                {
                    throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name);
                }
            }
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.FractionalDigits, ApplicableOptions.Digits));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.FutureDate, ApplicableOptions.Date));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.IntegerDigits, ApplicableOptions.Digits));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MaximumLength, ApplicableOptions.Length));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MinimumLength, ApplicableOptions.Length));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MaximumValue, ApplicableOptions.Value));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MinimumValue, ApplicableOptions.Value));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.NotEmpty, ApplicableOptions.NotEmpty));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.Nullable, ApplicableOptions.Nullable));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.PastDate, ApplicableOptions.Date));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.RegexPattern, ApplicableOptions.RegexPattern));
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.ValidationOptions.Validate, (ValidationOptions.GetApplicableValidationOptionsForType(property.Type) & ApplicableOptions.Validate) != ApplicableOptions.Validate));

            slyceGrid1.Items.Add(gridItem);
        }
        private void AddPropertyToPropertiesGrid(ComponentPropertyImpl property)
        {
            SlyceTreeGridItem gridItem = new SlyceTreeGridItem();
            gridItem.Tag = property;
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.Name));
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.Type));

            foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in property.Ex)
            {
                if (uo.DataType == typeof(bool?))
                {
                    bool? nullableBoolValue = (bool?)uo.Value;
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem(false, true, nullableBoolValue.HasValue ? nullableBoolValue.Value : false));
                }
                else if (uo.DataType == typeof(string))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((string)uo.Value));
                }
                else if (uo.DataType == typeof(int))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((int)uo.Value));
                }
                else if (uo.DataType == typeof(bool))
                {
                    gridItem.SubItems.Add(new SlyceTreeGridCellItem((bool)uo.Value));
                }
                else
                {
                    throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name);
                }
            }
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.FractionalDigits, ApplicableOptions.Digits));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.FutureDate, ApplicableOptions.Date));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.IntegerDigits, ApplicableOptions.Digits));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MaximumLength, ApplicableOptions.Length));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MinimumLength, ApplicableOptions.Length));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MaximumValue, ApplicableOptions.Value));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.MinimumValue, ApplicableOptions.Value));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.NotEmpty, ApplicableOptions.NotEmpty));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.Nullable, ApplicableOptions.Nullable));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.PastDate, ApplicableOptions.Date));
            gridItem.SubItems.Add(CreateNewNullableCell(property, property.ValidationOptions.RegexPattern, ApplicableOptions.RegexPattern));
            gridItem.SubItems.Add(new SlyceTreeGridCellItem(property.ValidationOptions.Validate, (ValidationOptions.GetApplicableValidationOptionsForType(property.Type) & ApplicableOptions.Validate) != ApplicableOptions.Validate));

            slyceGrid1.Items.Add(gridItem);
        }
        public void ApplyChanges(MappingSet mappingSet, EntityKey key)
        {
            // Create the new Spec
            ComponentSpecification spec = new ComponentSpecificationImpl(newComponentSpecificationName);

            var properties = key.Properties.ToList();

            foreach (var property in properties)
            {
                var newProperty = ComponentPropertyImpl.CreateFromProperty(property);
                spec.AddProperty(newProperty);
            }

            mappingSet.EntitySet.AddComponentSpecification(spec);

            // Create the new Component
            var component = spec.CreateImplementedComponentFor(key.Parent, newComponentName);

            // Map the old property's columns to the new component
            for (int i = 0; i < properties.Count; i++)
            {
                var property    = properties[i];
                var newProperty = spec.Properties[i];

                var componentProperty = component.GetProperty(newProperty.Name);
                mappingSet.ChangeMappingFor(componentProperty).To(property.MappedColumn());
            }

            // Delete old properties
            if (deleteExistingProperties)
            {
                foreach (var property in properties)
                {
                    property.DeleteSelf();
                }
            }

            // Set the Key to use the new component.
            key.Component = component;
        }
Beispiel #10
0
        private void slyceGrid1_CellValueChanged(int row, int cell, int columnIndex, string columnHeader, ref object tag, object newValue)
        {
            ComponentPropertyImpl property = (ComponentPropertyImpl)tag;

            if (property == null)
            {
                return;
            }

            bool nullableColumn = string.IsNullOrEmpty(columnHeader);

            if (nullableColumn)
            {
                columnHeader = slyceGrid1.Columns[columnIndex].Text;
            }

            switch (columnHeader)
            {
            case "Name":
                property.Name = (string)newValue;
                break;

            case "Type":
                property.Type = (string)newValue;
                break;

            case "Fractional Digits":
                property.ValidationOptions.FractionalDigits = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Future Date":
                property.ValidationOptions.FutureDate = GetNullableBooleanValue(row, cell, newValue, nullableColumn);
                break;

            case "Integer Digits":
                property.ValidationOptions.IntegerDigits = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Max Length":
                property.ValidationOptions.MaximumLength = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Max Value":
                property.ValidationOptions.MaximumValue = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Min Length":
                property.ValidationOptions.MinimumLength = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Min Value":
                property.ValidationOptions.MinimumValue = GetNullableIntValue(row, cell, newValue, nullableColumn);
                break;

            case "Not Empty":
                property.ValidationOptions.NotEmpty = GetNullableBooleanValue(row, cell, newValue, nullableColumn);
                break;

            case "Nullable":
                property.ValidationOptions.Nullable = GetNullableBooleanValue(row, cell, newValue, nullableColumn);
                break;

            case "Past Date":
                property.ValidationOptions.PastDate = GetNullableBooleanValue(row, cell, newValue, nullableColumn);
                break;

            case "Regex":
                if (nullableColumn)
                {
                    if ((bool)slyceGrid1.GetValue(row, cell))
                    {
                        property.ValidationOptions.RegexPattern = (string)slyceGrid1.GetValue(row, cell + 1);
                    }
                    else
                    {
                        property.ValidationOptions.RegexPattern = null;
                    }
                }
                else
                {
                    property.ValidationOptions.RegexPattern = (string)newValue;
                }
                break;

            case "Validate":
                property.ValidationOptions.Validate = newValue == null ? false : bool.Parse(newValue.ToString());
                break;

            default:
                bool found = false;

                foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in property.Ex)
                {
                    if (uo.Text == columnHeader)
                    {
                        found    = true;
                        uo.Value = newValue;
                        break;
                    }
                }
                if (!found)
                {
                    throw new NotImplementedException("Column header not handled yet: " + columnHeader);
                }
                break;
            }
            if (ComponentChanged != null)
            {
                ComponentChanged(ComponentSpecification, null);
            }
        }
        private void slyceGrid1_NewRowAdded(out object newObject)
        {
            ComponentPropertyImpl property = new ComponentPropertyImpl("NewProperty")
            {
                Type = "System.String"
            };
            property.ValidationOptions.FractionalDigits = 0;
            property.ValidationOptions.FutureDate = false;
            property.ValidationOptions.IntegerDigits = 0;
            property.ValidationOptions.MaximumLength = 0;
            property.ValidationOptions.MaximumValue = 0;
            property.ValidationOptions.MinimumLength = 0;
            property.ValidationOptions.MinimumValue = 0;
            property.ValidationOptions.NotEmpty = false;
            property.ValidationOptions.Nullable = false;
            property.ValidationOptions.PastDate = false;
            property.ValidationOptions.RegexPattern = "";
            property.ValidationOptions.Validate = false;

            ComponentSpecification.AddProperty(property);
            newObject = property;

            AddPropertyToPropertiesGrid(property);

            if (ComponentChanged != null)
                ComponentChanged(ComponentSpecification, null);
        }
        private void Populate()
        {
            Slyce.Common.Utility.SuspendPainting(slyceGrid1);
            slyceGrid1.Clear();
            // Populate Columns from Component
            slyceGrid1.Columns.Add(new ColumnItem("Name", ColumnItem.ColumnTypes.Textbox, "NewProp", "General"));
            slyceGrid1.Columns.Add(new ColumnItem("Type", ColumnItem.ColumnTypes.Textbox, "System.String", "General"));

            ComponentPropertyImpl prop = new ComponentPropertyImpl();

            foreach (ArchAngel.Interfaces.ITemplate.IUserOption uo in prop.Ex)
            {
                if (uo.DataType == typeof(bool?))
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.NullableCheckBox, null, "General"));
                else if (uo.DataType == typeof(string))
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"));
                else if (uo.DataType == typeof(int))
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Textbox, null, "General"));
                else if (uo.DataType == typeof(bool))
                    slyceGrid1.Columns.Add(new ColumnItem(uo.Text, ColumnItem.ColumnTypes.Checkbox, null, "General"));
                else
                    throw new NotImplementedException("Type not handled yet: " + uo.DataType.Name);
            }
            #region Validation options
            slyceGrid1.Columns.Add(new ColumnItem("Fractional Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Future Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Integer Digits", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Max Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Min Length", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Max Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Min Value", ColumnItem.ColumnTypes.NullableIntegerInput, 0, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Not Empty", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Nullable", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Past Date", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Regex", ColumnItem.ColumnTypes.NullableTextBox, "", "Validation (optional)"));
            slyceGrid1.Columns.Add(new ColumnItem("Validate", ColumnItem.ColumnTypes.NullableCheckBox, false, "Validation (optional)"));
            #endregion

            foreach (ComponentPropertyImpl property in ComponentSpecification.Properties)
            {
                AddPropertyToPropertiesGrid(property);
            }
            slyceGrid1.Populate();
            Slyce.Common.Utility.ResumePainting(slyceGrid1);
        }
 private SlyceTreeGridCellItem CreateNewNullableCell(ComponentPropertyImpl property, object value, ApplicableOptions options)
 {
     ApplicableOptions applicableOptions = ValidationOptions.GetApplicableValidationOptionsForType(property.Type);
     SlyceTreeGridCellItem cell = new SlyceTreeGridCellItem(value, (applicableOptions & options) != options);
     cell.IsNullable = true;
     return cell;
 }
Beispiel #14
0
        private void ProcessComponent(component hComponent, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults)
        {
            if (hComponent.@class == null)
            {
                log.ErrorFormat("Could not load component named {0} on class {1} because it does not have a class attribute.", hComponent.name, newEntity.Name);
                return;
            }

            var possibleClasses = GetPossibleClasses(hComponent.@class, hmNamespace, mappedTable.Schema, parseResults);

            if (possibleClasses.Count == 0)
            {
                log.ErrorFormat("Could not load component named {0} on class {1} because we could not find the class named {2}.", hComponent.name, newEntity.Name, hComponent.@class);
                return;
            }
            ComponentSpecification spec = null;

            foreach (var possibleClass in possibleClasses)
            {
                spec = specifications.GetValueOrDefault(possibleClass);

                if (spec != null)
                    break;
            }

            bool createProperties = false;

            if (spec == null)
            {
                // Create a new spec from these.
                spec = new ComponentSpecificationImpl(GetShortClassName(hComponent.@class));
                newEntity.EntitySet.AddComponentSpecification(spec);
                createProperties = true;
            }
            Component component = spec.CreateImplementedComponentFor(newEntity, hComponent.name);
            newEntity.Key.Component = component;

            var mapping = new ComponentMappingImpl();

            foreach (var prop in hComponent.Properties())
            {
                if (createProperties)
                {
                    ComponentProperty idProperty = new ComponentPropertyImpl(prop.name);
                    idProperty.Type = prop.type1;
                    idProperty.ValidationOptions.MaximumLength = prop.length.As<int>();
                    SetPropertyInfoFromParsedCode(possibleClasses, idProperty);

                    spec.AddProperty(idProperty);
                }

                var compProperty = component.GetProperty(prop.name);
                var column = mappedTable.GetColumn(prop.column.UnBackTick());
                if (column == null)
                {
                    // Create the column
                    column = entityProcessor.CreateColumn(compProperty.RepresentedProperty);
                    mapping.FromTable.AddColumn(column);
                }

                mapping.AddPropertyAndColumn(compProperty, column);
            }
            newEntity.EntitySet.MappingSet.AddMapping(mapping);
        }
Beispiel #15
0
        private bool ProcessComponentKey(compositeid hCompId, Entity newEntity, ITable mappedTable, Dictionary<Class, ComponentSpecification> specifications, string hmNamespace, ParseResults parseResults)
        {
            var possibleClasses = GetPossibleClasses(hCompId.@class, hmNamespace, mappedTable.Schema, parseResults);

            if (possibleClasses.Count == 0) return false;

            ComponentSpecification spec = null;

            foreach (var possibleClass in possibleClasses)
            {
                spec = specifications.GetValueOrDefault(possibleClass);

                if (spec != null)
                    break;
            }
            bool createProperties = false;

            if (spec == null)
            {
                // Create a new spec from these.
                spec = new ComponentSpecificationImpl(GetShortClassName(hCompId.@class));
                newEntity.EntitySet.AddComponentSpecification(spec);
                createProperties = true;
            }

            Component component = spec.CreateImplementedComponentFor(newEntity, hCompId.name);
            newEntity.Key.Component = component;

            var mapping = new ComponentMappingImpl();

            foreach (var prop in hCompId.KeyProperties())
            {
                if (createProperties)
                {

                    ComponentProperty idProperty = new ComponentPropertyImpl(prop.name);
                    idProperty.Type = prop.type1;
                    idProperty.ValidationOptions.MaximumLength = prop.length.As<int>();
                    SetPropertyInfoFromParsedCode(possibleClasses, idProperty);

                    spec.AddProperty(idProperty);
                }

                var compProperty = component.GetProperty(prop.name);
                var column = mappedTable.GetColumn(prop.column1.UnBackTick());
                if (column == null)
                {
                    // Create the column
                    column = entityProcessor.CreateColumn(compProperty.RepresentedProperty);
                    mapping.FromTable.AddColumn(column);
                }

                mapping.AddPropertyAndColumn(compProperty, column);
            }
            newEntity.EntitySet.MappingSet.AddMapping(mapping);

            return true;
        }