示例#1
0
        public IScriptConverter FindConverterForScript(string Script)
        {
#if (!ISWIN)
            IScriptConverter language = null;
            foreach (IScriptConverter convert in converters)
            {
                if (Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture))
                {
                    language = convert;
                }

                if (language == null && convert.Name == DefaultCompileLanguage)
                {
                    language = convert;
                }
            }
#else
            IScriptConverter language = converters.FirstOrDefault(convert => convert.Name == DefaultCompileLanguage);
            foreach (IScriptConverter convert in converters.Where(convert => Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture)))
            {
                language = convert;
            }
#endif

            return(language);
        }
示例#2
0
        void CheckLanguageAndConvert(string Script, UUID ownerID, out IScriptConverter converter,
                                     out string compileScript)
        {
            compileScript = Script;
            converter     = null;
            string language = DefaultCompileLanguage;

            foreach (
                IScriptConverter convert in
                converters.Where(
                    convert => Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture)))
            {
                language = convert.Name;
            }

            if (!AllowedCompilers.ContainsKey(language))
            {
                // Not allowed to compile to this language!
                AddError("The compiler for language \"" + language +
                         "\" is not in list of allowed compilers. Script will not be executed!");

                return;
            }

            if (m_scriptEngine.Scene != null && !m_scriptEngine.Scene.Permissions.CanCompileScript(ownerID, language))
            {
                // Not allowed to compile to this language!
                AddError(ownerID +
                         " is not in list of allowed users for this scripting language. Script will not be executed!");
                return;
            }

            AllowedCompilers.TryGetValue(language, out converter);
            converter.Convert(Script, out compileScript, out PositionMap);
        }
示例#3
0
 public IScriptConverter FindConverterForScript(string Script)
 {
     IScriptConverter language = converters.FirstOrDefault(convert => convert.Name == DefaultCompileLanguage);
     foreach (
         IScriptConverter convert in
             converters.Where(
                 convert => Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture)))
     {
         language = convert;
     }
     return language;
 }
示例#4
0
        public IScriptConverter FindConverterForScript(string Script)
        {
            IScriptConverter language = null;

            foreach (IScriptConverter convert in converters)
            {
                if (convert.Name == DefaultCompileLanguage)
                {
                    language = convert;
                    break;
                }
            }
            foreach (IScriptConverter convert in converters)
            {
                if (Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture))
                {
                    language = convert;
                }
            }

            return(language);
        }
示例#5
0
        private void CheckLanguageAndConvert(string Script, UUID ownerID, out IScriptConverter converter,
            out string compileScript)
        {
            compileScript = Script;
            converter = null;
            string language = DefaultCompileLanguage;

            foreach (
                IScriptConverter convert in
                    converters.Where(
                        convert => Script.StartsWith("//" + convert.Name, true, CultureInfo.InvariantCulture)))
            {
                language = convert.Name;
            }

            if (!AllowedCompilers.ContainsKey(language))
            {
                // Not allowed to compile to this language!
                AddError("The compiler for language \"" + language +
                         "\" is not in list of allowed compilers. Script will not be executed!");

                return;
            }

            if (m_scriptEngine.Scene != null && !m_scriptEngine.Scene.Permissions.CanCompileScript(ownerID, language))
            {
                // Not allowed to compile to this language!
                AddError(ownerID +
                         " is not in list of allowed users for this scripting language. Script will not be executed!");
                return;
            }

            AllowedCompilers.TryGetValue(language, out converter);
            converter.Convert(Script, out compileScript, out PositionMap);
        }
示例#6
0
        /// <summary>
        ///     Compile .NET script to .Net assembly (.dll)
        /// </summary>
        /// <param name="script">CS script</param>
        /// <param name="converter"></param>
        /// <param name="assembly"></param>
        /// <param name="originalScript"></param>
        /// <param name="inMemory"></param>
        /// <returns>Filename to .dll assembly</returns>
        internal void CompileFromDotNetText(string script, IScriptConverter converter, string assembly,
            string originalScript, bool inMemory)
        {
            string ext = "." + converter.Name;

            if (!inMemory)
            {
                // Output assembly name
                scriptCompileCounter++;
                try
                {
                    File.Delete(assembly);
                }
                catch (Exception e) // NOTLEGIT - Should be just FileIOException
                {
                    AddError("Unable to delete old existing " +
                             "script-file before writing new. Compile aborted: " +
                             e);
                    return;
                }
            }

            // DEBUG - write source to disk
            string srcFileName = Path.Combine(m_scriptEngine.ScriptEnginesPath,
                                              Path.GetFileNameWithoutExtension(assembly) + ext);
            if (WriteScriptSourceToDebugFile)
            {
                try
                {
                    File.WriteAllText(srcFileName, script);
                }
                catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                {
                    MainConsole.Instance.Error("[Compiler]: Exception while " +
                                               "trying to write script source to file \"" +
                                               srcFileName + "\": " + ex);
                }
            }

            // Do actual compile
            CompilerParameters parameters = new CompilerParameters {IncludeDebugInformation = true};

            string rootPath =
                Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

            if (rootPath != null)
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "WhiteCore.ScriptEngine.WhiteCoreDotNetEngine.dll"));
            parameters.ReferencedAssemblies.Add("System.dll");
            parameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
            parameters.ReferencedAssemblies.Add("System.Core.dll");
            if (rootPath != null)
            {
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "WhiteCore.Framework.dll"));
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "WhiteCore.BotManager.dll"));
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "OpenMetaverseTypes.dll"));
            }

            parameters.ReferencedAssemblies.AddRange(m_referencedFiles.ToArray());

            parameters.GenerateExecutable = false;
            parameters.GenerateInMemory = inMemory;
            parameters.OutputAssembly = assembly;
            parameters.IncludeDebugInformation = CompileWithDebugInformation;
            //parameters.WarningLevel = 1; // Should be 4?
            parameters.TreatWarningsAsErrors = false;

            CompilerResults results = converter.Compile(parameters, WriteScriptSourceToDebugFile,
                                                        WriteScriptSourceToDebugFile ? srcFileName : script);
            parameters = null;
            //
            // WARNINGS AND ERRORS
            //

            if (results.Errors.Count > 0)
            {
                try
                {
                    File.WriteAllText(srcFileName, script);
                }
                catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                {
                    MainConsole.Instance.Error("[Compiler]: Exception while " +
                                               "trying to write script source to file \"" +
                                               srcFileName + "\": " + ex);
                }

                foreach (CompilerError CompErr in results.Errors)
                {
                    string severity = CompErr.IsWarning ? "Warning" : "Error";
                    // Show 5 errors max, but check entire list for errors

                    string errtext = String.Empty;
                    string text = CompErr.ErrorText;
                    int LineN = 0;
                    int CharN = 0;
                    converter.FindErrorLine(CompErr, PositionMap, originalScript, out LineN, out CharN);
                    //This will crash some viewers if the pos is 0,0!
                    if (LineN <= 0 && CharN <= 0)
                    {
                        CharN = 1;
                        LineN = 1;
                    }

                    // The Second Life viewer's script editor begins
                    // countingn lines and columns at 0, so we subtract 1.
                    errtext += String.Format("({0},{1}): {3}: {2}\n",
                                             LineN, CharN, text, severity);
                    if (severity == "Error")
                        AddError(errtext);
                    else
                        AddWarning(errtext);
                }
            }
            results = null;
            if (m_errors.Count != 0) // Quit early then
                return;

            //  On today's highly asynchronous systems, the result of
            //  the compile may not be immediately apparent. Wait a
            //  reasonable amount of time before giving up on it.

            if (!inMemory)
            {
                if (!File.Exists(assembly))
                {
                    for (int i = 0; i < 500 && !File.Exists(assembly); i++)
                    {
                        Thread.Sleep(10);
                    }
                    AddError("No compile error. But not able to locate compiled file.");
                }
            }
        }
示例#7
0
        /// <summary>
        ///   Compile .NET script to .Net assembly (.dll)
        /// </summary>
        /// <param name = "Script">CS script</param>
        /// <returns>Filename to .dll assembly</returns>
        internal void CompileFromDotNetText(string Script, IScriptConverter converter, string assembly,
                                            string originalScript, bool inMemory)
        {
            string ext = "." + converter.Name;

            if (!inMemory)
            {
                // Output assembly name
                scriptCompileCounter++;
                try
                {
                    File.Delete(assembly);
                }
                catch (Exception e) // NOTLEGIT - Should be just FileIOException
                {
                    AddError("Unable to delete old existing " +
                             "script-file before writing new. Compile aborted: " +
                             e);
                    return;
                }
            }

            // DEBUG - write source to disk
            string srcFileName = Path.Combine(m_scriptEngine.ScriptEnginesPath,
                                              Path.GetFileNameWithoutExtension(assembly) + ext);

            if (WriteScriptSourceToDebugFile)
            {
                try
                {
                    File.WriteAllText(srcFileName, Script);
                }
                catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                {
                    MainConsole.Instance.Error("[Compiler]: Exception while " +
                                               "trying to write script source to file \"" +
                                               srcFileName + "\": " + ex);
                }
            }

            // Do actual compile
            CompilerParameters parameters = new CompilerParameters {
                IncludeDebugInformation = true
            };


            string rootPath =
                Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

            if (rootPath != null)
            {
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "Aurora.ScriptEngine.AuroraDotNetEngine.dll"));
            }
            parameters.ReferencedAssemblies.Add("System.dll");
            if (rootPath != null)
            {
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "Aurora.Framework.dll"));
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "OpenMetaverseTypes.dll"));

                if (converter.Name == "yp")
                {
                    parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                     "OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
                }
            }

            parameters.ReferencedAssemblies.AddRange(m_referencedFiles.ToArray());

            parameters.GenerateExecutable      = false;
            parameters.GenerateInMemory        = inMemory;
            parameters.OutputAssembly          = assembly;
            parameters.IncludeDebugInformation = CompileWithDebugInformation;
            //parameters.WarningLevel = 1; // Should be 4?
            parameters.TreatWarningsAsErrors = false;

            CompilerResults results = converter.Compile(parameters, WriteScriptSourceToDebugFile,
                                                        WriteScriptSourceToDebugFile ? srcFileName : Script);

            parameters = null;
            //
            // WARNINGS AND ERRORS
            //

            if (results.Errors.Count > 0)
            {
                try
                {
                    File.WriteAllText(srcFileName, Script);
                }
                catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                {
                    MainConsole.Instance.Error("[Compiler]: Exception while " +
                                               "trying to write script source to file \"" +
                                               srcFileName + "\": " + ex);
                }

                foreach (CompilerError CompErr in results.Errors)
                {
                    string severity = CompErr.IsWarning ? "Warning" : "Error";
                    // Show 5 errors max, but check entire list for errors

                    string errtext = String.Empty;
                    string text    = CompErr.ErrorText;
                    int    LineN   = 0;
                    int    CharN   = 0;
                    converter.FindErrorLine(CompErr, PositionMap, originalScript, out LineN, out CharN);
                    //This will crash some viewers if the pos is 0,0!
                    if (LineN <= 0 && CharN <= 0)
                    {
                        CharN = 1;
                        LineN = 1;
                    }


                    // The Second Life viewer's script editor begins
                    // countingn lines and columns at 0, so we subtract 1.
                    errtext += String.Format("({0},{1}): {3}: {2}\n",
                                             LineN, CharN, text, severity);
                    if (severity == "Error")
                    {
                        AddError(errtext);
                    }
                    else
                    {
                        AddWarning(errtext);
                    }
                }
            }
            results = null;
            if (m_errors.Count != 0) // Quit early then
            {
                return;
            }

            //  On today's highly asynchronous systems, the result of
            //  the compile may not be immediately apparent. Wait a
            //  reasonable amount of time before giving up on it.

            if (!inMemory)
            {
                if (!File.Exists(assembly))
                {
                    for (int i = 0; i < 500 && !File.Exists(assembly); i++)
                    {
                        Thread.Sleep(10);
                    }
                    AddError("No compile error. But not able to locate compiled file.");
                }
            }
        }
示例#8
0
        /// <summary>
        /// Compile .NET script to .Net assembly (.dll)
        /// </summary>
        /// <param name="Script">CS script</param>
        /// <returns>Filename to .dll assembly</returns>
        internal void CompileFromDotNetText(string Script, IScriptConverter converter, string assembly, string originalScript, bool inMemory)
        {
            string ext = "." + converter.Name;

            if (!inMemory)
            {
                // Output assembly name
                scriptCompileCounter++;
                try
                {
                    File.Delete(assembly);
                }
                catch (Exception e) // NOTLEGIT - Should be just FileIOException
                {
                    AddError("Unable to delete old existing " +
                             "script-file before writing new. Compile aborted: " +
                             e.ToString());
                    return;
                }

                // DEBUG - write source to disk
                if (WriteScriptSourceToDebugFile)
                {
                    string srcFileName = Path.GetFileNameWithoutExtension(assembly) + ext;
                    try
                    {
                        File.WriteAllText(Path.Combine(m_scriptEngine.ScriptEnginesPath,
                                                       srcFileName), Script);
                    }
                    catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                    {
                        m_log.Error("[Compiler]: Exception while " +
                                    "trying to write script source to file \"" +
                                    srcFileName + "\": " + ex.ToString());
                    }
                }
            }

            // Do actual compile
            CompilerParameters parameters = new CompilerParameters();

            parameters.IncludeDebugInformation = true;

            string rootPath =
                Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

            parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                             "Aurora.ScriptEngine.AuroraDotNetEngine.dll"));
            parameters.ReferencedAssemblies.Add("System.dll");
            parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                             "OpenSim.Framework.dll"));

            if (converter.Name == "yp")
            {
                parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
                                                                 "OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
            }

            parameters.ReferencedAssemblies.AddRange(m_referencedFiles.ToArray());

            parameters.GenerateExecutable      = false;
            parameters.GenerateInMemory        = inMemory;
            parameters.OutputAssembly          = assembly;
            parameters.IncludeDebugInformation = CompileWithDebugInformation;
            //parameters.WarningLevel = 1; // Should be 4?
            parameters.TreatWarningsAsErrors = false;

            CompilerResults results = converter.Compile(parameters, Script);

            parameters = null;
            //
            // WARNINGS AND ERRORS
            //

            if (results.Errors.Count > 0)
            {
                string srcFileName = FilePrefix + "_source_" +
                                     Path.GetFileNameWithoutExtension(assembly) + ext;
                try
                {
                    File.WriteAllText(Path.Combine(m_scriptEngine.ScriptEnginesPath,
                                                   srcFileName), Script);
                }
                catch (Exception ex) //NOTLEGIT - Should be just FileIOException
                {
                    m_log.Error("[Compiler]: Exception while " +
                                "trying to write script source to file \"" +
                                srcFileName + "\": " + ex.ToString());
                }

                foreach (CompilerError CompErr in results.Errors)
                {
                    string severity = CompErr.IsWarning ? "Warning" : "Error";

                    KeyValuePair <int, int> lslPos;

                    // Show 5 errors max, but check entire list for errors

                    string errtext = String.Empty;

                    if (severity == "Error")
                    {
                        string text  = CompErr.ErrorText;
                        int    LineN = 0;
                        int    CharN = 0;
                        // Use LSL type names
                        if (converter.Name == "lsl")
                        {
                            text   = ReplaceTypes(CompErr.ErrorText);
                            text   = CleanError(text);
                            lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, PositionMap);
                            LineN  = lslPos.Key - 1;
                            CharN  = lslPos.Value - 1;
                            if (LineN <= 0 && CharN != 0)
                            {
                                string[] lines    = originalScript.Split('\n');
                                int      charCntr = 0;
                                int      lineCntr = 0;
                                foreach (string line in lines)
                                {
                                    if (charCntr + line.Length > CharN)
                                    {
                                        //Its in this line
                                        CharN -= charCntr;
                                        LineN  = lineCntr;
                                        break;
                                    }
                                    charCntr += line.Length - 1;
                                    lineCntr++;
                                }
                            }
                        }
                        else
                        {
                            LineN = CompErr.Line;
                            CharN = CompErr.Column;
                        }

                        //This will crash some viewers if the pos is 0,0!
                        if (LineN <= 0 && CharN <= 0)
                        {
                            CharN = 1;
                            LineN = 1;
                        }


                        // The Second Life viewer's script editor begins
                        // countingn lines and columns at 0, so we subtract 1.
                        errtext += String.Format("({0},{1}): {3}: {2}\n",
                                                 LineN, CharN, text, severity);
                        AddError(errtext);
                    }
                    else
                    {
                        string text  = CompErr.ErrorText;
                        int    LineN = 0;
                        int    CharN = 0;
                        // Use LSL type names
                        if (converter.Name == "lsl")
                        {
                            text   = ReplaceTypes(CompErr.ErrorText);
                            text   = CleanError(text);
                            lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, PositionMap);
                            LineN  = lslPos.Key - 1;
                            CharN  = lslPos.Value - 1;
                            if (LineN <= 0 && CharN != 0)
                            {
                                string[] lines    = originalScript.Split('\n');
                                int      charCntr = 0;
                                int      lineCntr = 0;
                                foreach (string line in lines)
                                {
                                    if (charCntr + line.Length > CharN)
                                    {
                                        //Its in this line
                                        CharN -= charCntr;
                                        LineN  = lineCntr;
                                        break;
                                    }
                                    charCntr += line.Length - 1;
                                    lineCntr++;
                                }
                            }
                        }
                        else
                        {
                            LineN = CompErr.Line;
                            CharN = CompErr.Column;
                        }

                        //This will crash some viewers if the pos is 0,0!
                        if (LineN == 0 && CharN == 0)
                        {
                            CharN = 1;
                            LineN = 1;
                        }

                        // The Second Life viewer's script editor begins
                        // countingn lines and columns at 0, so we subtract 1.
                        errtext += String.Format("({0},{1}): {3}: {2}\n",
                                                 LineN, CharN, text, severity);
                        AddWarning(errtext);
                    }
                }
            }
            results = null;
            if (m_errors.Count != 0) // Quit early then
            {
                return;
            }

            //  On today's highly asynchronous systems, the result of
            //  the compile may not be immediately apparent. Wait a
            //  reasonable amount of time before giving up on it.

            if (!inMemory)
            {
                if (!File.Exists(assembly))
                {
                    for (int i = 0; i < 500 && !File.Exists(assembly); i++)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                    AddError("No compile error. But not able to locate compiled file.");
                }
            }
        }