-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPluginQueries.cs
More file actions
97 lines (90 loc) · 4.16 KB
/
Copy pathPluginQueries.cs
File metadata and controls
97 lines (90 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Generator.DTO;
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Data;
namespace Generator.Queries;
public static class PluginQueries
{
public static async Task<IEnumerable<SDKStep>> GetSDKMessageProcessingStepsAsync(this ServiceClient service, List<Guid>? solutionIds = null)
{
// Retrieve the SDK Message Processing Step entity using the componentId
var query = new QueryExpression("solutioncomponent")
{
ColumnSet = new ColumnSet("objectid"),
Criteria = new FilterExpression(LogicalOperator.And)
{
Conditions =
{
new ConditionExpression("solutionid", ConditionOperator.In, solutionIds),
new ConditionExpression("componenttype", ConditionOperator.Equal, 92)
}
},
LinkEntities =
{
new LinkEntity(
"solutioncomponent",
"sdkmessageprocessingstep",
"objectid",
"sdkmessageprocessingstepid",
JoinOperator.Inner)
{
Columns = new ColumnSet("sdkmessageprocessingstepid", "name", "filteringattributes", "sdkmessageid", "statecode"),
EntityAlias = "step",
LinkEntities =
{
new LinkEntity(
"sdkmessageprocessingstep",
"sdkmessagefilter",
"sdkmessagefilterid",
"sdkmessagefilterid",
JoinOperator.LeftOuter)
{
Columns = new ColumnSet("primaryobjecttypecode"),
EntityAlias = "filter"
},
new LinkEntity(
"sdkmessageprocessingstep",
"sdkmessage",
"sdkmessageid",
"sdkmessageid",
JoinOperator.Inner)
{
Columns = new ColumnSet("name"),
EntityAlias = "message"
}
//new LinkEntity
//{
// LinkFromEntityName = "sdkmessageprocessingstep",
// LinkFromAttributeName = "plugintypeid",
// LinkToEntityName = "plugintype",
// LinkToAttributeName = "plugintypeid",
// Columns = new ColumnSet("name"),
// EntityAlias = "plugintype"
//}
}
}
}
};
//if (solutionIds is not null) query.Criteria.Conditions.Add(new ConditionExpression("solutionid", ConditionOperator.In, solutionIds));
var result = await service.RetrieveAllAsync(query);
var steps = result.Select(e =>
{
var sdkMessageId = e.GetAttributeValue<AliasedValue>("step.sdkmessageid")?.Value as EntityReference;
var sdkStepName = e.GetAttributeValue<AliasedValue>("step.name")?.Value as string;
var sdkFilterAttributes = e.GetAttributeValue<AliasedValue>("step.filteringattributes")?.Value as string;
var sdkState = e.GetAttributeValue<AliasedValue>("step.statecode")?.Value as OptionSetValue;
var filterTypeCode = e.GetAttributeValue<AliasedValue>("filter.primaryobjecttypecode")?.Value as string;
var sdkMessageName = e.GetAttributeValue<AliasedValue>("message.name")?.Value as string;
return new SDKStep(
sdkMessageId?.Id.ToString() ?? "Unknown",
sdkStepName ?? "Unknown Name",
sdkFilterAttributes ?? "",
filterTypeCode ?? "Unknown",
sdkMessageName ?? "Unknown",
sdkState ?? new OptionSetValue(0)
);
});
return steps;
}
}