| | | 1 | | #if FAKE_XRM_EASY_2013 || FAKE_XRM_EASY_2015 || FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9 |
| | | 2 | | |
| | | 3 | | using Microsoft.Crm.Sdk.Messages; |
| | | 4 | | using Microsoft.Xrm.Sdk; |
| | | 5 | | using Microsoft.Xrm.Sdk.Query; |
| | | 6 | | using System; |
| | | 7 | | using System.Linq; |
| | | 8 | | using System.ServiceModel; |
| | | 9 | | |
| | | 10 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | | 11 | | { |
| | | 12 | | public class PickFromQueueRequestExecutor : IFakeMessageExecutor |
| | | 13 | | { |
| | | 14 | | public bool CanExecute(OrganizationRequest request) |
| | 5 | 15 | | { |
| | 5 | 16 | | return request is PickFromQueueRequest; |
| | 5 | 17 | | } |
| | | 18 | | |
| | | 19 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| | 20 | 20 | | { |
| | 20 | 21 | | var pickFromQueueRequest = (PickFromQueueRequest)request; |
| | | 22 | | |
| | 20 | 23 | | var queueItemId = pickFromQueueRequest.QueueItemId; |
| | 20 | 24 | | var workerid = pickFromQueueRequest.WorkerId; |
| | | 25 | | |
| | 20 | 26 | | if ((queueItemId == Guid.Empty) || (workerid == Guid.Empty)) |
| | 0 | 27 | | { |
| | 0 | 28 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Expected non-empty G |
| | | 29 | | } |
| | | 30 | | |
| | 20 | 31 | | var service = ctx.GetOrganizationService(); |
| | | 32 | | |
| | 20 | 33 | | var query = new QueryByAttribute("systemuser"); |
| | 20 | 34 | | query.Attributes.Add("systemuserid"); |
| | 20 | 35 | | query.Values.Add(workerid); |
| | | 36 | | |
| | 20 | 37 | | var worker = service.RetrieveMultiple(query).Entities.FirstOrDefault(); |
| | 20 | 38 | | if (worker == null) |
| | 5 | 39 | | { |
| | 5 | 40 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("Invali |
| | | 41 | | } |
| | | 42 | | |
| | 15 | 43 | | query = new QueryByAttribute("queueitem"); |
| | 15 | 44 | | query.Attributes.Add("queueitemid"); |
| | 15 | 45 | | query.Values.Add(queueItemId); |
| | | 46 | | |
| | 15 | 47 | | var queueItem = service.RetrieveMultiple(query).Entities.FirstOrDefault(); |
| | 15 | 48 | | if (queueItem == null) |
| | 5 | 49 | | { |
| | 5 | 50 | | throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("queuei |
| | | 51 | | } |
| | | 52 | | |
| | 10 | 53 | | if (pickFromQueueRequest.RemoveQueueItem) |
| | 5 | 54 | | { |
| | 5 | 55 | | service.Delete("queueitem", queueItemId); |
| | 5 | 56 | | } |
| | | 57 | | else |
| | 5 | 58 | | { |
| | 5 | 59 | | var pickUpdateEntity = new Entity |
| | 5 | 60 | | { |
| | 5 | 61 | | LogicalName = "queueitem", |
| | 5 | 62 | | Id = queueItem.Id, |
| | 5 | 63 | | Attributes = new AttributeCollection |
| | 5 | 64 | | { |
| | 5 | 65 | | { "workerid", worker.ToEntityReference() }, |
| | 5 | 66 | | { "workeridmodifiedon", DateTime.Now }, |
| | 5 | 67 | | } |
| | 5 | 68 | | }; |
| | | 69 | | |
| | 5 | 70 | | service.Update(pickUpdateEntity); |
| | 5 | 71 | | } |
| | | 72 | | |
| | 10 | 73 | | return new PickFromQueueResponse(); |
| | 10 | 74 | | } |
| | | 75 | | |
| | | 76 | | public Type GetResponsibleRequestType() |
| | 3597 | 77 | | { |
| | 3597 | 78 | | return typeof(PickFromQueueRequest); |
| | 3597 | 79 | | } |
| | | 80 | | } |
| | | 81 | | } |
| | | 82 | | |
| | | 83 | | #endif |