コード例 #1
0
        public CloudServiceOutput GetAllResourcesInCloudService(string subscriptionId, string cloudServiceName)
        {
            if (String.IsNullOrEmpty(cloudServiceName) || String.IsNullOrEmpty(cloudServiceName))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            IEnumerable<ResourceEntity> allResources = WebApiApplication.Storage.ResourceStorage.GetResources(subscriptionId, cloudServiceName);

            // Create the cloud service output
            CloudServiceOutput cloudServiceOutput = new CloudServiceOutput()
            {
                 GeoRegion = String.Empty,
                 Resources = new ResourceOutputCollection()
            };

            // Insert all resources
            foreach (ResourceEntity resourceEntity in allResources)
            {
                // Not great to reach out to another controller
                cloudServiceOutput.Resources.Add(ResourcesController.ResourceOutputFromResourceEntity(resourceEntity));
            }

            // Geo Region - we do nto save cloud services by themselves so deduce the region
            if (cloudServiceOutput.Resources.Count > 0)
            {
                cloudServiceOutput.GeoRegion = cloudServiceOutput.Resources[0].CloudServiceSettings.GeoRegion;
            }

            return cloudServiceOutput;

            //return DataModel.GetCloudServiceBySubscriptionIdAndName(subscriptionId, cloudServiceName);
        }
コード例 #2
0
        //----------------------------- Cloud Service Management -----------------------------
        public static CloudServiceOutput GetCloudServiceBySubscriptionIdAndName(string subscriptionId, string cloudServiceName)
        {
            lock (theMassiveLock)
            {
                Subscription subscription;
                if (!allSubscriptions.TryGetValue(subscriptionId, out subscription))
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                CloudService theMatchingCloudService = subscription.CloudServices.SingleOrDefault<CloudService>(cs => String.CompareOrdinal(cs.Name, cloudServiceName) == 0);

                if (theMatchingCloudService == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                CloudServiceOutput cloudServiceOutput = new CloudServiceOutput()
                {
                    GeoRegion = theMatchingCloudService.Resources.Count > 0 ? theMatchingCloudService.Resources[0].CloudServiceSettings.GeoRegion : String.Empty,
                    Resources = new ResourceOutputCollection(theMatchingCloudService.Resources)
                };

                return cloudServiceOutput;
            }
        }