Exemplo n.º 1
0
 public FileProcessor(ILog log, ILogProcessingConfiguration configuration, ILogProcessor logProcessor, ILogEntryGroupBox groupBox)
 {
     Log          = log;
     LogProcessor = logProcessor;
     GroupBox     = groupBox;
     Encoding     = CodePagesEncodingProvider.Instance.GetEncoding(configuration.Encoding) ?? Encoding.UTF8;
 }
 public void ProcessingLogs(ILogProcessor processor, FilterLog[] logs)
 {
     if (IsInfoEnabled)
     {
         Logger.Info($"Processing Logs.  Processor: {processor.GetType().FullName}, Logs: {logs.Length}");
     }
 }
Exemplo n.º 3
0
        public static void ProcessSheetWithProcessor(Worksheet sheet, ILogProcessor processor)
        {
            Sheets sheets = ThisAddIn.app.ActiveWorkbook.Sheets;

            // Check if the data chosen was already processed
            for (int n = 1; n <= sheets.Count; n++)
            {
                if (sheets[n].Name == Util.GetProcessedName(sheet.Name))
                {
                    return;
                }
            }

            // Disable UI updates
            ThisAddIn.app.ScreenUpdating = false;
            bool displayStatusBar = ThisAddIn.app.DisplayStatusBar;

            ThisAddIn.app.DisplayStatusBar = false;
            XlCalculation calculation = ThisAddIn.app.Calculation;

            ThisAddIn.app.Calculation = XlCalculation.xlCalculationManual;
            bool enableEvents = ThisAddIn.app.EnableEvents;

            ThisAddIn.app.EnableEvents = false;


            Worksheet outputSheet = AddSheetForOutput(sheet);

            System.Diagnostics.Trace.WriteLine("About to construct FastSheetReader at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());
            FastSheetReader reader = new FastSheetReader(sheet, processor.GetSeparator());

            System.Diagnostics.Trace.WriteLine("Finished constructing FastSheetReader at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());
            FastSheetWriter writer = new FastSheetWriter(outputSheet);

            System.Diagnostics.Trace.WriteLine("Finished constructing FastSheetWriter at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());

            Util.RunPipeline(reader, processor, writer, true);
            System.Diagnostics.Trace.WriteLine("Finished running pipeline at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());

            writer.Flush();
            System.Diagnostics.Trace.WriteLine("Flushed writer at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());

            // Tag the sheet with a machine type mark so we don't have to dig into the cell
            // data to identify machine type when trying to generate summary statistics
            outputSheet.CustomProperties.Add(Util.MACHINE_TYPE_MARK_NAME, processor.GetUniqueTag());

            // Re-enable UI updates
            ThisAddIn.app.ScreenUpdating   = true;
            ThisAddIn.app.DisplayStatusBar = displayStatusBar;
            ThisAddIn.app.Calculation      = calculation;
            ThisAddIn.app.EnableEvents     = enableEvents;

            writer.FormatPretty();
            System.Diagnostics.Trace.WriteLine("Finished format pretty at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());

            // Don't AutoFit, as it can be really slow.
            outputSheet.Columns.AutoFit();
            System.Diagnostics.Trace.WriteLine("Returning at " + new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());
        }
Exemplo n.º 4
0
 public LogFileReader(IOptions <FileGatewayConfiguration> settings, ILogProcessor logProcessor)
 {
     _settings           = settings.Value;
     _logProcessor       = logProcessor;
     _internalDictionary = new ConcurrentDictionary <string, long>();
     Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(PollFiles);
     //_internalWatcher.EnableRaisingEvents = true;
 }
Exemplo n.º 5
0
 public Controller()
 {
     ConfigurePath();
     _logProcessor          = new LogProcessor();
     _pythonScriptRunner    = new PythonScriptRunner(PythonScriptFilePath);
     _fileConversionUtility = new FileConversionUtility();
     _conceptLattice        = new Algorithm();
 }
        public void AddLoggerMethod1SadPath2()
        {
            var           services     = new ServiceCollection();
            ILogProcessor logProcessor = null;

            Action act = () => services.AddLogger(logProcessor);

            act.Should().ThrowExactly <ArgumentNullException>().WithMessage("*logProcessor*");
        }
Exemplo n.º 7
0
        protected ScriptorLogger(string name, IExternalScopeProvider scopeProvider, ILogProcessor logProcessor)
        {
            _logProcessor = logProcessor ?? throw new ArgumentException("logProcessor cannot be null", nameof(logProcessor));

            _scopeProvider = scopeProvider ?? new LoggerExternalScopeProvider();
            Name           = name ?? throw new ArgumentNullException(nameof(name));
            Filter         = (category, logLevel) => true;

            Compose = ComposeInternal;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Logger"/> class.
 /// </summary>
 /// <param name="logProcessor">The object responsible for processing logs.</param>
 /// <param name="name">The name of the logger.</param>
 /// <param name="level">The logging level of the logger.</param>
 /// <param name="logProviders">A collection of <see cref="ILogProvider"/> objects used by this logger.</param>
 /// <param name="isDisabled">A value indicating whether the logger is disabled.</param>
 /// <param name="contextProviders">
 /// A collection of <see cref="IContextProvider"/> objects that customize outgoing log entries.
 /// </param>
 public Logger(
     ILogProcessor logProcessor,
     string name    = DefaultName,
     LogLevel level = LogLevel.NotSet,
     [AlternateName("providers")] IReadOnlyCollection <ILogProvider> logProviders = null,
     bool isDisabled = false,
     IReadOnlyCollection <IContextProvider> contextProviders = null)
     : this(name, level, logProviders, isDisabled, contextProviders, logProcessor, disposeLogProcessor : false)
 {
 }
Exemplo n.º 9
0
 public EnquiryController(IEnquiry enquiry, DbContextOptions <ApplicationDbContext> applicationDbContext)
 {
     _enquiry = enquiry;
     _applicationDbContext = new ApplicationDbContext(applicationDbContext);
     _logProcessor         = new LogProcessor(_applicationDbContext);
     _configuration        = new ConfigurationRepository(_applicationDbContext);
     _irctcUrl             = _configuration.FindBy(x => x.key == "IRCTC_ApiURL").FirstOrDefault().value;
     _irctc_userName       = _configuration.FindBy(x => x.key == "IRCTC_Username").FirstOrDefault().value;
     _irctc_password       = _configuration.FindBy(x => x.key == "IRCTC_Password").FirstOrDefault().value;
     _authInfo             = _irctc_userName + ":" + _irctc_password;
 }
 public BookingController(IBooking booking, DbContextOptions <ApplicationDbContext> applicationDBContext)
 {
     _booking = booking;
     _applicationDbContext = new ApplicationDbContext(applicationDBContext);
     _log            = new LogProcessor(_applicationDbContext);
     _configuration  = new ConfigurationRepository(_applicationDbContext);
     _irctcUrl       = _configuration.FindBy(x => x.key == "IRCTC_ApiURL").FirstOrDefault().value;
     _irctc_userName = _configuration.FindBy(x => x.key == "IRCTC_Username").FirstOrDefault().value;
     _irctc_password = _configuration.FindBy(x => x.key == "IRCTC_Password").FirstOrDefault().value;
     _authInfo       = _irctc_userName + ":" + _irctc_password;
     _order          = new TicketOrdersRepository(_applicationDbContext);
 }
Exemplo n.º 11
0
 public static ILogProcessor GetCorrectProcessorForImportedSheet(Worksheet sheet)
 {
     // Go through our log processors and return the correct one for this sheet
     foreach (LogType logType in Enum.GetValues(typeof(LogType)))
     {
         ILogProcessor processor = CreateProcessor(logType);
         if (processor != null && processor.IsThisLog(sheet))
         {
             return(processor);
         }
     }
     return(null);
 }
Exemplo n.º 12
0
 public static void RunPipeline(IInputReader reader, ILogProcessor processor, IOutputWriter writer, bool writeHeader)
 {
     processor.SetWriter(writer);
     if (writeHeader)
     {
         processor.WriteHeader();
     }
     while (!reader.NoMoreLines())
     {
         processor.ReadLine(reader.ReadLine());
     }
     processor.Done();
 }
Exemplo n.º 13
0
        public static void ProcessEntireDirectory(LogType t)
        {
            String folder;
            // Create folder picker
            FileDialog fileDialog = ThisAddIn.app.FileDialog[MsoFileDialogType.msoFileDialogFolderPicker];

            fileDialog.AllowMultiSelect = false;
            if (fileDialog.Show() != -1)
            {
                return;
            }
            folder = fileDialog.SelectedItems.Item(1);

            // Prevent showing excel document updates to improve performance
            ThisAddIn.app.ScreenUpdating = false;

            string outputFileName = Path.Combine(folder, "processed_all.csv");

            string[] files = Directory.GetFiles(folder, Util.GetFileNamePatternForLog(t));

            // Quit if no files found
            if (files.Length == 0)
            {
                System.Windows.Forms.MessageBox.Show("No compatible files found in the selected directory.");
                return;
            }

            // Show progress bar
            ProgressBarForm progress = new ProgressBarForm();

            progress.InitializeAndShow(files.Length - 1);

            FileWriter writer = new FileWriter(outputFileName);

            // Loop to process multiple files consecutively
            for (int i = 0; i < files.Length; i++)
            {
                ILogProcessor processor = Util.CreateProcessor(t);
                FileReader    reader    = new FileReader(files[i]);
                processor.SetFileName(Path.GetFileName(files[i]));

                Util.RunPipeline(reader, processor, writer, writeHeader: i == 0);

                progress.Step();
            }

            writer.Flush();
            progress.Done();
            System.Windows.Forms.MessageBox.Show("Processed output written to " + outputFileName);
        }
Exemplo n.º 14
0
        public void ConstructorHappyPath()
        {
            var source = new TestConfigurationSource();

            source.Provider.Set("CustomLogger:Level", "Fatal");

            var configuration = new ConfigurationBuilder()
                                .Add(source)
                                .Build();

            var services = new ServiceCollection();

            services.Configure <LoggerOptions>("MyLogger", configuration.GetSection("CustomLogger"));

            var serviceProvider = services.BuildServiceProvider();

            var logProcessor     = new Mock <ILogProcessor>().Object;
            var name             = "MyLogger";
            var logProviders     = new[] { new Mock <ILogProvider>().Object };
            var contextProviders = new[] { new Mock <IContextProvider>().Object };
            var optionsMonitor   = serviceProvider.GetRequiredService <IOptionsMonitor <LoggerOptions> >();
            var options          = optionsMonitor.Get("MyLogger");
            Action <LoggerOptions> configureOptions = opt => { };

            var reloadingLogger = ReloadingLogger.New(logProcessor, name, logProviders, contextProviders, optionsMonitor, options, configureOptions);

            string        actualName         = reloadingLogger.Name;
            ILogProcessor actualLogProcessor = reloadingLogger._logProcessor;
            IReadOnlyCollection <ILogProvider>     actualLogProviders     = reloadingLogger._logProviders;
            IReadOnlyCollection <IContextProvider> actualContextProviders = reloadingLogger._contextProviders;
            Action <LoggerOptions> actualConfigureOptions = reloadingLogger._configureOptions;

            actualName.Should().BeSameAs(name);
            actualLogProcessor.Should().BeSameAs(logProcessor);
            actualLogProviders.Should().BeSameAs(logProviders);
            actualContextProviders.Should().BeSameAs(contextProviders);
            actualConfigureOptions.Should().BeSameAs(configureOptions);

            Logger logger = reloadingLogger._logger;

            logger.Name.Should().Be(name);
            logger.Level.Should().Be(LogLevel.Fatal);
            logger.IsDisabled.Should().BeFalse();
            logger.LogProviders.Should().BeSameAs(logProviders);
            logger.ContextProviders.Should().BeSameAs(contextProviders);
            logger.LogProcessor.Should().BeSameAs(logProcessor);
        }
Exemplo n.º 15
0
        public ReloadingLogger(ILogProcessor logProcessor,
                               string name,
                               IReadOnlyCollection <ILogProvider> logProviders,
                               IReadOnlyCollection <IContextProvider> contextProviders,
                               IOptionsMonitor <LoggerOptions> optionsMonitor,
                               LoggerOptions options,
                               Action <LoggerOptions> configureOptions)
        {
            Name              = name;
            _logProcessor     = logProcessor;
            _logProviders     = logProviders;
            _contextProviders = contextProviders;
            _configureOptions = configureOptions;
            _logger           = CreateLogger(options);

            optionsMonitor.OnChange(OptionsMonitorChanged);
        }
Exemplo n.º 16
0
 public LogTcpReceiver(IOptions <LogTcpSettings> settings, CancellationTokenSource cancellationToken, ILogProcessor logProcessor)
 {
     _nameTable           = new NameTable();
     _xmlNamespaceManager = new XmlNamespaceManager(_nameTable);
     _context             = new XmlParserContext(_nameTable, _xmlNamespaceManager, null, XmlSpace.None);
     _xmlReaderSettings   = new XmlReaderSettings();
     _xmlReaderSettings.ConformanceLevel             = ConformanceLevel.Fragment;
     _xmlReaderSettings.IgnoreWhitespace             = true;
     _xmlReaderSettings.IgnoreComments               = true;
     _xmlReaderSettings.IgnoreProcessingInstructions = true;
     _xmlReaderSettings.CheckCharacters              = false;
     _xmlNamespaceManager.AddNamespace("log4net", "ns");
     _settings          = settings.Value;
     _clientSocket      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     xsd                = GetSchema();
     _cancellationToken = cancellationToken.Token;
     _logProcessor      = logProcessor;
     Task.Factory.StartNew(InitSocket);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Logger"/> class.
        /// </summary>
        /// <param name="logProcessor">The object responsible for processing logs.</param>
        /// <param name="name">The name of the logger.</param>
        /// <param name="level">The logging level of the logger.</param>
        /// <param name="logProviders">A collection of <see cref="ILogProvider"/> objects used by this logger.</param>
        /// <param name="isDisabled">A value indicating whether the logger is disabled.</param>
        /// <param name="contextProviders">
        /// A collection of <see cref="IContextProvider"/> objects that customize outgoing log entries.
        /// </param>
        public Logger(
            ILogProcessor logProcessor,
            string name    = DefaultName,
            LogLevel level = LogLevel.NotSet,
            [AlternateName("providers")] IReadOnlyCollection <ILogProvider> logProviders = null,
            bool isDisabled = false,
            IReadOnlyCollection <IContextProvider> contextProviders = null)
        {
            if (!Enum.IsDefined(typeof(LogLevel), level))
            {
                throw new ArgumentException($"Log level is not defined: {level}.", nameof(level));
            }

            Name             = name ?? DefaultName;
            Level            = level;
            LogProviders     = logProviders ?? _emptyLogProviders;
            IsDisabled       = isDisabled;
            ContextProviders = contextProviders ?? _emptyContextProviders;
            LogProcessor     = logProcessor ?? throw new ArgumentNullException(nameof(logProcessor));

            _canProcessLogs = !IsDisabled && LogProviders.Count > 0;
        }
Exemplo n.º 18
0
        private void ProcessButton_Click(object sender, RibbonControlEventArgs e)
        {
            switch (e.Control.Id)
            {
            case "ProcessSingleButton":
                Worksheet     sheet     = ThisAddIn.app.ActiveWorkbook.ActiveSheet;
                ILogProcessor processor = Util.GetCorrectProcessorForImportedSheet(sheet);
                if (processor != null)
                {
                    Dispatch.ProcessSheetWithProcessor(sheet, processor);
                }
                else
                {
                    Util.MessageBox("Active worksheet not recognized as a valid log.");
                }
                break;

            case "ProcessAllButton":
                List <string> sheetNames = new List <string>();
                int           processed  = 0;
                foreach (Worksheet sh in ThisAddIn.app.ActiveWorkbook.Sheets)
                {
                    sheetNames.Add(sh.Name);
                }
                foreach (string sheetname in sheetNames)
                {
                    Worksheet     sheet_     = ThisAddIn.app.ActiveWorkbook.Sheets[sheetname];
                    ILogProcessor processor_ = Util.GetCorrectProcessorForImportedSheet(sheet_);
                    if (processor_ != null)
                    {
                        Dispatch.ProcessSheetWithProcessor(sheet_, processor_);
                        processed++;
                    }
                }
                Util.MessageBox(processed + " sheet(s) processed.");
                break;
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Adds an <see cref="ILogger"/>, along with its associated services, to the specified
        /// <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="services">
        /// The <see cref="IServiceCollection"/> to add the logger to.
        /// </param>
        /// <param name="logProcessor">The object that will process log entries on behalf of the logger.</param>
        /// <param name="loggerName">The name of the logger to build.</param>
        /// <param name="configureOptions">
        /// A delegate to configure the <see cref="ILoggerOptions"/> object that is used to configure the
        /// logger.
        /// </param>
        /// <param name="lifetime">The <see cref="ServiceLifetime"/> of the service.</param>
        /// <returns>
        /// An <see cref="ILoggerBuilder"/> object for adding log providers and context providers.
        /// </returns>
        /// <remarks>
        /// Note that if this method or any of its overloads are called more than once, then the
        /// last call defines the log processor for all.
        /// </remarks>
        public static ILoggerBuilder AddLogger(this IServiceCollection services,
                                               ILogProcessor logProcessor,
                                               string loggerName = Logger.DefaultName,
                                               Action <ILoggerOptions> configureOptions = null,
                                               ServiceLifetime lifetime = ServiceLifetime.Transient)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (logProcessor is null)
            {
                throw new ArgumentNullException(nameof(logProcessor));
            }

            var builder = new LoggerBuilder(services, loggerName, configureOptions);

            services.SetLogProcessor(logProcessor);
            services.Add(new ServiceDescriptor(typeof(ILogger), builder.Build, lifetime));
            services.SetLoggerLookupDescriptor();

            return(builder);
        }
Exemplo n.º 20
0
        private Logger(
            string name,
            LogLevel level,
            IReadOnlyCollection <ILogProvider> logProviders,
            bool isDisabled,
            IReadOnlyCollection <IContextProvider> contextProviders,
            ILogProcessor logProcessor,
            bool disposeLogProcessor)
        {
            if (!Enum.IsDefined(typeof(LogLevel), level))
            {
                throw new ArgumentException($"Log level is not defined: {level}.", nameof(level));
            }

            Name             = name ?? DefaultName;
            Level            = level;
            LogProviders     = logProviders ?? EmptyLogProviders;
            IsDisabled       = isDisabled;
            ContextProviders = contextProviders ?? EmptyContextProviders;
            LogProcessor     = logProcessor ?? throw new ArgumentNullException(nameof(logProcessor));

            _disposeLogProcessor = disposeLogProcessor;
            _canProcessLogs      = !IsDisabled && LogProviders.Count > 0;
        }
Exemplo n.º 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="scopeProvider"></param>
 /// <param name="logProcessor">ILogProcessorInstance</param>
 public JsonLogger(string name, IExternalScopeProvider scopeProvider, ILogProcessor logProcessor) : base(name, scopeProvider, logProcessor)
 {
 }
Exemplo n.º 22
0
        public static void ProcessSheetForLogType(Worksheet sheet, LogType t)
        {
            ILogProcessor processor = Util.CreateProcessor(t);

            ProcessSheetWithProcessor(sheet, processor);
        }
Exemplo n.º 23
0
 public LogsMatchedForProcessing(ILogProcessor logProcessor)
 {
     LogProcessor = logProcessor;
     MatchedLogs  = new List <FilterLog>();
 }
Exemplo n.º 24
0
 public LogsController(ILogProcessor logProcessor, ILogStorage storage)
 {
     _logProcessor = logProcessor;
     _storage      = storage;
 }
Exemplo n.º 25
0
 public LogStructureWithInput Then(ILogProcessor processor)
 {
     processor.SetContext(_flowStructure.Context);
     _flowStructure.Processors.Add(processor);
     return(new LogStructureWithInput(_flowStructure));
 }
Exemplo n.º 26
0
 public ILogsProcessorBuilder Add(ILogProcessor processor)
 {
     Processors.Add(processor);
     return(this);
 }
Exemplo n.º 27
0
 private static void SetLogProcessor(this IServiceCollection services, ILogProcessor logProcessor)
 {
     services.ClearLogProcessor();
     services.AddSingleton(logProcessor);
 }
 public ContinuousFileProcessor(ILog log, ILogProcessingConfiguration configuration, ILogProcessor logProcessor, ILogEntryGroupBox groupBox)
     : base(log, configuration, logProcessor, groupBox)
 {
     worker = new Thread(Thread_Job);
     worker.Start();
 }
Exemplo n.º 29
0
 public LogProcessor(ILogProcessor processor, IEnricher enricher)
 {
     _processor = processor;
     _enricher  = enricher;
 }
Exemplo n.º 30
0
 public LogStructureWithInput Then(ILogProcessor processor)
 {
     processor.SetContext(_flowStructure.Context);
     _flowStructure.Processors.Add(processor);
     return new LogStructureWithInput(_flowStructure);
 }
 public static void AddLogProcessor(ILogProcessor processor)
 {
     _logProcessors.Add(processor);
 }
Exemplo n.º 32
0
 public LogPacketHandler(ILogProcessor logProcessor)
 {
     _logProcessor = logProcessor;
 }