Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private UpdateCampaignFlagsResponse UpdateCampaignFlagsByCustomer(AuditLogEntity auditLog, string cardNo, CampaignSearchFilter searchFilter)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--CmtService.UpdateCustomerFlags--");

            try
            {
                Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer);

                var criteria = new CMT.UpdInquiry
                {
                    CampaignId   = searchFilter.CampaignId,
                    HasOffered   = searchFilter.HasOffered,
                    IsInterested = searchFilter.IsInterested,
                    UpdatedBy    = searchFilter.UpdatedBy,
                    Comments     = searchFilter.Comments,
                    Command      = profile.command
                };

                CMT.UpdateCustomerFlagsRequest reqCamp = new CMT.UpdateCustomerFlagsRequest
                {
                    header = new CMT.Header
                    {
                        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
                    },
                    UpdateCustFlag = new CMT.ReqUpdFlagEntity
                    {
                        CitizenId    = cardNo,
                        UpdInquiries = new CMT.UpdInquiry[] { criteria }
                    }
                };

                CMT.UpdateCustomerFlagsResponse resCamp = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject());
                        using (var client = new CMT.CmtServiceClient())
                        {
                            resCamp = ((CMT.ICmtService)client).UpdateCustomerFlags(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());

                    UpdateCampaignFlagsResponse response = new UpdateCampaignFlagsResponse();
                    response.StatusResponse.Status      = resCamp.status.status;
                    response.StatusResponse.ErrorCode   = resCamp.status.error_code;
                    response.StatusResponse.Description = resCamp.status.description;

                    if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status))
                    {
                        response.CitizenId = resCamp.detail.CitizenId;
                        if (resCamp.detail.Result != null)
                        {
                            response.UpdateStatus = resCamp.detail.Result.UpdateStatus;
                        }

                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);
                        return(response);
                    }

                    // Log DB
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags,
                                                                                 response.StatusResponse.ErrorCode, true));
                    throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags,
                                                                 response.StatusResponse.ErrorCode, false));
                }
            }
            finally
            {
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(null);
        }