private static bool Download(string ticker)
        {
            const string kr         = "http://financials.morningstar.com/ajax/exportKR2CSV.html?t=";
            const int    maxTimeout = 3;
            var          timeout    = 0;

            using (var download = new Utility.WebDownload())
            {
                bool success;
                do
                {
                    try
                    {
                        //DL KeyRatios
                        download.DownloadFile(kr + ticker, Temp + "KeyRatios.csv");
                        success = true;
                    }
                    catch (Exception e)
                    {
                        Utility.WriteToErrorLog(e);
                        success = false;
                        if (timeout == maxTimeout)
                        {
                            return(false);
                        }
                        var time = timeout + 1;
                        Console.Write("\rDownload failed, trying " + time + " of 3");
                        Thread.Sleep(1000); //Sleep for 1 second
                        timeout++;
                    }
                } while (!success);
            }
            //Combine to one XLSX
            using (var package = new ExcelPackage(new FileInfo(Temp + ticker.Trim() + ".xlsx")))
            {
                //Add Key Ratios
                var            source = Temp + "KeyRatios.csv";
                ExcelWorksheet worksheet;
                try
                {
                    worksheet = package.Workbook.Worksheets.Add("Key Ratios");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                    worksheet = package.Workbook.Worksheets[1];
                }
                var data = GetCsvData(source);
                if (data.Count < 4)
                {
                    Utility.WriteToLog(ticker, "Blank or unstandardized Excel document", ErrorLog);
                    return(false);
                }
                worksheet.Cells[1, 1].LoadFromArrays(data);

                try
                {
                    package.Save();
                    File.Delete(Temp + "KeyRatios.csv");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                }
            }
            return(true);
        }
        private static bool Download(string ticker, string dataFolder)
        {
            const string kr          = "http://financials.morningstar.com/ajax/exportKR2CSV.html?t=";
            const string report      = "http://financials.morningstar.com/ajax/ReportProcess4CSV.html?t=";
            const string parameters1 = "&reportType=";
            const string parameters2 = "&period=12&dataType=A&order=asc&columnYear=10&number=3";
            const int    maxTimeout  = 3;
            var          timeout     = 0;

            //No need to download if data is already there
            if (File.Exists(dataFolder + ticker.Trim() + ".xlsx"))
            {
                return(true);
            }

            using (var download = new Utility.WebDownload())
            {
                bool success;
                do
                {
                    try
                    {
                        //DL KeyRatios
                        download.DownloadFile(
                            kr +
                            ticker,
                            Temp +
                            "KeyRatios.csv");
                        //DL Income Statement
                        download.DownloadFile(
                            report +
                            ticker +
                            parameters1 +
                            "is" +
                            parameters2,
                            Temp +
                            "IncomeStatement.csv");
                        //DL Balance Sheet
                        download.DownloadFile(
                            report +
                            ticker +
                            parameters1 +
                            "bs" +
                            parameters2,
                            Temp +
                            "BalanceSheet.csv");
                        //DL Cash Flows
                        download.DownloadFile(
                            report +
                            ticker +
                            parameters1 +
                            "cf" +
                            parameters2,
                            Temp +
                            "CashFlows.csv");
                        success = true;
                    }
                    catch (Exception e)
                    {
                        Utility.WriteToErrorLog(e);
                        success = false;
                        if (timeout == maxTimeout)
                        {
                            return(false);
                        }
                        var time = timeout + 1;
                        Console.Write("\rDownload failed, trying " + time + " of 3");
                        Thread.Sleep(1000); //Sleep for 1 second
                        timeout++;
                    }
                } while (!success);
            }
            //Combine to one XLSX
            if (dataFolder == null)
            {
                dataFolder = Desktop;
            }
            using (var package = new ExcelPackage(new FileInfo(dataFolder + ticker.Trim() + ".xlsx")))
            {
                //Add Key Ratios
                var            source = Temp + "KeyRatios.csv";
                ExcelWorksheet worksheet;
                try
                {
                    worksheet = package.Workbook.Worksheets.Add("Key Ratios");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                    worksheet = package.Workbook.Worksheets[1];
                }
                var data = GetCsvData(source);
                if (data.Count < 4)
                {
                    Utility.WriteToLog(ticker, "Blank or unstandardized Excel document", ErrorLog);
                    return(false);
                }
                worksheet.Cells[1, 1].LoadFromArrays(data);

                //Add income statement
                source = Temp + "IncomeStatement.csv";
                try
                {
                    worksheet = package.Workbook.Worksheets.Add("Income Statement");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                    worksheet = package.Workbook.Worksheets[2];
                }
                data = GetCsvData(source);
                if (data.Count < 4)
                {
                    Utility.WriteToLog(ticker, "Blank or unstandardized Excel document", ErrorLog);
                    return(false);
                }
                worksheet.Cells[1, 1].LoadFromArrays(data);

                //Add balance sheet
                source = Temp + "BalanceSheet.csv";
                try
                {
                    worksheet = package.Workbook.Worksheets.Add("Balance Sheet");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                    worksheet = package.Workbook.Worksheets[3];
                }
                data = GetCsvData(source);
                if (data.Count < 4)
                {
                    Utility.WriteToLog(ticker, "Blank or unstandardized Excel document", ErrorLog);
                    return(false);
                }
                worksheet.Cells[1, 1].LoadFromArrays(data);

                //Add cash flows
                source = Temp + "CashFlows.csv";
                try
                {
                    worksheet = package.Workbook.Worksheets.Add("Cash Flows");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                    worksheet = package.Workbook.Worksheets[4];
                }
                data = GetCsvData(source);
                if (data.Count < 4)
                {
                    Utility.WriteToLog(ticker, "Blank or unstandardized Excel document", ErrorLog);
                    return(false);
                }
                worksheet.Cells[1, 1].LoadFromArrays(data);

                try
                {
                    package.Save();
                    File.Delete(Temp + "KeyRatios.csv");
                    File.Delete(Temp + "IncomeStatement.csv");
                    File.Delete(Temp + "BalanceSheet.csv");
                    File.Delete(Temp + "CashFlows.csv");
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e);
                }
            }
            return(true);
        }