public ActionResult Compile(string source)
        {
            //Use settings from the My Documents folder, in a hosted / multi-tenant environment, this will have to change.  This works for local machine for now
            var settings = new DebuggerSettings(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

#if DEBUG
            settings.compilerPaths[SourceLanguage.CSharp] = Server.MapPath("~") + @"bin\Compilers\CSharp\";
            settings.compilerPaths[SourceLanguage.Python] = Server.MapPath("~") + @"bin\Compilers\Python\";
#else
            settings.compilerPaths[SourceLanguage.CSharp] = Server.MapPath("~") + @"Compilers\CSharp\";
            settings.compilerPaths[SourceLanguage.Python] = Server.MapPath("~") + @"Compilers\Python\";
#endif


            Neo.Debugger.Core.Utils.Compiler compiler = new Neo.Debugger.Core.Utils.Compiler(settings);
            compiler.SendToLog += Compiler_SendToLog;

            Directory.CreateDirectory(settings.path);
            var fileName = Path.Combine(settings.path, "DebugContract.cs");

            bool success = compiler.CompileContract(source, fileName, Debugger.Core.Data.SourceLanguage.CSharp);

            if (success)
            {
                compiler.Log("Contract compiled successfully.");
            }

            return(Json(success));
        }
Ejemplo n.º 2
0
        public bool CompileContract(string sourceCode, SourceLanguage language, string outputFile = null)
        {
            Compiler compiler = new Compiler(Settings);

            compiler.SendToLog += Compiler_SendToLog;

            var extension = LanguageSupport.GetExtension(language);

            var sourceFile = TempContractName + extension;

            string fileName;

            if (outputFile == null)
            {
                Directory.CreateDirectory(Settings.path);
                fileName = Path.Combine(Settings.path, sourceFile);
            }
            else
            {
                fileName = outputFile.Replace(".avm", extension);
            }

            var avmPath = fileName.Replace(extension, ".avm");

            string abiFile      = avmPath.Replace(".avm", ".abi.json");
            string debugMapFile = avmPath.Replace(".avm", ".debug.json");

            try
            {
                File.Delete(abiFile);
                File.Delete(debugMapFile);
            }
            catch
            {
                // ignore
            }

            bool success = compiler.CompileContract(sourceCode, fileName, language);

            if (success)
            {
                _avmFilePath = avmPath;

                /*if (outputFile != null)
                 * {
                 *  File.Copy(_avmFilePath, outputFile, true);
                 *
                 *  if (File.Exists(abiFile))
                 *  {
                 *      File.Copy(abiFile, outputFile.Replace(".avm", ".abi.json"), true);
                 *  }
                 *
                 *  if (File.Exists(debugMapFile))
                 *  {
                 *      File.Copy(debugMapFile, outputFile.Replace(".avm", ".debug.json"), true);
                 *  }
                 * }*/
            }

            _isCompiled = success;
            return(success);
        }