public async Task Simulate(ICollection <TestData> testdataList) { var jsonMessageCreator = new JsonMessageCreator(); async Task Body() { foreach (var testData in testdataList) { _eventHubConnector.SendMessagesToEventHub(testData).GetAwaiter().GetResult(); _logger.Debug($"[Simulator] Start sending messages: {testData.ToString()}"); } }; _logger.Debug("[Simulator] Start sending messages to the EventHub."); await _executionEngine.Execute(Body); _logger.Debug("[Simulator] End sending messages to the EventHub."); }
/// <summary> /// Runs the script on the VM. /// </summary> /// <returns>The invocation script on vm.</returns> /// <param name="invocationScript">Invocation script.</param> private InvocationResult RunInvocationOnVM(byte[] invocationScript) { _executionEngine.LoadScript(invocationScript); _executionEngine.Execute(); var resultList = new List <object>(); foreach (var stackItem in _executionEngine.ResultStack) { using (stackItem) { resultList.Add(stackItem.GetRawObject()); } } var invocationResult = new InvocationResult(invocationScript, _executionEngine.State, _executionEngine.ConsumedGas, resultList.ToArray()); return(invocationResult); }
static int Main(string[] args) { if (args == null || args.Length < 1) { Console.WriteLine(""); return(1); } if (!File.Exists(args[0])) { Console.WriteLine(""); return(2); } Dictionary <char, DimensionalQuantity> definitions = new Dictionary <char, DimensionalQuantity>(); foreach (var arg in args.Skip(1)) { if (!Regex.IsMatch(arg, @"")) { Console.WriteLine(""); return(3); } string[] argParts = arg.Split('='); definitions[char.Parse(argParts[0])] = DimensionalQuantity.Parse(argParts[1]); } IWindsorContainer container = new WindsorContainer(); container.Install(new ContainerInstaller()); FileInfo file = new FileInfo(args[0]); IExecutionEngine engine = container.Resolve <IExecutionEngine>(); ExecutionResult result; switch (file.Extension.ToUpper()) { case "ANS": { ITokenizer tokenizer = container.Resolve <ITokenizer>(); ILexer lexer = container.Resolve <ILexer>(); IParser parser = container.Resolve <IParser>(); string content; using (StreamReader reader = new StreamReader(file.OpenRead())) { content = reader.ReadToEnd(); } Token[] tokens = tokenizer.Tokenize(content); LexicalToken[] lexTokens = lexer.Lex(tokens); ExecutionContext context = parser.Parse(lexTokens); result = engine.Execute(context, definitions); } break; case "ANC": { List <byte> content = new List <byte>(); using (BinaryReader reader = new BinaryReader(file.OpenRead())) { for (int count = 0; count < file.Length; count += 1024) { byte[] buffer = new byte[1024]; reader.Read(buffer, count, 1024); content.AddRange(buffer); } } result = engine.Execute(content.ToArray(), definitions); } break; default: { Console.WriteLine(""); return(3); } } foreach (var log in result.Log) { Console.BackgroundColor = ConsoleColor.Black; switch (log.Level) { case Level.Debug: Console.ForegroundColor = ConsoleColor.Blue; break; case Level.Info: Console.ForegroundColor = ConsoleColor.Gray; break; case Level.Warn: Console.ForegroundColor = ConsoleColor.Yellow; break; case Level.Error: Console.ForegroundColor = ConsoleColor.Red; break; case Level.Fatal: Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Red; break; } Console.WriteLine(); } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{result.Code}.{result.Subcode} - {result.Message}"); return(result.Code); }
public void Append(IActivity activity) { IExecutionToken token = _engine.Execute(activity); _compositeToken.Append(token); }