-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from Avanade/feature/updateTargetFramework
feat: creates Liquid.Adapter.Dataverse package.
- Loading branch information
Showing
18 changed files
with
865 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# CI & CD workflow | ||
name: CI/CD - Liquid.Cache component for Liquid Application Framework | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'src/Liquid.Adapter.Dataverse/**' | ||
|
||
pull_request: | ||
branches: [ main, releases/** ] | ||
types: [opened, synchronize, reopened] | ||
paths: | ||
- 'src/Liquid.Adapter.Dataverse/**' | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
call-reusable-build-workflow: | ||
uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main | ||
with: | ||
component_name: Liquid.Adapter.Dataverse | ||
secrets: | ||
sonar_token: ${{ secrets.SONAR_TOKEN_DATAVERSE }} | ||
nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.6.34202.202 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Adapter.Dataverse", "src\Liquid.Adapter.Dataverse\Liquid.Adapter.Dataverse.csproj", "{02191AB8-D13C-4CCC-8455-08813FB0C9C3}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Liquid.Adapter.Dataverse.Tests", "test\Liquid.Adapter.Dataverse.Tests\Liquid.Adapter.Dataverse.Tests.csproj", "{90D60966-6004-4705-907D-780503EBC141}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{02191AB8-D13C-4CCC-8455-08813FB0C9C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{02191AB8-D13C-4CCC-8455-08813FB0C9C3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{02191AB8-D13C-4CCC-8455-08813FB0C9C3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{02191AB8-D13C-4CCC-8455-08813FB0C9C3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{90D60966-6004-4705-907D-780503EBC141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{90D60966-6004-4705-907D-780503EBC141}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{90D60966-6004-4705-907D-780503EBC141}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{90D60966-6004-4705-907D-780503EBC141}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8105640B-39D2-4FFE-8BBD-D8E37F2A070D} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Liquid.Adapter.Dataverse | ||
{ | ||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
internal class DataMappingException : Exception | ||
{ | ||
public DataMappingException() | ||
{ | ||
} | ||
|
||
public DataMappingException(string? message) : base(message) | ||
{ | ||
} | ||
|
||
public DataMappingException(string? message, Exception? innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
protected DataMappingException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using CustomerRegistration.Infra.Dataverse; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Metadata; | ||
using Microsoft.Xrm.Sdk.Query; | ||
|
||
namespace Liquid.Adapter.Dataverse | ||
{ | ||
///<inheritdoc/> | ||
public class DataverseAdapter : ILiquidDataverseAdapter | ||
{ | ||
private readonly IDataverseClientFactory _serviceFactory; | ||
private readonly IOrganizationServiceAsync _client; | ||
/// <summary> | ||
/// Initialize a new instance of <see cref="DataverseAdapter"/> | ||
/// </summary> | ||
/// <param name="serviceFactory"></param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public DataverseAdapter(IDataverseClientFactory serviceFactory) | ||
{ | ||
_serviceFactory = serviceFactory ?? throw new ArgumentNullException(nameof(serviceFactory)); | ||
|
||
_client = _serviceFactory.GetClient(); | ||
} | ||
|
||
///<inheritdoc/> | ||
public Task<Guid> Create(Entity entity) | ||
{ | ||
var result = _client.Create(entity); | ||
return Task.FromResult(result); | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task DeleteById(Guid id, string entityName) | ||
{ | ||
await _client.DeleteAsync(entityName, id); | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task<Entity> GetById(Guid id, string entityName, ColumnSet? columns = null) | ||
{ | ||
if (columns == null) | ||
columns = new ColumnSet(true); | ||
|
||
var result = await _client.RetrieveAsync(entityName, id, columns); | ||
|
||
return result; | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task<List<Entity>> ListByFilter(string entityName, FilterExpression? filter = null, ColumnSet? columns = null) | ||
{ | ||
List<Entity> results = new List<Entity>(); | ||
|
||
QueryExpression queryData = new QueryExpression(entityName); | ||
|
||
if (filter != null) | ||
queryData.Criteria = filter; | ||
|
||
if (columns != null) | ||
queryData.ColumnSet = columns; | ||
|
||
var result = await _client.RetrieveMultipleAsync(queryData); | ||
if(result?.Entities != null) | ||
{ | ||
foreach (var item in result.Entities) | ||
{ | ||
results.Add(item); | ||
} | ||
} | ||
|
||
|
||
return results; | ||
} | ||
///<inheritdoc/> | ||
public async Task<List<Entity>> ListByFilter(string entityName, QueryExpression query) | ||
{ | ||
if (query is null) | ||
{ | ||
throw new ArgumentNullException(nameof(query)); | ||
} | ||
|
||
List<Entity> results = new List<Entity>(); | ||
|
||
var result = await _client.RetrieveMultipleAsync(query); | ||
|
||
if(result?.Entities != null) | ||
{ | ||
foreach (var item in result.Entities) | ||
{ | ||
results.Add(item); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
///<inheritdoc/> | ||
public async Task Update(Entity entity) | ||
{ | ||
await _client.UpdateAsync(entity); | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task<EntityMetadata> GetMetadata(string entityName) | ||
{ | ||
var retrieveEntityRequest = new RetrieveEntityRequest | ||
{ | ||
EntityFilters = EntityFilters.All, | ||
LogicalName = entityName | ||
}; | ||
var response = await _client.ExecuteAsync(retrieveEntityRequest); | ||
var metadata = (RetrieveEntityResponse)response; | ||
return metadata.EntityMetadata; | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task SetState(EntityReference entity, string state, string status) | ||
{ | ||
var setStateRequest = new SetStateRequest() | ||
{ | ||
EntityMoniker = new EntityReference | ||
{ | ||
Id = entity.Id, | ||
LogicalName = entity.LogicalName, | ||
}, | ||
State = new OptionSetValue(int.Parse(state)), | ||
Status = new OptionSetValue(int.Parse(status)) | ||
}; | ||
|
||
await _client.ExecuteAsync(setStateRequest); | ||
} | ||
|
||
///<inheritdoc/> | ||
public async Task Upsert(Entity entity) | ||
{ | ||
var request = new UpsertRequest() | ||
{ | ||
Target = entity | ||
}; | ||
|
||
await _client.ExecuteAsync(request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using CustomerRegistration.Infra.Dataverse; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Liquid.Adapter.Dataverse | ||
{ | ||
///<inheritdoc/> | ||
public class DataverseClientFactory : IDataverseClientFactory | ||
{ | ||
private readonly IOptions<DataverseSettings> _options; | ||
|
||
/// <summary> | ||
/// Initialize a new instance of <see cref="DataverseClientFactory"/> | ||
/// </summary> | ||
/// <param name="options">Configuration settigs.</param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public DataverseClientFactory(IOptions<DataverseSettings> options) | ||
{ | ||
if (options is null) | ||
{ | ||
throw new ArgumentNullException(nameof(options)); | ||
} | ||
|
||
_options = options; | ||
} | ||
|
||
[ExcludeFromCodeCoverage] | ||
///<inheritdoc/> | ||
public IOrganizationServiceAsync GetClient() | ||
{ | ||
var settings = _options.Value; | ||
|
||
var connectionString = string.Format("AuthType=ClientSecret;url={0};ClientId={1};ClientSecret={2};", settings.Url, settings.ClientId, settings.ClientSecret); | ||
|
||
var service = new ServiceClient(connectionString); | ||
|
||
return service; | ||
} | ||
} | ||
} |
Oops, something went wrong.