internal bool TryGet(ISymbol symbol, out Parameter?parameter) { if (Comparer.Equals(Console, symbol)) { parameter = new ConsoleParameter(Console); return(true); } if (Comparer.Equals(InvocationContext, symbol)) { parameter = new InvocationContextParameter(InvocationContext); return(true); } if (Comparer.Equals(ParseResult, symbol)) { parameter = new ParseResultParameter(ParseResult); return(true); } if (Comparer.Equals(HelpBuilder, symbol)) { parameter = new HelpBuilderParameter(HelpBuilder); return(true); } if (Comparer.Equals(BindingContext, symbol)) { parameter = new BindingContextParameter(BindingContext); return(true); } parameter = null; return(false); }
public override CommandResultType Handle(ConsoleParameter parameter) { PacketFactory pf = new PacketFactory(new MhfSetting()); pf.Test(); return(CommandResultType.Completed); }
public override CommandResultType Handle(ConsoleParameter parameter) { if (parameter.arguments.Count == 2) { FpmfArchiveIo archiveIo = new FpmfArchiveIo(); FileAttributes attr = File.GetAttributes(parameter.arguments[0]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { string[] hedFiles = Directory.GetFiles(parameter.arguments[0], "*.hed", SearchOption.AllDirectories); for (int i = 0; i < hedFiles.Length; i++) { FpmfArchive archive = archiveIo.Open(hedFiles[i]); archiveIo.Save(archive, parameter.arguments[1]); } } else { FpmfArchive archive = archiveIo.Open(parameter.arguments[0]); archiveIo.Save(archive, parameter.arguments[1]); } return(CommandResultType.Completed); } if (parameter.arguments.Count == 1) { FpmfArchiveIo archiveIo = new FpmfArchiveIo(); archiveIo.OpenWoItm(parameter.arguments[0]); return(CommandResultType.Completed); } if (parameter.arguments.Count == 3) { FpmfArchiveIo archiveIo = new FpmfArchiveIo(); string[] hedFiles; FileAttributes attr = File.GetAttributes(parameter.arguments[1]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { hedFiles = Directory.GetFiles(parameter.arguments[1], "*.hed", SearchOption.AllDirectories); } else { hedFiles = new string[1]; hedFiles[0] = parameter.arguments[1]; } for (int i = 0; i < hedFiles.Length; i++) { if (parameter.arguments[0] == "header") { archiveIo.Header(hedFiles[i], parameter.arguments[2]); } } return(CommandResultType.Completed); } return(CommandResultType.Continue); }
protected override bool CheckMyParametersAndConfig(ConsoleParameter p, ConsoleData d) { foreach (var s in MyConfig.GetConfigurationList("Mail")) { p[DomainKey.CONFIG, $"Mail_{s.Key}"] = s.Value; } return(true); }
protected static ConsoleFunction ReadFunction(StringReader sr, string line, string methodComment) { ConsoleFunction method = new ConsoleFunction(); Match methodMatches = Patterns.MatchMethod(line); string type = methodMatches.Groups[1].Value.Trim(); string name = methodMatches.Groups[2].Value.Trim(); method.Type = type; method.Name = name; if (!string.IsNullOrEmpty(methodMatches.Groups[4].Value)) { method.IsStringlyTyped = true; } if (type.Trim().Length == 0) { throw new NotImplementedException(); } if (methodMatches.Groups.Count == 2) { return(method); } string parameters = methodMatches.Groups[3].Value.Trim(); MatchCollection paramMatches = Patterns.MatchMethodParameters(parameters); foreach (Match param in paramMatches) { string pType = param.Groups[1].Value.Trim(); string pName = param.Groups[2].Value.Trim(); ConsoleParameter cParam = new ConsoleParameter { VarArgs = Patterns.IsParamVariadic(pName), Type = pType, Name = pName.Replace("...", "") }; if (param.Groups[3].Length > 0) { string defaultValue = param.Groups[3].Value.Trim(); if (defaultValue.StartsWith("nullAsType<")) { defaultValue = "null"; } cParam.DefaultValue = defaultValue.Trim(); } method.Parameters.Add(cParam); } method.Comment = methodComment; return(method); }
protected override void DoProcess(ConsoleParameter p, ConsoleData d) { try { base.DoProcess(p, d); } catch (Exception ex) { OnTaskError(ex); throw ex; } finally { AfterExcute(); } }
public override CommandResultType Handle(ConsoleParameter parameter) { if (parameter.arguments.Count == 3) { string[] itemInfo = File.ReadAllLines(parameter.arguments[0]); string[] items = File.ReadAllLines(parameter.arguments[1]); StreamWriter outFile = new StreamWriter(parameter.arguments[2]); foreach (string infoline in itemInfo) { if (infoline.StartsWith("#")) { continue; } string infoId = infoline.Substring(0, infoline.IndexOf(",")); foreach (string itemline in items) { if (itemline.StartsWith("#") || itemline.StartsWith(",") || itemline.StartsWith("N/A")) { continue; } string itemId = itemline.Substring(0, infoline.IndexOf(",")); if (infoId == itemId) { string infoName = infoline.Substring(infoline.IndexOf(",") + 1); string[] itemValues = itemline.Split(","); itemValues[5] = infoName; List <string> listItems = new List <string>(itemValues); listItems.RemoveAt(4); listItems.RemoveAt(2); string outLine = string.Join(",", listItems.ToArray()); outFile.WriteLine(outLine); break; } } } outFile.Close(); return(CommandResultType.Completed); } return(CommandResultType.Completed); }
public override CommandResultType Handle(ConsoleParameter parameter) { foreach (string key in parameter.switchMap.Keys) { ISwitchProperty property = FindSwitch(key); if (property == null) { _Logger.Error($"Switch '{key}' not found"); continue; } string value = parameter.switchMap[key]; if (!property.Assign(value)) { _Logger.Error($"Switch '{key}' failed, value: '{value}' is invalid"); } else { _Logger.Info($"Applied {key}={value}"); } } foreach (string booleanSwitch in parameter.switches) { ISwitchProperty property = FindSwitch(booleanSwitch); if (property == null) { _Logger.Error($"Switch '{booleanSwitch}' not found"); continue; } if (!property.Assign(bool.TrueString)) { _Logger.Error($"Switch '{booleanSwitch}' failed, value: '{bool.TrueString}' is invalid"); } else { _Logger.Info($"Applied {booleanSwitch}={bool.TrueString}"); } } return(CommandResultType.Completed); }
public override CommandResultType Handle(ConsoleParameter parameter) { FpmfArchiveIO archiveIO2 = new FpmfArchiveIO(); if (parameter.Arguments.Count == 3) { FpmfArchiveIO hedFile = new FpmfArchiveIO(); hedFile.Pack(parameter.Arguments[0], parameter.Arguments[1], parameter.Arguments[2]); return(CommandResultType.Completed); } else if (parameter.Arguments.Count == 4) { FpmfArchiveIO hedFile = new FpmfArchiveIO(); hedFile.Pack(parameter.Arguments[0], parameter.Arguments[1], parameter.Arguments[2], parameter.Arguments[3]); return(CommandResultType.Completed); } return(CommandResultType.Continue); }
public override CommandResultType Handle(ConsoleParameter parameter) { if (parameter.Arguments.Count >= 1) { string subKey = parameter.Arguments[0]; if (!_commands.ContainsKey(subKey)) { Logger.Error( $"Command: 'help {subKey}' not available. Type 'help' for a list of available commands."); return(CommandResultType.Continue); } IConsoleCommand consoleCommandHelp = _commands[subKey]; Logger.Info(ShowHelp(consoleCommandHelp)); return(CommandResultType.Continue); } ShowHelp(); return(CommandResultType.Continue); }
private CommandResultType ProcessArguments(string[] arguments) { ConsoleParameter parameter = ParseParameter(arguments); if (!_commands.ContainsKey(parameter.Key)) { Logger.Error( $"Command: '{parameter.Key}' not available. Type `help' for a list of available commands."); return(CommandResultType.Continue); } IConsoleCommand consoleCommand = _commands[parameter.Key]; if (consoleCommand != _switchCommand) { _switchCommand.Handle(parameter); } return(consoleCommand.Handle(parameter)); }
public override CommandResultType Handle(ConsoleParameter parameter) { if (parameter.Arguments.Count == 2) { string line; System.IO.StreamReader fileIn = new System.IO.StreamReader(parameter.Arguments[0]); System.IO.StreamWriter fileOut = new System.IO.StreamWriter(parameter.Arguments[1]); while ((line = fileIn.ReadLine()) != null) { if (!line.StartsWith(",") && !line.StartsWith("#") && line.Length != 0) { fileOut.WriteLine(line); } } fileIn.Close(); fileOut.Close(); return(CommandResultType.Completed); } return(CommandResultType.Continue); }
public override CommandResultType Handle(ConsoleParameter parameter) { if (_server == null) { MhfSetting setting = new MhfSetting(); _server = new MhfServer(setting); } if (parameter.Arguments.Contains("start")) { _server.Start(); return(CommandResultType.Completed); } if (parameter.Arguments.Contains("stop")) { _server.Stop(); return(CommandResultType.Completed); } return(CommandResultType.Continue); }
protected override ParameterStd ConvertParameters(object[] obj) { var p = new ConsoleParameter(); if (obj != null & obj.Length > 0) { var command = ComFunc.nvl(obj[0]).ToLower(); if (command == "stop") { p.ExtentionObj.stop = true; } } //config foreach (var item in MyConfig.GetConfigurationList("ConnectionStrings")) { p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value); } p.DBConnectionString = ComFunc.nvl(p[DomainKey.CONFIG, "DefaultConnection"]); bool bvalue = true; foreach (var item in MyConfig.GetConfigurationList("EFFC")) { if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue)) { p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value)); } else if (DateTimeStd.IsDateTime(item.Value)) { p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value; } else { p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value); } } return(p); }
protected override ParameterStd ConvertParameters(object[] obj) { var p = new ConsoleParameter(); if (obj != null & obj.Length > 0) { var la = ComFunc.nvl(obj[0]).Split('.', StringSplitOptions.RemoveEmptyEntries); p.CallLogicName = la.Length > 0 ? la[0] : ""; p.CallAction = la.Length > 1 ? la[1] : ""; } //config foreach (var item in MyConfig.GetConfigurationList("ConnectionStrings")) { p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value); } p.DBConnectionString = ComFunc.nvl(p[DomainKey.CONFIG, "DefaultConnection"]); bool bvalue = true; foreach (var item in MyConfig.GetConfigurationList("EFFC")) { if (bool.TryParse(ComFunc.nvl(item.Value), out bvalue)) { p[DomainKey.CONFIG, item.Key] = bool.Parse(ComFunc.nvl(item.Value)); } else if (DateTimeStd.IsDateTime(item.Value)) { p[DomainKey.CONFIG, item.Key] = DateTimeStd.ParseStd(item.Value).Value; } else { p[DomainKey.CONFIG, item.Key] = ComFunc.nvl(item.Value); } } return(p); }
public abstract CommandResultType Handle(ConsoleParameter parameter);
public override CommandResultType Handle(ConsoleParameter parameter) { if (parameter.arguments.Contains("w")) { StringBuilder sb = new StringBuilder(); sb.Append(Environment.NewLine); sb.Append("15. Disclaimer of Warranty."); sb.Append(Environment.NewLine); sb.Append("THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY"); sb.Append(Environment.NewLine); sb.Append("APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT"); sb.Append(Environment.NewLine); sb.Append("HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY"); sb.Append(Environment.NewLine); sb.Append("OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,"); sb.Append(Environment.NewLine); sb.Append("THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR"); sb.Append(Environment.NewLine); sb.Append("PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM"); sb.Append(Environment.NewLine); sb.Append("IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF"); sb.Append(Environment.NewLine); sb.Append("ALL NECESSARY SERVICING, REPAIR OR CORRECTION."); sb.Append(Environment.NewLine); _Logger.Info(sb.ToString()); return(CommandResultType.Completed); } if (parameter.arguments.Contains("c")) { StringBuilder sb = new StringBuilder(); sb.Append(Environment.NewLine); sb.Append("2. Basic Permissions."); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("All rights granted under this License are granted for the term of"); sb.Append(Environment.NewLine); sb.Append("copyright on the Program, and are irrevocable provided the stated"); sb.Append(Environment.NewLine); sb.Append("conditions are met. This License explicitly affirms your unlimited"); sb.Append(Environment.NewLine); sb.Append("permission to run the unmodified Program. The output from running a"); sb.Append(Environment.NewLine); sb.Append("covered work is covered by this License only if the output, given its"); sb.Append(Environment.NewLine); sb.Append("content, constitutes a covered work. This License acknowledges your"); sb.Append(Environment.NewLine); sb.Append("rights of fair use or other equivalent, as provided by copyright law."); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("You may make, run and propagate covered works that you do not"); sb.Append(Environment.NewLine); sb.Append("convey, without conditions so long as your license otherwise remains"); sb.Append(Environment.NewLine); sb.Append("in force. You may convey covered works to others for the sole purpose"); sb.Append(Environment.NewLine); sb.Append("of having them make modifications exclusively for you, or provide you"); sb.Append(Environment.NewLine); sb.Append("with facilities for running those works, provided that you comply with"); sb.Append(Environment.NewLine); sb.Append("the terms of this License in conveying all material for which you do"); sb.Append(Environment.NewLine); sb.Append("not control copyright. Those thus making or running the covered works"); sb.Append(Environment.NewLine); sb.Append("for you must do so exclusively on your behalf, under your direction"); sb.Append(Environment.NewLine); sb.Append("and control, on terms that prohibit them from making any copies of"); sb.Append(Environment.NewLine); sb.Append("your copyrighted material outside their relationship with you."); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("Conveying under any other circumstances is permitted solely under"); sb.Append(Environment.NewLine); sb.Append("the conditions stated below. Sublicensing is not allowed; section 10"); sb.Append(Environment.NewLine); sb.Append("makes it unnecessary."); sb.Append(Environment.NewLine); _Logger.Info(sb.ToString()); return(CommandResultType.Completed); } return(CommandResultType.Continue); }
public override CommandResultType Handle(ConsoleParameter parameter) { Logger.Info("Exiting..."); return(CommandResultType.Exit); }
protected override void InvokeBusiness(ConsoleParameter p, ConsoleData d) { if (p.ExtentionObj.stop != null && p.ExtentionObj.stop) { isrun = false; GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"接收到stop指令,准备结束运行,请等待..."); } if (_excute_options.IsNotExcute) { GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"程式不执行"); } else if (_excute_options.IsImmediately) { //立即执行并且只执行一次 //如果没指定要调用的逻辑,则默认都执行一次 foreach (var k in _call_dic.Keys) { var isrepeat = false; var repeatcount = 0; var repeattimes = 0; do { if (isrepeat) { repeatcount++; GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"当前为任务{k}第{repeatcount}次重复执行"); } try { using (var cp = p.DeepCopy <ConsoleParameter>()) { using (var cd = d.DeepCopy <ConsoleData>()) { GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"开始执行任务{k}"); var lname = k.Split('.')[0]; var action = k.Split('.')[1]; cp.CallLogicName = lname; cp.CallAction = action; if (!string.IsNullOrEmpty(cp.CallLogicName) && !string.IsNullOrEmpty(cp.CallAction)) { var logic = _call_dic[k].NewInstance(); logic.process(cp, cd); GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"结束任务{k}"); } else { GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"任务{k}不符合任务执行选项标准,故不执行"); } } } isrepeat = false; repeatcount = 0; repeattimes = 0; } catch (Exception ex) { var errormsg = new StringBuilder(); errormsg.AppendLine(); errormsg.AppendLine($"任务{k}执行出错,错误信息为{ex.Message}"); errormsg.AppendLine(ex.StackTrace); if (ex.InnerException != null) { errormsg.AppendLine(ex.InnerException.Message); errormsg.AppendLine(ex.StackTrace); } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, errormsg.ToString()); if (_call_dic[k].RepeatWhenExceptionType != null && (ex.GetType().FullName == _call_dic[k].RepeatWhenExceptionType.FullName || ex.GetType().IsSubclassOf(_call_dic[k].RepeatWhenExceptionType) || (ex.InnerException != null && (ex.InnerException.GetType().FullName == _call_dic[k].RepeatWhenExceptionType.FullName || ex.InnerException.GetType().IsSubclassOf(_call_dic[k].RepeatWhenExceptionType))))) { if (!isrepeat) { isrepeat = true; repeattimes = _call_dic[k].RepeatTimes; GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"任务{k}执行出现异常,因设定重复执行任务,因此进入重复执行序列,直到执行完成或达到重复次数,设定的重复次数为{repeattimes}"); } } else { isrepeat = false; repeatcount = 0; repeattimes = 0; } } finally { GC.Collect(); } } while (isrepeat && repeatcount < repeattimes); } } else { while (isrun) { var dt = DateTime.Now; var rs = _next_run_schedule.Where(t => 1 == 1).ToDictionary(k => k.Key, v => v.Value); foreach (var item in rs) { if (dt >= item.Value) { if (!IsRun(item.Key)) { SetRunFlag(item.Key); var task = Task.Run(() => { //等待task添加到dictionary中 Task.Delay(100).Wait(); var isrepeat = false; var repeatcount = 0; var repeattimes = 0; do { if (isrepeat) { repeatcount++; GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"当前为任务{item.Key}第{repeatcount}次重复执行"); } try { using (var cp = p.DeepCopy <ConsoleParameter>()) { using (var cd = d.DeepCopy <ConsoleData>()) { GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"开始执行任务{item.Key}"); var lname = item.Key.Split('.')[0]; var action = item.Key.Split('.')[1]; cp.CallLogicName = lname; cp.CallAction = action; if (!string.IsNullOrEmpty(cp.CallLogicName) && !string.IsNullOrEmpty(cp.CallAction)) { var logic = _call_dic[item.Key].NewInstance(); //提前写入下次执行的时间,便于logic执行善后处理 UpdateNextRunTime(item.Key, dt); cp.ExtentionObj.Next_Excute_Time = _next_run_schedule[item.Key]; cp.ExtentionObj.ExcuteName = _call_dic[item.Key].Name; cp.ExtentionObj.ExcuteDescription = _call_dic[item.Key].Desc; logic.process(cp, cd); GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"结束任务{item.Key},下次执行时间点为{_next_run_schedule[item.Key].ToString("yyyy-MM-dd HH:mm:ss")}"); } else { GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"任务{item.Key}不符合任务执行选项标准,故不执行,后续也不再执行"); } } } isrepeat = false; repeatcount = 0; repeattimes = 0; } catch (Exception ex) { var errormsg = new StringBuilder(); errormsg.AppendLine(); errormsg.AppendLine($"任务{item.Key}执行出错,错误信息为{ex.Message}"); errormsg.AppendLine(ex.StackTrace); if (ex.InnerException != null) { errormsg.AppendLine(ex.InnerException.Message); errormsg.AppendLine(ex.StackTrace); } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, errormsg.ToString()); if (_call_dic[item.Key].RepeatWhenExceptionType != null && (ex.GetType().FullName == _call_dic[item.Key].RepeatWhenExceptionType.FullName || ex.GetType().IsSubclassOf(_call_dic[item.Key].RepeatWhenExceptionType) || (ex.InnerException != null && (ex.InnerException.GetType().FullName == _call_dic[item.Key].RepeatWhenExceptionType.FullName || ex.InnerException.GetType().IsSubclassOf(_call_dic[item.Key].RepeatWhenExceptionType))))) { if (!isrepeat) { isrepeat = true; repeattimes = _call_dic[item.Key].RepeatTimes; GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"任务{item.Key}执行出现异常,因设定重复执行任务,因此进入重复执行序列,直到执行完成或达到重复次数,设定的重复次数为{repeattimes}"); } } else { isrepeat = false; repeatcount = 0; repeattimes = 0; } UpdateNextRunTime(item.Key, dt); } finally { SetStopFlag(item.Key); GC.Collect(); } } while (isrepeat && repeatcount < repeattimes); }); if (_running_task.ContainsKey(item.Key)) { _running_task[item.Key].Wait(); _running_task.Remove(item.Key); _running_task.Add(item.Key, task); } else { _running_task.Add(item.Key, task); } } } //else //{ // GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"任务{item.Key}未到执行时间点,无须执行"); //} } Task.Delay(1000).Wait(); } //结束之前需要等待所有的正在运行的线程执行完成 Task.WaitAll(_running_task.Values.ToArray()); GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.INFO, $"所有任务执行完成,结束运行"); } }
/// <summary> /// Parses the input text into arguments and switches. /// </summary> private ConsoleParameter ParseParameter(string[] args) { if (args.Length <= 0) { Logger.Error("Invalid input. Type 'help' for a list of available commands."); return(null); } string paramKey = args[0]; int cmdLength = args.Length - 1; string[] newArguments = new string[cmdLength]; if (cmdLength > 0) { Array.Copy(args, 1, newArguments, 0, cmdLength); } args = newArguments; ConsoleParameter parameter = new ConsoleParameter(paramKey); foreach (string arg in args) { int count = CountChar(arg, CliValueSeparator); if (count == 1) { string[] keyValue = arg.Split(CliValueSeparator); if (keyValue.Length == 2) { string key = keyValue[0]; string value = keyValue[1]; if (key.StartsWith('-')) { if (key.Length <= 2 || parameter.SwitchMap.ContainsKey(key)) { Logger.Error($"Invalid switch key: '{key}' is empty or duplicated."); continue; } parameter.SwitchMap.Add(key, value); continue; } if (key.Length <= 0 || parameter.ArgumentMap.ContainsKey(key)) { Logger.Error($"Invalid argument key: '{key}' is empty or duplicated."); continue; } parameter.ArgumentMap.Add(key, value); continue; } } if (arg.StartsWith('-')) { string switchStr = arg; if (switchStr.Length <= 2 || parameter.Switches.Contains(switchStr)) { Logger.Error($"Invalid switch: '{switchStr}' is empty or duplicated."); continue; } parameter.Switches.Add(switchStr); continue; } if (arg.Length <= 0 || parameter.Switches.Contains(arg)) { Logger.Error($"Invalid argument: '{arg}' is empty or duplicated."); continue; } parameter.Arguments.Add(arg); } return(parameter); }
protected override void AfterProcess(ConsoleParameter p, ConsoleData d) { p.Resources.CommitTransaction(p.CurrentTransToken); }
public override CommandResultType Handle(ConsoleParameter parameter) { FpmfArchiveIO archiveIO2 = new FpmfArchiveIO(); // archiveIO2.OpenWoItm("C:\\Games\\Wizardry Online\\data_un\\settings\\item.csv"); // return CommandResultType.Continue; if (parameter.Arguments.Count == 2) { FpmfArchiveIO archiveIO = new FpmfArchiveIO(); string[] hedFiles; FileAttributes attr = File.GetAttributes(parameter.Arguments[0]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { hedFiles = Directory.GetFiles(parameter.Arguments[0], "*.hed", SearchOption.AllDirectories); } else { hedFiles = new string[1]; hedFiles[0] = parameter.Arguments[0]; } for (int i = 0; i < hedFiles.Length; i++) { FpmfArchive archive = archiveIO.Open(hedFiles[i], parameter.Arguments[1]); archiveIO.Save(archive, parameter.Arguments[1]); } return(CommandResultType.Completed); } else if (parameter.Arguments.Count == 1) { FpmfArchiveIO archiveIO = new FpmfArchiveIO(); FpmfArchive archive = archiveIO.Open(parameter.Arguments[0]); archiveIO.OpenWoItm(parameter.Arguments[0]); return(CommandResultType.Completed); } else if (parameter.Arguments.Count == 3) { FpmfArchiveIO archiveIO = new FpmfArchiveIO(); string[] hedFiles; FileAttributes attr = File.GetAttributes(parameter.Arguments[1]); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { hedFiles = Directory.GetFiles(parameter.Arguments[1], "*.hed", SearchOption.AllDirectories); } else { hedFiles = new string[1]; hedFiles[0] = parameter.Arguments[1]; } for (int i = 0; i < hedFiles.Length; i++) { if (parameter.Arguments[0] == "header") { archiveIO.Header(hedFiles[i], parameter.Arguments[2]); } } return(CommandResultType.Completed); } return(CommandResultType.Continue); }
public override CommandResultType Handle(ConsoleParameter parameter) { if (_server == null) { SettingProvider settingProvider = new SettingProvider(); NecSetting setting = settingProvider.Load <NecSetting>(SETTING_FILE); if (setting == null) { Logger.Info($"No `{SETTING_FILE}` file found, creating new"); setting = new NecSetting(); settingProvider.Save(setting, SETTING_FILE); } else { Logger.Info($"Loaded Setting from: {settingProvider.GetSettingsPath(SETTING_FILE)}"); } SettingProvider secretsProvider = new SettingProvider(setting.secretsFolder); NecSecret secret = secretsProvider.Load <NecSecret>(SECRET_FILE); if (secret == null) { Logger.Info($"No `{SECRET_FILE}` file found, creating new"); secret = new NecSecret(); secretsProvider.Save(secret, SECRET_FILE); } else { Logger.Info($"Loaded Secrets from: {secretsProvider.GetSettingsPath(SECRET_FILE)}"); } setting.discordBotToken = secret.discordBotToken; setting.databaseSettings.password = secret.databasePassword; LogProvider.Configure <NecLogger>(setting); _server = new NecServer(setting); } if (parameter.arguments.Contains("start")) { _server.Start(); if (_service) { while (_server.running) { Thread.Sleep(TimeSpan.FromMinutes(5)); } return(CommandResultType.Exit); } return(CommandResultType.Completed); } if (parameter.arguments.Contains("stop")) { _server.Stop(); return(CommandResultType.Completed); } return(CommandResultType.Continue); }