Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Kopaev committed Dec 11, 2019
1 parent e75c1ec commit 94787cd
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 6 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,23 @@ Workflow
<td>Getting the GUID of the Account entity.</td>
</tr>
<tr>
<td>:new: Add Account to Marketing List</td>
<td>Добавление организации в маркетинговый список.</td>
</tr>
<tr>
<td>:new: Add Contact to Marketing List</td>
<td>Добавление контакта в маркетинговый список.</td>
</tr>
<tr>
<td>:new: Add Lead to Marketing List</td>
<td>Добавление интереса в маркетинговый список.</td>
</tr>
<tr>
<td>Create Annotation</td>
<td>Create annotation for any entity.</td>
</tr>
<tr>
<td>:new: Create Annotation with Text File</td>
<td>Create Annotation with Text File</td>
<td>Create annotation with text file attachment for any entity.</td>
</tr>
<tr>
Expand Down Expand Up @@ -177,11 +189,11 @@ Workflow
<td>Действие возвращает сущность "Валюта" (transactioncurrency) для указанного GUID.</td>
</tr>
<tr>
<td>:new: GUID to E-mail</td>
<td>GUID to E-mail</td>
<td>Действие возвращает сущность "E-mail" (email) для указанного GUID.</td>
</tr>
<tr>
<td>:new: GUID to Fax</td>
<td>GUID to Fax</td>
<td>Действие возвращает сущность "Факс" (fax) для указанного GUID.</td>
</tr>
<tr>
Expand All @@ -193,7 +205,7 @@ Workflow
<td>Действие возвращает сущность "Интерес" (lead) для указанного GUID.</td>
</tr>
<tr>
<td>:new: GUID to Letter</td>
<td>GUID to Letter</td>
<td>Действие возвращает сущность "Письмо" (letter) для указанного GUID.</td>
</tr>
<tr>
Expand Down Expand Up @@ -221,7 +233,7 @@ Workflow
<td>Действие возвращает сущности "Предложение" (quote) и "Продукт предложения" (quotedetail) для указанного GUID.</td>
</tr>
<tr>
<td>:new: GUID to Task</td>
<td>GUID to Task</td>
<td>Действие возвращает сущность "Задача" (task) для указанного GUID.</td>
</tr>
<tr>
Expand All @@ -237,7 +249,7 @@ Workflow
<td>Действие возвращает сущность "Бизнес-процесс" (workflow) для указанного GUID.</td>
</tr>
<tr>
<td>:new: Parse Entity Dynamic URL</td>
<td>Parse Entity Dynamic URL</td>
<td>Parsing the dynamic URL and getting the parameters of the entity.</td>
</tr>
</table>
Expand Down
4 changes: 4 additions & 0 deletions Source/Tools/Entity/Entity/Entity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Workflow\AddAccountToList.cs" />
<Compile Include="Workflow\AddContactToList.cs" />
<Compile Include="Workflow\AddEntityToList.cs" />
<Compile Include="Workflow\AddLeadToList.cs" />
<Compile Include="Workflow\CreateAnnotation.cs" />
<Compile Include="Workflow\EntityToGuid.cs" />
<Compile Include="Workflow\GuidToAccount.cs" />
Expand Down
29 changes: 29 additions & 0 deletions Source/Tools/Entity/Entity/Workflow/AddAccountToList.cs
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);
}
}
}
29 changes: 29 additions & 0 deletions Source/Tools/Entity/Entity/Workflow/AddContactToList.cs
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);
}
}
}
35 changes: 35 additions & 0 deletions Source/Tools/Entity/Entity/Workflow/AddEntityToList.cs
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 }
});
}
}
}
29 changes: 29 additions & 0 deletions Source/Tools/Entity/Entity/Workflow/AddLeadToList.cs
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);
}
}
}
1 change: 1 addition & 0 deletions Source/Tools/FetchXML/FetchXML/FetchXML.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<Compile Include="Workflow\AssignUser.cs" />
<Compile Include="Workflow\Average.cs" />
<Compile Include="Workflow\Concat.cs" />
<Compile Include="Workflow\Delete.cs" />
<Compile Include="Workflow\ExecuteWorkflowFromFetch.cs" />
<Compile Include="Workflow\Count.cs" />
<Compile Include="Workflow\Median.cs" />
Expand Down
1 change: 1 addition & 0 deletions Source/Tools/FetchXML/FetchXML/Workflow/AssignOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using PZone.Xrm.Workflow;
using PZone.Xrm;


namespace PZone.FetchXmlTools.Workflow
{
public abstract class AssignOwner : FetchXmlWorkflow
Expand Down
82 changes: 82 additions & 0 deletions Source/Tools/FetchXML/FetchXML/Workflow/Delete.cs
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));
}
}
}

0 comments on commit 94787cd

Please sign in to comment.