Пример #1
0
        private IDataSource AddDataSource(DataSource settings)
        {
            lock (_syncRoot)
            {
                IDataSource dataSource;
                if (!string.IsNullOrEmpty(settings.LogFileFolderPath))
                {
                    dataSource = new FolderDataSource(_taskScheduler, _logSourceFactory, _filesystem, settings);
                }
                else if (!string.IsNullOrEmpty(settings.File))
                {
                    dataSource = new FileDataSource(_logSourceFactory, _taskScheduler, settings, _maximumWaitTime);
                }
                else if (settings.CustomDataSourceConfiguration != null)
                {
                    dataSource = new CustomDataSource(_logSourceFactory, _taskScheduler, settings, _maximumWaitTime);
                }
                else
                {
                    if (settings.DisplayName == null)
                    {
                        settings.DisplayName = "Merged Data Source";
                    }

                    dataSource = new MergedDataSource(_taskScheduler, settings, _maximumWaitTime);
                }

                _dataSources.Add(dataSource);
                _dataSourceIds.Add(dataSource.Id);
                _bookmarks.AddDataSource(dataSource);
                return(dataSource);
            }
        }
Пример #2
0
        private IReadOnlyList <IDataSource> SynchronizeDataSources(IReadOnlyList <IFileInfo> files)
        {
            var newFiles    = new List <IFileInfo>();
            var oldFiles    = new List <IFileInfo>();
            var dataSources = new List <IDataSource>();

            try
            {
                lock (_syncRoot)
                {
                    foreach (var file in _dataSources.Keys)
                    {
                        if (!files.Contains(file))
                        {
                            oldFiles.Add(file);
                        }
                    }

                    foreach (var file in oldFiles)
                    {
                        _dataSources.TryGetValue(file, out var dataSource);
                        _dataSources.Remove(file);
                        dataSource?.Dispose();
                    }

                    foreach (var file in files)
                    {
                        if (!_dataSources.TryGetValue(file, out var dataSource))
                        {
                            // We'll print a nice warning to the user if this happens
                            if (_dataSources.Count >= LogEntrySourceId.MaxSources)
                            {
                                break;
                            }

                            var settings = new DataSource(file.FullPath)
                            {
                                Id = DataSourceId.CreateNew()
                            };
                            dataSource = new FileDataSource(_logSourceFactory,
                                                            _taskScheduler,
                                                            settings);
                            _dataSources.Add(file, dataSource);
                            newFiles.Add(file);
                        }

                        dataSources.Add(dataSource);
                    }
                }
            }
            catch (Exception)
            {
                foreach (var dataSource in dataSources)
                {
                    dataSource.Dispose();
                }
                throw;
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Adding #{0} files ({1}), removing #{2} files ({3})",
                                newFiles.Count,
                                string.Join(", ", newFiles.Select(x => x.FullPath)),
                                oldFiles.Count,
                                string.Join(", ", oldFiles.Select(x => x.FullPath)));
            }

            return(dataSources);
        }