private static void printOutClassesAndMethods(DLLModel dLLModel)
        {
            Console.WriteLine("Inside Here" + dLLModel.getFullyQualifiedPath());
            Dictionary<string, ClassModel> allClassesInDll =
                dLLModel.getAllClassesInThisDll();
            foreach(KeyValuePair<string, ClassModel> pair in allClassesInDll) {
                ClassModel classAtHand = pair.Value;
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("");
                Console.WriteLine("Class ---> " + classAtHand.getClassName());
                Console.WriteLine("");
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("");
                Console.WriteLine("Methods in this class");
                Console.WriteLine("");
                Console.WriteLine("-------------------------------------------");

                SortedList<string, MethodModel> methodsInClass = classAtHand.getAllMethodsInThisClass();
                foreach (KeyValuePair<string, MethodModel> methodPair in methodsInClass)
                {
                    MethodModel methodAtHand = methodPair.Value;
                    Console.WriteLine("  Returns " + methodAtHand.getMethodReturnType() + "-----" + '\t' + methodAtHand.getShortenedName() );
                }
                Console.WriteLine("");
                Console.WriteLine("");
            }
        }
Beispiel #2
0
        public static bool doConfiguration()
        {
            Console.WriteLine("In server mode");
            string dllPath = PropertyUtil.getSelectedDllFile();
            Console.WriteLine("DLL File is : " + dllPath);
            DLLModel dLLAtHand = null;
            if (dllPath != null && dllPath.EndsWith(".dll"))
            {
                dLLAtHand = new DLLModel(dllPath);
                dLLAtHand = dLLAtHand.processDll(dLLAtHand);
            }
            else
            {
                Console.WriteLine("DLL Path information is not properly configured.");
                Environment.Exit(0);
            }

            dLLAtHand = DLLProcessor.populateComplexTypes(dLLAtHand);
            dLLAtHand = DLLProcessor.populateUserSelectedClassesAndMethods(dLLAtHand);

            Assembly assemblyAtHand = new ControllerGenerator().generateControllersAndDll(dLLAtHand);
            if (assemblyAtHand != null)
            {
                generatedAssemblyAtHand = assemblyAtHand;
                dLLAtHand.generateXml();
                return true;
            }

            return false;
        }
 public static void doUserInteraction()
 {
     Console.WriteLine("In User input mode");
     string dllPath = ConfigurationManager.AppSettings["dllFilePath"];
     Console.WriteLine("DLL File is : " + dllPath);
     if (dllPath != null && dllPath.EndsWith(".dll"))
     {
         DLLModel dLLAtHand = new DLLModel(dllPath);
         dLLAtHand = dLLAtHand.processDll(dLLAtHand);
         printOutClassesAndMethods(dLLAtHand);
     }
     else
     {
         Console.WriteLine("DLL Path information is not properly configured.");
     }
 }
        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;
        }
Beispiel #5
0
 public void setDllThisClassBelongsTo(DLLModel dllAtHand)
 {
     this.dllThisClassBelongsTo = dllAtHand;
 }
 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;
 }
        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;
        }
        public DLLModel processDLL(DLLModel dLLAtHand)
        {
            if (!dLLAtHand.isDLLManaged())
            {
                dLLAtHand = convertDLLToManaged(dLLAtHand);
            }

            Console.WriteLine(dLLAtHand.ToString());
            Console.WriteLine(dLLAtHand.getFullyQualifiedPath());
            Assembly dLLAssembly = Assembly.LoadFile(dLLAtHand.getFullyQualifiedPath());

            foreach (Type memberType in dLLAssembly.GetTypes())
            {
                int i = 0;
                if (memberType.IsClass)
                {
                    i++;
                    ClassModel classAtHand = new ClassModel(memberType.FullName);
                    this.extractMethodsFromClass(classAtHand, memberType);
                    classAtHand.setDllThisClassBelongsTo(dLLAtHand);
                    dLLAtHand.getAllClassesInThisDll().Add(classAtHand.getClassName(), classAtHand);
                }
            }

            return dLLAtHand;
        }
 public static DLLModel populateUserSelectedClassesAndMethods(DLLModel dllAtHand)
 {
     string userAddedClassesAndMethods = ConfigurationManager.AppSettings["methodsToAdd"];
     if (userAddedClassesAndMethods == null)
     {
         Console.WriteLine("Incorrect configuration, methodsToAdd property not present.");
         Environment.Exit(0);
     }
     string[] colonSeparatedStrings = userAddedClassesAndMethods.Split(';');
     for (int i = 0; i < colonSeparatedStrings.Length; i++)
     {
         string methodAtHandString = colonSeparatedStrings[i];
         Dictionary<string, ClassModel> classesInDll = dllAtHand.getAllClassesInThisDll();
         foreach (KeyValuePair<string, ClassModel> pair in classesInDll)
         {
             ClassModel classAtHand = pair.Value;
             if (classAtHand.getAllMethodsInThisClass().ContainsKey(methodAtHandString))
             {
                 int indexOfMethodToBeFetched = classAtHand.getAllMethodsInThisClass().IndexOfKey(methodAtHandString);
                 classAtHand.getUserSelectedMethodsInThisClass().Add(methodAtHandString,
                     classAtHand.getAllMethodsInThisClass().ElementAt(indexOfMethodToBeFetched).Value);
                 //Now add this class to the DLL's user selected methods, no duplicates
                 if (!dllAtHand.getUserSelectedClassesInThisDll().ContainsKey(classAtHand.getClassName()))
                 {
                     dllAtHand.getUserSelectedClassesInThisDll().Add(classAtHand.getClassName(), classAtHand);
                 }
             }
         }
     }
     return dllAtHand;
 }
Beispiel #10
0
 public DLLModel processDll(DLLModel dllModel)
 {
     return new DLLProcessor().processDLL(dllModel);
 }
Beispiel #11
0
        public static DLLModel populateUserSelectedClassesAndMethods(DLLModel dllAtHand)
        {
            string userAddedClassesAndMethods = PropertyUtil.getUserSelectedMethods();
            if (userAddedClassesAndMethods == null)
            {
                Console.WriteLine("Incorrect configuration, methodsToAdd property not present.");
                Environment.Exit(0);
            }
            string[] colonSeparatedStrings = userAddedClassesAndMethods.Split(';');
            for (int i = 0; i < colonSeparatedStrings.Length; i++)
            {
                string methodAtHandString = colonSeparatedStrings[i];
                string tmpStringForSplit = new string(methodAtHandString.ToCharArray());
                string[] controllerAndActionAliases = tmpStringForSplit.Split(PropertyUtil.methodAndAliasSeparator);
                Boolean aliasesExist = false;
                string controllerAlias = null;
                string actionAlias = null;

                if (controllerAndActionAliases.Length > 1)
                {
                    //Aliases Exist, time to fetch them
                    aliasesExist = true;
                    string[] individualAliasNames = controllerAndActionAliases[1].Split(PropertyUtil.aliasSeparator);
                    controllerAlias = individualAliasNames[0];
                    actionAlias = individualAliasNames[1];

                    //Lest we pass the method name along with the aliases
                    methodAtHandString = controllerAndActionAliases[0];
                }
                Dictionary<string, ClassModel> classesInDll = dllAtHand.getAllClassesInThisDll();
                foreach (KeyValuePair<string, ClassModel> pair in classesInDll)
                {
                    ClassModel classAtHand = pair.Value;
                    if (classAtHand.getAllMethodsInThisClass().ContainsKey(methodAtHandString))
                    {
                        int indexOfMethodToBeFetched = classAtHand.getAllMethodsInThisClass().IndexOfKey(methodAtHandString);
                        MethodModel methodAtHand = classAtHand.getAllMethodsInThisClass().ElementAt(indexOfMethodToBeFetched).Value;
                        if (aliasesExist)
                        {
                            methodAtHand.setAliasName(actionAlias);
                            classAtHand.setAliasName(controllerAlias);
                        }
                        classAtHand.getUserSelectedMethodsInThisClass().Add(methodAtHandString,
                            methodAtHand);
                        //Now add this class to the DLL's user selected methods, no duplicates
                        if (!dllAtHand.getUserSelectedClassesInThisDll().ContainsKey(classAtHand.getClassName()))
                        {
                            dllAtHand.getUserSelectedClassesInThisDll().Add(classAtHand.getClassName(), classAtHand);
                        }
                    }
                }
            }
            return dllAtHand;
        }