Exemplo n.º 1
0
        public static string ResultsxCompletionMessage(
            AcCompilerParameters InParms, CompilerResults InResults)
        {
            string msg      = null;
            string fileName = null;

            // the name of the source file
            if (InParms.SourceLines != null)
            {
                fileName = "";
            }
            else
            {
                fileName = InParms.SourceFileInfo.Name;
            }

            if (InResults.Errors.Count == 0)
            {
                if (InParms.GenerateInMemory == true)
                {
                    msg =
                        "Source " + fileName +
                        " built into memory resident assembly";
                }
                else
                {
                    msg = "Source " + fileName +
                          " built into " + InResults.PathToAssembly;
                }
            }
            else
            {
                msg = "Errors building " + fileName;
            }
            return(msg);
        }
Exemplo n.º 2
0
 public new void SetCompilerParameters(AcCompilerParameters InParms)
 {
     base.SetCompilerParameters(InParms);
 }
Exemplo n.º 3
0
        Compile_Actual(
            string InSourcePath,
            string InSourceLines,
            ExecutableType InExecType,
            GenerateAssemblyIn InGenerateIn,
            List <string> InAddnReferencedAssemblies,
            CompilerVersion CompilerVersion
            )
        {
            System.Reflection.Assembly assem = null;
            List <string>   results          = new List <string>();
            CodeDomProvider provider         = null;
            // Microsoft.CSharp.CSharpCodeProvider provider = null;
            string               exeName = null;
            WipCompilerResults   wipCr   = new WipCompilerResults();
            AcCompilerParameters cp      = new AcCompilerParameters();

            // compile from lines in a source array or source file
            if (InSourceLines != null)
            {
                cp.SourceLines = InSourceLines;
            }
            else
            {
                cp.SourceFileInfo = new FileInfo(InSourcePath);
            }

            // Select the code provider based on the input file extension.
            if (cp.SourceLines != null)
            {
                Dictionary <string, string> provOpts =
                    new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v3.5" }
                };
                provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts);
//        provider = CodeDomProvider.CreateProvider("CSharp");
            }
            else if (cp.SourceFileInfo.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS")
            {
                Dictionary <string, string> provOpts =
                    new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v3.5" }
                };
                provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts);
//        provider = CodeDomProvider.CreateProvider("CSharp");
            }
            else
            {
                results.Add("Source file must have a .cs or .vb extension");
            }

            if (provider != null)
            {
                //  type of executable: Windows, Console, ClassLibrary
                cp.ExecutableType     = InExecType;
                cp.GenerateAssemblyIn = InGenerateIn;

                // setup name and path of the executable file to be created.
                if (cp.GenerateAssemblyIn == GenerateAssemblyIn.File)
                {
                    if (cp.ExecutableType == ExecutableType.ClassLibrary)
                    {
                        exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".dll";
                    }
                    else
                    {
                        exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".exe";
                    }
                    string exePath = AcFilePath.AddTo(cp.SourceFileInfo.DirectoryName, exeName);
                    cp.OutputAssembly = exePath;
                }

                // Set whether to treat all warnings as errors.
                cp.TreatWarningsAsErrors = false;
                cp.ReferencedAssemblies.Add("System.Dll");
                cp.ReferencedAssemblies.Add("System.Drawing.Dll");
                cp.ReferencedAssemblies.Add("System.Xml.Dll");
                cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");

                // additional assemblies
                foreach (string s1 in InAddnReferencedAssemblies)
                {
                    cp.ReferencedAssemblies.Add(s1);
                }

                // Invoke compilation of the source file.
                CompilerResults cr = null;
                if (cp.SourceLines != null)
                {
                    cr = provider.CompileAssemblyFromSource(cp, cp.SourceLines);
                }
                else
                {
                    cr = provider.CompileAssemblyFromFile(cp, cp.SourceFileInfo.FullName);
                }
                wipCr.SetCompilerResults(cr);
                wipCr.SetCompilerParameters(cp);

                // completion message
                results.Add(wipCr.CompletionMessage);

                if (wipCr.Errors.Count > 0)
                {
                    foreach (CompilerError ce in wipCr.Errors)
                    {
                        results.Add("   " + ce.ToString());
                    }
                }

                // Return the results of the compilation.
                if (wipCr.Errors.Count > 0)
                {
                    assem = null;
                }

                else
                {
                    assem = wipCr.CompiledAssembly;
                }
            }
            return(wipCr);
        }
Exemplo n.º 4
0
 protected void SetCompilerParameters(AcCompilerParameters InParms)
 {
     mParms = InParms;
 }