예제 #1
0
        public Assembly generateControllersAndDll(DLLModel dllAtHand)
        {
            IDictionary<string, string> compParams =
                             new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } };
            CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp", compParams);
            string warningText = "Do Not delete contents in this directory.";
            string filePath = ".\\" + dllAtHand.getDllFileName() + "\\readme.txt";
            System.IO.FileInfo file = new System.IO.FileInfo(filePath);
            file.Directory.Create();
            System.IO.File.WriteAllText(file.FullName, warningText);

            string outputDll = ".\\" + dllAtHand.getDllFileName() + "\\" + dllAtHand.getDllFileName() + "_controllers" + ".dll";
            string codeForDllContents = dllAtHand.generateCodeForDllContents();

            System.IO.File.WriteAllText(".\\" + dllAtHand.getDllFileName() + "\\" + dllAtHand.getDllFileName() + ".txt", codeForDllContents);

            System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateExecutable = false;
            parameters.OutputAssembly = outputDll;
            parameters.ReferencedAssemblies.Add(@"System.Net.Http.dll");
            parameters.ReferencedAssemblies.Add(@"System.Net.Http.WebRequest.dll");
            parameters.ReferencedAssemblies.Add(@"System.Net.Http.Formatting.dll");
            parameters.ReferencedAssemblies.Add(@"System.Web.Http.dll");
            parameters.ReferencedAssemblies.Add(PathUtil.getBasePath() + "Newtonsoft.Json.dll");
            parameters.ReferencedAssemblies.Add(PathUtil.getBasePath() + "CoreFramework.dll");

            CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, codeForDllContents);
            if (results.Errors.Count > 0)
            {
                Console.WriteLine("Build Failed");
                foreach (CompilerError CompErr in results.Errors)
                {
                    Console.WriteLine(
                                "Line number " + CompErr.Line +
                                ", Error Number: " + CompErr.ErrorNumber +
                                ", '" + CompErr.ErrorText + ";" +
                                Environment.NewLine + Environment.NewLine);
                }
            }
            else
            {
                Console.WriteLine("Build Succeeded");
                return Assembly.LoadFrom(outputDll);
            }
            return null;
        }
예제 #2
0
 public static DLLModel populateComplexTypes(DLLModel dllAtHand)
 {
     Assembly dLLAssembly = Assembly.LoadFile(dllAtHand.getFullyQualifiedPath());
     IEnumerable<TypeInfo> myTypes = dLLAssembly.DefinedTypes;
     Dictionary<string, ComplexTypeModel> complexTypesInDll = new Dictionary<string, ComplexTypeModel>();
     foreach (TypeInfo typeInfo in myTypes)
     {
         ComplexTypeModel complexTypeAtHand = createComplexModel(typeInfo.FullName, dLLAssembly);
         complexTypeAtHand.setDllFileThisTypeBelongsTo(dllAtHand.getDllFileName());
         complexTypesInDll = dllAtHand.getAllComplexTypesInDLL();
         if (!complexTypesInDll.ContainsKey(complexTypeAtHand.getActualTypeName()))
         {
             complexTypesInDll.Add(complexTypeAtHand.getActualTypeName(), complexTypeAtHand);
         }
     }
     ObjectProcessor.getComplexTypesAcrossDlls().Add(dllAtHand.getDllFileName(), complexTypesInDll);
     return dllAtHand;
 }
예제 #3
0
        private DLLModel convertDLLToManaged(DLLModel dLLModel)
        {
            Object typeLib;
            LoadTypeLibEx(dLLModel.getFullyQualifiedPath(), RegKind.RegKind_None, out typeLib);

            if (typeLib == null)
            {
                Console.WriteLine("LoadTypeLibEx failed.");
            }

            TypeLibConverter converter = new TypeLibConverter();
            ConversionEventHandler eventHandler = new ConversionEventHandler();

            string newDllName = dLLModel.getDllFileName()
                + "_converted.dll";
            AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(typeLib, newDllName, 0, eventHandler, null, null, null, null);

            asm.Save(newDllName);
            DLLModel newdLLModel = new DLLModel(AppDomain.CurrentDomain.BaseDirectory + newDllName);
            return newdLLModel;
        }