Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureResourceManagerClientOptions"/> class.
 /// </summary>
 /// <param name="defaultLocation"> The default location to use if can't be inherited from parent. </param>
 public AzureResourceManagerClientOptions(LocationData defaultLocation)
     : this(defaultLocation, null)
 {
 }
        /// <summary>
        /// Create a resource with a ResourceGroupOperations.
        /// </summary>
        /// <param name="name"> A string representing the name of the resource />. </param>
        /// <param name="model"> The model representing the object to create. />. </param>
        /// <param name="location"> A Location of where to to host the resource. />. </param>
        /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="P:System.Threading.CancellationToken.None" />. </param>
        /// <typeparam name="TContainer"> The type of the class containing the container for the specific resource. </typeparam>
        /// <typeparam name="TOperations"> The type of the operations class for a specific resource. </typeparam>
        /// <typeparam name="TResource"> The type of the class containing properties for the underlying resource. </typeparam>
        /// <returns> A <see cref="Task"/> that on completion returns a response with the <see cref="ArmResponse{TOperations}"/> operation for this resource. </returns>
        public Task <ArmResponse <TOperations> > CreateResourceAsync <TContainer, TOperations, TResource>(string name, TResource model, LocationData location = default, CancellationToken cancellationToken = default)
            where TResource : TrackedResource
            where TOperations : ResourceOperationsBase <TOperations>
            where TContainer : ResourceContainerBase <TOperations, TResource>
        {
            var myResource = model as TrackedResource;

            if (myResource == null)
            {
                myResource = new GenericResourceData(Id);
            }

            if (location != null)
            {
                myResource = new GenericResourceData(Id, location);
            }

            TContainer container = Activator.CreateInstance(typeof(TContainer), ClientOptions, myResource) as TContainer;

            return(container.CreateOrUpdateAsync(name, model, cancellationToken));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TrackedResource{TModel}"/> class.
 /// </summary>
 /// <param name="id"> The identifier of the resource that is the target of operations. </param>
 /// <param name="location"> The location of the resource. </param>
 /// <param name="data"> The model to copy from. </param>
 protected TrackedResource(ResourceIdentifier id, LocationData location, TModel data)
 {
     Id       = id;
     Location = location;
     Model    = data;
 }
        /// <summary>
        /// Gets resource operations base.
        /// </summary>
        /// <typeparam name="TContainer"> The type of the container class for a specific resource. </typeparam>
        /// <typeparam name="TOperations"> The type of the operations class for a specific resource. </typeparam>
        /// <typeparam name="TResource"> The type of the class containing properties for the underlying resource. </typeparam>
        /// <param name="subscription"> The id of the Azure subscription. </param>
        /// <param name="resourceGroup"> The resource group name. </param>
        /// <param name="name"> The resource type name. </param>
        /// <param name="model"> The resource data model. </param>
        /// <param name="location"> The resource geo-location. </param>
        /// <returns> Resource operations of the resource. </returns>
        public ArmResponse <TOperations> CreateResource <TContainer, TOperations, TResource>(string subscription, string resourceGroup, string name, TResource model, LocationData location = default)
            where TResource : TrackedResource
            where TOperations : ResourceOperationsBase <TOperations>
            where TContainer : ResourceContainerBase <TOperations, TResource>
        {
            if (location == null)
            {
                location = LocationData.Default;
            }

            TContainer container = Activator.CreateInstance(typeof(TContainer), ClientOptions, new GenericResourceData($"/subscriptions/{subscription}/resourceGroups/{resourceGroup}", location)) as TContainer;

            return(container.CreateOrUpdate(name, model));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericResourceData"/> class.
 /// </summary>
 /// <param name="id"> The identifier of the resource that is the target of operations. </param>
 /// <param name="location"> The location of the resource. </param>
 public GenericResourceData(ResourceIdentifier id, LocationData location)
     : base(id, location, null)
 {
 }