public void Open(ILogRecordFormat recordFormat) { var fileName = Properties.Settings.Default.TextFilePath; _logger.Info("Открытие файла {0}", fileName); _recordFormat = recordFormat; _cts = new CancellationTokenSource(); _file = new StreamReader(fileName); _messageCounter = 0; var readTask = Task.Run(async() => { _logger.Info("Запуск потока чтения файла"); string line; while ((line = _file.ReadLine()) != null) { _messageCounter++; DataReceived?.Invoke(this, new ReceiveEventArgs() { Data = Encoding.ASCII.GetBytes(line) }); await Task.Delay(10, _cts.Token); } }, _cts.Token); readTask.ContinueWith(_ => ReadError?.Invoke(this, new ErrorEventArgs(_.Exception)), TaskContinuationOptions.OnlyOnFaulted); }
public void Open(ILogRecordFormat recordFormat) { _recordFormat = recordFormat; _messageCounter = 0; InitReceiver(); Task.Run(() => Read(), _cts.Token).ContinueWith(_ => ReadError?.Invoke(this, new ErrorEventArgs(_.Exception)), TaskContinuationOptions.OnlyOnFaulted); }
public Processor(IReader reader, IPublisher publisher, ILogRecordFormat logRecordFormat) { _publisher = publisher; _reader = reader; _logRecordFormat = logRecordFormat; _timer = new Timer((s) => PublishDataPoints(), null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); foreach (var type in Util.GetTypesWithAttribute <DataPointAttribute>()) { var name = type.GetCustomAttribute <DataPointAttribute>().Name; _logTypes.Add(name, type); _logQueues.Add(name, new List <object>()); } foreach (var type in Util.GetTypesWithAttribute <ListConverterAttribute>()) { var name = type.GetCustomAttribute <ListConverterAttribute>().Name; _logListConverters.Add(name, (IListConverter)Activator.CreateInstance(type)); } }