Beispiel #1
0
        public int RunCommands(TextReader input, TextWriter output, Logger logger, IEnumerable<ResponseLine> responseLines)
        {
            var agent = Activator.CreateInstance("Orchard.Framework", "Orchard.Commands.CommandHostAgent").Unwrap();

            int result = (int)agent.GetType().GetMethod("StartHost").Invoke(agent, new object[] { input, output });
            if (result != 0)
                return result;

            foreach (var line in responseLines) {
                logger.LogInfo("{0} ({1}): Running command: {2}", line.Filename, line.LineNumber, line.LineText);

                var args = new OrchardParametersParser().Parse(new CommandParametersParser().Parse(line.Args));

                result = (int)agent.GetType().GetMethod("RunCommand").Invoke(agent, new object[] {
                    input,
                    output,
                    args.Tenant,
                    args.Arguments.ToArray(),
                    args.Switches});

                if (result != 0) {
                    output.WriteLine("{0} ({1}): Command returned error ({2})", line.Filename, line.LineNumber, result);
                    return result;
                }
            }

            result = (int)agent.GetType().GetMethod("StopHost").Invoke(agent, new object[] { input, output });
            return result;
        }
        public void LogInfoToJsonInputAsync()
        {
            var textInput = "e6d64ac2-c8e9-45e0-ac73-3298ff8cb96f";
            LogglyConfiguration.Configure(c => c.AuthenticateWith("csharptests", "Passw0rd!"));

            var logger = new Logger(textInput);
            var randomString = GenerateRandomString(8);
            logger.LogInfo(randomString, new Dictionary<string, object> { { "key1", "value1" }, { "key2", "value2" } } );

            var signal = new AutoResetEvent(false);
            SearchJsonResponse response = null;

            new Thread(() =>
            {
                var running = true;
                while (running)
                {
                    Thread.Sleep(3000);
                    response = new Searcher("csharptests").SearchJson("message", randomString);

                    if (response.TotalRecords > 0)
                        running = false;
                }

                signal.Set();
            }).Start();

            signal.WaitOne(50 * 1000); // wait till loggly index the new event (if it didn't after 50 seconds it is broken)

            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.TotalRecords);
            Assert.AreEqual(randomString, response.Results[0].Json["message"]);
            Assert.AreEqual("info", response.Results[0].Json["category"]);
            Assert.AreEqual("value1", response.Results[0].Json["key1"]);
            Assert.AreEqual("value2", response.Results[0].Json["key2"]);
        }
        public CommandReturnCodes RunCommands(TextReader input, TextWriter output, Logger logger, IEnumerable<ResponseLine> responseLines) {
            var agent = CreateAgent();

            CommandReturnCodes result = StartHost(agent, input, output);
            if (result != CommandReturnCodes.Ok)
                return result;

            foreach (var line in responseLines) {
                logger.LogInfo("{0} ({1}): Running command: {2}", line.Filename, line.LineNumber, line.LineText);

                var args = new OrchardParametersParser().Parse(new CommandParametersParser().Parse(line.Args));

                result = (CommandReturnCodes)agent.GetType().GetMethod("RunCommand").Invoke(agent, new object[] { 
                    input,
                    output,
                    args.Tenant,
                    args.Arguments.ToArray(),
                    args.Switches});

                if (result != CommandReturnCodes.Ok) {
                    output.WriteLine("{0} ({1}): Command returned error ({2})", line.Filename, line.LineNumber, result);
                    return result;
                }
            }

            result = StopHost(agent, input, output);
            return result;
        }
 public static void MethodCallingLogInfo(Logger logger, string msg = null)
 {
     logger.LogInfo(msg);
 }