Пример #1
0
        private static List <EnergyEstimateImportItem> GetRefDataFromFile()
        {
            string importFile;
            string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            importFile = Path.Combine(directory, "energy.txt");

            StreamReader reader     = new StreamReader(importFile);
            int          lineNumber = 0;

            List <EnergyEstimateImportItem> importItems = new List <EnergyEstimateImportItem>();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                lineNumber++;
                try
                {
                    string[] stringValues = line.Split("\t".ToCharArray());
                    if (stringValues.Length >= 2)
                    {
                        string             projectNumber = stringValues[0];
                        List <Degradation> degradations  = new List <Degradation>();

                        for (var i = 1; i < stringValues.Length; i++)
                        {
                            var    rate = stringValues[i];
                            double degradationRate;
                            int    degradationYear = -1;

                            string[] rateValuePairs = rate.Split('|');

                            degradationRate = Convert.ToDouble(rateValuePairs[0]);
                            if (rateValuePairs.Length == 2)
                            {
                                degradationYear = Convert.ToInt32(rateValuePairs[1]);
                            }

                            Degradation degradation = new Degradation();
                            degradation.Rate = degradationRate;
                            degradation.Year = degradationYear;
                            degradations.Add(degradation);
                        }

                        EnergyEstimateImportItem importItem = new EnergyEstimateImportItem();
                        importItem.ProjectNumber = projectNumber;
                        importItem.Degradations  = degradations;
                        importItems.Add(importItem);
                    }
                    else
                    {
                        throw new Exception("Incorrect # of values");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on line #" + lineNumber);
                    Console.WriteLine(ex.Message);
                }
            }

            return(importItems);
        }
Пример #2
0
        private static List<EnergyEstimateImportItem> GetRefDataFromFile()
        {
            string importFile;
            string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            importFile = Path.Combine(directory, "energy.txt");

            StreamReader reader = new StreamReader(importFile);
            int lineNumber = 0;

            List<EnergyEstimateImportItem> importItems = new List<EnergyEstimateImportItem>();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                lineNumber++;
                try
                {
                    string[] stringValues = line.Split("\t".ToCharArray());
                    if (stringValues.Length >= 2)
                    {
                        string projectNumber = stringValues[0];
                        List<Degradation> degradations = new List<Degradation>();

                        for (var i = 1; i < stringValues.Length; i++)
                        {
                            var rate = stringValues[i];
                            double degradationRate;
                            int degradationYear = -1;

                            string[] rateValuePairs = rate.Split('|');

                            degradationRate = Convert.ToDouble(rateValuePairs[0]);
                            if (rateValuePairs.Length == 2)
                            {
                                degradationYear = Convert.ToInt32(rateValuePairs[1]);
                            }

                            Degradation degradation = new Degradation();
                            degradation.Rate = degradationRate;
                            degradation.Year = degradationYear;
                            degradations.Add(degradation);
                        }

                        EnergyEstimateImportItem importItem = new EnergyEstimateImportItem();
                        importItem.ProjectNumber = projectNumber;
                        importItem.Degradations = degradations;
                        importItems.Add(importItem);

                    }
                    else
                        throw new Exception("Incorrect # of values");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on line #" + lineNumber);
                    Console.WriteLine(ex.Message);
                }
            }

            return importItems;
        }