Пример #1
0
        public DataSources(ILogFileFactory logFileFactory, ITaskScheduler taskScheduler, IDataSourcesSettings settings)
        {
            if (logFileFactory == null)
            {
                throw new ArgumentNullException(nameof(logFileFactory));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _logFileFactory  = logFileFactory;
            _taskScheduler   = taskScheduler;
            _maximumWaitTime = TimeSpan.FromMilliseconds(100);
            _syncRoot        = new object();
            _settings        = settings;
            _bookmarks       = new BookmarkCollection(_maximumWaitTime);
            _dataSources     = new List <IDataSource>();
            _dataSourceIds   = new HashSet <DataSourceId>();
            foreach (DataSource dataSource in settings)
            {
                AddDataSource(dataSource);
            }

            foreach (IDataSource dataSource in _dataSources)
            {
                DataSourceId parentId = dataSource.Settings.ParentId;
                if (parentId != DataSourceId.Empty)
                {
                    var parent = _dataSources.FirstOrDefault(x => x.Id == parentId) as MergedDataSource;
                    if (parent != null)
                    {
                        parent.Add(dataSource);
                    }
                    else
                    {
                        Log.WarnFormat("DataSource '{0} ({1})' is assigned a parent '{2}' but we don't know that one",
                                       dataSource.FullFileName,
                                       dataSource.Id,
                                       parentId);
                        // We don't want the rest of the application having to deal with this.
                        // Therefore we'll simply remove the parent link and treat this data
                        // source as any other ungrouped one.
                        dataSource.Settings.ParentId = DataSourceId.Empty;
                    }
                }
            }
        }