Beispiel #1
0
        private void CallScript(ExecutionInformation info, string command, bool answer, bool skipRights)
        {
            Log.Debug("Calling script (skipRights:{0}, answer:{1}): {2}", skipRights, answer, command);

            info.AddDynamicObject(new CallerInfo(command, false)
            {
                SkipRightsChecks = skipRights
            });

            try
            {
                // parse (and execute) the command
                var res = CommandManager.CommandSystem.Execute(info, command);

                if (!answer)
                {
                    return;
                }

                // Write result to user
                switch (res.ResultType)
                {
                case CommandResultType.String:
                    var sRes = (StringCommandResult)res;
                    if (!string.IsNullOrEmpty(sRes.Content))
                    {
                        info.Write(sRes.Content).UnwrapToLog(Log);
                    }
                    break;

                case CommandResultType.Empty:
                    break;

                default:
                    Log.Warn("Got result which is not a string/empty. Result: {0}", res.ToString());
                    break;
                }
            }
            catch (CommandException ex)
            {
                Log.Debug(ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_unexpected_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
        }
Beispiel #2
0
        private void CallScript(ExecutionInformation info, string command, bool answer, bool skipRights)
        {
            Log.Debug("Calling script (skipRights:{0}, answer:{1}): {2}", skipRights, answer, command);

            info.AddDynamicObject(new CallerInfo(command, false)
            {
                SkipRightsChecks = skipRights
            });

            try
            {
                // parse (and execute) the command
                var res = CommandManager.CommandSystem.Execute(info, command);

                if (!answer)
                {
                    return;
                }

                // Write result to user
                if (res.ResultType == CommandResultType.String)
                {
                    var sRes = (StringCommandResult)res;
                    if (!string.IsNullOrEmpty(sRes.Content))
                    {
                        info.Write(sRes.Content).UnwrapThrow();
                    }
                }
                else if (res.ResultType == CommandResultType.Json)
                {
                    var sRes = (JsonCommandResult)res;
                    info.Write("\nJson str: \n" + sRes.JsonObject).UnwrapThrow();
                    info.Write("\nJson val: \n" + sRes.JsonObject.Serialize()).UnwrapThrow();
                }
            }
            catch (CommandException ex)
            {
                Log.Debug(ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    info.Write(string.Format(strings.error_call_error, ex.Message));                         // XXX check return
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    info.Write(string.Format(strings.error_call_unexpected_error, ex.Message));                         // XXX check return
                }
            }
        }
Beispiel #3
0
        private void CallScript(ExecutionInformation info, string command, bool answer)
        {
            info.AddDynamicObject(new CallerInfo(command, false));

            try
            {
                // parse (and execute) the command
                var res = CommandManager.CommandSystem.Execute(info, command);

                if (!answer)
                {
                    return;
                }

                // Write result to user
                if (res.ResultType == CommandResultType.String)
                {
                    var sRes = (StringCommandResult)res;
                    if (!string.IsNullOrEmpty(sRes.Content))
                    {
                        info.Write(sRes.Content).UnwrapThrow();
                    }
                }
                else if (res.ResultType == CommandResultType.Json)
                {
                    var sRes = (JsonCommandResult)res;
                    info.Write("\nJson str: \n" + sRes.JsonObject.AsStringResult).UnwrapThrow();
                    info.Write("\nJson val: \n" + JsonConvert.SerializeObject(sRes.JsonObject)).UnwrapThrow();
                }
            }
            catch (CommandException ex)
            {
                Log.Debug(ex, "Command Error");
                if (answer)
                {
                    info.Write("Error: " + ex.Message);                         // XXX check return
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    info.Write("An unexpected error occured: " + ex.Message);                         // XXX check return
                }
            }
        }