示例#1
0
        public void Labors_Inductive_MultiThreading_Integration_Test()
        {
            Laboratory lab = new Laboratory();

            Subject download = lab.Expanse(new InstantDeputy(typeof(FirstCurrency).FullName, nameof(FirstCurrency.GetFirstCurrency)), "Download");

            download.Add(new InstantDeputy(typeof(SecondCurrency).FullName, nameof(SecondCurrency.GetSecondCurrency)));
            download.Visor.CreateLaborers(8); /// e.g. 8 workers/consumers for downloading 2 different currency rates

            Subject compute = lab.Expanse(new InstantDeputy(typeof(ComputeCurrency).FullName, nameof(ComputeCurrency.Compute)), "Compute");

            compute.Add(new InstantDeputy(typeof(PresentResult).FullName, nameof(PresentResult.Present)));
            compute.Visor.CreateLaborers(4); /// e.g. 4 workers/consumers for computing and presenting results


            List <Labor> ComputeResultRequirements = new List <Labor>()
            {
                download[nameof(FirstCurrency.GetFirstCurrency)],
                download[nameof(SecondCurrency.GetSecondCurrency)]
            };

            download[nameof(FirstCurrency.GetFirstCurrency)]
            .Laborer
            .AddEvoker(compute[nameof(ComputeCurrency.Compute)], ComputeResultRequirements);

            download[nameof(SecondCurrency.GetSecondCurrency)]
            .Laborer
            .AddEvoker(compute[nameof(ComputeCurrency.Compute)], ComputeResultRequirements);

            compute[nameof(ComputeCurrency.Compute)]
            .Laborer
            .AddEvoker(compute[nameof(PresentResult.Present)]);

            for (int i = 1; i < 15; i++)
            {
                download[nameof(FirstCurrency.GetFirstCurrency)].Elaborate("EUR", i);
                download[nameof(SecondCurrency.GetSecondCurrency)].Elaborate("USD", i);
            }

            Thread.Sleep(15000);

            download.Visor.Close(true);
            compute.Visor.Close(true);
        }