public static NameValueCollection ConvertUnderlyingFundViaWeb(CookieCollection cookies) { NameValueCollection values = new NameValueCollection(); ImportErrors = new List<KeyValuePair<Models.Entity.UnderlyingFund, Exception>>(); TotalImportRecords = 0; RecordsImportedSuccessfully = 0; List<DeepBlue.Models.Entity.UnderlyingFund> dbFunds = ConvertBlueToDeepBlue(); LogErrors(Errors); foreach (DeepBlue.Models.Entity.UnderlyingFund fund in dbFunds) { NameValueCollection formValues = new NameValueCollection(); TotalImportRecords++; try { CreateUnderlyingFundModel model = new CreateUnderlyingFundModel(); //model.FundName = fund.FundName; //// these fields are required. Although inception date is //// not required in the database, it is required by the app //model.TaxId = fund.TaxID; //if (fund.InceptionDate != null) { // model.InceptionDate = fund.InceptionDate; //} //else { // model.InceptionDate = new DateTime(1900, 1, 1); //} //// The following fields are optional //model.ScheduleTerminationDate = fund.ScheduleTerminationDate; //model.FinalTerminationDate = fund.FinalTerminationDate; //model.NumofAutoExtensions = fund.NumofAutoExtensions; //model.DateClawbackTriggered = fund.DateClawbackTriggered; //model.RecycleProvision = fund.RecycleProvision; //model.MgmtFeesCatchUpDate = fund.MgmtFeesCatchUpDate; //model.Carry = fund.Carry; //formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty)); //FundAccount fundAccount = fund.FundAccounts.First(); //FundBankDetail fundAccountModel = new FundBankDetail(); //if (!string.IsNullOrEmpty(fundAccount.BankName)) { // if (fundAccount.BankName.Length > 50) { // fundAccountModel.BankName = fundAccount.BankName.Substring(0, 50); // } //} //if (!string.IsNullOrEmpty(fundAccount.Account)) { // if (fundAccount.Account.Length > 50) { // fundAccountModel.AccountNo = fundAccount.Account.Substring(0, 50); // } //} //fundAccountModel.ABANumber = fundAccount.Routing; //fundAccountModel.Reference = fundAccount.Reference; //fundAccountModel.AccountOf = fundAccount.AccountOf; //fundAccountModel.Attention = fundAccount.Attention; //fundAccountModel.Telephone = fundAccount.Phone; //fundAccountModel.Fax = fundAccount.Fax; ////WARNING: the following fields are not present in blue ////fundAccount.SWIFT; ////fundAccount.AccountNumberCash; ////fundAccount.FFCNumber; ////fundAccount.IBAN; //formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty)); //// Send the request //string url = HttpWebRequestUtil.GetUrl("Fund/Create"); //byte[] postData = System.Text.Encoding.ASCII.GetBytes(HttpWebRequestUtil.ToFormValue(formValues)); //HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, postData, true, cookies); //if (response.StatusCode == System.Net.HttpStatusCode.OK) { // using (Stream receiveStream = response.GetResponseStream()) { // // Pipes the stream to a higher level stream reader with the required encoding format. // using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { // string resp = readStream.ReadToEnd(); // if (string.IsNullOrEmpty(resp)) { // RecordsImportedSuccessfully++; // values = values.Combine(formValues); // } // else { // ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Fund, Exception>(fund, new Exception(resp))); // } // response.Close(); // readStream.Close(); // } // } //} } catch (Exception ex) { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(fund, ex)); } } LogErrors(ImportErrors); return values; }
private static int? CreateNewUnderlyingFund(CookieCollection cookies, CreateUnderlyingFundModel model, out string resp) { resp = string.Empty; int? underlyingFundId = null; NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty); string url = HttpWebRequestUtil.GetUrl("Deal/UpdateUnderlyingFund"); string data = HttpWebRequestUtil.ToFormValue(formValues); messageLog.Append("Form Data:").AppendLine(data); byte[] postData = System.Text.Encoding.ASCII.GetBytes(data); HttpWebResponse response = HttpWebRequestUtil.SendRequest(url, postData, true, cookies); if (response.StatusCode == System.Net.HttpStatusCode.OK) { using (Stream receiveStream = response.GetResponseStream()) { // Pipes the stream to a higher level stream reader with the required encoding format. using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { resp = readStream.ReadToEnd(); if (!string.IsNullOrEmpty(resp)) { if (resp.ToLower().StartsWith("true")) { int ufid = 0; if (Int32.TryParse(resp.Substring(resp.LastIndexOf('|') + 1), out ufid)) { underlyingFundId = ufid; } } } messageLog.AppendLine("Response: " + resp); response.Close(); readStream.Close(); } } } return underlyingFundId; }
private static int? CreateUnderlyingFund(CookieCollection cookies, DeepBlue.Models.Entity.UnderlyingFund underlyingFund, Address address, int? issuerId, ref int RecordsImportedSuccessfully, ref List<KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>> ImportErrors) { CreateUnderlyingFundModel model = new CreateUnderlyingFundModel(); model.IsFeesIncluded = underlyingFund.IsFeesIncluded; model.FundName = underlyingFund.FundName; model.FundTypeId = underlyingFund.FundTypeID; model.IssuerId = issuerId.Value; model.VintageYear = underlyingFund.VintageYear; model.TotalSize = underlyingFund.TotalSize; model.TerminationYear = underlyingFund.TerminationYear; model.IncentiveFee = underlyingFund.IncentiveFee; model.LegalFundName = underlyingFund.LegalFundName; model.Description = underlyingFund.Description; model.FiscalYearEnd = underlyingFund.FiscalYearEnd; model.ManagementFee = underlyingFund.ManagementFee; model.Taxable = underlyingFund.Taxable; model.TaxRate = underlyingFund.TaxRate; model.AuditorName = underlyingFund.AuditorName; model.IsDomestic = underlyingFund.IsDomestic; model.Exempt = underlyingFund.Exempt; model.IndustryId = underlyingFund.IndustryID; model.GeographyId = underlyingFund.GeographyID; model.ReportingFrequencyId = underlyingFund.ReportingFrequencyID; model.ReportingTypeId = underlyingFund.ReportingTypeID; // We dont use the ShareClass Type // model.ShareClassTypeId // We also dont use the InvestmentTypeId // model.InvestmentTypeId = underlyingFund.InvestmentTypeID; model.Description = underlyingFund.Description; model.FiscalYearEnd = underlyingFund.FiscalYearEnd; model.IsDomestic = underlyingFund.IsDomestic; model.FundStructureId = underlyingFund.FundStructureID; model.Taxable = underlyingFund.Taxable; model.Exempt = underlyingFund.Exempt; model.ManagementFee = underlyingFund.ManagementFee; model.IncentiveFee = underlyingFund.IncentiveFee; model.TaxRate = underlyingFund.TaxRate; model.AuditorName = underlyingFund.AuditorName; model.WebUserName = underlyingFund.WebUserName; model.WebPassword = underlyingFund.WebPassword; if (underlyingFund.Account != null) { model.BankName = underlyingFund.Account.BankName; model.ABANumber = underlyingFund.Account.Routing; model.AccountOf = underlyingFund.Account.AccountOf; model.AccountNumber = underlyingFund.Account.Account1; model.Account = underlyingFund.Account.Account1; model.Attention = underlyingFund.Account.Attention; model.Reference = underlyingFund.Account.Reference; } if (address != null) { model.Address1 = address.Address1; model.Address2 = address.Address2; model.City = address.City; model.Country = address.Country; model.State = address.State; model.Zip = address.PostalCode; } else { model.Address1 = Globals.DefaultStringValue; model.City = Globals.DefaultStringValue; model.Country = Globals.DefaultCountryID; model.State = Globals.DefaultStateID; model.Zip = Globals.DefaultZip; } string resp = string.Empty; int? underlyingFundId = CreateNewUnderlyingFund(cookies, model, out resp); if (underlyingFundId != null) { RecordsImportedSuccessfully++; string error = string.Empty; // Create the Contact // /Deal/CreateUnderlyingFundContact List<UnderlyingFundContact> contacts = underlyingFund.UnderlyingFundContacts.ToList(); foreach (UnderlyingFundContact ufContact in contacts) { ufContact.UnderlyingtFundID = underlyingFundId.Value; int? ufContactID = CreateUnderlyingFundContact(ufContact, cookies, out resp); if (ufContactID == null) { error += " Underlying Fund Contact could not be created. Response: " + resp; } } // Create the Address // /Deal/CreateUnderlyingFundAddress if (address != null) { CreateUnderlyingFundAddress(underlyingFundId.Value, address, cookies, out resp); if (!string.IsNullOrEmpty(resp)) { error += " Underlying Fund Address could not be created. Response: " + resp; } } if (!string.IsNullOrEmpty(error)) { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(underlyingFund, new Exception("Underlying Fund was created, but the following errors were encountered: " + error))); } } else { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(underlyingFund, new Exception("Underlying Fund Could not be created. Response: " + resp))); } return underlyingFundId; }
public static NameValueCollection ImportFunds(CookieCollection cookies) { NameValueCollection values = new NameValueCollection(); ImportErrors = new List<KeyValuePair<Models.Entity.UnderlyingFund, Exception>>(); TotalImportRecords = 0; RecordsImportedSuccessfully = 0; List<KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Address>> dbFunds = ConvertBlueToDeepBlue(); LogErrors(Errors); // Create a new issuer and assign all the underlying funds to it int? issuerId = 0; if (dbFunds.Count > 0) { issuerId = CreateIssuer(cookies); } if (issuerId != null) { string msg = "Created new issuer: " + issuerId; Util.WriteNewEntry(msg); messageLog.AppendLine(msg); foreach (KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Address> kvp in dbFunds) { NameValueCollection formValues = new NameValueCollection(); DeepBlue.Models.Entity.UnderlyingFund underlyingFund = kvp.Key; if (!IsUnderlyingFundAlreadyPresent(underlyingFund.FundName)) { TotalImportRecords++; try { CreateUnderlyingFundModel model = new CreateUnderlyingFundModel(); model.IsFeesIncluded = underlyingFund.IsFeesIncluded; model.FundName = underlyingFund.FundName; model.FundTypeId = underlyingFund.FundTypeID; model.IssuerId = issuerId.Value; model.VintageYear = underlyingFund.VintageYear; model.TotalSize = underlyingFund.TotalSize; model.TerminationYear = underlyingFund.TerminationYear; model.IncentiveFee = underlyingFund.IncentiveFee; model.LegalFundName = underlyingFund.LegalFundName; model.Description = underlyingFund.Description; model.FiscalYearEnd = underlyingFund.FiscalYearEnd; model.ManagementFee = underlyingFund.ManagementFee; model.Taxable = underlyingFund.Taxable; model.TaxRate = underlyingFund.TaxRate; model.AuditorName = underlyingFund.AuditorName; model.IsDomestic = underlyingFund.IsDomestic; model.Exempt = underlyingFund.Exempt; model.IndustryId = underlyingFund.IndustryID; model.GeographyId = underlyingFund.GeographyID; model.ReportingFrequencyId = underlyingFund.ReportingFrequencyID; model.ReportingTypeId = underlyingFund.ReportingTypeID; // We dont use the ShareClass Type // model.ShareClassTypeId // We also dont use the InvestmentTypeId // model.InvestmentTypeId = underlyingFund.InvestmentTypeID; model.Description = underlyingFund.Description; model.FiscalYearEnd = underlyingFund.FiscalYearEnd; model.IsDomestic = underlyingFund.IsDomestic; model.FundStructureId = underlyingFund.FundStructureID; model.Taxable = underlyingFund.Taxable; model.Exempt = underlyingFund.Exempt; model.ManagementFee = underlyingFund.ManagementFee; model.IncentiveFee = underlyingFund.IncentiveFee; model.TaxRate = underlyingFund.TaxRate; model.AuditorName = underlyingFund.AuditorName; model.WebUserName = underlyingFund.WebUserName; model.WebPassword = underlyingFund.WebPassword; if (underlyingFund.Account != null) { model.BankName = underlyingFund.Account.BankName; model.ABANumber = underlyingFund.Account.Routing; model.AccountOf = underlyingFund.Account.AccountOf; model.AccountNumber = underlyingFund.Account.Account1; model.Account = underlyingFund.Account.Account1; model.Attention = underlyingFund.Account.Attention; model.Reference = underlyingFund.Account.Reference; } Address address = kvp.Value; if (address != null) { model.Address1 = address.Address1; model.Address2 = address.Address2; model.City = address.City; model.Country = address.Country; model.State = address.State; model.Zip = address.PostalCode; } string resp = string.Empty; int? underlyingFundId = CreateNewUnderlyingFund(cookies, model, out resp); if (underlyingFundId != null) { string newUFMsg = string.Format("created new UF. {0}, new UFID: {1}", model.FundName, underlyingFundId); messageLog.AppendLine(newUFMsg); Util.WriteNewEntry(newUFMsg); RecordsImportedSuccessfully++; string error = string.Empty; // Create the Contact // /Deal/CreateUnderlyingFundContact List<UnderlyingFundContact> contacts = underlyingFund.UnderlyingFundContacts.ToList(); foreach (UnderlyingFundContact ufContact in contacts) { ufContact.UnderlyingtFundID = underlyingFundId.Value; int? ufContactID = CreateUnderlyingFundContact(ufContact, cookies, out resp); if (ufContactID == null) { messageLog.AppendLine("FAIL: UF.Contact Could not be created."); string newContactMsg = " Underlying Fund Contact could not be created. Response: " + resp; Util.WriteError(newContactMsg); error += newContactMsg; } else { string newContactMsg = string.Format("created new contact for UF: {0}, UFID: {1}, Contact: {2}, UFContactID: {3}", model.FundName, underlyingFundId, ufContact.Contact.ContactName, ufContactID); messageLog.AppendLine(newContactMsg); Util.WriteNewEntry(newContactMsg); } } // Create the Address // /Deal/CreateUnderlyingFundAddress //Address address = kvp.Value; //if (address != null) { // CreateUnderlyingFundAddress(underlyingFundId.Value, address, cookies, out resp); // if (!string.IsNullOrEmpty(resp)) { // messageLog.AppendLine("FAIL: UF.FundAddress could not be created"); // error += " Underlying Fund Address could not be created. Response: " + resp; // } else { // string newAddressMsg = string.Format("created new address for UF: {0}, UFID: {1}", model.FundName, underlyingFundId); // messageLog.AppendLine(newAddressMsg); // Util.WriteNewEntry(newAddressMsg); // } //} if (!string.IsNullOrEmpty(error)) { Util.WriteError(error); ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(underlyingFund, new Exception("Underlying Fund was created, but the following errors were encountered: " + error))); } } else { Util.WriteError(string.Format("Error creating UF: {0}, Response: {1}" , underlyingFund.FundName, resp)); ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(underlyingFund, new Exception("Underlying Fund Could not be created. Response: " + resp))); } } catch (Exception ex) { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.UnderlyingFund, Exception>(underlyingFund, ex)); Util.WriteError(ex.Message); Util.Log(ex.Message); } } else { string alreadyPresent = string.Format("Underlying fund: {0} is already present", underlyingFund.FundName); Util.WriteWarning(alreadyPresent); messageLog.AppendLine(alreadyPresent); } } } else { Util.WriteError("CANNOT CREATE ISSUER. BAILING......."); messageLog.AppendLine("Error creating issuer"); } LogErrors(ImportErrors); LogMessages(); return values; }