예제 #1
0
        private static Dictionary <Type, IBuiltComponentMapping> GetSub_RG_EHN_EH_Model()
        {
            var cmSub = new ComponentMapping <Subscription>("Subscription")
                        .WithKey(s => s.Name);
            var cmRG = new ComponentMapping <ResourceGroup>("ResourceGroup")
                       .WithKey(rg => rg.Name)
                       .WithModelledHierarchyReference(rg => rg.Subscription, ModelledReferenceDirection.Child);
            var cmEHN = new ComponentMapping <EventHubNamespace>("EventHubNamespace")
                        .WithKey(ehn => ehn.Name)
                        .WithTags(e => e.Tags)
                        .WithModelledHierarchyReference(ehn => ehn.ResourceGroup, ModelledReferenceDirection.Child)
                        .WithModelledHierarchyReference(ehn => ehn.EventHubs, ModelledReferenceDirection.Parent);
            var cmEH = new ComponentMapping <EventHub>("EventHub")
                       .WithKey(eh => eh.Name);

            var mappings = new Dictionary <Type, IBuiltComponentMapping>
            {
                [typeof(Subscription)]      = cmSub,
                [typeof(ResourceGroup)]     = cmRG,
                [typeof(EventHubNamespace)] = cmEHN,
                [typeof(EventHub)]          = cmEH
            };

            return(mappings);
        }
        private void SetupForm()
        {
            if (Detached)
            {
                return;
            }

            form.Clear();

            form.SetProperties(component.Properties);
            form.ComponentName = component.Name;

            if (component.ParentEntity != null)
            {
                form.SetParentEntity(component.ParentEntity.Name);
                form.SetPossibleColumns(component.ParentEntity.MappedTables().SelectMany(t => t.Columns));
            }

            ComponentMapping mapping = component.Mapping();

            if (mapping != null)
            {
                form.SetMappings(mapping.Mappings);
            }

            form.SetVirtualProperties(component.Ex);
        }
예제 #3
0
        public void ShouldWriteComponentForComponentMapping()
        {
            var mapping = new ComponentMapping();

            writer.VerifyXml(mapping)
            .RootElement.HasName("component");
        }
예제 #4
0
        private void ProcessFields(object importRow, Item newItem, ComponentMapping mapping)
        {
            //add in the field mappings
            List <IBaseField> fieldDefs = GetComponentFieldDefinitionsByRow(importRow, mapping);

            ProcessFields(importRow, newItem, fieldDefs);
        }
예제 #5
0
        private PropertyMapping GetPropertyMapping(Type type, Member property, ComponentMapping component)
        {
            var mapping = new PropertyMapping
            {
                ContainingEntityType = type,
                Member = property
            };

            var columnName = property.Name;

            if (component != null)
            {
                columnName = expressions.GetComponentColumnPrefix(component.Member) + columnName;
            }

            mapping.AddDefaultColumn(new ColumnMapping {
                Name = columnName
            });

            if (!mapping.IsSpecified("Name"))
            {
                mapping.Name = mapping.Member.Name;
            }

            if (!mapping.IsSpecified("Type"))
            {
                mapping.SetDefaultValue("Type", GetDefaultType(property));
            }

            return(mapping);
        }
예제 #6
0
        private unsafe Auto <DisposableImageView> CreateSwapchainImageView(Image swapchainImage, VkFormat format)
        {
            var componentMapping = new ComponentMapping(
                ComponentSwizzle.R,
                ComponentSwizzle.G,
                ComponentSwizzle.B,
                ComponentSwizzle.A);

            var aspectFlags = ImageAspectFlags.ImageAspectColorBit;

            var subresourceRange = new ImageSubresourceRange(aspectFlags, 0, 1, 0, 1);

            var imageCreateInfo = new ImageViewCreateInfo()
            {
                SType            = StructureType.ImageViewCreateInfo,
                Image            = swapchainImage,
                ViewType         = ImageViewType.ImageViewType2D,
                Format           = format,
                Components       = componentMapping,
                SubresourceRange = subresourceRange
            };

            _gd.Api.CreateImageView(_device, imageCreateInfo, null, out var imageView).ThrowOnError();
            return(new Auto <DisposableImageView>(new DisposableImageView(_gd.Api, _device, imageView)));
        }
예제 #7
0
        private unsafe ImageView CreateImageView()
        {
            Device device = _renderer.Params.Device;
            AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer();
            Vk vk = _renderer.Vk;

            ImageViewCreateInfo imageViewCreateInfo = new()
            {
                SType = StructureType.ImageViewCreateInfo,

                Image    = _image,
                ViewType = ImageViewType.ImageViewType2D,
                Format   = _format,

                SubresourceRange = new ImageSubresourceRange()
                {
                    AspectMask     = ImageAspectFlags.ImageAspectColorBit,
                    BaseArrayLayer = 0,
                    LayerCount     = 1,
                    BaseMipLevel   = 0,
                    LevelCount     = _mipLevelCount
                },
                Components = new ComponentMapping()
                {
                    R = ComponentSwizzle.Identity,
                    G = ComponentSwizzle.Identity,
                    B = ComponentSwizzle.Identity,
                    A = ComponentSwizzle.Identity
                }
            };

            _renderer.AssertVulkan(vk.CreateImageView(device, imageViewCreateInfo, allocator, out ImageView imageView));
            return(imageView);
        }
예제 #8
0
        protected List <IComponentMapping> GetComponentDefinitions(Item i)
        {
            List <IComponentMapping> d = new List <IComponentMapping>();

            //check for templates folder
            Item temps = i.GetChildByTemplate(ComponentsFolderTemplateID);

            if (temps.IsNull())
            {
                Logger.Log($"there is no 'Components' folder on '{i.DisplayName}'", i.Paths.FullPath);
                return(d);
            }

            //check for any children
            if (!temps.HasChildren)
            {
                Logger.Log($"there are no component mappings to import on '{i.DisplayName}'", i.Paths.FullPath);
                return(d);
            }

            ChildList c = temps.Children;

            foreach (Item child in c)
            {
                //create an item to get the class / assembly name from
                ComponentMapping cm = new ComponentMapping(child);
                cm.FieldDefinitions = GetFieldDefinitions(child);

                d.Add(cm);
            }

            return(d);
        }
        public override void ProcessComponent(ComponentMapping mapping)
        {
            var conventions = finder.Find <IComponentConvention>();

            Apply <IComponentInspector, IComponentInstance>(conventions,
                                                            new ComponentInstance(mapping));
        }
        public void ShouldWriteComponentForComponentMapping()
        {
            var mapping = new ComponentMapping();

            writer.VerifyXml(mapping)
                .RootElement.HasName("component");
        }
 public ComponentInspector(ComponentMapping mapping)
     : base(mapping)
 {
     this.mapping = mapping;
     mappedProperties.AutoMap();
     mappedProperties.Map(x => x.LazyLoad, x => x.Lazy);
 }
예제 #12
0
        protected TemplateMapping GetComponentTemplateMapping(Item item, ComponentMapping mapping)
        {
            string tID = item.TemplateID.ToString();

            return((mapping.TemplateMappingDefinitions.ContainsKey(tID))
                                ? mapping.TemplateMappingDefinitions[tID]
                                : null);
        }
        public void LinkBySearch_FindsSeveralObjectsAlreadyHasRefs_CreatedExpectedReferences()
        {
            // Arrange
            var refName = "uses";
            var refType = 99;

            var employeeNumber     = "A221133";
            var countryComponentId = "country-1";

            var mapping = new ComponentMapping <Employee>("Employee").WithKey(emp => emp.EmployeeNumber);
            var service = GetService(mapping, refName);

            var searchBuilder = GetSearchBuilder();
            var employee      = new Employee {
                Name = "Magnus Carlsen", Age = 28, EmployeeNumber = employeeNumber
            };
            var employeeComponent = new Component(employeeNumber, null, null)
            {
                Type = "Employee"
            };

            var countryComponent1 = new Component("Norway", null, null)
            {
                Id = countryComponentId
            };
            var countryComponent2 = new Component("Sweden", null, null)
            {
                Id = "swe"
            };
            var countryComponent3 = new Component("Denmark", null, null)
            {
                Id = "dk"
            };
            IEnumerable <Component> searchResComponents = new List <Component> {
                countryComponent1, countryComponent2, countryComponent3
            };

            _searcherMock.Setup(s => s.Search(It.IsAny <SearchSpec>()))
            .Returns(Task.FromResult(searchResComponents));

            ParentChildRelation parentChildRelation = new ParentChildRelation(null, employee);

            _sessionMock.Setup(s => s.GetChildComponent(parentChildRelation))
            .Returns(employeeComponent);
            _sessionMock.Setup(s => s.GetReferenceTypeForName(refName))
            .Returns(refType);

            _sessionMock.Setup(s => s.GetAllSourceReferencesFromChild(parentChildRelation))
            .Returns(new List <Reference>());

            // Act
            service.LinkBySearch(searchBuilder, new List <ParentChildRelation> {
                parentChildRelation
            });

            // Assert
            _sessionMock.Verify(s => s.AddReference(refType, employeeComponent, It.IsAny <Component>()), Times.Exactly(3));
        }
예제 #14
0
        public void ShouldWriteSets()
        {
            var mapping = new ComponentMapping(ComponentType.Component);

            mapping.AddCollection(new SetMapping());

            writer.VerifyXml(mapping)
            .Element("set").Exists();
        }
예제 #15
0
        public DomainMapping <TClass> MapComponent <TComponent>(Expression <Func <TClass, TComponent> > expression, Action <ComponentMapping <TClass, TComponent> > mapping)
        {
            var component = new ComponentMapping <TClass, TComponent>(expression);

            mapping(component);

            this.subMappings.Add(component);
            return(this);
        }
        public void ShouldWriteManyToOnes()
        {
            var mapping = new ComponentMapping();

            mapping.AddReference(new ManyToOneMapping());

            writer.VerifyXml(mapping)
            .Element("many-to-one").Exists();
        }
예제 #17
0
        public void ShouldWriteComponents()
        {
            var mapping = new ComponentMapping(ComponentType.DynamicComponent);

            mapping.AddComponent(new ComponentMapping(ComponentType.Component));

            writer.VerifyXml(mapping)
            .Element("component").Exists();
        }
        private IBuiltComponentMapping GetMappingWithSameReferenceType(string componentType = "MyType", string rootComponentName = "Employees")
        {
            var mapping = new ComponentMapping <Employee>(componentType);

            mapping.WithReference(emp => emp.EmployedIn, "test_ref");
            mapping.WithReference(emp => emp.Roles, "test_ref");
            mapping.WithPreexistingHierarchyReference(rootComponentName);
            return(mapping);
        }
        public void ShouldWriteOneToOnes()
        {
            var mapping = new ComponentMapping();

            mapping.AddOneToOne(new OneToOneMapping());

            writer.VerifyXml(mapping)
            .Element("one-to-one").Exists();
        }
        public void ShouldWriteAnys()
        {
            var mapping = new ComponentMapping();

            mapping.AddAny(new AnyMapping());

            writer.VerifyXml(mapping)
            .Element("any").Exists();
        }
        public void ShouldWriteBags()
        {
            var mapping = new ComponentMapping(ComponentType.Component);

            mapping.AddCollection(CollectionMapping.Bag());

            writer.VerifyXml(mapping)
            .Element("bag").Exists();
        }
        public void ShouldWriteLists()
        {
            var mapping = new ComponentMapping();

            mapping.AddCollection(new ListMapping());

            writer.VerifyXml(mapping)
            .Element("list").Exists();
        }
        public void ShouldWriteDynamicComponents()
        {
            var mapping = new ComponentMapping();

            mapping.AddComponent(new DynamicComponentMapping());

            writer.VerifyXml(mapping)
            .Element("dynamic-component").Exists();
        }
예제 #24
0
        public void ShouldWriteLists()
        {
            var mapping = new ComponentMapping(ComponentType.DynamicComponent);

            mapping.AddCollection(CollectionMapping.List());

            writer.VerifyXml(mapping)
            .Element("list").Exists();
        }
        public void ShouldWriteProperties()
        {
            var mapping = new ComponentMapping();

            mapping.AddProperty(new PropertyMapping());

            writer.VerifyXml(mapping)
            .Element("property").Exists();
        }
예제 #26
0
        protected override ComponentMapping CreateComponentMappingRoot(AttributeStore store)
        {
            var componentMappingRoot = new ComponentMapping(ComponentType.Component, store)
            {
                ContainingEntityType = entity,
            };

            componentMappingRoot.Set(x => x.Class, Layer.Defaults, new TypeReference(typeof(T)));
            return(componentMappingRoot);
        }
예제 #27
0
        public void RemoveMapping(ComponentMapping mapping)
        {
            if (componentMappings.Remove(mapping))
            {
                mapping.MappingSet = null;
            }

            CacheInvalid = true;
            RaisePropertyChanged("ComponentMappings");
        }
예제 #28
0
        public void UpdateComponentTags_TagExistsButDoesNotReferenceComponent_UpdatesTag()
        {
            // Arrange
            var ehNamespaceName = "my-namespace";
            var tagString       = "tag1";
            var componentType   = "EventHubNamespace";
            var m = new ComponentMapping <EventHubNamespace>(componentType)
                    .WithKey(rg => rg.Name)
                    .WithTags(e => e.Tags)
                    .WithPreexistingHierarchyReference("EventHubs");

            var mappings = new Dictionary <Type, IBuiltComponentMapping>
            {
                [typeof(EventHubNamespace)] = m
            };

            var ehn = new EventHubNamespace
            {
                Name = ehNamespaceName,
                Tags = new List <string> {
                    tagString
                }
            };

            var relations = new List <ParentChildRelation> {
                new ParentChildRelation(null, ehn)
                {
                    PreexistingHierarchyReference = "EventHubs"
                }
            };

            var builder   = new ParentChildRelationHierarchyBuilder(mappings);
            var hierarchy = builder.BuildRelationHierarchies(relations).First();

            var existingTag = new Tag(tagString, null, null)
            {
                Components = new List <string> {
                    "tag2"
                }
            };
            var session = Helper.GetSession(null, null, new List <Tag> {
                existingTag
            });

            session.AddComponent(ehNamespaceName, null, componentType, null);

            var maintainer = new ComponentHierarchyMaintainer(mappings, session);

            // Act
            var c = maintainer.UpdateComponentTags(hierarchy);

            // Assert
            Assert.Equal(2, existingTag.Components.Count);
            Assert.Equal(1, c);
        }
        public void GetTags_NoAccessorSetup_ReturnsNull()
        {
            // Arrange
            var mapping = new ComponentMapping <EventHubNamespace>(null);

            // Act
            var tags = mapping.GetTags(new EventHubNamespace());

            // Assert
            Assert.Null(tags);
        }
        public void WithTags_GetterBasedWithGetterAlreadyDefined_ThrowsArgumentException()
        {
            // Arrange
            var mapping = new ComponentMapping <EventHubNamespace>(null)
                          .WithTags(enh => enh.Tags);

            // Act & Assert
            var ex = Assert.Throws <ArgumentException>(() => mapping.WithTags(Tags.FromExpression <EventHubNamespace>(ns => ns.TagMap.Select(p => $"{p.Key}::{p.Value}"))));

            Assert.Equal("Tag getter already defined.", ex.Message);
        }
예제 #31
0
        public void AddMapping(ComponentMapping mapping)
        {
            if (componentMappings.Contains(mapping))
            {
                return;
            }

            componentMappings.Add(mapping);
            mapping.MappingSet = this;
            CacheInvalid       = true;
            RaisePropertyChanged("ComponentMappings");
        }
        public void ReferenceSetup_WithFirstModelledThenPreexisting_ThrowsInvalidOperationException()
        {
            // Arrange
            var mapping = new ComponentMapping <EventHubNamespace>(null);

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => mapping
                                                               .WithModelledHierarchyReference(eh => eh.ResourceGroup, ModelledReferenceDirection.Child)
                                                               .WithPreexistingHierarchyReference("Namespace"));

            Assert.Equal("Can only configure a single reference where the class is the child.", ex.Message);
        }
예제 #33
0
        public void Map(ClassMappingBase classMap, Member property)
        {
            var mapping = new ComponentMapping(ComponentType.Component)
            {
                Name = property.Name,
                Member = property,
                ContainingEntityType = classMap.Type,
                Type = property.PropertyType
            };

            mapper.FlagAsMapped(property.PropertyType);
            mapper.MergeMap(property.PropertyType, mapping, new List<Member>());

            classMap.AddComponent(mapping);
        }
예제 #34
0
        public void Map(ClassMappingBase classMap, PropertyInfo property)
        {
            var mapping = new ComponentMapping
            {
                Name = property.Name,
                PropertyInfo = property,
                ContainingEntityType = classMap.Type,
                Type = property.PropertyType
            };

            mapper.FlagAsMapped(property.PropertyType);
            mapper.MergeMap(property.PropertyType, mapping, new List<string>());

            classMap.AddComponent(mapping);
        }
예제 #35
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            var mapping = new ComponentMapping(ComponentType.Component)
            {
                Name = member.Name,
                Member = member,
                ContainingEntityType = classMap.Type,
                Type = member.PropertyType,
                ColumnPrefix = cfg.GetComponentColumnPrefix(member)
            };

            if (member.IsProperty && !member.CanWrite)
                mapping.Access = cfg.GetAccessStrategyForReadOnlyProperty(member).ToString();

            mapper.FlagAsMapped(member.PropertyType);
            mapper.MergeMap(member.PropertyType, mapping, new List<Member>());

            classMap.AddComponent(mapping);
        }
예제 #36
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]);
        }
 public object Write(ComponentMapping mappingModel)
 {
     return _componentWriter.Write(mappingModel);
 }
 public ComponentInstance(ComponentMapping mapping)
     : base(mapping)
 {
     this.mapping = mapping;
     nextBool = true;
 }
 public void OptimisticLockShouldDefaultToTrue()
 {
     var mapping = new ComponentMapping();
     mapping.OptimisticLock.ShouldBeTrue();
 }
 public void LazyShouldDefaultToFalse()
 {
     var mapping = new ComponentMapping();
     mapping.Lazy.ShouldBeFalse();
 }
 public string SerialiseComponentMapping(ComponentMapping mapping)
 {
     return Serialise(writer => SerialiseComponentMappingInternal(mapping, writer));
 }
예제 #42
0
        public void RemoveMapping(ComponentMapping mapping)
        {
            if (componentMappings.Remove(mapping))
            {
                mapping.MappingSet = null;
            }

            CacheInvalid = true;
            RaisePropertyChanged("ComponentMappings");
        }
 public void InsertShouldDefaultToTrue()
 {
     var mapping = new ComponentMapping();
     mapping.Insert.ShouldBeTrue();
 }
 public void UniqueShouldDefaultToFalse()
 {
     var mapping = new ComponentMapping();
     mapping.Unique.ShouldBeFalse();
 }
 public void SetUp()
 {
     mappingSet = new MappingSetImpl();
     mapping = new ComponentMappingImpl();
     mappingSet.AddMapping(mapping);
 }
 public void SetUp()
 {
     mapping = new ComponentMappingImpl();
 }
        private void SerialiseComponentMappingInternal(ComponentMapping mapping, XmlWriter writer)
        {
            if (mapping.FromTable == null)
                throw new ArgumentNullException("mapping", "mapping.FromTable cannot be null");
            if (mapping.ToComponent == null)
                throw new ArgumentNullException("mapping", "mapping.ToComponent cannot be null");
            if (mapping.ToComponent.Specification == null)
                throw new ArgumentNullException("mapping", "mapping.ToComponent.Specification cannot be null");
            if (mapping.ToComponent.ParentEntity == null)
                throw new ArgumentNullException("mapping", "mapping.ToComponent.ParentEntity cannot be null");
            if (mapping.ToProperties == null)
                throw new ArgumentException("ToProperties in Mapping cannot be null");
            if (mapping.FromColumns == null)
                throw new ArgumentException("FromColumns in Mapping cannot be null");
            if (mapping.FromColumns.Count <= 0)
                throw new ArgumentException("FromColumns in Mapping cannot be empty");
            if (mapping.ToProperties.Count <= 0)
                throw new ArgumentException("ToProperties in Mapping cannot be empty");

            WriterHelper document = new WriterHelper(writer);

            using (document.Element("ComponentMapping"))
            {
                writer.WriteElementString("FromTable", mapping.FromTable.Name);
                writer.WriteElementString("FromSchema", mapping.FromTable.Schema);

                using (document.Element("ToComponent"))
                {
                    writer.WriteAttributeString("specification", mapping.ToComponent.Specification.Name);
                    writer.WriteAttributeString("parent-entity", mapping.ToComponent.ParentEntity.Name);
                    writer.WriteAttributeString("name", mapping.ToComponent.Name);
                }

                using (document.Element("FromColumns"))
                    foreach (var column in mapping.FromColumns)
                        writer.WriteElementString("Column", column.Name);

                using (document.Element("ToProperties"))
                    foreach (var property in mapping.ToProperties)
                        writer.WriteElementString("Property", property.RepresentedProperty.Name);

                ProcessScriptBase(mapping, writer);
            }
        }
 public void UpdateShouldDefaultToTrue()
 {
     var mapping = new ComponentMapping();
     mapping.Update.ShouldBeTrue();
 }
예제 #49
0
 public DynamicComponentInspector(ComponentMapping mapping)
     : base(mapping)
 {
     this.mapping = mapping;
 }
예제 #50
0
        public void AddMapping(ComponentMapping mapping)
        {
            if (componentMappings.Contains(mapping))
                return;

            componentMappings.Add(mapping);
            mapping.MappingSet = this;
            CacheInvalid = true;
            RaisePropertyChanged("ComponentMappings");
        }