private static void CreateServiceInstances(IApplicationController applicationController,
                                                   IMargin margin,
                                                   IScaleState scaleState,
                                                   out IDataService dataService,
                                                   out IScaleService scaleService,
                                                   out IBufferedDrawingService bufferedDrawingService)
        {
            dataService = new DataService();
            applicationController.RegisterInstance <IDataService>(dataService);

            scaleService = new ScaleService(scaleState, dataService, margin);
            applicationController.RegisterInstance <IScaleService>(scaleService);

            bufferedDrawingService = new BufferedDrawingService();
            applicationController.RegisterInstance <IBufferedDrawingService>(bufferedDrawingService);
        }
Beispiel #2
0
        private static IDrawing StartCreateAndDrawDataLines(int pointsNumber, bool drawInBitmap, bool runProvider)
        {
            var linesNumber = pointsNumber - 1;
            var linesToDraw = 0;
            IDataProviderService provider = null;

            TestDrawingWrapper drawingTester = null;
            DrawingBuffer      buffer        = null;
            Drawing2DWrapper   drawingBitmap = null;
            IDrawing           drawing       = null;
            var size = new Size(800, 600);

            if (drawInBitmap)
            {
                size          = new Size(8000, 4500);
                buffer        = new DrawingBuffer(size);
                drawingBitmap = new Drawing2DWrapper(buffer.Graphics);
                drawing       = drawingBitmap;
            }
            else
            {
                drawingTester = new TestDrawingWrapper(100);
                drawing       = drawingTester;
            }

            IScaleService           scaleService           = null;
            IDataService            dataService            = null;
            var                     controller             = GraphControlFactory.CreateController();
            IBufferedDrawingService bufferedDrawingService = new BufferedDrawingService();
            int                     receivedPoints         = 0;

            try
            {
                // Create all services
                provider = TestSinusDataProviderService.Create(pointsNumber);
                var view = TestDataView.Create(controller, provider, bufferedDrawingService);

                var margin  = new Margin(100, 5, 5, 60);
                var options = new DataDrawOptions(size, true, true, null, new DataDrawState());
                scaleService = controller.GetInstance <IScaleService>();
                scaleService.UpdateScale(options); // to prepare scaling service without presenter

                dataService = controller.GetInstance <IDataService>();

                dataService.DataUpdated += (sender, e) =>
                {
                    scaleService.UpdateScale(options);
                    drawingTester?.Reset();
                    view.Draw(drawing, options, margin);
                    receivedPoints += e.Items.Count;
                };

                if (pointsNumber > 0)
                {
                    provider.Run();

                    // Wait to draw at least test points
                    while (receivedPoints < pointsNumber)
                    {
                        Thread.Sleep(0);
                    }
                }
                else
                {
                    view.Draw(drawing, options, margin);
                }

                linesToDraw = dataService.GetItems(scaleService.State.X1, scaleService.State.X2).Count();
            }
            finally
            {
                bufferedDrawingService.Dispose();
            }

            Assert.IsTrue(bufferedDrawingService.LastQueueOverflow.Ticks == 0, $"drawing queue overflow, last time: {bufferedDrawingService.LastQueueOverflow.ToLongTimeString()}");

            Assert.IsTrue(linesToDraw == pointsNumber,
                          $"dataService.GetItems({new DateTime((long)scaleService.State.X1 * TimeSpan.TicksPerMillisecond).ToString("HH:mm:ss.fff")}"
                          + $", {new DateTime((long)scaleService.State.X1 * TimeSpan.TicksPerMillisecond).ToString("HH:mm:ss.fff")}) {linesToDraw} ({dataService.ItemCount}) != generated points {pointsNumber}");

            if (!drawInBitmap)
            {
                Assert.IsTrue(drawingTester.Lines.Count >= linesNumber, $"lines count is {drawingTester.Lines.Count} less than {linesNumber}");
            }

            return(drawing);
        }