All pastes #913649 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-22 06:25 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using RabbitMQ.Client;
using ClusterClient.Model;

namespace ClusterClient
{
	/// <summary>
	/// Very naive charmichael searcher. 
	/// </summary>
	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<CarmichaelWorkItem>(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<CarmichaelResult> results = new List<CarmichaelResult>();
			
			//Search the bounds of our work item
			for(BigInteger i=item.StartAt;i<item.EndAt;i++)
			{
				//First we factorize the number
				
				List<factors> 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");
			
		}
	}
}