protected ICollection <TypeReference> GetExpandedTypeDependanceList(ModuleDefinition module)
        {
            Mono.Collections.Generic.Collection <TypeDefinition> moduleTypes;
            if (!UserDefinedTypes.TryGetValue(module, out moduleTypes))
            {
                throw new Exception("Module types not found.");
            }

            HashSet <TypeReference> firstLevelDependanceTypes = new HashSet <TypeReference>();

            foreach (TypeReference type in moduleTypes)
            {
                if (!firstLevelDependanceTypes.Contains(type))
                {
                    firstLevelDependanceTypes.Add(type);
                }
            }

            foreach (TypeReference type in module.GetTypeReferences())
            {
                if (!firstLevelDependanceTypes.Contains(type))
                {
                    firstLevelDependanceTypes.Add(type);
                }
            }

            return(Telerik.JustDecompiler.Decompiler.Utilities.GetExpandedTypeDependanceList(firstLevelDependanceTypes));
        }
        /// <summary>
        /// Carga los tipos definidos por el usuario
        /// </summary>
        /// <returns>Tables </returns>
        internal UserDefinedTypes LoadUserDefinedTypes()
        {
            DataTable        wDttTypes = null;
            UserDefinedType  wUserDefinedType;
            UserDefinedTypes wUserDefinedTypes = new UserDefinedTypes();
            Tables           wTables           = new Tables();

            try
            {
                wDttTypes           = GetUserDefinedTypesFromDataBase();
                wDttTypes.TableName = "Types";
                foreach (DataRow oDtr in wDttTypes.Rows)
                {
                    wUserDefinedType                  = new UserDefinedType();
                    wUserDefinedType.Name             = oDtr["Name"].ToString();
                    wUserDefinedType.Nullable         = Convert.ToBoolean(oDtr["Nullable"]);
                    wUserDefinedType.Length           = Convert.ToInt32(oDtr["Length"]);
                    wUserDefinedType.NumericPrecision = Convert.ToInt32(oDtr["NumericPrecision"]);
                    wUserDefinedType.Schema           = oDtr["Schema"].ToString();
                    wUserDefinedType.SystemType       = oDtr["SystemType"].ToString();

                    wUserDefinedTypes.Add(wUserDefinedType);
                }


                wDttTypes.Dispose();
                wDttTypes = null;

                OnAddElementEvent();
                return(wUserDefinedTypes);
            }
            catch (Exception ex)
            { throw ex; }
        }
Beispiel #3
0
        static FwkGeneratorHelper()
        {
            roottemplate = Path.Combine(HelperFunctions.ProgramFilesx86(), @"Fwk Software Factory\5.0\FwkTemplates\tt\");
            
            _TemplateDocument = (TemplateDocument)HelperFunctions.DeserializeFromXml(typeof(TemplateDocument), GetFileTemplate("Templates.xml"));
            _MappingTypes = (MappingTypes)HelperFunctions.DeserializeFromXml(typeof(MappingTypes), GetFileTemplate("MappingType.xml"));

            NotSupportTypes_ToIncludeInBackEnd = "xml,timestamp,sql_variant";

            NotSupportTypes_ToSearchInStoreProcedure = "xml,timestamp,sql_variant,varbinary,binary,image";
            NotSupportTypes_ToInsertStoreProcedure = "xml,timestamp,sql_variant";


            _Entity_Envelope_tt = FwkGeneratorHelper.GetFileTemplate("Entity.txt");
            _Entity_Property_TemplateBinary_tt = _TemplateDocument.GetTemplate("Property_Binary").Content;

            _Entity_Property_tt = _TemplateDocument.GetTemplate("Property").Content;

            _Entity_Member_tt = "           private [TYPENAME][NullToken] _[Property_Name];";
            
            UserDefinedTypes = new UserDefinedTypes();






        }
Beispiel #4
0
        static DbTypeToCsType()
        {
            var all = typeof(SqlGeography).Assembly.GetTypes();

            foreach (var item in all)
            {
                var attributes = item.GetCustomAttributes(true);

                if (attributes.Any(f => f is SqlUserDefinedTypeAttribute))
                {
                    UserDefinedTypes.Add(item.Name.Replace("Sql", ""), item);
                }
            }

            SqlDefinedTypes.Add(SqlDbType.BigInt, typeof(long));

            SqlDefinedTypes.Add(SqlDbType.Binary, typeof(byte[]));
            SqlDefinedTypes.Add(SqlDbType.Image, typeof(byte[]));
            SqlDefinedTypes.Add(SqlDbType.Timestamp, typeof(byte[]));
            SqlDefinedTypes.Add(SqlDbType.VarBinary, typeof(byte[]));

            SqlDefinedTypes.Add(SqlDbType.TinyInt, typeof(byte));

            SqlDefinedTypes.Add(SqlDbType.Bit, typeof(bool));

            SqlDefinedTypes.Add(SqlDbType.Char, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.NChar, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.NText, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.NVarChar, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.Text, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.VarChar, typeof(string));
            SqlDefinedTypes.Add(SqlDbType.Xml, typeof(string));

            SqlDefinedTypes.Add(SqlDbType.DateTime, typeof(DateTime));
            SqlDefinedTypes.Add(SqlDbType.SmallDateTime, typeof(DateTime));
            SqlDefinedTypes.Add(SqlDbType.Date, typeof(DateTime));
            SqlDefinedTypes.Add(SqlDbType.Time, typeof(DateTime));
            SqlDefinedTypes.Add(SqlDbType.DateTime2, typeof(DateTime));

            SqlDefinedTypes.Add(SqlDbType.Decimal, typeof(decimal));
            SqlDefinedTypes.Add(SqlDbType.Money, typeof(decimal));
            SqlDefinedTypes.Add(SqlDbType.SmallMoney, typeof(decimal));

            SqlDefinedTypes.Add(SqlDbType.Float, typeof(double));

            SqlDefinedTypes.Add(SqlDbType.Int, typeof(int));

            SqlDefinedTypes.Add(SqlDbType.Real, typeof(float));

            SqlDefinedTypes.Add(SqlDbType.UniqueIdentifier, typeof(Guid));

            SqlDefinedTypes.Add(SqlDbType.SmallInt, typeof(short));

            SqlDefinedTypes.Add(SqlDbType.Variant, typeof(object));
            SqlDefinedTypes.Add(SqlDbType.Udt, typeof(object));

            SqlDefinedTypes.Add(SqlDbType.Structured, typeof(DataTable));
            SqlDefinedTypes.Add(SqlDbType.DateTimeOffset, typeof(DateTimeOffset));
        }
Beispiel #5
0
 public override void Run()
 {
     PrimitivesLineage.RunMe();
     UserDefinedTypes.RunMe();
     Classes.RunMe();
     InterfaceImplementer.RunMe();
     Delegates.RunMe();
     Attributes.RunMe();
 }
Beispiel #6
0
        internal void Initialize(DatabaseModel database)
        {
            Database = database;

            StoredProcedures = database.StoredProcedures.Where(sp => sp.SchemaName == Name).ToList();
            StoredProcedures.ForEach(sp => sp.Initialize(this));

            UserDefinedTypes = database.UserDefinedTypes.Where(sp => sp.SchemaName == Name).ToList();
            UserDefinedTypes.ForEach(udt => udt.Initialize(this));
        }
Beispiel #7
0
        internal static bool TryGetEnumNames(string enumName, out string[] names)
        {
            if (enumName == null || !(UserDefinedTypes.TryGetValue(enumName, out Type type) || AllTypes.TryGetValue(enumName, out type)) || !type.IsEnum)
            {
                names = null;
                return(false);
            }

            names = Enum.GetNames(type).Select(name => type.Name + "." + name).ToArray();
            return(true);
        }
Beispiel #8
0
        public static Type GetClrType(string sqlType)
        {
            SqlDbType result;
            var       resultState = Enum.TryParse(sqlType, true, out result);

            if (!resultState)
            {
                return(UserDefinedTypes.FirstOrDefault(s => s.Key.ToLower() == sqlType).Value);
            }
            return(SqlDefinedTypes[result]);
        }
Beispiel #9
0
        static FwkGeneratorHelper()
        {
            roottemplate = Path.Combine(HelperFunctions.ProgramFilesx86(), @"Fwk Software Factory\5.0\FwkTemplates\tt\");

            _TemplateDocument = (TemplateDocument)HelperFunctions.DeserializeFromXml(typeof(TemplateDocument), GetFileTemplate("Templates.xml"));
            _MappingTypes     = (MappingTypes)HelperFunctions.DeserializeFromXml(typeof(MappingTypes), GetFileTemplate("MappingType.xml"));

            NotSupportTypes_ToIncludeInBackEnd = "xml,timestamp,sql_variant";

            NotSupportTypes_ToSearchInStoreProcedure = "xml,timestamp,sql_variant,varbinary,binary,image";
            NotSupportTypes_ToInsertStoreProcedure   = "xml,timestamp,sql_variant";


            _Entity_Envelope_tt = FwkGeneratorHelper.GetFileTemplate("Entity.txt");
            _Entity_Property_TemplateBinary_tt = _TemplateDocument.GetTemplate("Property_Binary").Content;

            _Entity_Property_tt = _TemplateDocument.GetTemplate("Property").Content;

            _Entity_Member_tt = "           private [TYPENAME][NullToken] _[Property_Name];";

            UserDefinedTypes = new UserDefinedTypes();
        }
Beispiel #10
0
        /// <summary>
        /// Carga los tipos definidos por el usuario
        /// </summary>
        /// <returns>Tables </returns>
        internal UserDefinedTypes LoadUserDefinedTypes()
        {

            DataTable wDttTypes = null;
            UserDefinedType wUserDefinedType;
            UserDefinedTypes wUserDefinedTypes = new UserDefinedTypes();
            Tables wTables = new Tables();
            try
            {
                wDttTypes = GetUserDefinedTypesFromDataBase();
                wDttTypes.TableName = "Types";
                foreach (DataRow oDtr in wDttTypes.Rows)
                {
                    wUserDefinedType = new UserDefinedType();
                    wUserDefinedType.Name = oDtr["Name"].ToString();
                    wUserDefinedType.Nullable = Convert.ToBoolean(oDtr["Nullable"]);
                    wUserDefinedType.Length = Convert.ToInt32(oDtr["Length"]);
                    wUserDefinedType.NumericPrecision = Convert.ToInt32(oDtr["NumericPrecision"]);
                    wUserDefinedType.Schema = oDtr["Schema"].ToString();
                    wUserDefinedType.SystemType = oDtr["SystemType"].ToString();
                    
                    wUserDefinedTypes.Add(wUserDefinedType);
                }


                wDttTypes.Dispose();
                wDttTypes = null;

                OnAddElementEvent();
                return wUserDefinedTypes;

            }
            catch (Exception ex)
            { throw ex; }

        }
        protected virtual void WriteUserDefinedTypes(ModuleDefinition module, Func <bool> shouldCancel)
        {
            Mono.Collections.Generic.Collection <TypeDefinition> moduleTypes;

            if (!UserDefinedTypes.TryGetValue(module, out moduleTypes))
            {
                throw new Exception("Module types not found.");
            }

            ProjectItemWriterFactory writerFactory =
                new ProjectItemWriterFactory(this.assembly, moduleTypes, this.projectFileManager, this.filePathsService, this.language.VSCodeFileExtension, this.targetDir);

#if !NET35
            CancellationTokenSource cts = new CancellationTokenSource();

            ParallelOptions parallelOptions = new ParallelOptions()
            {
                CancellationToken = cts.Token, MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            try
            {
                Parallel.ForEach(
                    moduleTypes,
                    parallelOptions,
                    (TypeDefinition type) =>
                {
                    try
                    {
                        if (shouldCancel())
                        {
                            cts.Cancel();
                            return;
                        }

                        IProjectItemFileWriter itemWriter = writerFactory.GetProjectItemWriter(type);

                        bool shouldBeXamlPartial = Utilities.ShouldBePartial(type) || this.projectFileManager.XamlFullNameToRelativePathMap.ContainsKey(type.FullName);

                        if (shouldBeXamlPartial)
                        {
                            string typeName = type.FullName;
                            if (this.xamlGeneratedFields.ContainsKey(typeName))
                            {
                                this.xamlGeneratedFields[typeName].Add("_contentLoaded");                                         // Always present, not bound to any XAML element
                            }
                            else
                            {
                                this.xamlGeneratedFields.Add(typeName, new HashSet <string>(new string[1] {
                                    "_contentLoaded"
                                }));                                                                                                                                     // Always present, not bound to any XAML element
                            }
                        }

                        List <WritingInfo> writingInfos;
                        string theCodeString;
                        bool exceptionsWhileDecompiling = WriteTypeToFile(type, itemWriter, this.xamlGeneratedFields, shouldBeXamlPartial,
                                                                          language, out writingInfos, out theCodeString);
                        bool exceptionsWhileWriting = HasExceptionsWhileWriting(writingInfos);

                        lock (writeTypesLock)
                        {
                            itemWriter.GenerateProjectItems();

                            Dictionary <MemberIdentifier, CodeSpan> mapping = null;
                            if (this.fileGeneratedNotifier != null)
                            {
                                /// Create the mapping only when it's needed for the internal API.
                                mapping = GenerateMemberMapping(this.assemblyPath, theCodeString, writingInfos);
                            }

                            IUniqueMemberIdentifier uniqueMemberIdentifier = new UniqueMemberIdentifier(module.FilePath, type.MetadataToken.ToInt32());
                            IFileGeneratedInfo args = new TypeGeneratedInfo(itemWriter.FullSourceFilePath, exceptionsWhileDecompiling, exceptionsWhileWriting, uniqueMemberIdentifier, mapping);
                            this.OnProjectFileCreated(args);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.OnTypeWritingFailure(type.FullName, ex);

                        if (this.projectNotifier != null)
                        {
                            this.projectNotifier.OnTypeWritingFailure(type.FullName, ex);
                        }
                    }
                });
            }
            catch (OperationCanceledException e)
            {
            }
#else
            for (int typeIndex = 0; typeIndex < moduleTypes.Count; typeIndex++)
            {
                if (shouldCancel())
                {
                    return;
                }
                TypeDefinition type = moduleTypes[typeIndex];
                try
                {
                    IProjectItemFileWriter itemWriter = writerFactory.GetProjectItemWriter(type);
                    bool shouldBeXamlPartial          = Utilities.ShouldBePartial(type) || this.projectFileManager.XamlFullNameToRelativePathMap.ContainsKey(type.FullName);
                    if (shouldBeXamlPartial)
                    {
                        string typeName = type.FullName;
                        if (xamlGeneratedFields.ContainsKey(typeName))
                        {
                            xamlGeneratedFields[typeName].Add("_contentLoaded");                            //Always present, not bound to any XAML element
                        }
                        else
                        {
                            xamlGeneratedFields.Add(typeName, new HashSet <string>(new string[1] {
                                "_contentLoaded"
                            }));                                                                                                                   //Always present, not bound to any XAML element
                        }
                    }
                    List <WritingInfo> writingInfos;
                    string             typeCode;
                    bool exceptionsWhileDecompiling = WriteTypeToFile(type, itemWriter, xamlGeneratedFields, shouldBeXamlPartial,
                                                                      language, out writingInfos, out typeCode);
                    bool exceptionsWhileWriting = HasExceptionsWhileWriting(writingInfos);
                    itemWriter.GenerateProjectItems();
                    Dictionary <MemberIdentifier, CodeSpan> mapping = GenerateMemberMapping(this.assemblyPath, typeCode, writingInfos);

                    IUniqueMemberIdentifier uniqueMemberIdentifier = new UniqueMemberIdentifier(module.FilePath, type.MetadataToken.ToInt32());
                    IFileGeneratedInfo      args = new TypeGeneratedInfo(itemWriter.FullSourceFilePath, exceptionsWhileDecompiling, exceptionsWhileWriting, uniqueMemberIdentifier, mapping);
                    this.OnProjectFileCreated(args);
                }
                catch (Exception ex)
                {
                    if (TypeWritingFailure != null)
                    {
                        TypeWritingFailure(this, type.FullName, ex);
                    }
                }
            }
#endif
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pCnnString"></param>
 public UserDefinedTypesBack(string pCnnString)
     : base(pCnnString)
 {
     _UserDefinedTypes         = new UserDefinedTypes();
     _GetUserDefinedTypesQuery = GetQuery();
 }
Beispiel #13
0
 internal static bool IsEnum(string enumName)
 {
     return(enumName != null && (UserDefinedTypes.TryGetValue(enumName, out Type type) || AllTypes.TryGetValue(enumName, out type)) &&
            type.IsEnum && Enum.GetValues(type).Length > 0);
 }
Beispiel #14
0
        /// <summary>
        /// Carga el atributo UserDefinedTypes 
        /// </summary>
        public void LoadUserDefinedTypes()
        {
            UserDefinedTypesBack wUserDefinedTypesBack = new UserDefinedTypesBack(_DataBaseServer.CnnString.ToString());
            _UserDefinedTypes = wUserDefinedTypesBack.LoadUserDefinedTypes();

        }
Beispiel #15
0
 /// <summary>
 /// Constructor 
 /// </summary>
 /// <param name="pCnnString"></param>
 public UserDefinedTypesBack(string pCnnString)
     : base(pCnnString)
 {
     _UserDefinedTypes = new UserDefinedTypes();
     _GetUserDefinedTypesQuery = GetQuery();
 }
Beispiel #16
0
        /// <summary>
        /// Carga el atributo UserDefinedTypes
        /// </summary>
        public void LoadUserDefinedTypes()
        {
            UserDefinedTypesBack wUserDefinedTypesBack = new UserDefinedTypesBack(_DataBaseServer.CnnString.ToString());

            _UserDefinedTypes = wUserDefinedTypesBack.LoadUserDefinedTypes();
        }