예제 #1
0
        public static bool ReadFile(List <OptimisationResult> data,
                                    string pathToReportFile,
                                    string expectedCurecncy  = null,
                                    double?expectedBalance   = null,
                                    int?expectedLaverage     = null,
                                    string expectedPathToBot = null,
                                    bool deleteAfterReading  = true)
        {
            if (!File.Exists(pathToReportFile))
            {
                return(false);
            }

            bool ans = false;

            using (ReportReader reader = new ReportReader(pathToReportFile))
            {
                if (!string.IsNullOrEmpty(expectedCurecncy) &&
                    !string.IsNullOrWhiteSpace(expectedCurecncy) &&
                    reader.Currency != expectedCurecncy)
                {
                    throw new Exception("Currency is different");
                }
                if (!string.IsNullOrEmpty(expectedPathToBot) &&
                    !string.IsNullOrWhiteSpace(expectedPathToBot) &&
                    reader.RelativePathToBot != expectedPathToBot)
                {
                    throw new Exception("Path to bot is different");
                }
                if (expectedBalance.HasValue &&
                    reader.Balance != expectedBalance.Value)
                {
                    throw new Exception("Balance is different");
                }
                if (expectedLaverage.HasValue &&
                    reader.Laverage != expectedLaverage)
                {
                    throw new Exception("Laverage is different");
                }

                while (reader.Read())
                {
                    data.Add(reader.ReportItem.Value);
                    if (!ans)
                    {
                        ans = true;
                    }
                }
            }

            if (deleteAfterReading)
            {
                File.Delete(pathToReportFile);
            }

            return(ans);
        }
        /// <summary>
        /// Чтение файла с результатами оптимизаций
        /// </summary>
        /// <param name="file">Файл</param>
        /// <param name="expert">Имя жксперта</param>
        /// <param name="deposit">Депозит</param>
        /// <param name="currensy">Валюта депозита</param>
        /// <param name="laverage">Кредитное плечо</param>
        /// <returns>Список результатов оптимизации</returns>
        private List <OptimisationResult> GetItems(FileInfo file, out string expert,
                                                   out double deposit, out string currensy, out int laverage)
        {
            List <OptimisationResult> ans = new List <OptimisationResult>();

            using (ReportReader reader = new ReportReader(file.FullName))
            {
                expert   = reader.RelativePathToBot;
                deposit  = reader.Balance;
                currensy = reader.Currency;
                laverage = reader.Laverage;

                while (reader.Read())
                {
                    if (reader.ReportItem.HasValue)
                    {
                        ans.Add(reader.ReportItem.Value);
                    }
                }
            }

            return(ans);
        }