Exemplo n.º 1
0
        static void Main()
        {
            // Access token from the azure-cli
            // az account get-access-token
            var token          = "";
            var subscriptionId = "";
            var creds          = new TokenCredentials(token, "Bearer");

            var client   = new IotCentralClient(creds);
            var skuInfo  = new AppSkuInfo("ST2");
            var location = "unitedstates";
            var app      = new App(location, skuInfo);

            client.SubscriptionId = subscriptionId;

            var name          = "csharp-test-app";
            var resourceGroup = "myResourceGroup";

            app.Location    = location;
            app.Subdomain   = name;
            app.DisplayName = name;

            Console.WriteLine("Check if the app name is available");
            OperationInputs input         = new OperationInputs(name);
            var             nameAvailable = client.Apps.CheckNameAvailability(input);

            Console.WriteLine(nameAvailable.Message);

            Console.WriteLine("Creating the app");
            client.Apps.CreateOrUpdate(resourceGroup, name, app);

            Console.WriteLine("Getting the app");
            var resultApp = client.Apps.Get(resourceGroup, name);

            Console.WriteLine(resultApp);

            Console.WriteLine("Updating the app");
            var updateApp = new AppPatch();

            updateApp.DisplayName = name + "-new-name";
            var updateResult = client.Apps.Update(resourceGroup, name, updateApp);

            Console.WriteLine(updateResult);

            Console.WriteLine("Listing apps");
            foreach (var currentApp in client.Apps.ListByResourceGroup(resourceGroup))
            {
                Console.WriteLine($"{currentApp.DisplayName} ({currentApp.Id})");
            }

            Console.WriteLine(Environment.NewLine);
            // Console.WriteLine("Removing app");
            // client.Apps.Delete(resourceGroup, name);

            Console.WriteLine("Done");
        }
        public IotCentralAppData(AzureLocation location, AppSkuInfo sku) : base(location)
        {
            if (sku == null)
            {
                throw new ArgumentNullException(nameof(sku));
            }

            Sku = sku;
            PrivateEndpointConnections = new ChangeTrackingList <IotCentralPrivateEndpointConnectionData>();
        }
 internal IotCentralAppData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, AppSkuInfo sku, SystemAssignedServiceIdentity identity, ProvisioningState?provisioningState, string applicationId, string displayName, string subdomain, string template, AppState?state, PublicNetworkAccess?publicNetworkAccess, NetworkRuleSets networkRuleSets, IReadOnlyList <IotCentralPrivateEndpointConnectionData> privateEndpointConnections) : base(id, name, resourceType, systemData, tags, location)
 {
     Sku                        = sku;
     Identity                   = identity;
     ProvisioningState          = provisioningState;
     ApplicationId              = applicationId;
     DisplayName                = displayName;
     Subdomain                  = subdomain;
     Template                   = template;
     State                      = state;
     PublicNetworkAccess        = publicNetworkAccess;
     NetworkRuleSets            = networkRuleSets;
     PrivateEndpointConnections = privateEndpointConnections;
 }
        public void TestAppSkuInfoWhenNullInput()
        {
            var exceptionThrown = false;

            try
            {
                AppSkuInfo appSku = new AppSkuInfo();
                appSku.Validate();
            }
            catch (Exception ex)
            {
                exceptionThrown = true;
                Assert.Equal(typeof(ValidationException), ex.GetType());
            }
            Assert.True(exceptionThrown);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            // Access token from the azure-cli
            // az account get-access-token
            var token          = "";
            var subscriptionId = "";
            var creds          = new TokenCredentials(token, "Bearer");

            var client  = new IotCentralClient(creds);
            var skuInfo = new AppSkuInfo("S1");
            var app     = new App("West Us", skuInfo);

            client.SubscriptionId = subscriptionId;

            var name          = "csharp-test-app";
            var resourceGroup = "myResourceGroup";

            app.Location    = "West Us";
            app.Subdomain   = name;
            app.DisplayName = name;

            Console.WriteLine("Creating app");
            var resultApp = client.Apps.CreateOrUpdate(resourceGroup, name, app);

            Console.WriteLine("Listing apps");
            foreach (var currentApp in client.Apps.ListByResourceGroup(resourceGroup))
            {
                Console.WriteLine($"{currentApp.DisplayName} ({currentApp.Id})");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Removing app");
            client.Apps.Delete(resourceGroup, name);

            Console.WriteLine("Done");
        }
        static void Main()
        {
            // Access token from the azure-cli
            // az account get-access-token
            var token          = "";
            var subscriptionId = "";
            var creds          = new TokenCredentials(token, "Bearer");

            var client   = new IotCentralClient(creds);
            var skuInfo  = new AppSkuInfo("ST2");
            var location = "unitedstates";
            var app      = new App(location, skuInfo);

            client.SubscriptionId = subscriptionId;

            var name          = "csharp-test-app";
            var resourceGroup = "myResourceGroup";

            app.Location    = location;
            app.Subdomain   = name;
            app.DisplayName = name;

            Console.WriteLine("===Check if the app name is available");
            OperationInputs input = new OperationInputs(name);
            var             appNameAvailability = client.Apps.CheckNameAvailability(input);

            if (appNameAvailability.NameAvailable == true)
            {
                Console.WriteLine("app name is available!");
            }
            else
            {
                Console.WriteLine($"app name isn't available because {appNameAvailability.Reason}");
            }

            Console.WriteLine("===Creating the app");
            var createApp = client.Apps.CreateOrUpdate(resourceGroup, name, app);

            Console.WriteLine(createApp.Name);
            Console.WriteLine(createApp.DisplayName);

            Console.WriteLine("===Getting the app");
            var resultApp = client.Apps.Get(resourceGroup, name);

            Console.WriteLine(resultApp.Name);
            Console.WriteLine(resultApp.DisplayName);

            Console.WriteLine("===Updating the app");
            var updateApp = new AppPatch();

            updateApp.DisplayName = name + "-new-name";
            var updateResult = client.Apps.Update(resourceGroup, name, updateApp);

            Console.WriteLine(updateResult.Name);
            Console.WriteLine(updateResult.DisplayName);

            Console.WriteLine($"===Listing all the apps under the resource group of {resourceGroup}");
            foreach (var currentApp in client.Apps.ListByResourceGroup(resourceGroup))
            {
                Console.WriteLine($"{currentApp.DisplayName} ({currentApp.Id})");
            }

            Console.WriteLine("===Listing all the operations in iotc");
            foreach (var currentOperation in client.Operations.List())
            {
                Console.WriteLine(currentOperation.Name);
            }

            Console.WriteLine("===Listing all the app templates in iotc");
            foreach (var currentAppTemplate in client.Apps.ListTemplates())
            {
                Console.WriteLine(currentAppTemplate.Name);
            }

            Console.WriteLine("===Removing app");
            client.Apps.Delete(resourceGroup, name);

            Console.WriteLine("Done");
        }
Exemplo n.º 7
0
        internal static IotCentralAppData DeserializeIotCentralAppData(JsonElement element)
        {
            AppSkuInfo sku = default;
            Optional <SystemAssignedServiceIdentity> identity = default;
            IDictionary <string, string>             tags     = default;
            AzureLocation                  location           = default;
            ResourceIdentifier             id                  = default;
            string                         name                = default;
            ResourceType                   type                = default;
            SystemData                     systemData          = default;
            Optional <ProvisioningState>   provisioningState   = default;
            Optional <string>              applicationId       = default;
            Optional <string>              displayName         = default;
            Optional <string>              subdomain           = default;
            Optional <string>              template            = default;
            Optional <AppState>            state               = default;
            Optional <PublicNetworkAccess> publicNetworkAccess = default;
            Optional <NetworkRuleSets>     networkRuleSets     = default;
            Optional <IReadOnlyList <IotCentralPrivateEndpointConnectionData> > privateEndpointConnections = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sku"))
                {
                    sku = AppSkuInfo.DeserializeAppSkuInfo(property.Value);
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = JsonSerializer.Deserialize <SystemAssignedServiceIdentity>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new ProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("applicationId"))
                        {
                            applicationId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("displayName"))
                        {
                            displayName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("subdomain"))
                        {
                            subdomain = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("template"))
                        {
                            template = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("state"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            state = new AppState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("publicNetworkAccess"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            publicNetworkAccess = new PublicNetworkAccess(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("networkRuleSets"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkRuleSets = NetworkRuleSets.DeserializeNetworkRuleSets(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("privateEndpointConnections"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <IotCentralPrivateEndpointConnectionData> array = new List <IotCentralPrivateEndpointConnectionData>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(IotCentralPrivateEndpointConnectionData.DeserializeIotCentralPrivateEndpointConnectionData(item));
                            }
                            privateEndpointConnections = array;
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new IotCentralAppData(id, name, type, systemData, tags, location, sku, identity, Optional.ToNullable(provisioningState), applicationId.Value, displayName.Value, subdomain.Value, template.Value, Optional.ToNullable(state), Optional.ToNullable(publicNetworkAccess), networkRuleSets.Value, Optional.ToList(privateEndpointConnections)));
        }