Beispiel #1
0
        public static void Execute()
        {
            if (_initialized)
                throw new InvalidOperationException("Compilador só pode ser executado no Pre-Start!");

            _initialized = true;

            //plugin loader
            PluginLoaderEntryPoint.Initialize();

            if (BootstrapperSection.Instance.Kompiler.ForceRecompilation)
            {
                //se forçar a recompilação, remove o assembly existente.
                KompilerDbService.RemoveExistingCompiledAssemblyFromDb();
            }

            AddReferences(PluginStorage.GetAssemblies().ToArray());

            byte[] buffer = new byte[0];
            string msg;

            try
            {
                //todo: usar depdendency injection
                IKompiler kompiler;

                if (BootstrapperSection.Instance.Kompiler.Roslyn)
                {
                    kompiler = new RoslynWrapper();
                }
                else
                {
                    kompiler = new CodeDomWrapper();
                }

                if (BootstrapperSection.Instance.Kompiler.LoadFromDb)
                {
                    Trace.TraceInformation("Compiling from DB...");
                    var source = KompilerDbService.LoadSourceCodeFromDb();
                    msg = kompiler.CompileFromSource(source, out buffer);
                }
                else
                {
                    var localRootFolder = BootstrapperSection.Instance.DumpToLocal.Folder;
                    Trace.TraceInformation("Compiling from Local File System: {0}", localRootFolder);
                    msg = kompiler.CompileFromFolder(localRootFolder, out buffer);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Trace.TraceInformation("Erro durante a compilação do projeto no banco de dados. \r\n" + ex.Message);
            }

            if (string.IsNullOrWhiteSpace(msg) && buffer.Length > 0)
            {
                Trace.TraceInformation("[Kompiler]: DB Compilation Result: SUCCESS");

                if (!BootstrapperSection.Instance.Kompiler.ForceRecompilation)
                {
                    //só salva no banco se compilação forçada for False
                    KompilerDbService.SaveCompiledCustomAssembly(buffer);
                }

                PluginLoaderEntryPoint.SaveAndLoadAssembly(CompiledAssemblyName + ".dll", buffer);
            }
            else
            {
                Trace.TraceInformation("[Kompiler]: DB Compilation Result: Bytes:{0}, Msg:{1}",
                    buffer.Length, msg);
            }
        }
Beispiel #2
0
        public static void Execute()
        {
            if (_initialized)
            {
                throw new InvalidOperationException("Compilador só pode ser executado no Pre-Start!");
            }

            _initialized = true;

            //plugin loader
            PluginLoaderEntryPoint.Initialize();

            if (BootstrapperSection.Instance.Kompiler.ForceRecompilation)
            {
                //se forçar a recompilação, remove o assembly existente.
                KompilerDbService.RemoveExistingCompiledAssemblyFromDb();
            }

            AddReferences(PluginStorage.GetAssemblies().ToArray());

            byte[] buffer = new byte[0];
            string msg;

            try
            {
                //todo: usar depdendency injection
                IKompiler kompiler;

                if (BootstrapperSection.Instance.Kompiler.Roslyn)
                {
                    kompiler = new RoslynWrapper();
                }
                else
                {
                    kompiler = new CodeDomWrapper();
                }

                if (BootstrapperSection.Instance.Kompiler.LoadFromDb)
                {
                    Trace.TraceInformation("Compiling from DB...");
                    var source = KompilerDbService.LoadSourceCodeFromDb();
                    msg = kompiler.CompileFromSource(source, out buffer);
                }
                else
                {
                    var localRootFolder = BootstrapperSection.Instance.DumpToLocal.Folder;
                    Trace.TraceInformation("Compiling from Local File System: {0}", localRootFolder);
                    msg = kompiler.CompileFromFolder(localRootFolder, out buffer);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Trace.TraceInformation("Erro durante a compilação do projeto no banco de dados. \r\n" + ex.Message);
            }

            if (string.IsNullOrWhiteSpace(msg) && buffer.Length > 0)
            {
                Trace.TraceInformation("[Kompiler]: DB Compilation Result: SUCCESS");

                if (!BootstrapperSection.Instance.Kompiler.ForceRecompilation)
                {
                    //só salva no banco se compilação forçada for False
                    KompilerDbService.SaveCompiledCustomAssembly(buffer);
                }

                PluginLoaderEntryPoint.SaveAndLoadAssembly(CompiledAssemblyName + ".dll", buffer);
            }
            else
            {
                Trace.TraceInformation("[Kompiler]: DB Compilation Result: Bytes:{0}, Msg:{1}",
                                       buffer.Length, msg);
            }
        }