示例#1
0
        private object RunWithETWCollector(string argument, MethodInfo mi, object obj)
        {
            object result;

            using (var collector = new ClrEtwCollector())
            {
                collector.Start();
                result = Run(argument, mi, obj);
                collector.Stop();

                this.HeapStatsData   = collector.HeapStatsData;
                this.GcData          = collector.GcData;
                this.GenerationsData = collector.GenerationsData;
            }

            return(result);
        }
示例#2
0
        public string Execute(string argument)
        {
            Type       type = assembly.GetTypes().First();
            MethodInfo mi   = type.GetMethods(BindingFlags.Instance | BindingFlags.Public).First();
            object     obj  = Activator.CreateInstance(type);

            this.engine.UpdateLog($"Object with type {type.FullName} and method {mi.Name} resolved.");

            object result = null;

            try
            {
                TextWriter programWriter = new StringWriter();
                Console.SetOut(programWriter);
                this.engine.UpdateLog($"Invoking method {mi.Name} with argument {argument}");

                using (var collector = new ClrEtwCollector())
                {
                    collector.Start();
                    result = mi.Invoke(obj, new object[] { argument });
                    collector.Stop();

                    this.HeapStatsData   = collector.HeapStatsData;
                    this.GcData          = collector.GcData;
                    this.GenerationsData = collector.GenerationsData;
                }

                this.engine.UpdateLog($"Script result: {result}");
                this.engine.UpdateLog("Script log:");
                this.engine.UpdateLog(programWriter.ToString());
                return(result.ToString());
            }
            catch (Exception e)
            {
                this.engine.UpdateLog($"Script execution failed: {e.ToString()}");
                return(e.ToString());
            }
        }