Exemple #1
0
        /// <summary>
        /// Reads the file and the analysis result provide as an instance of <see cref="IDataEntity"/>.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="timeStamp">The time stamp.</param>
        /// <param name="columnSeparator">The column separator.</param>
        /// <returns>IDataEntity.</returns>
        internal static IDataEntity ReadFile(string fullPath, DateTime timeStamp, string columnSeparator)
        {
            DataEntity _ret = null;

            string[] _content   = File.ReadAllLines(fullPath);
            int      _line2Read = int.Parse(_content[0].Trim());

            _ret = new DataEntity()
            {
                TimeStamp = timeStamp, Tags = _content[_line2Read].Split(new string[] { columnSeparator }, StringSplitOptions.None)
            };
            return(_ret);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataObservable" /> class.
        /// </summary>
        /// <param name="filename">The filename to be scanned.</param>
        /// <param name="settings">The application user settings.</param>
        /// <param name="traceSource">The trace source.</param>
        /// <exception cref="System.ArgumentNullException">
        /// settings
        /// or
        /// traceSource
        /// </exception>
        internal DataObservable(string filename, ITextReaderProtocolParameters settings, ITraceSource traceSource)
        {
            m_Settings     = settings ?? throw new ArgumentNullException(nameof(settings));
            TraceSource    = traceSource ?? throw new ArgumentNullException(nameof(traceSource));
            m_FileFullPath = Path.GetFullPath(filename);
            string _path     = Path.GetDirectoryName(m_FileFullPath);
            string _fileName = Path.GetFileName(m_FileFullPath);

            m_FileSystemWatcher = new FileSystemWatcher(_path, _fileName)
            {
                IncludeSubdirectories = false, EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite
            };
            m_DataEntityObservable = Observable
                                     .FromEventPattern <FileSystemEventHandler, FileSystemEventArgs>(x => m_FileSystemWatcher.Changed += x, y => m_FileSystemWatcher.Changed -= y)
                                     .Buffer <EventPattern <FileSystemEventArgs> >(TimeSpan.FromMilliseconds(settings.DelayFileScan))
                                     .Where <IList <EventPattern <FileSystemEventArgs> > >(_list => _list.Count > 0)
                                     .Select <IList <EventPattern <FileSystemEventArgs> >, FileSystemEventPattern>(x => new FileSystemEventPattern(x[x.Count - 1]))
                                     .Delay <FileSystemEventPattern>(TimeSpan.FromMilliseconds(settings.DelayFileScan))
                                     .Select <FileSystemEventPattern, IDataEntity>(x => DataEntity.ReadFile(x.EventPattern.EventArgs.FullPath, x.TimeStamp, m_Settings.ColumnSeparator))
                                     .Do <IDataEntity>(data => { }, exception => LogException(exception));
            TraceSource.TraceMessage(TraceEventType.Verbose, 107, $"Successfully created data observer for the file {filename} with parameters {settings}");
        }