Ejemplo n.º 1
0
    private void DoExport(ExportSettings settings, ExportTask task)
    {
      try
      {
        IDataSeries dataSeries = task.DataSeries;
        FileInfo fileInfo = new FileInfo(string.Format("{0}\\{1}", (object) settings.Directory.FullName, (object) task.OutputFileName));
        DataType dataType = DataSeriesHelper.GetDataSeriesInfo(dataSeries.Name).DataType;
        task.State = ExportTaskState.Exporting;
        this.UpdateTaskState(task);
        this.SetLabelText(this.lblCurrentProgress, string.Format("{0} {1} -> {2}", (object) DataSeriesHelper.GetDataSeriesInfo(dataSeries.Name).Symbol, (object) DataSeriesHelper.SeriesNameToString(dataSeries.Name), (object) fileInfo.FullName));
        this.SetProgressValue(this.pgbCurrent, 0);
        Thread.Sleep(0);
        DataExporter dataExporter;
        switch (dataType)
        {
          case DataType.Trade:
            dataExporter = (DataExporter) new TradeExporter();
            break;
          case DataType.Quote:
            dataExporter = (DataExporter) new QuoteExporter();
            break;
          case DataType.Bar:
            dataExporter = (DataExporter) new BarExporter();
            break;
          case DataType.Daily:
            dataExporter = (DataExporter) new DailyExporter();
            break;
          default:
            throw new NotSupportedException(string.Format("Insupported data type - {0}", (object) dataType));
        }
        StreamWriter streamWriter = new StreamWriter(fileInfo.FullName);
        streamWriter.WriteLine(this.ToString(dataExporter.GetHeader()));
        int num1 = 0;
        int num2 = 0;
        for (int index = 0; index < dataSeries.Count; ++index)
        {
					IDataObject idataObject = dataSeries[index] as IDataObject;
          if (!this.pendingCancel)
          {
            DateTime dateTime = idataObject.DateTime;
            if (!(dateTime < settings.RangeBegin) && !(dateTime > settings.RangeEnd))
              streamWriter.WriteLine(this.ToString(dataExporter.DataObjectToString(idataObject)));
            ++num1;
            int num3 = (int) ((long) num1 * 100L / (long) dataSeries.Count);
            if (num3 > num2)
            {
              num2 = num3;
              this.SetProgressValue(this.pgbCurrent, num2);
            }
            Thread.Sleep(0);
          }
          else
            break;
        }
        streamWriter.Close();
        if (this.pendingCancel)
        {
          task.State = ExportTaskState.Error;
          task.Text = "Aborted";
        }
        else
        {
          task.State = ExportTaskState.Done;
          task.Text = "Completed";
        }
        this.UpdateTaskState(task);
      }
      catch (Exception ex)
      {
        task.State = ExportTaskState.Error;
        task.Text = ((object) ex).ToString();
        this.UpdateTaskState(task);
      }
    }