コード例 #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();
            }
        }
コード例 #2
0
        /// <summary>
        /// Відправляє задачу на виконання.
        /// </summary>
        /// <param name="scriptTask">Об'єкт задачі, яку потрібно виконати.</param>
        /// <returns>Об'єкт <see cref="System.Threading.Tasks.Task"/>, за допомогою якого можна отримати результат виконання.</returns>
        public async Task <CSharpTaskCompletionResult> RunTask(CSharpScriptTask scriptTask)
        {
            if (scriptTask.Id == default(Guid))
            {
                scriptTask.Id = Guid.NewGuid();
            }
            var taskCompletionSource = new TaskCompletionSource <CSharpTaskCompletionResult>();
            var executionContext     = new CSharpScriptExecutionContext(scriptTask, taskCompletionSource);

            _resultsDispatchActorRef.Tell(executionContext);
            var worker = _workersBalancer.GetNextWorkerDeplInfo();
            var actor  = _actorSystem.ActorOf(_workerRouters[worker]);

            actor.Tell(scriptTask);
            CSharpTaskCompletionResult result = await taskCompletionSource.Task;

            scriptTask.CompletionResult = result;
            return(result);
        }