示例#1
0
        private string HandleSBNErrorNotification(string inputXML)
        {
            string result = "200";
            // deserialize the inputXML
            var serializer = new XmlSerializer(typeof(SBNErrorNotification1));
            SBNErrorNotification1 errorNotification;

            using (TextReader reader = new StringReader(inputXML))
            {
                errorNotification = (SBNErrorNotification1)serializer.Deserialize(reader);
            }


            // check to see if it is simply a problem with an old account number.
            if (errorNotification.body.validationErrors[0].errorMessageNumber.Equals("11845")) // Transaction not allowed - Duplicate Client event exists )
            {
                Log.Logger.Error($"CRA has rejected the message due to an incorrect business number.  The business in question may have had multiple business numbers in the past and the number in the record is no longer valid.  Please correct the business number for record with partnernote of {errorNotification.header.partnerNote}");
            }
            else if (errorNotification.body.validationErrors[0].errorMessageNumber.Equals("11409")) // Old account number.
            {
                Log.Logger.Information("Error is old account number is already associated with another account.  Retrying.");
                // retry the request with a higher increment.

                string licenceGuid   = OneStopUtils.GetGuidFromPartnerNote(errorNotification.header.partnerNote);
                int    currentSuffix = OneStopUtils.GetSuffixFromPartnerNote(errorNotification.header.partnerNote, Log.Logger);

                string cacheKey    = "_BPAR_" + licenceGuid;
                int    suffixLimit = 10;
                Log.Logger.Information($"Reading cache value for key {cacheKey}");

                _cache.TryGetValue(cacheKey, out suffixLimit);

                // sanity check
                if (currentSuffix < suffixLimit)
                {
                    currentSuffix++;
                    Log.Logger.Information($"Starting resend of licence creation message, with new value of {currentSuffix}");

                    var patchRecord = new MicrosoftDynamicsCRMadoxioLicences()
                    {
                        AdoxioBusinessprogramaccountreferencenumber = currentSuffix.ToString()
                    };
                    _dynamicsClient.Licenceses.Update(licenceGuid, patchRecord);

                    BackgroundJob.Schedule(() => new OneStopUtils(Configuration, _cache).SendLicenceCreationMessageREST(null, licenceGuid, currentSuffix.ToString("D3")) // zero pad 3 digit.
                                           , TimeSpan.FromSeconds(30));                                                                                                  // Try again after 30 seconds
                }
                else
                {
                    Log.Logger.Error($"Skipping resend of licence creation message as there have been too many tries({currentSuffix} - {suffixLimit}) Partner Note is partner note {errorNotification.header.partnerNote}");
                }
            }
            else
            {
                Log.Logger.Error($"Received error notification for record with partner note {errorNotification.header.partnerNote} Error Code is  {errorNotification.body.validationErrors[0].errorMessageNumber}. Error Text is {errorNotification.body.validationErrors[0].errorMessageText} {inputXML}");
            }

            return(result);
        }
示例#2
0
        private string HandleSBNErrorNotification(string inputXML)
        {
            string result = "200";
            // deserialize the inputXML
            var serializer = new XmlSerializer(typeof(SBNErrorNotification1));
            SBNErrorNotification1 errorNotification;

            using (TextReader reader = new StringReader(inputXML))
            {
                errorNotification = (SBNErrorNotification1)serializer.Deserialize(reader);
            }
            _logger.LogError("Received error notification");
            _logger.LogError(inputXML);

            // check to see if it is simply a problem with an old account number.
            if (errorNotification.body.validationErrors[0].errorMessageNumber.Equals("11845")) // Transaction not allowed - Duplicate Client event exists )
            {
                _logger.LogError("****************************************************");
                _logger.LogError("CRA has rejected the message due to an incorrect business number.  The business in question may have had multiple business numbers in the past and the number in the record is no longer valid.  Please correct the business number.");
                _logger.LogError("****************************************************");
            }
            else if (errorNotification.body.validationErrors[0].errorMessageNumber.Equals("11409")) // Old account number.
            {
                _logger.LogInformation("Error is old account number is already associated with another account.  Retrying.");
                // retry the request with a higher increment.

                string licenceGuid   = OneStopUtils.GetGuidFromPartnerNote(errorNotification.header.partnerNote);
                int    currentSuffix = OneStopUtils.GetSuffixFromPartnerNote(errorNotification.header.partnerNote, _logger);

                // sanity check
                if (currentSuffix < 10)
                {
                    currentSuffix++;
                    _logger.LogInformation($"Starting resend of licence creation message, with new value of {currentSuffix}");
                    BackgroundJob.Schedule(() => new OneStopUtils(Configuration, _logger).SendLicenceCreationMessageREST(null, licenceGuid, currentSuffix.ToString("D3")) // zero pad 3 digit.
                                           , TimeSpan.FromMinutes(1));                                                                                                    // Try again after 1 minutes.
                }
                else
                {
                    _logger.LogInformation($"Skipping resend of licence creation message as there have been too many tries({currentSuffix})");
                }
            }

            return(result);
        }
        private string HandleSBNErrorNotification(string inputXML)
        {
            string result = "200";
            // deserialize the inputXML
            var serializer = new XmlSerializer(typeof(SBNErrorNotification1));
            SBNErrorNotification1 errorNotification;

            using (TextReader reader = new StringReader(inputXML))
            {
                errorNotification = (SBNErrorNotification1)serializer.Deserialize(reader);
            }
            _logger.LogError("Received error notification");
            _logger.LogError(inputXML);

            // check to see if it is simply a problem with an old account number.

            if (errorNotification.body.validationErrors[0].errorMessageNumber.Equals("11409")) // Old account number.
            {
                _logger.LogInformation("Error is old account number is already associated with another account.");
                // retry the request with a higher increment.

                string licenceGuid   = OneStopUtils.GetGuidFromPartnerNote(errorNotification.header.partnerNote);
                int    currentSuffix = OneStopUtils.GetSuffixFromPartnerNote(errorNotification.header.partnerNote);

                // sanity check
                if (currentSuffix < 10)
                {
                    currentSuffix++;
                    _logger.LogInformation($"Starting resend of licence creation message, attempt {currentSuffix}");
                    BackgroundJob.Enqueue(() => new OneStopUtils(Configuration, _logger).SendLicenceCreationMessageREST(null, licenceGuid, currentSuffix.ToString()));
                }
                else
                {
                    _logger.LogInformation($"Skipping resend of licence creation message as there have been too many tries({currentSuffix})");
                }
            }

            return(result);
        }