示例#1
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";
        }
示例#2
0
文件: Expiry.cs 项目: xxjeng/nuxleus
        public Notification ProcessNotification(Notification n, INotificationIndex index)
        {
            DateTime ExpiryLimit = limitDate;

            if (hoursToAdd > 0.0)
            {
                ExpiryLimit = (DateTime.Now).AddHours(hoursToAdd);
            }

            if (n.Expires.Value < ExpiryLimit)
            {
                return n;
            }

            return null;
        }
示例#3
0
 /// <summary>
 /// Simply returns the passed notification.
 /// </summary>
 /// <return>
 /// Returns the notification as-is.
 /// </return>
 public Notification ProcessNotification ( Notification n, INotificationIndex index ) {
     return n;
 }
示例#4
0
 private void BlipReceived ( Notification n ) {
     if (index != null) {
         index.Index(n);
     }
     // If the Notification is valid then we 
     // we send it to the connected routers.
     n = filter.ProcessNotification(n, index);
     if (n != null) {
         SendToAll(n);
     }
 }
示例#5
0
 /// <summary>
 /// Sends the notification to all connected clients.
 /// </summary>
 private void SendToAll ( Notification n ) {
     if (clients.Count > 0) {
         byte[] blip = Notification.Serialize(n);
         int loopSleep = 0;
         foreach (ISocketConnection client in clients) {
             try {
                 client.BeginSend(blip);
             } finally {
                 ThreadEx.LoopSleep(ref loopSleep);
             }
         }
     }
 }
示例#6
0
 /// <summary>
 /// Notify that a notification is ready to be processed.
 /// </summary>
 public void Post ( Notification n ) {
     if (Mailbox != null) {
         Mailbox(n);
     }
 }
示例#7
0
 public static byte[] Serialize ( Notification notification, Encoding encoding ) {
     return encoding.GetBytes(notification.ToString());
 }
示例#8
0
 public static byte[] Serialize ( Notification notification ) {
     return Encoding.UTF8.GetBytes(notification.ToString());
 }