Esempio n. 1
0
        public TaskStatus AcceptTask(int num1, int num2, string op)
        {
            string taskData = num1.ToString() + "," + op + "," + num2.ToString();

            int taskId = this.StartNewTask(taskData);

            TaskStatus ts = new TaskStatus();

            ts.TaskId = taskId;

            ts.Complete = false;
            ts.Successful = false;
            ts.ResultMessage = "Task started...";

            return ts;
        }
Esempio n. 2
0
        public TaskStatus AcceptTask(int num1, int num2, string op)
        {
            string taskData = num1.ToString() + "," + op + "," + num2.ToString();

            Binding binding = new NetTcpBinding();

            ICoordinator proxy = ChannelFactory<ICoordinator>.CreateChannel(binding, _coordinatorAddress);

            int taskId = proxy.StartNewTask(taskData);

            TaskStatus ts = new TaskStatus();

            ts.TaskId = taskId;

            ts.Complete = false;
            ts.Successful = false;
            ts.ResultMessage = "Task started...";

            return ts;
        }
Esempio n. 3
0
        private static void WaitForResult(TaskStatus t, int port)
        {
            bool isComplete = false;

            do
            {
                Console.Write(".");

                Thread.Sleep(500);

                Console.Write(".");

                Thread.Sleep(500);

                Console.Write(".");

                Thread.Sleep(500);

                EndpointAddress a = new EndpointAddress(string.Format("net.tcp://localhost:{0}", port.ToString()));

                Binding binding = new NetTcpBinding();

                ITask proxy = ChannelFactory<ITask>.CreateChannel(binding, a);

                TaskStatus status = proxy.CheckProgress(t.TaskId);

                isComplete = status.Complete;

                Console.WriteLine();
                Console.WriteLine("Status Report for Task ID:{0}", t.TaskId);
                Console.WriteLine("The task is currently {0}", status.Complete ? "Complete" : "Incomplete");
                Console.WriteLine("The current state is: {0}", status.ResultMessage);
                Console.WriteLine();
            }
            while(!isComplete);

            Console.WriteLine("Task Finished");
        }
Esempio n. 4
0
        private void DoNextTask(Task task)
        {
            Console.WriteLine("Starting Task ID: {0}...", task.TaskId);

            int operand1, operand2, result;
            string op;
            string[] chunks = task.TaskData.Split(new[] { ',' });

            operand1 = int.Parse(chunks[0]);
            op = chunks[1];
            operand2 = int.Parse(chunks[2]);

            switch (op)
            {
                case "+":

                    result = operand1 + operand2;

                    break;
                case "-":

                    result = operand1 - operand2;

                    break;
                case "*":

                    result = operand1 * operand2;

                    break;
                case "/":

                    result = operand1 / operand2;

                    break;
                default:
                    throw new Exception("Operator not recognised");
            }

            TaskStatus status = new TaskStatus() { Successful = true, Complete = true, ResultMessage = string.Format("{0}: The result of {1} is {2}", _processHost.Description.Endpoints[1].Address.ToString(), (operand1.ToString() + " " + op + " " + operand2.ToString()), result) };

            // wait here to mimic a long running task
            Thread.Sleep(5000);

            lock (_statusLock)
            {
                _taskStatuses[task.TaskId] = status;
            }

            Console.WriteLine("Task completed");
            Console.WriteLine();
        }