-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roman Kopaev
committed
Dec 11, 2019
1 parent
e75c1ec
commit 94787cd
Showing
9 changed files
with
228 additions
and
6 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
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,29 @@ | ||
using System.Activities; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using PZone.Xrm.Workflow; | ||
|
||
|
||
namespace PZone.EntityTools.Workflow | ||
{ | ||
/// <summary> | ||
/// Добавление организации в маркетинговый список. | ||
/// </summary> | ||
public class AddAccountToList : AddEntityToList | ||
{ | ||
/// <summary> | ||
/// Организация. | ||
/// </summary> | ||
[RequiredArgument] | ||
[Input("Account")] | ||
[ReferenceTarget("account")] | ||
public InArgument<EntityReference> AccountRef { get; set; } | ||
|
||
|
||
/// <inheritdoc /> | ||
protected override void Execute(Context context) | ||
{ | ||
AddToList(context, AccountRef.Get(context).Id); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System.Activities; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using PZone.Xrm.Workflow; | ||
|
||
|
||
namespace PZone.EntityTools.Workflow | ||
{ | ||
/// <summary> | ||
/// Добавление контакта в маркетинговый список. | ||
/// </summary> | ||
public class AddContactToList : AddEntityToList | ||
{ | ||
/// <summary> | ||
/// Контакт. | ||
/// </summary> | ||
[RequiredArgument] | ||
[Input("Contact")] | ||
[ReferenceTarget("contact")] | ||
public InArgument<EntityReference> ContactRef { get; set; } | ||
|
||
|
||
/// <inheritdoc /> | ||
protected override void Execute(Context context) | ||
{ | ||
AddToList(context, ContactRef.Get(context).Id); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Activities; | ||
using Microsoft.Crm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using PZone.Xrm.Workflow; | ||
|
||
|
||
namespace PZone.EntityTools.Workflow | ||
{ | ||
/// <summary> | ||
// Базовый класс для добавления элементов маркетингового списка. | ||
/// </summary> | ||
public abstract class AddEntityToList : WorkflowBase | ||
{ | ||
/// <summary> | ||
/// Маркетинговый список. | ||
/// </summary> | ||
[RequiredArgument] | ||
[Input("Marketing List")] | ||
[ReferenceTarget("list")] | ||
public InArgument<EntityReference> ListRef { get; set; } | ||
|
||
|
||
protected void AddToList(Context context, Guid entityId) | ||
{ | ||
var service = context.SourceActivityContext.GetExtension<IOrganizationServiceFactory>().CreateOrganizationService(null); | ||
service.Execute(new AddListMembersListRequest | ||
{ | ||
ListId = ListRef.Get(context).Id, | ||
MemberIds = new[] { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Activities; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using PZone.Xrm.Workflow; | ||
|
||
|
||
namespace PZone.EntityTools.Workflow | ||
{ | ||
/// <summary> | ||
/// Добавление интереса в маркетинговый список. | ||
/// </summary> | ||
public class AddLeadToList : AddEntityToList | ||
{ | ||
/// <summary> | ||
/// Интерес. | ||
/// </summary> | ||
[RequiredArgument] | ||
[Input("Lead")] | ||
[ReferenceTarget("lead")] | ||
public InArgument<EntityReference> LeadRef { get; set; } | ||
|
||
|
||
/// <inheritdoc /> | ||
protected override void Execute(Context context) | ||
{ | ||
AddToList(context, LeadRef.Get(context).Id); | ||
} | ||
} | ||
} |
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,82 @@ | ||
using System; | ||
using System.Activities; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using PZone.Xrm; | ||
using PZone.Xrm.Workflow; | ||
|
||
|
||
namespace PZone.FetchXmlTools.Workflow | ||
{ | ||
public class Delete : FetchXmlWorkflow | ||
{ | ||
/// <summary> | ||
/// Количество найденных записей. | ||
/// </summary> | ||
[Output("Finded Count")] | ||
public OutArgument<int> FindedCount { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// Количество удаленных записей. | ||
/// </summary> | ||
[Output("Deleted Count")] | ||
public OutArgument<int> DeletedCount { get; set; } | ||
|
||
|
||
protected override void Execute(Context context) | ||
{ | ||
var query = FetchXml.Get(context); | ||
if (string.IsNullOrWhiteSpace(query)) | ||
return; | ||
|
||
var entities = context.Service.RetrieveMultiple(query).Entities; | ||
|
||
FindedCount.Set(context, entities.Count); | ||
|
||
if (entities.Count == 0) | ||
{ | ||
DeletedCount.Set(context, 0); | ||
return; | ||
} | ||
|
||
var request = new ExecuteMultipleRequest | ||
{ | ||
Settings = new ExecuteMultipleSettings | ||
{ | ||
ContinueOnError = false, | ||
ReturnResponses = true | ||
}, | ||
Requests = new OrganizationRequestCollection() | ||
}; | ||
request.Requests.AddRange(entities.Select(entity => new DeleteRequest | ||
{ | ||
Target = entity.ToEntityReference() | ||
})); | ||
|
||
var service = context.SourceActivityContext.GetExtension<IOrganizationServiceFactory>().CreateOrganizationService(null); | ||
|
||
var responses = (ExecuteMultipleResponse)service.Execute(request); | ||
if (!responses.IsFaulted) | ||
{ | ||
DeletedCount.Set(context, entities.Count); | ||
return; | ||
} | ||
|
||
var deletedCount = 0; | ||
var faults = new List<string>(); | ||
foreach (var response in responses.Responses) | ||
{ | ||
if (response.Fault == null) | ||
deletedCount++; | ||
else | ||
faults.Add(response.Fault.Message); | ||
} | ||
DeletedCount.Set(context, deletedCount); | ||
throw new Exception(string.Join(" ", faults)); | ||
} | ||
} | ||
} |