Exemple #1
0
        public IDictionary <byte, int> ComputeCounts(string filePath)
        {
            var results = new ConcurrentDictionary <byte, int>();

            using (var countdownEvent = new CountdownEvent(1))
            {
                using (Stream source = File.OpenRead(filePath))
                {
                    // use the threadpool below to create many threads working on counting bytes each 1kb
                    byte[] buffer = new byte[1024];
                    int    bytesRead;
                    while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        countdownEvent.AddCount();

                        var bytesToCount = buffer.Take(bytesRead).ToArray();
                        var counter      = new ByteCounter(bytesToCount, countdownEvent, results);

                        ThreadPool.QueueUserWorkItem(counter.Count);
                    }
                    countdownEvent.Signal();
                }
                countdownEvent.Wait();
            }

            return(results);
        }
Exemple #2
0
 private void IPSessionsForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     cts.Cancel();
     Instance = null;
     UdpDetector.Stop();
     ByteCounter.Stop();
     busyForm.Done.SetResult(true);
 }
Exemple #3
0
        public void Next_IncrementsBy1()
        {
            var generator = new ByteCounter(0);

            generator.Next().ShouldEqual((byte)1);
            generator.Next().ShouldEqual((byte)2);
            generator.Next().ShouldEqual((byte)3);
        }
        public async Task Playground_03()
        {
            var counter = new ByteCounter();

            var result = await counter.CountBytes(TEST_FOLDER_PATH);
        }
Exemple #5
0
        public void Constructor_ShouldInitializeCounterWithAStartValue()
        {
            var generator = new ByteCounter(0);

            generator.Next().ShouldEqual((byte)1);
        }
Exemple #6
0
        public void Next_Returns1WhenMaxOf255IsExceeded()
        {
            var generator = new ByteCounter(byte.MaxValue);

            generator.Next().ShouldEqual((byte)1);
        }
Exemple #7
0
        public void Reset_ReturnsZero()
        {
            var generator = new ByteCounter(5);

            generator.Reset().ShouldEqual((byte)0);
        }