コード例 #1
0
    // Start is called before the first frame update
    private async void Awake()
    {
        Core.RunCoreAtMainTread();
        //Core.RunCore();

        try
        {
            //var executor = new ThreadPoolExecutor();
            var executor = new ThreadExecutor();

            Core.AddActor("main/one", new ActorOne(executor));
            Core.AddActor("main/two", new ActorTwo(executor));

            var actor = await Core.GetActor <ActorOne.Invoker>("main/one");

            Debug.Log($"Actor: {actor}");
            for (int i = 0; i != Count + 1; i++)
            {
                actor.SumInvoke(i, 10);
            }

            Debug.LogWarning("Add all");
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
コード例 #2
0
    public void FindByIndex_ThreadExecutor_ShouldWorkCorrectly()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();
        Task       task1    = new Task(5, 1, Priority.HIGH);
        Task       task2    = new Task(6, 3, Priority.LOW);
        Task       task3    = new Task(7, 6, Priority.LOW);
        Task       task4    = new Task(8, 3, Priority.EXTREME);
        Task       task5    = new Task(9, 5, Priority.MEDIUM);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task3);

        //Assert
        Assert.AreEqual(5, executor.Count);
        Assert.AreSame(task1, executor.GetByIndex(0));
        Assert.AreSame(task2, executor.GetByIndex(1));
        Assert.AreSame(task4, executor.GetByIndex(2));
        Assert.AreSame(task5, executor.GetByIndex(3));
        Assert.AreSame(task3, executor.GetByIndex(4));
    }
コード例 #3
0
    public void Contains_100000_Elements_ShouldExecuteFast()
    {
        // Arrange
        IScheduler        executor = new ThreadExecutor();
        const int         count    = 100000;
        LinkedList <Task> tasks    = new LinkedList <Task>();

        for (int i = 0; i < count; i++)
        {
            tasks.AddLast(new Task(i, i, Priority.HIGH));
            executor.Execute(tasks.Last.Value);
        }

        // Act
        Stopwatch             sw   = Stopwatch.StartNew();
        LinkedListNode <Task> node = tasks.First;

        while (node != null)
        {
            Assert.True(executor.Contains(node.Value));
            node = node.Next;
        }

        sw.Stop();
        Assert.Less(sw.ElapsedMilliseconds, 250);
    }
コード例 #4
0
    public void FindByIndex_ThreadExecutor_ShouldWorkFast()
    {
        // Arrange
        IScheduler  executor = new ThreadExecutor();
        const int   count    = 10000;
        List <Task> tasks    = new List <Task>();

        for (int i = 0; i < count; i++)
        {
            tasks.Add(new Task(i, i, Priority.HIGH));
            executor.Execute(tasks[i]);
        }

        // Act
        Stopwatch sw   = Stopwatch.StartNew();
        Random    rand = new Random();

        for (int i = 0; i < 10_000; i++)
        {
            int rnd = rand.Next(0, 1500);
            Assert.AreEqual(tasks[rnd], executor.GetByIndex(rnd));
        }
        // Assert
        sw.Stop();
        Assert.Less(sw.ElapsedMilliseconds, 150);
    }
コード例 #5
0
    public void FindById_ThreadExecutor_ShouldWorkCorrectly()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();
        Task       task1    = new Task(5, 6, Priority.HIGH);
        Task       task2    = new Task(6, 2, Priority.LOW);
        Task       task3    = new Task(7, 4, Priority.LOW);
        Task       task4    = new Task(0, 56, Priority.EXTREME);
        Task       task5    = new Task(0, 56, Priority.EXTREME);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);

        Task result1 = executor.GetById(5);
        Task result2 = executor.GetById(6);
        Task result3 = executor.GetById(7);
        Task result4 = executor.GetById(0);

        //Assert
        Assert.AreSame(result1, task1);
        Assert.AreSame(result2, task2);
        Assert.AreSame(result3, task3);
        Assert.AreSame(result4, task4);
        Assert.AreNotSame(result4, task5);
    }
コード例 #6
0
ファイル: Perf2.cs プロジェクト: OOP-03376400/Data-Structures
    public void FindById_ThreadExecutor_ShouldWorkFast()
    {
        // Arrange
        IScheduler        executor = new ThreadExecutor();
        const int         count    = 100000;
        LinkedList <Task> tasks    = new LinkedList <Task>();

        for (int i = 0; i < count; i++)
        {
            tasks.AddLast(new Task(i + 1, i, Priority.HIGH));
            executor.Execute(tasks.Last.Value);
        }

        // Act
        Stopwatch             sw   = Stopwatch.StartNew();
        LinkedListNode <Task> node = tasks.First;

        while (node != null)
        {
            Assert.AreSame(node.Value, executor.GetById(node.Value.Id));
            node = node.Next;
        }

        sw.Stop();
        Assert.Less(sw.ElapsedMilliseconds, 250);
    }
コード例 #7
0
    public void GetByPriorityAndMinimumConsumption_ThreadExecutor_ShouldReturnEmptyCollection()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task        task1    = new Task(52, 5, Priority.LOW);
        Task        task2    = new Task(56, 12, Priority.HIGH);
        Task        task3    = new Task(58, 12, Priority.LOW);
        Task        task4    = new Task(100, 51, Priority.HIGH);
        Task        task5    = new Task(600, 15, Priority.MEDIUM);
        Task        task6    = new Task(12, 5, Priority.EXTREME);
        Task        task7    = new Task(125, 6, Priority.MEDIUM);
        Task        task8    = new Task(0, 8, Priority.HIGH);
        List <Task> expected = new List <Task>();

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task6);
        executor.Execute(task7);
        executor.Execute(task8);

        executor.ChangePriority(56, Priority.LOW);
        executor.ChangePriority(52, Priority.HIGH);

        executor.Cycle(12);
        //Assert
        List <Task> actual = executor.GetByPriorityAndMinimumConsumption(Priority.LOW, 10).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
コード例 #8
0
ファイル: Test17.cs プロジェクト: SonicTheCat/Data-Structures
    public void GetByPriority_ThreadExecutor_ShouldWorkCorrectly()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task        task1    = new Task(52, 5, Priority.HIGH);
        Task        task2    = new Task(56, 12, Priority.HIGH);
        Task        task3    = new Task(58, 12, Priority.LOW);
        Task        task4    = new Task(100, 51, Priority.HIGH);
        Task        task5    = new Task(600, 15, Priority.MEDIUM);
        Task        task6    = new Task(12, 5, Priority.EXTREME);
        Task        task7    = new Task(125, 6, Priority.MEDIUM);
        Task        task8    = new Task(0, 8, Priority.LOW);
        List <Task> expected = new List <Task>()
        {
            task4, task2, task1
        };

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task6);
        executor.Execute(task7);
        executor.Execute(task8);
        Assert.AreEqual(8, executor.Count);

        //Assert
        List <Task> actual = executor.GetByPriority(Priority.HIGH).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
コード例 #9
0
ファイル: Perf1.cs プロジェクト: OOP-03376400/Data-Structures
    public void Execute_ThreadExecutor_ShouldWorkFast()
    {
        //Arange

        const int items = 80_000;

        IScheduler executor = new ThreadExecutor();
        Stopwatch  watch    = new Stopwatch();

        //Act
        watch.Start();
        Random rand = new Random();

        for (int i = 0; i < items; i++)
        {
            executor.Execute(new Task(i, rand.Next(0, 2000), Priority.EXTREME));
        }
        watch.Stop();

        Assert.AreEqual(items, executor.Count);
        //Assert
        long elapsed = watch.ElapsedMilliseconds;

        Assert.Less(elapsed, 400);
    }
コード例 #10
0
    public void Cycle_ThreadExecutor_ShouldWorkCorrectly()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(5, 5, Priority.HIGH);
        Task task2 = new Task(6, 5, Priority.LOW);
        Task task3 = new Task(7, 12, Priority.MEDIUM);
        Task task4 = new Task(12, 5, Priority.HIGH);
        Task task5 = new Task(15, 3, Priority.LOW);
        Task task6 = new Task(19, 2, Priority.LOW);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task6);

        Assert.AreEqual(6, executor.Count);
        executor.Cycle(3);
        Assert.AreEqual(4, executor.Count);
        Assert.Throws <ArgumentException>(() => executor.GetById(19));
        Assert.Throws <ArgumentException>(() => executor.GetById(15));
        executor.Cycle(5);

        //Assert
        Assert.AreEqual(1, executor.Count);
        Task t = executor.GetByIndex(0);

        Assert.AreSame(task3, t);
        Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(1));
    }
コード例 #11
0
    public void Cycle_ThreadExecutor_ShouldThrowWhenEmpty()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        //Act
        //Assert
        Assert.Throws <InvalidOperationException>(() => executor.Cycle(1));
    }
コード例 #12
0
        private void btnZtBeginUnInput_Click(object sender, EventArgs e)
        {
            this.txtZtInputData.Text = "";
            this.AllowZtInput        = true;
            Zt598Importer.ZT_EPP_OpenKeyVoic(3);
            ThreadExecutor thread = new ThreadExecutor(ZtUnEncryptInput);

            thread.BeginInvoke(null, null);
        }
コード例 #13
0
    public void FindByIndex_ThreadExecutor_ShouldThrowWhenEmpty()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();

        //Act
        //Assert
        Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(0));
    }
コード例 #14
0
ファイル: Program.cs プロジェクト: IvayloIV/Data-Structures
    static void Main(string[] args)
    {
        var executor = new ThreadExecutor();

        executor.Execute(new Task(12, 5, Priority.EXTREME));
        executor.Execute(new Task(13, 10, Priority.EXTREME));
        executor.Execute(new Task(14, 15, Priority.EXTREME));

        Console.WriteLine(executor.Cycle(5));
    }
コード例 #15
0
    public void ChangePriority_ThreadExecutor_ShouldThrow_On_InvalidArgument()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        //Act

        //Assert
        Assert.Throws <ArgumentException>(() => executor.ChangePriority(600, Priority.HIGH));
    }
コード例 #16
0
ファイル: Perf4.cs プロジェクト: OOP-03376400/Data-Structures
    public void GetByConsumptionRange_ThreadExecutor_ShouldWorkFast()
    {
        //Arange
        const int items = 100_000;

        IScheduler  executor = new ThreadExecutor();
        Stopwatch   watch    = new Stopwatch();
        List <Task> expected = new List <Task>();

        Priority[] priorities = new Priority[] { Priority.LOW, Priority.MEDIUM, Priority.HIGH, Priority.EXTREME };
        Random     rand       = new Random();

        //Act
        for (int i = 0; i < items; i++)
        {
            Task task = new Task(i, rand.Next(0, 10000), priorities[rand.Next(0, 4)]);
            expected.Add(task);
            executor.Execute(task);
        }

        //do
        List <Tuple <int, int> > ranges = new List <Tuple <int, int> >();
        List <List <Task> >      tasks  = new List <List <Task> >();

        for (int i = 0; i < 100; i++)
        {
            int lower = rand.Next(2500, 5000);
            int upper = rand.Next(5005, 9999);

            ranges.Add(new Tuple <int, int>(lower, upper));
            tasks.Add(expected
                      .Where(x => x.Consumption >= lower && x.Consumption <= upper)
                      .OrderBy(x => x.Consumption)
                      .ThenByDescending(x => x.TaskPriority)
                      .ToList()
                      );
        }

        watch.Start();

        List <IEnumerable <Task> > actualTasks = new List <IEnumerable <Task> >();

        for (int i = 0; i < 100; i++)
        {
            var range = ranges[i];
            actualTasks.Add(executor.GetByConsumptionRange(range.Item1, range.Item2, true));
        }

        watch.Stop();

        //Assert
        Assert.Less(watch.ElapsedMilliseconds, 200);
        CollectionAssert.AreEqual(tasks, actualTasks);
    }
コード例 #17
0
    public void Cycle_ThreadExecutor_ShouldReturnCorrectRemovalCount()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(5, 5, Priority.HIGH);
        Task task2 = new Task(6, 5, Priority.LOW);
        Task task3 = new Task(7, 12, Priority.MEDIUM);
        Task task4 = new Task(12, 5, Priority.HIGH);
        Task task5 = new Task(15, 3, Priority.HIGH);
        Task task6 = new Task(19, 2, Priority.EXTREME);
        Task task7 = new Task(23, 16, Priority.LOW);
        Task task8 = new Task(73, 6, Priority.LOW);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task6);
        executor.Execute(task7);
        executor.Execute(task8);

        //Assert
        Assert.AreEqual(8, executor.Count);
        List <Task> expectedStructure = new List <Task>()
        {
            task1, task2, task3, task4, task5, task6, task7, task8
        };
        List <Task> actualStructure = new List <Task>();

        executor.ToList().ForEach(x => actualStructure.Add(x));
        CollectionAssert.AreEqual(expectedStructure, actualStructure);
        Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(-5));

        int cycleCount = executor.Cycle(5);

        Assert.AreEqual(5, cycleCount);
        cycleCount = executor.Cycle(12);
        Assert.AreEqual(3, cycleCount);

        Assert.AreEqual(0, executor.Count);

        expectedStructure = new List <Task>()
        {
        };
        actualStructure = new List <Task>();
        executor.ToList().ForEach(x => actualStructure.Add(x));
        CollectionAssert.AreEqual(expectedStructure, actualStructure);
    }
コード例 #18
0
    public void Contains_ThreadExecutor_ShouldWorkCorrectly_AfterCycle()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(52, 12, Priority.EXTREME);
        Task task2 = new Task(13, 8, Priority.HIGH);

        //Act
        executor.Execute(task2);

        //Assert
        Assert.AreEqual(1, executor.Count);
        Assert.False(executor.Contains(task1));
    }
コード例 #19
0
    public void FindByIndex_ThreadExecutor_ShouldThrowWhenOutOfBounds()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();
        //Act
        Task task1 = new Task(5, 6, Priority.HIGH);
        Task task2 = new Task(6, 2, Priority.LOW);

        executor.Execute(task1);
        executor.Execute(task2);

        //Assert
        Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(-5));
        Assert.Throws <ArgumentOutOfRangeException>(() => executor.GetByIndex(5));
    }
コード例 #20
0
        private void btnCashCodeIdentify_Click(object sender, EventArgs e)
        {
            StringBuilder msg    = new StringBuilder();
            int           result = CashCodeImporter.StartIdentifyV2("", "", this.GetCashCodeSetting(), msg);

            this.lbCashCodeHint.Text = "准备投币返回code:" + result + "返回msg:" + msg;
            this.AllowAcceptMoney    = true;
            ThreadExecutor thread = new ThreadExecutor(IdentifyMoney);

            thread.BeginInvoke(null, null);

            //Thread thread = new Thread();
            // thread.IsBackground = true;
            // thread.Start();
        }
コード例 #21
0
    public void AddingTask_ThreadExecutor_CountShouldIncrease()
    {
        //Arrange
        Task task1 = new Task(52, 12, Priority.EXTREME);
        Task task2 = new Task(13, 66, Priority.HIGH);

        IScheduler executor = new ThreadExecutor();

        //Act
        executor.Execute(task1);
        executor.Execute(task2);

        //Assert
        Assert.AreEqual(2, executor.Count);
    }
コード例 #22
0
    public void GetByConsumptionRange_ThreadExecutor_ShouldReturnAnEmptyCollection()
    {
        //Arange
        IScheduler executor  = new ThreadExecutor();
        IScheduler executor2 = new ThreadExecutor();

        Task task1 = new Task(52, 5, Priority.HIGH);
        Task task2 = new Task(153, 7, Priority.LOW);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);

        //Assert
        CollectionAssert.IsEmpty(executor2.GetByConsumptionRange(5, 6, true));
        CollectionAssert.AreEqual(new List <Task>(), executor.GetByConsumptionRange(6, 6, true));
    }
コード例 #23
0
    public void Enumerator_ThreadExecutor_ShouldReturnEmptyCollection()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(52, 5, Priority.HIGH);
        Task task2 = new Task(56, 12, Priority.HIGH);

        List <Task> expected = new List <Task>();

        //Act
        Assert.AreEqual(0, executor.Count);

        //Assert
        List <Task> actual = executor.ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
コード例 #24
0
ファイル: Test3.cs プロジェクト: OOP-03376400/Data-Structures
    public void AddingExistingId_ThreadExecutor_ShouldThrowException()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(5, 1, Priority.EXTREME);
        Task task2 = new Task(6, 1, Priority.HIGH);
        Task task3 = new Task(12, 5, Priority.MEDIUM);
        Task task4 = new Task(12, 5, Priority.HIGH);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);

        //Assert
        Assert.AreEqual(3, executor.Count);
        Assert.Throws <ArgumentException>(() => executor.Execute(task4));
    }
コード例 #25
0
    public void FindById_ThreadExecutor_OnNonExistingId_ShouldThrow()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();
        Task       task1    = new Task(5, 6, Priority.HIGH);
        Task       task2    = new Task(6, 2, Priority.LOW);
        Task       task3    = new Task(7, 4, Priority.LOW);
        Task       task4    = new Task(0, 56, Priority.EXTREME);
        Task       task5    = new Task(0, 56, Priority.EXTREME);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);

        //Assert
        Assert.AreEqual(4, executor.Count);
        Assert.Throws <ArgumentException>(() => executor.GetById(12));
    }
コード例 #26
0
    public void Cycle_ThreadExecutor_ShouldRemoveFast()
    {
        //Arange
        const int count = 100_000;

        IScheduler executor = new ThreadExecutor();
        Stopwatch  watch    = new Stopwatch();

        Random rand = new Random();

        Priority[] priorities = new Priority[] { Priority.LOW, Priority.MEDIUM, Priority.HIGH, Priority.EXTREME };

        List <Task> tasks = new List <Task>();

        //Act
        for (int i = 1; i < count; i++)
        {
            Task t = new Task(i, i, priorities[rand.Next(0, 4)]);
            tasks.Add(t);
            executor.Execute(t);
        }

        watch.Start();

        int totalCycles = 0;

        for (int i = 0; i < 1000; i++)
        {
            int cycles = rand.Next(10, 100);
            executor.Cycle(cycles);
            totalCycles += cycles;
        }
        List <Task> exepcted = tasks.Skip(totalCycles).ToList();

        CollectionAssert.AreEqual(exepcted, executor.ToList());

        watch.Stop();

        //Assert
        Assert.Less(watch.ElapsedMilliseconds, 200);
    }
コード例 #27
0
        private void btnZtInputUserPwd_Click(object sender, EventArgs e)
        {
            this.SetParam();
            this.txtZtUserPwd.Text = "";

            this.AllowZtInput = true;

            pwdLen    = Convert.ToInt32(this.txtZtEncryptLength.Text);
            pwdNowLen = 0;
            ztPinMode = this.rbZtFrontEncrypt.Checked ? 1 : 0;
            if (ztPinMode == 1)
            {
                Zt598Importer.ZT_EPP_PinLoadCardNo(this.txtZtEncryptPan.Text);
                Zt598Importer.ZT_EPP_ActivWorkPin(this.ztMainId, this.ztWorkId);
            }
            Zt598Importer.ZT_EPP_OpenKeyVoic(2);
            Zt598Importer.ZT_EPP_PinStartAdd(Convert.ToInt32(this.txtZtEncryptLength.Text), 1, ztPinMode, 0, this.ztTimeout);
            ThreadExecutor thread = new ThreadExecutor(ZtPwdEncryptInput);

            thread.BeginInvoke(null, null);
        }
コード例 #28
0
    public void GetByPriorityAndMinimumConsumption_ThreadExecutor_ShouldWorkCorrectly_AfterCycle()
    {
        //Arange
        IScheduler executor = new ThreadExecutor();

        Task        task1    = new Task(52, 5, Priority.LOW);
        Task        task2    = new Task(56, 12, Priority.LOW);
        Task        task3    = new Task(58, 12, Priority.LOW);
        Task        task4    = new Task(100, 14, Priority.LOW);
        Task        task5    = new Task(600, 15, Priority.LOW);
        Task        task6    = new Task(12, 5, Priority.LOW);
        Task        task7    = new Task(125, 6, Priority.LOW);
        Task        task8    = new Task(0, 8, Priority.EXTREME);
        List <Task> expected = new List <Task>()
        {
            task5
        };

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);
        executor.Execute(task4);
        executor.Execute(task5);
        executor.Execute(task6);
        executor.Execute(task7);
        executor.Execute(task8);

        Assert.AreEqual(8, executor.Count);

        executor.Cycle(5);
        executor.Cycle(5);
        executor.Cycle(4);

        //Assert
        List <Task> actual = executor.GetByPriorityAndMinimumConsumption(Priority.LOW, 10).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
コード例 #29
0
    public void Addition_ThreadExecutor_ShouldAddCorrectTasks()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();
        Task       task1    = new Task(5, 1, Priority.EXTREME);
        Task       task2    = new Task(6, 5, Priority.HIGH);
        Task       task3    = new Task(12, 12, Priority.LOW);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);
        executor.Execute(task3);

        //Assert
        Task result1 = executor.GetByIndex(0);
        Task result2 = executor.GetByIndex(1);
        Task result3 = executor.GetByIndex(2);

        Assert.AreSame(task1, result1);
        Assert.AreSame(task2, result2);
        Assert.AreSame(task3, result3);
    }
コード例 #30
0
ファイル: Form1.cs プロジェクト: romanu6891/fivemen
        private void btnZtInputUserPwd_Click(object sender, EventArgs e)
        {
            this.SetParam();
            this.txtZtUserPwd.Text = "";

            this.AllowZtInput = true;

               pwdLen= Convert.ToInt32(this.txtZtEncryptLength.Text);
               pwdNowLen = 0;
               ztPinMode = this.rbZtFrontEncrypt.Checked ? 1 : 0;
               if (ztPinMode == 1)
               {
               Zt598Importer.ZT_EPP_PinLoadCardNo(this.txtZtEncryptPan.Text);
               Zt598Importer.ZT_EPP_ActivWorkPin(this.ztMainId,this.ztWorkId);
               }
            Zt598Importer.ZT_EPP_OpenKeyVoic(2);
            Zt598Importer.ZT_EPP_PinStartAdd(Convert.ToInt32(this.txtZtEncryptLength.Text), 1, ztPinMode, 0, this.ztTimeout);
            ThreadExecutor thread = new ThreadExecutor(ZtPwdEncryptInput);
            thread.BeginInvoke(null, null);
        }
コード例 #31
0
    public void ChangePriority_ThreadExecutor_ShouldWorkFast()
    {
        //Arange
        const int  items    = 100_000;
        IScheduler executor = new ThreadExecutor();

        Stopwatch watch = new Stopwatch();
        Dictionary <Priority, List <Task> > dict = new Dictionary <Priority, List <Task> >();

        dict.Add(Priority.LOW, new List <Task>());
        dict.Add(Priority.MEDIUM, new List <Task>());
        dict.Add(Priority.HIGH, new List <Task>());
        dict.Add(Priority.EXTREME, new List <Task>());

        Priority[] priorities = new Priority[] { Priority.LOW, Priority.MEDIUM, Priority.HIGH, Priority.EXTREME };
        Random     rand       = new Random();

        //Act
        for (int i = 0; i < items; i++)
        {
            Task task = new Task(i, rand.Next(0, 10000), priorities[rand.Next(0, 4)]);
            dict[task.TaskPriority].Add(task);
            executor.Execute(task);
        }

        dict[Priority.LOW]     = dict[Priority.LOW].OrderByDescending(x => x.Id).ToList();
        dict[Priority.MEDIUM]  = dict[Priority.MEDIUM].OrderByDescending(x => x.Id).ToList();
        dict[Priority.HIGH]    = dict[Priority.HIGH].OrderByDescending(x => x.Id).ToList();
        dict[Priority.EXTREME] = dict[Priority.EXTREME].OrderByDescending(x => x.Id).ToList();
        //Act

        Priority p1 = priorities[rand.Next(0, 4)];
        Priority p2 = priorities[rand.Next(0, 4)];

        int         randomCount = rand.Next(5000, 6000);
        List <Task> p2Tasks     = dict[p2].Skip(randomCount - (randomCount / 2)).Take(randomCount).ToList();
        List <Task> p1Tasks     = dict[p1].Skip(randomCount - (randomCount / 2)).Take(randomCount).ToList();

        watch.Start();
        int min = Math.Min(p1Tasks.Count, p2Tasks.Count);

        for (int i = 0; i < min; i++)
        {
            executor.ChangePriority(p1Tasks[i].Id, p2);
            executor.ChangePriority(p2Tasks[i].Id, p1);
        }

        watch.Stop();

        dict[p1].RemoveRange(randomCount - (randomCount / 2), randomCount);
        dict[p2].RemoveRange(randomCount - (randomCount / 2), randomCount);
        dict[p1].AddRange(p2Tasks);
        dict[p2].AddRange(p1Tasks);

        dict[p1] = dict[p1].OrderByDescending(x => x.Id).ToList();
        dict[p2] = dict[p2].OrderByDescending(x => x.Id).ToList();

        CollectionAssert.AreEqual(dict[p1], executor.GetByPriority(p1));
        CollectionAssert.AreEqual(dict[p2], executor.GetByPriority(p2));

        //Assert

        Assert.Less(watch.ElapsedMilliseconds, 200);
    }
コード例 #32
0
ファイル: Form1.cs プロジェクト: romanu6891/fivemen
        private void btnCashCodeIdentify_Click(object sender, EventArgs e)
        {
            StringBuilder msg = new StringBuilder();
             int result=CashCodeImporter.StartIdentifyV2("", "", this.GetCashCodeSetting(), msg);
             this.lbCashCodeHint.Text = "准备投币返回code:" + result + "返回msg:" + msg;
             this.AllowAcceptMoney = true;
             ThreadExecutor thread = new ThreadExecutor(IdentifyMoney);
             thread.BeginInvoke(null, null);

             //Thread thread = new Thread();
            // thread.IsBackground = true;
            // thread.Start();
        }
コード例 #33
0
ファイル: Form1.cs プロジェクト: romanu6891/fivemen
 private void btnZtBeginUnInput_Click(object sender, EventArgs e)
 {
     this.txtZtInputData.Text = "";
     this.AllowZtInput=true;
     Zt598Importer.ZT_EPP_OpenKeyVoic(3);
      ThreadExecutor thread = new ThreadExecutor(ZtUnEncryptInput);
      thread.BeginInvoke(null, null);
 }