Ejemplo n.º 1
0
        private void ParseCashFlowAnnual()
        {
            // 1) Parse all the datetimes
            HtmlNode node = htmlNodeCollection[1];

            foreach (var i in node.ChildNodes)
            {
                if (typeof(HtmlNode) == i.GetType() && i.Name == "thead")
                {
                    //Console.WriteLine(i.Name);
                    HtmlNodeCollection dates = i.FirstChild.ChildNodes;
                    foreach (var ii in dates)
                    {
                        if (typeof(HtmlNode) == ii.GetType())
                        {
                            string[] dateArray = ii.InnerText.Split(new char[] { ' ' });

                            try
                            {
                                DateTime tt = DateTime.Parse(dateArray[dateArray.Length - 1]);
                                //Console.WriteLine(tt.ToString());
                                Periods.Add(tt);
                            }
                            catch (Exception ex)
                            {
                                //throw new FormatException("Could not properly parse Cash Flow Financials Dates", ex);
                                //Console.WriteLine("Exception: ");
                                //Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            // 2) Make data structure for the datetime => row element name
            foreach (var i in node.ChildNodes)
            {
                if (typeof(HtmlNode) == i.GetType() && i.Name == "tbody")
                {
                    //Console.WriteLine(i.Name);

                    foreach (var ii in i.ChildNodes)
                    {
                        //Console.WriteLine(ii.Name);
                        int nodeCount = 0;

                        if (typeof(HtmlNode) == ii.GetType() && ii.Name == "tr")
                        {
                            CashFlowTypeValue[] cashFlowTypeValue = new CashFlowTypeValue[Periods.Count];

                            int ci = 0;
                            Periods.ForEach(p =>
                            {
                                cashFlowTypeValue[ci] = new CashFlowTypeValue()
                                {
                                    Date = p
                                };
                                ci++;
                            });

                            int nodeCountRow = 0;
                            foreach (var iii in ii.ChildNodes)
                            {
                                /*
                                 #text
                                 * tr
                                 * ==>#text
                                 * ==>td        // MemberElementName
                                 * ==>#text
                                 * ==>td        // Nearest Date Value
                                 * ==>#text
                                 * ==>td        // 2nd Nearest Date Value
                                 * ==>#text
                                 * ==>td        // 3rd Nearest Date Value
                                 * ==>#text
                                 * ==>td        // 4th Nearest Date Value
                                 * ==>#text
                                 #text
                                 */
                                //Console.WriteLine("==>{0}", iii.Name);
                                if (typeof(HtmlNode) == iii.GetType() && iii.Name == "td")
                                {
                                    switch (nodeCountRow)
                                    {
                                    case 0:
                                        //cashFlowTypeValue.MemeberElementName = iii.InnerText;
                                        // TODO: use generic .All(Func<>) instead of this loop.
                                        for (int z = 0; z < Periods.Count; z++)
                                        {
                                            cashFlowTypeValue[z].MemeberElementName = iii.InnerText.Trim().Trim(new char[] { '\n' });
                                        }
                                        break;

                                    case 1:
                                        //cashFlowTypeValue.Value = double.Parse(iii.InnerText);
                                        try
                                        {
                                            cashFlowTypeValue[0].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                        }
                                        catch (FormatException ex)
                                        {
                                            //Console.WriteLine("FormatException: {0}", ex.Message);
                                            //throw new FormatException("Problem parsing first date's value.", ex);
                                        }
                                        break;

                                    case 2:
                                        try
                                        {
                                            cashFlowTypeValue[1].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                        }
                                        catch (FormatException ex)
                                        {
                                            //Console.WriteLine("FormatException: {0}", ex.Message);
                                            //throw new FormatException("Problem parsing second date's value.", ex);
                                        }
                                        break;

                                    case 3:
                                        try
                                        {
                                            cashFlowTypeValue[2].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                        }
                                        catch (FormatException ex)
                                        {
                                            //Console.WriteLine("FormatException: {0}", ex.Message);
                                            //throw new FormatException("Problem parsing third date's value.", ex);
                                        }
                                        break;

                                    case 4:
                                        try
                                        {
                                            cashFlowTypeValue[3].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                        }
                                        catch (FormatException ex)
                                        {
                                            //Console.WriteLine("FormatException: {0}", ex.Message);
                                            //throw new FormatException("Problem parsing forth date's value.", ex);
                                        }
                                        break;
                                    }
                                    nodeCountRow++;
                                }
                            }

                            CashFlowValues = new List <CashFlowTypeValue>();
                            for (int z = 0; z < Periods.Count; z++)
                            {
                                CashFlowValues.Add(cashFlowTypeValue[z]);
                            }

                            CashFlowValuesDatabase.Add(CashFlowValues[0].MemeberElementName, CashFlowValues);


                            //CashFlowValues.Add(cashFlowTypeValue);

                            nodeCount++;
                        }
                    }
                }// Should produce our data set.
            }
            // 3) Make data structure for the row element => value
        }
Ejemplo n.º 2
0
        private void ParseCashFlowAnnual()
        {
            // 1) Parse all the datetimes
            HtmlNode node = htmlNodeCollection[1];
            foreach (var i in node.ChildNodes)
            {
                if (typeof(HtmlNode) == i.GetType() && i.Name == "thead")
                {
                    //Console.WriteLine(i.Name);
                    HtmlNodeCollection dates = i.FirstChild.ChildNodes;
                    foreach (var ii in dates)
                    {
                        if (typeof(HtmlNode) == ii.GetType())
                        {
                            
                            string[] dateArray = ii.InnerText.Split(new char[] { ' ' });

                            try
                            {
                                DateTime tt = DateTime.Parse(dateArray[dateArray.Length-1]);
                                //Console.WriteLine(tt.ToString());
                                Periods.Add(tt);
                            }
                            catch (Exception ex)
                            {
                                //throw new FormatException("Could not properly parse Cash Flow Financials Dates", ex);
                                //Console.WriteLine("Exception: ");
                                //Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            // 2) Make data structure for the datetime => row element name
            foreach (var i in node.ChildNodes)
            {
                if (typeof(HtmlNode) == i.GetType() && i.Name == "tbody")
                {
                    //Console.WriteLine(i.Name);

                    foreach (var ii in i.ChildNodes)
                    {
                        //Console.WriteLine(ii.Name);
                        int nodeCount = 0;

                        if (typeof(HtmlNode) == ii.GetType() && ii.Name == "tr")
                        {

                            CashFlowTypeValue[] cashFlowTypeValue = new CashFlowTypeValue[Periods.Count];

                            int ci = 0;
                            Periods.ForEach(p =>
                                {
                                    cashFlowTypeValue[ci] = new CashFlowTypeValue()
                                    {
                                        Date = p
                                    };
                                    ci++;
                                });

                            int nodeCountRow = 0;
                            foreach (var iii in ii.ChildNodes)
                            {
                                /*
                                #text
                                tr
                                ==>#text
                                ==>td 		// MemberElementName
                                ==>#text
                                ==>td 		// Nearest Date Value
                                ==>#text
                                ==>td 		// 2nd Nearest Date Value
                                ==>#text
                                ==>td 		// 3rd Nearest Date Value 
                                ==>#text
                                ==>td 		// 4th Nearest Date Value 
                                ==>#text
                                #text
                                */
                                //Console.WriteLine("==>{0}", iii.Name);
                                if (typeof(HtmlNode) == iii.GetType() && iii.Name == "td")
                                {
                                    switch (nodeCountRow)
                                    {
                                        case 0:
                                            //cashFlowTypeValue.MemeberElementName = iii.InnerText;
                                            // TODO: use generic .All(Func<>) instead of this loop.
                                            for (int z = 0; z < Periods.Count; z++)
                                            {
                                                cashFlowTypeValue[z].MemeberElementName = iii.InnerText.Trim().Trim(new char[] { '\n' });
                                            }
                                            break;

                                        case 1:
                                            //cashFlowTypeValue.Value = double.Parse(iii.InnerText);
                                            try
                                            {
                                                cashFlowTypeValue[0].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                            }
                                            catch (FormatException ex)
                                            {
                                                //Console.WriteLine("FormatException: {0}", ex.Message);
                                                //throw new FormatException("Problem parsing first date's value.", ex);
                                            }
                                            break;

                                        case 2:
                                            try
                                            {
                                                cashFlowTypeValue[1].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                            }
                                            catch (FormatException ex)
                                            {
                                                //Console.WriteLine("FormatException: {0}", ex.Message);
                                                //throw new FormatException("Problem parsing second date's value.", ex);
                                            }
                                            break;

                                        case 3:
                                            try
                                            {
                                                cashFlowTypeValue[2].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                            }
                                            catch (FormatException ex)
                                            {
                                                //Console.WriteLine("FormatException: {0}", ex.Message);
                                                //throw new FormatException("Problem parsing third date's value.", ex);
                                            }
                                            break;

                                        case 4:
                                            try
                                            {
                                                cashFlowTypeValue[3].Value = double.Parse(iii.InnerText.Trim().Trim(new char[] { '\n' }));
                                            }
                                            catch (FormatException ex)
                                            {
                                                //Console.WriteLine("FormatException: {0}", ex.Message);
                                                //throw new FormatException("Problem parsing forth date's value.", ex);
                                            }
                                            break;
                                    }
                                    nodeCountRow++;
                                }

                             
                            }

                            CashFlowValues = new List<CashFlowTypeValue>();
                            for (int z = 0; z < Periods.Count; z++)
                            {
                                CashFlowValues.Add(cashFlowTypeValue[z]);
                            }

                            CashFlowValuesDatabase.Add(CashFlowValues[0].MemeberElementName, CashFlowValues);
                               

                            //CashFlowValues.Add(cashFlowTypeValue);

                            nodeCount++;
                        }
                    }
                }// Should produce our data set.
            }
            // 3) Make data structure for the row element => value 
            
        }