<commit_before>﻿//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace CommSample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;

    internal sealed class Program
    {
        private static void Main(string[] args)
        {
            Logger logger = new Logger();
            TimeSpan duration = TimeSpan.FromSeconds(5.0d);
            int senderCount = 2;
            logger.WriteLine("Receive loop with {0} senders, {1:0.0} sec...", senderCount, duration.TotalSeconds);
            Receive_loop_with_N_senders(logger, senderCount, duration);
            logger.WriteLine("Done.");
        }

        private static void Receive_loop_with_N_senders(Logger logger, int senderCount, TimeSpan duration)
        {
            MemoryChannel channel = new MemoryChannel();
            int[] sentDataSizes = new int[] { 11, 19, 29, 41, 53, 71 };

            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                DataOracle oracle = new DataOracle();
                Sender[] senders = new Sender[senderCount];
                for (int i = 0; i < senders.Length; ++i)
                {
                    int bufferSize = sentDataSizes[i % sentDataSizes.Length];
                    byte fill = (byte)(i + 1);
                    senders[i] = new Sender(channel, logger, bufferSize, fill, new Delay(2, 1));
                    oracle.AddPattern(fill, bufferSize);
                }

                Receiver receiver = new Receiver(channel, logger, 16);
                receiver.DataReceived += delegate(object sender, DataEventArgs e)
                {
                };

                Task[] senderTasks = new Task[senders.Length];
                for (int i = 0; i < senderTasks.Length; ++i)
                {
                    senderTasks[i] = senders[i].RunAsync(cts.Token);
                }

                Task receiverTask = receiver.RunAsync();

                Thread.Sleep(duration);<commit_msg>Add received data validation<commit_after>﻿//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="<NAME>ers">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace CommSample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;

    internal sealed class Program
    {
        private static void Main(string[] args)
        {
            Logger logger = new Logger();
            TimeSpan duration = TimeSpan.FromSeconds(5.0d);
            int senderCount = 2;
            logger.WriteLine("Receive loop with {0} senders, {1:0.0} sec...", senderCount, duration.TotalSeconds);
            Receive_loop_with_N_senders(logger, senderCount, duration);
            logger.WriteLine("Done.");
        }

        private static void Receive_loop_with_N_senders(Logger logger, int senderCount, TimeSpan duration)
        {
            MemoryChannel channel = new MemoryChannel();
            int[] sentDataSizes = new int[] { 11, 19, 29, 41, 53, 71 };

            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                DataOracle oracle = new DataOracle();
                Sender[] senders = new Sender[senderCount];
                for (int i = 0; i < senders.Length; ++i)
                {
                    int bufferSize = sentDataSizes[i % sentDataSizes.Length];
                    byte fill = (byte)(i + 1);
                    senders[i] = new Sender(channel, logger, bufferSize, fill, new Delay(2, 1));
                    oracle.AddPattern(fill, bufferSize);
                }

                Receiver receiver = new Receiver(channel, logger, 16);
                byte lastSeen = 0;
                int lastCount = 0;
                receiver.DataReceived += delegate(object sender, DataEventArgs e)
                {
                    for (int i = 0; i < e.BytesRead; ++i)
                    {
                        if (lastSeen != e.Buffer[i])
                        {
                            if (lastSeen != 0)
                            {
                                oracle.VerifyLastSeen(lastSeen, lastCount);
                            }

                            lastSeen = e.Buffer[i];
                            lastCount = 0;
                        }

                        ++lastCount;
                    }
                };

                Task[] senderTasks = new Task[senders.Length];
                for (int i = 0; i < senderTasks.Length; ++i)
                {
                    senderTasks[i] = senders[i].RunAsync(cts.Token);
                }

                Task receiverTask = receiver.RunAsync();

                Thread.Sleep(duration);
{'fraction_non_alphanumeric': 0.15295730513121816, 'fraction_numerical': 0.011163337250293772, 'mean_word_length': 1.3213636363636363, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2975671', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1204, 'n_words': 314}