public void When_a_request_is_called_Queueitem_Is_Removed()
        {
            var context = new XrmFakedContext();

            var queueItem = new Entity
            {
                LogicalName = Crm.QueueItem.EntityLogicalName,
                Id          = Guid.NewGuid()
            };

            context.Initialize(new[]
            {
                queueItem
            });

            var executor = new RemoveFromQueueRequestExecutor();

            var req = new RemoveFromQueueRequest
            {
                QueueItemId = queueItem.Id
            };

            executor.Execute(req, context);

            var retrievedQueueItem = context.Data[Crm.QueueItem.EntityLogicalName].Values;

            Assert.True(!retrievedQueueItem.Any());
        }
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Retrieve all queueitems with inactive phone calls from a queue.
        /// Delete all inactive phone call entity instances.
        /// Optionally delete any entity records that were created for this sample.
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        /// </summary>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
                                                                    serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    CreateRequiredRecords();


                    // Retrieve the queueitem with inactive phone calls from a queue
                    RemoveFromQueueRequest removeFromQueueRequest = new RemoveFromQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    _serviceProxy.Execute(removeFromQueueRequest);


                    Console.WriteLine("Inactive phonecalls have been deleted from the queue.");

                    DeleteRequiredRecords(promptForDelete);
                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
        public void When_a_request_without_QueueItem_is_called_exception_is_raised()
        {
            var context  = new XrmFakedContext();
            var executor = new RemoveFromQueueRequestExecutor();
            var req      = new RemoveFromQueueRequest();

            Assert.Throws <FaultException <OrganizationServiceFault> >(() => executor.Execute(req, context));
        }
示例#4
0
        /// <summary>
        /// Remove a <c>Queue Item</c> from a <c>Queue</c>.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.removefromqueuerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="queueItemId"><c>Queue Item</c> Id</param>
        /// <returns><see cref="RemoveFromQueueResponse"/></returns>
        public RemoveFromQueueResponse Remove(Guid queueItemId)
        {
            ExceptionThrow.IfGuidEmpty(queueItemId, "queueItemId");

            RemoveFromQueueRequest request = new RemoveFromQueueRequest()
            {
                QueueItemId = queueItemId
            };

            return((RemoveFromQueueResponse)this.OrganizationService.Execute(request));
        }
示例#5
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Retrieve all queueitems with inactive phone calls from a queue.
        /// Delete all inactive phone call entity instances.
        /// Optionally delete any entity records that were created for this sample.
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        /// </summary>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {

                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
                                                                     serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    CreateRequiredRecords();


                    //<snippetCleanUpQueueItems1>
                    // Retrieve the queueitem with inactive phone calls from a queue            
                    RemoveFromQueueRequest removeFromQueueRequest = new RemoveFromQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    _serviceProxy.Execute(removeFromQueueRequest);

                    //</snippetCleanUpQueueItems1>  

                    Console.WriteLine("Inactive phonecalls have been deleted from the queue.");

                    DeleteRequiredRecords(promptForDelete);

                }
            }
            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
        [STAThread] // Added to support UX
        static void Main(string[] args)
        {
            CrmServiceClient service = null;

            try
            {
                service = SampleHelpers.Connect("Connect");
                if (service.IsReady)
                {
                    #region Sample Code
                    //////////////////////////////////////////////
                    #region Set up
                    SetUpSample(service);
                    #endregion Set up
                    #region Demonstrate

                    // Retrieve the queueitem with inactive phone calls from a queue
                    var removeFromQueueRequest = new RemoveFromQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    service.Execute(removeFromQueueRequest);


                    Console.WriteLine("Inactive phonecalls have been deleted from the queue.");

                    #region Clean up
                    CleanUpSample(service);
                    #endregion Clean up
                }
                #endregion Demonstrate
                #endregion Sample Code
                else
                {
                    const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Microsoft Dataverse";
                    if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR))
                    {
                        Console.WriteLine("Check the connection string values in cds/App.config.");
                        throw new Exception(service.LastCrmError);
                    }
                    else
                    {
                        throw service.LastCrmException;
                    }
                }
            }
            catch (Exception ex)
            {
                SampleHelpers.HandleException(ex);
            }

            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }