void LoadData(BackgroundWorker worker, DoWorkEventArgs e)
{
int periodsToLoad = 0;
int allPeriods = Enum.GetValues(typeof(DataPeriods)).Length;
Data.IntraBars = new int[allPeriods];
Data.IntraBarData = new Bar[Data.Bars][];
Data.IntraBarBars = new int[Data.Bars];
Data.IntraBarsPeriods = new DataPeriods[Data.Bars];
Data.LoadedIntraBarPeriods = 0;
for (int bar = 0; bar < Data.Bars; bar++)
{
Data.IntraBarsPeriods[bar] = Data.Period;
Data.IntraBarBars[bar] = 0;
}
// Counts how many periods to load
for (int prd = 0; prd < allPeriods; prd++)
{
DataPeriods period = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
if (period < Data.Period)
{
periodsToLoad++;
}
}
// Load the intrabar data (Starts from 1 Min)
for (int prd = 0; prd < allPeriods && isLoadingNow; prd++)
{
if (worker.CancellationPending) break;
int loadedBars = 0;
DataPeriods period = (DataPeriods)Enum.GetValues(typeof(DataPeriods)).GetValue(prd);
SetLabelProgressText(Language.T("Loading:") + " " + Data.DataPeriodToString(period) + "...");
if (period < Data.Period)
{
loadedBars = LoadIntrabarData(period);
if (loadedBars > 0)
{
Data.IsIntrabarData = true;
Data.LoadedIntraBarPeriods++;
}
}
else if (period == Data.Period)
{
loadedBars = Data.Bars;
Data.LoadedIntraBarPeriods++;
}
Data.IntraBars[prd] = loadedBars;
// Report progress as a percentage of the total task.
int percentComplete = periodsToLoad > 0 ? 100 * (prd + 1) / periodsToLoad : 100 ;
percentComplete = percentComplete > 100 ? 100 : percentComplete;
if (percentComplete > progressPercent)
{
progressPercent = percentComplete;
worker.ReportProgress(percentComplete);
}
}
CheckIntrabarData();
RepairIntrabarData();
if (Configs.UseTickData)
{
SetLabelProgressText(Language.T("Loading:") + " " + Language.T("Ticks") + "...");
worker.ReportProgress(200);
try
{
LoadTickData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
return;
}