예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerArgument"/> class
        /// with the specified values.
        /// </summary>
        /// <param name="flavorId">The ID of the flavor to use when creating new servers. See <see cref="Flavor.Id"/>.</param>
        /// <param name="imageId">The ID of the image to use when creating new servers. See <see cref="SimpleServerImage.Id"/>.</param>
        /// <param name="name">The prefix to use when assigning names to new servers.</param>
        /// <param name="diskConfiguration">The disk configuration to use for new servers.</param>
        /// <param name="networks">A collection of <see cref="ServerNetworkArgument"/> objects describing the networks to initially connect newly created servers to.</param>
        /// <param name="personality">A collection of <see cref="Personality"/> objects describing the personality for new server instances.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="flavorId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="imageId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="networks"/> contains any <see langword="null"/> values.
        /// <para>-or-</para>
        /// <para>If <paramref name="personality"/> contains any <see langword="null"/> values.</para>
        /// </exception>
        public ServerArgument(FlavorId flavorId, ImageId imageId, string name, DiskConfiguration diskConfiguration, IEnumerable<ServerNetworkArgument> networks, IEnumerable<Personality> personality)
        {
            if (flavorId == null)
                throw new ArgumentNullException("flavorId");
            if (imageId == null)
                throw new ArgumentNullException("imageId");

            _flavorId = flavorId;
            _imageId = imageId;
            _name = name;
            _diskConfiguration = diskConfiguration;

            if (networks != null)
            {
                _networks = networks.ToArray();
                if (_networks.Contains(null))
                    throw new ArgumentException("networks cannot contain any null values", "networks");
            }

            if (personality != null)
            {
                _personality = personality.ToArray();
                if (_personality.Contains(null))
                    throw new ArgumentException("personality cannot contain any null values", "personality");
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerArgument"/> class
        /// with the specified values.
        /// </summary>
        /// <param name="flavorId">The ID of the flavor to use when creating new servers. See <see cref="Flavor.Id"/>.</param>
        /// <param name="imageId">The ID of the image to use when creating new servers. See <see cref="SimpleServerImage.Id"/>.</param>
        /// <param name="name">The prefix to use when assigning names to new servers.</param>
        /// <param name="diskConfiguration">The disk configuration to use for new servers.</param>
        /// <param name="networks">A collection of <see cref="ServerNetworkArgument"/> objects describing the networks to initially connect newly created servers to.</param>
        /// <param name="personality">A collection of <see cref="Personality"/> objects describing the personality for new server instances.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="flavorId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="imageId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="networks"/> contains any <see langword="null"/> values.
        /// <para>-or-</para>
        /// <para>If <paramref name="personality"/> contains any <see langword="null"/> values.</para>
        /// </exception>
        public ServerArgument(FlavorId flavorId, ImageId imageId, string name, DiskConfiguration diskConfiguration, IEnumerable <ServerNetworkArgument> networks, IEnumerable <Personality> personality)
        {
            if (flavorId == null)
            {
                throw new ArgumentNullException("flavorId");
            }
            if (imageId == null)
            {
                throw new ArgumentNullException("imageId");
            }

            _flavorId          = flavorId;
            _imageId           = imageId;
            _name              = name;
            _diskConfiguration = diskConfiguration;

            if (networks != null)
            {
                _networks = networks.ToArray();
                if (_networks.Contains(null))
                {
                    throw new ArgumentException("networks cannot contain any null values", "networks");
                }
            }

            if (personality != null)
            {
                _personality = personality.ToArray();
                if (_personality.Contains(null))
                {
                    throw new ArgumentException("personality cannot contain any null values", "personality");
                }
            }
        }
예제 #3
0
 public ServiceData(string name, FlavorId flavorId, ImmutableArray<ServiceDomain> domains, ImmutableArray<ServiceOrigin> origins, ImmutableArray<ServiceCache> caching, ImmutableArray<ServiceRestriction> restrictions)
 {
     _name = name;
     _flavorId = flavorId;
     _domains = domains;
     _origins = origins;
     _caching = caching;
     _restrictions = restrictions;
 }
예제 #4
0
        public override int GetHashCode()
        {
            int hashCode = 1016347869;

            hashCode = hashCode * -1521134295 + Id.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Brand);

            hashCode = hashCode * -1521134295 + InitialAmount.GetHashCode();
            hashCode = hashCode * -1521134295 + ConsumedAmount.GetHashCode();
            hashCode = hashCode * -1521134295 + CurrentAmount.GetHashCode();
            hashCode = hashCode * -1521134295 + DeliveryDate.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <FlavorDto> .Default.GetHashCode(Flavor);

            hashCode = hashCode * -1521134295 + FlavorId.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <SupplementTypeDto> .Default.GetHashCode(SupplementType);

            hashCode = hashCode * -1521134295 + SupplementTypeId.GetHashCode();
            return(hashCode);
        }
        public static Task RemoveFlavorAsync(this IContentDeliveryService service, FlavorId flavorId, CancellationToken cancellationToken)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            return TaskBlocks.Using(
                () => service.PrepareRemoveFlavorAsync(flavorId, cancellationToken),
                task => task.Result.SendAsync(cancellationToken));
        }
        /// <summary>
        /// Get a database instance flavor by ID.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="flavorId">The flavor ID. This is obtained from <see cref="DatabaseFlavor.Id">DatabaseFlavor.Id</see></param>
        /// <returns>
        /// A <see cref="DatabaseFlavor"/> object describing the flavor.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="flavorId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/GET_getFlavorById__version___accountId__flavors__flavorId__.html">List Flavor By ID (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static DatabaseFlavor GetFlavor(this IDatabaseService service, FlavorId flavorId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetFlavorAsync(flavorId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        public async Task TestCreateService()
        {
            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource())
            {
                string domainName = "www.mywebsite.com";
                string ruleName = "mywebsite.com";
                string ruleUri = "www.mywebsite.com";
                string serviceOriginName = "example.com";
                string cacheRuleName = "default";
                string cacheRuleUri = "www.mywebsite.com";
                string restrictionRuleName = "mywebsite.com";
                string restrictionRuleReferrer = "www.mywebsite.com";
                string serviceRestrictionName = "website only";
                string serviceName = "testService";
                FlavorId flavorId = new FlavorId("cdn");


                cancellationTokenSource.CancelAfter(TestTimeout(TimeSpan.FromSeconds(10)));
                CancellationToken cancellationToken = cancellationTokenSource.Token;

                ServiceProtocol serviceProtocol = ServiceProtocol.Http;
                ServiceDomain sd = new ServiceDomain(domainName, serviceProtocol);
                ImmutableArray<ServiceDomain>.Builder sdbuilder = ImmutableArray.CreateBuilder<ServiceDomain>();
                sdbuilder.Add(sd);
                ImmutableArray<ServiceDomain> domains = sdbuilder.ToImmutable();

                ServiceOriginRule sor = new ServiceOriginRule(ruleName, ruleUri);
                ImmutableArray<ServiceOriginRule>.Builder sorbuilder = ImmutableArray.CreateBuilder<ServiceOriginRule>();
                sorbuilder.Add(sor);
                ImmutableArray<ServiceOriginRule> rules = sorbuilder.ToImmutable();


                ServiceOrigin so = new ServiceOrigin(serviceOriginName, 80, false, rules);
                ImmutableArray<ServiceOrigin>.Builder sobuilder = ImmutableArray.CreateBuilder<ServiceOrigin>();
                sobuilder.Add(so);
                ImmutableArray<ServiceOrigin> origins = sobuilder.ToImmutable();

            
                ServiceCacheRule scr = new ServiceCacheRule(cacheRuleName, cacheRuleUri);
                ImmutableArray<ServiceCacheRule>.Builder scrbuilder = ImmutableArray.CreateBuilder<ServiceCacheRule>();
                scrbuilder.Add(scr);
                ImmutableArray<ServiceCacheRule> scrules = scrbuilder.ToImmutable();


                ImmutableArray<ServiceCache>.Builder scbuilder = ImmutableArray.CreateBuilder<ServiceCache>();
                ServiceCache sc = new ServiceCache(cacheRuleName, new TimeSpan(0, 0, 3600), scrules);
                scbuilder.Add(sc);
                ImmutableArray<ServiceCache> caching = scbuilder.ToImmutable();
                caching = new ImmutableArray<ServiceCache>();



                ImmutableArray<ServiceRestrictionRule>.Builder srrbuilder = ImmutableArray.CreateBuilder<ServiceRestrictionRule>();
                ServiceRestrictionRule srr = new ServiceRestrictionRule(restrictionRuleName, restrictionRuleReferrer);
                srrbuilder.Add(srr);
                ImmutableArray<ServiceRestrictionRule> srrules = srrbuilder.ToImmutable();
                srrules = new ImmutableArray<ServiceRestrictionRule>();



                ImmutableArray<ServiceRestriction>.Builder rbuilder = ImmutableArray.CreateBuilder<ServiceRestriction>();
                ServiceRestriction sr = new ServiceRestriction(serviceRestrictionName, srrules);
                rbuilder.Add(sr);
                ImmutableArray<ServiceRestriction> restrictions = rbuilder.ToImmutable();
                restrictions = new ImmutableArray<ServiceRestriction>();


                ServiceData serviceData = new ServiceData(serviceName, flavorId, domains, origins, caching, restrictions);
//
                //ServiceData sed = new ServiceData(serviceName, flavorId, domains, origins, caching, restrictions);
                //CancellationToken cn = new CancellationToken();
                //ServiceId x = await cdc.AddServiceAsync(serviceData, cn);
//

                IContentDeliveryService service = CreateService();
                using (AddServiceApiCall apiCall = await service.PrepareAddServiceAsync(serviceData, cancellationToken))
                {
                    Tuple<HttpResponseMessage, ServiceId> response = await apiCall.SendAsync(cancellationToken);
                    Assert.IsNotNull(response);

                    var responseMessage = response.Item1;
                    Assert.IsNotNull(responseMessage);
                    Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode);

                    ServiceId serviceID = response.Item2;
                    Assert.IsNotNull(serviceID);
                }


                using (GetHomeApiCall apiCall = await service.PrepareGetHomeAsync(cancellationToken))
                {
                    Tuple<HttpResponseMessage, HomeDocument> response = await apiCall.SendAsync(cancellationToken);
                    Assert.IsNotNull(response);

                    var responseMessage = response.Item1;
                    Assert.IsNotNull(responseMessage);
                    Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode);

                    HomeDocument homeDocument = response.Item2;
                    CheckHomeDocument(homeDocument);
                }
            }
        }