Beispiel #1
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate method to create any entity records that this sample requires.
        /// Remove worker from queue item to release queued object
        /// which user is working on.
        /// Optionally delete any entity records that were created for this sample.
        /// <para name="organizationFriendlyName">The friendly name of the
        /// target organization.</para>
        /// <para name="discoveryServer">The name of the discovery server.</para>
        /// <param name="promptForDelete">Indicates whether to prompt the user to delete
        /// the records created in this sample.</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();

                    // Remove worker from queue item to release queued object
                    // from worker's queue using ReleaseToQueueRequest

                    ReleaseToQueueRequest releaseToQueueRequest = new ReleaseToQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    _serviceProxy.Execute(releaseToQueueRequest);

                    Console.WriteLine("Released the queued object from worker 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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Assign a <c>Queue Item</c> back to the queue owner.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.releasetoqueuerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="queueItemId"><c>Queue Item</c> Id</param>
        /// <returns><see cref="ReleaseToQueueResponse"/></returns>
        public ReleaseToQueueResponse Release(Guid queueItemId)
        {
            ExceptionThrow.IfGuidEmpty(queueItemId, "queueItemId");

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

            return((ReleaseToQueueResponse)this.OrganizationService.Execute(request));
        }
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate method to create any entity records that this sample requires.
        /// Remove worker from queue item to release queued object
        /// which user is working on.
        /// Optionally delete any entity records that were created for this sample.
        /// <para name="organizationFriendlyName">The friendly name of the 
        /// target organization.</para>
        /// <para name="discoveryServer">The name of the discovery server.</para>
        /// <param name="promptForDelete">Indicates whether to prompt the user to delete
        /// the records created in this sample.</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();

                    //<snippetRemoveQueueItemWorker1>
                    // Remove worker from queue item to release queued object
                    // from worker's queue using ReleaseToQueueRequest

                    ReleaseToQueueRequest releaseToQueueRequest = new ReleaseToQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    _serviceProxy.Execute(releaseToQueueRequest);

                    Console.WriteLine("Released the queued object from worker queue.");
                    //</snippetRemoveQueueItemWorker1>                 

                    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;
            }
        }
Beispiel #4
0
        [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
                    // Remove worker from queue item to release queued object
                    // from worker's queue using ReleaseToQueueRequest

                    ReleaseToQueueRequest releaseToQueueRequest = new ReleaseToQueueRequest
                    {
                        QueueItemId = _queueItemId
                    };
                    service.Execute(releaseToQueueRequest);

                    Console.WriteLine("Released the queued object from worker 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();
            }
        }