Пример #1
0
 public static ResourceStrategy <TModel> Create <TModel, TOperations>(
     string provider,
     Func <WebSiteManagementClient, TOperations> getOperations,
     Func <TOperations, GetAsyncParams, Task <TModel> > getAsync,
     Func <TOperations, CreateOrUpdateAsyncParams <TModel>, Task <TModel> > createOrUpdateAsync,
     Func <TModel, int> createTime,
     bool compulsoryLocation = false) where TModel : Resource
 => ResourceStrategy.Create(
     type : new ResourceType("Microsoft.Web", provider),
     getOperations : getOperations,
     getAsync : getAsync,
     createOrUpdateAsync : createOrUpdateAsync,
     getLocation : config => config.Location,
     setLocation : (config, location) => config.Location = location,
     createTime : createTime,
     compulsoryLocation : compulsoryLocation);
Пример #2
0
 public static ResourceStrategy <TModel> Create <TModel, TOperations>(
     string provider,
     Func <NetworkManagementClient, TOperations> getOperations,
     Func <TOperations, GetAsyncParams, Task <TModel> > getAsync,
     Func <TOperations, CreateOrUpdateAsyncParams <TModel>, Task <TModel> > createOrUpdateAsync,
     Func <TModel, int> createTime)
     where TModel : Resource
 => ResourceStrategy.Create(
     new ResourceType("Microsoft.Network", provider),
     getOperations,
     getAsync,
     createOrUpdateAsync,
     model => model.Location,
     (model, location) => model.Location = location,
     createTime,
     true);
Пример #3
0
 public static ResourceStrategy <TModel> Create <TModel, TOperations>(
     string type,
     string provider,
     Func <ComputeManagementClient, TOperations> getOperations,
     Func <TOperations, GetAsyncParams, Task <TModel> > getAsync,
     Func <TOperations, CreateOrUpdateAsyncParams <TModel>, Task <TModel> > createOrUpdateAsync,
     Func <TModel, int> createTime)
     where TModel : Resource
 => ResourceStrategy.Create(
     type : type,
     providers : new[] { "Microsoft.Compute", provider },
     getOperations: getOperations,
     getAsync: getAsync,
     createOrUpdateAsync: createOrUpdateAsync,
     getLocation: config => config.Location,
     setLocation: (config, location) => config.Location = location,
     createTime: createTime,
     compulsoryLocation: true);
Пример #4
0
        public void TestDependencyGraph()
        {
            // resource group
            var rgStrategy = ResourceStrategy.Create <Model, Client, Client>(
                ResourceType.ResourceGroup,
                c => c,
                async(c, m) => null,
                async(c, m) => new Model(),
                m => m.Location,
                (m, location) => m.Location = location,
                m => 0,
                false);

            var rgConfig  = rgStrategy.CreateResourceConfig(null, "rgname");
            var rgConfig2 = rgStrategy.CreateResourceConfig(null, "rgname2");

            // resource
            var resourceStrategy = ResourceStrategy.Create <Model, Client, Client>(
                new ResourceType("Company.Namespace", "resourceProvider"),
                c => c,
                async(c, m) => null,
                async(c, m) => new Model(),
                m => m.Location,
                (m, location) => m.Location = location,
                m => 0,
                false);

            var resource = resourceStrategy.CreateResourceConfig(rgConfig, "res");

            // nested resource
            var rgNestedStrategy = NestedResourceStrategy.Create <NestedModel, Model>(
                "rgnested",
                m => m.Nested,
                (m, list) => m.Nested = list,
                nm => nm.Name,
                (nm, name) => nm.Name = name);

            // add the nested resource to the resource group.
            var rgNestedConfig = rgConfig.CreateNested(rgNestedStrategy, "rgnestedname");

            // nested resource
            var nestedStrategy = NestedResourceStrategy.Create <NestedModel, Model>(
                "nested",
                m => m.Nested,
                (m, list) => m.Nested = list,
                nm => nm.Name,
                (nm, name) => nm.Name = name);

            // add the nested resource to a resource.
            var nestedConfig = resource.CreateNested(
                nestedStrategy,
                "nestedname",
                e => new NestedModel
            {
                Id = e.GetId(rgConfig2)
            });

            //
            var engine = new SdkEngine("s");

            // empty state.
            var current = new StateOperationContext(new Client(), new CancellationToken())
                          .Result;

            var state   = resource.GetTargetState(current, engine, "eastus");
            var rgModel = state.Get(rgConfig);

            Assert.Equal("eastus", rgModel.Location);

            var rgNestedModel = rgModel.Nested.First() as NestedModel;

            Assert.Equal("rgnestedname", rgNestedModel.Name);

            var rgModel2 = state.Get(rgConfig2);

            Assert.NotNull(rgModel2);
        }