コード例 #1
0
ファイル: PluginCompiler.cs プロジェクト: strykes/Oxide
        public void Compile(List<CompilablePlugin> plugins, Action<string, byte[], float> callback)
        {
            var currentId = lastId++;
            pluginComp[currentId] = new Compilation { callback = callback, plugins = plugins };
            if (!CheckCompiler())
            {
                foreach (var compilation in pluginComp.Values)
                {
                    foreach (var plugin in compilation.plugins)
                    {
                        plugin.CompilerErrors = "Compiler couldn't be started.";
                    }
                    compilation.Completed();
                }
                pluginComp.Clear();
                return;
            }

            ResolveReferences(currentId, () =>
            {
                if (plugins.Count < 1) return;
                foreach (var plugin in plugins) plugin.CompilerErrors = null;
                SpawnCompiler(currentId);
            });
        }
コード例 #2
0
ファイル: PluginCompiler.cs プロジェクト: AEtherSurfer/Oxide
 internal void Compile(CompilablePlugin[] plugins, Action<Compilation> callback)
 {
     var id = lastId++;
     var compilation = new Compilation(id, callback, plugins);
     compilations[id] = compilation;
     compilation.Prepare(() => EnqueueCompilation(compilation));
 }
コード例 #3
0
ファイル: PluginCompiler.cs プロジェクト: HalfShotz/Oxide
        public void Compile(List<CompilablePlugin> plugins, Action<byte[], float> callback)
        {
            var currentId = lastId++;
            pluginComp[currentId] = new Compilation {callback = callback, plugins = plugins};
            if (!CheckCompiler())
            {
                foreach (var value in pluginComp.Values)
                {
                    foreach (var plugin in value.plugins)
                    {
                        plugin.CompilerErrors = "Compiler couldn't be started.";
                    }
                    Interface.Oxide.NextTick(() => value.callback(new byte[0], 0));
                }
                pluginComp.Clear();
                return;
            }

            ResolveReferences(currentId, () =>
            {
                if (plugins.Count < 1) return;
                foreach (var plugin in plugins) plugin.CompilerErrors = null;
                SpawnCompiler(currentId);
            });
        }
コード例 #4
0
ファイル: Compilation.cs プロジェクト: OlympusServers/Oxide
        internal Compilation(int id, Action<Compilation> callback, CompilablePlugin[] plugins)
        {
            this.id = id;
            this.callback = callback;
            this.queuedPlugins = new ConcurrentHashSet<CompilablePlugin>(plugins);

            if (Current == null) Current = this;

            foreach (var plugin in plugins)
            {
                plugin.CompilerErrors = null;
                plugin.OnCompilationStarted();
            }

            includePath = Path.Combine(Interface.Oxide.PluginDirectory, "Include");
            extensionNames = Interface.Oxide.GetAllExtensions().Select(ext => ext.Name).ToArray();
            gameExtensionNamespace = Interface.Oxide.GetAllExtensions().SingleOrDefault(ext => ext.IsGameExtension)?.GetType().Namespace;
            newGameExtensionNamespace = gameExtensionNamespace != null && gameExtensionNamespace.Contains(".Game.");
        }
コード例 #5
0
ファイル: Compilation.cs プロジェクト: yas-online/Oxide
        internal void Prepare(Action callback)
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    referencedPlugins.Clear();
                    references.Clear();

                    // Include references made by the CSharpPlugins project
                    foreach (var name in CSharpPluginLoader.PluginReferences)
                        references[name + ".dll"] = new CompilerFile(Interface.Oxide.ExtensionDirectory, name + ".dll");

                    //Interface.Oxide.LogDebug("Preparing compilation");

                    CompilablePlugin plugin;
                    while (queuedPlugins.TryDequeue(out plugin))
                    {
                        if (Current == null) Current = this;

                        if (!CacheScriptLines(plugin) || plugin.ScriptLines.Length < 1)
                        {
                            plugin.References.Clear();
                            plugin.IncludePaths.Clear();
                            plugin.Requires.Clear();
                            Interface.Oxide.LogWarning("Plugin script is empty: " + plugin.Name);
                            RemovePlugin(plugin);
                        }
                        else if (plugins.Add(plugin))
                        {
                            //Interface.Oxide.LogDebug("Adding plugin to compilation: " + plugin.Name);
                            PreparseScript(plugin);
                            ResolveReferences(plugin);
                        }
                        else
                        {
                            //Interface.Oxide.LogDebug("Plugin is already part of compilation: " + plugin.Name);
                        }

                        CacheModifiedScripts();

                        // We don't want the main thread to be able to add more plugins which could be missed
                        if (queuedPlugins.Count == 0 && Current == this)
                        {
                            Current = null;
                            //Interface.Oxide.LogDebug("Probably done preparing compilation: " + plugins.Select(p => p.Name).ToSentence());
                        }
                    }

                    //Interface.Oxide.LogDebug("Done preparing compilation: " + plugins.Select(p => p.Name).ToSentence());

                    callback();
                }
                catch (Exception ex)
                {
                    Interface.Oxide.LogException("Exception while resolving plugin references", ex);
                    RemoteLogger.Exception("Exception while resolving plugin references", ex);
                }
            });
        }
コード例 #6
0
ファイル: PluginCompiler.cs プロジェクト: AEtherSurfer/Oxide
 private void EnqueueCompilation(Compilation compilation)
 {
     if (compilation.plugins.Count < 1)
     {
         Interface.Oxide.LogDebug("EnqueueCompilation called for an empty compilation");
         return;
     }
     if (!CheckCompiler())
     {
         OnCompilerFailed("Compiler couldn't be started.");
         return;
     }
     compilation.Started();
     //Interface.Oxide.LogDebug("Compiling with references: " + compilation.references.Keys.ToSentence());
     var source_files = compilation.plugins.SelectMany(plugin => plugin.IncludePaths).Distinct().Select(path => new CompilerFile(path)).ToList();
     source_files.AddRange(compilation.plugins.Select(plugin => new CompilerFile(plugin.ScriptName + ".cs", plugin.ScriptSource)));
     //Interface.Oxide.LogDebug("Compiling files: " + source_files.Select(f => f.Name).ToSentence());
     var data = new CompilerData
     {
         OutputFile = compilation.name,
         SourceFiles = source_files.ToArray(),
         ReferenceFiles = compilation.references.Values.ToArray()
     };
     var message = new CompilerMessage { Id = compilation.id, Data = data, Type = CompilerMessageType.Compile };
     if (ready)
         client.PushMessage(message);
     else
         messageQueue.Enqueue(message);
 }
コード例 #7
0
ファイル: PluginCompiler.cs プロジェクト: RuanPitout88/Oxide
        internal void Compile(CompilablePlugin[] plugins, Action<Compilation> callback)
        {
            if (!CheckCompiler())
            {
                OnCompilerFailed("Compiler couldn't be started.");
                return;
            }

            var id = lastId++;
            var compilation = new Compilation(id, callback, plugins);
            compilations[id] = compilation;

            compilation.Prepare(() => EnqueueCompilation(compilation));
        }
コード例 #8
0
ファイル: Compilation.cs プロジェクト: thematkon/Oxide
        internal void Prepare(Action callback)
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    referencedPlugins.Clear();
                    references.Clear();

                    // Include references made by the CSharpPlugins project
                    foreach (var name in CSharpPluginLoader.PluginReferences)
                    {
                        references[name + ".dll"] = new CompilerFile(Interface.Oxide.ExtensionDirectory, name + ".dll");
                    }

                    //Interface.Oxide.LogDebug("Preparing compilation");

                    CompilablePlugin plugin;
                    while (queuedPlugins.TryDequeue(out plugin))
                    {
                        if (Current == null)
                        {
                            Current = this;
                        }

                        if (!CacheScriptLines(plugin) || plugin.ScriptLines.Length < 1)
                        {
                            plugin.References.Clear();
                            plugin.IncludePaths.Clear();
                            plugin.Requires.Clear();
                            Interface.Oxide.LogWarning("Plugin script is empty: " + plugin.Name);
                            RemovePlugin(plugin);
                        }
                        else if (plugins.Add(plugin))
                        {
                            //Interface.Oxide.LogDebug("Adding plugin to compilation: " + plugin.Name);
                            PreparseScript(plugin);
                            ResolveReferences(plugin);
                        }
                        else
                        {
                            //Interface.Oxide.LogDebug("Plugin is already part of compilation: " + plugin.Name);
                        }

                        CacheModifiedScripts();

                        // We don't want the main thread to be able to add more plugins which could be missed
                        if (queuedPlugins.Count == 0 && Current == this)
                        {
                            Current = null;
                            //Interface.Oxide.LogDebug("Probably done preparing compilation: " + plugins.Select(p => p.Name).ToSentence());
                        }
                    }

                    //Interface.Oxide.LogDebug("Done preparing compilation: " + plugins.Select(p => p.Name).ToSentence());

                    callback();
                }
                catch (Exception ex)
                {
                    Interface.Oxide.LogException("Exception while resolving plugin references", ex);
                    RemoteLogger.Exception("Exception while resolving plugin references", ex);
                }
            });
        }