-
Notifications
You must be signed in to change notification settings - Fork 0
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 #16 from thygesteffensen/dev
Dev
- Loading branch information
Showing
135 changed files
with
2,269 additions
and
1,529 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,63 @@ | ||
name: Build | ||
|
||
on: | ||
pull_request: | ||
types: [assigned, opened, synchronize, reopened] | ||
|
||
jobs: | ||
test: | ||
runs-on: windows-latest | ||
name: Testing | ||
steps: | ||
- name: Checkout code base | ||
uses: actions/checkout@v2 | ||
|
||
# - name: Add nuget Source | ||
# env: | ||
# GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
# run: nuget sources Add -Name Github -Source https://nuget.pkg.github.com/thygesteffensen/index.json -UserName thygesteffensen -Password $env:GH_TOKEN | ||
# | ||
# - name: Set Github nuget API | ||
# env: | ||
# GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
# run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json | ||
|
||
- name: Run tests | ||
run: dotnet test --verbosity normal --configuration Release | ||
|
||
build: | ||
runs-on: windows-latest | ||
name: Building | ||
steps: | ||
- name: Checkout code base | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup MSBuild | ||
uses: microsoft/setup-msbuild@v1 | ||
|
||
# - name: Add nuget Source | ||
# env: | ||
# GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
# run: nuget sources Add -Name Github -Source https://nuget.pkg.github.com/thygesteffensen/index.json -UserName thygesteffensen -Password $env:GH_TOKEN | ||
# | ||
# - name: Set Github nuget API | ||
# env: | ||
# GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
# run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json | ||
|
||
- name: Restore NuGet packages | ||
run: dotnet restore PAMU_CDS.sln /p:Configuration=Release | ||
|
||
- name: Run tests | ||
run: dotnet test --verbosity normal --configuration Release | ||
|
||
- name: Build solution | ||
run: msbuild /p:OutputPath=../build /p:Configuration=Release /p:RestorePackages=false | ||
|
||
- name: Archive build to artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: build | ||
path: | | ||
build/PAMU_CDS.dll | ||
retention-days: 5 |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ jobs: | |
run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json | ||
|
||
- name: Run tests | ||
run: dotnet test --verbosity normal | ||
run: dotnet test --verbosity normal --configuration Release | ||
|
||
release: | ||
name: Releasing | ||
|
@@ -56,7 +56,7 @@ jobs: | |
GIT_AUTHOR_NAME: thygesteffensen | ||
GIT_AUTHOR_EMAIL: [email protected] | ||
run: | | ||
echo "RELEASE_VERSION=$((npx semantic-release --dry-run).Where({ $_ -like '*Release note*' }) | Out-String | Select-String '[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-z]+[.][0-9]*)' | % { $_.Matches } | % { $_.Value })" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | ||
echo "RELEASE_VERSION=$((npx semantic-release --dry-run).Where({ $_ -like '*Release note*' }) | Out-String | Select-String '[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-z]+[.][0-9]*)?' | % { $_.Matches } | % { $_.Value })" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | ||
- name: Print release verison | ||
run: echo ${env:RELEASE_VERSION} | ||
|
@@ -75,10 +75,10 @@ jobs: | |
run: nuget setapikey $env:GH_TOKEN -Source https://nuget.pkg.github.com/thygesteffensen/index.json | ||
|
||
- name: Restore NuGet packages | ||
run: nuget restore PAMU_CDS.sln | ||
run: dotnet restore PAMU_CDS.sln /p:Configuration=Release | ||
|
||
- name: Package PAMU | ||
run: msbuild /t:pack /p:PackageVersion=${env:RELEASE_VERSION} /p:OutputPath=..\\artifacts | ||
run: msbuild /t:pack /p:PackageVersion=${env:RELEASE_VERSION} /p:Configuration=Release /p:OutputPath=..\\artifacts | ||
if: ${{ env.RELEASE_VERSION }} | ||
|
||
- name: Release to GitHub | ||
|
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
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
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
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
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,93 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using PAMU_CDS.Auxiliary; | ||
using Parser.ExpressionParser; | ||
using Parser.FlowParser.ActionExecutors; | ||
|
||
namespace PAMU_CDS.Actions | ||
{ | ||
public class DisAndAssociateEntitiesAction : OpenApiConnectionActionExecutorBase | ||
{ | ||
private const string AssociateId = "AssociateEntities"; | ||
private const string DisassociateId = "DisassociateEntities"; | ||
public static readonly string[] OperationId = {AssociateId, DisassociateId}; | ||
|
||
private readonly IOrganizationService _organizationService; | ||
|
||
public DisAndAssociateEntitiesAction( | ||
IExpressionEngine expressionEngine, | ||
OrganizationServiceContext organizationServiceContext) : base(expressionEngine) | ||
{ | ||
_organizationService = organizationServiceContext?.GetOrganizationService() ?? | ||
throw new ArgumentNullException(nameof(organizationServiceContext)); | ||
} | ||
|
||
|
||
public override Task<ActionResult> Execute() | ||
{ | ||
var entity = new Entity(); | ||
entity = entity.CreateEntityFromParameters(Parameters); | ||
|
||
OrganizationRequest associateRequest; | ||
|
||
switch (Host.OperationId) | ||
{ | ||
case AssociateId: | ||
{ | ||
var relatedEntity = ExtractEntityReferenceFromOdataId("item/@odata.id"); | ||
associateRequest = new AssociateRequest | ||
{ | ||
Target = entity.ToEntityReference(), | ||
Relationship = new Relationship(Parameters["associationEntityRelationship"].GetValue<string>()), | ||
RelatedEntities = new EntityReferenceCollection {relatedEntity} | ||
}; | ||
break; | ||
} | ||
case DisassociateId: | ||
{ | ||
var relatedEntity = ExtractEntityReferenceFromOdataId("$id"); | ||
|
||
associateRequest = new DisassociateRequest | ||
{ | ||
Target = entity.ToEntityReference(), | ||
Relationship = new Relationship(Parameters["associationEntityRelationship"].GetValue<string>()), | ||
RelatedEntities = new EntityReferenceCollection {relatedEntity} | ||
}; | ||
break; | ||
} | ||
default: | ||
throw new PowerAutomateException( | ||
$"Action {nameof(DisAndAssociateEntitiesAction)} can only handle {AssociateId} and {DisassociateId} operations, not {Host.OperationId}."); | ||
} | ||
|
||
try | ||
{ | ||
// TODO: Figure out how this handle bad associations and error handling. | ||
// assignees: thygesteffensen | ||
_organizationService.Execute(associateRequest); | ||
} | ||
catch (InvalidPluginExecutionException exp) | ||
{ | ||
// We need to do some experiments on how the error handling works. Take a look at one of your customers. | ||
return Task.FromResult(new ActionResult | ||
{ActionStatus = ActionStatus.Failed, ActionExecutorException = exp}); | ||
} | ||
|
||
return Task.FromResult(new ActionResult {ActionStatus = ActionStatus.Succeeded}); | ||
} | ||
|
||
private EntityReference ExtractEntityReferenceFromOdataId(string itemKey) | ||
{ | ||
// https://dglab6.crm4.dynamics.com/api/data/v9.1/contacts(8c711383-b933-eb11-a813-000d3ab11761) | ||
|
||
var oDataId = Parameters[itemKey].GetValue<string>(); | ||
var entityName = | ||
oDataId.Substring(oDataId.LastIndexOf('/') + 1, oDataId.IndexOf('(') - oDataId.LastIndexOf('/') - 2); | ||
var entityId = oDataId.Substring(oDataId.IndexOf('(') + 1, oDataId.IndexOf(')') - oDataId.IndexOf('(') - 1); | ||
|
||
return new EntityReference(entityName, new Guid(entityId)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.