Skip to content

Commit

Permalink
Extend the IResourceProvider interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ciprianjichici committed Jan 27, 2024
1 parent baa4c90 commit 5517894
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/dotnet/Common/Interfaces/IResourceProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public interface IResourceProviderService
/// <summary>
/// Gets a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the requested resource.</typeparam>
/// <param name="resourcePath">The logical path of the requested resource.</param>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
/// <returns>The instance of the resource corresponding to the specified logical path.</returns>
Task<T> GetResourceAsync<T>(string resourcePath) where T: class;

/// <summary>
/// Gets a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the requested resource.</typeparam>
/// <param name="resourcePath">The logical path of the requested resource.</param>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
/// <returns>The instance of the resource corresponding to the specified logical path.</returns>
T GetResource<T>(string resourcePath) where T : class;

Expand All @@ -45,5 +45,37 @@ public interface IResourceProviderService
/// <param name="actionPath">The logical path of the action to be executed.</param>
/// <returns>The <see cref="ResourceProviderActionResult"/> that contains details about the result of the execution.</returns>
Task<ResourceProviderActionResult> ExecuteAction(string actionPath);

/// <summary>
/// Creates or updates a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
/// <param name="resource">The instance of the resource being created or updated.</param>
/// <returns></returns>
Task UpsertResourceAsync<T>(string resourcePath, T resource) where T : class;

/// <summary>
/// Creates or updates a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
/// <param name="resource">The instance of the resource being created or updated.</param>
void UpsertResource<T>(string resourcePath, T resource) where T : class;

/// <summary>
/// Deletes a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
/// <returns></returns>
Task DeleteResourceAsync<T>(string resourcePath) where T : class;

/// <summary>
/// Deletes a resource based on its logical path.
/// </summary>
/// <typeparam name="T">The type of the resource.</typeparam>
/// <param name="resourcePath">The logical path of the resource.</param>
void DeleteResource<T>(string resourcePath) where T : class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ public async Task<T> GetResourceAsync<T>(string resourcePath) where T : class
return await GetResourceAsyncInternal<T>(instances);
}

/// <inheritdoc/>
public async Task UpsertResourceAsync<T>(string resourcePath, T resource) where T : class
{
if (!_isInitialized)
throw new ResourceProviderException($"The resource provider {_name} is not initialized.");
var instances = GetResourceInstancesFromPath(resourcePath);
await UpsertResourceAsync<T>(resourcePath, resource);
}

/// <inheritdoc/>
public void UpsertResource<T>(string resourcePath, T resource) where T : class
{
if (!_isInitialized)
throw new ResourceProviderException($"The resource provider {_name} is not initialized.");
var instances = GetResourceInstancesFromPath(resourcePath);
UpsertResource<T>(instances, resource);
}

/// <inheritdoc/>
public async Task DeleteResourceAsync<T>(string resourcePath) where T : class
{
if (!_isInitialized)
throw new ResourceProviderException($"The resource provider {_name} is not initialized.");
var instances = GetResourceInstancesFromPath(resourcePath);
await DeleteResourceAsync<T>(instances);
}

/// <inheritdoc/>
public void DeleteResource<T>(string resourcePath) where T : class
{
if (!_isInitialized)
throw new ResourceProviderException($"The resource provider {_name} is not initialized.");
var instances = GetResourceInstancesFromPath(resourcePath);
DeleteResource<T>(instances);
}

/// <summary>
/// The internal implementation of Initialize. Must be overridden in derived classes.
/// </summary>
Expand Down Expand Up @@ -134,6 +170,46 @@ protected virtual async Task<T> GetResourceAsyncInternal<T>(List<ResourceTypeIns
throw new NotImplementedException();
}

/// <summary>
/// The internal implementation of UpsertResource. Must be overridden in derived classes.
/// </summary>
/// <param name="instances">The list of <see cref="ResourceTypeInstance"/> objects parsed from the resource path.</param>
/// <param name="resource">The instance of the resource being created or updated.</param>
/// <returns></returns>
protected virtual void UpsertResource<T>(List<ResourceTypeInstance> instances, T resource) =>
throw new NotImplementedException();

/// <summary>
/// The internal implementation of UpsertResourceAsync. Must be overridden in derived classes.
/// </summary>
/// <param name="instances">The list of <see cref="ResourceTypeInstance"/> objects parsed from the resource path.</param>
/// <param name="resource">The instance of the resource being created or updated.</param>
/// <returns></returns>
protected virtual async Task UpsertResourceAsync<T>(List<ResourceTypeInstance> instances, T resource)
{
await Task.CompletedTask;
throw new NotImplementedException();
}

/// <summary>
/// The internal implementation of DeleteResource. Must be overridden in derived classes.
/// </summary>
/// <param name="instances">The list of <see cref="ResourceTypeInstance"/> objects parsed from the resource path.</param>
/// <returns></returns>
protected virtual void DeleteResource<T>(List<ResourceTypeInstance> instances) =>
throw new NotImplementedException();

/// <summary>
/// The internal implementation of DeleteResourceAsync. Must be overridden in derived classes.
/// </summary>
/// <param name="instances">The list of <see cref="ResourceTypeInstance"/> objects parsed from the resource path.</param>
/// <returns></returns>
protected virtual async Task DeleteResourceAsync<T>(List<ResourceTypeInstance> instances)
{
await Task.CompletedTask;
throw new NotImplementedException();
}

private List<ResourceTypeInstance> GetResourceInstancesFromPath(string resourcePath)
{
if (string.IsNullOrWhiteSpace(resourcePath))
Expand Down

0 comments on commit 5517894

Please sign in to comment.