Пример #1
0
        static void Main(string[] args)
        {
            var ipAddresses = new List <string>();

            Console.Write($"Enter at least one IP-address of deployed worker system: ");
            string enteredIp = null;

            do
            {
                enteredIp = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(enteredIp))
                {
                    ipAddresses.Add(enteredIp);
                    Console.Write("Enter one more IP-address or empty string for deploying main system: ");
                }
            } while (!string.IsNullOrWhiteSpace(enteredIp));

            var workerDeploymentInfos = ipAddresses.Select(ip => new WorkerDeploymentInfo(ip, 1)).ToList();

            using (var mainSystem = MainSystem.DelpoyInstance(workerDeploymentInfos)) {
                Parallel.ForEach(ipAddresses, ip => {
                    CSharpTaskCompletionResult result = mainSystem.RunTask("return new Random().NextDouble();").Result;
                    Console.WriteLine($"Random result of {ip}: {(result.Success ? "succes" : "failure")} - {result.Message}");
                });
                Console.WriteLine($"Press any key to STOP main system...");
                Console.ReadKey();
            }
        }
 public TasksController(IConfiguration config)
 {
     if (_mainSystem == null)
     {
         try {
             IConfigurationSection workers = config.GetSection("Workers");
             var workerDploymentInfos      = workers.Get <string[]>()
                                             .Select(x => {
                 string[] values = x.Split(",").Select(s => s.Trim()).Take(2).ToArray();
                 return(new WorkerDeploymentInfo(values[0], double.Parse(values[1])));
             })
                                             .ToArray();
             _mainSystem = MainSystem.DelpoyInstance(workerDploymentInfos);
         } catch (Exception e) {
             throw new ApplicationException("Main system deployment failed, check your configuration.", e);
         }
     }
 }