Esempio n. 1
0
        static void Main(string[] args)
        {
            List<XmlTestData> tests = new List<XmlTestData>()
            {
                new XmlTestData(){ ClassName = "CalcServer.Toolboxes.MathToolbox", ClassVersion = "1.0.0.0", FunctionName = "MinMax", DataToProcess = GenerateRandomNumbersList(5, 100) },
                new XmlTestData(){ ClassName = "CalcServer.Toolboxes.MathToolbox", ClassVersion = "1.0.0.0", FunctionName = "MinMaxIdx", DataToProcess = GenerateRandomNumbersList(5, 100) },
                new XmlTestData(){ ClassName = "CalcServer.Toolboxes.StatisticsToolbox", ClassVersion = "1.0.0.0", FunctionName = "MeanStdDev", DataToProcess = GenerateRandomNumbersList(5, 100) },
                new XmlTestData(){ ClassName = "CalcServer.Toolboxes.StatisticsToolbox", ClassVersion = "1.0.0.0", FunctionName = "WordsCount", DataToProcess = "a test string"}
            };

            for (int i = 0; i < tests.Count; i++)
            {
                string taskDataStr = tests[i].ToString();
                Console.WriteLine(taskDataStr);

                new Thread(() =>
                {
                    string taskDataName = string.Format("TaskData-{0}", i);

                    Console.WriteLine(Environment.NewLine + taskDataName);

                    TaskExecution te = new TaskExecution("http://localhost:9001/ProcessingService/", TimeSpan.FromSeconds(1));
                    te.OnTaskExecutionCompleted += new TaskExecutionCompletedHandler(te_OnTaskExecutionCompleted);
                    te.OnTaskExecutionProgress += new TaskExecutionProgressHandler(te_OnTaskExecutionProgress);

                    te.SetTaskData(taskDataName, taskDataStr);
                    te.Start();
                }
                ) { IsBackground = true }.Start();

                mre.WaitOne();

                Thread.Sleep(2000);
                Console.WriteLine(Environment.NewLine + "==========" + Environment.NewLine);

                mre.Reset();
            }

            Console.WriteLine("Premere <Invio> per terminare l'applicazione...");
            Console.ReadLine();
        }
        /// <summary>
        /// Invia una richiesta di elaborazione al servizio remoto e attende che venga completata.
        /// </summary>
        /// <remarks>
        /// Il lavoro viene eseguito su un nuovo thread.
        /// </remarks>
        private void ExecuteProcess()
        {
            TaskResult = string.Empty;
            ReportText = string.Empty;

            string uriProcessingService = ProcessingServicesList[SelectedProcessingServiceIndex];
            string currentTaskName = "Task-" + (m_TasksCounter++).ToString();

            if (!IsValidUri(uriProcessingService))
            {
                UpdateReportText("Errore: indirizzo non valido per il servizio di elaborazione ({0}).", uriProcessingService);
                return;
            }

            IsBusy = true;

            new Thread(() =>
            {
                TaskExecution te = new TaskExecution(uriProcessingService, TimeSpan.FromSeconds(2));
                te.OnTaskExecutionProgress += new TaskExecutionProgressHandler(TaskExecution_Progress);
                te.OnTaskExecutionCompleted += new TaskExecutionCompletedHandler(TaskExecution_Completed);

                te.SetTaskData(currentTaskName, TaskData);
                te.Start();
            }
            ) { Name = "ProcessingThread", IsBackground = true }.Start();
        }