예제 #1
0
        public async static void ExampleDoc()
        {
            // Authenticate
            var identity = new CloudIdentity
            {
                APIKey   = "{apikey}",
                Username = "******"
            };
            var authProvider = new CloudIdentityProvider(identity);
            var cdnService   = new ContentDeliveryNetworkService(authProvider, "{region}");

            // List Flavors
            IEnumerable <Flavor> flavors = await cdnService.ListFlavorsAsync();

            // Get Flavor
            Flavor flavor = await cdnService.GetFlavorAsync("{flavorId}");

            // Create Service
            ServiceDefinition serviceDefinition = new ServiceDefinition("example_site", "{flavorId}",
                                                                        domains: new[] { new ServiceDomain("www.example.com") },
                                                                        origins: new[] { new ServiceOrigin("example.com") });
            string serviceId = await cdnService.CreateServiceAsync(serviceDefinition);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            // List Services
            IPage <Service> services = await cdnService.ListServicesAsync();

            // Get Service
            Service service = await cdnService.GetServiceAsync("{serviceId}");

            // Purge All Service Assets
            await cdnService.PurgeCachedAssetsAsync("{serviceId}");

            // Purge a Specific Service Asset
            await cdnService.PurgeCachedAssetAsync("{serviceId}", "{relativeUrlOfAsset}");

            // Update Service
            var patch = new JsonPatchDocument <ServiceDefinition>();

            patch.Replace(svc => svc.Name, "newServiceName");
            await cdnService.UpdateServiceAsync("{serviceId}", patch);

            await cdnService.WaitForServiceDeployedAsync("{serviceId}");

            // Delete Service
            await cdnService.DeleteServiceAsync("{serviceId}");

            await cdnService.WaitForServiceDeletedAsync("{serviceId}");
        }
        public async void FindServiceOnAPage()
        {
            var serviceIds = new List <string>();

            try
            {
                var create1 = CreateService("ci-test1", "mirror.example1.com", "example1.com").ContinueWith(t => serviceIds.Add(t.Result));
                var create2 = CreateService("ci-test2", "mirror.example2.com", "example2.com").ContinueWith(t => serviceIds.Add(t.Result));
                var create3 = CreateService("ci-test3", "mirror.example3.com", "example3.com").ContinueWith(t => serviceIds.Add(t.Result));

                await Task.WhenAll(create1, create2, create3);

                var currentPage = await _cdnService.ListServicesAsync(pageSize : 1);

                while (currentPage.Any())
                {
                    if (currentPage.Any(x => x.Name == "ci-test3"))
                    {
                        Trace.WriteLine("Found the desired service");
                        break;
                    }

                    currentPage = await currentPage.GetNextPageAsync();
                }
            }
            finally
            {
                Trace.WriteLine("Cleaning up any test data...");

                Trace.WriteLine("Removing the services...");
                var deletes = serviceIds.Select(serviceId => _cdnService
                                                .DeleteServiceAsync(serviceId)
                                                .ContinueWith(t => _cdnService.WaitForServiceDeletedAsync(serviceId))
                                                .ContinueWith(t => Trace.WriteLine(string.Format("Service was deleted: {0}", serviceId))))
                              .ToArray();

                Task.WaitAll(deletes);
                Trace.WriteLine("The services were cleaned up sucessfully.");
            }
        }
예제 #3
0
        public async Task Run(string username, string apiKey)
        {
            // Authenticate
            var identity = new CloudIdentity
            {
                APIKey   = apiKey,
                Username = username
            };
            var authProvider = new CloudIdentityProvider(identity);
            var cdnService   = new ContentDeliveryNetworkService(authProvider, "DFW");

            // List Flavors
            Console.WriteLine();
            Console.WriteLine("List Flavors...");
            IEnumerable <Flavor> flavors = await cdnService.ListFlavorsAsync();

            foreach (Flavor f in flavors)
            {
                Console.WriteLine("{0}\t{1}", f.Id, f.Providers.First().Name);
            }

            // Get Flavor
            Console.WriteLine();
            Console.WriteLine("Get Flavor...");
            Flavor flavor = await cdnService.GetFlavorAsync(flavors.First().Id);

            Console.WriteLine("{0}\t{1}", flavor.Id, flavor.Providers.First().Name);

            // Create Service
            Console.WriteLine();
            Console.WriteLine("Create Service...");
            ServiceDefinition serviceDefinition = new ServiceDefinition("example_site", flavor.Id,
                                                                        domains: new[] { new ServiceDomain("www.example.com") },
                                                                        origins: new[] { new ServiceOrigin("example.com") });
            string serviceId = await cdnService.CreateServiceAsync(serviceDefinition);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            Console.WriteLine("Service Created: {0}", serviceId);

            // List Services
            Console.WriteLine();
            Console.WriteLine("List Services..");
            IPage <Service> services = await cdnService.ListServicesAsync();

            foreach (Service s in services)
            {
                Console.WriteLine("{0}\t{1}", s.Id, s.Name);
            }

            // Get Service
            Console.WriteLine();
            Console.WriteLine("Get Service");
            Service service = await cdnService.GetServiceAsync(serviceId);

            Console.WriteLine("{0}\t{1}", service.Id, service.Name);

            // Purge All Service Assets
            Console.WriteLine();
            Console.WriteLine("Purge All Service Assets...");
            await cdnService.PurgeCachedAssetsAsync(serviceId);

            // Purge a Specific Service Asset
            Console.WriteLine();
            Console.WriteLine("Purge a Specific Service Asset...");
            await cdnService.PurgeCachedAssetAsync(serviceId, "index.html");

            // Update Service
            Console.WriteLine();
            Console.WriteLine("Update Service...");
            var patch = new JsonPatchDocument <ServiceDefinition>();

            patch.Replace(svc => svc.Name, "newServiceName");
            await cdnService.UpdateServiceAsync(serviceId, patch);

            await cdnService.WaitForServiceDeployedAsync(serviceId);

            // Delete Service
            Console.WriteLine();
            Console.WriteLine("Delete Service...");
            await cdnService.DeleteServiceAsync(serviceId);

            await cdnService.WaitForServiceDeletedAsync(serviceId);
        }