Esempio n. 1
0
        /// <summary>
        /// Handle the success event.
        /// </summary>
        /// <param name="sender">The DataImporter.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private void OnSuccess(object sender, DataImporter.ImportEventArgs eventArgs)
        {
            this.Dispatcher.BeginInvoke(
                DispatcherPriority.Normal,
                new Action(delegate()
            {
                this.timer.Stop();
                this.TimeLeft = TimeSpan.Zero;

                if (eventArgs.FailedCount == 0)
                {
                    BindingOperations.ClearBinding(this, WindowImport.HeaderProperty);
                    this.Header            = String.Format(Properties.Resources.ImportEndedSuccessHeader, eventArgs.SucceededCount);
                    this.Message           = String.Format(Properties.Resources.ImportEndedSuccessMessage, Path.GetFileName(this.ImportFile));
                    this.cancelBtn.Content = Properties.Resources.Close;
                    this.succeeded         = true;
                    this.Activate();
                }
                else
                {
                    WindowImportReport report = new WindowImportReport();

                    report.ImportEventArgs = eventArgs;
                    report.FailureFile     = this.failureFile;
                    report.SchemaVersion   = this.SchemaVersion;
                    report.Owner           = this;
                    report.ShowDialog();
                    this.Close();
                }
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// Handle the failed event.
        /// </summary>
        /// <param name="sender">The DataImporter.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private void OnFailed(object sender, DataImporter.ImportEventArgs eventArgs)
        {
            this.Dispatcher.BeginInvoke(
                DispatcherPriority.Normal,
                new Action(delegate()
            {
                Boolean threadAborted = eventArgs.Exception is ThreadAbortException || eventArgs.Exception.InnerException is ThreadAbortException;

                this.timer.Stop();
                if (!(threadAborted && !this.loaded))
                {
                    WindowImportReport report = new WindowImportReport();

                    if (eventArgs.FailedCount != 0)
                    {
                        report.FailureFile = this.failureFile;
                    }
                    else
                    {
                        report.FailureFile = null;
                    }
                    report.ImportEventArgs = eventArgs;
                    report.SchemaVersion   = this.SchemaVersion;
                    report.Owner           = this;
                    report.ShowDialog();
                    this.Close();
                }
            }));
        }
Esempio n. 3
0
 /// <summary>
 /// Handle the ReadPulse and ImportPulse events. Tick the progress bar forward once.
 /// </summary>
 /// <param name="sender">The DataImporter.</param>
 /// <param name="eventArgs">The event arguments.</param>
 private void OnPulse(object sender, DataImporter.ImportEventArgs eventArgs)
 {
     this.Dispatcher.BeginInvoke(
         DispatcherPriority.Normal,
         new Action(delegate()
     {
         this.Succeeded          = eventArgs.SucceededCount;
         this.TimeLeftVisibility = Visibility.Visible;
         this.Value    = eventArgs.Position;
         TimeSpan left = new TimeSpan((long)((this.Maximum - this.Value) * ((DateTime.Now - this.startTime).Ticks / this.Value)));
         this.TimeLeft = left < TimeSpan.Zero ? TimeSpan.Zero : left;
     }));
 }
Esempio n. 4
0
        /// <summary>
        /// Handle the import event arguments changing.
        /// </summary>
        /// <param name="sender">The import report whose ImportEventArgs changed.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private static void OnImportEventArgsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            DataImporter.ImportEventArgs importEventArgs = eventArgs.NewValue as DataImporter.ImportEventArgs;
            String fullText = "";
            String error    = "";

            sender.SetValue(WindowImportReport.FailedProperty, importEventArgs.Exception != null);
            sender.SetValue(WindowImportReport.FailedCountProperty, importEventArgs.FailedCount);
            sender.SetValue(WindowImportReport.SucceededCountProperty, importEventArgs.SucceededCount);

            if (importEventArgs.Exception == null)
            {
                fullText = String.Format(Properties.Resources.ImportSucceededWithErrors, importEventArgs.SucceededCount, importEventArgs.FailedCount);
            }
            else
            {
                if (importEventArgs.Exception is ThreadAbortException)
                {
                    error = String.Format(Properties.Resources.ImportAborted, importEventArgs.SucceededCount);
                }
                else if (importEventArgs.Exception is ImportHeaderNotFoundException)
                {
                    StringBuilder        headerText     = new StringBuilder();
                    ICollection <String> headers        = (importEventArgs.Exception as ImportHeaderNotFoundException).Headers;
                    ICollection <String> missingHeaders = (importEventArgs.Exception as ImportHeaderNotFoundException).MissingHeaders;
                    Int32 index = 0;

                    if (missingHeaders != null)
                    {
                        foreach (String header in missingHeaders)
                        {
                            index += 1;
                            headerText.Append(header);
                            if (index < missingHeaders.Count)
                            {
                                headerText.Append(", ");
                            }
                        }

                        error = String.Format(Properties.Resources.ImportFailedRequiredColumnMissing, headerText);
                    }
                    else
                    {
                        foreach (String header in headers)
                        {
                            index += 1;
                            headerText.Append(header);
                            if (index < headers.Count)
                            {
                                headerText.Append(", ");
                            }
                        }

                        error = String.Format(Properties.Resources.ImportFailedNoHeaders, headerText);
                    }
                }
                else if (importEventArgs.Exception is XmlSchemaValidationException)
                {
                    XmlSchemaValidationException exception = importEventArgs.Exception as XmlSchemaValidationException;
                    error = String.Format(Properties.Resources.XmlValidationFailed, exception.LineNumber, exception.LinePosition, exception.Message);
                }
                else if (importEventArgs.Exception is XmlException)
                {
                    XmlException exception = importEventArgs.Exception as XmlException;
                    error = String.Format(Properties.Resources.XmlValidationFailed, exception.LineNumber, exception.LinePosition, exception.Message);
                }
                else if (importEventArgs.Exception is FormatException)
                {
                    XmlException exception = importEventArgs.Exception as XmlException;
                    error = String.Format(Properties.Resources.ImportVersionMismatch, sender.GetValue(WindowImportReport.SchemaVersionProperty));
                }
                else
                {
                    error = importEventArgs.Exception.Message;
                    // This is an unexpected error. Log it.
                    FluidTrade.Core.EventLog.Error("Exception while importing: {0}\nStack trace: {1}", importEventArgs.Exception.Message, importEventArgs.Exception.StackTrace);
                }

                fullText = String.Format(Properties.Resources.ImportFailed, error);
            }

            sender.SetValue(WindowImportReport.ErrorProperty, fullText);
        }