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"; }
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; }
/// <summary> /// Simply returns the passed notification. /// </summary> /// <return> /// Returns the notification as-is. /// </return> public Notification ProcessNotification ( Notification n, INotificationIndex index ) { return n; }
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); } }
/// <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); } } } }
/// <summary> /// Notify that a notification is ready to be processed. /// </summary> public void Post ( Notification n ) { if (Mailbox != null) { Mailbox(n); } }
public static byte[] Serialize ( Notification notification, Encoding encoding ) { return encoding.GetBytes(notification.ToString()); }
public static byte[] Serialize ( Notification notification ) { return Encoding.UTF8.GetBytes(notification.ToString()); }