示例#1
0
        internal static Type TryGetType(DataTypeDescriptor dataTypeDescriptor, bool forceReCompilation, out bool codeGenerationNeeded)
        {
            Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor");
            codeGenerationNeeded = false;

            Type type;

            if (!forceReCompilation)
            {
                type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
                if (type != null) return type;

                if (!dataTypeDescriptor.IsCodeGenerated)
                {
                    type = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName);
                    if (type != null) return type;
                }
            }

            if (!dataTypeDescriptor.IsCodeGenerated)
            {
                return null;
            }

            if (forceReCompilation)
            {
                type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
                if (type != null) return type;
            }

            codeGenerationNeeded = true;
            return null;
        }
示例#2
0
        /// <summary>
        /// This method will return type given by the dataTypeDescriptor.
        /// If the data type does not exist, one will be dynamically
        /// runtime code generated.
        /// </summary>
        /// <param name="dataTypeDescriptor"></param>
        /// <param name="forceReCompilation">If this is true a new type will be compiled regardless if one already exists.</param>
        /// <returns></returns>
        public static Type GetType(DataTypeDescriptor dataTypeDescriptor, bool forceReCompilation = false)
        {
            bool codeGenerationNeeded;

            Type type = TryGetType(dataTypeDescriptor, forceReCompilation, out codeGenerationNeeded);
            if (type != null)
            {
                return type;
            }

            if (codeGenerationNeeded)
            {
                lock (_lock)
                {
                    type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
                    if (type != null) return type;

                    var codeGenerationBuilder = new CodeGenerationBuilder("DataInterface: " + dataTypeDescriptor.Name);
                    InterfaceCodeGenerator.AddAssemblyReferences(codeGenerationBuilder, dataTypeDescriptor);
                    InterfaceCodeGenerator.AddInterfaceTypeCode(codeGenerationBuilder, dataTypeDescriptor);

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

                    return types.Single();
                }
            }

            return null;
        }
示例#3
0
        public static Type GetDataWrapperType(DataTypeDescriptor dataTypeDescriptor)
        {
            Type wrapperType = TryGetWrapperType(dataTypeDescriptor.GetFullInterfaceName());
            if (wrapperType != null) return wrapperType;

            lock (_lock)
            {
                wrapperType = TryGetWrapperType(dataTypeDescriptor.GetFullInterfaceName());
                if (wrapperType != null) return wrapperType;

                var codeGenerationBuilder = new CodeGenerationBuilder("DataWrapper:" + dataTypeDescriptor.GetFullInterfaceName());

                DataWrapperCodeGenerator.AddDataWrapperClassCode(codeGenerationBuilder, dataTypeDescriptor);

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

                return types.Single();
            }
        }
示例#4
0
        /// <summary>
        /// Gets the runtime data type for the given data type id.
        /// In case of generated types, this call might result in a interface code compilation.
        /// </summary>
        /// <param name="dataTypeDescriptor">
        /// The DataTypeDescriptor for the data type.
        /// </param>
        /// <returns>Returns the data type. Never null.</returns>
        public static Type GetDataType(DataTypeDescriptor dataTypeDescriptor)
        {
            Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor");

            Type loadedDataType = _LoadedDataTypes.FirstOrDefault(f => f.FullName == dataTypeDescriptor.GetFullInterfaceName());
            if (loadedDataType != null) return loadedDataType;

            Type type = InterfaceCodeManager.GetType(dataTypeDescriptor);

            return type;
        }
        private static CodeTypeDeclaration CreateCodeTypeDeclaration(DataTypeDescriptor dataTypeDescriptor)
        {
            string fullName = dataTypeDescriptor.GetFullInterfaceName();

            IEnumerable<Tuple<string, Type, bool>> properties =
                dataTypeDescriptor.Fields.
                Select(f => new Tuple<string, Type, bool>(f.Name, f.InstanceType, f.IsReadOnly)).
                Concat(new[] { new Tuple<string, Type, bool>("DataSourceId", typeof(DataSourceId), true) });

            return CreateCodeTypeDeclaration(fullName, properties);
        }
        /// <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;
        }
示例#7
0
        internal static string GenerateTableName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, CultureInfo cultureInfo)
        {
            string tableName = dataTypeDescriptor.GetFullInterfaceName().Replace('.', '_');

            switch (dataScope.Name)
            {
                case DataScopeIdentifier.PublicName:
                    break;
                case DataScopeIdentifier.AdministratedName:
                    tableName += "_Unpublished";
                    break;
                default:
                    throw new InvalidOperationException("Unsupported data scope identifier: '{0}'".FormatWith(dataScope.Name));
            }

            if (!cultureInfo.Name.IsNullOrEmpty())
            {
                tableName += "_" + cultureInfo.Name.Replace('-', '_').Replace(' ', '_');
            }

            return tableName;
        }
        private static string GetTempFileName(DataTypeDescriptor typeDescriptor)
        {
            string folderPath = PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory);

            string filePath = Path.Combine(folderPath, typeDescriptor.GetFullInterfaceName() + ".cs");
            if (filePath.Length > 255)
            {
                filePath = Path.Combine(folderPath, typeDescriptor.DataTypeId + ".cs");
            }

            return filePath;
        }
 internal static string GetEmptyClassTypeFullName(DataTypeDescriptor dataTypeDescriptor)
 {
     return NamespaceName + "." + CreateClassName(dataTypeDescriptor.GetFullInterfaceName());
 }
示例#10
0
 internal static string MakeWrapperClassName(DataTypeDescriptor dataTypeDescriptor)
 {
     return string.Format("{0}Wrapper", dataTypeDescriptor.GetFullInterfaceName().Replace('.', '_').Replace('+', '_'));
 }
示例#11
0
 private static string MakeNiceTypeFullName(DataTypeDescriptor dataTypeDescriptor)
 {
     return dataTypeDescriptor.GetFullInterfaceName().Replace('.', '_').Replace('+', '_');
 }
示例#12
0
 internal static string GenerateTableName(DataTypeDescriptor dataTypeDescriptor)
 {
     return dataTypeDescriptor.GetFullInterfaceName().Replace('.', '_');
 }