Exemple #1
0
        public static async Task <ResponseMessage> Process2(RequestRawMessageModel requestRawMessageModel)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            responseMessage.Error = "";

            await DataBaseFunctions.InsertDBRunningLog2("Process2: New RawMessage " + requestRawMessageModel.REQUEST_MESSAGE);

            return(responseMessage);
        }
 public static string ValidateRequest(string RequestJSON)
 {
     try
     {
         RequestRawMessageModel cfxRequest = JsonConvert.DeserializeObject <RequestRawMessageModel>(RequestJSON);
         return(StaticClasses.StaticVars.SUCCESS);
     }
     catch (Exception ex)
     {
         return(ex.Message.ToString());
     }
 }
        public static async Task Run([EventHubTrigger("MyAzureFunctionCallSP", Connection = "AzureEventHubConnectionString")] EventData[] events, ILogger log)
        {
            var exceptions = new List <Exception>();

            /////////////////////Loop thru messages as is//////////////////////////////////////////////////
            foreach (EventData eventData in events)
            {
                var MainMessage = string.Empty;

                try
                {
                    string ErrorsInObject = string.Empty;

                    //Get the message from event hub/////////////////////////////
                    string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
                    MainMessage = messageBody;

                    /////Temp Logging log to DB as is:
                    await DataBaseFunctions.InsertDBSTRIIMMessages(log, messageBody);

                    //JSON message object collection schema
                    List <RootObject> rootObjectCollection = new List <RootObject>();

                    // Deserilize to object collection.
                    rootObjectCollection = ConvertMessageToObject(messageBody, ref ErrorsInObject);

                    if (rootObjectCollection != null)
                    {
                        foreach (RootObject rootObject in rootObjectCollection)
                        {
                            // Start the logging collection for every loop as the the logging happens in TPMessageLog
                            ErrorResponseMessages errorResponseMessage = new ErrorResponseMessages();

                            // serilize the object
                            string JsonString = JsonConvert.SerializeObject(rootObject.data, Formatting.None);

                            ////////////////////////////Alter input message: This is from ProcessTest Test data ////////////////////////////
                            ///////////////THere is a reason to do this, this is helps in proper logging.
                            ///For now this is hardcoded for a specific tagnumber. For message type 1
                            RequestRawMessageModel requestRawMessageModel = JsonConvert.DeserializeObject <RequestRawMessageModel>(JsonString);
                            RequestMessageModel    requestMessageModel    = JsonConvert.DeserializeObject <RequestMessageModel>(requestRawMessageModel.REQUEST_MESSAGE);
                            requestMessageModel.TagNumber          = "015015018";
                            requestRawMessageModel.RequestMesssage = requestMessageModel;
                            string ConvertMessage = JsonConvert.SerializeObject(requestRawMessageModel, Formatting.None);
                            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                            // This does not mean there is error, error object is same as logging.
                            errorResponseMessage.RequestMessage = JsonString;

                            if (ConvertMessage.Length > 0)
                            {
                                // Validate the message
                                string ValidateMessage = StaticClasses.Validate.ValidateRequest(ConvertMessage);

                                if (ValidateMessage == StaticClasses.StaticVars.SUCCESS)
                                {
                                    errorResponseMessage.MessageValidation = "True";

                                    //ALL MAIN PROCESS HAPPENS HERE///////////////////////////////////////////////////////////
                                    ResponseMessage ResponseJSON = await TranscoreProcess.Process(requestRawMessageModel);///

                                    ////////////////////////////////////////////////////////////////////////////////////////

                                    errorResponseMessage.ResponseMessage = ResponseJSON.JSONMessage;

                                    if (ResponseJSON.Error.Length > 0)
                                    {
                                        errorResponseMessage.MessageProcessStatus = false;
                                        errorResponseMessage.ErrorResponseMessage = errorResponseMessage.ErrorResponseMessage + " | " + ResponseJSON.Error;
                                    }
                                    else
                                    {
                                        //SEND TO RABBITMQ
                                        SendToQueue(ResponseJSON.JSONMessage, errorResponseMessage);
                                    }
                                }
                                else
                                {
                                    errorResponseMessage.MessageValidation = "False";
                                    log.LogInformation($"Invalid Message");
                                }
                            }
                            else
                            {
                                log.LogInformation($"Message Length is ZERO: {ConvertMessage}");
                            }

                            string jsonMessageError = JsonConvert.SerializeObject(errorResponseMessage, Formatting.None);

                            await DataBaseFunctions.InsertDB(requestRawMessageModel.CRM_REQUEST_ID, requestRawMessageModel.REQUEST_TYPE, jsonMessageError, errorResponseMessage.ResponseMessage, errorResponseMessage.RequestMessage, errorResponseMessage.ErrorResponseMessage);
                        }

                        // await InsertDB(log,0,jsonMessageError, "Success", "OutMessage");
                        log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
                        await Task.Yield();
                    }
                    else
                    {
                    }
                }
                catch (Exception e)
                {
                    await DataBaseFunctions.InsertDB(9999, 0, MainMessage, "", "", "Invalid Message");

                    // We need to keep processing the rest of the batch - capture this exception and continue.
                    // Also, consider capturing details of the message that failed processing so it can be processed again later.
                    exceptions.Add(e);
                }
            }

            // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.

            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }
Exemple #4
0
        public static async Task <ResponseMessage> Process(RequestRawMessageModel cfxRequest)
        {
            ResponseMessage rm = new ResponseMessage();

            try
            {
                TempController tempController = new TempController();
                string         ResponseJSON   = string.Empty;;

                CFXAccountResponse cfxAccountResponse;

                switch (cfxRequest.REQUEST_TYPE)
                {
                //One
                case StaticRequestType.TagLookupSimple:

                    cfxAccountResponse = await tempController.GetAccountInfoGivenTagNumber(cfxRequest.RequestMesssage.TagNumber, cfxRequest.RequestMesssage.IssuingAuthority);

                    ResponseTypeOneModel responseTypeOneModel = new ResponseTypeOneModel();

                    responseTypeOneModel.RequestType = cfxRequest.REQUEST_TYPE;
                    responseTypeOneModel.RequestId   = cfxRequest.CRM_REQUEST_ID;
                    responseTypeOneModel.Requestor   = cfxRequest.REQUESTOR;
                    responseTypeOneModel.RequestDate = Validate.ConvertToDateTime(cfxRequest.REQUEST_DATE);

                    if (cfxAccountResponse.Errors.Length == 0)
                    {
                        responseTypeOneModel.ResponseCode         = "0";
                        responseTypeOneModel.ResponseMessage      = "";
                        responseTypeOneModel.AccountNumber        = cfxAccountResponse.AccountNumber;
                        responseTypeOneModel.AccountStatusCurrent = cfxAccountResponse.AccountStatus;
                        responseTypeOneModel.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                    }
                    else
                    {
                        responseTypeOneModel.ResponseCode    = "1";
                        responseTypeOneModel.ResponseMessage = "Account Not Found for TagNumber:" + cfxRequest.RequestMesssage.TagNumber;
                    }
                    ResponseJSON = JsonConvert.SerializeObject(responseTypeOneModel, Newtonsoft.Json.Formatting.None);

                    rm.JSONMessage = ResponseJSON;

                    break;

                case StaticRequestType.PlateLookupForVES:

                    cfxAccountResponse = await tempController.GetAccountInfoGivenPlateInfo(cfxRequest.RequestMesssage.LicensePlate, cfxRequest.RequestMesssage.LicenseState);

                    ResponseTypeTwoModel responseTypeTwoModel = new ResponseTypeTwoModel();

                    responseTypeTwoModel.RequestType = cfxRequest.REQUEST_TYPE;
                    responseTypeTwoModel.RequestId   = cfxRequest.CRM_REQUEST_ID;
                    responseTypeTwoModel.Requestor   = cfxRequest.REQUESTOR;
                    responseTypeTwoModel.RequestDate = cfxRequest.REQUEST_DATE;

                    if (cfxAccountResponse.Errors.Length == 0)
                    {
                        responseTypeTwoModel.ResponseCode         = "0";
                        responseTypeTwoModel.ResponseMessage      = "";
                        responseTypeTwoModel.AccountNumber        = cfxAccountResponse.AccountNumber;
                        responseTypeTwoModel.AccountStatusCurrent = cfxAccountResponse.AccountStatus;
                        responseTypeTwoModel.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;

                        responseTypeTwoModel.cfxEPASS.TagNumber            = cfxAccountResponse.TagNumber;
                        responseTypeTwoModel.cfxEPASS.IssuingAuthority     = cfxAccountResponse.IssuingAuthorityCode;
                        responseTypeTwoModel.cfxEPASS.AccountNumber        = cfxAccountResponse.AccountNumber;
                        responseTypeTwoModel.cfxEPASS.AccountStatusAtTrans = cfxAccountResponse.AccountStatus;
                        responseTypeTwoModel.cfxEPASS.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                        // responseTypeTwoModel.cfxEPASS. = cfxAccountResponse.RevNonRevType;

                        responseTypeTwoModel.cfxTRPP.TagNumber            = cfxAccountResponse.TagNumber;
                        responseTypeTwoModel.cfxTRPP.IssuingAuthority     = cfxAccountResponse.IssuingAuthorityCode;
                        responseTypeTwoModel.cfxTRPP.StateCode            = cfxAccountResponse.StateCode;
                        responseTypeTwoModel.cfxTRPP.AccountNumber        = cfxAccountResponse.AccountNumber;
                        responseTypeTwoModel.cfxTRPP.AccountStatusCurrent = cfxAccountResponse.AccountStatusAtTransaction;
                        responseTypeTwoModel.cfxTRPP.AccountStatusCurrent = cfxAccountResponse.AccountStatus;

                        responseTypeTwoModel.cfxPOCH.TagNumber        = cfxAccountResponse.TagNumber;
                        responseTypeTwoModel.cfxPOCH.IssuingAuthority = cfxAccountResponse.IssuingAuthority;
                        responseTypeTwoModel.cfxPOCH.StateCode        = cfxAccountResponse.StateCode;
                        responseTypeTwoModel.cfxPOCH.AccountNumber    = cfxAccountResponse.AccountNumber;

                        responseTypeTwoModel.cfxCHP.TagNumber            = cfxAccountResponse.TagNumber;
                        responseTypeTwoModel.cfxCHP.IssuingAuthority     = cfxAccountResponse.IssuingAuthority;
                        responseTypeTwoModel.cfxCHP.StateCode            = cfxAccountResponse.StateCode;
                        responseTypeTwoModel.cfxCHP.AccountNumber        = cfxAccountResponse.AccountNumber;
                        responseTypeTwoModel.cfxCHP.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                    }
                    else
                    {
                        responseTypeTwoModel.ResponseCode    = "2";
                        responseTypeTwoModel.ResponseMessage = "Account Not Found for TagNumber:" + cfxRequest.RequestMesssage.TagNumber;
                    }
                    ResponseJSON = JsonConvert.SerializeObject(responseTypeTwoModel, Newtonsoft.Json.Formatting.None);

                    rm.JSONMessage = ResponseJSON;


                    break;

                case StaticRequestType.Loop2Tagas:

                    cfxAccountResponse = await tempController.GetAccountInfoGivenTagNumber(cfxRequest.RequestMesssage.TagNumber, cfxRequest.RequestMesssage.IssuingAuthority);

                    ResponseTypeThreeModel requestTypeThreeModel = new ResponseTypeThreeModel();
                    requestTypeThreeModel.RequestType = cfxRequest.REQUEST_TYPE;
                    requestTypeThreeModel.RequestId   = cfxRequest.CRM_REQUEST_ID;
                    requestTypeThreeModel.Requestor   = cfxRequest.REQUESTOR;
                    requestTypeThreeModel.RequestDate = Validate.ConvertToDateTime(cfxRequest.REQUEST_DATE);

                    if (requestTypeThreeModel.Errors.Length == 0)
                    {
                        requestTypeThreeModel.ResponseCode         = "0";
                        requestTypeThreeModel.ResponseMessage      = "";
                        requestTypeThreeModel.AccountNumber        = cfxAccountResponse.AccountNumber;
                        requestTypeThreeModel.AccountStatusCurrent = cfxAccountResponse.AccountStatus;
                        requestTypeThreeModel.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                    }
                    else
                    {
                        requestTypeThreeModel.ResponseCode    = "1";
                        requestTypeThreeModel.ResponseMessage = "Account Not Found for TagNumber:" + cfxRequest.RequestMesssage.TagNumber;
                    }
                    ResponseJSON = JsonConvert.SerializeObject(requestTypeThreeModel, Newtonsoft.Json.Formatting.None);

                    rm.JSONMessage = ResponseJSON;



                    break;

                case StaticRequestType.Loop2Plates:

                    cfxAccountResponse = await tempController.GetAccountInfoGivenTagNumber(cfxRequest.RequestMesssage.TagNumber, cfxRequest.RequestMesssage.IssuingAuthority);

                    ResponseTypeFourModel requestTypeFourModel = new ResponseTypeFourModel();
                    requestTypeFourModel.RequestType = cfxRequest.REQUEST_TYPE;
                    requestTypeFourModel.RequestId   = cfxRequest.CRM_REQUEST_ID;
                    requestTypeFourModel.Requestor   = cfxRequest.REQUESTOR;
                    requestTypeFourModel.RequestDate = Validate.ConvertToDateTime(cfxRequest.REQUEST_DATE);

                    if (requestTypeFourModel.Errors.Length == 0)
                    {
                        requestTypeFourModel.ResponseCode         = "0";
                        requestTypeFourModel.ResponseMessage      = "";
                        requestTypeFourModel.AccountNumber        = cfxAccountResponse.AccountNumber;
                        requestTypeFourModel.AccountStatusCurrent = cfxAccountResponse.AccountStatus;
                        requestTypeFourModel.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                    }
                    else
                    {
                        requestTypeFourModel.ResponseCode    = "1";
                        requestTypeFourModel.ResponseMessage = "Account Not Found for TagNumber:" + cfxRequest.RequestMesssage.TagNumber;
                    }
                    ResponseJSON = JsonConvert.SerializeObject(requestTypeFourModel, Newtonsoft.Json.Formatting.None);

                    rm.JSONMessage = ResponseJSON;


                    break;

                case StaticRequestType.Rebates:

                    cfxAccountResponse = await tempController.GetAccountInfoGivenTagNumber(cfxRequest.RequestMesssage.TagNumber, cfxRequest.RequestMesssage.IssuingAuthority);

                    ResponseTypeFiveModel requestTypeFiveModel = new ResponseTypeFiveModel();
                    requestTypeFiveModel.RequestType = cfxRequest.REQUEST_TYPE;
                    requestTypeFiveModel.RequestId   = cfxRequest.CRM_REQUEST_ID;
                    requestTypeFiveModel.Requestor   = cfxRequest.REQUESTOR;
                    requestTypeFiveModel.RequestDate = Validate.ConvertToDateTime(cfxRequest.REQUEST_DATE);

                    if (requestTypeFiveModel.Errors.Length == 0)
                    {
                        requestTypeFiveModel.ResponseCode         = "0";
                        requestTypeFiveModel.ResponseMessage      = "";
                        requestTypeFiveModel.AccountNumber        = cfxAccountResponse.AccountNumber;
                        requestTypeFiveModel.AccountStatusCurrent = cfxAccountResponse.AccountStatus;
                        requestTypeFiveModel.AccountStatusAtTrans = cfxAccountResponse.AccountStatusAtTransaction;
                    }
                    else
                    {
                        requestTypeFiveModel.ResponseCode    = "1";
                        requestTypeFiveModel.ResponseMessage = "Account Not Found for TagNumber:" + cfxRequest.RequestMesssage.TagNumber;
                    }
                    ResponseJSON = JsonConvert.SerializeObject(requestTypeFiveModel, Newtonsoft.Json.Formatting.None);

                    rm.JSONMessage = ResponseJSON;


                    break;

                case StaticRequestType.TagStatus:
                    break;

                case StaticRequestType.MTOLLS:
                    break;

                default:

                    break;
                }
            }
            catch (Exception ex)
            {
                rm.Error = ex.Message.ToString();
            }



            return(rm);
        }