GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
UnitOfWork.cs
1// =============================================================================
2// GPAL - Generally Positive Automation Library
3// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4//
5// This file is part of GPAL.
6// Licensed under the Business Source License 1.1
7//
8// Primary development, architecture, and vision by Michael B. Vederman,
9// CEO of Software Decisions, Inc., Texas.
10//
11// Internal development maintained privately.
12// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13//
14// See LICENSE for full terms, including Additional Use Grant.
15// =============================================================================
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.Threading.Tasks;
22using System.Windows.Forms;
23using System.Windows.Automation;
24using OpenQA.Selenium;
25using static GenerallyPositive.Enums;
29
30
31namespace GenerallyPositive
32{
38 public class UnitOfWork
39 {
45 public List<Selector> WithSelectorList { get; internal set; } = null;
46
47 // list of IN (nested) selectors defined
53 public List<Selector> InSelectorList { get; internal set; } = null;
58 public Selector CurrentSelector { get; internal set; } = null;
66 public Selector NextPageButton { get; internal set; } = null;
74 public bool InfiniteScroll { get; internal set; } = false;
80 public int PageCount { get; internal set; } = 1;
81
89 internal IGPALGrid<string> RetGrid { get; set; } = null;
96 public List<string> TokenList { get; internal set; } = null;
97
101 internal class WebElementWithType
102 {
103 internal Selector selector;
104 internal GPALElement gPalElement;
105 internal ElementType elementType;
106 internal bool currentNode;
107
108 internal WebElementWithType(Selector selector, GPALElement webElement, ElementType elementType)
109 {
110 this.gPalElement = webElement;
111 this.elementType = elementType;
112 this.currentNode = true;
113 this.selector = selector;
114 }
115 }
116 internal List<WebElementWithType> ContextPath { get; set; }
117 // TODO: make gpalsearchcontext and inherit from isearchcontext
118 internal GPALElement ShadowRoot { get; set; }
119 // response bodies from .Fetch, one per page per row of tokens, in the order they were requested
120 internal List<string> FetchResults { get; set; } = new List<string>();
121 // rows of values .Fetch drops into the request's numbered tokens, one row per set of requests
122 internal IGPALGrid<string> FetchTokens { get; set; }
123// internal GPALElement ShadowRootGPALElement { get; set; }
124
125 internal class ElementNode
126 {
127 public AutomationElement AutomationElement { get; internal set; }
128 public Control ControlElement { get; internal set; }
129 public GPALElement GPALElement { get; internal set; }
130 public InteractionType InteractionType { get; internal set; } = InteractionType.Selenium;
131 public int OffsetX { get; internal set; } = 0;
132 public int OffsetY { get; internal set; } = 0;
133 }
134 // data grid of elements rows and columns
135 // used with FillInFrom
136 // used with FillInFromTokens
137 internal GPALGrid<UnitOfWork.ElementNode> ElementGrid { get; set; } = null;
145 public List<string> HeaderList { get; internal set; } = null;
146 internal SortedDictionary<int, string> MatchedRowIndexes { get; set; } = null;
153 public bool PartialMatch { get; internal set; } = false;
154
155 // toggles, if BrowserAction is called, the next WithSelector will start a new UOW (old UOW saved but no longer in scope)
161 public bool ActionCalled { get; internal set; } = false;
165 internal bool GetGridCalled { get; set; } = false;
171 public int WithAllThatMatch { get; internal set; } = int.MaxValue; // all rows, default
178 internal WaitTime WaitForInMs { get; set; } = WaitTime.Never;
184 internal DateTime? WaitForSatisfied { get; set; } = null;
185 internal string WaitForTitle { get; set; } = null;
186 internal string WaitForTitleRegex { get; set; } = null;
187 internal ElementState WaitForElementState { get; set; } = ElementState.NotSet;
188
189 internal int ColCount { get; set; } = 0;
190 internal int RowCount { get; set; } = 0;
191
192 internal Browser.Browser.CallAfterFillInDelegate CallAfterFillIn { get; set; }
193 internal List<CallIfDelegate> CallIfFound { get; set; }
194 internal List<CallIfDelegate> CallIfNotFound { get; set; }
195 internal Application.Application.CallAfterFillInDelegate AppCallAfterFillIn { get; set; }
196 internal List<Application.Application.CallIfDelegate> AppCallIfFound { get; set; }
197 internal List<Application.Application.CallIfDelegate> AppCallIfNotFound { get; set; }
198
199 public CallIfStatus CallIfFoundHandled { get; internal set; } = CallIfStatus.NotHandled;
200 public CallIfStatus CallIfNotFoundHandled { get; internal set; } = CallIfStatus.NotHandled;
201 public CallIfStatus AppCallIfFoundHandled { get; internal set; } = CallIfStatus.NotHandled;
202 public CallIfStatus AppCallIfNotFoundHandled { get; internal set; } = CallIfStatus.NotHandled;
203
210 public GPALFile InputFile { get; internal set; }
217 public IGPALDatabase InputDatabase { get; internal set; }
218
219 public Browser.Browser Browser { get; internal set; }
220
221 internal UnitOfWork()
222 {
223 WithSelectorList = new List<Selector>();
224 InSelectorList = new List<Selector>();
225 HeaderList = new List<string>();
226 CallIfFound = new List<CallIfDelegate>();
227 CallIfNotFound = new List<CallIfDelegate>();
228 AppCallIfFound = new List<Application.Application.CallIfDelegate>();
229 AppCallIfNotFound = new List<Application.Application.CallIfDelegate>();
230 MatchedRowIndexes = new SortedDictionary<int, string>();
231 ElementGrid = new GPALGrid<UnitOfWork.ElementNode>();
232 ContextPath = new List<WebElementWithType>();
233 WaitForInMs = GPAL.GPALSettings.WaitForInMs; // if globally defined, then set the 'default' waitfor time
234 ShadowRoot = null;
235 RetGrid = GPAL.GridForType<string>();
236 }
237
238 }
239}
240
Browser object that contains the fluent methods to create your Browser workflow. Instatiated using G...
Definition Browser.cs:68
Pseudo element used in Applications and Browser workflows for image matching and unified automation....
GPAL File object instantied with GPAL.File Used to load tokens into a GPALGrid [rows/columns].
Definition GPALFile.cs:36
GPAL Selector used to locate Application and Browser elements. Instantiated with GPAL....
Definition Selector.cs:56
Everything revolves around the Unit of Work. A Unit of Work is defined as one or more selectors betw...
Definition UnitOfWork.cs:39
int WithAllThatMatch
Controls whether the selectors in scope are multiple elements on screen, and to get all Use ....
IGPALDatabase InputDatabase
The input database from which to consume tokens. This is set using any [Append/FillIn/Insert]FromDat...
List< string > HeaderList
Output header list, Defined using .WithHeader or, if not supplied, from the names given to selectors....
List< Selector > InSelectorList
List of iframe or shadow dom selectors. Set using .InFrame() or .InShadowDom() Use ....
Definition UnitOfWork.cs:53
Selector NextPageButton
The next page button. When scraping multiple pages of results, this element is pressed for a new page...
Definition UnitOfWork.cs:66
List< Selector > WithSelectorList
List of With selectors Use .WithSelector to add selectors to this list.
Definition UnitOfWork.cs:45
List< string > TokenList
Input data grid retrieved from a file or database. A grid is rows and columns. Each column value is ...
Definition UnitOfWork.cs:96
int PageCount
Number of pages to retrieve. Default is 1 page. Use .WithPages() to set this value.
Definition UnitOfWork.cs:80
bool PartialMatch
Only relevant if there is a match criteria or matching function. Of all the found selectors,...
bool ActionCalled
Has an action been called on the current unit of work? If true, then the next .WithSelector() will c...
Selector CurrentSelector
The current selector being used from the current UOW. The selectors are iterated in declared order.
Definition UnitOfWork.cs:58
bool InfiniteScroll
Go to page end to get the next page of results. Use with .WithPages() to retrieve multiple pages of ...
Definition UnitOfWork.cs:74
GPALFile InputFile
The input File from which to consume tokens. This is set using any [Append/FillIn/Insert]FromFile me...