Пример #1
0
 public CoreMathsService(IWorkerMessageService messageService)
 {
     this.messageService = messageService;
     this.messageService.IncomingMessage += OnMessage;
     mathsService     = new MathsService();
     mathsService.Pi += (s, progress) => messageService.PostMessageAsync($"{EventsPi}:{progress}");
 }
Пример #2
0
 private void OnMessage(object sender, string message)
 {
     if (message.StartsWith(nameof(mathsService.EstimatePI)))
     {
         var messageParams = message.Substring(nameof(mathsService.EstimatePI).Length).Trim();
         var rx            = new Regex(@"\((?<arg>[^\)]+)\)");
         var arg0          = rx.Match(messageParams).Groups["arg"].Value.Trim();
         var iterations    = int.Parse(arg0);
         mathsService.EstimatePI(iterations).ContinueWith(t =>
                                                          messageService.PostMessageAsync($"{ResultMessage}:{t.Result}"));
         return;
     }
 }