GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
ResultCollection.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
18using static GenerallyPositive.Enums;
19using System.Collections.Generic;
20using System.Linq;
21
22public class ResultCollection
23{
24 private readonly List<(string Name, object Result, int Iteration)> _results;
25 private readonly string _clientName;
26
27 public ResultCollection()
28 {
29 }
30
31 internal ResultCollection(List<(string Name, object Result, int Iteration)> results, string clientName)
32 {
33 _results = results;
34 _clientName = clientName;
35 }
36
37 public object this[string name]
38 {
39 get
40 {
41 var result = _results.LastOrDefault(r => r.Name == name).Result;
42 if (result == null)
43 {
44 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
45 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}Result named [{name}] not found.",
46 null, GPALObjectType.None);
47 }
48 return result;
49 }
50 set
51 {
52 var lastEntry = _results.LastOrDefault(r => r.Name == name);
53 if (lastEntry.Result != null)
54 {
55 // Update the last entry's result
56 int index = _results.LastIndexOf(lastEntry);
57 _results[index] = (lastEntry.Name, value, lastEntry.Iteration);
58 }
59 else
60 {
61 // Add a new entry if not found
62 _results.Add((name, value, 0));
63 }
64 }
65 }
66
67 public object this[string name, int iteration]
68 {
69 get
70 {
71 var result = _results.LastOrDefault(r => r.Name == name && r.Iteration == iteration).Result;
72 if (result == null)
73 {
74 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
75 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}Result named [{name}] for iteration [{iteration}] not found.",
76 null, GPALObjectType.None);
77 }
78 return result;
79 }
80 }
81
82 public IReadOnlyList<object> GetAllResults(string name)
83 {
84 var results = _results
85 .Where(r => r.Name == name)
86 .Select(r => r.Result)
87 .ToList()
88 .AsReadOnly();
89 if (!results.Any())
90 {
91 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
92 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}No results named [{name}].",
93 null, GPALObjectType.None);
94 }
95 return results;
96 }
97}
Everything starts here, all the GPAL controls and global settings using fluent syntax are here....
Definition GPAL.cs:49
static void PublishSimpleEvent(GPALEventType gPALEventType, string msg, dynamic gPALObject=null, Enums.GPALObjectType gPALObjectType=GPALObjectType.None, Exception ex=null)
Publish a message to either the information channel or exception channel (if exception passed in) Pub...
Definition GPAL.cs:2406