71 if (
null == process ||
true == process.HasExited || IntPtr.Zero == process.MainWindowHandle)
76 IntPtr foreground = GetForegroundWindow();
78 if (process.MainWindowHandle == foreground)
return;
83 GetWindowThreadProcessId(foreground, out
int owner);
85 if (owner == process.Id)
return;
95 ShowWindow(process.MainWindowHandle, 1);
104 SetForegroundWindow(process.MainWindowHandle);
111 GPAL.
PublishSimpleEvent(GPALEventType.EXCEPTION, $
"Unable to top process [{process.ProcessName}], attempting a hardware click to top.",
null, GPALObjectType.None, ex);
113 GetWindowRect(process.MainWindowHandle, out rect);
114 HardwareHelper.HardwareClick(rect.X + 10, rect.Y + 10, ClickType.LeftClick);
118 GPAL.
PublishSimpleEvent(GPALEventType.EXCEPTION, $
"Unable to top process, unable to get process information using GetWindowRect.",
null, GPALObjectType.None, ex);
135 List<ReadOnlyCollection<GPALAutomationElement>> rowsOfColumns =
new List<ReadOnlyCollection<GPALAutomationElement>>();
136 List<ReadOnlyCollection<GPALAutomationElement>> rowsOfElements =
new List<ReadOnlyCollection<GPALAutomationElement>>();
139 List<SmallSelectorNode> interactionInfo =
new List<SmallSelectorNode>();
148 rowsOfElements.Clear();
149 rowsOfColumns.Clear();
150 application.CurrentUOW.MatchedRowIndexes.Clear();
151 application.CurrentUOW.ColCount = 0;
152 application.CurrentUOW.RowCount = 0;
153 application.CurrentUOW.PartialMatch =
false;
155 foreach (
Selector sel
in application.CurrentUOW.WithSelectorList)
158 List<GPALAutomationElement> matchedElems;
159 ReadOnlyCollection<GPALAutomationElement> tmpElems = ElementHelper.FindElements(application, application.CurrentUOW, sel, out
bool matchedAll, out matchedElems);
160 rowsOfElements.Add(tmpElems);
161 application.CurrentUOW.ColCount++;
163 if (
false == matchedAll)
164 application.CurrentUOW.PartialMatch |=
true;
166 if (0 < tmpElems?.Count &&
true == matchedAll)
169 application.CurrentUOW.RowCount = Math.Max(application.CurrentUOW.RowCount, (
int.MaxValue == application.CurrentUOW.WithAllThatMatch ? tmpElems.Count : application.CurrentUOW.WithAllThatMatch));
171 else if (0 < matchedElems?.Count &&
false == matchedAll)
180 if (-1 != (tmpIdx = tmpElems.IndexOf(webElement)))
181 if (
false == application.CurrentUOW.MatchedRowIndexes.Contains(
new KeyValuePair<int, string>(tmpIdx, sel.AttributeName)))
182 application.CurrentUOW.MatchedRowIndexes.Add(tmpIdx, sel.AttributeName);
186 application.CurrentUOW.RowCount = (int.MaxValue == application.CurrentUOW.WithAllThatMatch ? application.CurrentUOW.MatchedRowIndexes.Count : application.CurrentUOW.WithAllThatMatch);
190 if (0 < matchedElems?.Count || 0 < tmpElems?.Count)
191 interactionInfo.Add(
new SmallSelectorNode() { InteractionType = sel.
InteractionType, OffsetX = sel.
DeltaX, OffsetY = sel.
DeltaY, DeltaX = sel.
DeltaY, DeltaY = sel.DeltaY });
195 if (
true == application.CurrentUOW.PartialMatch)
197 List<GPALAutomationElement> newColumn =
new List<GPALAutomationElement>();
199 application.CurrentUOW.RowCount = application.CurrentUOW.MatchedRowIndexes.Count;
203 foreach (ReadOnlyCollection<GPALAutomationElement> rowOfElements
in rowsOfElements)
207 foreach (KeyValuePair<int, string> idx
in application.CurrentUOW.MatchedRowIndexes)
208 newColumn.Add(rowOfElements[idx.Key]);
209 rowsOfColumns.Add(
new ReadOnlyCollection<GPALAutomationElement>(newColumn));
210 newColumn =
new List<GPALAutomationElement>();
215 foreach (ReadOnlyCollection<GPALAutomationElement> rowOfElements
in rowsOfElements)
216 rowsOfColumns.Add(rowOfElements);
220 application.CurrentUOW.ElementGrid.Clear();
223 if (0 != application.CurrentUOW.ColCount)
225 for (
int cnt = 0; cnt < application.CurrentUOW.RowCount; cnt++)
226 application.CurrentUOW.ElementGrid.AddRow(
new List<UnitOfWork.ElementNode>(application.CurrentUOW.ColCount));
233 foreach (ReadOnlyCollection<GPALAutomationElement> rowOfColumns
in rowsOfColumns)
239 switch (elem.
Ae.Current.LocalizedControlType.ToLower())
245 application.CurrentUOW.ElementGrid[rowCnt++].Add(
248 AutomationElement = elem.Ae,
249 InteractionType = interactionInfo[columnIdx].InteractionType,
250 OffsetX = interactionInfo[columnIdx].OffsetX,
251 OffsetY = interactionInfo[columnIdx].OffsetY
261 if (rowCnt >= application.CurrentUOW.WithAllThatMatch)
272 if (tokenIdx < tokens.Count())
276 foreach (List<UnitOfWork.ElementNode> elementNode
in application.CurrentUOW.ElementGrid)
279 List<T> currentRow = tokens[tokenIdx++];
281 foreach (T token
in currentRow)
283 if (elementIdx < elementNode.Count &&
null != elementNode[elementIdx])
285 if (InteractionType.Hardware == elementNode[elementIdx].InteractionType)
286 ElementHelper.HardwareFillInFrom(application,
new GPALAutomationElement(elementNode[elementIdx].AutomationElement), elementNode[elementIdx].OffsetX, elementNode[elementIdx].OffsetY, token.ToString(), writeMode);
288 ElementHelper.FillInFrom(application, elementNode[elementIdx].AutomationElement, elementNode[elementIdx], token.ToString(), writeMode);
292 GPAL.
PublishSimpleEvent(GPALEventType.WARNING, $
"Unused token [{token}] from tokens [{string.Join(",
", currentRow)}]", application, GPALObjectType.Application);
298 while (elementIdx < elementNode.Count &&
null != elementNode[elementIdx])
300 GPAL.
PublishSimpleEvent(GPALEventType.WARNING, $
"No token for control: [{elementNode[elementIdx].AutomationElement.Current.LocalizedControlType}]", application, GPALObjectType.Application);
306 CallIfStatus handled = CallIfStatus.NotHandled;
310 if (
null != application.CurrentUOW.AppCallAfterFillIn)
311 handled = application.CurrentUOW.AppCallAfterFillIn(application, (IGPALGrid<string>)tokens, tokenIdx);
315 application.CurrentUOW = safeUOW;
317 if (CallIfStatus.Terminate == handled)
319 GPAL.
PublishSimpleEvent(GPALEventType.INFO, $
"CallAfterFillIn handler requested program termination.", application, GPALObjectType.Application);
320 throw new GPALException($
"{GPAL.MyMethodName()}: CallAfterFillIn handler requested program termination.");
326 lastRowCnt += rowCnt;
333 if (tokenIdx == tokens.Count())