Ejemplo n.º 1
0
 public void OnNotify(object sender, NotifyEventArgs e)
 {
     if (e.ProgressEventType == ProgressEventType.Error && extractCommand != null)
     {
         extractCommand.ElevateState(ExtractCommandState.Crashed);
     }
 }
Ejemplo n.º 2
0
        private void WriteMetadata(IDataLoadEventListener listener)
        {
            ExtractCommand.ElevateState(ExtractCommandState.WritingMetadata);
            WordDataWriter wordDataWriter;


            try
            {
                wordDataWriter = new WordDataWriter(this);
                wordDataWriter.GenerateWordFile();//run the report
            }
            catch (Exception e)
            {
                //something about the pipeline resulted i a known unsupported state (e.g. extracting to a database) so we can't use WordDataWritter with this
                // tell user that we could not run the report and set the status to warning
                ExtractCommand.ElevateState(ExtractCommandState.Warning);

                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Word metadata document NOT CREATED", e));
                return;
            }

            //if there were any exceptions
            if (wordDataWriter.ExceptionsGeneratingWordFile.Any())
            {
                ExtractCommand.ElevateState(ExtractCommandState.Warning);

                foreach (Exception e in wordDataWriter.ExceptionsGeneratingWordFile)
                {
                    listener.OnNotify(wordDataWriter, new NotifyEventArgs(ProgressEventType.Warning, "Word metadata document creation caused exception", e));
                }
            }
            else
            {
                ExtractCommand.ElevateState(ExtractCommandState.Completed);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the extraction once and returns true if it was success otherwise false
        /// </summary>
        /// <param name="listener"></param>
        /// <returns></returns>
        private bool ExecuteOnce(IDataLoadEventListener listener)
        {
            try
            {
                ExtractCommand.ElevateState(ExtractCommandState.WaitingToExecute);

                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"Running Extraction {ExtractCommand} with Pipeline {_pipeline.Name} (ID={_pipeline.ID})"));

                var engine = GetEngine(_pipeline, listener);

                try
                {
                    engine.ExecutePipeline(Token ?? new GracefulCancellationToken());
                    listener.OnNotify(Destination, new NotifyEventArgs(ProgressEventType.Information, "Extraction completed successfully into : " + Destination.GetDestinationDescription()));
                }
                catch (Exception e)
                {
                    ExtractCommand.ElevateState(ExtractCommandState.Crashed);
                    _dataLoadInfo.LogFatalError("Execute extraction pipeline", ExceptionHelper.ExceptionToListOfInnerMessages(e, true));

                    if (ExtractCommand is ExtractDatasetCommand)
                    {
                        //audit to extraction results
                        var result = (ExtractCommand as ExtractDatasetCommand).CumulativeExtractionResults;
                        result.Exception = ExceptionHelper.ExceptionToListOfInnerMessages(e, true);
                        result.SaveToDatabase();
                    }
                    else
                    {
                        //audit to extraction results
                        var result = (ExtractCommand as ExtractGlobalsCommand).ExtractionResults;
                        foreach (var extractionResults in result)
                        {
                            extractionResults.Exception = ExceptionHelper.ExceptionToListOfInnerMessages(e, true);
                            extractionResults.SaveToDatabase();
                        }
                    }

                    //throw so it can be audited to UI (triple audit yay!)
                    throw new Exception("An error occurred while executing pipeline", e);
                }

                if (Source == null)
                {
                    throw new Exception("Execute Pipeline completed without Exception but Source was null somehow?!");
                }

                if (Source.WasCancelled)
                {
                    Destination.TableLoadInfo.DataLoadInfoParent.LogFatalError(this.GetType().Name, "User Cancelled Extraction");
                    ExtractCommand.ElevateState(ExtractCommandState.UserAborted);

                    if (ExtractCommand is ExtractDatasetCommand)
                    {
                        //audit to extraction results
                        var result = (ExtractCommand as ExtractDatasetCommand).CumulativeExtractionResults;
                        result.Exception = "User Cancelled Extraction";
                        result.SaveToDatabase();
                    }
                    else
                    {
                        //audit to extraction results
                        var result = (ExtractCommand as ExtractGlobalsCommand).ExtractionResults;
                        foreach (var extractionResults in result)
                        {
                            extractionResults.Exception = "User Cancelled Extraction";
                            extractionResults.SaveToDatabase();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Execute pipeline failed with Exception", ex));
                ExtractCommand.ElevateState(ExtractCommandState.Crashed);
            }

            //if it didn't crash / get aborted etc
            if (ExtractCommand.State < ExtractCommandState.WritingMetadata)
            {
                if (ExtractCommand is ExtractDatasetCommand)
                {
                    WriteMetadata(listener);
                }
                else
                {
                    ExtractCommand.ElevateState(ExtractCommandState.Completed);
                }
            }
            else
            {
                return(false); // it crashed or was aborted etc
            }
            return(true);
        }