Пример #1
0
        /**
         * Create Program Details Broadcast.
         * XML Message sent to the Hub broadcasting the details of the new cannabis licence issued.
         * The purpose is to broadcast licence details to partners subscribed to the Hub
         */
        public string CreateXML(MicrosoftDynamicsCRMadoxioLicences licence, OneStopHubStatusChange statusChange)
        {
            if (licence == null)
            {
                throw new Exception("The licence can not be null");
            }

            if (licence.AdoxioLicencee == null)
            {
                throw new Exception("The licence must have an AdoxioLicencee");
            }

            if (licence.AdoxioBusinessprogramaccountreferencenumber == null)
            {
                // set to 1 and handle errors as encountered.
                licence.AdoxioBusinessprogramaccountreferencenumber = "1";
            }
            var sbnChangeStatus = new SBNChangeStatus();

            sbnChangeStatus.header = GetHeader(licence);
            sbnChangeStatus.body   = GetBody(licence, statusChange);

            var serializer = new XmlSerializer(typeof(SBNChangeStatus));

            using (StringWriter textWriter = new StringWriter())
            {
                serializer.Serialize(textWriter, sbnChangeStatus);
                return(textWriter.ToString());
            }
        }
 public IActionResult SendChangeStatusMessage(string licenceGuid, OneStopHubStatusChange statusChange)
 {
     _logger.Information($"Reached SendChangeStatusMessage. licenceGuid: {licenceGuid}");
     BackgroundJob.Enqueue(() => new OneStopUtils(Configuration, _cache).SendChangeStatusRest(null, licenceGuid, statusChange, null));
     return(Ok());
 }
Пример #3
0
        private SBNChangeStatusBody GetBody(MicrosoftDynamicsCRMadoxioLicences licence, OneStopHubStatusChange statusChange)
        {
            var body = new SBNChangeStatusBody();

            // licence number
            body.partnerInfo1 = licence.AdoxioLicencenumber;

            body.statusData = new SBNChangeStatusBodyStatusData();


            body.statusData.businessRegistrationNumber = licence.AdoxioLicencee.Accountnumber;
            body.statusData.businessProgramIdentifier  = OneStopUtils.BUSINESS_PROGRAM_IDENTIFIER;

            body.statusData.businessProgramAccountReferenceNumber = licence.AdoxioBusinessprogramaccountreferencenumber;
            // programAccountStatus
            body.statusData.programAccountStatus = GetProgramAccountStatus(licence, statusChange);

            // partnerInfo1
            body.partnerInfo1 = licence.AdoxioLicencenumber;

            // partnerInfo2 - date
            if (licence.AdoxioExpirydate != null)
            {
                body.partnerInfo2 = licence.AdoxioExpirydate.Value.DateTime; // may need to be ("yyyy-MM-dd");
            }


            body.statusData.timeStamp = Utils.GetTimeStamp();

            return(body);
        }
Пример #4
0
        private SBNChangeStatusBodyStatusDataProgramAccountStatus GetProgramAccountStatus(MicrosoftDynamicsCRMadoxioLicences licence, OneStopHubStatusChange statusChange)
        {
            var programAccountStatus = new SBNChangeStatusBodyStatusDataProgramAccountStatus();

            switch (statusChange)
            {
            case OneStopHubStatusChange.Cancelled:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_CLOSED;     // 02
                programAccountStatus.programAccountReasonCode = "111";
                break;

            case OneStopHubStatusChange.CancellationRemoved:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_ACTIVE;
                programAccountStatus.programAccountReasonCode = null;
                break;

            case OneStopHubStatusChange.Expired:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_CLOSED;
                programAccountStatus.programAccountReasonCode = "112";
                break;

            case OneStopHubStatusChange.Renewed:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_ACTIVE;
                programAccountStatus.programAccountReasonCode = null;
                break;

            case OneStopHubStatusChange.Suspended:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_SUSPENDED;
                programAccountStatus.programAccountReasonCode = "114";
                break;

            case OneStopHubStatusChange.SuspensionEnded:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_ACTIVE;
                programAccountStatus.programAccountReasonCode = null;
                // programAccountReasonCode = null
                break;

            case OneStopHubStatusChange.TransferComplete:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_CLOSED;
                programAccountStatus.programAccountReasonCode = "113";
                break;

            case OneStopHubStatusChange.EnteredDormancy:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_SUSPENDED;
                programAccountStatus.programAccountReasonCode = "115";

                break;

            case OneStopHubStatusChange.DormancyEnded:
                programAccountStatus.programAccountStatusCode = OneStopUtils.PROGRAM_ACCOUNT_STATUS_CODE_ACTIVE;
                programAccountStatus.programAccountReasonCode = null;
                break;
            }

            //effective date of the licence (the date licence is issued or a future date if the licensee specifies a date they want the licence to start
            programAccountStatus.effectiveDate = DateTime.Now.AddHours(-8); //ToGetFromDynamics. Current date time for test purposes, adjusted for Pacific time.

            return(programAccountStatus);
        }
Пример #5
0
        /// <summary>
        /// Hangfire job to send Change Status message to One stop.
        /// </summary>
        public async Task SendChangeStatusRest(PerformContext hangfireContext, string licenceGuidRaw, OneStopHubStatusChange statusChange, string queueItemId)
        {
            IDynamicsClient dynamicsClient = DynamicsSetupUtil.SetupDynamics(_configuration);

            if (hangfireContext != null)
            {
                hangfireContext.WriteLine("Starting OneStop REST ChangeStatus Job.");
            }

            string licenceGuid = Utils.ParseGuid(licenceGuidRaw);

            //prepare soap content
            var req     = new ChangeStatus();
            var licence = dynamicsClient.GetLicenceByIdWithChildren(licenceGuid);

            if (hangfireContext != null && licence != null)
            {
                hangfireContext.WriteLine($"Got Licence {licenceGuid}.");
            }

            if (licence == null)
            {
                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine($"Unable to get licence {licenceGuid}.");
                }

                if (Log.Logger != null)
                {
                    Log.Logger.Error($"Unable to get licence {licenceGuid}.");
                }
            }
            else
            {
                var innerXML = req.CreateXML(licence, statusChange);

                if (Log.Logger != null)
                {
                    Log.Logger.Information(innerXML);
                }

                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine(innerXML);
                }

                //send message to Onestop hub
                var outputXML = await _onestopRestClient.ReceiveFromPartner(innerXML);

                UpdateQueueItemForSend(dynamicsClient, hangfireContext, queueItemId, innerXML, outputXML);

                if (hangfireContext != null)
                {
                    hangfireContext.WriteLine(outputXML);
                    hangfireContext.WriteLine("End of OneStop REST ProgramAccountDetailsBroadcast  Job.");
                }
            }
        }
Пример #6
0
        private SBNChangeStatusBody GetBody(MicrosoftDynamicsCRMadoxioLicences licence, OneStopHubStatusChange statusChange)
        {
            var body = new SBNChangeStatusBody();

            // licence number
            body.partnerInfo1 = licence.AdoxioLicencenumber;

            body.statusData = new SBNChangeStatusBodyStatusData();


            body.statusData.businessRegistrationNumber = licence.AdoxioLicencee.AdoxioBusinessregistrationnumber;
            body.statusData.businessProgramIdentifier  = OneStopUtils.BUSINESS_PROGRAM_IDENTIFIER;

            body.statusData.businessProgramAccountReferenceNumber = licence.AdoxioBusinessprogramaccountreferencenumber;
            // programAccountStatus
            body.statusData.programAccountStatus = GetProgramAccountStatus(licence, statusChange);

            // partnerInfo1
            body.partnerInfo1 = licence.AdoxioLicencenumber;

            // partnerInfo2 - date

            return(body);
        }