public void Setup() { inputQueueFormatName = Queues.TryCreate(inputQueuePath, QueueTransactional.None); adminQueueFormatName = Queues.TryCreate(adminQueuePath, QueueTransactional.None); outputQueueFormatName1 = Queues.TryCreate(outputQueuePath1, QueueTransactional.None); outputQueueFormatName2 = Queues.TryCreate(outputQueuePath2, QueueTransactional.None); deadQueueFormatName = $"{inputQueueFormatName };Poison"; Queues.Purge(inputQueueFormatName); Queues.Purge(adminQueueFormatName); input = new QueueWriter(inputQueueFormatName); dead = new QueueReader(deadQueueFormatName); dead.Purge(); outRead1 = new QueueReader(outputQueueFormatName1); outRead1.Purge(); outRead2 = new QueueReader(outputQueueFormatName2); outRead2.Purge(); outSend1 = new QueueWriter(outputQueueFormatName1); outSend2 = new QueueWriter(outputQueueFormatName2); sender = new Postman(adminQueueFormatName); }
public async Task can_route_multiple_message() { var key = Environment.TickCount; using (var router = new SubQueueRouter(testQueueFormatName, GetSubQueue)) { await router.StartAsync(); try { using (var q = new QueueWriter(testQueueFormatName)) { q.Write(new Message { Label = "my.sq", AppSpecific = key }); q.Write(new Message { Label = "my.sq", AppSpecific = key + 1 }); } using (var sq = new QueueReader(testQueueFormatName + ";sq")) { var got = sq.Read(Properties.AppSpecific, timeout: TimeSpan.FromMilliseconds(500)); Assert.AreEqual(key, got.AppSpecific); got = sq.Read(Properties.AppSpecific, timeout: TimeSpan.FromMilliseconds(500)); Assert.AreEqual(key + 1, got.AppSpecific); } } finally { await router.StopAsync(); } } }
static void Main(string[] args) { var eventAggregator = new EventAggregator <Message>(); var projectionHost = new ProjectionHost(eventAggregator); projectionHost.SetUpProjections(); var inMemQueue = new InMemQueue <Message>(); var reader = new QueueReader <Message>(inMemQueue); eventAggregator.AttachTo(reader); var foo = new QueueWriter <Message>(inMemQueue); reader.Start(); while (true) { foo.Handle(new FooMessage()); Thread.Sleep(1000); } //var dispatcher = new ByTypeDispatcher(); //dispatcher.Subscribe(new FooHandler()); //dispatcher.Handle(new FooMessage()); }
public void Receive() { var dto = new LogEntryDTO("MyApp", "SomeTarget", new LogEntry { CreatedAt = DateTime.Now, Exception = new Exception("Something awful"), LoggedType = typeof(LogEntryDTO), MethodName = "Some", LogLevel = LogLevel.Info, Message = "No no", ThreadId = 20, UserName = "******" }); var queue = new MessageQueue(Queue.Name) { Formatter = new XmlMessageFormatter(new[] { typeof(LogEntryDTO) }) }; queue.Send(new Message(dto)); var receiver = new Receiver(); var listenr = new QueueReader(Queue.Name, receiver); receiver.Event.WaitOne(1000); Assert.NotEmpty(receiver.Entries); var entry = receiver.Entries.First(); Assert.Equal("Arnwe", entry.UserName); Assert.Equal("No no", entry.Message); }
private void RegistermSmsServices(ContainerBuilder builder) { var smsQueue = new AzureQueueExt(_settings.Db.ClientPersonalInfoConnString, "smsqueue"); var smsQueueReader = new QueueReader(smsQueue, "SmsQueueReader", 3000, _log); builder.Register <IQueueReader>(x => smsQueueReader).SingleInstance(); builder.RegisterType <TemplateGenerator>().As <ITemplateGenerator>(); builder.RegisterType <SmsTextGenerator>().As <ISmsTextGenerator>().SingleInstance(); if (_settings.Sms.UseMocks) { builder.RegisterType <SmsMockSender>().As <ISmsSender>().SingleInstance(); builder.RegisterType <AlternativeSmsMockSender>().As <IAlternativeSmsSender>().SingleInstance(); } else { builder.RegisterInstance(_settings.Sms.Nexmo) .SingleInstance(); builder.RegisterType <NexmoSmsSender>().As <ISmsSender>().SingleInstance(); builder.RegisterInstance(_settings.Sms.Twilio) .SingleInstance(); builder.RegisterType <TwilioSmsSender>().As <IAlternativeSmsSender>().SingleInstance(); } }
private void Read() { try { using (FileStream _compressedFile = new FileStream(SourceFile, FileMode.Open)) { while (_compressedFile.Position < _compressedFile.Length) { byte[] lengthBuffer = new byte[8]; //8 _compressedFile.Read(lengthBuffer, 0, lengthBuffer.Length); int blockLength = BitConverter.ToInt32(lengthBuffer, 4); //4 byte[] compressedData = new byte[blockLength]; lengthBuffer.CopyTo(compressedData, 0); _compressedFile.Read(compressedData, 8, blockLength - 8); int _dataSize = BitConverter.ToInt32(compressedData, blockLength - 4);//-4 byte[] lastBuffer = new byte[_dataSize]; ByteBlock _block = new ByteBlock(_counter, lastBuffer, compressedData); QueueReader.EnqueueForWriting(_block); _counter++; ConsoleProgress.ProgressBar(_compressedFile.Position, _compressedFile.Length); } QueueReader.Stop(); } } catch (Exception ex) { Console.WriteLine(ex.Message); Cancelled = true; } }
private void Decompress(object i) { try { while (!Cancelled) { ByteBlock _block = QueueReader.Dequeue(); if (_block == null) { return; } using (MemoryStream ms = new MemoryStream(_block.CompressedBuffer)) { using (GZipStream _gz = new GZipStream(ms, CompressionMode.Decompress)) { _gz.Read(_block.Buffer, 0, _block.Buffer.Length); byte[] decompressedData = _block.Buffer.ToArray(); ByteBlock block = new ByteBlock(_block.ID, decompressedData); QueueWriter.EnqueueForWriting(block); } } } } catch (Exception ex) { Console.WriteLine("Error in thread number {0}. \n Error description: {1}", i, ex.Message); Cancelled = true; } }
private void Compress(object i) { try { while (!Cancelled) { ByteBlock _block = QueueReader.Dequeue(); if (_block == null) { return; } using (MemoryStream _memoryStream = new MemoryStream()) { using (GZipStream cs = new GZipStream(_memoryStream, CompressionMode.Compress)) { cs.Write(_block.Buffer, 0, _block.Buffer.Length); } byte[] compressedData = _memoryStream.ToArray(); ByteBlock _out = new ByteBlock(_block.ID, compressedData); QueueWriter.EnqueueForWriting(_out); } WaitHandle doneEvent = DoneEvents[(int)i]; doneEvent.Dispose(); } } catch (Exception ex) { Console.WriteLine("Ошибка в номере потока {0}. \n описание ошибки: {1}", i, ex.Message); Cancelled = true; } }
public async Task can_remove_subscription() { using (var requestWriter = new QueueWriter(requestFN)) using (var replyReader = new QueueReader(replyFN)) { var addReq = new Message { AppSpecific = (int)PubSubAction.Add, ResponseQueue = replyFN }; addReq.BodyUTF8("thing.one" + Environment.NewLine + "thing.two"); requestWriter.Write(addReq); var removeReq = new Message { AppSpecific = (int)PubSubAction.Remove, ResponseQueue = replyFN }; removeReq.BodyUTF8("thing.one"); requestWriter.Write(removeReq); var listReq = new Message { AppSpecific = (int)PubSubAction.List, ResponseQueue = replyFN }; requestWriter.Write(listReq); var got = replyReader.Read(timeout: TimeSpan.FromSeconds(3)); Assert.IsNotNull(got); Assert.AreEqual("thing.two", got.BodyUTF8()); } }
private void RegisterEmailServices(ContainerBuilder builder) { var emailsQueue = new AzureQueueExt(_settings.Db.ClientPersonalInfoConnString, "emailsqueue"); var internalEmailQueueReader = new QueueReader(emailsQueue, "InternalEmailQueueReader", 3000, _log); var blockChainEmailQueue = new AzureQueueExt(_settings.Db.BitCoinQueueConnectionString, "emailsqueue"); var blockChainEmailQueueReader = new QueueReader(blockChainEmailQueue, "BlockchainEmailQueueReader", 3000, _log); var sharedEmailQueue = new AzureQueueExt(_settings.Db.SharedStorageConnString, "emailsqueue"); var sharedEmailQueueReader = new QueueReader(sharedEmailQueue, "SharedEmailQueueReader", 3000, _log); builder.Register <IEnumerable <IQueueReader> >(x => new List <IQueueReader> { internalEmailQueueReader, blockChainEmailQueueReader, sharedEmailQueueReader }) .SingleInstance(); builder.RegisterType <EmailGenerator>() .As <IEmailGenerator>() .SingleInstance() .WithParameters(new [] { TypedParameter.From(_settings.Email), TypedParameter.From(_settings.Blockchain), TypedParameter.From(_settings.WalletApi) }); builder.RegisterType <HttpRequestClient>(); builder.RegisterType <RemoteTemplateGenerator>() .As <IRemoteTemplateGenerator>() .SingleInstance() .WithParameter(TypedParameter.From(_settings.Email.EmailTemplatesHost)); builder.RegisterType <SwiftCredentialsService>().As <ISwiftCredentialsService>().SingleInstance(); SmtpClient ClientFactory() { var client = new SmtpClient { Timeout = 10000 }; client.Connect(_settings.Email.SmtpHost, _settings.Email.SmtpPort); client.Authenticate(new NetworkCredential(_settings.Email.SmtpLogin, _settings.Email.SmtpPwd)); return(client); } var from = new MailboxAddress(_settings.Email.EmailFromDisplayName, _settings.Email.EmailFrom); if (_settings.Email.UseMocks) { builder.RegisterType <SmtpMailSenderMock>().SingleInstance(); builder.Register(x => new SmtpMailSender(_log, ClientFactory, from, x.Resolve <IBroadcastMailsRepository>())); builder.RegisterType <MockAndRealMailSender>().As <ISmtpEmailSender>().SingleInstance(); } else { builder.Register <ISmtpEmailSender>(x => new SmtpMailSender(_log, ClientFactory, from, x.Resolve <IBroadcastMailsRepository>())); } }
public void Setup() { destFormatName = Queues.TryCreate(destQueuePath, QueueTransactional.Transactional); adminFormatName = Queues.TryCreate(adminQueuePath, QueueTransactional.None); Queues.Purge(destFormatName); dest = new QueueWriter(destFormatName); admin = new QueueReader(adminFormatName); admin.Purge(); }
public Task <Task> StartAsync() { _input = new QueueReader(InputQueueFormatName); _admin = new QueueReader(AdminQueueFormatName); _cache = new Cache <string, Message>(CacheGen0Limit, CacheTimeToLive); _mainTask = RunAsync(); _adminTask = AdminAsync(); return(Task.FromResult(_mainTask)); }
public void TestInitialize() { dataAccess = new Mock <IBusDataAccess>(); log = new Mock <ILog <QueueReader> >(); perfCounters = new Mock <IPerfCounters>(); serializer = new Mock <ISerializer>(); clock = new Mock <ISystemClock>(); clock.SetupGet(x => x.UtcNow) .Returns(new DateTime(2022, 2, 22, 14, 22, 22, 222, DateTimeKind.Utc)); dataAccess.Setup(d => d.Update(It.IsAny <QueueMessage>(), It.IsAny <string>())) .Callback <QueueMessage, string>((m, q) => { UpdatedMessage = m; UpdatedQueue = q; }) .Returns(Task.CompletedTask); dataAccess.Setup(d => d.Insert(It.IsAny <SagaData>(), It.IsAny <string>())) .Callback <SagaData, string>((d, n) => { InsertedSagaData = d; InsertedSagaName = n; }) .Returns(Task.FromResult <long>(12345)); dataAccess.Setup(d => d.Update(It.IsAny <SagaData>(), It.IsAny <string>())) .Callback <SagaData, string>((d, n) => { UpdatedSagaData = d; UpdatedSagaName = n; }) .Returns(Task.CompletedTask); dataAccess.Setup(d => d.FailMessage(It.IsAny <QueueMessage>(), It.IsAny <string>())) .Callback <QueueMessage, string>((d, n) => { FailedMessage = d; FailedQueue = n; }) .Returns(Task.CompletedTask); dataAccess.Setup(d => d.CompleteMessage(It.IsAny <QueueMessage>(), It.IsAny <string>())) .Callback <QueueMessage, string>((d, n) => { CompletedMessage = d; CompletedQueue = n; }) .Returns(Task.CompletedTask); serializer.Setup(s => s.SerializeSaga(It.IsAny <object>(), typeof(TestSagaData))) .Returns("SerializedTestSagaData"); reader = new QueueReader(dataAccess.Object, log.Object, perfCounters.Object, serializer.Object, clock.Object); }
public Task <Task> StartAsync() { _input = new QueueReader(_inputFormatName); if (Queues.IsTransactional(_input.FormatName) == QueueTransactional.Transactional) { _transaction = QueueTransaction.Single; } _running = RunAsync(); return(Task.FromResult(_running)); }
public RequestReply(string requestQueueFormantName, string replyQueueFormatName, Postman postman) { Contract.Requires(postman != null); Contract.Requires(requestQueueFormantName != null); Contract.Requires(replyQueueFormatName != null); _requestQueue = new QueueWriter(requestQueueFormantName); _responseQueue = new QueueReader(replyQueueFormatName); _postman = postman; }
public Task <Task> StartAsync() { _clientRequestReader = new QueueReader(ClientRequestQueueFormatName, share: QueueShareReceive.ExclusiveReceive); _inputReader = new QueueReader(MulticastInputQueueFormatName); _adminReader = new QueueReader(_adminQueueFormatName, share: QueueShareReceive.ExclusiveReceive); _subscriptionTask = SubscriptionLoop(); _dispatcherTask = MulticastInputDispatcher(); _adminTask = AdminTask(); return(Task.FromResult(_subscriptionTask)); }
public void QueueReaderFileWrongVersionTest() { const string filePath = "wrong_version.dat"; using (var fileStream = File.Create(filePath, 7168)) { fileStream.Write(new byte[7168], 0, 7168); } Assert.Throws <NotSupportedException>(() => QueueReader.ReadQueue(filePath)); File.Delete(filePath); }
public void QueueReaderFileWrongLengthTest() { const string filePath = "wrong_length.dat"; using (var fileStream = File.Create(filePath, 7000)) { fileStream.Write(new byte[7000], 0, 7000); } Assert.Throws <IOException>(() => QueueReader.ReadQueue(filePath)); File.Delete(filePath); }
private QueueReader CreateQueue(Node node, BufferTree tree, QueueIndex queue) { QueueReader reader = new QueueReader(node) { Index = queue, }; tree.Queues.Add(reader); this.AddWritersAndProperties(node, reader, tree, queue); return(reader); }
private void Server(int count) { using (var requestQ = new QueueReader(requestQueueFormatName)) using (var replyQ = new QueueWriter(replyQueueFormatName)) { for (int i = 0; i < count; i++) { var msg = requestQ.Read(Properties.All, TimeSpan.FromSeconds(0.5)); msg.CorrelationId = msg.Id; replyQ.Write(msg); } } }
public Expression GetReadWriteExpression(QueueReader reader) { Expression parentValue = this.GetQueuePropertyExpression(reader.Index, "List"); Expression body = this.GetReadWriteExpression(reader, parentValue); if (reader.Index.Type == RelationQueueType.Cached && reader.Index.Cache.Any()) { body = this.GetCacheExpression(reader.Index, body); } Expression queueIndex = this.GetQueueIndexExpression(reader.Index); Expression assignVariable = Expression.Assign(reader.Index.Variable, queueIndex); return(this.GetBlockOrExpression(new[] { assignVariable, body }, new[] { reader.Index.Variable })); }
private void MoveToPoisonSubqueue(QueueReader fromQueue, long lookupId, QueueTransaction transaction) { Contract.Requires(fromQueue != null); if (_posionQueue == null) { _posionQueue = new SubQueue(InputQueueFormatName + ";" + UnroutableSubQueue); } try { Queues.MoveMessage(fromQueue, _posionQueue, lookupId, transaction); return; } catch (QueueException e) { Console.Error.WriteLine($"WARN Failed to move message {{lookupId={lookupId}}} {{subqueue={UnroutableSubQueue}}} {{error={e.Message}}}"); } }
private QueueData ReadQueueFile(string path) { // Make sure the queue file exists first. Would like to avoid the exception overhead. if (File.Exists(path)) { // queue.dat is not required to get a reading // if something goes wrong just catch and log try { return(QueueReader.ReadQueue(path)); } catch (Exception ex) { Logger.WarnFormat(ex, Constants.ClientNameFormat, Settings.Name, ex.Message); } } return(null); }
public async Task can_route_many() { using (var input = new QueueWriter(testQueueFormatName)) using (var out1 = new QueueReader(testQueueFormatName + ";one")) using (var out2 = new QueueReader(testQueueFormatName + ";two")) using (var router = new SubQueueRouter(testQueueFormatName, GetSubQueue)) { out1.Purge(); out2.Purge(); for (int i = 0; i < 1000; i++) { input.Write(new Message { Label = "1", AppSpecific = i }); input.Write(new Message { Label = "2", AppSpecific = i }); } var sw = new Stopwatch(); sw.Start(); var rtask = router.StartAsync(); try { for (int i = 0; i < 1000; i++) { var got = out1.Read(Properties.Label | Properties.AppSpecific); Assert.AreEqual("1", got.Label, "Label"); Assert.AreEqual(i, got.AppSpecific, "AppSpecific"); got = out2.Read(Properties.Label | Properties.AppSpecific); Assert.AreEqual("2", got.Label, "Label"); Assert.AreEqual(i, got.AppSpecific, "AppSpecific"); } sw.Stop(); } finally { await router.StopAsync(); } Console.WriteLine($"Reading 2000 routed messages took {sw.ElapsedMilliseconds:N0} MS"); } }
static void Main(string[] args) { VerifyQueuesExistAndEmpty(); var splitter = new Splitter(SPLITTER_QUEUE, PASSENGER_INFO_QUEUE, LUGGAGE_QUEUE); splitter.BeginReceive(); QueueReader.BeginReceive(PASSENGER_INFO_QUEUE, OnPassengerMessageReceived); QueueReader.BeginReceive(LUGGAGE_QUEUE, OnLuggageMessageReceived); var flightDetails = CreateFlightDetails(); SPLITTER_QUEUE.Send(new Message(flightDetails)); Console.ReadLine(); CleanUp(); }
static void Main(string[] args) { VerifyQueuesExistAndEmpty(); var publisher = new Publisher(PUBLISH_QUEUE, CLIENTS); QueueReader.BeginReceive(CLIENT_A, WriteToConsole); QueueReader.BeginReceive(CLIENT_B, WriteToConsole); QueueReader.BeginReceive(CLIENT_C, WriteToConsole); publisher.BeginReceive(); PUBLISH_QUEUE.Send(new Message(new PublishedMessage { Body = "Published information" })); Console.ReadLine(); CleanUp(); }
static void Main(string[] args) { VerifyQueuesExistAndEmpty(); var router = new Router(ROUTER_QUEUE, CLIENTS); QueueReader.BeginReceive(CLIENT_A, WriteToConsole); QueueReader.BeginReceive(CLIENT_B, WriteToConsole); QueueReader.BeginReceive(CLIENT_C, WriteToConsole); router.BeginReceive(); var messages = new List <RoutedMessage> { new RoutedMessage { Sender = CLIENT_A.Path, Destination = CLIENT_B.Path, Body = "Message from A to B" }, new RoutedMessage { Sender = CLIENT_A.Path, Destination = CLIENT_C.Path, Body = "Message from A to C" }, new RoutedMessage { Sender = CLIENT_B.Path, Destination = CLIENT_A.Path, Body = "Message from B to A" }, new RoutedMessage { Sender = CLIENT_B.Path, Destination = CLIENT_C.Path, Body = "Message from B to C" }, new RoutedMessage { Sender = CLIENT_C.Path, Destination = CLIENT_A.Path, Body = "Message from C to A" }, new RoutedMessage { Sender = CLIENT_C.Path, Destination = CLIENT_B.Path, Body = "Message from C to B" }, }; foreach (var m in messages) { ROUTER_QUEUE.Send(new Message(m)); } Console.ReadLine(); CleanUp(); }
public static EngagementResult GetEngagement(EngagementRequest request) { EngagementResult result = new EngagementResult(); string agentId = request.AgentId; var agentItem = AgentReader.GetAgentItems().First(i => i.AgentId.Equals(agentId, StringComparison.OrdinalIgnoreCase)); string[] queues = agentItem.QueueList; string queueId = queues[0]; QueueItem queueItem = QueueReader.GetQueueItems().First(q => q.QueueId.Equals(queueId, StringComparison.OrdinalIgnoreCase)); AgentEngagementManager engagementManager = new AgentEngagementManager(); int freeMinutes = engagementManager.CalculateFreeMinutes(agentId, queueItem); result.FreeMinutes = freeMinutes; result.Items = EngagementReader.GetEngagementItems(freeMinutes); return(result); }
public void can_peek_when_opened_with_move_acces() { var fn = Queues.TryCreate(".\\private$\\subqtest", QueueTransactional.None); var sqfn = fn + ";sq"; using (var qWriter = new QueueWriter(fn)) { qWriter.Write(new Message { AppSpecific = 234 }); } using (var qReader = new QueueReader(fn)) using (var subQueue = new SubQueue(sqfn)) { var msg = qReader.Peek(Properties.LookupId); Queues.MoveMessage(qReader, subQueue, msg.LookupId); var got = subQueue.Read(); Assert.AreEqual(234, got.AppSpecific); } }
private async Task <int> PerformReads(string queueName) { ParmCheck.NotNullOrEmpty(nameof(queueName), queueName); int numRead = 0; var options = new JsonSerializerOptions { WriteIndented = true }; var reader = new QueueReader(_connectionString, queueName); FishObservation observation = await reader.Read <FishObservation>(); while (observation != null) { numRead++; Console.WriteLine(JsonSerializer.Serialize(observation, typeof(FishObservation), options)); observation = await reader.Read <FishObservation>(); } return(numRead); }
/*private static void EnqueueShortAsBytes(ByteWriter output, short value) { //output.WriteByteShort(value); //output.Enqueue((byte)(value >> 8)); //output.Enqueue((byte)(value & 0xFF)); }*/ private static short DequeueShortAsBytes(QueueReader<byte> input) { return (short)((input.Dequeue() << 8) | input.Dequeue()); }
public static short[,] DecompressWorld(bool iDeflated, byte[] data) { QueueReader<byte> input; short[,] world; short[] cornerBlocks; short width; short height; input = new QueueReader<byte>(data); width = DequeueShortAsBytes(input); height = DequeueShortAsBytes(input); world = new short[width, height]; cornerBlocks = new short[2*width + 2*height - 4]; DecompressQuadTree(world, input, 1, 1, (short)(width - 1), (short)(height - 1)); DecompressBinaryTree(cornerBlocks, input, 0, (short)cornerBlocks.Length); // Put corner blocks to the world. short i = 0; short j = width; short k = 0; for (; i < j; i++) // top { world[i, 0] = cornerBlocks[i]; } k = j; j += width; for (; i < j; i++) // bottom { world[i - k, 199] = cornerBlocks[i]; } k = (short)(j - 1); j += (short)(height - 2); for (; i < j; i++) // left { world[0, i - k] = cornerBlocks[i]; } k = (short)(j - 1); j += (short)(height - 2); for (; i < j; i++) // right { world[199, i - k] = cornerBlocks[i]; } return world; }
//public static void DecompressQuadTree(short[,] output, QueueReader<byte> input, short x, short y, short width, short height) public static void DecompressQuadTree(short[,] output, QueueReader<byte> input, short x1, short y1, short x2, short y2) { short width = (short)(x2 - x1); short height = (short)(y2 - y1); short middleX; short middleY; int binaryDataByte; //byte id; if (width == 0 || height == 0) return; if (width <= 2 && height <= 2) { for (int yy = y1; yy < y2; yy++) //output[x, y] = input.Dequeue(); { for (int xx = x1; xx < x2; xx++) output[xx, yy] = (short)((input.Dequeue()<<8) | input.Dequeue()); } return; } middleX = (short)(x1 + (width >> 1));//(x1) - (x1+x2 >> 1); middleY = (short)(y1 + (height >> 1));//(y1) - (y1+y2 >> 1); binaryDataByte = input.Dequeue(); Action<byte> lambda = new Action<byte>(b => { short l_x1; short l_y1; short l_x2; short l_y2; short l_id; switch (b) { case 0: l_x1 = x1; l_y1 = y1; l_x2 = middleX; l_y2 = middleY; break; case 1: l_x1 = middleX; l_y1 = y1; l_x2 = x2; l_y2 = middleY; break; case 2: l_x1 = x1; l_y1 = middleY; l_x2 = middleX; l_y2 = y2; break; case 3: //strong x, strong y l_x1 = middleX; l_y1 = middleY; l_x2 = x2; l_y2 = y2; break; default: throw new Exception(b.ToString() + " is an invalid quadtree child index. It can only be 0,1,2 or 3."); } if ((binaryDataByte & (1 << b)) == (1 << b)) { l_id = DequeueShortAsBytes(input); for (int yy = l_y1; yy < l_y2; yy++) { for (int xx = l_x1; xx < l_x2; xx++) output[xx, yy] = l_id; } } else { DecompressQuadTree(output, input, l_x1, l_y1, l_x2, l_y2); } }); lambda(0); lambda(1); lambda(2); lambda(3); }
public static void DecompressBinaryTree(short[] output, QueueReader<byte> input, short start, short end) { short length = (short)(start - end); short middle; //tells if the children are simple(true) or complex(false). byte binaryDataByte; short id; if (length <= 2) { if (length == 0) return; if (length == 1) { output[start] = DequeueShortAsBytes(input); } else // length must be 2 { output[start] = DequeueShortAsBytes(input); output[start + 1] = DequeueShortAsBytes(input); } return; } middle = (short)(start + length / 2); binaryDataByte = input.Dequeue(); if ((binaryDataByte & 1) == 1) { id = DequeueShortAsBytes(input); for (int i = start; i < middle; i++) output[i] = id; } else { DecompressBinaryTree(output, input, start, middle); } if ((binaryDataByte & 2) == 2) { id = DequeueShortAsBytes(input); for (int i = middle; i < end; i++) output[i] = id; } else { DecompressBinaryTree(output, input, middle, end); } }
public void Receive() { var dto = new LogEntryDTO("MyApp", "SomeTarget", new LogEntry { CreatedAt = DateTime.Now, Exception = new Exception("Something awful"), LoggedType = typeof (LogEntryDTO), MethodName = "Some", LogLevel = LogLevel.Info, Message = "No no", ThreadId = 20, UserName = "******" }); var queue = new MessageQueue(Queue.Name) {Formatter = new XmlMessageFormatter(new[] {typeof (LogEntryDTO)})}; queue.Send(new Message(dto)); var receiver = new Receiver(); var listenr = new QueueReader(Queue.Name, receiver); receiver.Event.WaitOne(1000); Assert.NotEmpty(receiver.Entries); var entry = receiver.Entries.First(); Assert.Equal("Arnwe", entry.UserName); Assert.Equal("No no", entry.Message); }