Ejemplo n.º 1
0
        /// <summary>
        /// 将脚本运行环境转储为二进制数组
        /// </summary>
        /// <returns></returns>
        public static async Task <byte[]> Dump(ScriptRuntime runtime)
        {
            var intent = DumpRuntimeIntent.CreateEmpty();

            intent.runtime = runtime;
            intent         = (await MessageService.ProcessAsync <DumpRuntimeIntent>(Message <DumpRuntimeIntent> .Create(CoreConstant.Mask, CoreConstant.DumpRuntime, intent))).Content;
            var tasks = new DumpRuntimeIntent.TaskLists();

            while (runtime != null)
            {
                foreach (var value in runtime.MemoryStack)
                {
                    tasks.OnDump(value);
                }
                foreach (var(_, value) in runtime.Exported)
                {
                    tasks.OnDump(value);
                }
                if (runtime.ActiveScope != null)
                {
                    tasks.OnDump(runtime.ActiveScope);
                }
                runtime = runtime.LoadingTarget;
            }
            await tasks.WaitAll();

            var serializer = new BinaryFormatter();
            var stream     = new MemoryStream();

            serializer.Serialize(stream, intent);
            return(stream.ToArray());
        }
Ejemplo n.º 2
0
 public override Task OnDump(DumpRuntimeIntent.TaskLists tasks)
 {
     foreach (var(_, value) in LocalVariables)
     {
         tasks.OnDump(value);
     }
     if (parentScope != null)
     {
         tasks.OnDump(parentScope);
     }
     return(base.OnDump(tasks));
 }