예제 #1
0
        protected void Publish(string url)
        {
            using (var mqClient = _mQServer.CreateMessageQueueClient())
            {
                BusMirror.TryAdd(url, false);
                mqClient.Publish(new Url {
                    Path = url,
                });

                // Now wait for the response
                IMessage <UrlResponse> responseMsg = mqClient.Get <UrlResponse>(QueueNames <UrlResponse> .In, TimeSpan.FromSeconds(180));
                mqClient.Ack(responseMsg);
                var response = responseMsg.GetBody();

                // Log response
                _writer.Write(response.Response);

                // Parse for new links
                if (!_options.IgnoreLinks)
                {
                    Add(response.Links);
                }

                // Update the BusMirror to reflect processing is complete
                BusMirror.TryUpdate(url, true, false);
                if (Progress != null)
                {
                    Progress(this, new ProgressEventArgs {
                        Count = BusMirror.Count, Remaining = QueueSize
                    });
                }
            }
        }
예제 #2
0
        public void Draw(IWriterService writerService)
        {
            if (_lastRemovedPoint.HasValue)
            {
                writerService.SetWritePosition(_lastRemovedPoint.Value.Y, _lastRemovedPoint.Value.X);
                writerService.WriteLine(" ");
            }

            if (_isFirstDraw)
            {
                foreach (var p in _activePoints)
                {
                    writerService.SetWritePosition(p.Y, p.X);
                    writerService.Write("S");
                }

                _isFirstDraw = false;
            }

            writerService.SetWritePosition(HeadCoordinates.Y, HeadCoordinates.X);
            writerService.Write("S");
            writerService.SetWritePosition(32, 0);
        }
예제 #3
0
        public void Draw(IWriterService writerService)
        {
            writerService.Clear();
            var border = new string('#', BottomRightCoordinates.X - UpperLeftCoordinates.X);

            writerService.SetWritePosition(UpperLeftCoordinates.Y, UpperLeftCoordinates.X);
            writerService.WriteLine(border);
            for (int i = UpperLeftCoordinates.Y + 1; i < BottomRightCoordinates.Y - 1; i++)
            {
                writerService.SetWritePosition(i, UpperLeftCoordinates.X);
                writerService.Write("#");
                writerService.SetWritePosition(i, BottomRightCoordinates.X - 1);
                writerService.WriteLine("#");
            }

            writerService.WriteLine(border);
        }
예제 #4
0
파일: Game.cs 프로젝트: andre197/SnakeGame
        private void SpawnNewFood()
        {
            var random = new Random();

            while (true)
            {
                var x = random.Next(_gameArea.UpperLeftCoordinates.X + 1, _gameArea.BottomRightCoordinates.X - 1);
                var y = random.Next(_gameArea.UpperLeftCoordinates.Y + 1, _gameArea.BottomRightCoordinates.Y - 1);

                var foodPoint = new Point(x, y);

                if (_snake.ActivePoints.Any(p => p == foodPoint) || _snake.HeadCoordinates == foodPoint)
                {
                    continue;
                }

                _foodPosition = foodPoint;
                _writerService.SetWritePosition(foodPoint.Y, foodPoint.X);
                _writerService.Write("*");
                break;
            }
        }
예제 #5
0
 /// <summary>
 /// <para>Write using the default encoding <see cref="Encoding.Default"/></para>
 /// <para>This extension will be available to all implementers of <see cref="IWriterService"/></para>
 /// </summary>
 public static void Write(this IWriterService writer, string content)
 {
     writer.Write(content, Encoding.Default);
 }
예제 #6
0
 public void SaveToFile(IWriterService writerService)
 {
     writerService.Write(_animals);
 }