Beispiel #1
0
        internal static string GetSourceFileRaw(string location, bool useCsharpCode = false)
        {
            string file;

            location = location.TrimEx();
            if (location.ContainsAny("http://", "https://"))
            {
                Cli.PrintLnC($"{location} Downloading...", ConsoleColor.White);

                file = JsonTools.GetStringAsync(location).Result;
            }
            else
            {
                if (!useCsharpCode && !location.EndsWith(".xr"))
                {
                    throw new KernelException("extension (.xr) mandatory");
                }

                file = File.ReadAllText(location);
            }

            var(valid, message) = IsValidSource(file);

            if (!valid)
            {
                throw new KernelException(message);
            }

            return(file);
        }
Beispiel #2
0
        public CompilerService Run(params string[] args)
        {
            Cli.PrintLnC($"Start Running...", ConsoleColor.White);

            var assemblyLoadContextWeakRef = LoadAndExecute(SourceDetail.BuildCode, args);

            for (var i = 0; i < 8 && assemblyLoadContextWeakRef.IsAlive; i++)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            _logger.Info(assemblyLoadContextWeakRef.IsAlive ? "Unloading failed!" : "Unloading success!");

            return(this);
        }
Beispiel #3
0
        internal static void PrintBrand()
        {
            var _brand = $@"
'##::::'##:'#########:
. ##::'##:: ##.... ##:
:. ##'##::: ##:::: ##:
::. ###:::: #########:
:: ## ##::: ##.. ##:::
: ##:. ##:: ##::. ##::
 ##:::. ##: ##:::. ##:
..:::::..::..:::::..::
{KIND_VERSION}

© {DateTime.Now.Year} - Powered by 0xd3c0d3d
";

            Cli.PrintLnC(_brand, ConsoleColor.Gray);
        }
Beispiel #4
0
        public CompilerService Build(string assemblyName, string location, bool useCsharpCode = false, params string[] moduleRef)
        {
            var buildWatch = new Stopwatch();

            buildWatch.Start();

            _logger.Info("Build Start");

            string rawData = SourceParse.GetSourceFileRaw(location, useCsharpCode);

            string source = SourceParse.ParseFile(rawData);

            _logger.Info($"---- Source Code Generate ----:\n{source}");

            SourceDetail = new SourceDetail(assemblyName, source, moduleRef);

            var compResult = GenerateCode(SourceDetail.AssemblyName, SourceDetail.SourceCode, SourceDetail.ModuleRef);

            byte[] emitResult = compResult.EmitToArray();

            Cli.PrintLnC($"{location} Success", ConsoleColor.White);

            // update
            SourceDetail.BuildCode = emitResult;

            buildWatch.Stop();
            TimeSpan ts = buildWatch.Elapsed;

            string elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               ts.Hours, ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            _logger.Info($"Build End - {elapsedTime}");

            return(this);
        }