Пример #1
0
        private bool TryCompilePlugin(string filename, ICommandInteraction writer)
        {
            string sha;

            using (var shaComputer = SHA256.Create())
            {
                using (var f = File.OpenRead(filename))
                {
                    var bytesSha = shaComputer.ComputeHash(f);

                    var strBldr = new StringBuilder(32 * 2);
                    foreach (var b in bytesSha)
                    {
                        strBldr.AppendFormat("{0:X2}", b);
                    }
                    sha = strBldr.ToString();

                    if (scannedFilesCache.Contains(sha))
                    {
                        writer.WriteLine($"Code from file {filename} has already been compiled. Ignoring...");
                        return(true);
                    }
                }
            }

            try
            {
                if (!EmulationManager.Instance.CompiledFilesCache.TryGetEntryWithSha(sha, out var compiledCode))
                {
                    var compiler = new AdHocCompiler();
                    compiledCode = compiler.Compile(filename);
                    EmulationManager.Instance.CompiledFilesCache.StoreEntryWithSha(sha, compiledCode);
                }

                cache.ClearCache();
                var result = TypeManager.Instance.ScanFile(compiledCode);
                if (result)
                {
                    scannedFilesCache.Add(sha);
                }
                return(result);
            }
            catch (Exception e)
                when(e is RecoverableException ||
                     e is InvalidOperationException)
                {
                    writer.WriteError("Errors during compilation or loading:\r\n" + e.Message.Replace(Environment.NewLine, "\r\n"));
                    return(false);
                }
        }
        private bool TryCompilePlugin(string filename, ICommandInteraction writer)
        {
            var compiler = new AdHocCompiler();

            try
            {
                var result = compiler.Compile(filename, AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic).Select(x => x.Location));
                return(TypeManager.Instance.ScanFile(result));
            }
            catch (RecoverableException e)
            {
                writer.WriteError("Errors during compilation or loading:\r\n" + e.Message.Replace(Environment.NewLine, "\r\n"));
                return(false);
            }
        }
Пример #3
0
        private bool TryCompilePlugin(string filename, ICommandInteraction writer)
        {
            var compiler = new AdHocCompiler();

            try
            {
                var result = compiler.Compile(filename);
                cache.ClearCache();
                return(TypeManager.Instance.ScanFile(result));
            }
            catch (Exception e)
                when(e is RecoverableException ||
                     e is InvalidOperationException)
                {
                    writer.WriteError("Errors during compilation or loading:\r\n" + e.Message.Replace(Environment.NewLine, "\r\n"));
                    return(false);
                }
        }