Пример #1
0
        private async Task OpenAndMeasure(bool hasDialog, int numRetries)
        {
            // Take screenshot.
            Bitmap before = proc.TakeScreenshot().Result;

            // Open window.
            await RawOpen(hasDialog);

            // Take screenshot.
            Bitmap after = proc.TakeScreenshot().Result;

            // Process images.
            window = GraphicsUtils.FindWindow(before, after);
            var tabBar = GraphicsUtils.ToLightmap(after, window.X, window.Y, TabBarWidth, window.Height);

            tabBar = GraphicsUtils.Erode(tabBar, TabBarWidth, window.Height, 3);
            var blobs = GraphicsUtils.FindBlobs(tabBar, TabBarWidth, window.Height);

            // Validate.
            if (blobs.Count < 2 || blobs.Count > 15 || blobs[0].Count < 800 || blobs[0].X0 != 0 || blobs[0].Y0 != 0)
            {
                if (numRetries == 0)
                {
                    throw new Exception("Vendor Window validation failed for all retries.");
                }
                else
                {
                    input.Escape();
                    await Task.Delay(500);
                    await OpenAndMeasure(hasDialog, numRetries - 1);

                    return;
                }
            }

            if (blobs.Count > 2)
            {
                tabX       = window.X + (blobs[1].X0 + blobs[1].X1) / 2;
                tabY       = window.Y + (blobs[1].Y0 + blobs[1].Y1) / 2;
                tabDy      = (blobs[2].Y0 + blobs[2].Y1) / 2 - (blobs[1].Y0 + blobs[1].Y1) / 2;
                itemX      = tabX + ItemOffsetFromTabX;
                itemY      = tabY;
                itemDy     = tabDy * 228 / 264;
                isMeasured = true;
            }
        }