コード例 #1
0
        /// <summary>
        /// Executes the WorkFlow.
        /// </summary>
        /// <param name="crmWorkflowContext">The <see cref="WorkFlowActivityBase.LocalWorkflowContext"/> which contains the
        /// <param name="executionContext" > <see cref="CodeActivityContext"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
        /// The WorkFlow's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the WorkFlow. Also, multiple system threads
        /// could execute the WorkFlow at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in WorkFlows.
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            var tracingService = executionContext.GetExtension <ITracingService>();

            tracingService.Trace("CreatePayment starting...");

            try
            {
                // 1. Validation
                ValidateNotNull(crmWorkflowContext);

                // 2. Prepare API Request
                tracingService.Trace("Calling PrepareCardPaymentRequest...");
                CreatePaymentRequest apiRequest = this.PrepareCardPaymentRequest(executionContext);

                // 2. Retrieve Configuration
                tracingService.Trace("Calling RetrieveCardPaymentServiceConfiguration...");
                RestServiceConfiguration cardServiceConfiguration = this.RetrieveCardPaymentServiceConfiguration(executionContext, ConfigurationPrefix.Get(executionContext));

                // 3. Set-up the Api Service
                tracingService.Trace("Instantiating CardPaymentService...");
                CardPaymentService cardPaymentService = new CardPaymentService(cardServiceConfiguration);

                // 4. Call the API
                tracingService.Trace("Calling GovPay CreatePayment with amount='{0}', description='{1}', reference='{2}', returnUrl='{3}'", apiRequest.amount, apiRequest.description, apiRequest.reference, apiRequest.return_url);
                CreatePaymentResponse apiResponse = cardPaymentService.CreatePayment(apiRequest);

                // TODO Log request and Response

                // 5. Return the response
                if (apiResponse != null && apiResponse.error_message != null)
                {
                    tracingService.Trace("Error message: {0}", apiResponse.error_message);
                }
                tracingService.Trace("Calling PrepareOutputParameters...");
                this.PrepareOutputParameters(executionContext, apiResponse, tracingService);
            }
            catch (Exception ex)
            {
                // Todo: Log the Error
                tracingService.Trace("Exception: " + ex);
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the WorkFlow.
        /// </summary>
        /// <param name="crmWorkflowContext">The <see cref="WorkFlowActivityBase.LocalWorkflowContext"/> which contains the
        /// <param name="executionContext" > <see cref="CodeActivityContext"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
        /// The WorkFlow's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the WorkFlow. Also, multiple system threads
        /// could execute the WorkFlow at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in WorkFlows.
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            var tracingService = executionContext.GetExtension <ITracingService>();

            tracingService.Trace("FindPayment starting...");

            try
            {
                // 1. Validation
                ValidateNotNull(crmWorkflowContext);

                // 2. Prepare API Request
                tracingService.Trace("Calling PrepareFindPaymentRequest...");
                FindPaymentRequest apiRequest = this.PrepareFindPaymentRequest(executionContext, crmWorkflowContext, tracingService);

                // 3. Retrieve Configuration
                tracingService.Trace("Calling RetrieveCardPaymentServiceConfiguration...");
                RestServiceConfiguration cardServiceConfiguration = this.RetrieveCardPaymentServiceConfiguration(executionContext, ConfigurationPrefix.Get(executionContext));

                // 4. Set-up the Api Service
                tracingService.Trace("Instantiating CardPaymentService...");
                CardPaymentService cardPaymentService = new CardPaymentService(cardServiceConfiguration);

                // 5. Call the API
                tracingService.Trace("Calling GovPay FindPayment...");
                FindPaymentResponse apiResponse = cardPaymentService.FindPayment(apiRequest);

                // 6. Return the response
                tracingService.Trace("Calling PrepareOutputParameters...");
                this.PrepareOutputParameters(executionContext, apiResponse, tracingService);
            }
            catch (Exception ex)
            {
                // Todo: Log the Error
                tracingService.Trace("Exception: " + ex);
                throw ex;
            }
        }