Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/PaoloPia/pnpcore into pr354
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Mar 15, 2021
2 parents ee7ceef + 42de3ac commit 20cbaa0
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 850 deletions.
89 changes: 4 additions & 85 deletions src/sdk/PnP.Core/Model/Base/BaseDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
using System.Linq.Expressions;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

namespace PnP.Core.Model
{

/// <summary>
/// Delegate for requesting the Api call for doing an ADD operation
/// </summary>
Expand Down Expand Up @@ -44,7 +44,6 @@ namespace PnP.Core.Model
/// <typeparam name="TModel">Model class</typeparam>
internal class BaseDataModel<TModel> : TransientObject, IDataModel<TModel>, IDataModelProcess, IDataModelLoad, IRequestable, IMetadataExtensible, IDataModelWithKey, IDataModelMappingHandler
{

#region Core properties

/// <summary>
Expand Down Expand Up @@ -110,16 +109,6 @@ public async Task ProcessResponseAsync(ApiResponse apiResponse, Expression<Func<

#region Get

/// <summary>
/// Retrieves a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual TModel Get(params Expression<Func<TModel, object>>[] expressions)
{
return GetAsync(expressions).GetAwaiter().GetResult();
}

/// <summary>
/// Retrieves a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
Expand All @@ -146,25 +135,14 @@ public virtual async Task<TModel> GetAsync(params Expression<Func<TModel, object
return (TModel)(object)newDataModel;
}


/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="batch">Batch add this request to</param>
/// <param name="selectors">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual IBatchSingleResult<TModel> GetBatch(Batch batch, params Expression<Func<TModel, object>>[] selectors)
{
return GetBatchAsync(batch, selectors).GetAwaiter().GetResult();
}

/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="batch">Batch add this request to</param>
/// <param name="selectors">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual Task<IBatchSingleResult<TModel>> GetBatchAsync(Batch batch, params Expression<Func<TModel, object>>[] selectors)
public virtual Task<IBatchSingleResult<TModel>> GetBatchAsync(Batch batch,
params Expression<Func<TModel, object>>[] selectors)
{
return GetBatchAsync(batch, default, selectors);
}
Expand Down Expand Up @@ -200,28 +178,10 @@ internal virtual async Task<IBatchSingleResult<TModel>> GetBatchAsync(Batch batc
return batchResult;
}

/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual async Task<IBatchSingleResult<TModel>> GetBatchAsync(params Expression<Func<TModel, object>>[] expressions)
{
return await GetBatchAsync(PnPContext.CurrentBatch, expressions).ConfigureAwait(false);
}

/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual IBatchSingleResult<TModel> GetBatch(params Expression<Func<TModel, object>>[] expressions)
{
return GetBatchAsync(PnPContext.CurrentBatch, expressions).GetAwaiter().GetResult();
}
#endregion

#region Load

/// <summary>
/// Loads a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
Expand All @@ -234,16 +194,6 @@ public virtual Task LoadAsync(params LambdaExpression[] selectors)
return BaseRetrieveAsync(expressions: newExpressions);
}

/// <summary>
/// Loads a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="selectors">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual void Load(params Expression<Func<TModel, object>>[] selectors)
{
LoadAsync(selectors).GetAwaiter().GetResult();
}

/// <summary>
/// Loads a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
Expand Down Expand Up @@ -278,37 +228,6 @@ public virtual async Task<IBatchResult> LoadBatchAsync(Batch batch, params Expre
return await BaseBatchRetrieveAsync(batch, default, MappingHandler, PostMappingHandler, selectors).ConfigureAwait(false);
}

/// <summary>
/// Batches the load of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="batch">Batch to use for the current request</param>
/// <param name="selectors">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual IBatchResult LoadBatch(Batch batch, params Expression<Func<TModel, object>>[] selectors)
{
return LoadBatchAsync(batch, selectors).GetAwaiter().GetResult();
}

/// <summary>
/// Batches the load of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual async Task<IBatchResult> LoadBatchAsync(params Expression<Func<TModel, object>>[] expressions)
{
return await LoadBatchAsync(PnPContext.CurrentBatch, expressions).ConfigureAwait(false);
}

/// <summary>
/// Batches the load of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public virtual IBatchResult LoadBatch(params Expression<Func<TModel, object>>[] expressions)
{
return LoadBatchAsync(expressions).GetAwaiter().GetResult();
}

#endregion

#region Add
Expand Down
29 changes: 22 additions & 7 deletions src/sdk/PnP.Core/Model/Base/DataModelCollectionLoadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ namespace PnP.Core.Model
/// <summary>
/// Extension methods for <see cref="IDataModelCollectionLoad{TModel}"/>
/// </summary>
internal static class DataModelCollectionLoadExtensions
public static class DataModelCollectionLoadExtensions
{

/// <summary>
/// Batches the load of the list from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="dataModelLoad"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static Task<IBatchResult> LoadBatchAsync<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
public static Task<IBatchResult> LoadBatchAsync<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelLoad == null)
{
Expand All @@ -34,7 +33,24 @@ internal static Task<IBatchResult> LoadBatchAsync<TModel>(this IDataModelCollect
/// <param name="batch">Batch add this request to</param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, Batch batch, params Expression<Func<TModel, object>>[] expressions)
public static Task<IBatchResult> LoadBatchAsync<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, Batch batch, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelLoad == null)
{
throw new ArgumentNullException(nameof(dataModelLoad));
}

return dataModelLoad.LoadBatchAsync(batch, expressions);
}

/// <summary>
/// Batches the load of the list from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="dataModelLoad"></param>
/// <param name="batch">Batch add this request to</param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, Batch batch, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelLoad == null)
{
Expand All @@ -50,7 +66,7 @@ internal static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TMo
/// <param name="dataModelLoad"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
public static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelLoad == null)
{
Expand All @@ -67,7 +83,7 @@ internal static IBatchResult LoadBatch<TModel>(this IDataModelCollectionLoad<TMo
/// <param name="dataModelLoad"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static void Load<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
public static void Load<TModel>(this IDataModelCollectionLoad<TModel> dataModelLoad, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelLoad == null)
{
Expand All @@ -76,6 +92,5 @@ internal static void Load<TModel>(this IDataModelCollectionLoad<TModel> dataMode

dataModelLoad.LoadAsync(expressions).GetAwaiter().GetResult();
}

}
}
30 changes: 23 additions & 7 deletions src/sdk/PnP.Core/Model/Base/DataModelGetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace PnP.Core.Model
/// <summary>
/// Extension methods for <see cref="IDataModelProcess"/>
/// </summary>
internal static class DataModelGetExtensions
public static class DataModelGetExtensions
{
/// <summary>
/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="dataModelGet"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static Task<IBatchSingleResult<TModel>> GetBatchAsync<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
public static Task<IBatchSingleResult<TModel>> GetBatchAsync<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelGet == null)
{
Expand All @@ -33,7 +33,24 @@ internal static Task<IBatchSingleResult<TModel>> GetBatchAsync<TModel>(this IDat
/// <param name="batch">Batch add this request to</param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<TModel> dataModelGet, Batch batch, params Expression<Func<TModel, object>>[] expressions)
public static Task<IBatchSingleResult<TModel>> GetBatchAsync<TModel>(this IDataModelGet<TModel> dataModelGet, Batch batch, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelGet == null)
{
throw new ArgumentNullException(nameof(dataModelGet));
}

return dataModelGet.GetBatchAsync(batch, expressions);
}

/// <summary>
/// Batches the retrieval of a Domain Model object from the remote data source, eventually selecting custom properties or using a default set of properties
/// </summary>
/// <param name="dataModelGet"></param>
/// <param name="batch">Batch add this request to</param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
public static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<TModel> dataModelGet, Batch batch, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelGet == null)
{
Expand All @@ -49,7 +66,7 @@ internal static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<T
/// <param name="dataModelGet"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
public static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelGet == null)
{
Expand All @@ -65,7 +82,7 @@ internal static IBatchSingleResult<TModel> GetBatch<TModel>(this IDataModelGet<T
/// <param name="dataModelGet"></param>
/// <param name="expressions">The properties to select</param>
/// <returns>The Domain Model object</returns>
internal static TModel Get<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
public static TModel Get<TModel>(this IDataModelGet<TModel> dataModelGet, params Expression<Func<TModel, object>>[] expressions)
{
if (dataModelGet == null)
{
Expand All @@ -74,6 +91,5 @@ internal static TModel Get<TModel>(this IDataModelGet<TModel> dataModelGet, para

return dataModelGet.GetAsync(expressions).GetAwaiter().GetResult();
}

}
}
Loading

0 comments on commit 20cbaa0

Please sign in to comment.