Inheritance: CodeAccessSecurityAttribute
Exemplo n.º 1
0
        private List <LogInfo> ValidateUISection(PluginSection section)
        {
            // Force parsing of code, bypassing caching by section.GetUICodes()
            List <string>    lines   = section.GetLines();
            SectionAddress   addr    = new SectionAddress(p, section);
            List <UICommand> uiCodes = UIParser.ParseRawLines(lines, addr, out List <LogInfo> logs);

            foreach (UICommand uiCmd in uiCodes)
            {
                switch (uiCmd.Type)
                {
                case UIType.CheckBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_CheckBox));
                    UIInfo_CheckBox info = uiCmd.Info as UIInfo_CheckBox;

                    if (info.SectionName != null)
                    {
                        if (p.Sections.ContainsKey(info.SectionName))         // Only if section exists
                        {
                            logs.AddRange(ValidateCodeSection(p.Sections[info.SectionName]));
                        }
                    }
                }
                break;

                case UIType.Button:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_Button));
                    UIInfo_Button info = uiCmd.Info as UIInfo_Button;

                    if (info.SectionName != null)
                    {
                        if (p.Sections.ContainsKey(info.SectionName))         // Only if section exists
                        {
                            logs.AddRange(ValidateCodeSection(p.Sections[info.SectionName]));
                        }
                    }
                }
                break;

                case UIType.RadioButton:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioButton));
                    UIInfo_RadioButton info = uiCmd.Info as UIInfo_RadioButton;

                    if (info.SectionName != null)
                    {
                        if (p.Sections.ContainsKey(info.SectionName))         // Only if section exists
                        {
                            logs.AddRange(ValidateCodeSection(p.Sections[info.SectionName]));
                        }
                    }
                }
                break;
                }
            }

            return(logs);
        }
Exemplo n.º 2
0
    protected virtual async Task Write(IEnumerable <PluginRecord> data, IFileOutputFormatterOptions options)
    {
        if (options is null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        if (string.IsNullOrWhiteSpace(options.Path))
        {
            throw new ArgumentException(nameof(options.Path));
        }

        var document = Document.Create("List of VSTs");

        var detailsList = data.ToList();

        var projectSection = new ProjectSection();

        projectSection.Add(detailsList);

        var pluginSection = new PluginSection();

        pluginSection.Add(detailsList);

        var mainIndex = new MainIndex("main-index", "Main index");

        mainIndex.Add(new ISection[] { projectSection, pluginSection });

        document.AddMainIndex(mainIndex);
        document.AddSection(projectSection);
        document.AddSection(pluginSection);

        document.Save(options.Path);
        await Task.CompletedTask;
    }
Exemplo n.º 3
0
        public static List <LogInfo> Visible(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>(1);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Visible));
            CodeInfo_Visible info = cmd.Info as CodeInfo_Visible;

            string visibilityStr = StringEscaper.Preprocess(s, info.Visibility);
            bool   visibility    = false;

            if (visibilityStr.Equals("True", StringComparison.OrdinalIgnoreCase))
            {
                visibility = true;
            }
            else if (visibilityStr.Equals("False", StringComparison.OrdinalIgnoreCase) == false)
            {
                logs.Add(new LogInfo(LogState.Error, $"Invalid boolean value [{visibilityStr}]"));
                return(logs);
            }

            Plugin        p     = cmd.Addr.Plugin;
            PluginSection iface = p.GetInterface(out string ifaceSecName);

            if (iface == null)
            {
                logs.Add(new LogInfo(LogState.Error, $"Plugin [{cmd.Addr.Plugin.ShortPath}] does not have section [{ifaceSecName}]"));
                return(logs);
            }

            List <UICommand> uiCodes = iface.GetUICodes(true);
            UICommand        uiCmd   = uiCodes.Find(x => x.Key.Equals(info.InterfaceKey, StringComparison.OrdinalIgnoreCase));

            if (uiCmd == null)
            {
                logs.Add(new LogInfo(LogState.Error, $"Cannot find interface control [{info.InterfaceKey}] from section [{ifaceSecName}]"));
                return(logs);
            }

            if (uiCmd.Visibility != visibility)
            {
                uiCmd.Visibility = visibility;
                uiCmd.Update();

                // Re-render Plugin
                Application.Current.Dispatcher.Invoke(() =>
                {
                    MainWindow w = (Application.Current.MainWindow as MainWindow);
                    if (w.CurMainTree.Plugin == cmd.Addr.Plugin)
                    {
                        w.DrawPlugin(cmd.Addr.Plugin);
                    }
                });
            }

            logs.Add(new LogInfo(LogState.Success, $"Interface control [{info.InterfaceKey}]'s visibility set to [{visibility}]"));

            return(logs);
        }
Exemplo n.º 4
0
 public static void DisableSetLocal(EngineState s, PluginSection section)
 {
     if (s.SetLocalSection != null && s.SetLocalSection.Equals(section) &&
         s.LocalVarsBackup != null)
     {
         s.Variables.SetVarDict(VarsType.Local, s.LocalVarsBackup);
         s.LocalVarsBackup = null;
         s.SetLocalSection = null;
     }
 }
        /// <summary>
        /// Requires the integration test support.
        /// </summary>
        /// <param name="feature">The feature.</param>
        /// <returns>The base class name.</returns>
        protected virtual string GetLiveTestBaseClassName(Feature feature)
        {
            if (feature.Tags != null)
            {
                PluginSection pluginSection = this.GetConfiguration(Path.GetDirectoryName(feature.SourceFile));

                if ((pluginSection != null) && (pluginSection.BaseClass != null) && (!string.IsNullOrEmpty(pluginSection.BaseClass.Type)))
                {
                    return(pluginSection.BaseClass.Type);
                }
            }

            return(typeof(LiveTest).FullName);
        }
Exemplo n.º 6
0
        public List <LogInfo> LoadLocalMacroDict(Plugin p, bool append, string sectionName = "Variables")
        {
            if (p.Sections.ContainsKey(sectionName))
            {
                PluginSection section = p.Sections[sectionName];

                // [Variables]'s type is SectionDataType.Lines
                // Pick key-value only if key is not wrapped by %
                SectionAddress addr = new SectionAddress(p, section);
                Dictionary <string, string> dict = Ini.ParseIniLinesIniStyle(section.GetLines());
                return(LoadLocalMacroDict(addr, dict, append));
            }
            else
            {
                return(new List <LogInfo>());
            }
        }
Exemplo n.º 7
0
        private List <LogInfo> ValidateCodeSection(PluginSection section)
        {
            // Already processed, so skip
            if (visitedSections.Contains(section))
            {
                return(new List <LogInfo>());
            }

            // Force parsing of code, bypassing caching by section.GetCodes()
            List <string>      lines = section.GetLines();
            SectionAddress     addr  = new SectionAddress(p, section);
            List <CodeCommand> codes = CodeParser.ParseStatements(lines, addr, out List <LogInfo> logs);

            visitedSections.Add(section);
            InternalValidateCodes(codes, logs);

            return(logs);
        }
        /// <summary>
        /// The decorate with discovered tag mappings.
        /// </summary>
        /// <param name="featureFile">The feature File.</param>
        /// <param name="tagName">The tag Name.</param>
        /// <param name="method">The method.</param>
        protected virtual void DecorateWithDiscoveredTagMappings(string featureFile, string tagName, CodeMemberMethod method)
        {
            PluginSection pluginSection = this.GetConfiguration(Path.GetDirectoryName(featureFile));
            TagMapping    tagMapping    = null;

            if (pluginSection != null)
            {
                tagMapping = pluginSection.TagMappings.Cast <TagMapping>().SingleOrDefault(t => t.Tag == tagName);
            }

            if (tagMapping != null)
            {
                CodeAttributeDeclarationCollection attributeDeclarations = GetAttributeDeclarationsFromTagMapping(tagMapping);

                if (attributeDeclarations != null)
                {
                    method.CustomAttributes.AddRange(attributeDeclarations);
                }
            }
        }
Exemplo n.º 9
0
        public EngineState(Project project, Logger logger, MainViewModel mainModel, Plugin runSingle = null, string entrySection = "Process")
        {
            this.Project = project;
            this.Logger  = logger;

            Macro = new Macro(Project, Variables, out List <LogInfo> macroLogs);
            logger.Build_Write(BuildId, macroLogs);

            if (runSingle == null)
            {
                Plugins = project.ActivePlugins;

                CurrentPlugin    = Plugins[0]; // Main Plugin, since its internal level is -256
                CurrentPluginIdx = 0;

                RunOnePlugin = false;
            }
            else
            {  // Run only one plugin
                Plugins = new List <Plugin>(1)
                {
                    runSingle
                };

                CurrentPlugin    = runSingle;
                CurrentPluginIdx = Plugins.IndexOf(runSingle);

                RunOnePlugin = true;
            }

            CurrentSection = null;
            EntrySection   = entrySection;

            CurSectionParams = new Dictionary <int, string>();

            MainViewModel = mainModel;
        }
Exemplo n.º 10
0
        public static List <LogInfo> Set(EngineState s, CodeCommand cmd)
        {
            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Set));
            CodeInfo_Set info = cmd.Info as CodeInfo_Set;

            Variables.VarKeyType varType = Variables.DetermineType(info.VarKey);
            if (varType == Variables.VarKeyType.None)
            {
                // Check Macro
                if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled).Success) // Macro Name Validation
                {
                    string macroCommand = StringEscaper.Preprocess(s, info.VarValue);

                    if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase))
                    {
                        macroCommand = null;
                    }

                    LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Addr, info.Permanent);
                    return(new List <LogInfo>(1)
                    {
                        log
                    });
                }
            }

            // [WB082 Behavior]
            // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface.
            // Need to investigate where the logs are saved in this case.
            switch (info.Permanent)
            {
            case true:
            {         // Check if interface contains VarKey
                List <LogInfo> logs = new List <LogInfo>();

                if (Variables.DetermineType(info.VarKey) != Variables.VarKeyType.Variable)
                {
                    goto case false;
                }

                string varKey     = Variables.TrimPercentMark(info.VarKey);
                string finalValue = StringEscaper.Preprocess(s, info.VarValue);

                #region Set UI
                Plugin        p     = cmd.Addr.Plugin;
                PluginSection iface = p.GetInterface(out string sectionName);
                if (iface == null)
                {
                    goto case false;
                }

                List <UICommand> uiCmds = iface.GetUICodes(true);
                UICommand        uiCmd  = uiCmds.Find(x => x.Key.Equals(varKey));
                if (uiCmd == null)
                {
                    goto case false;
                }

                bool match = false;
                switch (uiCmd.Type)
                {
                case UIType.TextBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_TextBox));
                    UIInfo_TextBox uiInfo = uiCmd.Info as UIInfo_TextBox;

                    uiInfo.Value = finalValue;

                    logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]"));
                    match = true;
                }
                break;

                case UIType.NumberBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_NumberBox));
                    UIInfo_NumberBox uiInfo = uiCmd.Info as UIInfo_NumberBox;

                    // WB082 just write string value in case of error, but PEBakery will throw warning
                    if (!NumberHelper.ParseInt32(finalValue, out int intVal))
                    {
                        logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid integer"));
                        return(logs);
                    }

                    uiInfo.Value = intVal;

                    logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]"));
                    match = true;
                }
                break;

                case UIType.CheckBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_CheckBox));
                    UIInfo_CheckBox uiInfo = uiCmd.Info as UIInfo_CheckBox;

                    if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase))
                    {
                        uiInfo.Value = true;

                        logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [True]"));
                        match = true;
                    }
                    else if (finalValue.Equals("False", StringComparison.OrdinalIgnoreCase))
                    {
                        uiInfo.Value = false;

                        logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [False]"));
                        match = true;
                    }
                    else
                    {                 // WB082 just write string value in case of error, but PEBakery will throw warning
                        logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid boolean"));
                        return(logs);
                    }
                }
                break;

                case UIType.ComboBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_ComboBox));
                    UIInfo_ComboBox uiInfo = uiCmd.Info as UIInfo_ComboBox;

                    int idx = uiInfo.Items.FindIndex(x => x.Equals(finalValue, StringComparison.OrdinalIgnoreCase));
                    if (idx == -1)
                    {                 // Invalid Index
                        logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] not found in item list"));
                        return(logs);
                    }

                    uiInfo.Index = idx;
                    uiCmd.Text   = uiInfo.Items[idx];

                    logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{uiCmd.Text}]"));
                    match = true;
                }
                break;

                case UIType.RadioButton:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioButton));
                    UIInfo_RadioButton uiInfo = uiCmd.Info as UIInfo_RadioButton;

                    if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase))
                    {
                        uiInfo.Selected = true;

                        logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to true]"));
                        match = true;
                    }
                    else if (finalValue.Equals("False", StringComparison.OrdinalIgnoreCase))
                    {
                        uiInfo.Selected = false;

                        logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [False]"));
                        match = true;
                    }
                    else
                    {                 // WB082 just write string value, but PEBakery will ignore and throw and warning
                        logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid boolean"));
                        return(logs);
                    }
                }
                break;

                case UIType.FileBox:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_FileBox));
                    UIInfo_FileBox uiInfo = uiCmd.Info as UIInfo_FileBox;

                    uiCmd.Text = finalValue;

                    logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]"));
                    match = true;
                }
                break;

                case UIType.RadioGroup:
                {
                    Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioGroup));
                    UIInfo_RadioGroup uiInfo = uiCmd.Info as UIInfo_RadioGroup;

                    int idx = uiInfo.Items.FindIndex(x => x.Equals(finalValue, StringComparison.OrdinalIgnoreCase));
                    if (idx == -1)
                    {                 // Invalid Index
                        logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] not found in item list"));
                        return(logs);
                    }

                    uiInfo.Selected = idx;

                    logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]"));
                    match = true;
                }
                break;
                }

                if (match)
                {
                    uiCmd.Update();

                    logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false));
                    return(logs);
                }
                else
                {
                    goto case false;
                }
                #endregion
            }

            case false:
            default:
                return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent));
            }
        }
Exemplo n.º 11
0
        public Macro(Project project, Variables variables, out List <LogInfo> logs)
        {
            macroEnabled = true;
            logs         = new List <LogInfo>();
            if (project.MainPlugin.Sections.ContainsKey("Variables") == false)
            {
                macroEnabled = false;
                logs.Add(new LogInfo(LogState.Info, "Macro not defined"));
                return;
            }

            Dictionary <string, string> varDict = Ini.ParseIniLinesVarStyle(project.MainPlugin.Sections["Variables"].GetLines());

            if ((varDict.ContainsKey("API") && varDict.ContainsKey("APIVAR")) == false)
            {
                macroEnabled = false;
                logs.Add(new LogInfo(LogState.Info, "Macro not defined"));
                return;
            }

            // Get macroPlugin
            string rawPluginPath   = varDict["API"];
            string macroPluginPath = variables.Expand(varDict["API"]); // Need Expansion

            macroPlugin = project.AllPlugins.Find(x => string.Equals(x.FullPath, macroPluginPath, StringComparison.OrdinalIgnoreCase));
            if (macroPlugin == null)
            {
                macroEnabled = false;
                logs.Add(new LogInfo(LogState.Error, $"Macro defined but unable to find macro plugin [{rawPluginPath}"));
                return;
            }

            // Get macroPlugin
            if (macroPlugin.Sections.ContainsKey(varDict["APIVAR"]) == false)
            {
                macroEnabled = false;
                logs.Add(new LogInfo(LogState.Error, $"Macro defined but unable to find macro section [{varDict["APIVAR"]}"));
                return;
            }
            macroSection = macroPlugin.Sections[varDict["APIVAR"]];
            variables.SetValue(VarsType.Global, "API", macroPluginPath);
            if (macroPlugin.Sections.ContainsKey("Variables"))
            {
                variables.AddVariables(VarsType.Global, macroPlugin.Sections["Variables"]);
            }

            // Import Section [APIVAR]'s variables, such as '%Shc_Mode%=0'
            variables.AddVariables(VarsType.Global, macroSection);

            // Parse Section [APIVAR] into MacroDict
            {
                SectionAddress addr = new SectionAddress(macroPlugin, macroSection);
                Dictionary <string, string> rawDict = Ini.ParseIniLinesIniStyle(macroSection.GetLines());
                foreach (var kv in rawDict)
                {
                    try
                    {
                        if (Regex.Match(kv.Key, Macro.MacroNameRegex, RegexOptions.Compiled).Success) // Macro Name Validation
                        {
                            macroDict[kv.Key] = CodeParser.ParseStatement(kv.Value, addr);
                        }
                        else
                        {
                            logs.Add(new LogInfo(LogState.Error, $"Invalid macro name [{kv.Key}]"));
                        }
                    }
                    catch (Exception e)
                    {
                        logs.Add(new LogInfo(LogState.Error, e));
                    }
                }
            }

            // Parse MainPlugin's section [Variables] into MacroDict
            // (Written by SetMacro, ... ,PERMANENT
            if (project.MainPlugin.Sections.ContainsKey("Variables"))
            {
                PluginSection  permaSection         = project.MainPlugin.Sections["Variables"];
                SectionAddress addr                 = new SectionAddress(project.MainPlugin, permaSection);
                Dictionary <string, string> rawDict = Ini.ParseIniLinesIniStyle(permaSection.GetLines());
                foreach (var kv in rawDict)
                {
                    try
                    {
                        if (Regex.Match(kv.Key, Macro.MacroNameRegex, RegexOptions.Compiled).Success) // Macro Name Validation
                        {
                            macroDict[kv.Key] = CodeParser.ParseStatement(kv.Value, addr);
                        }
                        else
                        {
                            logs.Add(new LogInfo(LogState.Error, $"Invalid macro name [{kv.Key}]"));
                        }
                    }
                    catch (Exception e)
                    {
                        logs.Add(new LogInfo(LogState.Error, e));
                    }
                }
            }
        }
        /// <summary>
        /// The can decorate from.
        /// </summary>
        /// <param name="tagName">The tag name.</param>
        /// <param name="generationContext">The generation context.</param>
        /// <param name="testMethod">The test method.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        public bool CanDecorateFrom(string tagName, TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
        {
            PluginSection pluginSection = this.GetConfiguration(Path.GetDirectoryName(generationContext.Feature.SourceFile));

            return((pluginSection != null) && pluginSection.TagMappings.Cast <TagMapping>().Any(tagMapping => tagMapping.Tag == tagName));
        }
Exemplo n.º 13
0
        private void SyntaxCheckButton_Click(object sender, RoutedEventArgs e)
        {
            if (m.Syntax_InputCode.Equals(string.Empty, StringComparison.Ordinal))
            {
                m.Syntax_Output = "No Code";
                return;
            }

            Project project = m.CodeBox_CurrentProject;

            Plugin        p = project.MainPlugin;
            PluginSection section;

            if (project.MainPlugin.Sections.ContainsKey("Process"))
            {
                section = p.Sections["Process"];
            }
            else
            {
                section = new PluginSection(p, "Process", SectionType.Code, new List <string>(), 1);
            }
            SectionAddress addr = new SectionAddress(p, section);

            List <string>      lines = m.Syntax_InputCode.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
            List <CodeCommand> cmds  = CodeParser.ParseStatements(lines, addr, out List <LogInfo> errorLogs);

            // Check Macros
            Macro macro = new Macro(project, project.Variables, out List <LogInfo> macroLogs);

            if (macro.MacroEnabled)
            {
                foreach (CodeCommand cmd in cmds)
                {
                    if (cmd.Type == CodeType.Macro)
                    {
                        Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Macro));
                        CodeInfo_Macro info = cmd.Info as CodeInfo_Macro;

                        if (!macro.MacroDict.ContainsKey(info.MacroType))
                        {
                            errorLogs.Add(new LogInfo(LogState.Error, $"Invalid CodeType or Macro [{info.MacroType}]", cmd));
                        }
                    }
                }
            }

            if (0 < errorLogs.Count)
            {
                StringBuilder b = new StringBuilder();
                for (int i = 0; i < errorLogs.Count; i++)
                {
                    LogInfo log = errorLogs[i];
                    b.AppendLine($"[{i + 1}/{errorLogs.Count}] {log.Message} ({log.Command})");
                }
                m.Syntax_Output = b.ToString();
            }
            else
            {
                m.Syntax_Output = "No Error";
            }
        }
Exemplo n.º 14
0
        public static List <LogInfo> Set(EngineState s, CodeCommand cmd)
        {
            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Set));
            CodeInfo_Set info = cmd.Info as CodeInfo_Set;

            Variables.VarKeyType varType = Variables.DetermineType(info.VarKey);
            if (varType == Variables.VarKeyType.None)
            {
                // Check Macro
                if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled).Success) // Macro Name Validation
                {
                    string macroCommand = StringEscaper.Preprocess(s, info.VarValue);

                    if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase))
                    {
                        macroCommand = null;
                    }

                    LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Addr, info.Permanent, false);
                    return(new List <LogInfo>(1)
                    {
                        log
                    });
                }
            }

            // [WB082 Behavior]
            // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface.
            // Need to investigate where the logs are saved in this case.
            switch (info.Permanent)
            {
            case true:
            {         // Check if interface contains VarKey
                List <LogInfo> logs = new List <LogInfo>();

                if (Variables.DetermineType(info.VarKey) != Variables.VarKeyType.Variable)
                {
                    goto case false;
                }

                string varKey     = Variables.TrimPercentMark(info.VarKey);
                string finalValue = StringEscaper.Preprocess(s, info.VarValue);

                #region Set UI
                Plugin        p     = cmd.Addr.Plugin;
                PluginSection iface = p.GetInterface(out string sectionName);
                if (iface == null)
                {
                    goto case false;
                }

                List <UICommand> uiCmds = iface.GetUICodes(true);
                UICommand        uiCmd  = uiCmds.Find(x => x.Key.Equals(varKey, StringComparison.OrdinalIgnoreCase));
                if (uiCmd == null)
                {
                    goto case false;
                }

                bool match = uiCmd.SetValue(finalValue, false, out List <LogInfo> varLogs);
                logs.AddRange(varLogs);

                if (match)
                {
                    uiCmd.Update();

                    logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false));
                    return(logs);
                }
                else
                {
                    goto case false;
                }
                #endregion
            }

            case false:
            default:
                return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent));
            }
        }
Exemplo n.º 15
0
        public static List <LogInfo> ReadInterface(EngineState s, CodeCommand cmd)
        { // ReadInterface,<Element>,<PluginFile>,<Section>,<Key>,<DestVar>
            List <LogInfo> logs = new List <LogInfo>(1);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_ReadInterface));
            CodeInfo_ReadInterface info = cmd.Info as CodeInfo_ReadInterface;

            string pluginFile = StringEscaper.Preprocess(s, info.PluginFile);
            string section    = StringEscaper.Preprocess(s, info.Section);
            string key        = StringEscaper.Preprocess(s, info.Key);

            Plugin p = Engine.GetPluginInstance(s, cmd, s.CurrentPlugin.FullPath, pluginFile, out bool inCurrentPlugin);

            if (!p.Sections.ContainsKey(section))
            {
                logs.Add(new LogInfo(LogState.Error, $"Plugin [{pluginFile}] does not have section [{section}]"));
                return(logs);
            }

            PluginSection    iface  = p.Sections[section];
            List <UICommand> uiCmds = iface.GetUICodes(true);
            UICommand        uiCmd  = uiCmds.Find(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (uiCmd == null)
            {
                logs.Add(new LogInfo(LogState.Error, $"Interface [{key}] does not exist"));
                return(logs);
            }

            string destStr;

            switch (info.Element)
            {
            case InterfaceElement.Text:
                destStr = uiCmd.Text;
                break;

            case InterfaceElement.Visible:
                destStr = uiCmd.Visibility.ToString();
                break;

            case InterfaceElement.PosX:
                destStr = ((int)uiCmd.Rect.X).ToString();
                break;

            case InterfaceElement.PosY:
                destStr = ((int)uiCmd.Rect.Y).ToString();
                break;

            case InterfaceElement.Width:
                destStr = ((int)uiCmd.Rect.Width).ToString();
                break;

            case InterfaceElement.Height:
                destStr = ((int)uiCmd.Rect.Height).ToString();
                break;

            case InterfaceElement.Value:
                destStr = uiCmd.GetValue();
                if (destStr == null)
                {
                    logs.Add(new LogInfo(LogState.Error, $"Reading [Value] from [{uiCmd.Type}] is not supported"));
                    return(logs);
                }
                break;

            default:
                throw new InternalException($"Internal Logic Error at ReadInterface");
            }

            // Do not expand read values
            List <LogInfo> varLogs = Variables.SetVariable(s, info.DestVar, destStr, false, false, false);

            logs.AddRange(varLogs);

            return(logs);
        }
Exemplo n.º 16
0
        public static List <LogInfo> WriteInterface(EngineState s, CodeCommand cmd)
        { // WriteInterface,<Element>,<PluginFile>,<Section>,<Key>,<Value>
            List <LogInfo> logs = new List <LogInfo>(2);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_WriteInterface));
            CodeInfo_WriteInterface info = cmd.Info as CodeInfo_WriteInterface;

            string pluginFile = StringEscaper.Preprocess(s, info.PluginFile);
            string section    = StringEscaper.Preprocess(s, info.Section);
            string key        = StringEscaper.Preprocess(s, info.Key);
            string finalValue = StringEscaper.Preprocess(s, info.Value);

            Plugin p = Engine.GetPluginInstance(s, cmd, s.CurrentPlugin.FullPath, pluginFile, out bool inCurrentPlugin);

            if (!p.Sections.ContainsKey(section))
            {
                logs.Add(new LogInfo(LogState.Error, $"Plugin [{pluginFile}] does not have section [{section}]"));
                return(logs);
            }

            PluginSection    iface  = p.Sections[section];
            List <UICommand> uiCmds = iface.GetUICodes(true);
            UICommand        uiCmd  = uiCmds.Find(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (uiCmd == null)
            {
                logs.Add(new LogInfo(LogState.Error, $"Interface [{key}] does not exist"));
                return(logs);
            }

            switch (info.Element)
            {
            case InterfaceElement.Text:
                uiCmd.Text = finalValue;
                break;

            case InterfaceElement.Visible:
            {
                bool visibility = false;
                if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase))
                {
                    visibility = true;
                }
                else if (!finalValue.Equals("False", StringComparison.OrdinalIgnoreCase))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid boolean value"));
                    return(logs);
                }

                uiCmd.Visibility = visibility;
            }
            break;

            case InterfaceElement.PosX:
            {
                if (!NumberHelper.ParseInt32(finalValue, out int x))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer"));
                    return(logs);
                }

                uiCmd.Rect.X = x;
            }
            break;

            case InterfaceElement.PosY:
            {
                if (!NumberHelper.ParseInt32(finalValue, out int y))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer"));
                    return(logs);
                }

                uiCmd.Rect.Y = y;
            }
            break;

            case InterfaceElement.Width:
            {
                if (!NumberHelper.ParseInt32(finalValue, out int width))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer"));
                    return(logs);
                }

                uiCmd.Rect.Width = width;
            }
            break;

            case InterfaceElement.Height:
            {
                if (!NumberHelper.ParseInt32(finalValue, out int height))
                {
                    logs.Add(new LogInfo(LogState.Error, $"[{finalValue}] is not a valid integer"));
                    return(logs);
                }

                uiCmd.Rect.Height = height;
            }
            break;

            case InterfaceElement.Value:
            {
                bool success = uiCmd.SetValue(finalValue, false, out List <LogInfo> varLogs);
                logs.AddRange(varLogs);

                if (success == false && varLogs.Count == 0)
                {
                    logs.Add(new LogInfo(LogState.Error, $"Wring [Value] to [{uiCmd.Type}] is not supported"));
                    return(logs);
                }
            }
            break;

            default:
                throw new InternalException($"Internal Logic Error at WriteInterface");
            }

            // Update uiCmd into file
            uiCmd.Update();

            // Rerender Plugin
            Application.Current?.Dispatcher.Invoke(() =>
            { // Application.Current is null in unit test
                MainWindow w = (Application.Current.MainWindow as MainWindow);
                if (w.CurMainTree.Plugin == cmd.Addr.Plugin)
                {
                    w.DrawPlugin(cmd.Addr.Plugin);
                }
            });

            return(logs);
        }
Exemplo n.º 17
0
 public static void EnableSetLocal(EngineState s, PluginSection section)
 {
     s.LocalVarsBackup = s.Variables.GetVarDict(VarsType.Local);
     s.SetLocalSection = section;
 }
Exemplo n.º 18
0
        public Task <long> Run(string runName)
        {
            task = Task.Run(() =>
            {
                s.BuildId = s.Logger.Build_Init(s, runName);

                s.MainViewModel.BuildFullProgressBarMax = s.Plugins.Count;

                // Update project variables
                s.Project.UpdateProjectVariables();

                while (true)
                {
                    ReadyRunPlugin(s);

                    // Run Main Section
                    if (s.CurrentPlugin.Sections.ContainsKey(s.EntrySection))
                    {
                        PluginSection mainSection = s.CurrentPlugin.Sections[s.EntrySection];
                        SectionAddress addr       = new SectionAddress(s.CurrentPlugin, mainSection);
                        s.Logger.LogStartOfSection(s, addr, 0, true, null, null);
                        Engine.RunSection(s, new SectionAddress(s.CurrentPlugin, mainSection), new List <string>(), 1, false);
                        s.Logger.LogEndOfSection(s, addr, 0, true, null);
                    }

                    // End of Plugin
                    FinishRunPlugin(s);

                    // OnPluginExit event callback
                    Engine.CheckAndRunCallback(s, ref s.OnPluginExit, FinishEventParam(s), "OnPluginExit");

                    if (s.Plugins.Count - 1 <= s.CurrentPluginIdx ||
                        s.RunOnePlugin || s.ErrorHaltFlag || s.UserHaltFlag || s.CmdHaltFlag)
                    { // End of Build
                        bool alertErrorHalt = s.ErrorHaltFlag;
                        bool alertUserHalt  = s.UserHaltFlag;
                        bool alertCmdHalt   = s.CmdHaltFlag;

                        if (s.UserHaltFlag)
                        {
                            s.MainViewModel.PluginDescriptionText = "Build stop requested by user";
                            s.Logger.Build_Write(s, Logger.LogSeperator);
                            s.Logger.Build_Write(s, new LogInfo(LogState.Info, "Build stop requested by user"));
                        }

                        string eventParam = FinishEventParam(s);

                        // Reset Halt Flags before running OnBuildExit
                        s.ErrorHaltFlag = false;
                        s.UserHaltFlag  = false;
                        s.CmdHaltFlag   = false;

                        // OnBuildExit event callback
                        Engine.CheckAndRunCallback(s, ref s.OnBuildExit, eventParam, "OnBuildExit", true);

                        if (alertUserHalt)
                        {
                            MessageBox.Show("Build Stopped by User", "Build Halt", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else if (alertCmdHalt)
                        {
                            MessageBox.Show("Build Stopped by Halt Command", "Build Halt", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else if (alertErrorHalt)
                        {
                            MessageBox.Show("Build Stopped by Error", "Build Halt", MessageBoxButton.OK, MessageBoxImage.Information);
                        }

                        break;
                    }

                    // Run Next Plugin
                    s.CurrentPluginIdx     += 1;
                    s.CurrentPlugin         = s.Plugins[s.CurrentPluginIdx];
                    s.PassCurrentPluginFlag = false;
                }

                s.Logger.Build_Finish(s);

                return(s.BuildId);
            });

            return(task);
        }
Exemplo n.º 19
0
        public static List <LogInfo> VisibleOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>(8);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_VisibleOp));
            CodeInfo_VisibleOp infoOp = cmd.Info as CodeInfo_VisibleOp;

            Plugin        p     = cmd.Addr.Plugin;
            PluginSection iface = p.GetInterface(out string ifaceSecName);

            if (iface == null)
            {
                logs.Add(new LogInfo(LogState.Error, $"Plugin [{cmd.Addr.Plugin.ShortPath}] does not have section [{ifaceSecName}]"));
                return(logs);
            }

            List <UICommand> uiCodes = iface.GetUICodes(true);

            List <Tuple <string, bool> > prepArgs = new List <Tuple <string, bool> >();

            foreach (CodeInfo_Visible info in infoOp.InfoList)
            {
                string visibilityStr = StringEscaper.Preprocess(s, info.Visibility);
                bool   visibility    = false;
                if (visibilityStr.Equals("True", StringComparison.OrdinalIgnoreCase))
                {
                    visibility = true;
                }
                else if (visibilityStr.Equals("False", StringComparison.OrdinalIgnoreCase) == false)
                {
                    throw new ExecuteException($"Invalid boolean value [{visibilityStr}]");
                }

                prepArgs.Add(new Tuple <string, bool>(info.InterfaceKey, visibility));
            }

            List <UICommand> uiCmdList = new List <UICommand>();

            foreach (Tuple <string, bool> args in prepArgs)
            {
                UICommand uiCmd = uiCodes.Find(x => x.Key.Equals(args.Item1, StringComparison.OrdinalIgnoreCase));
                if (uiCmd == null)
                {
                    logs.Add(new LogInfo(LogState.Error, $"Cannot find interface control [{args.Item1}] from section [{ifaceSecName}]"));
                    continue;
                }

                uiCmd.Visibility = args.Item2;
                uiCmdList.Add(uiCmd);
            }

            UICommand.Update(uiCmdList);

            foreach (Tuple <string, bool> args in prepArgs)
            {
                logs.Add(new LogInfo(LogState.Success, $"Interface control [{args.Item1}]'s visibility set to [{args.Item2}]"));
            }

            // Re-render Plugin
            Application.Current.Dispatcher.Invoke(() =>
            {
                MainWindow w = (Application.Current.MainWindow as MainWindow);
                if (w.CurMainTree.Plugin == cmd.Addr.Plugin)
                {
                    w.DrawPlugin(cmd.Addr.Plugin);
                }
            });

            return(logs);
        }