示例#1
0
 /// <summary>
 /// Sets the processing state of the script to done
 /// it will not be returned by the NextItem property.
 /// </summary>
 /// <param name="script">The script to set the stage for</param>
 public void SetState(ISourceScript script, ProcessStage stage)
 {
     if (IsIncluded(script))
     {
         doneState[IndexOfFile(script.GetKey())] = stage;
     }
 }
示例#2
0
 /// <summary>
 ///     Gets called once on each file.
 ///     Looping Through All the Files
 ///     Looping Through All the plugins
 /// </summary>
 /// <param name="script">the current source script</param>
 /// <param name="sourceManager">the current source manager</param>
 /// <param name="defTable">the current definitions</param>
 /// <returns>state of the process(if false will abort processing)</returns>
 public virtual bool OnLoad_FullScriptStage(
     ISourceScript script,
     ISourceManager sourceManager,
     IDefinitions defTable)
 {
     return(true);
 }
示例#3
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true); //No error, we just dont have any generic parameters to replace.
            }

            string[] genParams = file.GetValueFromCache <string[]>("genParams");

            Logger.Log(LogType.Log, "Discovering Generic Keywords...", PLUGIN_MIN_SEVERITY);
            if (genParams != null && genParams.Length > 0)
            {
                for (int i = genParams.Length - 1; i >= 0; i--)
                {
                    Logger.Log(LogType.Log,
                               $"Replacing Keyword {GenericKeyword}{i} with {genParams[i]} in file {file.GetKey()}",
                               PLUGIN_MIN_SEVERITY + 1);
                    Utils.ReplaceKeyWord(file.GetSource(), genParams[i],
                                         GenericKeyword + i);
                }
            }


            Logger.Log(LogType.Log, "Generic Keyword Replacement Finished", PLUGIN_MIN_SEVERITY);

            return(true);
        }
 /// <summary>
 ///     Gets called once on each file.
 ///     Looping Through All the Files
 ///     Looping Through All the plugins
 /// </summary>
 /// <param name="script">the current source script</param>
 /// <param name="sourceManager">the current source manager</param>
 /// <param name="defTable">the current definitions</param>
 /// <returns>state of the process(if false will abort processing)</returns>
 public override bool OnMain_FullScriptStage(
     ISourceScript script,
     ISourceManager sourceManager,
     IDefinitions defTable)
 {
     return(FullScriptStage(script, sourceManager, defTable));
 }
示例#5
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true); //No error, we just dont have any generic parameters to replace.
            }

            string[] genParams = file.GetValueFromCache <string[]>("genParams");

            Logger.Log(PPLogType.Log, Verbosity.Level5, "Discovering Generic Keywords...");
            if (genParams != null && genParams.Length > 0)
            {
                for (int i = genParams.Length - 1; i >= 0; i--)
                {
                    Logger.Log(PPLogType.Log, Verbosity.Level6, "Replacing Keyword {0}{1} with {2} in file {3}",
                               GenericKeyword, i, genParams[i], file.GetKey());
                    Utils.ReplaceKeyWord(file.GetSource(), genParams[i],
                                         GenericKeyword + i);
                }
            }


            Logger.Log(PPLogType.Log, Verbosity.Level5, "Generic Keyword Replacement Finished");

            return(true);
        }
示例#6
0
        /// <summary>
        /// </summary>
        /// <param name="fullScriptStage">The chain for this stage</param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">The script to operate on</param>
        /// <param name="sourceManager">The sourcemanager used.</param>
        /// <param name="defTable">The definitions used</param>
        /// <returns></returns>
        private bool RunFullScriptStage(
            List <AbstractPlugin> fullScriptStage, ProcessStage stage, ISourceScript script,
            ISourceManager sourceManager, IDefinitions defTable)
        {
            foreach (AbstractPlugin abstractPlugin in fullScriptStage)
            {
                bool ret = true;
                Logger.Log(LogType.Log, $"Running Plugin: {abstractPlugin}", 4);
                if (stage == ProcessStage.OnLoadStage)
                {
                    ret = abstractPlugin.OnLoad_FullScriptStage(script, sourceManager, defTable);
                }
                else if (stage == ProcessStage.OnMain)
                {
                    ret = abstractPlugin.OnMain_FullScriptStage(script, sourceManager, defTable);
                }

                if (!ret)
                {
                    Logger.Log(LogType.Error, $"Processing was aborted by Plugin: {abstractPlugin}", 1);
                    return(false);
                }
            }

            return(true);
        }
示例#7
0
        /// <summary>
        /// Runs the plugin stage with the specififed type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">the script to be processed</param>
        /// <param name="sourceManager"></param>
        /// <param name="defTable">the definitions that are used</param>
        /// <returns>True if the operation completed successfully</returns>
        private bool RunPluginStage(PluginType type, ProcessStage stage, ISourceScript script, ISourceManager sourceManager, IDefinitions defTable)
        {
            List <AbstractPlugin> chain = AbstractPlugin.GetPluginsForStage(_plugins, type, stage);


            bool ret = true;

            if (type == PluginType.FULL_SCRIPT_PLUGIN)
            {
                ret = RunFullScriptStage(chain, stage, script, sourceManager, defTable);
            }
            else if (type == PluginType.LINE_PLUGIN_BEFORE || type == PluginType.LINE_PLUGIN_AFTER)
            {
                string[] src = script.GetSource();
                RunLineStage(chain, stage, src);
                script.SetSource(src);
            }
            if (!ret)
            {
                return(false);
            }


            return(true);
        }
示例#8
0
        /// <summary>
        ///     Runs the specified stage on the passed script
        /// </summary>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">the script to be processed</param>
        /// <param name="sourceManager"></param>
        /// <param name="defTable">the definitions that are used</param>
        /// <returns></returns>
        private static bool RunStages(
            PreProcessor pp,
            ProcessStage stage,
            ISourceScript script,
            ISourceManager sourceManager,
            IDefinitions defTable)
        {
            if (!pp.RunPluginStage(PluginType.LinePluginBefore, stage, script, sourceManager, defTable))
            {
                return(false);
            }

            if (stage != ProcessStage.OnFinishUp &&
                !pp.RunPluginStage(PluginType.FullScriptPlugin, stage, script, sourceManager, defTable))
            {
                return(false);
            }

            if (!pp.RunPluginStage(PluginType.LinePluginAfter, stage, script, sourceManager, defTable))
            {
                return(false);
            }

            return(true);
        }
示例#9
0
        /// <summary>
        /// Runs the plugin stage with the specififed type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="stage">The stage of the current processing</param>
        /// <param name="script">the script to be processed</param>
        /// <param name="sourceManager"></param>
        /// <param name="defTable">the definitions that are used</param>
        /// <returns>True if the operation completed successfully</returns>
        private bool RunPluginStage(PluginType type, ProcessStage stage, ISourceScript script,
                                    ISourceManager sourceManager, IDefinitions defTable)
        {
            List <AbstractPlugin> chain = AbstractPlugin.GetPluginsForStage(plugins, type, stage);


            bool ret = true;

            if (type == PluginType.FullScriptPlugin)
            {
                ret = RunFullScriptStage(chain, stage, script, sourceManager, defTable);
            }
            else if (type == PluginType.LinePluginBefore || type == PluginType.LinePluginAfter)
            {
                string[] src = script.GetSource();
                RunLineStage(chain, stage, src);
                script.SetSource(src);
            }
            if (!ret)
            {
                return(false);
            }


            return(true);
        }
示例#10
0
        /// <summary>
        ///     Processes the file with the settings, definitions and the source manager specified.
        /// </summary>
        /// <param name="files">the file paths to be processed</param>
        /// <param name="settings">the settings that are used</param>
        /// <param name="defs">the definitions that are used</param>
        /// <returns>Returns a list of files that can be compiled in reverse order</returns>
        private ISourceScript[] Process(IFileContent[] files, Settings settings, IDefinitions defs)
        {
            Logger.Log(LogType.Log, "Preprocessing files: " + files.Unpack(", "), 1);
            Timer.GlobalTimer.Restart();
            IDefinitions definitions = defs ?? new Definitions();

            settings = settings ?? new Settings();
            SourceManager sm = new SourceManager(plugins);

            InitializePlugins(settings, definitions, sm);

            foreach (IFileContent file in files)
            {
                sm.SetLock(false);
                sm.TryCreateScript(out ISourceScript sss, sep, file, new ImportResult(), false);
                sm.SetLock(true);
                sm.AddToTodo(sss);
            }

            ISourceScript ss = sm.NextItem;

            do
            {
                Logger.Log(LogType.Log, "Selecting Current File: " + ss.GetFileInterface().GetFilePath(), 2);


                if (!(ss as SourceScript).IsSourceLoaded)
                {
                    RunStages(this, ProcessStage.OnLoadStage, ss, sm, definitions);
                }

                Logger.Log(LogType.Log, $"Selecting File: {Path.GetFileName(ss.GetFileInterface().GetKey())}", 3);

                //RUN MAIN
                sm.SetLock(false);
                RunStages(this, ProcessStage.OnMain, ss, sm, definitions);
                sm.SetLock(true);
                sm.SetState(ss, ProcessStage.OnFinishUp);
                ss = sm.NextItem;
            } while (ss != null);


            ISourceScript[] ret = sm.GetList().ToArray();

            foreach (ISourceScript finishedScript in ret)
            {
                Logger.Log(
                    LogType.Log,
                    $"Selecting File: {Path.GetFileName(finishedScript.GetFileInterface().GetKey())}",
                    3
                    );
                RunStages(this, ProcessStage.OnFinishUp, finishedScript, sm, definitions);
            }

            Logger.Log(LogType.Log, "Finished Processing Files.", 2);


            return(ret);
        }
示例#11
0
 /// <summary>
 /// Adds a file to a list while checking for the key
 /// </summary>
 /// <param name="script"></param>
 /// <param name="checkForExistingKey"></param>
 private void AddFile(ISourceScript script, bool checkForExistingKey)
 {
     if (checkForExistingKey && ContainsFile(script.GetKey()))
     {
         return;
     }
     _sources.Add(script);
 }
示例#12
0
 /// <summary>
 /// Adds a script to the to do list of the source manager.
 /// Will do nothing if already included
 /// </summary>
 /// <param name="script">The script to enqueue for computation</param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         AddFile(script, false);
         doneState.Add(ProcessStage.Queued);
     }
 }
示例#13
0
        /// <summary>
        /// Sets the processing state of the script to done
        /// it will not be returned by the NextItem property.
        /// </summary>
        /// <param name="script"></param>
        public void SetState(ISourceScript script, ProcessStage stage)
        {
            if (IsIncluded(script))
            {
                _doneState[IndexOfFile(script.GetKey())] = stage;

                this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Finished Script: {0}", Path.GetFileName(script.GetFilePath()));
            }
        }
示例#14
0
        public bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> source = file.GetSource().ToList();

            foreach (var breakpoint in _breakpoints)
            {
                for (lineCount = 0; lineCount < source.Count; lineCount++)
                {
                    if (isBreaking)
                    {
                        do
                        {
                            this.Log(DebugLevel.LOGS, Verbosity.LEVEL1, "Type -dbg-continue to contine processing\nType -dbg-exit to exit the program\nType -dbg-file to list the current file from line you set the breakpoint\n-dbg-file-all to list the whole file\n-dbg-dump <pathtofile> dumps the current file source.\n-dbg-add-bp <breakpointstring>");
                            string getInput = Console.ReadLine();
                            if (getInput == "-dbg-continue")
                            {
                                isBreaking = false;
                                return(true);
                            }
                            else if (getInput == "-dbg-exit")
                            {
                                return(false);
                            }
                            else if (getInput == "-dbg-file")
                            {
                                source.TakeLast(source.Count - lineCount).ToList().ForEach(Console.WriteLine);
                            }
                            else if (getInput == "-dbg-file-all")
                            {
                                source.ForEach(Console.WriteLine);
                            }
                            else if (getInput.StartsWith("-dbg-dump "))
                            {
                                string ff = getInput.Split(" ")[1];
                                if (ff != "")
                                {
                                    File.WriteAllLines(ff, source);
                                }
                            }
                            else if (getInput.StartsWith("-dbg-add-bp "))
                            {
                                Breakpoint[] ff = Breakpoint.Parse(getInput.Split(" "), this);
                                _breakpoints.AddRange(ff);
                            }
                        } while (isBreaking);
                    }
                    if (breakpoint.Break(lineCount, file.GetKey()))
                    {
                        isBreaking = true;
                    }
                }
            }



            return(true);
        }
示例#15
0
 /// <summary>
 /// Adds a script to the to do list of the source manager.
 /// Will do nothing if already included
 /// </summary>
 /// <param name="script"></param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Adding Script to Todo List: {0}", Path.GetFileName(script.GetFilePath()));
         AddFile(script, false);
         _doneState.Add(ProcessStage.QUEUED);
     }
 }
示例#16
0
 /// <summary>
 /// Adds a script to the to do list of the source manager.
 /// Will do nothing if already included
 /// </summary>
 /// <param name="script">The script to enqueue for computation</param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         Logger.Log(PPLogType.Log, Verbosity.Level3, "Adding Script to Todo List: {0}",
                    Path.GetFileName(script.GetFileInterface().GetKey()));
         AddFile(script, false);
         doneState.Add(ProcessStage.Queued);
     }
 }
示例#17
0
        /// <summary>
        /// Sets the processing state of the script to done
        /// it will not be returned by the NextItem property.
        /// </summary>
        /// <param name="script">The script to set the stage for</param>
        public void SetState(ISourceScript script, ProcessStage stage)
        {
            if (IsIncluded(script))
            {
                doneState[IndexOfFile(script.GetKey())] = stage;

                Logger.Log(PPLogType.Log, Verbosity.Level3, "Finished Script: {0}",
                           Path.GetFileName(script.GetFileInterface().GetKey()));
            }
        }
示例#18
0
        private bool GetISourceScript(
            ISourceManager manager,
            string statement,
            string currentPath,
            bool isInline,
            out List <ISourceScript> scripts)
        {
            string[] vars = Utils.SplitAndRemoveFirst(statement, Separator);

            scripts = new List <ISourceScript>();

            if (vars.Length != 0)
            {
                ImportResult importInfo = manager.GetComputingScheme()(vars, currentPath);

                if (!importInfo)
                {
                    Logger.Log(LogType.Error, "Invalid Include Statement", 1);

                    return(false);
                }

                string filepath = importInfo.GetString("filename");
                importInfo.RemoveEntry("filename");
                string key = importInfo.GetString("key");
                importInfo.RemoveEntry("key");
                string originalDefinedName = importInfo.GetString("definedname");
                importInfo.RemoveEntry("definedname");

                IFileContent cont = new FilePathContent(filepath, originalDefinedName);
                cont.SetKey(key);

                if (manager.TryCreateScript(out ISourceScript iss, Separator, cont, importInfo, isInline))
                {
                    scripts.Add(iss);
                }

                for (int index = scripts.Count - 1; index >= 0; index--)
                {
                    ISourceScript sourceScript = scripts[index];

                    if (sourceScript.GetFileInterface().HasValidFilepath&&
                        !Utils.FileExistsRelativeTo(currentPath, sourceScript.GetFileInterface()))
                    {
                        Logger.Log(LogType.Error, $"Could not find File: {sourceScript.GetFileInterface()}", 1);
                        scripts.RemoveAt(index);
                    }
                }

                return(true);
            }

            return(false);
        }
示例#19
0
        /// <summary>
        /// Fixes the order of the file tree if a script was being loaded and is now referenced (again)
        /// by removing it from the lower position and readding it at the top
        /// </summary>
        /// <param name="script"></param>
        public void FixOrder(ISourceScript script)
        {
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL3, "Fixing Build Order of file: {0}", Path.GetFileName(script.GetFilePath()));
            int idx = IndexOfFile(script.GetKey());
            var a   = _sources[idx];
            var ab  = _doneState[idx];

            _doneState.RemoveAt(idx);
            _doneState.Add(ab);
            _sources.RemoveAt(idx);
            AddFile(a, true);
        }
示例#20
0
        /// <summary>
        /// Processes the file with the settings, definitions and the source manager specified.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="settings"></param>
        /// <param name="defs"></param>
        /// <returns>Returns a list of files that can be compiled in reverse order</returns>
        public ISourceScript[] Process(string[] files, Settings settings = null, IDefinitions defs = null)
        {
            string dir = Directory.GetCurrentDirectory();

            defs = defs ?? new Definitions();
            SourceManager sm = new SourceManager(_plugins);

            InitializePlugins(settings, defs, sm);

            this.Log(DebugLevel.LOGS, Verbosity.LEVEL1, "Starting Processing of Files: {0}", files.Unpack(", "));
            foreach (var file in files)
            {
                string f = Path.GetFullPath(file);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(f));

                sm.SetLock(false);
                sm.CreateScript(out ISourceScript sss, _sep, f, f, new Dictionary <string, object>());
                sm.SetLock(true);
                List <ISourceScript> all = new List <ISourceScript>();
                sm.AddToTodo(sss);
            }

            ISourceScript ss = sm.NextItem;

            do
            {
                if (!(ss as SourceScript).IsSourceLoaded)
                {
                    RunStages(ProcessStage.ON_LOAD_STAGE, ss, sm, defs);
                }

                this.Log(DebugLevel.PROGRESS, Verbosity.LEVEL1, "Remaining Files: {0}", sm.GetTodoCount());
                this.Log(DebugLevel.LOGS, Verbosity.LEVEL2, "Selecting File: {0}", Path.GetFileName(ss.GetFilePath()));
                //RUN MAIN
                sm.SetLock(false);
                RunStages(ProcessStage.ON_MAIN, ss, sm, defs);
                sm.SetLock(true);
                sm.SetState(ss, ProcessStage.ON_FINISH_UP);
                ss = sm.NextItem;
            } while (ss != null);


            Directory.SetCurrentDirectory(dir);
            ISourceScript[] ret = sm.GetList().ToArray();
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL1, "Finishing Up...");
            foreach (var finishedScript in ret)
            {
                this.Log(DebugLevel.LOGS, Verbosity.LEVEL2, "Selecting File: {0}", Path.GetFileName(finishedScript.GetFilePath()));
                RunStages(ProcessStage.ON_FINISH_UP, finishedScript, sm, defs);
            }
            this.Log(DebugLevel.LOGS, Verbosity.LEVEL1, "Finished Processing Files.");
            return(ret);
        }
示例#21
0
        /// <summary>
        /// Convenience wrapper to create a source script without knowing the actual type of the script.
        /// </summary>
        /// <param name="separator"></param>
        /// <param name="file"></param>
        /// <param name="key"></param>
        /// <param name="pluginCache"></param>
        /// <returns></returns>
        public bool CreateScript(out ISourceScript script, string separator, string file, string key, Dictionary <string, object> pluginCache)
        {
            if (LockScriptCreation)
            {
                script = null;
                this.Log(DebugLevel.WARNINGS, Verbosity.LEVEL1, "A Plugin is trying to add a file outside of the main stage. Is the configuration correct?");
                return(false);
            }

            script = new SourceScript(separator, file, key, pluginCache);
            return(true);
        }
示例#22
0
        /// <summary>
        /// Convenience wrapper to create a source script without knowing the actual type of the script.
        /// </summary>
        /// <param name="separator">the separator used.</param>
        /// <param name="file">the path of the file</param>
        /// <param name="key">the key of the file</param>
        /// <param name="importInfo">the import info of the key and path importation</param>
        /// <returns>the success state of the operation</returns>
        public bool TryCreateScript(out ISourceScript script, string separator, IFileContent file, ImportResult importInfo)
        {
            if (LockScriptCreation)
            {
                script = null;
                this.Warning("A Plugin is trying to add a file outside of the main stage. Is the configuration correct?");
                return(false);
            }

            script = new SourceScript(separator, file, importInfo);
            return(true);
        }
示例#23
0
        /// <summary>
        /// Fixes the order of the file tree if a script was being loaded and is now referenced (again)
        /// by removing it from the lower position and readding it at the top
        /// </summary>
        /// <param name="script">The script that got referenced.</param>
        public void FixOrder(ISourceScript script)
        {
            Logger.Log(LogType.Log,
                       "Fixing Build Order of file: {Path.GetFileName(script.GetFileInterface().GetKey())}", 3);
            int           idx = IndexOfFile(script.GetKey());
            ISourceScript a   = sources[idx];
            ProcessStage  ab  = doneState[idx];

            doneState.RemoveAt(idx);
            doneState.Add(ab);
            sources.RemoveAt(idx);
            AddFile(a, true);
        }
示例#24
0
        /// <summary>
        /// Convenience wrapper to create a source script without knowing the actual type of the script.
        /// </summary>
        /// <param name="separator">the separator used.</param>
        /// <param name="file">the path of the file</param>
        /// <param name="key">the key of the file</param>
        /// <param name="importInfo">the import info of the key and path importation</param>
        /// <returns>the success state of the operation</returns>
        public bool TryCreateScript(out ISourceScript script, string separator, IFileContent file,
                                    ImportResult importInfo)
        {
            if (lockScriptCreation)
            {
                script = null;
                Logger.Log(PPLogType.Warning, Verbosity.Level3,
                           "A Plugin is trying to add a file outside of the main stage. Is the configuration correct?");
                return(false);
            }

            script = new SourceScript(separator, file, importInfo);
            return(true);
        }
示例#25
0
        /// <summary>
        ///     Adds a file to a list while checking for the key
        /// </summary>
        /// <param name="script">The file to be added.</param>
        /// <param name="checkForExistingKey">A flag to optionally check if the key of the file is already existing</param>
        private void AddFile(ISourceScript script, bool checkForExistingKey, bool atFront = false)
        {
            if (checkForExistingKey && ContainsFile(script.GetKey()))
            {
                return;
            }

            if (atFront)
            {
                sources.Insert(0, script);
                return;
            }

            sources.Add(script);
        }
示例#26
0
 /// <summary>
 ///     Adds a script to the to do list of the source manager.
 ///     Will do nothing if already included
 /// </summary>
 /// <param name="script">The script to enqueue for computation</param>
 public void AddToTodo(ISourceScript script)
 {
     if (!IsIncluded(script))
     {
         AddFile(script, false, script.IsInline);
         if (script.IsInline)
         {
             doneState.Insert(0, ProcessStage.Queued);
         }
         else
         {
             doneState.Add(ProcessStage.Queued);
         }
     }
 }
示例#27
0
        public override bool FullScriptStage(ISourceScript file, ISourceManager todo, IDefinitions defs)
        {
            List <string> source = file.GetSource().ToList();

            for (int i = source.Count - 1; i >= 0; i--)
            {
                if (i < source.Count - 1 && source[i].TrimEnd().EndsWith(MultiLineKeyword))
                {
                    string newstr = source[i].Substring(0, source[i].Length - MultiLineKeyword.Length) + source[i + 1];
                    source.RemoveAt(i + 1);
                    source[i] = newstr;
                }
            }
            file.SetSource(source.ToArray());
            return(true);
        }
示例#28
0
 /// <summary>
 /// Runs the specified stage on the passed script
 /// </summary>
 /// <param name="stage">The stage of the current processing</param>
 /// <param name="script">the script to be processed</param>
 /// <param name="sourceManager"></param>
 /// <param name="defTable">the definitions that are used</param>
 /// <returns></returns>
 private static bool RunStages(PreProcessor pp, ProcessStage stage, ISourceScript script, ISourceManager sourceManager,
                               IDefinitions defTable)
 {
     if (!pp.RunPluginStage(PluginType.LINE_PLUGIN_BEFORE, stage, script, sourceManager, defTable))
     {
         return(false);
     }
     if (stage != ProcessStage.ON_FINISH_UP && !pp.RunPluginStage(PluginType.FULL_SCRIPT_PLUGIN, stage, script, sourceManager, defTable))
     {
         return(false);
     }
     if (!pp.RunPluginStage(PluginType.LINE_PLUGIN_AFTER, stage, script, sourceManager, defTable))
     {
         return(false);
     }
     return(true);
 }
示例#29
0
        public bool FullScriptStage(ISourceScript file, ISourceManager sourceManager, IDefinitions defs)
        {
            if (!file.HasValueOfType <string[]>("genParams"))
            {
                return(true);                                             //No error, we just dont have any generic parameters to replace.
            }
            string[] GenParams = file.GetValueFromCache <string[]>("genParams");

            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Discovering Generic Keywords...");
            if (GenParams != null && GenParams.Length > 0)
            {
                for (var i = GenParams.Length - 1; i >= 0; i--)
                {
                    this.Log(DebugLevel.LOGS, Verbosity.LEVEL6, "Replacing Keyword {0}{1} with {2} in file {3}", GenericKeyword, i, GenParams[i], file.GetKey());
                    Utils.ReplaceKeyWord(file.GetSource(), GenParams[i],
                                         GenericKeyword + i);
                }
            }


            this.Log(DebugLevel.LOGS, Verbosity.LEVEL5, "Generic Keyword Replacement Finished");

            return(true);
        }
示例#30
0
        public override bool FullScriptStage(ISourceScript script, ISourceManager sourceManager, IDefinitions defs)
        {
            Logger.Log(LogType.Log, "Disovering Include Statments...", PLUGIN_MIN_SEVERITY);
            List <string> source      = script.GetSource().ToList();
            string        currentPath = Path.GetDirectoryName(script.GetFileInterface().GetFilePath());
            bool          hasIncludedInline;

            do
            {
                hasIncludedInline = false;
                for (int i = source.Count - 1; i >= 0; i--)
                {
                    if (Utils.IsStatement(source[i], IncludeInlineKeyword))
                    {
                        Logger.Log(LogType.Log, "Found Inline Include Statement...", PLUGIN_MIN_SEVERITY + 1);
                        string[] args = Utils.SplitAndRemoveFirst(source[i], Separator);
                        if (args.Length == 0)
                        {
                            Logger.Log(LogType.Error, "No File Specified", 1);
                            continue;
                        }

                        if (Utils.FileExistsRelativeTo(currentPath, args[0]))
                        {
                            Logger.Log(LogType.Log, "Replacing Inline Keyword with file content",
                                       PLUGIN_MIN_SEVERITY + 2);
                            source.RemoveAt(i);

                            source.InsertRange(i, IOManager.ReadAllLines(Path.Combine(currentPath, args[0])));
                            hasIncludedInline = true;
                        }
                        else
                        {
                            Logger.Log(LogType.Error, $"File does not exist: {args[0]}", 1);
                        }
                    }
                }

                script.SetSource(source.ToArray());
            } while (hasIncludedInline);


            string[] incs = Utils.FindStatements(source.ToArray(), IncludeKeyword);

            foreach (string includes in incs)
            {
                Logger.Log(LogType.Log, $"Processing Statement: {includes}", PLUGIN_MIN_SEVERITY + 1);
                bool tmp = GetISourceScript(sourceManager, includes, currentPath, out List <ISourceScript> sources);
                if (tmp)
                {
                    foreach (ISourceScript sourceScript in sources)
                    {
                        Logger.Log(LogType.Log,
                                   $"Processing Include: {Path.GetFileName(sourceScript.GetFileInterface().GetKey())}",
                                   PLUGIN_MIN_SEVERITY + 2);

                        if (!sourceManager.IsIncluded(sourceScript))
                        {
                            sourceManager.AddToTodo(sourceScript);
                        }
                        else
                        {
                            sourceManager.FixOrder(sourceScript);
                        }
                    }
                }
                else
                {
                    return
                        (false); //We crash if we didnt find the file. but if the user forgets to specify the path we will just log the error
                }
            }

            Logger.Log(LogType.Log, "Inclusion of Files Finished", PLUGIN_MIN_SEVERITY);
            return(true);
        }