/// <summary> /// Handles a command. /// </summary> /// <param name="command">The command to handle.</param> /// <remarks> /// This method will be called when a command arrives on the bus and should contain /// the custom logic to execute when the command is received. /// </remarks> public void Handle(ExperianTargetBusiness3dPartyCommand command) { ResultInfoAccomulator <IEnumerable <Experian3dPartyCompanyInfo> > info = Experian.TargetBusiness(command.CompanyName, command.PostCode, command.IsLimited, command.RegNumber.HasValue ? command.RegNumber.GetValue() : ""); if (info.HasErrors) { //TODO : check again if (Transaction.Current != null) { Transaction.Current.Rollback(); base.RegisterError(info, command); } } else { SendReply(info, command, o => o.CompanyInfos = info.Result.ToArray()); } }
/// <summary> /// Targets the business. /// </summary> /// <param name="companyName">Name of the company.</param> /// <param name="postCode">The post code.</param> /// <param name="isLimited">if set to <c>true</c> [is limited].</param> /// <param name="regNum">The reg number.</param> /// <returns></returns> public ResultInfoAccomulator <IEnumerable <Experian3dPartyCompanyInfo> > TargetBusiness(string companyName, string postCode, bool isLimited, string regNum = "") { ResultInfoAccomulator <IEnumerable <Experian3dPartyCompanyInfo> > info = new ResultInfoAccomulator <IEnumerable <Experian3dPartyCompanyInfo> >(); companyName = HttpUtility.HtmlEncode(companyName); var xml = new TargetingRequest(companyName, postCode, regNum, isLimited).TransformText(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ExperianESeriesUrl); request.Method = "POST"; request.AllowAutoRedirect = false; request.ContentType = "application/xml"; request.ContentLength = xml.Length; var stOut = new StreamWriter(request.GetRequestStream(), Encoding.ASCII); stOut.Write(xml); stOut.Close(); using (WebResponse resp = request.GetResponse()) { Stream stream = resp.GetResponseStream(); if (stream == null) { LogError("could not read web response.", info); return(info); } using (var sr = new StreamReader(stream)) { string response = sr.ReadToEnd(); var companies = this.HandleResponse(response, info); if (info.HasErrors) { return(info); } info.Result = companies; return(info); } } }