GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
GPALUrl.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.Web;
21using static GenerallyPositive.Enums;
22
23// written by grok, modified by mbv
25{
52 public class GPALUrl : IGPALUrl
53 {
54 private string _url;
55 private readonly List<StorageAction> _actions = new List<StorageAction>();
56
61 internal GPALUrl(string url = null)
62 {
63 _url = string.IsNullOrWhiteSpace(url) ? "https://google.com" : url;
64 }
65
69 public string Url => _url;
70
74 IReadOnlyList<StorageAction> IGPALUrl.GetActions() => _actions.AsReadOnly();
75
79 public static implicit operator string(GPALUrl url) => url?._url;
80
81 private static int implicitCount = 0;
82
90 public static implicit operator GPALUrl(string url)
91 {
92 GPAL.PublishSimpleEvent(GPALEventType.DEBUG, $"Implicit GPALUrl created for [{url}]");
93
94 // emit warning once.
95 if (0 == implicitCount++)
96 GPAL.PublishSimpleEvent(GPALEventType.DEBUG, $"Implicit GPALUrl conversions lack equality, even if Urls match. Create instance using GPAL.Url for reuse.");
97
98 return new GPALUrl(url);
99 }
100
107 {
108 _url = string.IsNullOrWhiteSpace(url) ? "https://google.com" : url;
109 return this;
110 }
111
117 public IAllowGPALUrlStorageItemConfig WithStorageType(WebsiteStorageType type)
118 {
119 _actions.Add(new StorageAction { StorageType = type });
120 return this;
121 }
122
129 {
130 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(data))
131 return this;
132
133 int lastIndex = _actions.Count - 1;
134
135 _actions[lastIndex].Data = data;
136
137 return this;
138 }
139
147 {
148 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(key))
149 return this;
150
151 int lastIndex = _actions.Count - 1;
152
153 _actions[lastIndex].Key = key;
154
155 return this;
156 }
157
164 {
165 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(path))
166 return this;
167
168 int lastIndex = _actions.Count - 1;
169
170 _actions[lastIndex].Path = path;
171
172 return this;
173 }
174
181 {
182 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(domain))
183 return this;
184
185 int lastIndex = _actions.Count - 1;
186
187 _actions[lastIndex].Domain = domain;
188
189 return this;
190 }
191
198 {
199 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(storeName))
200 return this;
201
202 int lastIndex = _actions.Count - 1;
203
204 _actions[lastIndex].StoreName = storeName;
205
206 return this;
207 }
208
215 {
216 if (_actions.Count == 0 || string.IsNullOrWhiteSpace(userDefined))
217 return this;
218
219 int lastIndex = _actions.Count - 1;
220
221 _actions[lastIndex].UserDefined = userDefined;
222
223 return this;
224 }
225
227 {
228 if (_actions.Count == 0)
229 return this;
230
231 int lastIndex = _actions.Count - 1;
232
233 _actions[lastIndex].DeleteAcrossOrigins = trueOrFalse;
234
235 return this;
236 }
237
243 public List<StorageAction> Add(StorageAction storageAction)
244 {
245 _actions.Add(storageAction);
246 return _actions;
247 }
248
254 public List<StorageAction> Add(List<StorageAction> storageActions)
255 {
256 _actions.AddRange(storageActions);
257 return _actions;
258 }
259
265 {
266 return this;
267 }
268 }
269
273 public class StorageAction
274 {
275 public StorageAction()
276 {
277 }
278
279 public StorageAction(StorageAction action)
280 {
281 Action = action.Action;
282 StorageType = action.StorageType;
283 Key = action.Key;
284 Path = action.Path;
285 Domain = action.Domain;
286 StoreName = action.StoreName;
287 Data = action.Data;
289 }
293 public WebsiteStorageAction Action { get; internal set; } = WebsiteStorageAction.notSet;
294
298 public WebsiteStorageType StorageType { get; internal set; } = WebsiteStorageType.notSet;
299
303 public string Key { get; internal set; }
304
308 public string Path { get; internal set; }
309
313 public string Domain { get; internal set; }
314
318 public string StoreName { get; internal set; }
319
320 internal string _data = null;
321
327 public string Data
328 {
329 get => _data;
330 internal set => _data = value;
331 }
332
333
339 public bool IncludeProvenance { get; internal set; } // not currently used (correctly)
340
344 public string UserDefined { get; internal set; }
345
351 public bool DeleteAcrossOrigins { get; internal set; } = false;
352 }
353}
IAllowGPALUrlStorageItemConfig WithStorageKey(string key)
Specifies the key for the most recently added storage action.
Definition GPALUrl.cs:146
IAllowGPALUrlStorageItemConfig WithStoragePath(string path)
Specifies the path restriction for the most recently added storage action (mainly for cookies).
Definition GPALUrl.cs:163
IAllowGPALUrlStorageItemConfig WithDeleteAcrossOrigins(bool trueOrFalse)
OttoMagic Only: For delete operations without a domain, limit to origin? true = delete across origins...
Definition GPALUrl.cs:226
IAllowGPALUrlStorageItemConfig WithStorageDomain(string domain)
Specifies the domain restriction for the most recently added storage action (mainly cookies).
Definition GPALUrl.cs:180
IGPALUrl ToGPALObject()
Returns this instance typed as IGPALUrl.
Definition GPALUrl.cs:264
IAllowGPALUrlStorageType ForUrl(string url)
Changes (or sets) the target URL for this builder instance.
Definition GPALUrl.cs:106
string Url
Gets the target URL string.
Definition GPALUrl.cs:69
List< StorageAction > Add(StorageAction storageAction)
Adds a fully-configured StorageAction to the list.
Definition GPALUrl.cs:243
List< StorageAction > Add(List< StorageAction > storageActions)
Adds multiple fully-configured StorageAction items.
Definition GPALUrl.cs:254
IAllowGPALUrlStorageItemConfig WithStorageType(WebsiteStorageType type)
Specify the storage type for this storage action.
Definition GPALUrl.cs:117
IAllowGPALUrlStorageItemConfig WithStorageData(string data)
Specifies the data to set.
Definition GPALUrl.cs:128
IAllowGPALUrlStorageItemConfig WithStorageStoreName(string storeName)
Specifies the IndexedDB store name for the most recently added action.
Definition GPALUrl.cs:197
IAllowGPALUrlStorageItemConfig WithUserDefined(string userDefined)
Specifies the data to set.
Definition GPALUrl.cs:214
Represents a single storage-related action to perform before navigating to a URL.
Definition GPALUrl.cs:274
bool DeleteAcrossOrigins
OttoMagic Only: For delete operations without a domain, limit to origin? true = delete across origins...
Definition GPALUrl.cs:351
WebsiteStorageType StorageType
The target storage type (cookies, localStorage, indexedDb, etc.).
Definition GPALUrl.cs:298
string Key
Key name for localStorage, sessionStorage, IndexedDB, or cookie name.
Definition GPALUrl.cs:303
bool IncludeProvenance
For wildcard storage gets returning multiple elements. If set to true, return domain,...
Definition GPALUrl.cs:339
WebsiteStorageAction Action
The action to perform: "get", "set", or "delete".
Definition GPALUrl.cs:293
string UserDefined
User defined data strictly used for filtering in GPAL, can store any data of value.
Definition GPALUrl.cs:344
string StoreName
IndexedDB object store name.
Definition GPALUrl.cs:318
string Domain
Domain restriction (primarily for cookies).
Definition GPALUrl.cs:313
string Path
Path restriction (primarily for cookies).
Definition GPALUrl.cs:308
string Data
Value to get/set (used when Action = "get" or "set"). NOTE: context sensitive (json) data NOTE: Data ...
Definition GPALUrl.cs:328
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
Interface after deleting a specific item - allows optional path/domain.
Interface after URL is set - allows selecting storage type.
Public interface exposed to consumers.
IReadOnlyList< StorageAction > GetActions()
List of storage actions to perform before navigation.