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 // an empty collection reads and writes like any other. Left null, every member here threw on the first ask
28 public ResultCollection()
29 {
30 _results = new List<(string Name, object Result, int Iteration)>();
31 }
32
33 internal ResultCollection(List<(string Name, object Result, int Iteration)> results, string clientName)
34 {
35 _results = results;
36 _clientName = clientName;
37 }
38
39 public object this[string name]
40 {
41 get
42 {
43 var result = _results.LastOrDefault(r => r.Name == name).Result;
44 if (result == null)
45 {
46 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
47 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}Result named [{name}] not found.",
48 null, GPALObjectType.None);
49 }
50 return result;
51 }
52 set
53 {
54 var lastEntry = _results.LastOrDefault(r => r.Name == name);
55 if (lastEntry.Result != null)
56 {
57 // Update the last entry's result
58 int index = _results.LastIndexOf(lastEntry);
59 _results[index] = (lastEntry.Name, value, lastEntry.Iteration);
60 }
61 else
62 {
63 // Add a new entry if not found
64 _results.Add((name, value, 0));
65 }
66 }
67 }
68
69 public object this[string name, int iteration]
70 {
71 get
72 {
73 var result = _results.LastOrDefault(r => r.Name == name && r.Iteration == iteration).Result;
74 if (result == null)
75 {
76 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
77 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}Result named [{name}] for iteration [{iteration}] not found.",
78 null, GPALObjectType.None);
79 }
80 return result;
81 }
82 }
83
84 public IReadOnlyList<object> GetAllResults(string name)
85 {
86 var results = _results
87 .Where(r => r.Name == name)
88 .Select(r => r.Result)
89 .ToList()
90 .AsReadOnly();
91 if (!results.Any())
92 {
93 GPAL.PublishSimpleEvent(GPALEventType.WARNING,
94 $"{(string.IsNullOrEmpty(_clientName) ? "" : $"[{_clientName}] ")}No results named [{name}].",
95 null, GPALObjectType.None);
96 }
97 return results;
98 }
99}
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:2568