示例#1
0
            /// <summary>
            /// This method is called when a message is posted to the Azure Service Bus.
            /// </summary>
            /// <param name="context">Data for the request.</param>
            /// <returns>A 'Success' string.</returns>
            public string Execute(RemoteExecutionContext context)
            {
                Utility.Print(context);

                // This is the return value that can be used within Dynamics
                return("Success");
            }
示例#2
0
        public void ProcessMessages()
        {
            while (true)
            {
                Console.Write("Press [Enter] to retrieve a message from the message buffer (type quit to exit): ");
                string line = Console.ReadLine();

                if (!string.IsNullOrEmpty(line) & amp; &amp; string.Equals(line, "quit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                try
                {
                    // Retrieve a message from the message buffer.
                    Console.WriteLine("Waiting fom a message from the message buffer... ");
                    Message retrievedMessage = this.client.PeekLock();

                    // Check if the message was sent from Microsoft Dynamics CRM.
                    if (retrievedMessage.Headers.Action ==
                        "http://schemas.microsoft.com/xrm/2011/Contracts/IServiceEndpointPlugin/Execute")
                    {
                        Utility.Print(retrievedMessage.GetBody <RemoteExecutionContext>());
                        this.client.DeleteLockedMessage(retrievedMessage);
                    }
                    else
                    {
                        // The message did not originate from Microsoft Dynamics CRM.
                        this.client.ReleaseLock(retrievedMessage);
                    }
                }
                catch (System.TimeoutException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                catch (System.ServiceModel.FaultException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
        }
示例#3
0
 /// <summary>
 /// This method is called when a message is posted to the Azure Service Bus.
 /// </summary>
 /// <param name="context">Data for the request.</param>
 /// <returns>A 'Success' string.</returns>
 public string Execute(RemoteExecutionContext context)
 {
     Utility.Print(context);
     return("Success");
 }
 public void Execute(RemoteExecutionContext context)
 {
     Utility.Print(context);
 }
        public void ProcessMessages()
        {
            // Get receive mode (PeekLock or ReceiveAndDelete) from queueClient.
            ReceiveMode mode = this.queueClient.Mode;

            while (true)
            {
                Console.Write("Press [Enter] to retrieve a message from the queue (type quit to exit): ");
                string line = Console.ReadLine();

                if (!string.IsNullOrEmpty(line) && string.Equals(line, "quit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                // Retrieve a message from the queue.
                Console.WriteLine("Waiting for a message from the queue... ");
                BrokeredMessage message;
                try
                {
                    message = this.queueClient.Receive();
                    // Check if the message received.
                    if (message != null)
                    {
                        try
                        {
                            // Verify EntityLogicalName and RequestName message properties
                            // to only process specific message sent from Microsoft Dynamics CRM.
                            string keyRoot = "http://schemas.microsoft.com/xrm/2011/Claims/";
                            string entityLogicalNameKey = "EntityLogicalName";
                            string requestNameKey       = "RequestName";
                            object entityLogicalNameValue;
                            object requestNameValue;
                            message.Properties.TryGetValue(keyRoot + entityLogicalNameKey, out entityLogicalNameValue);
                            message.Properties.TryGetValue(keyRoot + requestNameKey, out requestNameValue);

                            // Filter message with specific message properties. i.e. EntityLogicalName=letter and RequestName=Create
                            if (entityLogicalNameValue != null && requestNameValue != null)
                            {
                                if (entityLogicalNameValue.ToString() == "letter" && requestNameValue.ToString() == "Create")
                                {
                                    Console.WriteLine("--------------------------------");
                                    Console.WriteLine(string.Format("Message received: Id = {0}", message.MessageId));
                                    // Display message properties that are set on the brokered message.
                                    Utility.PrintMessageProperties(message.Properties);
                                    // Display body details.
                                    Utility.Print(message.GetBody <RemoteExecutionContext>());
                                    Console.WriteLine("--------------------------------");
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                            // If receive mode is PeekLock then set message complete to remove message from queue.
                            if (mode == ReceiveMode.PeekLock)
                            {
                                message.Complete();
                            }
                        }
                        catch (System.Exception ex)
                        {
                            // Indicate a problem, unlock message in queue.
                            if (mode == ReceiveMode.PeekLock)
                            {
                                message.Abandon();
                            }
                            Console.WriteLine(ex.Message);
                            continue;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                catch (System.TimeoutException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                catch (System.ServiceModel.FaultException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
        }