public void ApplyChanges(MappingSet mappingSet, EntityKey key)
        {
            // Create new Component
            var component = existingSpecToUse.CreateImplementedComponentFor(key.Parent, newComponentName);

            // Set mapped column on the new Component's properties.
            foreach (var pair in propertyMappings)
            {
                var newProperty = component.GetProperty(pair.Key);
                var oldProperty = key.Properties.FirstOrDefault(p => p.Name == pair.Value);

                if (oldProperty == null)
                {
                    // Something went horribly wrong. We have a Property that has been mapped,
                    // but it doesn't actually exist. I am chosing to ignore this here, but log it.
                    log.ErrorFormat("Property {0} was mapped in the ConvertKeyToComponent wizard, but doesn't actually exist in the model.", pair.Value);
                    continue;
                }

                newProperty.SetMappedColumn(oldProperty.MappedColumn());
            }

            // Delete existing properties if needed.
            if (deleteExistingProperties)
            {
                foreach (var property in key.Properties.ToList())
                {
                    property.DeleteSelf();
                }
            }

            key.Component = component;
        }
        public void Setup()
        {
            database  = new Database("Db1");
            entitySet = new EntitySetImpl();

            table = new Table("Table1");
            table.AddColumn(new Column("AddressStreet"));

            var entity1 = new EntityImpl("Entity1");

            componentSpec = new ComponentSpecificationImpl("Address");
            entitySet.AddComponentSpecification(componentSpec);
            componentSpec.AddProperty(new ComponentPropertyImpl("Street"));

            component1 = componentSpec.CreateImplementedComponentFor(entity1, "HomeAddress");
            component2 = componentSpec.CreateImplementedComponentFor(entity1, "WorkAddress");

            database.AddTable(table);
            entitySet.AddEntity(entity1);
        }
        void form_AddNewUsage(object sender, Slyce.Common.GenericEventArgs <Entity> e)
        {
            if (Detached)
            {
                return;
            }
            if (e.Object == null)
            {
                throw new ArgumentNullException("e");
            }

            spec.CreateImplementedComponentFor(e.Object, spec.Name + "_New");
        }
예제 #4
0
        public void Setup()
        {
            set = new MappingSetImpl();
            entity = new EntityImpl("Entity1");
            set.EntitySet.AddEntity(entity);
            table = new Table("Table1");
            table.AddColumn(new Column("Street"));
            set.Database.AddTable(table);

            spec = new ComponentSpecificationImpl("Address");
            spec.AddProperty(new ComponentPropertyImpl("Street"));
            set.EntitySet.AddComponentSpecification(spec);

            component = spec.CreateImplementedComponentFor(entity, "HomeAddress");
            set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]);
        }
        public void Setup()
        {
            set    = new MappingSetImpl();
            entity = new EntityImpl("Entity1");
            set.EntitySet.AddEntity(entity);
            table = new Table("Table1");
            table.AddColumn(new Column("Street"));
            set.Database.AddTable(table);

            spec = new ComponentSpecificationImpl("Address");
            spec.AddProperty(new ComponentPropertyImpl("Street"));
            set.EntitySet.AddComponentSpecification(spec);

            component = spec.CreateImplementedComponentFor(entity, "HomeAddress");
            set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]);
        }
        public void Setup()
        {
            // Setup Database
            database = new Database("DB1");
            var table = new Table("User");

            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("AddressStreet"));
            table.AddColumn(new Column("AddressCity"));
            table.AddColumn(new Column("AddressCountry"));
            database.AddTable(table);

            // Setup Entities
            entitySet = new EntitySetImpl();
            Entity userEntity = new EntityImpl("User");

            userEntity.AddProperty(new PropertyImpl("Name"));

            // Create the Address type
            spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.AddProperty(new ComponentPropertyImpl("City"));
            spec.AddProperty(new ComponentPropertyImpl("Country"));

            // Create the Address component for the User entity.
            component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress");

            entitySet.AddEntity(userEntity);
            entitySet.AddComponentSpecification(spec);

            // Setup the Mappings
            mappingSet       = new MappingSetImpl(database, entitySet);
            componentMapping = new ComponentMappingImpl();
            mappingSet.AddMapping(componentMapping);

            componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]);
            componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]);
            componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]);

            // Add the mapping between the Name property and the Name column in the database table.
            mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]);
        }
예제 #7
0
        public Component DeserialiseComponent(XmlNode componentNode, ComponentSpecification spec)
        {
            var proc = new NodeProcessor(componentNode);

            string parentName   = proc.Attributes.GetString("parent-type");
            var    parentEntity = spec.EntitySet.GetEntity(parentName);

            if (parentEntity == null)
            {
                throw new DeserialisationException(string.Format("Could not find parent type {0} of component", parentName));
            }

            string componentName = proc.Attributes.GetString("name");

            Component component = spec.CreateImplementedComponentFor(parentEntity, componentName);

            ProcessScriptBase(component, componentNode);

            return(component);
        }
예제 #8
0
        public void Setup()
        {
            // Setup Database
            database = new Database("DB1");
            var table = new Table("User");
            table.AddColumn(new Column("Name"));
            table.AddColumn(new Column("AddressStreet"));
            table.AddColumn(new Column("AddressCity"));
            table.AddColumn(new Column("AddressCountry"));
            database.AddTable(table);

            // Setup Entities
            entitySet = new EntitySetImpl();
            Entity userEntity = new EntityImpl("User");
            userEntity.AddProperty(new PropertyImpl("Name"));

            // Create the Address type
            spec = new ComponentSpecificationImpl("Address");

            spec.AddProperty(new ComponentPropertyImpl("Street"));
            spec.AddProperty(new ComponentPropertyImpl("City"));
            spec.AddProperty(new ComponentPropertyImpl("Country"));

            // Create the Address component for the User entity.
            component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress");

            entitySet.AddEntity(userEntity);
            entitySet.AddComponentSpecification(spec);

            // Setup the Mappings
            mappingSet = new MappingSetImpl(database, entitySet);
            componentMapping = new ComponentMappingImpl();
            mappingSet.AddMapping(componentMapping);

            componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]);
            componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]);
            componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]);

            // Add the mapping between the Name property and the Name column in the database table.
            mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]);
        }
 private void comboBoxExEntities_SelectedIndexChanged(object sender, EventArgs e)
 {
     Entity = (Entity)comboBoxExEntities.SelectedItem;
     ComponentSpecification.CreateImplementedComponentFor(Entity, textBoxComponentName.Text);
     Populate();
 }
        private bool Save()
        {
            if (Entity == null)
                return false;

            if (ComponentSpecification == null)
            {
                MessageBox.Show(this, "No component selected.", "Component missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component = ComponentSpecification.GetImplementationFor(Entity);

            if (component == null)
            {
                // Create a new mapping
                component = ComponentSpecification.CreateImplementedComponentFor(Entity, textBoxComponentName.Text);
            }
            component.Name = textBoxComponentName.Text;
            List<Column> columns = GetColumnsOfType(Entity, "xxx");
            int numTables = Entity.MappedTables().Count();

            for (int i = 0; i < ComponentSpecification.Properties.Count; i++)
            {
                if (ComboBoxes[i].SelectedItem != null)
                {
                    Column col = null;
                    string selectedName = ComboBoxes[i].SelectedItem.ToString();

                    if (numTables > 1)
                    {
                        foreach (Column c in columns)
                        {
                            if (string.Format("{0}.{1}  [{2}]", c.Parent.Name, c.Name, c.OriginalDataType) == selectedName)
                            {
                                col = c;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (Column c in columns)
                        {
                            if (string.Format("{0}  [{1}]", c.Name, c.OriginalDataType) == selectedName)
                            {
                                col = c;
                                break;
                            }
                        }
                    }
                    if (col == null)
                        throw new Exception("Column shouldn't be null");

                    component.Properties[i].SetMappedColumn(col);
                }
                else
                {
                    component.Properties[i].SetMappedColumn(null);
                }
            }
            return true;
        }