Exemple #1
0
        public void CreateCompiler_ReturnsSame()
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.Same(provider.CreateCompiler(), provider.CreateCompiler());
#pragma warning restore 0618
        }
Exemple #2
0
		public void Deny_Unrestricted ()
		{
			VBCodeProvider vbprov = new VBCodeProvider ();
			Assert.AreEqual ("vb", vbprov.FileExtension, "FileExtension");
			Assert.AreEqual (LanguageOptions.CaseInsensitive, vbprov.LanguageOptions, "LanguageOptions");
			Assert.IsNotNull (vbprov.CreateCompiler (), "CreateCompiler");
			Assert.IsNotNull (vbprov.CreateGenerator (), "CreateGenerator");
			try {
				Assert.IsNotNull (vbprov.GetConverter (typeof (string)), "GetConverter");
			}
			catch (NotImplementedException) {
				// mono
			}
#if NET_2_0
			CodeTypeMember ctm = new CodeTypeMember ();
			StringWriter sw = new StringWriter ();
			CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
			try {
				vbprov.GenerateCodeFromMember (ctm, sw, cgo);
			}
			catch (NotImplementedException) {
				// mono
			}
#endif
		}
Exemple #3
0
        public void Ctor_IDictionaryStringString(IDictionary<string, string> providerOptions)
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.NotNull(provider.CreateGenerator());
            Assert.Same(provider.CreateGenerator(), provider.CreateCompiler());
#pragma warning restore 0618
        }
Exemple #4
0
        public void Ctor_Default()
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.NotNull(provider.CreateGenerator());
            Assert.Same(provider.CreateGenerator(), provider.CreateCompiler());
#pragma warning restore 0618
        }
Exemple #5
0
		static TestUtilities()
		{
			cSharpCompiler = new CSharpCodeProvider();
			compiler = cSharpCompiler.CreateCompiler();
			compileParameters = new CompilerParameters();

			vbCompilerProvider = new VBCodeProvider();
			vbCompiler = vbCompilerProvider.CreateCompiler();
			vbCompileParameters = new CompilerParameters();
		}
        private static CompilerResults CompileVBScripts(ICollection fileColl,
														string assemblyFile,
														LibraryConfig libConfig,
														bool debug)
        {
            VBCodeProvider provider = new VBCodeProvider();
            ICodeCompiler compiler = provider.CreateCompiler();

            string[] files = new string[fileColl.Count];
            fileColl.CopyTo(files, 0);

            Console.Write("{0}[VB,{1}", libConfig.Name, files.Length);

            CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files );

            m_AdditionalReferences.Add(assemblyFile);

            if ( results.Errors.Count > 0 )
            {
                int errorCount = 0, warningCount = 0;

                foreach ( CompilerError e in results.Errors )
                {
                    if ( e.IsWarning )
                        ++warningCount;
                    else
                        ++errorCount;
                }

                Console.WriteLine();
                if ( errorCount > 0 )
                    Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount );
                else
                    Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount );

                foreach ( CompilerError e in results.Errors )
                {
                    Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText );
                }
            }
            else
            {
                Console.Write("] ");
            }

            return results;
        }
        private void CompileRunningVB()
        {
            string name2 = name;
            if (name == "") name2 = "DotNetProcessing.Running";
            else name2 = name2 + "Sketch";

            // Generamos DotNetProcessing.Running.dll
            VBCodeProvider vbCompiler;
            ICodeCompiler iCodeCompiler;
            CompilerParameters compilerParams;
            CompilerResults cr;

            vbCompiler = new VBCodeProvider();
            iCodeCompiler = vbCompiler.CreateCompiler();

            compilerParams = new CompilerParameters();
            compilerParams.OutputAssembly = apppath + name2 + ".dll";
            compilerParams.ReferencedAssemblies.Add("System.dll");
            compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
            compilerParams.ReferencedAssemblies.Add("System.Core.dll");
            compilerParams.ReferencedAssemblies.Add("System.Drawing.dll");
            compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            compilerParams.ReferencedAssemblies.Add(apppath + "DotNetProcessing.Kernel.dll");
            compilerParams.ReferencedAssemblies.Add(apppath + "DotNetProcessing.AbstractRunning.dll");
            compilerParams.GenerateExecutable = false;
            cr = iCodeCompiler.CompileAssemblyFromFile(compilerParams, apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");

            if( cr.Errors.Count > 0 )
            {
                string er = "";
                for( int i=0; i<cr.Errors.Count; i++ )
                {
                    StreamReader srerrors = File.OpenText(apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");
                    for (int j=0; j<cr.Errors[i].Line-1; j++) srerrors.ReadLine();
                    er = er + "ERROR:\t" + cr.Errors[i].ErrorText + "\r\n" + "LINE:\t" + srerrors.ReadLine().Trim() + "\r\nCOLUMN:\t" + cr.Errors[i].Column + "\r\n\r\n";
                    srerrors.Close();
                }
                try
                {
                DelFileWrapper(apppath + "Input.pde");
                DelFileWrapper(apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");
                }
                catch
                {}
                throw new DNPParseException(er);
            }
        }
		private static CompilerResults CompileVBScripts(ICollection fileColl,
														string assemblyFile,
														Config.Library libConfig,
														bool debug) {
			VBCodeProvider provider = new VBCodeProvider();
			ICodeCompiler compiler = provider.CreateCompiler();

			string[] files = new string[fileColl.Count];
			fileColl.CopyTo(files, 0);

			log.InfoFormat("Compiling library {0}, {1} C# sources",
						   libConfig.Name, files.Length);

			CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files );

			m_AdditionalReferences.Add(assemblyFile);

			if ( results.Errors.Count > 0 )
			{
				int errorCount = 0, warningCount = 0;

				foreach ( CompilerError e in results.Errors )
				{
					if ( e.IsWarning )
						++warningCount;
					else
						++errorCount;
				}

				if ( errorCount > 0 )
					log.ErrorFormat("Compilation failed ({0} errors, {1} warnings)",
									errorCount, warningCount);
				else
					log.InfoFormat("Compilation complete ({0} warnings)", warningCount);

				foreach ( CompilerError e in results.Errors )
				{
					String msg = String.Format("{0}: {1}: (line {2}, column {3}) {4}",
											   e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText);
					if (e.IsWarning)
						log.Warn(msg);
					else
						log.Error(msg);
				}
			}
			else
			{
				log.Info("Compilation complete");
			}

			return results;
		}
Exemple #9
0
        static void Main(string[] args)
        {
            // Prompt for target language.
            Console.Write("Do you want to generate C# or VB .NET code? ");
            syntaxTarget = Console.ReadLine();

            // Get ICodeGenerator interface.
            switch(syntaxTarget.ToUpper())
            {
                case "C#":
                case "CSharp":
                case "CS":
                    syntaxTarget = "cs";
                    CSharpCodeProvider cdp = new CSharpCodeProvider();
                    itfCG = cdp.CreateGenerator();
                    itfCC = cdp.CreateCompiler();
                break;
                case "VB .NET":
                case "VB.NET":
                case "VB":
                    syntaxTarget = "vb";
                    VBCodeProvider vbdp = new VBCodeProvider();
                    itfCG = vbdp.CreateGenerator();
                    itfCC = vbdp.CreateCompiler();
                break;
                default:
                    Console.WriteLine("Sorry...can't do it...");
                    syntaxTarget = null;
                break;
            }

            // Only proceed if they picked a valid language
            // supported by System.CodeDOM.
            if(syntaxTarget != null)
            {
                // Now create the file and generate the code!
                TextWriter txtWriter = CreateFile(syntaxTarget);
                PopulateNamespace(itfCG, txtWriter);
                txtWriter.Close();
                Console.WriteLine("Done!");

                // Now compile the code into a .NET DLL.
                Console.WriteLine("Compiling code...");
                CompileCode(itfCC, syntaxTarget);

                // Now launch the application!
                Console.Write("Enter your message: ");
                string msg = Console.ReadLine();
                LoadAndRunAsm(msg);
                Console.WriteLine("Thanks for playing...");
            }
        }
Exemple #10
0
			public string CompileAssemblyFromDomBatch (string tempDir)
			{
				CompilerParameters options = new CompilerParameters ();
				options.GenerateExecutable = false;
				options.GenerateInMemory = false;
				options.TempFiles = new TempFileCollection (tempDir);

				VBCodeProvider codeProvider = new VBCodeProvider ();
				ICodeCompiler compiler = codeProvider.CreateCompiler ();
				CompilerResults results = compiler.CompileAssemblyFromDomBatch (options, new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });

				// verify compilation was successful
				AssertCompileResults (results, true);

				if (results.CompiledAssembly.Location.Length == 0)
					throw new Exception ("Location should not be empty string");
				if (results.PathToAssembly == null)
					throw new Exception ("PathToAssembly should not be null");

				return results.PathToAssembly;
			}
			public string CompileAssemblyFromDom (string tempDir)
			{
				CompilerParameters options = new CompilerParameters ();
				options.GenerateExecutable = false;
				options.GenerateInMemory = false;
				options.TempFiles = new TempFileCollection (tempDir);

				VBCodeProvider codeProvider = new VBCodeProvider ();
				ICodeCompiler compiler = codeProvider.CreateCompiler ();
				CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());

				// verify compilation was successful
				AssertCompileResults (results, true);

				Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
					"Location should not be empty string");
				Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");

				return results.PathToAssembly;
			}
		private static CompilerResults CompileVBScripts(bool debug)
		{
			VBCodeProvider provider = new VBCodeProvider();
			ICodeCompiler compiler = provider.CreateCompiler();

			Console.Write("Scripts: Compiling VB.net scripts...");
			string[] files = GetScripts("*.vb");

			if (files.Length == 0)
			{
				Console.WriteLine("no files found.");
				return null;
			}

			string path = GetUnusedPath("Scripts.VB");

			CompilerResults results = compiler.CompileAssemblyFromFileBatch(new CompilerParameters(GetReferenceAssemblies(), path, true), files);

			m_AdditionalReferences.Add(path);

			if (results.Errors.Count > 0)
			{
				int errorCount = 0, warningCount = 0;

				foreach (CompilerError e in results.Errors)
				{
					if (e.IsWarning)
						++warningCount;
					else
						++errorCount;
				}

				if (errorCount > 0)
					Console.WriteLine("failed ({0} errors, {1} warnings)", errorCount, warningCount);
				else
					Console.WriteLine("done ({0} errors, {1} warnings)", errorCount, warningCount);

				foreach (CompilerError e in results.Errors)
				{
					Console.WriteLine(" - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText);
				}
			}
			else
			{
				Console.WriteLine("done (0 errors, 0 warnings)");
			}

			return results;
		}