private void CompileMissingTypes(IList <GeneratedTypesInfo> typesInfo)
        {
            // Compiling missing classes
            if (typesInfo.Any(s => s.CompilationNeeded))
            {
                var codeGenerationBuilder = new CodeGenerationBuilder(_dataProviderContext.ProviderName + ":DataId and helper classes");
                var codeBuilder           = new XmlDataProviderCodeBuilder(_dataProviderContext.ProviderName, codeGenerationBuilder);

                foreach (var storeToLoad in typesInfo.Where(s => s.CompilationNeeded))
                {
                    codeBuilder.AddDataType(storeToLoad.DataTypeDescriptor);

                    // Compiling some other classes for optimization
                    DataWrapperCodeGenerator.AddDataWrapperClassCode(codeGenerationBuilder, storeToLoad.DataTypeDescriptor);
                    EmptyDataClassCodeGenerator.AddEmptyDataClassTypeCode(codeGenerationBuilder, storeToLoad.DataTypeDescriptor);
                }

                var types = CodeGenerationManager.CompileRuntimeTempTypes(codeGenerationBuilder, false).ToDictionary(type => type.FullName);

                foreach (var storeToLoad in typesInfo.Where(s => s.CompilationNeeded))
                {
                    storeToLoad.DataIdClass             = types[storeToLoad.DataIdClassName];
                    storeToLoad.DataProviderHelperClass = types[storeToLoad.DataProviderHelperClassName];
                }
            }
        }
Exemplo n.º 2
0
        internal static Type GetFileBuilderNewHandler(Type dataType)
        {
            Type result;

            if (!_fileBuildNewHandlerTypes.TryGetValue(dataType, out result))
            {
                lock (_lock)
                {
                    if (!_fileBuildNewHandlerTypes.TryGetValue(dataType, out result))
                    {
                        DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(dataType);

                        string fullName = EmptyDataClassCodeGenerator.GetEmptyClassTypeFullName(dataTypeDescriptor);

                        result = TypeManager.TryGetType(fullName);

                        if (result == null)
                        {
                            CodeAttributeDeclaration codeAttributeDeclaration = new CodeAttributeDeclaration(
                                new CodeTypeReference(typeof(FileStreamManagerAttribute)),
                                new [] {
                                new CodeAttributeArgument(new CodeTypeOfExpression(typeof(IFileEmptyDataClassFileStreamManager)))
                            });

                            result = EmptyDataClassTypeManager.CreateEmptyDataClassType(dataTypeDescriptor, typeof(IFileEmptyDataClassBase), codeAttributeDeclaration);
                        }

                        _fileBuildNewHandlerTypes.Add(dataType, result);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        internal static Type CreateEmptyDataClassType(DataTypeDescriptor dataTypeDescriptor, Type baseClassType = null, CodeAttributeDeclaration codeAttributeDeclaration = null)
        {
            CodeGenerationBuilder codeGenerationBuilder = new CodeGenerationBuilder("EmptyDataClass: " + dataTypeDescriptor.Name);

            EmptyDataClassCodeGenerator.AddAssemblyReferences(codeGenerationBuilder, dataTypeDescriptor);
            EmptyDataClassCodeGenerator.AddEmptyDataClassTypeCode(codeGenerationBuilder, dataTypeDescriptor, baseClassType, codeAttributeDeclaration);

            IEnumerable <Type> types = CodeGenerationManager.CompileRuntimeTempTypes(codeGenerationBuilder);

            return(types.Single());
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method will return the type of the empty data class type.
        /// If the type does not exist, one will be runtime code generated
        /// using the <paramref name="dataTypeDescriptor"/>.
        /// </summary>
        /// <param name="dataTypeDescriptor">
        /// The data type descriptor for the data type to get
        /// the empty class type for.
        /// </param>
        /// <param name="forceReCompilation">
        /// If this is true a new empty class will be
        /// compiled at runtime regardless if it exists or not.
        /// Use with caution!
        /// </param>
        /// <returns>The empty class type for the given data interface type.</returns>
        public static Type GetEmptyDataClassType(DataTypeDescriptor dataTypeDescriptor, bool forceReCompilation = false)
        {
            if (!string.IsNullOrEmpty(dataTypeDescriptor.BuildNewHandlerTypeName))
            {
                return(GetEmptyClassFromBuildNewHandler(dataTypeDescriptor));
            }


            if (forceReCompilation)
            {
                return(CreateEmptyDataClassType(dataTypeDescriptor));
            }

            Type interfaceType = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());

            string emptyClassFullName = EmptyDataClassCodeGenerator.GetEmptyClassTypeFullName(dataTypeDescriptor);
            Type   emptyClassType     = TypeManager.TryGetType(emptyClassFullName);

            bool isRecompileNeeded = true;

            if (interfaceType != null)
            {
                isRecompileNeeded = CodeGenerationManager.IsRecompileNeeded(interfaceType, new[] { emptyClassType });
            }

            if (isRecompileNeeded)
            {
                lock (_lock)
                {
                    interfaceType  = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
                    emptyClassType = TypeManager.TryGetType(emptyClassFullName);
                    if (interfaceType != null)
                    {
                        isRecompileNeeded = CodeGenerationManager.IsRecompileNeeded(interfaceType, new[] { emptyClassType });
                    }

                    if (isRecompileNeeded)
                    {
                        emptyClassType = CreateEmptyDataClassType(dataTypeDescriptor);
                    }
                }
            }

            return(emptyClassType);
        }