Esempio n. 1
0
        /// <summary>
        /// Launches the engine.
        /// </summary>
        /// <param name="inputFilePaths">List of full input files to be processed.</param>
        /// <param name="recordReader">Instance that reads the record from the input files.</param>
        /// <param name="expression">Instance of the expression used to matched against the record.</param>
        public override void LaunchEngine(String[] inputFilePaths, IRecordReader recordReader, IRecordMatchExpression expression)
        {
            this.recordWriter = CreateRecordWriter();

              var engine = new Engine();
              engine.FileOpened += this.FileOpenedHandler;
              engine.FileRead += this.FileReadHandler;
              engine.CheckForCancellation = this.CheckForCancellation;

              this.worker = new BackgroundWorker();
              this.worker.WorkerSupportsCancellation = true;
              this.worker.DoWork += (sender, e) =>
              {
            engine.Execute(
              inputFilePaths,
              this.uiLogManager,
              new FileReaderFactory(),
              recordReader,
              expression,
              this.recordWriter,
              this.statisticsManager,
              this.statisticsManager);

            if (engine.CheckForCancellation())
            {
              e.Cancel = true;
            }
              };

              this.worker.RunWorkerCompleted += BackgroundWorkCompleted;
              this.worker.RunWorkerAsync();
        }
Esempio n. 2
0
        /// <summary>
        /// Launches the engine.
        /// </summary>
        /// <param name="inputFilePaths">List of full input files to be processed.</param>
        /// <param name="recordReader">Instance that reads the record from the input files.</param>
        /// <param name="expression">Instance of the expression used to matched against the record.</param>
        public override void LaunchEngine(String[] inputFilePaths, IRecordReader recordReader, IRecordMatchExpression expression)
        {
            var recordWriter = CreateRecordWriter();

              var engine = new Engine();
              engine.FileOpened += this.FileOpenedHandler;
              engine.FileRead += this.FileReadHandler;
              engine.CheckForCancellation = this.CheckForCancellation;

              // Get the UI thread now because this method is guaranteed to be running on that thread (since this
              // method is called from a winform control handler method)
              this.mainTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();

              // Create a new cancellation source and token - the previous one may have been cancelled already.
              this.cancellationTokenSource = new CancellationTokenSource();
              this.cancellationToken = this.cancellationTokenSource.Token;

              var task = Task.Factory.StartNew(() =>
              {
            engine.Execute(
              inputFilePaths,
              this.uiLogManager,
              new FileReaderFactory(),
              recordReader,
              expression,
              recordWriter,
              this.statisticsManager,
              this.statisticsManager);
              }, this.cancellationToken);

              var finishedTask = task.ContinueWith((antecedent) =>
              {
            if (antecedent.Exception != null)
            {
              this.uiLogManager.WriteMessagesToLogs("Job FAILED.");
              var ae = antecedent.Exception.Flatten();
              Int32 count = 1;
              foreach (Exception e in ae.InnerExceptions)
              {
            this.uiLogManager.WriteMessagesToLogs(String.Format("EXCEPTION {0}: {1}", count++, e.Message));
            this.uiLogManager.WriteMessagesToLogs("STACK: " + e.StackTrace);
              }
            }
            else if (this.cancellationToken.IsCancellationRequested)
            {
              this.uiLogManager.WriteMessagesToLogs("CANCELLED.");
            }

            recordWriter.Close();
            this.uiLogManager.Close();
            this.mainForm.JobFinished();
              }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Esempio n. 3
0
        public void Execute(
      String[] filePaths,
      ILogManager logManager,
      IStreamReaderFactory streamReaderFactory,
      IRecordReader recordReader,
      IRecordMatchExpression expression,
      IRecordWriter recordWriter,
      IStatisticsCollector statisticsCollector,
      IStatisticsReporter statisticsReporter)
        {
            logManager.VerifyThatObjectIsNotNull("Parameter 'logManager' is null.");

              try
              {
            this.logManager = logManager;

            statisticsCollector.VerifyThatObjectIsNotNull("Parameter 'statisticsCollector' is null.");
            this.statisticsCollector = statisticsCollector;

            statisticsReporter.VerifyThatObjectIsNotNull("Parameter 'statisticsReporter' is null.");
            this.statisticsReporter = statisticsReporter;

            this.logManager.WriteMessagesToLogs("Run Started...");

            Action<IStreamReader, Record> writeMatchedRecordMethod, writeUnmatchedRecordMethod;
            this.DetermineOutputMethods(recordWriter, out writeMatchedRecordMethod, out writeUnmatchedRecordMethod);

            this.Process(filePaths, streamReaderFactory, recordReader, expression, writeMatchedRecordMethod, writeUnmatchedRecordMethod);

            recordWriter.Close();

            this.statisticsReporter.WriteToLog(this.logManager);

            this.logManager.WriteMessagesToLogs("Run Finished.");
              }
              catch (Exception exception)
              {
            logManager.WriteMessageToApplicationLog("EXCEPTION: " + exception.Message);
            logManager.WriteMessageToApplicationLog("STACK: " + exception.StackTrace);
            throw exception;
              }
        }
Esempio n. 4
0
        private void Process(String[] filePaths, IStreamReaderFactory streamReaderFactory, IRecordReader recordReader, IRecordMatchExpression expression, Action<IStreamReader, Record> writeMatchedRecordMethod, Action<IStreamReader, Record> writeUnmatchedRecordMethod)
        {
            var messageBuilder = new StringBuilder();

              foreach (String filePath in filePaths)
              {
            this.logManager.WriteImportantMessageToJobLog("Processing '" + filePath + "'.");
            var fileReader = streamReaderFactory.CreateStreamReader(filePath);

            this.OnFileOpened(fileReader.Length);

            Record record;
            while (!expression.HasReachedMatchQuota && (record = recordReader.ReadRecord(fileReader)) != null)
            {
              this.OnFileRead(fileReader.Position);

              messageBuilder.Append("Record found at position " + record.Start + " with Term '" + record.Term + "'");
              if (expression.IsMatch(record))
              {
            this.statisticsCollector.RecordIsMatched(filePath);
            messageBuilder.Append(" matches with List Term '" + record.Term + "'");
            writeMatchedRecordMethod(fileReader, record);
              }
              else
              {
            this.statisticsCollector.RecordIsUnmatched(filePath);
            writeUnmatchedRecordMethod(fileReader, record);
              }

              messageBuilder.Append(".");
              this.logManager.WriteMessageToJobLog(messageBuilder.ToString());
              messageBuilder.Clear();

              if (this.IsCancelled())
              {
            break;
              }
            }

            fileReader.Close();
              }
        }
Esempio n. 5
0
 /// <summary>
 /// Launches the engine.
 /// </summary>
 /// <param name="inputFilePaths">List of full input files to be processed.</param>
 /// <param name="recordReader">Instance that reads the record from the input files.</param>
 /// <param name="expression">Instance of the expression used to matched against the record.</param>
 public abstract void LaunchEngine(String[] inputFilePaths, IRecordReader recordReader, IRecordMatchExpression expression);