Beispiel #1
0
        private async Task <IEnumerable <IAzureUserAccountSubscriptionContext> > GetSubscriptionsFromCacheAsync(AzureUserAccount user)
        {
            var result = Enumerable.Empty <IAzureUserAccountSubscriptionContext>();

            if (user != null)
            {
                result = _subscriptionCache.Get(user.UniqueId);
                if (result == null)
                {
                    result = await GetSubscriptionFromServiceAsync(user);

                    _subscriptionCache.UpdateCache(user.UniqueId, result);
                }
            }
            result = result ?? Enumerable.Empty <IAzureUserAccountSubscriptionContext>();
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a  list of Azure sql databases for given subscription
        /// </summary>
        private async Task <ServiceResponse <DatabaseInstanceInfo> > GetDatabaseForSubscriptionAsync(object notRequired,
                                                                                                     IAzureUserAccountSubscriptionContext input, string serverName,
                                                                                                     CancellationToken cancellationToken, CancellationToken internalCancellationToken)
        {
            ServiceResponse <DatabaseInstanceInfo> result = null;
            bool shouldFilter = !string.IsNullOrEmpty(serverName);

            try
            {
                string key = input.Subscription.SubscriptionId;

                //when the data was coming from cache and no async mthod was called the parallel tasks running crashed so I had to call this line async to fix it
                result = await GetFromCacheAsync(key);

                if (result == null)
                {
                    //this will only get the databases for the given server name
                    result = await GetDatabaseForSubscriptionFromServiceAsync(input, serverName, cancellationToken, internalCancellationToken);
                }
                else if (shouldFilter)
                {
                    //we should filter the result because the cached data includes databases for all servers
                    result = new ServiceResponse <DatabaseInstanceInfo>(result.Data.Where(x => x.ServerInstanceInfo.FullyQualifiedDomainName == serverName),
                                                                        result.Errors);
                }

                //only update the cache if server name is not passes so the result is not filtered. The cache data supposed to be the data for all server
                if (!shouldFilter && !cancellationToken.IsCancellationRequested)
                {
                    result = _cache.UpdateCache(key, result);
                }
            }
            catch (Exception ex)
            {
                result = new ServiceResponse <DatabaseInstanceInfo>(ex);
            }

            return(result);
        }