Пример #1
0
 private void setupSources(BooCompiler compiler, ViewCompilerInfo info) {
     compiler.Parameters.Input.Clear();
     foreach (var source in info.Sources) {
         var input = new StringInput(source.Key, source.GetContent());
         compiler.Parameters.Input.Add(input);
     }
 }
Пример #2
0
        public override Assembly Compile(ViewCompilerInfo info) {
			lock(this) {
				var log = myapp.QorpentApplication.LogManager.GetLog(this.GetType().FullName + ";MvcHandler", this);
				try {
					if (AllInMemory) info.InMemory = true;
					initCompiler(info);
					setupPipeline(compiler, info);
					setupParameters(compiler, info);
					setupSources(compiler, info);
					var cunit = new CompileUnit();
					cunit["sources"] = info.Sources;
					var result = compiler.Run(cunit);
					this.LastResult = result;
					if (result.Errors.Count != 0 && !info.ProcessingTest) {
						throw new Exception(result.Errors.ToString(true));
					}
					if (!info.ProcessingTest) {
						return result.GeneratedAssembly;
					}
					return null;
				}catch(Exception ex) {
					log.Error("",new BrailCompilerException(info,ex),this);
					throw;
				}
			}

        }
Пример #3
0
        private void setupAssemblies(BooCompiler compiler, ViewCompilerInfo info) {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
                if(assembly.IsDynamic) continue;
				if(!compiler.Parameters.References.Contains(assembly)) {
					compiler.Parameters.References.Add(assembly);
				}
            }
        }
Пример #4
0
 public Type CompileSingle(ViewCodeSource source, ViewEngineOptions options) {
     var info = new ViewCompilerInfo
                    {
                        AssemblyName = Guid.NewGuid().ToString(),
                        InMemory = true,
                        Sources = new[] {source},
                        Options =  options,
                    };
     var assembly = this.Compile(info);
     return assembly.GetType(source.Key.Replace("/","_0_"));
 }
Пример #5
0
 public Assembly CompileApplication(ViewEngineOptions options) {
     var resolver = (BrailSourceResolver)Resolver ?? new BrailSourceResolver();
     var sources = resolver.GetAll();
     var assemblyname = "_application_views";
     var targetdirectory = resolver.FileSystem.Resolve("~/tmp/", false);
     var info = new ViewCompilerInfo
                    {
                        AssemblyName = assemblyname,
                        Sources = sources,
                        TargetDirecrtory = targetdirectory,
                        InMemory = false,
                        Options =  options,
                    };
     if(!info.InMemory) {
         Directory.CreateDirectory(targetdirectory);
     }
     return Compile(info);
 }
        public CompilerContext compile(string code,string check, bool runonly = true) {
            var info = new ViewCompilerInfo();
            info.Options = new MvcViewEngineOptions();
            info.InMemory = true;
            info.ProcessingTest = true;
            info.Sources = new[] {new ViewCodeSource {DirectContent = code, Key = "CUSTOM"}};
            compiler.Compile(info);
            compiler.SetOutput(new StringWriter());
            var result = compiler.LastResult;
            Console.WriteLine("source code:");
            Console.WriteLine(code);
            Console.WriteLine("----------------------------------------------------------------------------------------------");
            if(result.Errors.Count>0) {
                Console.WriteLine("errors: ");
                Console.WriteLine(result.Errors.ToString());
                Console.WriteLine("----------------------------------------------------------------------------------------------");
            }
            string srctochech = result.CompileUnit.Modules[0].ToCodeString();
            if (runonly)
            {
                srctochech =
                    ((Method)((ClassDefinition)result.CompileUnit.Modules[0].Members[0]).Members["Run"]).Body.
                        ToCodeString();
            }
            Console.WriteLine("result code:");
            Console.WriteLine(srctochech);
            Console.WriteLine("----------------------------------------------------------------------------------------------");
            Assert.AreEqual(0,result.Errors.Count);
           
            var equal = StringExtensions.simplifyBoo(srctochech) ==
                        StringExtensions.simplifyBoo(check);
            if (!equal) {
                Console.WriteLine("but waits:");
                Console.WriteLine(check);
                Console.WriteLine("----------------------------------------------------------------------------------------------");

            }
            Assert.AreEqual(StringExtensions.simplifyBoo( srctochech),StringExtensions.simplifyBoo( check));
            return result;
        }
Пример #7
0
 protected override void execute() {
     
    
     try {
         if (test.Length != 0) {
             var info = new ViewCompilerInfo();
             info.Sources = test.Select(x => factory.Resolver.GetFullInfo(x)).ToArray();
             info.InMemory = true;
             info.Options = factory.Options;
             factory.MyCompiler.Compile(info);
         }else {
             factory.CompileAll();
         }
     }catch(Exception e) {
         if(e.ToString().Contains("CompilerError")) {
             logerror(e.Message);
             
         }else {
             throw;
         }
     }
 }
Пример #8
0
 private void setupParameters(BooCompiler compiler, ViewCompilerInfo info) {
     compiler.Parameters.GenerateInMemory = info.InMemory;
     compiler.Parameters.Ducky = true;
     compiler.Parameters.Debug = true;
     compiler.Parameters.OutputType = CompilerOutputType.Library;
     if(info.InMemory) {
         compiler.Parameters.OutputAssembly = info.AssemblyName + ".dll";
     }else {
         compiler.Parameters.OutputAssembly = Path.Combine(info.TargetDirecrtory, info.AssemblyName + ".dll");
     }
 }
Пример #9
0
 private void initCompiler(ViewCompilerInfo info) {
     if(null==this.compiler) {
         this.compiler = new BooCompiler();
         setupAssemblies(compiler, info);
     }
 }
Пример #10
0
        private void setupPipeline(BooCompiler compiler, ViewCompilerInfo info) {
            if(info.InMemory) {
                if (info.ProcessingTest) {
                    compiler.Parameters.Pipeline = new ResolveExpressions();
                }
                else {
                    compiler.Parameters.Pipeline = new CompileToMemory();
                }
            }else {
                
                compiler.Parameters.Pipeline = new CompileToFile();
            }
            compiler.Parameters.Pipeline.RemoveAt(0);
            compiler.Parameters.Pipeline.Insert(0,new WSAIgnoranceParsingStep());
            var processor = new BrailPreProcessor(null, true);
            compiler.Parameters.Pipeline.Insert(0, processor);
            compiler.Parameters.Pipeline.InsertAfter(typeof(WSAIgnoranceParsingStep), new ExpandBmlStep());
            compiler.Parameters.Pipeline.InsertAfter(typeof(WSAIgnoranceParsingStep), new IncludeAstMacroExpandStep());
            
            compiler.Parameters.Pipeline.Insert(2, new TransformToBrailStep(info.Options));
            compiler.Parameters.Pipeline.InsertAfter(typeof(TransformToBrailStep), new BrailRenamerAndTimeStamper());
            compiler.Parameters.Pipeline.InsertAfter(typeof(ExpandBmlStep),
                                                     new InterpolationUnescapeStep());
            compiler.Parameters.Pipeline.InsertAfter(typeof (MacroAndAttributeExpansion), new OutputWriteUnification());

           // if (!info.BrailProcessingTest) {
                compiler.Parameters.Pipeline.Replace(typeof (ProcessMethodBodiesWithDuckTyping),
                                                     new ReplaceUknownWithParameters());
                if (!info.ProcessingTest) {
                    compiler.Parameters.Pipeline.Replace(typeof (ExpandDuckTypedExpressions),
                                                         new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods
                                                             ());
                }

#if !LIB2
            compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices),
                                                 new InitializeCustomTypeSystem());
#endif
                compiler.Parameters.Pipeline.InsertBefore(typeof (MacroAndAttributeExpansion),
                                                          new FixTryGetParameterConditionalChecks());
                compiler.Parameters.Pipeline.RemoveAt(
                    compiler.Parameters.Pipeline.Find(typeof (IntroduceGlobalNamespaces)));
            //}
            if(null!=PreparePipeline) {
                PreparePipeline(compiler.Parameters.Pipeline);
            }
            if(StopOnError)this.compiler.Parameters.Pipeline.BreakOnErrors = true;
            this.compiler.Parameters.Pipeline.BeforeStep += Pipeline_BeforeStep;
            this.compiler.Parameters.Pipeline.AfterStep += Pipeline_AfterStep;
        }
Пример #11
0
 public abstract Assembly Compile(ViewCompilerInfo info);
Пример #12
0
     public void very_simple_mixed_test()
     {
         var compiler = new BrailCompiler();
         var options = new MvcViewEngineOptions();
         var src = new ViewCodeSource
         {
             Key = "/test/x",
             DirectContent = @"<p>${i}</p>"
         };
         var src2 = new ViewCodeSource
         {
             Key = "/test/x2",
             DirectContent = @"bml:
 p : ""${i+i}"""
         };
         var info = new ViewCompilerInfo {Sources = new[] {src, src2}, InMemory = true, Options = options};
         var ass = compiler.Compile(info);
         var type1 = ass.GetType("/test/x".Replace("/", "_0_"));
         var type2 = ass.GetType("/test/x2".Replace("/", "_0_"));
         var view1 = (IView)type1.create<BrailBase>(types: new Type[] { typeof(BooViewEngine) }, parameters: new object[] { null });
         var view2 = (IView)type2.create<BrailBase>(types: new Type[] { typeof(BooViewEngine) }, parameters: new object[] { null });
         var sw = new StringWriter();
         var vc = new ViewContext();
         vc.ViewData = new ViewDataDictionary();
         vc.ViewData["i"] = 3;
         view1.Render(vc, sw);            
         Assert.AreEqual("<p>3</p>", sw.ToString());
         sw = new StringWriter();
         view2.Render(vc, sw);
         Assert.AreEqual("<p>6</p>", sw.ToString());
     }
		//
		// For guidelines regarding the creation of new exception types, see
		//    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
		// and
		//    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
		//


		public BrailCompilerException(ViewCompilerInfo info, Exception inner) : base("Ошибка компиляции "+info.Sources.Select(x=>x.FileName).concat(","), inner) {
			this.info = info;
		}