Esempio n. 1
0
 public void DeploySetters(Object output, MetaEntity entity, TypedObjectProvider provider)
 {
     foreach (TypePropertyMapItem item in provider.items)
     {
         if (item.metaProperty == null)
         {
         }
         else
         {
             MetaPropertySetter setter = entity.GetSetter(item.metaProperty.PropertyName);
             if (setter != null)
             {
                 Object setterValue = setter.Value;
                 if (setterValue != null)
                 {
                     if (item.converter != null)
                     {
                         setterValue = item.converter.Convert(setterValue);
                     }
                     SetPropertyValue(item.metaProperty, item.propertyInfo, setterValue, output, true);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public TypedObjectWorkshop(MetaEntityNamespaceCollection namespaces, TypedObjectWorkshopSettings workshopSettings, IDataMiningTypeProvider typeProvider)
        {
            Namespaces   = namespaces;
            TypeProvider = typeProvider;

            foreach (TypedObjectProviderDefinition provider in workshopSettings.providers)
            {
                TypedObjectProvider provider_instance = new TypedObjectProvider(provider);

                MetaEntityClass entityClass = Namespaces.FindClass(provider.EntityClassNamePath);
                provider_instance.Deploy(entityClass, typeProvider);

                ObjectProviders.Add(provider_instance);
            }

            foreach (TypedObjectProvider provider in ObjectProviders)
            {
                foreach (TypePropertyMapDefinitionItem itemDefinition in provider.map.items)
                {
                    PropertyInfo pi = provider.type.GetProperty(itemDefinition.typePropertyName);

                    TypePropertyMapItem mapItem = new TypePropertyMapItem()
                    {
                        metaPropertyName = itemDefinition.metaPropertyName,
                        typePropertyName = itemDefinition.typePropertyName,
                        propertyInfo     = pi
                    };

                    //var IListInterface = pi.PropertyType.GetInterface("IList");

                    //Type[] GenericArguments = pi.PropertyType.GetGenericArguments();

                    //if (GenericArguments.Any())
                    //{

                    //}

                    TypedObjectProvider subentity_provider = GetProviderForType(pi.PropertyType);

                    mapItem.TypeProvider = subentity_provider;

                    IMetaEntityExpressionTarget metaTarget = provider.entityClass.SelectTargetByPath(itemDefinition.metaPropertyName);
                    if (metaTarget is MetaEntityClassProperty metaProperty)
                    {
                        mapItem.metaProperty = metaProperty;
                    }

                    if (itemDefinition.converter != null)
                    {
                        IPropertyItemConverter mapConverter = itemDefinition.converter.GetConverter(pi);
                        mapItem.converter = mapConverter;
                    }

                    provider.items.Add(mapItem);
                }
            }
        }
Esempio n. 3
0
        //  public Dictionary<MetaEntityClass, TypedObjectProvider> ObjectProviderByClassNamepath { get; set; } = new Dictionary<MetaEntityClass, TypedObjectProvider>();


        public TypedObjectProvider GetProviderForEntityClass(MetaEntityClass entityClass)
        {
            TypedObjectProvider output = null;

            foreach (var provider in ObjectProviders)
            {
                if (provider.entityClass == entityClass)
                {
                    if (output == null)
                    {
                        output = provider;
                    }
                    else
                    {
                        if (provider.IsPrimary)
                        {
                            output = provider;
                        }
                    }
                }
            }

            return(output);
        }
Esempio n. 4
0
        /// <summary>
        /// Objects from meta entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="output">The output.</param>
        /// <param name="provider">The provider.</param>
        /// <returns></returns>
        public Object ObjectFromMetaEntity(MetaEntity entity, Object output, TypedObjectProvider provider)
        {
            if (provider == null)
            {
                provider = GetProviderForEntityClass(entity.EntityClassDefinition);
            }

            if (output == null)
            {
                output = provider.type.getInstance(null);
            }

            DeploySetters(output, entity, provider);

            foreach (TypePropertyMapItem item in provider.items)
            {
                if (item.metaPropertyName == ".")
                {
                    Object typeTarget = item.propertyInfo.GetValue(output, null);
                    DeploySetters(typeTarget, entity, item.TypeProvider);
                }
                else
                {
                    if (item.metaProperty.type.HasFlag(MetaEntityClassPropertyType.value))
                    {
                        if (item.metaProperty.type.HasFlag(MetaEntityClassPropertyType.collection))
                        {
                        }
                        else
                        {
                        }
                    }
                    else if (item.metaProperty.type.HasFlag(MetaEntityClassPropertyType.entity))
                    {
                        var subentity = entity.Items.FirstOrDefault(x => x.name == item.metaProperty.name);

                        if (item.metaProperty.type.HasFlag(MetaEntityClassPropertyType.collection))
                        {
                            Object collection = item.propertyInfo.GetValue(output, null);

                            if (collection is IList IListCollection)
                            {
                                foreach (MetaEntity entityItem in subentity.Items)
                                {
                                    Object instanceItem = ObjectFromMetaEntity(entityItem, null, item.TypeProvider);

                                    IListCollection.Add(instanceItem);
                                }
                            }
                        }
                        else
                        {
                            Object subtyped_instance = item.propertyInfo.GetValue(output, null);

                            Object subinstance = ObjectFromMetaEntity(subentity, subtyped_instance, item.TypeProvider);
                            item.propertyInfo.SetValue(output, subinstance, new object[] { });
                        }
                    }
                }
            }

            return(output);
        }