private InquiryActivityLogResponse InquiryActivityLog(AuditLogEntity auditLog, ActivitySearchFilter searchFilter) { CAR.CASLogServiceSoapClient client = null; var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--CARLogService.InquiryActivityLog--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.InquiryActivityLog); var header = new CAR.LogServiceHeader { ReferenceNo = profile.reference_no, ServiceName = profile.service_name, SystemCode = profile.system_code, SecurityKey = profile.password, TransactionDateTime = DateTime.Now, }; decimal subsTypeCodeAsDecimal; try { subsTypeCodeAsDecimal = Convert.ToDecimal(searchFilter.SubsTypeCode, CultureInfo.InvariantCulture); } catch (Exception ex) { subsTypeCodeAsDecimal = 0; Logger.Error("Exception occur:\n", ex); } if (subsTypeCodeAsDecimal == 0 || string.IsNullOrEmpty(searchFilter.CardNo)) { subsTypeCodeAsDecimal = 0; searchFilter.CardNo = null; } var activitiyLogData = new CAR.InqueryActivityLogData { ActivityStartDateTime = searchFilter.ActivityStartDateTimeValue, // "2015-01-01".ParseDateTime("yyyy-MM-dd").Value ActivityEndDateTime = searchFilter.ActivityEndDateTimeValue, // "2016-06-07".ParseDateTime("yyyy-MM-dd").Value ChannelID = null, SubscriptionTypeID = searchFilter.SrOnly ? 0 : subsTypeCodeAsDecimal, // 1, SubscriptionID = searchFilter.SrOnly ? null : searchFilter.CardNo, // "3601000025739", SrID = searchFilter.SrOnly ? searchFilter.SrNo : null, // "162817263527", CampaignID = string.Empty, TypeID = 0, AreaID = 0, SubAreaID = 0 }; CAR.InqueryActivytyLogResponse resActivity = null; #region "Call Service" string flgCatchErrorCode = string.Empty; // Avoid error codes _commonFacade = new CommonFacade(); List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CAR, Constants.ServiceName.InquiryActivityLog); try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}\n{1}", header.SerializeObject(), activitiyLogData.SerializeObject()); client = new CAR.CASLogServiceSoapClient("CASLogServiceSoap"); resActivity = client.InquiryActivityLog(header, activitiyLogData); if (client != null) { ((ICommunicationObject)client).Abort(); } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resActivity != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resActivity.SerializeObject()); InquiryActivityLogResponse response = new InquiryActivityLogResponse(); response.StatusResponse.ErrorCode = resActivity.ResponseStatus.ResponseCode; response.StatusResponse.Description = resActivity.ResponseStatus.ResponseMessage; if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resActivity.ResponseStatus.ResponseCode)) { response.StatusResponse.ErrorCode = Constants.ActivityResponse.Success; } if (Constants.ActivityResponse.Success.Equals(response.StatusResponse.ErrorCode)) { if (resActivity.InquiryActivityDataList != null) { response.ActivityDataItems = resActivity.InquiryActivityDataList .Select(ac => new ActivityDataItem { ActivityDateTime = ac.ActivityDateTime, ActivityID = ac.ActivityID, ActivityTypeID = ac.ActivityTypeID, ActivityTypeName = ac.ActivityTypeName, AreaID = ac.AreaID, AreaName = ac.AreaName, CISID = ac.CISID, CampaignID = ac.CampaignID, CampaignName = ac.CampaignName, ChannelID = ac.ChannelID, ChannelName = ac.ChannelName, ContractID = ac.ContractID, TypeID = ac.TypeID, TypeName = ac.TypeName, TicketID = ac.TicketID, ProductID = ac.ProductID, ProductName = ac.ProductName, ProductGroupID = ac.ProductGroupID, ProductGroupName = ac.ProductGroupName, SrID = ac.SrID, SubAreaID = ac.SubAreaID, SubAreaName = ac.SubAreaName, Status = ac.Status, SubStatus = ac.SubStatus, SubscriptionTypeName = ac.SubscriptionTypeName, SubscriptionID = ac.SubscriptonID, CustomerInfo = new CustomerInfo { SubscriptionType = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 1)), SubscriptionID = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 2)), FullName = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 3)) }, ContractInfo = new ContractInfo { AccountNo = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 1)), CreateSystem = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 2)), RegistrationNo = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 3)), FullName = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 11)) + " " + GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 12)), }, ActivityInfo = new ActivityInfo { CreatorBranch = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 10)), CreatorSR = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 11)), OwnerBranch = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 12)), OwnerSR = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 13)), DelegateBranch = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 14)), DelegateSR = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 15)), SendEmail = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 16)), EmailTo = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 17)), EmailCc = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 18)), EmailSubject = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 19)), EmailBody = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 20)), EmailAttachments = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 21)), ActivityDescription = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 22)), ActivityType = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 23)), SRStatus = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 24)), }, OfficerInfo = new OfficerInfo { FullName = GetDataItemValue(ac.OfficerInfoList.FirstOrDefault(x => x.SeqNo == 1)) }, ProductInfo = new ProductInfo { ProductGroup = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 1)), Product = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 2)), Campaign = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 3)) } }) .OrderByDescending(x => x.SrID) .ThenByDescending(x => x.ActivityDateTime) .ToList(); } AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(response); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CAR, Constants.ServiceName.InquiryActivityLog, response.StatusResponse.ErrorCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.CAR, Constants.ServiceName.InquiryActivityLog, response.StatusResponse.ErrorCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
private Ticket SearchLead(AuditLogEntity auditLog, string cardNo) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--COCService.SearchLead--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.SearchLead); COC.ServiceRequest reqLead = new COC.ServiceRequest(); reqLead.RequestHeader = new COC.Header { ChannelID = profile.channel_id, Username = profile.user_name, Password = profile.password, System = profile.system_code }; DataSet ds = ReadSearchLeadXml(); DataTable dt = ds.Tables[0]; dt.Rows[0]["cid"] = cardNo; dt.Rows[0]["firstname"] = ""; dt.Rows[0]["lastname"] = ""; dt.Rows[0]["status"] = ""; dt.Rows[0]["productGroupId"] = ""; dt.Rows[0]["productId"] = ""; dt.Rows[0]["maxRecord"] = "30"; reqLead.RequestXml = ds.ToXml(); COC.ServiceResponse resLead = null; #region "Call Service" string flgCatchErrorCode = string.Empty; // Avoid error codes _commonFacade = new CommonFacade(); List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.COC, Constants.ServiceName.SearchLead); try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqLead.SerializeObject()); using (var client = new COC.ServiceClient()) { resLead = ((COC.IService)client).SearchLead(reqLead); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resLead != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resLead.SerializeObject()); var xdoc = XDocument.Parse(resLead.ResponseXml); Ticket ticket = (xdoc.Descendants("ticket") .Select(x => new Ticket { TicketId = x.Attribute("id").Value, ResponseCode = x.Element("responseCode").Value, ResponseMessage = x.Element("responseMessage").Value, StrResponseDate = x.Element("responseDate").Value, StrResponseTime = x.Element("responseTime").Value, TotalLeads = x.Element("totalLeads") == null ? string.Empty : x.Element("totalLeads").Value })).FirstOrDefault(); if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(ticket.ResponseCode)) { ticket.ResponseCode = Constants.TicketResponse.COC_Success; } if (Constants.TicketResponse.COC_Success.Equals(ticket.ResponseCode)) { List <TicketItem> items = null; if (xdoc.Descendants("result") != null && xdoc.Descendants("result").Count() > 0) { items = xdoc.Descendants("result") .Select(x => new TicketItem { TicketId = x.Element("ticketId").Value, CardNo = x.Element("cid").Value, FirstName = x.Element("firstname").Value, LastName = x.Element("lastname").Value, TelNo1 = x.Element("telNo1").Value, Status = x.Element("status").Value, StatusDesc = x.Element("statusDesc").Value, CampaignCode = x.Element("campaign").Value, CampaignDesc = x.Element("campaignDesc").Value, ProductGroupId = x.Element("productGroupId").Value, ProductGroupDesc = x.Element("productGroupDesc").Value, ProductId = x.Element("productId").Value, ProductDesc = x.Element("productDesc").Value, ChannelId = x.Element("channelId").Value, OwnerLead = x.Element("ownerLead").Value, OwnerLeadName = x.Element("ownerLeadName").Value, DelegateLead = x.Element("delegateLead").Value, DelegateLeadName = x.Element("delegateLeadName").Value, CreatedUser = x.Element("createdUser").Value, CreatedUserName = x.Element("createdUserName").Value, StrCreatedDate = x.Element("createdDate").Value, StrCreatedTime = x.Element("createdTime").Value, StrAssignedDate = x.Element("assignedDate").Value, StrAssignedTime = x.Element("assignedTime").Value, OwnerBranch = x.Element("ownerBranch").Value, OwnerBranchName = x.Element("ownerBranchName").Value, DelegateBranch = x.Element("delegateBranch").Value, DelegateBranchName = x.Element("delegateBranchName").Value, CreatedBranch = x.Element("createdBranch").Value, CreatedBranchName = x.Element("createdBranchName").Value }).ToList(); } ticket.Items = items; AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(ticket); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.COC, Constants.ServiceName.SearchLead, ticket.ResponseCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.COC, Constants.ServiceName.SearchLead, ticket.ResponseCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
private RecommendCampaignResponse GetCampaignByCustomer(AuditLogEntity auditLog, string cardNo, string hasOffered, string isInterested, string customerFlag, int campaignNum) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--CmtService.CampaignByCustomer--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer); CMT.Header2 header = new CMT.Header2 { password = profile.password, reference_no = profile.reference_no, service_name = profile.service_name, system_code = profile.system_code, transaction_date = profile.transaction_date, user_name = profile.user_name }; CMT.CampaignByCustomersRequest reqCamp = new CMT.CampaignByCustomersRequest { header = header, CampByCitizenIdBody = new CMT.ReqCampByCusEntity { CitizenId = cardNo, HasOffered = hasOffered, IsInterested = isInterested, CustomerFlag = customerFlag, Command = profile.command, RequestDate = DateTime.Now.FormatDateTime("yyyyMMdd"), Channel = profile.channel_id, CampaignNum = campaignNum, ProductTypeId = "0,2" } }; CMT.CampaignByCustomersResponse resCamp = null; #region "Call Service" string flgCatchErrorCode = string.Empty; // Avoid error codes _commonFacade = new CommonFacade(); List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer); try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject()); using (var client = new CMT.CmtServiceClient()) { resCamp = ((CMT.ICmtService)client).CampaignByCustomers(reqCamp); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resCamp != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resCamp.SerializeObject()); RecommendCampaignResponse response = new RecommendCampaignResponse(); response.StatusResponse.Status = resCamp.status.status; response.StatusResponse.ErrorCode = resCamp.status.error_code; response.StatusResponse.Description = resCamp.status.description; if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resCamp.status.error_code)) { response.StatusResponse.Status = Constants.StatusResponse.Success; } if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status)) { if (resCamp.detail != null) { response.CitizenId = resCamp.detail.CitizenId; if (resCamp.detail.CitizenIds != null && resCamp.detail.CitizenIds.Count() > 0) { var results = resCamp.detail.CitizenIds.Where(x => x != null).Select(x => new CampaignDetail { CampaignCriteria = x.CampaignCreiteria, CampaignDesc = x.CampaignDescription, CampaignId = x.CampaignId, CampaignName = x.CampaignName, CampaignOffer = x.CampaignOffer, CampaignScore = x.CampaignScore, Channel = x.Channel, CitizenIds = x.CitizenIds, DescCust = x.DescCust, StrExpireDate = x.ExpireDate, IsInterested = x.IsInterested, ContractNoRefer = x.ContractNo, ProductTypeId = x.ProductTypeId, ProductTypeName = x.ProductTypeName }); response.RecommendCampaignDetails = results.OrderBy(x => x.ExpireDate).ToList(); } } AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(response); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer, response.StatusResponse.ErrorCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer, response.StatusResponse.ErrorCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }