public void Combine() { var one = new NameValueCollection { {"A", "1"} }; var two = new NameValueCollection { {"A", "2"}, {"B", "2"} }; var three = new NameValueCollection { {"A", "3"}, {"B", "3"}, {"C", "3"} }; var result = one.Combine(two, three); Assert.Equal(3, result.AllKeys.Length); Assert.Equal("1", result["A"]); Assert.Equal("2", result["B"]); Assert.Equal("3", result["C"]); }
public static int? CreateIssuerViaWeb(List<DeepBlue.Models.Entity.Issuer> dbIssuers, CookieCollection cookies) { int? issuerId = null; ImportErrors = new List<KeyValuePair<Models.Entity.Issuer, Exception>>(); TotalImportRecords = 0; RecordsImportedSuccessfully = 0; foreach (DeepBlue.Models.Entity.Issuer issuer in dbIssuers) { NameValueCollection formValues = new NameValueCollection(); TotalImportRecords++; try { IssuerDetailModel model = new IssuerDetailModel(); model.CountryId = Globals.DefaultCountryID; model.AnnualMeetingDate = DateTime.Now.Date; model.Name = issuer.Name; formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty)); // Send the request string url = HttpWebRequestUtil.GetUrl("Deal/CreateIssuer"); 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(); issuerId = HttpWebRequestUtil.GetNewKeyFromResponse(resp); if (issuerId != null) { RecordsImportedSuccessfully++; } else { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Issuer, Exception>(issuer, new Exception(resp))); } response.Close(); readStream.Close(); } } } } catch (Exception ex) { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Issuer, Exception>(issuer, ex)); } } LogErrors(ImportErrors); return issuerId; }
public static NameValueCollection ImportInvestors(CookieCollection cookies) { NameValueCollection values = new NameValueCollection(); ImportErrors = new List<KeyValuePair<Models.Entity.Investor, Exception>>(); TotalImportRecords = 0; RecordsImportedSuccessfully = 0; List<DeepBlue.Models.Entity.Investor> dbInvestors = ConvertBlueToDeepBlue(); LogErrors(Errors); foreach (DeepBlue.Models.Entity.Investor investor in dbInvestors) { // make sure that the investor doesnt already exist List<Models.Entity.Investor> existingInvestors = GetInvestors(cookies, null, investor.InvestorName); if (existingInvestors.Count > 0) { //make sure the name match exactly Models.Entity.Investor inv = existingInvestors.Where(x => x.InvestorName.Equals(investor.InvestorName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (inv != null) { // investor already exists Util.WriteWarning(string.Format("Investor: {0} already exists. Found investor: Investor Name: {1}, InvestorID: {2}", investor.InvestorName, inv.InvestorName, inv.InvestorID)); continue; } } NameValueCollection formValues = new NameValueCollection(); TotalImportRecords++; try { CreateModel model = new CreateModel(); model.Alias = investor.Alias; model.DomesticForeign = investor.IsDomestic; model.EntityType = investor.InvestorEntityTypeID; model.InvestorName = investor.InvestorName; model.Alias = investor.FirstName; model.StateOfResidency = investor.ResidencyState.Value; model.SocialSecurityTaxId = investor.Social; model.Notes = investor.Notes; #region Investor's Address InvestorAddress investorAddress = investor.InvestorAddresses.First(); Address address = investorAddress.Address; model.Address1 = address.Address1 ?? ""; model.Address2 = address.Address2 ?? ""; model.City = address.City ?? ""; model.Country = address.Country; model.Zip = address.PostalCode; model.State = address.State.Value; #endregion #region Investor's communication (email, fax etc) List<InvestorCommunication> investorComms = investor.InvestorCommunications.ToList(); foreach (InvestorCommunication comm in investorComms) { if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.HomePhone) { model.Phone = comm.Communication.CommunicationValue; } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.Email) { model.Email = comm.Communication.CommunicationValue; } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.WebAddress) { model.WebAddress = comm.Communication.CommunicationValue; } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.Fax) { model.Fax = comm.Communication.CommunicationValue; } } #endregion #region Investor's Accounts int counter = 0; foreach (InvestorAccount investorAccount in investor.InvestorAccounts.ToList()) { // if (DataTypeHelper.ToInt32(collection[(index + 1).ToString() + "_" + "BankIndex"]) <= 0) continue; formValues.Add(++counter + "_BankIndex", counter.ToString()); // Only the following form keys have name different from the object properties //investorAccount.Routing = DataTypeHelper.ToInt32(collection[(index + 1).ToString() + "_" + "ABANumber"]); //investorAccount.FFCNumber = Convert.ToString(collection[(index + 1).ToString() + "_" + "FFCNO"]); //investorAccount.Account = Convert.ToString(collection[(index + 1).ToString() + "_" + "AccountNumber"]); if (investorAccount.Routing != null) { formValues.Add(counter + "_ABANumber", investorAccount.Routing.ToString()); } if (!string.IsNullOrEmpty(investorAccount.FFCNumber)) { formValues.Add(counter + "_FFCNO", investorAccount.FFCNumber.ToString()); } if (!string.IsNullOrEmpty(investorAccount.Account)) { formValues.Add(counter + "_AccountNumber", investorAccount.Account.ToString()); } formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(investorAccount, counter + "_", string.Empty)); } model.AccountLength = counter; #endregion #region Investor's contact counter = 0; foreach (InvestorContact investorContact in investor.InvestorContacts) { counter++; //if (DataTypeHelper.ToInt32(collection[(index + 1).ToString() + "_" + "ContactIndex"]) <= 0) continue; formValues.Add(counter + "_ContactIndex", counter.ToString()); Contact contact = investorContact.Contact; // Only the following form keys have name different from the object properties //investorContact.Contact.ContactName = Convert.ToString(collection[(index + 1).ToString() + "_" + "ContactPerson"]); //investorContact.Contact.ReceivesDistributionNotices = DataTypeHelper.CheckBoolean(collection[(index + 1).ToString() + "_" + "DistributionNotices"]); //investorContact.Contact.ReceivesFinancials = DataTypeHelper.CheckBoolean(collection[(index + 1).ToString() + "_" + "Financials"]); //investorContact.Contact.ReceivesInvestorLetters = DataTypeHelper.CheckBoolean(collection[(index + 1).ToString() + "_" + "InvestorLetters"]); //investorContact.Contact.ReceivesK1 = DataTypeHelper.CheckBoolean(collection[(index + 1).ToString() + "_" + "K1"]); if (!string.IsNullOrEmpty(contact.ContactName)) { formValues.Add(counter + "_ContactPerson", contact.ContactName); } formValues.Add(counter + "_DistributionNotices", contact.ReceivesDistributionNotices.ToString()); formValues.Add(counter + "_Financials", contact.ReceivesFinancials.ToString()); formValues.Add(counter + "_InvestorLetters", contact.ReceivesInvestorLetters.ToString()); formValues.Add(counter + "_K1", contact.ReceivesK1.ToString()); formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(contact, counter + "_", string.Empty)); #region Contact's address foreach (ContactAddress contactAddress in contact.ContactAddresses) { Address addr = contactAddress.Address; // Only the following form keys have name different from the object properties // contactAddress.Address.PostalCode = collection[(index + 1).ToString() + "_" + "ContactZip"]; if (!string.IsNullOrEmpty(addr.PostalCode)) { formValues.Add(counter + "_ContactZip", addr.PostalCode); } formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(addr, counter + "_Contact", string.Empty)); } #endregion #region Contact's communication (email, fax etc) foreach (ContactCommunication comm in contact.ContactCommunications) { string commValue = comm.Communication.CommunicationValue; if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.HomePhone) { formValues.Add(counter + "_ContactPhoneNumber", commValue); } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.Email) { formValues.Add(counter + "_ContactEmail", commValue); } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.WebAddress) { formValues.Add(counter + "_ContactWebAddress", commValue); } else if (comm.Communication.CommunicationTypeID == (int)Models.Admin.Enums.CommunicationType.Fax) { formValues.Add(counter + "_ContactFaxNumber", commValue); } } #endregion } model.ContactLength = counter; #endregion formValues = formValues.Combine(HttpWebRequestUtil.SetUpForm(model, string.Empty, string.Empty)); // Send the request string url = HttpWebRequestUtil.GetUrl("Investor/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)) { int? investorId = HttpWebRequestUtil.GetNewKeyFromResponse(resp); if (investorId.HasValue) { RecordsImportedSuccessfully++; values = values.Combine(formValues); Util.WriteNewEntry(string.Format("Created new investor: {0}, InvestorId: {1}", model.InvestorName, investorId)); } else { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Investor, Exception>(investor, new Exception(resp))); } } else { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Investor, Exception>(investor, new Exception(resp))); } response.Close(); readStream.Close(); } } } } catch (Exception ex) { ImportErrors.Add(new KeyValuePair<DeepBlue.Models.Entity.Investor, Exception>(investor, ex)); } } LogErrors(ImportErrors); return values; }
public static NameValueCollection CreateUnderlyingFundAddress(int underlyingFundId, Address address, CookieCollection cookies, out string resp) { resp = string.Empty; NameValueCollection values = new NameValueCollection(); UnderlyingFundAddressInformation registeredAddress = new UnderlyingFundAddressInformation(); registeredAddress.UnderlyingFundId = underlyingFundId; registeredAddress.Address1 = address.Address1; registeredAddress.Address2 = address.Address2; registeredAddress.City = address.City; registeredAddress.Country = address.Country; registeredAddress.State = address.State; registeredAddress.Zip = address.PostalCode; NameValueCollection formValues = HttpWebRequestUtil.SetUpForm(registeredAddress, string.Empty, string.Empty); // Send the request string url = HttpWebRequestUtil.GetUrl("Deal/CreateUnderlyingFundAddress"); messageLog.AppendLine("Deal/CreateUnderlyingFundAddress"); string data = HttpWebRequestUtil.ToFormValue(formValues); messageLog.AppendLine("Form Data: " + 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)) { values = values.Combine(formValues); } else { } messageLog.AppendLine("Response: "+resp); response.Close(); readStream.Close(); } } } return values; }