コード例 #1
0
ファイル: FulfillmentManager.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Get subscription information for the given subscription
        /// </summary>
        /// <param name="subscriptionId">The subscription id</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <MarketplaceSubscription> GetSubscriptionAsync(
            Guid subscriptionId,
            CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation(
                    LoggingUtils.ComposeHttpClientLogMessage(
                        _fulfillmentClient.GetType().Name,
                        nameof(_fulfillmentClient.GetSubscriptionAsync),
                        subscriptionId));

                Guid requestId     = Guid.NewGuid();
                Guid correlationId = Guid.NewGuid();

                var subscription = await _fulfillmentClient.GetSubscriptionAsync(
                    subscriptionId, requestId, correlationId, cancellationToken);

                return(MarketplaceSubscription.From(subscription));
            }
            catch (Exception e)
            {
                var errorMessage = $"Cannot get subscription {subscriptionId} from Azure Marketplace.";
                throw new LunaFulfillmentException(errorMessage, e);
            }
        }
コード例 #2
0
        public async Task <Subscription> UpdateOperationCompletedAsync(Guid subscriptionId, string activatedBy = "system")
        {
            Subscription subscription = await _context.Subscriptions.FindAsync(subscriptionId);

            ValidateSubscriptionAndInputState(subscription);

            try
            {
                Offer offer = await FindOfferById(subscription.OfferId);

                if (subscription.ProvisioningType.Equals(nameof(ProvisioningType.Unsubscribe)))
                {
                    var sub = await _fulfillmentClient.GetSubscriptionAsync(subscriptionId, Guid.NewGuid(), Guid.NewGuid());

                    subscription.TermEndTime = sub.Term.EndDate;
                }

                if (subscription.ProvisioningStatus.Equals(ProvisioningState.NotificationPending.ToString(), StringComparison.InvariantCultureIgnoreCase) &&
                    offer.ManualCompleteOperation)
                {
                    _logger.LogInformation($"ManualCompleteOperation of offer {offer.OfferName} is set to true. Will not complete the operation automatically.");

                    return(await TransitToNextState(subscription, ProvisioningState.ManualCompleteOperationPending));
                }

                // Don't need to update marketplace operation for delete data
                // 02-15-2021: Marketplace behavior change: Don't need to update marketplace operation for unsubscribe
                if (!subscription.ProvisioningType.Equals(nameof(ProvisioningType.DeleteData)) &&
                    !subscription.ProvisioningType.Equals(nameof(ProvisioningType.Unsubscribe)))
                {
                    Plan plan = await FindPlanById(subscription.PlanId);

                    OperationUpdate update = new OperationUpdate
                    {
                        PlanId   = plan.PlanName,
                        Quantity = subscription.Quantity,
                        Status   = OperationUpdateStatusEnum.Success
                    };

                    _logger.LogInformation(
                        LoggingUtils.ComposeHttpClientLogMessage(
                            _fulfillmentClient.GetType().Name,
                            nameof(_fulfillmentClient.UpdateSubscriptionOperationAsync),
                            subscriptionId));

                    var result = await _fulfillmentClient.UpdateSubscriptionOperationAsync(
                        subscriptionId,
                        subscription.OperationId ?? Guid.Empty,
                        update,
                        Guid.NewGuid(),
                        Guid.NewGuid(),
                        default);
                }

                switch (subscription.ProvisioningType)
                {
                case nameof(ProvisioningType.Update):
                case nameof(ProvisioningType.Reinstate):
                    subscription.Status = nameof(FulfillmentState.Subscribed);
                    break;

                case nameof(ProvisioningType.DeleteData):
                    subscription.Status = nameof(FulfillmentState.Purged);
                    break;

                case nameof(ProvisioningType.Suspend):
                    subscription.LastSuspendedTime = DateTime.UtcNow;
                    subscription.Status            = nameof(FulfillmentState.Suspended);
                    break;

                case nameof(ProvisioningType.Unsubscribe):
                    subscription.UnsubscribedTime = DateTime.UtcNow;
                    subscription.Status           = nameof(FulfillmentState.Unsubscribed);
                    break;

                default:
                    throw new ArgumentException($"Provisioning type {subscription.ProvisioningType} is not supported.");
                }
                subscription.ActivatedBy = activatedBy;
                return(await TransitToNextState(subscription, ProvisioningState.Succeeded));
            }
            catch (Exception e)
            {
                return(await HandleExceptions(subscription, e));
            }
        }