Exemplo n.º 1
0
        public static void Enqueue ( MessageEvent me ) {
            if (!run) {
                throw new InvalidOperationException("The pool is not running");
            }

            messages.Enqueue(me);
        }
Exemplo n.º 2
0
        private static string Push (string queueName, string message) {
            // Notification
            Notification n = new Notification();
            n.Action = "publish";
            n.Expires = DateTime.Now.AddHours(1);
            n.Categories = new Category[2];
            n.Categories[0] = new Category();
            n.Categories[0].Term = message;
            n.Categories[1] = new Category();
            n.Categories[1].Term = "indie";

            // The actual Queue Message to send
            Message pm = new Message();
            pm.Op.Type = OperationType.PushMessage;
            pm.QueueId = queueName;

            Console.WriteLine(queueName);
            Console.WriteLine(n.ToString());
            pm.Payload = Convert.ToBase64String(Notification.Serialize(n));

            // An event handler
            MessageEvent me = new MessageEvent();
            me.Message = pm;
            // Let's see what the response of the server was
            me.MessageReceived += new MessageEventHandler(queue_MessageReceived);

            QueueClientPool.Enqueue(me);

            return "message sent";
        }
Exemplo n.º 3
0
 /// <summary> 
 /// Asynchronously read from the queue and put the content into 
 /// the provided MessageState.
 /// </summary>   
 public static void AsyncRecv ( MessageEvent ms ) {
     if (ms.Client == null) {
         throw new InvalidOperationException("The 'Client' property must be set");
     }
     ms.Client.Socket.BeginReceive(ms.Buffer, 0, ms.BufferSize, 0,
                   new AsyncCallback(ReceiveCallback), ms);
 }
Exemplo n.º 4
0
 public static void AsyncSend ( MessageEvent me ) {
     if (me.Client == null) {
         throw new InvalidOperationException("The 'Client' property must be set");
     }
     string message = String.Format("{0}\r\n\r\n", me.Message.ToString());
     byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
     me.Client.Socket.BeginSend(data, 0, data.Length, 0,
                new AsyncCallback(SendCallback), me);
 }