Beispiel #1
0
 public static TypeRegistry Default(CompiledAssemblyCache compiledAssemblyCache) => new TypeRegistry(compiledAssemblyCache,
                                                                                                     ImmutableDictionary <string, Expression> .Empty
                                                                                                     .Add("object", CreateStatic(typeof(Object)))
                                                                                                     .Add("bool", CreateStatic(typeof(Boolean)))
                                                                                                     .Add("byte", CreateStatic(typeof(Byte)))
                                                                                                     .Add("char", CreateStatic(typeof(Char)))
                                                                                                     .Add("short", CreateStatic(typeof(Int16)))
                                                                                                     .Add("int", CreateStatic(typeof(Int32)))
                                                                                                     .Add("long", CreateStatic(typeof(Int64)))
                                                                                                     .Add("ushort", CreateStatic(typeof(UInt16)))
                                                                                                     .Add("uint", CreateStatic(typeof(UInt32)))
                                                                                                     .Add("ulong", CreateStatic(typeof(UInt64)))
                                                                                                     .Add("decimal", CreateStatic(typeof(Decimal)))
                                                                                                     .Add("double", CreateStatic(typeof(Double)))
                                                                                                     .Add("float", CreateStatic(typeof(Single)))
                                                                                                     .Add("string", CreateStatic(typeof(String)))
                                                                                                     .Add("Object", CreateStatic(typeof(Object)))
                                                                                                     .Add("Boolean", CreateStatic(typeof(Boolean)))
                                                                                                     .Add("Byte", CreateStatic(typeof(Byte)))
                                                                                                     .Add("Char", CreateStatic(typeof(Char)))
                                                                                                     .Add("Int16", CreateStatic(typeof(Int16)))
                                                                                                     .Add("Int32", CreateStatic(typeof(Int32)))
                                                                                                     .Add("Int64", CreateStatic(typeof(Int64)))
                                                                                                     .Add("UInt16", CreateStatic(typeof(UInt16)))
                                                                                                     .Add("UInt32", CreateStatic(typeof(UInt32)))
                                                                                                     .Add("UInt64", CreateStatic(typeof(UInt64)))
                                                                                                     .Add("Decimal", CreateStatic(typeof(Decimal)))
                                                                                                     .Add("Double", CreateStatic(typeof(Double)))
                                                                                                     .Add("Single", CreateStatic(typeof(Single)))
                                                                                                     .Add("String", CreateStatic(typeof(String))),
                                                                                                     ImmutableList <Func <string, Expression> > .Empty
                                                                                                     .Add(type => CreateStatic(compiledAssemblyCache.FindType(type)))
                                                                                                     .Add(type => CreateStatic(compiledAssemblyCache.FindType("System." + type)))
                                                                                                     );
Beispiel #2
0
        private void Init()
        {
            if (Options.FullCompile)
            {
                // touch assembly
                SyntaxFactory.Token(SyntaxKind.NullKeyword);
                InitOptions();

                if (!Directory.Exists(Options.OutputPath))
                {
                    Directory.CreateDirectory(Options.OutputPath);
                }
            }

            var wsa = assemblyDictionary.GetOrAdd(Options.WebSiteAssembly, _ => Assembly.LoadFile(Options.WebSiteAssembly));

            configuration = GetCachedConfiguration(wsa, Options.WebSitePath,
                                                   (services) => {
                if (Options.FullCompile)
                {
                    throw new NotImplementedException();
                    //TODO: LAST PARAMETER | bindingCompiler = new AssemblyBindingCompiler(Options.BindingsAssemblyName, Options.BindingClassName, Path.Combine(Options.OutputPath, Options.BindingsAssemblyName + ".dll"), null);
                    services.AddSingleton <IBindingCompiler>(bindingCompiler);
                    services.AddSingleton <IExpressionToDelegateCompiler>(bindingCompiler.GetExpressionToDelegateCompiler());
                }
            });
            if (Options.SerializeConfig)
            {
                result.Configuration = configuration;
            }

            if (Options.DothtmlFiles == null)
            {
                Options.DothtmlFiles = configuration.RouteTable.Select(r => r.VirtualPath).Where(r => !string.IsNullOrWhiteSpace(r)).ToArray();
            }


            if (Options.FullCompile || Options.CheckBindingErrors)
            {
                compiledAssemblyCache = configuration.ServiceProvider.GetService <CompiledAssemblyCache>();
                controlTreeResolver   = configuration.ServiceProvider.GetService <IControlTreeResolver>();
                fileLoader            = configuration.ServiceProvider.GetService <IMarkupFileLoader>();
            }

            if (Options.FullCompile)
            {
                compiler    = configuration.ServiceProvider.GetService <IViewCompiler>();
                compilation = compiler.CreateCompilation(Options.AssemblyName);
            }
        }
        public DefaultControlResolver(DotvvmConfiguration configuration, IControlBuilderFactory controlBuilderFactory, CompiledAssemblyCache compiledAssemblyCache) : base(configuration.Markup)
        {
            this.configuration         = configuration;
            this.controlBuilderFactory = controlBuilderFactory;
            this.compiledAssemblyCache = compiledAssemblyCache;

            if (!isInitialized)
            {
                lock (locker)
                {
                    if (!isInitialized)
                    {
                        var startupTracer = configuration.ServiceProvider.GetService <IStartupTracer>();

                        startupTracer?.TraceEvent(StartupTracingConstants.InvokeAllStaticConstructorsStarted);
                        InvokeStaticConstructorsOnAllControls();
                        startupTracer?.TraceEvent(StartupTracingConstants.InvokeAllStaticConstructorsFinished);

                        isInitialized = true;
                    }
                }
            }
        }
Beispiel #4
0
        private static bool Run(Options options)
        {
            TypeCollection totalTypeCollection;

            try
            {
                totalTypeCollection = LoadAll(options);
            }
            catch (IOException e)
            {
                Console.WriteLine("Error loading files: " + e.Message);
                return(false);
            }

            options.Log("Preparing output template C# source code.");

            string template = Assembly.GetExecutingAssembly()
                              .GetEmbeddedResourceText("Crossdox/DefaultTemplates/SingleDocument.template");

            string sourceCode = SourceCodeGenerator.CreateFullSourceFile(template,
                                                                         "SingleDocument.template",
                                                                         new[]
            {
                new TemplateArg(typeof(NameInfo), "RootNamespace"),
                new TemplateArg(typeof(TypeCollection), "Types")
            },
                                                                         includeName =>
            {
                string includeText = Assembly.GetExecutingAssembly()
                                     .GetEmbeddedResourceText("Crossdox/DefaultTemplates/" + includeName);
                return(includeText);
            }
                                                                         );

            options.Log("Compiling output template source code.");

            string crossdoxCacheFolder             = Path.Combine(Path.GetTempPath(), "crossdox");
            CompiledAssemblyCache assemblyCache    = new CompiledAssemblyCache(crossdoxCacheFolder);
            CompiledAssembly      compiledAssembly = assemblyCache.LoadOrCompile(options, sourceCode, "SingleDocument.template");

            if (compiledAssembly.HasErrors)
            {
                foreach (string error in compiledAssembly.Errors)
                {
                    Console.Error.WriteLine("Error compiling script: " + error);
                }
                return(false);
            }

            Assembly assembly = compiledAssembly.ToAssembly();

            options.Log("Reflecting against template assembly.");

            Type            compiledTemplate         = assembly.GetType("TemplateScript.CompiledTemplate");
            ConstructorInfo constructor              = compiledTemplate.GetConstructor(Type.EmptyTypes);
            object          compiledTemplateInstance = constructor.Invoke(new object[0]);

            MethodInfo runMethod = compiledTemplate.GetMethod("Run");

            object[] runArgs = new object[]
            {
                new NameInfo(null, "Test", null, null, default),
                totalTypeCollection,
            };

            options.Log("Invoking template assembly Run() method.");

            string result;

            try
            {
                result = (string)runMethod.Invoke(compiledTemplateInstance, runArgs);
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException != null)
                {
                    Console.Error.WriteLine("Error running script: " + e.InnerException);
                }
                else
                {
                    Console.Error.WriteLine("Error running script: " + e);
                }
                return(false);
            }

            if (result != null)
            {
                Console.WriteLine(result);
            }

            return(true);
        }
Beispiel #5
0
 public TypeRegistry(CompiledAssemblyCache compiledAssemblyCache, ImmutableDictionary <string, Expression> registry, ImmutableList <Func <string, Expression> > resolvers)
 {
     this.compiledAssemblyCache = compiledAssemblyCache;
     this.registry  = registry;
     this.resolvers = resolvers;
 }
Beispiel #6
0
 public ResolvedTreeBuilder(BindingCompilationService bindingService, CompiledAssemblyCache compiledAssemblyCache)
 {
     this.bindingService        = bindingService;
     this.compiledAssemblyCache = compiledAssemblyCache;
 }
 public OfflineCompilationControlResolver(DotvvmConfiguration config, IControlBuilderFactory controlBuilderFactory, ViewStaticCompiler compiler, CompiledAssemblyCache compiledAssemblyCache)
     : base(config, controlBuilderFactory, compiledAssemblyCache)
 {
     this.compiler = compiler;
 }
Beispiel #8
0
 public BindingExpressionBuilder(CompiledAssemblyCache compiledAssemblyCache)
 {
     this.compiledAssemblyCache = compiledAssemblyCache;
 }