コード例 #1
0
ファイル: CompilablePlugin.cs プロジェクト: ryan0213/Oxide
 public void Compile(Action <bool> callback)
 {
     CheckLastModificationTime();
     if (LastCompiledAt == LastModifiedAt)
     {
         //Interface.GetMod().LogInfo("Plugin is already compiled: {0}", Name);
         callback(true);
         return;
     }
     if (compiler != null)
     {
         Interface.GetMod().LogInfo("Plugin compilation is already in progress: {0}", ScriptName);
         return;
     }
     compiler = new PluginCompiler(this);
     compiler.Compile(compiled =>
     {
         if (compiled)
         {
             Interface.GetMod().LogInfo("{0} plugin was compiled successfully in {1}ms", ScriptName, Math.Round(compiler.Duration * 1000f));
         }
         else
         {
             Interface.GetMod().LogInfo("{0} plugin failed to compile! Exit code: {1}", ScriptName, compiler.ExitCode);
             Interface.GetMod().LogInfo(compiler.StdOutput.ToString());
             if (compiler.ErrOutput.Length > 0)
             {
                 Interface.GetMod().LogInfo(compiler.ErrOutput.ToString());
             }
         }
         compiler = null;
         callback(compiled);
     });
 }
コード例 #2
0
 private void CompileAssembly(CompilablePlugin[] plugins)
 {
     compiler.Compile(plugins, compilation =>
     {
         if (compilation.compiledAssembly == null)
         {
             foreach (var plugin in compilation.plugins)
             {
                 plugin.OnCompilationFailed();
                 PluginErrors[plugin.Name] = "Failed to compile: " + plugin.CompilerErrors;
                 Interface.Oxide.LogError("{0} plugin failed to compile!", plugin.ScriptName);
                 Interface.Oxide.LogError(plugin.CompilerErrors);
                 RemoteLogger.Warning($"{plugin.ScriptName} plugin failed to compile!\n{plugin.CompilerErrors}");
             }
         }
         else
         {
             if (compilation.plugins.Count > 0)
             {
                 var compiled_names = compilation.plugins.Select(pl => pl.Name).ToArray();
                 var verb           = compilation.plugins.Count > 1 ? "were" : "was";
                 Interface.Oxide.LogInfo($"{compiled_names.ToSentence()} {verb} compiled successfully in {Math.Round(compilation.duration * 1000f)}ms");
             }
             foreach (var plugin in compilation.plugins)
             {
                 if (plugin.CompilerErrors == null)
                 {
                     Interface.Oxide.UnloadPlugin(plugin.Name);
                 }
             }
             foreach (var plugin in compilation.plugins)
             {
                 if (plugin.CompilerErrors == null)
                 {
                     plugin.OnCompilationSucceeded(compilation.compiledAssembly);
                 }
                 else
                 {
                     plugin.OnCompilationFailed();
                     PluginErrors[plugin.Name] = "Failed to compile: " + plugin.CompilerErrors;
                     Interface.Oxide.LogError($"Error while compiling {plugin.CompilerErrors}");
                 }
             }
         }
     });
 }
コード例 #3
0
        private void CompileAssembly(CompilablePlugin[] plugins)
        {
            compiler.Compile(plugins, compilation =>
            {
                if (compilation.compiledAssembly == null)
                {
                    foreach (CompilablePlugin plugin in compilation.plugins)
                    {
                        plugin.OnCompilationFailed();
                        PluginErrors[plugin.Name] = $"Failed to compile: {plugin.CompilerErrors}";
                        Interface.Oxide.LogError($"Error while compiling: {plugin.CompilerErrors}");
                        //RemoteLogger.Warning($"{plugin.ScriptName} plugin failed to compile!\n{plugin.CompilerErrors}");
                    }
                }
                else
                {
                    if (compilation.plugins.Count > 0)
                    {
                        string[] compiledNames = compilation.plugins.Where(pl => string.IsNullOrEmpty(pl.CompilerErrors)).Select(pl => pl.Name).ToArray();
                        string verb            = compiledNames.Length > 1 ? "were" : "was";
                        Interface.Oxide.LogInfo($"{compiledNames.ToSentence()} {verb} compiled successfully in {Math.Round(compilation.duration * 1000f)}ms");
                    }

                    foreach (CompilablePlugin plugin in compilation.plugins)
                    {
                        if (plugin.CompilerErrors == null)
                        {
                            Interface.Oxide.UnloadPlugin(plugin.Name);
                            plugin.OnCompilationSucceeded(compilation.compiledAssembly);
                        }
                        else
                        {
                            plugin.OnCompilationFailed();
                            PluginErrors[plugin.Name] = $"Failed to compile: {plugin.CompilerErrors}";
                            Interface.Oxide.LogError($"Error while compiling: {plugin.CompilerErrors}");
                        }
                    }
                }
            });
        }