void ExportProgressChanged(object sender, ExportProgressChangedEventArgs e) {
     this.Dispatcher.Invoke(() => {
         switch (e.ExportProgressType) {
             case ExportProgressType.DuplicateRecordFound:
                 duplicatesRows.AddLast(e.UserState as OrderModel);
                 break;
             case ExportProgressType.RecordInserted:
                 insertedRows.AddLast(e.UserState as OrderModel);
                 ordersFromDBRows.AddLast(e.UserState as OrderModel);
                 break;
             case ExportProgressType.ExportCompleted:
             case ExportProgressType.ExportCancelled:
                 txtBlockExportLog.Text = String.Format("{0}\n{1}", txtBlockExportLog.Text, e.UserState.ToString());
                 UpdateUI();
                 break;
             default:
                 txtBlockExportLog.Text = String.Format("{0}\n{1}", txtBlockExportLog.Text, e.UserState.ToString());
                 break;
         }
         if (e.ProgressPercentage > 0)
             PBExport.Value = e.ProgressPercentage;
     });
 }
Пример #2
0
 protected virtual void OnExportProgressChanged(ExportProgressChangedEventArgs e) {
     ExportProgressChangedEventHandler handler = ExportProgressChanged;
     if (handler != null)
         handler(this, e);
 }
Пример #3
0
 void ExportXml(object sender, DoWorkEventArgs e) {
     Orders ordersFromXml = ParseXml();
     if (ordersFromXml != null) {
         OrderDetails[] orderDetailsFromXml = ordersFromXml.OrderDetailsList;
         using (FileStream stream = new FileStream("Duplicates.csv", FileMode.Create)) {
             StreamWriter streamWriter = new StreamWriter(stream);
             streamWriter.Write("CustomerID,OrderDate,OrderValue,OrderStatus,OrderType");
             if (orderDetailsFromXml != null) {
                 for (int i = 0; i < orderDetailsFromXml.Length; i++) {
                     if (exportWorker.CancellationPending) {
                         e.Cancel = true;
                         break;
                     }
                     OrderModel order = ordersFromXml.ToOrder(orderDetailsFromXml[i]);
                     int progressPercentage = 10 + Convert.ToInt32((float)i / (float)orderDetailsFromXml.Length * 90);
                     ExportProgressChangedEventArgs progressArgs = null;
                     OrderModel duplicateOrder = SelectDuplicateOrder(order.OrderValue);
                     if (duplicateOrder != null) {
                         progressArgs = new ExportProgressChangedEventArgs(ExportProgressType.DuplicateRecordFound, progressPercentage, duplicateOrder);
                         // Save Duplicate order to CSV file
                         string content = String.Format("\n{0},{1},{2},{3},{4}", duplicateOrder.CustomerID, duplicateOrder.OrderDate, duplicateOrder.OrderValue, duplicateOrder.OrderStatus, duplicateOrder.OrderType);
                         streamWriter.Write(content);
                     }
                     else {
                         InsertOrderRecord(order);
                         progressArgs = new ExportProgressChangedEventArgs(ExportProgressType.RecordInserted, progressPercentage, order);
                     }
                     OnExportProgressChanged(progressArgs);
                 }
             }
         }
     }
 }