Exemple #1
0
        void Dequeue(object arg)
        {
            Uri bufferAddress = arg as Uri;

            Debug.Assert(bufferAddress != null);

            MessageBufferClient bufferClient = MessageBufferClient.GetMessageBuffer(m_Credential, bufferAddress);

            while (true)
            {
                Message message = null;

                try
                {
                    message = bufferClient.Retrieve();
                }
                catch (TimeoutException)
                {
                    Trace.WriteLine("Timed out before retirieving message");
                    continue;
                }
                if (message.Headers.Action == CloseAction)
                {
                    return;
                }
                else
                {
                    Dispatch(message);
                }
            }
        }
 private static String GetMove(MessageBufferClient bufferClient)
 {
     String move;
     using (Message moveMessage = bufferClient.Retrieve())
     {
         move = moveMessage.GetBody<String>();
     }
     Console.WriteLine("{0} <- {1}", bufferClient.MessageBufferUri.LocalPath[1], move);
     return move;
 }
Exemple #3
0
        private string RetrieveMessage(MessageBufferClient client)
        {
            System.ServiceModel.Channels.Message retrievedMessage = null;;

            try
            {
                retrievedMessage = client.Retrieve();

                return(retrievedMessage.GetBody <string>());
            }
            finally
            {
                if (retrievedMessage != null)
                {
                    retrievedMessage.Close();
                }
            }
        }
Exemple #4
0
        void Dequeue(object arg)
        {
            Uri bufferAddress = arg as Uri;

            Debug.Assert(bufferAddress != null);

            MessageBufferClient bufferClient = MessageBufferClient.GetMessageBuffer(m_Credential, bufferAddress);

            while (true)
            {
                Message message = bufferClient.Retrieve();
                if (message.Headers.Action == CloseAction)
                {
                    return;
                }
                else
                {
                    Dispatch(message);
                }
            }
        }
Exemple #5
0
        //internal static string CustomEntityName = "new_isvactivityverifier";
        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.InitiatingUserId);

            ServiceBusListener  serviceBusListener  = new ServiceBusListener();
            MessageBufferClient messageBufferClient = serviceBusListener.GetMessageBufferClient();

            Message message = null;

            try
            {
                message = messageBufferClient.Retrieve();
            }
            catch (FaultException)
            {
                //MessageBufferClient.Retrieve() will throw a timeout exception, if there are no packets to retrieve. So, do not throw if it is a TimeOutException.
                //if (!(fe.Message.Contains("Message could not be retrieved")))
                //{
                //    throw fe;
                //}
                //continue;
            }
            catch (Exception)
            {
                //MessageBufferClient.Retrieve() will throw a timeout exception, if there are no packets to retrieve. So, do not throw if it is a TimeOutException.
                //if (!(ex.GetType().Name.Equals("TimeoutException") &amp;&amp; ex.Message.Equals("Message could not be retrieved: RequestTimeout, Request Timeout")))
                //{
                //    throw ex;
                //}
                //continue;
            }

            foreach (MessageHeader header in message.Headers)
            {
                if (header.Name != "SecurityToken")
                {
                    continue;
                }

                StringBuilder sb     = new StringBuilder();
                var           writer = XmlWriter.Create(sb);
                header.WriteHeader(writer, MessageVersion.Default);
                writer.Close();

                string headerString = sb.ToString();

                string startNode   = "<SecurityToken xmlns=\"ns\">";
                int    startIndex  = headerString.IndexOf(startNode) + startNode.Length;
                int    endIndex    = headerString.LastIndexOf("</SecurityToken>");
                string tokenString = headerString.Substring(startIndex, endIndex - startIndex);
            }

            switch (message.Headers.Action)
            {
            case "http://schemas.microsoft.com/xrm/2011/Contracts/IServiceEndpointPlugin/Execute":
                ProcessMessages(message.GetBody <RemoteExecutionContext>(), service);
                break;
                //} //end - infinite for loop
            }
        }