示例#1
0
        private void Simulate(Station station, CancellationToken token)
        {
            double lastValue = double.NaN;

            // for smart strategy:
            double numberOfValuesGenerated = 0;

            var date = Begin;

            while (date < End && !token.IsCancellationRequested)
            {
                SetLinearValues();

                double value = 0;

                switch (Strategy)
                {
                case DistributionStrategy.Linear:
                    value = GetLinearValue(lastValue);
                    break;

                case DistributionStrategy.Random:
                    value = GetRandomValue(lastValue);
                    break;

                case DistributionStrategy.Smart:
                    value = GetSmartValue(ref numberOfValuesGenerated);
                    break;
                }

                lastValue = value;
                value     = Math.Round(value, 2);

                var measurement = new Measurement(value, CurrentMeasurementType.Id, date, station.Id, CurrentMeasurementType.Id);

                if (value >= FromValue && value <= ToValue)
                {
                    if (!IsLoadTesting)
                    {
                        MeasurementGenerated?.Invoke(station.Id, CurrentMeasurementType, measurement);
                    }

                    _simulatorService.SaveMeasurement(measurement);
                }

                Thread.Sleep((int)Math.Floor((Interval / Speed) * 1000));

                date = date.AddMinutes(Speed);
            }

            TaskCompleted();
        }