using System; using System.Collections.Generic; using System.Text; using RabbitMQ.Client; using ClusterClient.Model; namespace ClusterClient { /// /// Very naive charmichael searcher. /// public class CarmichaelChannel : ClusterClient { public CarmichaelChannel(string queueName, string exchangeName,string routingKey,IConnection connection) : base(queueName, exchangeName,routingKey, connection) { } //Called when we have a new work item. protected override void OnMessage(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body) { CarmichaelWorkItem item = ClusterClient.Deserialize(body); Console.WriteLine("Got new carmichael work item:"); Console.WriteLine("Lower bound: {0}",item.StartAt.ToString()); Console.WriteLine("Upper bound: {0}",item.EndAt.ToString()); List results = new List(); //Search the bounds of our work item for(BigInteger i=item.StartAt;i factors = Factorize(i); if(IsCarmichaelNumber(i, factors)) { //add carmichael number to results list CarmichaelResult result = new CarmichaelResult(); //The actual carmichael number result.CarmichaelNumber = i; //Factors so server can test result result.Factors = factors; results.Add(result); } } //Send results this.Send(results,properties.ReplyToAddress.RoutingKey,"Noreply"); } } }