public override bool LoadData(string rootFolder, StockSerie stockSerie)
        {
            StockLog.Write("Group: " + stockSerie.StockGroup + " - " + stockSerie.StockName + " - " + stockSerie.Count);
            bool res = false;

            //if (stockSerie.StockGroup == StockSerie.Groups.CAC40_RS)
            //{
            //   StockSerie baseSerie = stockDictionary[stockSerie.StockName.Replace("_RS", "")];
            //   StockSerie cacSerie = stockDictionary["CAC40"];

            //   return stockSerie.GenerateRelativeStrenthStockSerie(baseSerie, cacSerie);
            //}
            string abcGroup = null;

            switch (stockSerie.StockGroup)
            {
                case StockSerie.Groups.SRD:
                    abcGroup = "srdp";
                    break;
                case StockSerie.Groups.SP500:
                    abcGroup = "sp500u";
                    break;
                case StockSerie.Groups.EURO_A:
                    abcGroup = "eurolistap";
                    break;
                case StockSerie.Groups.EURO_B:
                    abcGroup = "eurolistbp";
                    break;
                case StockSerie.Groups.EURO_C:
                    abcGroup = "eurolistcp";
                    break;
                case StockSerie.Groups.ALTERNEXT:
                    abcGroup = "alterp";
                    break;
                case StockSerie.Groups.SECTORS_CAC:
                    abcGroup = "indicessecp";
                    break;
                default:
                    break;
            }
            string fileName = null;
            string[] files;
            if (abcGroup != null)
            {
                try
                {
                    if (!loadedGroups.Contains(abcGroup))
                    {
                        if (loadingGroup == null)
                        {
                            loadingGroup = abcGroup;
                        }
                        else
                        {
                            StockLog.Write("Already busy loading group: " + stockSerie.StockGroup);
                            if (loadingGroup == abcGroup)
                            {
                                do
                                {
                                    Thread.Sleep(100);
                                } while (loadingGroup == abcGroup);
                                return stockSerie.Count != 0;
                            }
                            else
                            {
                                do
                                {
                                    Thread.Sleep(100);
                                } while (loadingGroup == abcGroup);
                            }
                        }

                        //
                        StockLog.Write("Sync OK Group: " + stockSerie.StockGroup + " - " + stockSerie.StockName);
                        fileName = abcGroup + "_*.csv";
                        var groupFiles =
                           System.IO.Directory.GetFiles(rootFolder + ARCHIVE_FOLDER, fileName).OrderByDescending(s => s);
                        foreach (string archiveFileName in groupFiles)
                        {
                            NotifyProgress("Loading data for " + Path.GetFileNameWithoutExtension(archiveFileName));
                            if (!ParseABCGroupCSVFile(archiveFileName, stockSerie.StockGroup)) break;
                            else
                            {
                                res = true;
                            }
                        }
                        groupFiles =
                           System.IO.Directory.GetFiles(rootFolder + ABC_DAILY_FOLDER, fileName).OrderByDescending(s => s);
                        foreach (string currentFileName in groupFiles)
                        {
                            res = ParseABCGroupCSVFile(currentFileName, stockSerie.StockGroup);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    StockLog.Write(ex);
                }
                finally
                {
                    loadingGroup = null;
                    loadedGroups.Add(abcGroup);
                }
                // @@@@ stockSerie.ClearBarDurationCache(); Removed as I don't know why it's here.
            }

            if (stockSerie.Count == 0)
            {
                // Read archive first
                fileName = stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() +
                           "_*.csv";
                files = System.IO.Directory.GetFiles(rootFolder + ARCHIVE_FOLDER, fileName);
                foreach (string archiveFileName in files)
                {
                    res |= ParseCSVFile(stockSerie, archiveFileName);
                }

                // Read daily value
                fileName = rootFolder + ABC_DAILY_FOLDER + "\\" + stockSerie.ShortName + "_" + stockSerie.StockName + "_" +
                           stockSerie.StockGroup.ToString() + ".csv";
                res |= ParseCSVFile(stockSerie, fileName);
            }
            // Read intraday
            if (res && stockSerie.Keys.Last() != DateTime.Today)
            {
                if (stockSerie.BelongsToGroup(StockSerie.Groups.SRD))
                {
                    fileName = rootFolder + ABC_INTRADAY_FOLDER + "\\" + DateTime.Today.ToString("yyMMdd_") + "SRD.csv";
                    ParseABCGroupCSVFile(fileName, StockSerie.Groups.SRD, true);
                    return true;
                }
                else if (stockSerie.BelongsToGroup(StockSerie.Groups.SP500))
                {
                    fileName = rootFolder + ABC_INTRADAY_FOLDER + "\\" + DateTime.Today.ToString("yyMMdd_") + "SP500.csv";
                    ParseABCGroupCSVFile(fileName, StockSerie.Groups.SP500, true);
                    return true;
                }
                else if (stockSerie.BelongsToGroup(StockSerie.Groups.INDICES))
                {
                    fileName = rootFolder + ABC_INTRADAY_FOLDER + "\\" + DateTime.Today.ToString("yyMMdd_") + "IndicesFR.csv";
                    ParseABCIntradayFile(stockSerie, fileName);
                    return true;
                }
            }
            return res;
        }
        public override bool DownloadDailyData(string rootFolder, StockSerie stockSerie)
        {
            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
             {
            string shortName = stockSerie.ShortName;
            if (stockSerie.BelongsToGroup(StockSerie.Groups.FTSE100))
            {
               shortName = "LON:" + shortName;
            }
            else if (stockSerie.BelongsToGroup(StockSerie.Groups.DAX30))
            {
               shortName = "ETR:" + shortName;
            }

            bool isUpTodate = false;
            stockSerie.Initialise();
            if (stockSerie.Count > 0)
            {
               // This serie already exist, download just the missing data.
               DateTime lastDate = stockSerie.Keys.Last();

               isUpTodate = (lastDate >= DateTime.Today) ||
                   (lastDate.DayOfWeek == DayOfWeek.Friday && (DateTime.Now - lastDate).Days <= 2 && (DateTime.Today.DayOfWeek == DayOfWeek.Monday && DateTime.UtcNow.Hour < 20)) ||
                   (lastDate >= DateTime.Today.AddDays(-1) && DateTime.UtcNow.Hour < 20);

               NotifyProgress("Downloading " + stockSerie.StockGroup.ToString() + " - " + stockSerie.StockName);
               if (!isUpTodate)
               {
                  for (int year = lastDate.Year; year < DateTime.Today.Year; year++)
                  {
                     // Happy new year !!! it's time to archive old data...
                     if (
                        !File.Exists(rootFolder + ARCHIVE_FOLDER + "\\" + stockSerie.ShortName + "_" +
                                     stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + "_" +
                                     year.ToString() + ".csv"))
                     {
                        this.DownloadFileFromProvider(rootFolder + ARCHIVE_FOLDER,
                           stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() +
                           "_" + year.ToString() + ".csv", new DateTime(year, 1, 1), new DateTime(year, 12, 31),
                           stockSerie.ShortName);
                     }
                  }
                  DateTime startDate = new DateTime(DateTime.Today.Year, 01, 01);
                  string fileName = stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + ".csv";
                  this.DownloadFileFromProvider(rootFolder + FOLDER, fileName, startDate, DateTime.Today, shortName);

                  if (stockSerie.StockName == "ADIDAS") // Check if something new has been downloaded using ANGLO AMERICAN as the reference for all downloads
                  {
                     this.ParseCSVFile(stockSerie, rootFolder + FOLDER + "\\" + fileName);
                     if (lastDate == stockSerie.Keys.Last())
                     {
                        this.needDownload = false;
                     }
                  }
               }
               else
               {
                  if (stockSerie.StockName == "ADIDAS")
                  {
                     this.needDownload = false;
                  }
               }
               stockSerie.IsInitialised = isUpTodate;
            }
            else
            {
               NotifyProgress("Creating archive for " + stockSerie.StockName + " - " + stockSerie.StockGroup.ToString());
               DateTime lastDate = new DateTime(DateTime.Today.Year, 01, 01);
               for (int i = lastDate.Year - 1; i > ARCHIVE_START_YEAR; i--)
               {
                  if (!this.DownloadFileFromProvider(rootFolder + ARCHIVE_FOLDER, stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + "_" + i.ToString() + ".csv", new DateTime(i, 1, 1), new DateTime(i, 12, 31), shortName))
                  {
                     break;
                  }
               }
               this.DownloadFileFromProvider(rootFolder + FOLDER, stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + ".csv", lastDate, DateTime.Today, shortName);
            }
             }
             return true;
        }
        public override bool DownloadIntradayData(string rootFolder, StockSerie stockSerie)
        {
            StockLog.Write("DownloadIntradayData Group: " + stockSerie.StockGroup + " - " + stockSerie.StockName);

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                NotifyProgress("Downloading intraday for" + stockSerie.StockGroup.ToString());

                if (!stockSerie.Initialise())
                {
                    return false;
                }

                if (DateTime.Today.DayOfWeek == DayOfWeek.Saturday
                        || DateTime.Today.DayOfWeek == DayOfWeek.Sunday
                        || stockSerie.Keys.Last() == DateTime.Today)
                {
                    return false;
                }

                string folder = rootFolder + ABC_INTRADAY_FOLDER;
                string fileName;
                string item;
                if (stockSerie.BelongsToGroup(StockSerie.Groups.SRD))
                {
                    fileName = DateTime.Today.ToString("yyMMdd_") + "SRD.csv";
                    item = "complet";
                }
                else
                {
                    fileName = DateTime.Today.ToString("yyMMdd_") + "IndicesFr.csv";
                    item = "indicesfrp";
                }
                if (File.Exists(folder + "\\" + fileName))
                {
                    if (File.GetLastWriteTime(folder + "\\" + fileName) > DateTime.Now.AddMinutes(-4))
                        return false;
                }
                // TODO Check the time of the day to avoid useless download
                if (this.DownloadIntradayFileFromABC(folder, fileName, item))
                {
                    // Deinitialise all the SBF120 stock
                    foreach (StockSerie serie in stockDictionary.Values.Where(s => s.BelongsToGroup(stockSerie.StockGroup)))
                    {
                        serie.IsInitialised = false;
                    }
                    loadedGroups.Clear();
                    //foreach (StockSerie serie in stockDictionary.Values.Where(s => s.DataProvider == StockDataProvider.Breadth && s.StockName.Contains("SBF120") || s.StockName.Contains("CAC40")))
                    //{
                    //   serie.IsInitialised = false;
                    //}
                }
            }
            return true;
        }