Пример #1
0
        public static List <TOCScreenshot> ReadTOC(string TOCPath)
        {
            if (string.IsNullOrWhiteSpace(TOCPath) || !File.Exists(TOCPath))
            {
                throw new ArgumentException("Blank or non-existant path given", nameof(TOCPath));
            }

            try
            {
                var          res = new List <TOCScreenshot>();
                XSSFWorkbook tocWorkbook;
                var          sheetNames = new List <string>();
                using (FileStream file = new FileStream(TOCPath, FileMode.Open, FileAccess.Read))
                {
                    tocWorkbook = new XSSFWorkbook(file);
                    for (int i = 1; i < tocWorkbook.NumberOfSheets; i++)
                    {
                        sheetNames.Add(tocWorkbook.GetSheetName(i));
                    }
                }
                var tocChoices = new ExcelMapper(@TOCPath)
                {
                    TrackObjects = false
                };
                foreach (var sheetName in sheetNames)
                {
                    var screenshot = new TOCScreenshot()
                    {
                        Filename = $"{sheetName}.png"
                    };
                    screenshot.Choices = tocChoices.Fetch <TOCChoice>(sheetName).ToList();
                    res.Add(screenshot);
                }

                return(res);
            }
            catch (Exception x)
            {
                x.Data.Add(nameof(TOCPath), TOCPath);
                throw;
            }
        }
Пример #2
0
            internal static void ExamineSearchResult(SearchResult result, List <TOCScreenshot> screenshotsSettings, string resultPrefix)
            {
                TOCScreenshot screenshotSettings = null;
                TOCChoice     choice             = null;

                try
                {
                    //step0: setup
                    CurrentDriver.Navigate().GoToUrl(result.ResultUrl);
                    LoadSite(result.ResultUrl, IDs.Redland.Buttons["Home.Search"]);
                    ConfirmReady();
                    //#0:Hide Show TOC if it is hidden
                    //ClickField(IDs.Redland.Buttons["Home.ToggleTOC"]);
                    //

                    for (int i = 0; i < screenshotsSettings.Count; i++)
                    {
                        ShowTOCIfNotVisible();
                        var prefix = $"{resultPrefix}screenshot {i + 1} of {screenshotsSettings.Count}: ";
                        currentStep = $"{prefix}Show TOC if hidden";
                        CallUpdateStatus(currentStep);

                        screenshotSettings = screenshotsSettings[i];
                        currentStep        = $"{prefix}{screenshotSettings.Filename}";
                        CallUpdateStatus(currentStep);
                        for (int j = 0; j < screenshotSettings.Choices.Count; j++)
                        {
                            //#0:skip a whole branch of the TOC if its root is no
                            choice = screenshotSettings.Choices[j];
                            if (string.IsNullOrWhiteSpace(choice.By) || string.IsNullOrWhiteSpace(choice.Value))
                            {
                                continue;
                            }

                            if (choice.ChoiceText == "Coastal Management District")
                            {
                                1.ToString();
                            }
                            var byObject = GetBy(choice);
                            if (byObject != null)
                            {
                                var text = choice.ChoiceText;
                                if (!string.IsNullOrWhiteSpace(choice.Ticked) && Convert.ToBoolean(choice.Ticked))
                                {
                                    //#0:Why is "Road Names" not clicked here?
                                    ClickFieldIfUnchecked(byObject);
                                    currentStep = $"{prefix}Click if unchecked: {text}";
                                    CallUpdateStatus(currentStep);
                                }
                                else
                                {
                                    //#0:Hangs on this for screenshot1: result 1 of 1: screenshot 1 of 2: Click if checked: Coastal Management District
                                    //#0:Why is "Lot Numbers" not clicked here?
                                    ClickFieldIfChecked(byObject);
                                    currentStep = $"{prefix}Click if checked: {text}";
                                    CallUpdateStatus(currentStep);
                                }
                            }
                        }
                        ClickField(IDs.Redland.Buttons["Home.ToggleTOC"]);
                        ConfirmReady();
                        currentStep = $"{prefix} Waiting for charts to load";
                        CallUpdateStatus(currentStep);
                        if (!ConfirmImagesLoaded())
                        {
                            throw new ApplicationException($"{currentStep} - Charts were not loaded. A timeout may have occured");
                        }

                        currentStep = $"{prefix} saving screenshot";
                        Thread.Sleep(Engine.Variables.TOCSlidingDelay);
                        CallUpdateStatus(currentStep);
                        var imagePath = Path.Combine(result.ResultFolder, screenshotSettings.Filename);
                        TakeScreenshot(imagePath);
                    }
                }
                catch (Exception x)
                {
                    if (screenshotSettings != null)
                    {
                        x.Data.Add(nameof(screenshotSettings), screenshotSettings.ToString());
                    }
                    if (choice != null)
                    {
                        x.Data.Add(nameof(choice), choice.ToString());
                    }
                    throw;
                }
            }