public JObject ColectBBTable(int tablePosition, string headerCaption, string?defaultType) { try { var wc = new WebClient(); wc.Encoding = UTF8Encoding.UTF8; string page = System.Web.HttpUtility.HtmlDecode(wc.DownloadString(Links.GetLink(Link.BB_PAGE))); var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(page); JObject tableData = new JObject(); List <string> headerTable = new List <string>(); string type = defaultType != null ? defaultType : String.Empty; foreach (HtmlNode node in htmlDocument.QuerySelectorAll($"#formulario > table:nth-child({tablePosition}) > thead > tr:nth-child(2) > th")) { headerTable.Add(node.InnerText.Trim()); } InvestmentFundHeader header = new InvestmentFundHeader(); header.name = headerTable[0]; header.day = headerTable[1]; header.accumulatedMonth = headerTable[2]; header.month = headerTable[3]; header.year = headerTable[4]; header.month12 = headerTable[5]; header.month24 = headerTable[6]; header.month36 = headerTable[7]; header.month12_PL_Avarage = headerTable[8]; header.annualAdministrationFee = headerTable[9]; header.quotaDate = headerTable[10]; header.quotaValue = headerTable[11]; header.startDate = headerTable[12]; List <InvestmentFund> bodyData = new List <InvestmentFund>(); foreach (HtmlNode trNode in htmlDocument.QuerySelectorAll($"#formulario > table:nth-child({tablePosition}) > tbody > tr")) { var totalElements = trNode.GetChildElements(); if (trNode.GetChildElements().Count() == 1) { type = trNode.InnerText.Trim(); } else { InvestmentFund investmentFundItem = new InvestmentFund(); List <string> itemData = new List <string>(); foreach (HtmlNode tdNode in trNode.GetChildElements()) { itemData.Add(tdNode.InnerText.Trim()); } investmentFundItem.name = itemData[0].Replace("\n", "").Replace("\t", ""); investmentFundItem.day = itemData[1] != null && itemData[1] != "" && itemData[1] != "-" ? double.Parse(itemData[1].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.accumulatedMonth = itemData[2] != null && itemData[2] != "" && itemData[2] != "-" ? double.Parse(itemData[2].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.month = itemData[3] != null && itemData[3] != "" && itemData[3] != "-" ? double.Parse(itemData[3].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.year = itemData[4] != null && itemData[4] != "" && itemData[4] != "-" ? double.Parse(itemData[4].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.month12 = itemData[5] != null && itemData[5] != "" && itemData[5] != "-" ? double.Parse(itemData[5].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.month24 = itemData[6] != null && itemData[6] != "" && itemData[6] != "-" ? double.Parse(itemData[6].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.month36 = itemData[7] != null && itemData[7] != "" && itemData[7] != "-" ? double.Parse(itemData[7].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.month12_PL_Avarage = itemData[8] != null && itemData[8] != "" && itemData[8] != "-" ? int.Parse(itemData[8].Replace(".", ""), CultureInfo.InvariantCulture) : 0; investmentFundItem.annualAdministrationFee = itemData[9]; investmentFundItem.quotaDate = itemData[10]; investmentFundItem.quotaValue = itemData[11] != null && itemData[11] != "" && itemData[11] != "-" ? double.Parse(itemData[11].Replace(",", "."), CultureInfo.InvariantCulture) : 0.00; investmentFundItem.startDate = itemData[12]; investmentFundItem.type = type; bodyData.Add(investmentFundItem); } } tableData.Add("name", headerCaption); tableData.Add("header", JToken.FromObject(header)); tableData.Add("data", JToken.FromObject(bodyData)); return(tableData); } catch (Exception e) { return(null); } }
public void PortfolioContructionTest() { Equity e; Debt s; InvestmentFund f; Rating r; AssetHolding ia; Portfolio p; try { using (var db = new FGABusinessComponent.BusinessComponent.FGAContext("PREPROD", compiledModel)) { #if DEBUG // xml seeder: le fichier xml est lu et est chargé comme valeurs par défaut db.SaveChanges(); // ecriture du fichier pour permettre d avoir un fichier FGABusinessComponent.BusinessComponent.Util.EFCodeFirstMethods.DumpDbCreationScriptToFile(db); #endif f = new InvestmentFund(ISIN: "ZZ11110000", FinancialInstrumentName: "Equity 1-Holding test", FinancialAssetTypeCategoryCode: FinancialAssetTypeCategoryCode.DEBT); db.InvestmentFunds.Add(f); p = new Portfolio(ISIN: "ZZ11110000", Date: new DateTime(9999, 12, 31), Name: "ExempleFonds1"); db.Portfolios.Add(p); db.SaveChanges(); AssetPortfolioAssociation assoc = new AssetPortfolioAssociation(p, f); f.UnderlyingPortfolio = assoc; assoc.InvestmentAmount = new CurrencyAndAmount(); assoc.InvestmentAmount.Value = 5; assoc.InvestmentAmount.Currency = (CurrencyCode)"EUR"; db.AssetPortfolioAssociations.Add(assoc); db.SaveChanges(); s = new Debt(ISIN: "PP11110000", FinancialInstrumentName: "Debt 1-Portfolio test", MaturityDate: new DateTime(2013, 1, 1), interestCoupon: new InterestCalculation(new PercentageRate(1.666), new FrequencyCode(1))); db.Debts.Add(s); ia = new AssetHolding(Date: this.dateOfData, ISIN: s.ISINId, HoldAsset: s, Holder: p, Quantity: 100); db.AssetHoldings.Add(ia); p.Add(ia); e = new Equity(ISIN: "PP11110000", FinancialInstrumentName: "Equity 1-Portfolio test"); db.Equities.Add(e); ia = new AssetHolding(Date: this.dateOfData, ISIN: e.ISINId, Holder: p, HoldAsset: e, Quantity: 200); db.AssetHoldings.Add(ia); p.Add(ia); s = new Debt(ISIN: "PP22220000", FinancialInstrumentName: "Debt 2-Portfolio test", MaturityDate: new DateTime(2013, 1, 1), interestCoupon: new InterestCalculation(new PercentageRate(1.666), new FrequencyCode(1))); db.Debts.Add(s); ia = new AssetHolding(Date: this.dateOfData, ISIN: s.ISINId, Holder: p, HoldAsset: s, Quantity: 300); db.AssetHoldings.Add(ia); p.Add(ia); db.SaveChanges(); } } catch (Exception ex) { System.Console.WriteLine(ex); throw ex; } }
public InvestmentFundBuilder() { investmentFund = new InvestmentFund(); }