Beispiel #1
0
 public int GetRefreshInterval()
 {
     if (GlobalDict.ContainsKey("interval"))
     {
         return(int.Parse(GlobalDict["interval"]));
     }
     else
     {
         return(30); // 默认半小时刷新一次
     }
 }
Beispiel #2
0
 public long GetVersion()
 {
     if (GlobalDict.ContainsKey("GlobalDict"))
     {
         return(long.Parse(GlobalDict["GlobalDict"]));
     }
     else
     {
         return(0);
     }
 }
Beispiel #3
0
        public LogInfo SetMacro(string macroName, string macroCommand, ScriptSection section, bool global, bool permanent)
        {
            // Macro Name Validation
            if (!Regex.Match(macroName, MacroNameRegex, RegexOptions.Compiled | RegexOptions.CultureInvariant).Success)
            {
                return(new LogInfo(LogState.Error, $"Invalid macro name [{macroName}]"));
            }

            if (macroCommand != null)
            { // Insert
                // Try parsing
                CodeParser  parser = new CodeParser(section, Global.Setting, section.Project.Compat);
                CodeCommand cmd    = parser.ParseStatement(macroCommand);
                if (cmd.Type == CodeType.Error)
                {
                    CodeInfo_Error info = cmd.Info.Cast <CodeInfo_Error>();
                    return(new LogInfo(LogState.Error, info.ErrorMessage));
                }

                // Put into dictionary
                if (permanent) // MacroDict
                {
                    GlobalDict[macroName] = cmd;
                    if (IniReadWriter.WriteKey(section.Project.MainScript.RealPath, ScriptSection.Names.Variables, macroName, cmd.RawCode))
                    {
                        return(new LogInfo(LogState.Success, $"Permanent Macro [{macroName}] set to [{cmd.RawCode}]"));
                    }
                    else
                    {
                        return(new LogInfo(LogState.Error, $"Could not write macro into [{section.Project.MainScript.RealPath}]"));
                    }
                }

                if (global) // MacroDict
                {
                    GlobalDict[macroName] = cmd;
                    return(new LogInfo(LogState.Success, $"Global Macro [{macroName}] set to [{cmd.RawCode}]"));
                }

                LocalDict[macroName] = cmd;
                return(new LogInfo(LogState.Success, $"Local Macro [{macroName}] set to [{cmd.RawCode}]"));
            }
            else
            {
                // Delete
                // Put into dictionary
                if (permanent) // MacroDict
                {
                    if (GlobalDict.ContainsKey(macroName))
                    {
                        GlobalDict.Remove(macroName);
                        IniReadWriter.DeleteKey(section.Project.MainScript.RealPath, ScriptSection.Names.Variables, macroName);
                        return(new LogInfo(LogState.Success, $"Permanent Macro [{macroName}] deleted"));
                    }

                    return(new LogInfo(LogState.Error, $"Permanent Macro [{macroName}] not found"));
                }

                if (global) // MacroDict
                {
                    if (GlobalDict.ContainsKey(macroName))
                    {
                        GlobalDict.Remove(macroName);
                        return(new LogInfo(LogState.Success, $"Global Macro [{macroName}] deleted"));
                    }

                    return(new LogInfo(LogState.Error, $"Global Macro [{macroName}] not found"));
                }

                // LocalDict
                if (LocalDict.ContainsKey(macroName))
                {
                    LocalDict.Remove(macroName);
                    return(new LogInfo(LogState.Success, $"Local Macro [{macroName}] deleted"));
                }

                return(new LogInfo(LogState.Error, $"Local Macro [{macroName}] not found"));
            }
        }