Example #1
0
        private static void SensorReadingsDemo()
        {
            Console.WriteLine("Loading sample data...");
            List <SensorDataItem> sensorDataSamples = new List <SensorDataItem>();
            IEnumerable <string>  sensorDataRaw     = File.ReadLines("data/sensor-data.csv", UTF8Encoding.UTF8);
            int r = 0;

            foreach (string s in sensorDataRaw)
            {
                if (r != 0)
                {
                    string[] splitString = s.Split(',');

                    SensorDataItem sdi = new SensorDataItem();
                    sdi.OilTemperature = decimal.Parse(splitString[1], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.PumpPressure   = decimal.Parse(splitString[2], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.MeasuredWearX  = decimal.Parse(splitString[3], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.MeasuredWearY  = decimal.Parse(splitString[4], System.Globalization.CultureInfo.InvariantCulture);

                    sensorDataSamples.Add(sdi);
                }

                r += 1;
            }
            Console.WriteLine("Done.");

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            int numOfTasks = 10;

            Task[] tasks = new Task[numOfTasks];
            for (int t = 0; t < numOfTasks; t++)
            {
                int  nt      = t + 1;
                Task newTask = new Task(() => SendSensorData(nt, token, sensorDataSamples), TaskCreationOptions.LongRunning);
                tasks[t] = newTask;
                newTask.Start();
            }

            RunTasks(tasks, tokenSource);
        }
Example #2
0
        private static void SensorReadingsDemo()
        {
            Console.WriteLine("Loading sample data...");
            List<SensorDataItem> sensorDataSamples = new List<SensorDataItem>();
            IEnumerable<string> sensorDataRaw = File.ReadLines("data/sensor-data.csv", UTF8Encoding.UTF8);
            int r = 0;
            foreach (string s in sensorDataRaw)
            {
                if (r != 0)
                {
                    string[] splitString = s.Split(',');

                    SensorDataItem sdi = new SensorDataItem();
                    sdi.OilTemperature = decimal.Parse(splitString[1], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.PumpPressure = decimal.Parse(splitString[2], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.MeasuredWearX = decimal.Parse(splitString[3], System.Globalization.CultureInfo.InvariantCulture);
                    sdi.MeasuredWearY = decimal.Parse(splitString[4], System.Globalization.CultureInfo.InvariantCulture);

                    sensorDataSamples.Add(sdi);
                }

                r += 1;
            }
            Console.WriteLine("Done.");

            var tokenSource = new CancellationTokenSource();
            var token = tokenSource.Token;

            int numOfTasks = 10;

            Task[] tasks = new Task[numOfTasks];
            for (int t = 0; t < numOfTasks; t++)
            {
                int nt = t + 1;
                Task newTask = new Task(() => SendSensorData(nt, token, sensorDataSamples), TaskCreationOptions.LongRunning);
                tasks[t] = newTask;
                newTask.Start();
            }

            RunTasks(tasks, tokenSource);
        }