Helpers
Files
- BrowserMonitor.cs
This file defines a static utility class, `BrowserMonitor`, designed to manage asynchronous login flows that require user interaction via a web browser. Its primary function is to execute a provided login delegate while simultaneously monitoring for the appearance and disappearance of specific browser processes (such as Chrome, Edge, or Firefox). The component detects new browser instances launched by the login process and cancels the operation if those browsers are closed before completion, ensuring clean cancellation handling. Key components include helper methods like `GetBrowserPids` to identify active browser processes and `IsProcessAlive` to check their status, alongside a robust loop that coordinates the background login task with real-time process monitoring.
- CommonGeometry.cs
`CommonGeometry.cs` is a small helper class within the `GlassHopper.Helpers` namespace designed for geometric calculations in Rhino 3D modeling. Its primary function is to compute a default horizontal reference direction vector based on a given surface normal (`normalZ`). The method `GetDefaultReferenceDirection` uses the cross product of the input normal and the Z-axis to determine an orthogonal X-direction, ensuring a consistent local coordinate system. It includes a specific edge-case handling that returns the standard X-axis if the input normal is already parallel to the Z-axis, preventing undefined behavior. This utility is essential for orienting geometry or defining reference planes relative to arbitrary glass surfaces.
- ComponentGuids.cs
This file is a C# static class named `ComponentGuids` that serves as a centralized registry for unique identifiers within the GlassHopper application. It defines approximately 50 public constant strings, each holding a specific Globally Unique Identifier (GUID) associated with various software components or features. These components cover domains such as structural analysis, authentication, material definitions, load calculations, and mesh processing utilities. By centralizing these GUIDs, the code ensures consistent identification across different parts of the system, likely facilitating component registration, serialization, or UI binding in a modular architecture. This approach prevents hardcoding errors and simplifies maintenance by providing a single source of truth for all component identities.
- ConstValues.cs
This file defines a static helper class named `ConstValues` within the `GlassHopper.Helpers` namespace. It serves as a centralized repository for application-wide constant values, specifically storing numeric limits. The single key component is the read-only property `DurationLimit50Years`, which holds the value `1576800000.0`. This constant likely represents the total number of seconds in 50 years, used for time-based calculations or validation logic. By using a static class, the code ensures the value is accessible globally without requiring instantiation.
- HttpClientFactory.cs
This file defines a static `HttpClientFactory` class that manages and caches `HttpClient` instances based on their base addresses using a thread-safe concurrent dictionary. It provides simplified, high-level methods (`GetAsync`, `PostAsync`, `PutAsync`) for performing HTTP requests while automatically handling Bearer token authentication and optional idempotency keys. The factory ensures resource efficiency by reusing existing clients for the same base address rather than creating new connections for every request. Each HTTP method supports configurable timeout settings and conditional header injection, such as adding an Idempotency-Key for POST/PUT operations. Additionally, it includes a `DisposeAll` method to properly clean up and release all cached client resources when the application or plugin shuts down.
- RestHelper.cs
This file defines a static utility class named `RestHelper` within the `GlassHopper.Helpers` namespace. Its primary function is to prevent HTTP GET request caching by appending a unique timestamp parameter to URLs. The key component is the `AddTickToGet` method, which checks if a query string already exists and appends `_=<ticks>` accordingly using `DateTime.UtcNow.Ticks`. This "cache buster" technique ensures that each request is treated as unique by intermediaries like proxies or browsers.
- SdkHelper.cs
This file defines a static utility class named `SdkHelper` within the `GlassHopper.Helpers` namespace, designed to bridge compatibility gaps between different versions of the RhinoCommon SDK. It provides wrapper methods for creating `Plane` objects from points or normals, specifically addressing features available in SDK 8 that were missing in SDK 7. The key components are two static methods: `CreateFromPointsCompat`, which constructs a plane from an origin and two axis points, and `CreateFromNormalCompat`, which creates a plane from an origin and a normal vector. By encapsulating these geometric operations, the helper ensures consistent behavior across varying SDK environments without requiring conditional compilation checks in consuming code. This approach simplifies cross-version compatibility for geometry manipulation tasks within the application.
- SecureStorage.cs
`SecureStorage.cs` is a utility class within the `GlassHopper.Helpers` namespace designed to securely save, load, and clear sensitive data on disk. It utilizes Windows DPAPI (`ProtectedData`) to encrypt and decrypt strings using the current user's scope, ensuring that only the logged-in user can access the stored information. The file path for the cached data is dynamically generated based on the application's API server prefix and saved in the local application data directory. Key components include three static methods: `Save` for writing encrypted data, `Load` for reading and decrypting it, and `Clear` for deleting the cache file. This approach provides a simple yet effective mechanism for handling authentication caches or other secrets without requiring manual key management.