Compare commits

..

103 Commits

Author SHA1 Message Date
Neil Dorin
884b2c2e6e feat: Enhance documentation for MicrophonePrivacyController and its factory with detailed summaries and parameter descriptions 2026-04-08 15:49:38 -06:00
Neil Dorin
daf9b4bda0 refactor: Change CustomActivate and Initialize methods to protected access in multiple classes for better inheritance control 2026-04-08 15:47:58 -06:00
Neil Dorin
e818c9ca03 fix: Downgrade setup-dotnet action version to v5 for compatibility 2026-04-08 15:24:13 -06:00
Neil Dorin
5dd6d18fcc feat: Update CI workflow and project files for improved testing and documentation generation 2026-04-08 15:23:49 -06:00
Neil Dorin
37961b9eac feat: Enhance device testing and environment handling with new interfaces and fakes 2026-04-08 13:21:15 -06:00
Neil Dorin
24df4e7a03 feat: Add unit tests and fakes for Crestron environment and data store
- Introduced `FakeCrestronEnvironment` and `FakeEthernetHelper` for testing purposes.
- Implemented `InMemoryCrestronDataStore` to facilitate unit tests for data storage.
- Created `DebugServiceTests` to validate the behavior of debug-related services.
- Added project files for unit tests targeting .NET 9.0 with necessary dependencies.
- Developed production adapters (`CrestronConsoleAdapter`, `CrestronDataStoreAdapter`, `CrestronEnvironmentAdapter`, `CrestronEthernetAdapter`) to interface with the Crestron SDK.
- Updated `Debug` class to utilize injected service abstractions instead of direct SDK calls.
- Enhanced `ControlSystem` initialization to register service adapters before usage.
2026-04-08 12:41:15 -06:00
Neil Dorin
bfb9838743 refactor: Rename logging level switch variables for clarity and add fallback handler to WebApiServer to allow for serving debug app 2026-04-08 11:51:10 -06:00
Neil Dorin
c98b48ff87 refactor: Clean up and streamline Debug and WebApiServer classes for improved readability and performance 2026-04-07 15:53:00 -06:00
Neil Dorin
5c26438a1c refactor: Remove DebugWebsocketSink.cs to streamline the codebase 2026-03-31 19:29:58 -06:00
Neil Dorin
7bec96e68b refactor: Remove obsolete interfaces and classes to streamline the codebase 2026-03-30 12:11:21 -06:00
Neil Dorin
7076eafc21 Refator: Refactor timer implementation across multiple classes to use System.Timers.Timer instead of CTimer for improved consistency and performance.
- Updated RelayControlledShade to utilize Timer for output pulsing.
- Refactored MockVC to replace CTimer with Timer for call status simulation.
- Modified VideoCodecBase to enhance documentation and improve feedback handling.
- Removed obsolete IHasCamerasMessenger and updated related classes to use IHasCamerasWithControls.
- Adjusted PressAndHoldHandler to implement Timer for button hold actions.
- Enhanced logging throughout MobileControl and RoomBridges for better debugging and information tracking.
- Cleaned up unnecessary comments and improved exception handling in various classes.
2026-03-30 11:44:15 -06:00
Neil Dorin
b4d53dbe0e refactor: routing interfaces and implementations to support current sources
- Updated ICurrentSources interface to use IRoutingSource instead of SourceListItem.
- Introduced CurrentSourcesChangedEventArgs for detailed event notifications.
- Modified IRoutingOutputs and IRoutingSource interfaces to include JSON properties for serialization.
- Enhanced IRoutingSink and related interfaces to implement ICurrentSources for better source management.
- Refactored RoutingFeedbackManager to utilize new current source handling.
- Updated GenericAudioOut, GenericSink, and BlueJeansPc classes to implement new current source logic.
- Adjusted MobileControl messengers to accommodate changes in current source handling.
- Removed deprecated destination handling in MobileControlEssentialsRoomBridge.
2026-03-26 13:49:23 -06:00
Neil Dorin
43a9661e08 Refactor: Removing unused classes that reference Crestron HTTP classes
- Removed the HttpLogoServer class and its related functionality from ControlSystem.
- Updated ControlSystem to eliminate references to the logo server, including initialization and device checks.
- Cleaned up unused variables and methods related to logo server handling.
2026-03-23 11:20:44 -06:00
Neil Dorin
7137945c94 refactor: Remove GenericRESTfulClient and GenericRESTfulConstants classes to streamline codebase 2026-03-12 13:56:18 -06:00
Neil Dorin
ac393c4885 refactor(force-patch): Remove obsolete GenericHttpClient class in favor of built-in HttpClient 2026-03-10 17:35:23 -06:00
Neil Dorin
346a5e9e57 refactor: Refactor DeviceManager and related classes to improve thread safety and performance
- Replaced CCriticalSection with lock statements in DeviceManager for better thread management.
- Updated AddDevice and RemoveDevice methods to use Monitor for locking.
- Enhanced event handling for device activation and registration.
- Modified FileIO class to utilize Task for asynchronous file operations instead of CrestronInvoke.
- Improved feedback mechanisms in FeedbackBase and SystemMonitorController using Task.Run.
- Refactored GenericQueue to remove Crestron threading dependencies and utilize System.Threading.
- Updated BlueJeansPc and VideoCodecBase classes to use Task for asynchronous operations.
- Cleaned up unnecessary critical sections and improved code documentation across various files.
2026-03-10 17:30:59 -06:00
Nick Genovese
426ef4ad6b fix: add error handling when saving debug settings 2026-03-10 00:35:18 -06:00
Nick Genovese
bcb65c7fa4 ci(force-patch): force build 2026-03-10 00:35:18 -06:00
Andrew Welker
c2ff65dce3 build: remove unneeded references from PD Core project 2026-03-10 00:35:18 -06:00
Andrew Welker
3feab2593d fix: use correct line endings for verbatim strings 2026-03-10 00:35:18 -06:00
Andrew Welker
5d90fafbd7 chore: remove duplication namespace declaration
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-10 00:31:20 -06:00
Andrew Welker
7f60dcb4cf chore: update local build version 2026-03-10 00:30:57 -06:00
Andrew Welker
574e4dfb0f feat: modify factory loading
Updating IDeviceFactory to resolve [FEATURE]-Refactor Plugin loading mechanism  #1065.
This change should be backwards-compatible with existing plugins that use the EssentialsPluginDeviceFactory<T> class,
as the interfaces are implemented by the various base classes.

In addition, the correct assembly name is now printed when a type is loaded.
2026-03-10 00:30:36 -06:00
Andrew Welker
76759d35cc feat: remove context file for storing values 2026-03-10 00:22:13 -06:00
Andrew Welker
3ece4f0b7b chore: move all files to file-scoped namespace 2026-03-10 00:21:06 -06:00
Andrew Welker
aaa5b0532b feat: modify plugin loading process 2026-03-06 10:34:53 -07:00
Andrew Welker
04c4557528 docs: update XML docs 2026-03-05 17:19:20 -07:00
Andrew Welker
9febbf2557 chore: fix issues related to remving crestron usings 2026-03-05 15:51:29 -07:00
Andrew Welker
eafade9569 docs: add XML comments 2026-03-05 15:43:42 -07:00
Andrew Welker
4e5b8f3897 wip: package updates 2026-03-05 14:54:54 -07:00
jtalborough
7bd3ccd54b fix: adjust installation steps for prerequisites based on environment detection 2026-03-05 14:23:45 -07:00
jtalborough
790b5a6fb9 fix: update condition for CPZ copy target and remove obsolete workflows 2026-03-05 14:23:45 -07:00
jtalborough
fbcd9c84da wip: address performance issues in plugin loading and versioning 2026-03-05 14:22:53 -07:00
jtalborough
4a2c9fe311 fix: update target framework to net8 and bump PepperDashCore version to 2.0.0-alpha-462
BREAKING CHANGE: Target Framework is now .NET 8:
2026-03-05 13:10:22 -07:00
jtalborough
bdd398e2e6 feat: implement WebSocket classes and update culture settings; bump PepperDashCore version 2026-03-05 13:10:22 -07:00
jtalborough
8be5481ac9 fix: update target frameworks and package references; change culture to InvariantCulture 2026-03-05 13:09:14 -07:00
jtalborough
dbab427d69 fix: update package references and clean up unused imports 2026-03-05 12:00:35 -07:00
Andrew Welker
db4f540710 Merge pull request #1394 from PepperDash/temp
merge temp into dev
2026-03-03 13:39:46 -05:00
Andrew Welker
b64f63ac6b Merge pull request #1389 from PepperDash/copilot/fix-crestrononvif-dll-error
fix(hotfix): skip CrestronOnvif.dll during assembly scanning at startup
2026-03-03 12:38:34 -05:00
Nick Genovese
b21be608f0 Update src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-01 14:38:07 -05:00
copilot-swe-agent[bot]
6ab3ed9911 fix(hotfix): skip CrestronOnvif.dll when scanning assemblies at startup
Co-authored-by: ngenovese11 <23391587+ngenovese11@users.noreply.github.com>
2026-03-01 19:27:22 +00:00
copilot-swe-agent[bot]
a9fdf30880 Initial plan 2026-03-01 19:23:14 +00:00
Neil Dorin
963925ffef Merge pull request #1388 from PepperDash/feature/add-IHasWebViewWithPwaMode
Feature/add i has web view with pwa mode
2026-02-24 15:36:59 -07:00
Neil Dorin
e162ed208b Update src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasWebView.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-24 14:53:31 -07:00
Neil Dorin
bd38475b10 Update src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IHasWebView.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-24 14:53:12 -07:00
Neil Dorin
a704e48ae6 feat: add IsInPwaModeFeedback property to IHasWebViewWithPwaMode interface 2026-02-24 14:48:21 -07:00
Neil Dorin
b40200ecae feat: add IHasWebViewWithPwaMode interface with PWA navigation methods 2026-02-24 11:52:08 -07:00
Neil Dorin
9de14da201 Merge pull request #1386 from PepperDash/docfx-docs
docs: fix capitalization error in toc
2026-02-09 14:16:08 -07:00
Andrew Welker
633608c8c6 docs: fix capitalization error in toc 2026-02-09 14:53:04 -06:00
Neil Dorin
f8a81de177 Merge pull request #1385 from PepperDash/docfx-docs 2026-02-09 13:48:27 -07:00
Neil Dorin
39ebf6f63d Merge pull request #1377 from PepperDash/feature/circuittype-property-versiport 2026-02-09 13:47:36 -07:00
Andrew Welker
3ed0bd52d8 Merge branch 'main' into feature/circuittype-property-versiport 2026-02-09 14:58:06 -05:00
Andrew Welker
afc5cf1a14 docs: update landing page and getting started 2026-02-09 13:57:24 -06:00
Andrew Welker
8ff9de817c docs: reorganize and add article on working with docFx 2026-02-09 13:31:42 -06:00
Andrew Welker
b35d2b47cf Merge pull request #1379 from PepperDash/xml-docs-devices
feat: complete XML documentation in Devices.Common
2026-02-09 10:04:25 -05:00
Andrew Welker
10579f1424 Merge pull request #1380 from PepperDash/xml-docs-essentials-core
Xml docs essentials core
2026-02-09 10:04:07 -05:00
Andrew Welker
f88bb13367 docs: update XML comments for Essentials Core 2026-02-09 08:58:52 -06:00
Erik Meyer
2924ce6916 docs: complete XML documentation in Devices.Common 2026-02-09 08:55:08 -06:00
Andrew Welker
4437074f07 fix: implement copilot suggestions 2026-02-09 08:45:28 -06:00
Andrew Welker
0764685c51 Merge pull request #1378 from PepperDash/xml-docs
feat: complete XML documentation in PD Core
2026-02-09 09:33:24 -05:00
Andrew Welker
1fb5d3e5ee fix: make registering for push schedule updates optional
The default config for a Fusion room will now NOT subscribe for Fusion schedule push updates unless explicitly
requested.
2026-02-09 08:09:18 -06:00
Neil Dorin
1404899342 Merge pull request #1383 from onryigit/fix/case-insensitive-files 2026-02-03 13:51:56 -07:00
Yiğit Öner
a4759c3e67 fix case sensitivity issue for file searches
Updated logic to use case-insensitive filtering
2026-02-03 23:11:19 +03:00
Erik Meyer
a1029cd7c7 fix: add param info, clean up trailing whitespace and minor formatting 2026-01-27 14:39:50 -05:00
Erik Meyer
b1a5136ec6 fix: remove buildFile.txt 2026-01-27 13:53:26 -05:00
Erik Meyer
a7c4e2fd60 feat: complete XML documentation in PD Core 2026-01-27 13:22:27 -05:00
equinoy
c0971a4f8e Merge remote-tracking branch 'origin/screen-lift-controller-mute-logic' into feature/circuittype-property-versiport 2026-01-22 15:36:27 -06:00
equinoy
8bc6d4392b feat: add circuitType property to IOPortConfig and implement state inversion in digital input devices 2026-01-22 15:04:25 -06:00
Neil Dorin
4fa7a42330 Merge pull request #1376 from PepperDash/client-id-issues
fix: handle subsequent join calls and clientid/websocket client mismatches
2026-01-21 14:59:22 -07:00
Andrew Welker
9bad3ae21b fix: handle subsequent join calls and clientid/websocket client mismatches 2026-01-21 15:20:27 -06:00
Nick Genovese
f49901d3fa fix: Improve status messages in StatusMonitorCollection
Enhanced error and warning message generation to use monitor names when available, include counts, proper pluralization, and append "Offline" when issues are present. Avoided multiple enumerations by converting to lists. "Room Ok." is shown when no issues are detected.
2026-01-01 18:01:37 -06:00
Nick Genovese
7910b7931e feat: Add mute logic to ScreenLiftController
- adds a config value that mutes the display when the screen is in the up position
- screens will now mute/unmute based on their position if the config is set
2026-01-01 09:02:04 -06:00
Nick Genovese
3fb30d5561 Merge pull request #1373 from PepperDash/matrix-routing-isonline
Multiple fixes
2025-12-31 15:19:31 -05:00
Andrew Welker
57cd77f019 fix: implement IKeyName for DspControlPoint 2025-12-31 14:04:04 -06:00
Andrew Welker
7f2bb078c8 fix: revert prop name to inUpPosition for screenlift messenger
- refactor volume interfaces into separate files
- IBasicVolumeControl implements IKeyName
2025-12-31 12:20:40 -06:00
Andrew Welker
316bb849b4 fix: update matrix routing inputs if endpoint online status changes 2025-12-30 16:58:36 -06:00
Andrew Welker
a983e2c87f fix: save config only when values change 2025-12-30 14:34:11 -06:00
Nick Genovese
babb9a77df fix: a few logging updates 2025-12-29 16:48:13 -06:00
Nick Genovese
7629921113 fix: a few logging updates 2025-12-29 15:34:14 -06:00
Andrew Welker
3878c85a7a fix: use correct property name for isInUpPosition 2025-12-29 13:36:47 -06:00
Andrew Welker
7ad8218af0 fix: fusion controller now sets only associated room custom values 2025-12-29 13:03:47 -06:00
Andrew Welker
0c4aec14d1 fix: use .NET timers instead of CTimer 2025-12-29 11:53:52 -06:00
Andrew Welker
7d3f871460 Merge branch 'copilot/featureadd-raise-lower-time' into mc-connection-issues 2025-12-29 09:03:09 -06:00
Andrew Welker
78c9381108 fix: add clientId as qp for websocket for MC 2025-12-29 08:57:52 -06:00
Erik Meyer
a7ff2e8903 fix: move isInUpPosition to momvement complete method, remove conditionlal logic on raise/lower commands 2025-12-27 17:09:56 -06:00
copilot-swe-agent[bot]
ae0b2fe086 Refactor timer disposal and improve code readability
Co-authored-by: erikdred <88980320+erikdred@users.noreply.github.com>
2025-12-27 20:17:59 +00:00
copilot-swe-agent[bot]
bd11c827da Split movement time into separate raise/lower times and remove timing from latched mode
Co-authored-by: erikdred <88980320+erikdred@users.noreply.github.com>
2025-12-27 20:14:39 +00:00
copilot-swe-agent[bot]
7ea1efbabf Add raise/lower movement time configuration and banked command support
Co-authored-by: erikdred <88980320+erikdred@users.noreply.github.com>
2025-12-27 20:09:31 +00:00
copilot-swe-agent[bot]
9d6aaa2a0e Initial plan 2025-12-27 20:02:52 +00:00
Andrew Welker
53e7a30224 fix: handle threading issues for concurrent clients joining 2025-12-26 12:34:31 -06:00
Neil Dorin
ce8b08e312 Merge pull request #1371 from PepperDash/temp-to-dev 2025-12-23 12:14:03 -05:00
Neil Dorin
39c1f60a4d Merge pull request #1370 from PepperDash/udp-eisc 2025-12-23 12:10:37 -05:00
Andrew Welker
2cc37a4e40 fix: ExecuteJoinAction now uses the correct Sig collections 2025-12-23 11:06:52 -06:00
Andrew Welker
076e5dfa9d chore: update comments, debug methods, and mark some things obsolete 2025-12-23 10:25:53 -06:00
Andrew Welker
092896bb25 fix: support for legacy UDP EISC 2025-12-23 09:57:49 -06:00
Neil Dorin
7c8f0586e6 Merge pull request #1369 from PepperDash/volume-messenger-issue 2025-12-16 17:15:46 -05:00
Andrew Welker
c5b0872a4c fix: DeviceVolumeMessenger only sends rawValue when device implements it 2025-12-16 15:41:33 -06:00
Andrew Welker
13e833b797 Merge pull request #1366 from PepperDash/main
Main -> Development
2025-12-09 15:48:09 -05:00
Andrew Welker
2be078da18 Merge pull request #1360 from PepperDash/temp-to-dev
Temp to dev
2025-11-25 13:42:11 -05:00
Neil Dorin
7330ae2e30 Merge pull request #1330 from PepperDash/temp-to-dev 2025-10-10 10:32:48 -04:00
Andrew Welker
a57dddba5e Merge pull request #1341 from PepperDash/main
Update temp-to-dev branch
2025-10-10 10:31:28 -04:00
Neil Dorin
0bfec16622 Merge pull request #1328 from PepperDash/temp-to-dev
Temp to dev
2025-09-08 11:29:40 -06:00
Andrew Welker
94e7b8210f Merge pull request #1323 from PepperDash/temp-to-dev
Temp to dev
2025-08-26 10:19:59 -04:00
653 changed files with 49124 additions and 49349 deletions

13
.config/dotnet-tools.json Normal file
View File

@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.2.4",
"commands": [
"csharpier"
],
"rollForward": false
}
}
}

View File

@@ -6,9 +6,26 @@ on:
- '**'
jobs:
# runTests:
# uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-tests.yml@main
# secrets: inherit
runTests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: 9.0.x
- name: Restore dependencies
working-directory: .
run: dotnet restore
- name: Test
working-directory: .
run: dotnet test --verbosity normal --no-restore --collect:"xplat code coverage"
getVersion:
uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-getversion.yml@main
secrets: inherit
needs: runTests
build-4Series:
uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-4Series-builds.yml@main
secrets: inherit

View File

@@ -0,0 +1,247 @@
name: Essentials v3 Development Build
on:
push:
branches:
- feature-3.0.0/*
- hotfix-3.0.0/*
- release-3.0.0/*
- development-3.0.0
env:
SOLUTION_PATH: .
SOLUTION_FILE: PepperDash.Essentials
VERSION: 0.0.0-buildtype-buildnumber
BUILD_TYPE: Debug
RELEASE_BRANCH: main
jobs:
Build_Project_4-Series:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Detect environment (Act vs GitHub)
- name: Detect environment
id: detect_env
run: |
if [ -n "$ACT" ]; then
echo "is_local=true" >> $GITHUB_OUTPUT
else
echo "is_local=false" >> $GITHUB_OUTPUT
fi
- name: Install prerequisites
run: |
if [ "${{ steps.detect_env.outputs.is_local }}" == "true" ]; then
# For Act - no sudo needed
apt-get update
apt-get install -y curl wget libicu-dev git unzip
else
# For GitHub runners - sudo required
sudo apt-get update
sudo apt-get install -y curl wget libicu-dev git unzip
fi
- name: Set Version Number
id: setVersion
shell: bash
run: |
latestVersion="3.0.0"
newVersion=$latestVersion
phase=""
newVersionString=""
if [[ $GITHUB_REF =~ ^refs/pull/.* ]]; then
phase="beta"
newVersionString="${newVersion}-${phase}-${GITHUB_RUN_NUMBER}"
elif [[ $GITHUB_REF =~ ^refs/heads/hotfix-3.0.0/.* ]]; then
phase="hotfix"
newVersionString="${newVersion}-${phase}-${GITHUB_RUN_NUMBER}"
elif [[ $GITHUB_REF =~ ^refs/heads/feature-3.0.0/.* ]]; then
phase="alpha"
newVersionString="${newVersion}-${phase}-${GITHUB_RUN_NUMBER}"
elif [[ $GITHUB_REF == "refs/heads/development-3.0.0" ]]; then
phase="beta"
newVersionString="${newVersion}-${phase}-${GITHUB_RUN_NUMBER}"
elif [[ $GITHUB_REF =~ ^refs/heads/release-3.0.0/.* ]]; then
version=$(echo $GITHUB_REF | awk -F '/' '{print $NF}' | sed 's/v//')
phase="rc"
newVersionString="${version}-${phase}-${GITHUB_RUN_NUMBER}"
else
# For local builds or unrecognized branches
newVersionString="${newVersion}-local"
fi
echo "version=$newVersionString" >> $GITHUB_OUTPUT
# Create Build Properties file
- name: Create Build Properties
run: |
cat > Directory.Build.props << EOF
<Project>
<PropertyGroup>
<Version>${{ steps.setVersion.outputs.version }}</Version>
<AssemblyVersion>${{ steps.setVersion.outputs.version }}</AssemblyVersion>
<FileVersion>${{ steps.setVersion.outputs.version }}</FileVersion>
<InformationalVersion>${{ steps.setVersion.outputs.version }}</InformationalVersion>
<PackageVersion>${{ steps.setVersion.outputs.version }}</PackageVersion>
<NuGetVersion>${{ steps.setVersion.outputs.version }}</NuGetVersion>
</PropertyGroup>
</Project>
EOF
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Restore NuGet Packages
run: dotnet restore ${SOLUTION_FILE}.sln
- name: Build Solution
run: dotnet build ${SOLUTION_FILE}.sln --configuration ${BUILD_TYPE} --no-restore
# Copy the CPZ file to the output directory with version in the filename
- name: Copy and Rename CPZ Files
run: |
mkdir -p ./output/cpz
# Find the main CPZ file in the build output
if [ -f "./src/PepperDash.Essentials/bin/${BUILD_TYPE}/net8/PepperDashEssentials.cpz" ]; then
cp "./src/PepperDash.Essentials/bin/${BUILD_TYPE}/net8/PepperDashEssentials.cpz" "./output/cpz/PepperDashEssentials.${{ steps.setVersion.outputs.version }}.cpz"
echo "Main CPZ file copied and renamed successfully."
else
echo "Warning: Main CPZ file not found at expected location."
find ./src -name "*.cpz" | xargs -I {} cp {} ./output/cpz/
fi
- name: Pack Solution
run: dotnet pack ${SOLUTION_FILE}.sln --configuration ${BUILD_TYPE} --output ./output/nuget --no-build
# List build artifacts (runs in both environments)
- name: List Build Artifacts
run: |
echo "=== Build Artifacts ==="
echo "NuGet Packages:"
find ./output/nuget -type f | sort
echo ""
echo "CPZ/CPLZ Files:"
find ./output -name "*.cpz" -o -name "*.cplz" | sort
echo "======================="
# Enhanced package inspection for local runs
- name: Inspect NuGet Packages
if: steps.detect_env.outputs.is_local == 'true'
run: |
echo "=== NuGet Package Details ==="
for pkg in $(find ./output/nuget -name "*.nupkg"); do
echo "Package: $(basename "$pkg")"
echo "Size: $(du -h "$pkg" | cut -f1)"
# Extract and show package contents
echo "Contents:"
unzip -l "$pkg" | tail -n +4 | head -n -2
echo "--------------------------"
# Try to extract and show the nuspec file (contains metadata)
echo "Metadata:"
unzip -p "$pkg" "*.nuspec" 2>/dev/null | grep -E "(<id>|<version>|<description>|<authors>|<dependencies>)" || echo "Metadata extraction failed"
echo "--------------------------"
done
echo "==========================="
# Tag creation - GitHub version
- name: Create tag for non-rc builds (GitHub)
if: ${{ !contains(steps.setVersion.outputs.version, 'rc') && steps.detect_env.outputs.is_local == 'false' }}
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git tag ${{ steps.setVersion.outputs.version }}
git push --tags origin
# Tag creation - Act mock version
- name: Create tag for non-rc builds (Act Mock)
if: ${{ !contains(steps.setVersion.outputs.version, 'rc') && steps.detect_env.outputs.is_local == 'true' }}
run: |
echo "Would create git tag: ${{ steps.setVersion.outputs.version }}"
echo "Would push tag to: origin"
# Release creation - GitHub version
- name: Create Release (GitHub)
if: steps.detect_env.outputs.is_local == 'false'
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: 'output/cpz/*,output/**/*.cplz'
generateReleaseNotes: true
prerelease: ${{contains('debug', env.BUILD_TYPE)}}
tag: ${{ steps.setVersion.outputs.version }}
# Release creation - Act mock version with enhanced output
- name: Create Release (Act Mock)
if: steps.detect_env.outputs.is_local == 'true'
run: |
echo "=== Mock Release Creation ==="
echo "Would create release with:"
echo "- Tag: ${{ steps.setVersion.outputs.version }}"
echo "- Prerelease: ${{contains('debug', env.BUILD_TYPE)}}"
echo "- Artifacts matching pattern: output/cpz/*,output/**/*.cplz"
echo ""
echo "Matching artifacts:"
find ./output/cpz -type f
find ./output -name "*.cplz"
# Detailed info about release artifacts
echo ""
echo "Artifact Details:"
for artifact in $(find ./output/cpz -type f; find ./output -name "*.cplz"); do
echo "File: $(basename "$artifact")"
echo "Size: $(du -h "$artifact" | cut -f1)"
echo "Created: $(stat -c %y "$artifact")"
echo "MD5: $(md5sum "$artifact" | cut -d' ' -f1)"
echo "--------------------------"
done
echo "============================"
# NuGet setup - GitHub version
- name: Setup NuGet (GitHub)
if: steps.detect_env.outputs.is_local == 'false'
run: |
dotnet nuget add source https://nuget.pkg.github.com/pepperdash/index.json -n github -u pepperdash -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
# NuGet setup - Act mock version
- name: Setup NuGet (Act Mock)
if: steps.detect_env.outputs.is_local == 'true'
run: |
echo "=== Mock NuGet Setup ==="
echo "Would add GitHub NuGet source: https://nuget.pkg.github.com/pepperdash/index.json"
echo "======================="
# Publish to NuGet - GitHub version
- name: Publish to Nuget (GitHub)
if: steps.detect_env.outputs.is_local == 'false'
run: dotnet nuget push ./output/nuget/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
# Publish to NuGet - Act mock version
- name: Publish to Nuget (Act Mock)
if: steps.detect_env.outputs.is_local == 'true'
run: |
echo "=== Mock Publish to NuGet ==="
echo "Would publish the following packages to https://api.nuget.org/v3/index.json:"
find ./output/nuget -name "*.nupkg" | sort
echo "============================="
# Publish to GitHub NuGet - GitHub version
- name: Publish to Github Nuget (GitHub)
if: steps.detect_env.outputs.is_local == 'false'
run: dotnet nuget push ./output/nuget/*.nupkg --source github --api-key ${{ secrets.GITHUB_TOKEN }}
# Publish to GitHub NuGet - Act mock version
- name: Publish to Github Nuget (Act Mock)
if: steps.detect_env.outputs.is_local == 'true'
run: |
echo "=== Mock Publish to GitHub NuGet ==="
echo "Would publish the following packages to the GitHub NuGet registry:"
find ./output/nuget -name "*.nupkg" | sort
echo "=================================="

View File

@@ -36,49 +36,151 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{02EA681E-C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash.Core", "src\PepperDash.Core\PepperDash.Core.csproj", "{E5336563-1194-501E-BC4A-79AD9283EF90}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash.Core.Tests", "src\PepperDash.Core.Tests\PepperDash.Core.Tests.csproj", "{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepperDash.Essentials.Core.Tests", "src\PepperDash.Essentials.Core.Tests\PepperDash.Essentials.Core.Tests.csproj", "{F508E0BA-E885-424F-9D4C-359CF0011DEF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug 4.7.2|Any CPU = Debug 4.7.2|Any CPU
Debug 4.7.2|x64 = Debug 4.7.2|x64
Debug 4.7.2|x86 = Debug 4.7.2|x86
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|Any CPU.ActiveCfg = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|Any CPU.Build.0 = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|x64.ActiveCfg = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|x64.Build.0 = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|x86.ActiveCfg = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Debug|x86.Build.0 = Debug|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|Any CPU.Build.0 = Release|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|x64.ActiveCfg = Release|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|x64.Build.0 = Release|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|x86.ActiveCfg = Release|Any CPU
{53E204B7-97DD-441D-A96C-721DF014DF82}.Release|x86.Build.0 = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|Any CPU.ActiveCfg = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|Any CPU.Build.0 = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|x64.ActiveCfg = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|x64.Build.0 = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|x86.ActiveCfg = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Debug|x86.Build.0 = Debug|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|Any CPU.Build.0 = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|x64.ActiveCfg = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|x64.Build.0 = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|x86.ActiveCfg = Release|Any CPU
{CB3B11BA-625C-4D35-B663-FDC5BE9A230E}.Release|x86.Build.0 = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|Any CPU.ActiveCfg = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|Any CPU.Build.0 = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|x64.ActiveCfg = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|x64.Build.0 = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|x86.ActiveCfg = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Debug|x86.Build.0 = Debug|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|Any CPU.Build.0 = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|x64.ActiveCfg = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|x64.Build.0 = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|x86.ActiveCfg = Release|Any CPU
{3D192FED-8FFC-4CB5-B5F7-BA307ABA254B}.Release|x86.Build.0 = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|Any CPU.ActiveCfg = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|Any CPU.Build.0 = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|x64.ActiveCfg = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|x64.Build.0 = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|x86.ActiveCfg = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Debug|x86.Build.0 = Debug|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|Any CPU.Build.0 = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|x64.ActiveCfg = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|x64.Build.0 = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|x86.ActiveCfg = Release|Any CPU
{F6D362DE-2256-44B1-927A-8CE4705D839A}.Release|x86.Build.0 = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|Any CPU.ActiveCfg = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|Any CPU.Build.0 = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|x64.Build.0 = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Debug|x86.Build.0 = Debug|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|Any CPU.Build.0 = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|x64.ActiveCfg = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|x64.Build.0 = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|x86.ActiveCfg = Release|Any CPU
{B438694F-8FF7-464A-9EC8-10427374471F}.Release|x86.Build.0 = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|Any CPU.ActiveCfg = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|Any CPU.Build.0 = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|x64.ActiveCfg = Debug 4.7.2|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|x64.Build.0 = Debug 4.7.2|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|x86.ActiveCfg = Debug 4.7.2|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug 4.7.2|x86.Build.0 = Debug 4.7.2|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|x64.ActiveCfg = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|x64.Build.0 = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Debug|x86.Build.0 = Debug|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|Any CPU.Build.0 = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|x64.ActiveCfg = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|x64.Build.0 = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|x86.ActiveCfg = Release|Any CPU
{E5336563-1194-501E-BC4A-79AD9283EF90}.Release|x86.Build.0 = Release|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug 4.7.2|Any CPU.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug 4.7.2|x64.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug 4.7.2|x86.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug|x64.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Debug|x86.ActiveCfg = Debug|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Release|x64.ActiveCfg = Release|Any CPU
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C}.Release|x86.ActiveCfg = Release|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug 4.7.2|Any CPU.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug 4.7.2|x64.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug 4.7.2|x86.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug|x64.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Debug|x86.ActiveCfg = Debug|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Release|x64.ActiveCfg = Release|Any CPU
{F508E0BA-E885-424F-9D4C-359CF0011DEF}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -90,6 +192,8 @@ Global
{F6D362DE-2256-44B1-927A-8CE4705D839A} = {B24989D7-32B5-48D5-9AE1-5F3B17D25206}
{B438694F-8FF7-464A-9EC8-10427374471F} = {B24989D7-32B5-48D5-9AE1-5F3B17D25206}
{E5336563-1194-501E-BC4A-79AD9283EF90} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{680BA287-E61F-4B8D-BD7A-84C2504F5F9C} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{F508E0BA-E885-424F-9D4C-359CF0011DEF} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6907A4BF-7201-47CF-AAB1-3597F3B8E1C3}

View File

@@ -52,6 +52,7 @@
"_appLogoPath": "docs/images/favicon-32x32.png",
"_appFaviconPath": "docs/images/favicon.ico",
"_disableToc": false,
"_enableNewTab": true,
"pdf": false
}
}

View File

@@ -4,23 +4,44 @@
[YouTube Video - Getting Started with PepperDash Essentials](https://youtu.be/FxEZtbpCwiQ)
***
## Download or clone
## Get a CPZ
You may clone Essentials at <https://github.com/PepperDash/Essentials.git>
### Prerequisites
* [VS Code](https://code.visualstudio.com/)
* [.NET 9 SDK](https://dotnet.microsoft.com/en-us/download)
* [Git](https://git-scm.com/)
> Note: Essentials 2.x.x uses .NET Framework 4.7.2 currently. The .NET 9 SDK will build the project with the appropriate references
### Build From Source
1. Clone the repo: `git clone https://github.com/PepperDash/Essentials.git`
2. Open the folder in VS Code
3. Build using the dotnet CLI: `dotnet build`
### Download the latest release
The latest release can be found on [Github](https://github.com/PepperDash/Essentials/releases/latest)
## How to Get Started
This section assumes knowledge of loading programs to and working with the file system on a Crestron processor.
2. Using an SFTP client or Crestron Toolbox, load the downloaded (or built) cpz to the processor in program slot 1
1. If using SFTP, connect via SSH and start the program by sending console command `progload -p:1`
3. On first boot, the Essentials Application will build the necessary configuration folder structure in the user/program1/ path.
4. The application has some example configuration files included. Copy `/Program01/Example Configuration/EssentialsSpaceHuddleRoom/configurationFile-HuddleSpace-2-Source.json` to the `/User/Program1/` folder.
6. Reset the program via console `progreset -p:1`. The program will load the example configuration file.
1. Using an SFTP client, load `PepperDashEssentials1.4.32.cpz` to the processor in program slot 1 and start the program by sending console command `progload -p:1`
1. On first boot, the Essentials Application will build the necessary configuration folder structure in the User/Program1/ path.
1. The application has some example configuration files included. Copy `/Program01/Example Configuration/EssentialsSpaceHuddleRoom/configurationFile-HuddleSpace-2-Source.json` to the `/User/Program1/` folder.
1. Copy the SGD files from `/Program01/SGD` to `/User/Program1/sgd`
1. Reset the program via console `progreset -p:1`. The program will load the example configuration file.
1. Via console, you can run the `devlist:1` command to get some insight into what has been loaded from the configuration file into the system . This will print the basic device information in the form of ["key"] "Name". The "key" value is what we can use to interact with each device uniquely.
1. Run the command `devprops:1 display-1`. This will print the real-time property values of the device with key "display-1".
1. Run the command `devmethods:1 display-1`. This will print the public methods available for the device with key "display-1".
1. Run the command `devjson:1 {"deviceKey":"display-1","methodName":"PowerOn", "params": []}`. This will call the method PowerOn() on the device with key "display-1".
1. Run the provided example XPanel SmartGraphics project and connect to your processor at the appropriate IPID.
Once Essentials is running with a valid configuration, the following console commands can be used to see what's going on:
Next: [Standalone use](~/docs/Standalone-Use.md)
* ```devlist:1```
* Print the list of devices in [{key}] {name} format
* The key of a device can be used with the rest of the commands to get more information
* `devprops:1 {deviceKey}`
* Print the real-time property values of the device with key "display-1".
* `devmethods:1 display-1`
* Print the public methods available for the device with key "display-1".
* `devjson:1 {"deviceKey":"display-1","methodName":"PowerOn", "params": []}`
* Call the method `PowerOn()` on the device with key "display-1".
Next: [Standalone use](~/docs/usage/Standalone-Use.md)

View File

@@ -39,7 +39,7 @@ Thanks!
## Collaboration
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/Plugins.md)
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/technical-docs/Plugins.md)
### Open-source-collaborative workflow

View File

@@ -1,6 +1,6 @@
# Deprecated
**Note : this entry is out of date - please see [Plugins](~/docs/Plugins.md)**
**Note : this entry is out of date - please see [Plugins](~/docs/technical-docs/Plugins.md)**
## What are Essentials Plugins?

View File

@@ -358,7 +358,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
@@ -474,4 +474,4 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
Next: [Essentials architecture](~/docs/Arch-summary.md)
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)

View File

@@ -1,6 +1,6 @@
# SIMPL Windows Bridging
**Note : this entry is out of date - please see [SIMPL Windows Bridging - Updated](~/docs/SIMPL-Bridging-Updated.md)**
**Note : this entry is out of date - please see [SIMPL Windows Bridging - Updated](~/docs/usage/SIMPL-Bridging-Updated.md)**
Essentials allows for devices defined within the SIMPL# Pro application to be bridged to a SIMPL Windows application over Ethernet Intersystem Communication (EISC). This allows a SIMPL Windows program to take advantage of some of the features of the SIMPL# Pro environment, without requiring the entire application to be written in C#.
@@ -356,7 +356,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
@@ -472,4 +472,4 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
Next: [Essentials architecture](~/docs/Arch-summary.md)
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)

View File

@@ -0,0 +1,148 @@
# How to Add Documentation to Essentials
This guide explains how to add new documentation articles to the Essentials docFx site.
## Overview
The Essentials documentation uses [docFx](https://dotnet.github.io/docfx/) to generate a static documentation website. Documentation files are organized in a hierarchical structure with a table of contents (TOC) file that defines the site navigation. Documentation should be organized and written to fit into the [Diátaxis](https://diataxis.fr/start-here/) conceptual framework.
## Documentation Structure
Documentation files are located in `/docs/docs/` and organized into the following subdirectories:
- **how-to/** - Step-by-step guides and tutorials
- **usage/** - Usage documentation for SIMPL bridging, standalone use, and hardware integration
- **technical-docs/** - Technical documentation including architecture, plugins, and API references
- **images/** - Image assets used in documentation
## Adding a New Document
### Step 1: Create Your Markdown File
1. Determine which category your document belongs to (how-to, usage, or technical-docs)
2. Create a new `.md` file in the appropriate subdirectory
3. Use a descriptive filename with hyphens (e.g., `my-new-feature.md`)
**Example:**
```bash
# For a how-to guide
touch /docs/docs/how-to/configure-audio-settings.md
# For usage documentation
touch /docs/docs/usage/video-switcher-control.md
# For technical documentation
touch /docs/docs/technical-docs/custom-device-plugin.md
```
### Step 2: Write Your Content
Start your markdown file with a level 1 heading (`#`) that serves as the page title:
```markdown
# Your Document Title
Brief introduction to the topic.
## Section Heading
Content goes here...
### Subsection
More detailed content...
```
**Markdown Features:**
- Use standard markdown syntax
- Include code blocks with language specifiers (```csharp, ```json, etc.)
- Add images: `![Alt text](../images/your-image.png)`
- Link to other docs: `[Link text](../usage/related-doc.md)`
### Step 3: Add to Table of Contents
Edit `/docs/docs/toc.yml` to add your new document to the navigation:
```yaml
- name: How-to's
items:
- href: how-to/how-to-add-docs.md
- href: how-to/your-new-doc.md # Add your document here
```
**TOC Structure:**
- `name:` - Display name in the navigation menu
- `href:` - Relative path to the markdown file
- `items:` - Nested items for hierarchical navigation
**Example with nested items:**
```yaml
- name: Usage
items:
- name: SIMPL Bridging
href: usage/SIMPL-Bridging-Updated.md
items:
- name: Your Sub-Topic
href: usage/your-sub-topic.md
```
### Step 4: Test Locally
Build and preview the docFx site locally to verify your changes:
```bash
# Navigate to the docs directory
cd docs
# Build the documentation
docfx build
# Serve the site locally
docfx serve _site
```
Then open your browser to `http://localhost:8080` to view the site.
## Best Practices
### File Naming
- Use lowercase with hyphens: `my-document-name.md`
- Be descriptive but concise
- Avoid special characters
### Content Guidelines
- Start with a clear introduction
- Use hierarchical headings (H1 → H2 → H3)
- Include code examples where appropriate
- Add images to illustrate complex concepts
- Link to related documentation
### TOC Organization
- Group related documents under the same parent
- Order items logically (basic → advanced)
- Keep the TOC hierarchy shallow (2-3 levels max)
- Use clear, descriptive names for navigation items
## Common Issues
### Document Not Appearing
- Verify the file path in `toc.yml` is correct and uses forward slashes
- Ensure the markdown file exists in the specified location
- Check for YAML syntax errors in `toc.yml`
### Images Not Loading
- Verify image path is relative to the markdown file location
- Use `../images/` for files in the images directory
- Ensure image files are committed to the repository
### Broken Links
- Use relative paths for internal links
- Test all links after building the site
- Use `.md` extension when linking to other documentation files
## Additional Resources
- [docFx Documentation](https://dotnet.github.io/docfx/)
- [Markdown Guide](https://www.markdownguide.org/)
- [YAML Syntax](https://yaml.org/spec/1.2/spec.html)
- [Diátaxis](https://diataxis.fr/start-here/)

View File

@@ -26,7 +26,7 @@ Types of things in `DeviceManager`:
A Device doesn't always represent a physical piece of hardware, but rather a logical construct that "does something" and is used by one or more other devices in the running program. For example, we create a room device, and its corresponding Fusion device, and that room has a Cisco codec device, with an attached SSh client device. All of these lie in a flat collection in the `DeviceManager`.
> The `DeviceManager` is nothing more than a modified collection of things, and technically those things don't have to be Devices, but must at least implement the `IKeyed` (`PepperDash.Core.IKeyed`) interface (simply so items can be looked up by their key.) Items in the `DeviceManager` that are Devices are run through additional steps of [activation](~/docs/Arch-activate.md#2-pre-activation) at startup. This collection of devices is all interrelated by their string keys.
> The `DeviceManager` is nothing more than a modified collection of things, and technically those things don't have to be Devices, but must at least implement the `IKeyed` (`PepperDash.Core.IKeyed`) interface (simply so items can be looked up by their key.) Items in the `DeviceManager` that are Devices are run through additional steps of [activation](~/docs/technical-docs/Arch-activate.md#2-pre-activation) at startup. This collection of devices is all interrelated by their string keys.
In this flat design, we spin up devices, and then introduce them to their "coworkers and bosses" - the other devices and logical units that they will interact with - and get them all operating together to form a running unit. For example: A room configuration will contain a "VideoCodecKey" property and a "DefaultDisplayKey" property. The `DeviceManager` provides the room with the codec or displays having the appropriate keys. What the room does with those is dependent on its coding.
@@ -38,4 +38,4 @@ This flat structure ensures that every device in a system exists in one place an
![Architecture overview](~/docs/images/arch-overview.png)
Next: [Configurable lifecycle](~/docs/Arch-lifecycle.md)
Next: [Configurable lifecycle](~/docs/technical-docs/Arch-lifecycle.md)

View File

@@ -32,7 +32,7 @@ If the `CustomActivate()` method is long, consider breaking it up into many smal
Note: It is best-practice in Essentials to not write arbitrarily-timed startup sequences to ensure that a "system" or room is functional. Rather, we encourage the developer to use various properties and conditions on devices to aggregate together "room is ready" statuses that can trigger further action. This ensures that all devices can be up and alive, allowing them to be debugged within a program that may otherwise be misbehaving - as well as not making users and expensive developers wait for code to start up!
```cs
public override bool CustomActivate()
protected override bool CustomActivate()
{
Debug.Console(0, this, "Final activation. Setting up actions and feedbacks");
SetupFunctions();
@@ -52,7 +52,7 @@ We can see in the example below that during the `CustomActivate()` phase, we def
### **Example**
```cs
public override bool CustomActivate()
protected override bool CustomActivate()
{
foreach (var i in Config.Inputs)
{
@@ -105,7 +105,7 @@ Each of the three activation phases operates in a try/catch block for each devic
In any real-world system, devices and business logic need to talk to each other, otherwise, what's the point of all this coding? When creating your classes and configuration, it is best practice to _try_ not to "plug" one device into another during construction or activation. For example your touchpanel controller class has a `Display1` property that holds the display-1 object. Rather, it may be better to refer to the device as it is stored in the `DeviceManager` when it's needed using the static `DeviceManager.GetDeviceForKey(key)` method to get a reference to the device, which can be cast using various interfaces/class types, and then interacted with. This prevents objects from being referenced in places where the developer may later forget to dereference them, causing memory leak. This will become more important as Essentials becomes more able to be reconfigured at runtime.
As an example, [connection-based routing](~/docs/Connection-based-routing.md#essentials-connection-based-routing) uses these methods. When a route is requested, the collection of tielines and devices is searched for the devices and paths necessary to complete a route, but there are no devices or tie lines that are object-referenced in running code. It can all be torn down and reconfigured without any memory-management dereferencing, setting things to null.
As an example, [connection-based routing](~/docs/technical-docs/Connection-based-routing.md#essentials-connection-based-routing) uses these methods. When a route is requested, the collection of tielines and devices is searched for the devices and paths necessary to complete a route, but there are no devices or tie lines that are object-referenced in running code. It can all be torn down and reconfigured without any memory-management dereferencing, setting things to null.
## Device Initialization
@@ -115,7 +115,7 @@ The main task that should be undertaken in the `Initialize()` method for any 3rd
### Example (from `PepperDash.Essentials.Devices.Common.VideoCodec.Cisco.CiscoSparkCodec`)
```cs
public override void Initialize()
protected override void Initialize()
{
var socket = Communication as ISocketStatus;
if (socket != null)
@@ -155,4 +155,4 @@ Robust C#-based system code should not depend on "order" or "time" to get runnin
When designing new Device-based classes, be it rooms, devices, port controllers, bridges, make them as independent as possible. They could exist alone in a program with no required partner objects, and just quietly exist without failing. We want the system to be fast and flexible, and keeping the interdependence between objects at a minimum improves this flexibility into the future.
Next: [More architecture](~/docs/Arch-topics.md)
Next: [More architecture](~/docs/technical-docs/Arch-topics.md)

View File

@@ -2,8 +2,8 @@
The diagram below describes how Essentials gets a program up and running.
(The various activation phases are covered in more detail on the [next page](~/docs/Arch-activate.md))
(The various activation phases are covered in more detail on the [next page](~/docs/technical-docs/Arch-activate.md))
![Lifecycle](~/docs/images/lifecycle.png)
Next: [Activation phases](~/docs/Arch-activate.md)
Next: [Activation phases](~/docs/technical-docs/Arch-activate.md)

View File

@@ -16,4 +16,4 @@ The diagram below shows the reference dependencies that exist between the differ
![Architecture drawing](~/docs/images/arch-high-level.png)
Next: [Architecture](~/docs/Arch-1.md)
Next: [Architecture](~/docs/technical-docs/Arch-1.md)

View File

@@ -1,48 +1,52 @@
- name: Get Started With Essentials
- href: ../index.md
- href: Get-started.md
- href: Get-started.md
- name: How-to's
items:
- name: How to add an article or doc page
href: how-to/how-to-add-docs.md
- name: Usage
items:
- href: Standalone-Use.md
- href: SIMPL-Bridging-Updated.md
- href: usage/Standalone-Use.md
- href: usage/SIMPL-Bridging-Updated.md
items:
- name: Join Maps
href: JoinMaps.md
href: usage/JoinMaps.md
- name: Bridging to Hardware Resources
href: Bridging-To-Hardware-Resources.md
href: usage/Bridging-To-Hardware-Resources.md
items:
- name: GenericComm Bridging
href: GenericComm.md
href: usage/GenericComm.md
- name: RelayOutput Bridging
href: RelayOutput.md
href: usage/RelayOutput.md
- name: Digital Input Bridging
href: DigitalInput.md
href: usage/DigitalInput.md
- name: IR Driver Bridging
href: IR-Driver-Bridging.md
href: usage/IR-Driver-Bridging.md
- name: Technical documentation
items:
- href: Arch-summary.md
- href: technical-docs/Arch-summary.md
- name: Devices and DeviceManager
href: Arch-1.md
href: technical-docs/Arch-1.md
- name: Configurable lifecycle
href: Arch-lifecycle.md
href: technical-docs/Arch-lifecycle.md
- name: Activation phases
href: Arch-activate.md
href: technical-docs/Arch-activate.md
- name: More
href: Arch-topics.md
href: technical-docs/Arch-topics.md
- name: Plugins
href: Plugins.md
href: technical-docs/Plugins.md
- name: Communication Basics
href: Communication-Basics.md
href: technical-docs/Communication-Basics.md
- name: Debugging
href: Debugging.md
href: technical-docs/Debugging.md
- name: Feedback Classes
href: Feedback-Classes.md
href: technical-docs/Feedback-Classes.md
- name: Connection Based Routing
href: Connection-Based-Routing.md
href: technical-docs/Connection-Based-Routing.md
- name: Configuration Structure
href: ConfigurationStructure.md
href: technical-docs/ConfigurationStructure.md
- name: Supported Devices
href: Supported-Devices.md
href: technical-docs/Supported-Devices.md
- name: Glossary of Terms
href: Glossary-of-Terms.md
href: technical-docs/Glossary-of-Terms.md

View File

@@ -6,10 +6,10 @@ One of the most powerful features of Essentials is the ability to bridge SIMPL t
Follow the links below for examples of bridging to hardware and network resources.
**[GenericComm Bridging](~/docs/GenericComm.md)**
**[GenericComm Bridging](~/docs/usage/GenericComm.md)**
**[RelayOutput Bridging](~/docs/RelayOutput.md)**
**[RelayOutput Bridging](~/docs/usage/RelayOutput.md)**
**[Digital Input Bridging](~/docs/DigitalInput.md)**
**[Digital Input Bridging](~/docs/usage/DigitalInput.md)**
**[Card Frame Bridging](~/docs/CardFrame.md)**

View File

@@ -286,7 +286,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
3. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
4. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
4. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
5. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing `DisplayControllerJoinMap`. This way, you can swap plugins without needing any change on the SIMPL Windows side. This is extremely powerful when maintaining SIMPL Windows code bases for large deployments that may utilize differing equipment per room. If you can build a SIMPL Windows program that interacts with established join maps, you can swap out the device via config without any change needed to SIMPL Windows.
@@ -302,7 +302,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
## Join Map Documentation
[Join Map Documentation](~/docs/JoinMaps.md)
[Join Map Documentation](~/docs/usage/JoinMaps.md)
## Device Type Join Maps
@@ -408,4 +408,4 @@ Please note that these joinmaps _may_ be using a deprecated implementation. The
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
Next: [Essentials architecture](~/docs/Arch-summary.md)
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)

View File

@@ -8,7 +8,7 @@ By defining devices and a room in a JSON configuration file, Essentials can cont
### Devices
Essentials supports device plugins for communicating with various devices using both standard Crestron CIP communications, Cresnet, SSH, or other TCP/IP-based communication methods. See [the Plugins section](~/docs/Plugins.md) for more details
Essentials supports device plugins for communicating with various devices using both standard Crestron CIP communications, Cresnet, SSH, or other TCP/IP-based communication methods. See [the Plugins section](~/docs/technical-docs/Plugins.md) for more details
### Rooms
@@ -16,4 +16,4 @@ In order to tie together equipment into a unit that comprises what devices are u
See Also: [[Supported Devices|Supported-Devices]]
Next: [Simpl Windows bridging](~/docs/SIMPL-Bridging-Updated.md)
Next: [Simpl Windows bridging](~/docs/usage/SIMPL-Bridging-Updated.md)

View File

@@ -8,12 +8,12 @@ Essentials is a collection of C# libraries that can be used in many ways. It is
## Get started
- [Download essentials build or clone repo](~/docs/Get-started.md)
- [How to get started](~/docs/Get-started.md)
- [Download an Essentials build or clone the repo](~/docs/Get-started.md)
- [Get started](~/docs/Get-started.md)
- [YouTube Video Series Playlist](https://youtube.com/playlist?list=PLKOoNNwgPFZdV5wDEBDZxTHu1KROspaBu)
- [Discord Server](https://discord.gg/6Vh3ssDdPs)
Or use the links to the right to navigate our documentation.
Or use the links to the left to navigate our documentation.
---
@@ -25,21 +25,12 @@ Or use the links to the right to navigate our documentation.
- Shared resources made easily available
- More flexibility with less code
- Configurable using simple JSON files
- Is awesome
---
## Comment
The Essentials wiki is clearly in-progress right now. Take a look at the links to the right. We are actively working on this documentation, so please be patient with us. If you have any comments on or suggestions for the documentation, please file an issue here, with as much detail as you can provide: <https://github.com/PepperDash/Essentials/issues>
Thanks!
---
## Collaboration
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/Plugins.md)
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/technical-docs/Plugins.md)
### Open-source-collaborative workflow
@@ -52,7 +43,7 @@ The `main` branch always contain the latest stable version. The `development` br
- Example: `feature/add-awesomeness` or `hotfix/really-big-oops`
- When working on a new feature or bugfix, branch from the `development` branch. When working on a hotfix, branch from `main`.
3. Make commits as necessary (often is better). And use concise, descriptive language, leveraging issue notation and/or [Closing Keywords](https://help.github.com/articles/closing-issues-using-keywords) to ensure any issues addressed by your work are referenced accordingly.
4. When the scope of the work for your branch is complete, make sure to rebase your branch in case further progress has been made since the repo was forked
4. When the scope of the work for your branch is complete, make sure to update your branch in case further progress has been made since the repo was forked
5. Create a Pull Request to pull your branch into the appropriate branch in the main repository.
6. Your Pull Request will be reviewed by our team and evaluated for inclusion into the main repository.

7
runtimeconfig.json Normal file
View File

@@ -0,0 +1,7 @@
{
"runtimeOptions": {
"configProperties": {
"System.Globalization.Invariant": false
}
}
}

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.19.4-local</Version>
<Version>3.0.0-local</Version>
<InformationalVersion>$(Version)</InformationalVersion>
<Authors>PepperDash Technology</Authors>
<Company>PepperDash Technology</Company>

View File

@@ -1,14 +1,14 @@
<Project>
<ItemGroup>
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).clz" Condition="$(ProjectType) == 'Library'">
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).clz" Condition="$(ProjectType) == 'Library' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != ''">
<Pack>true</Pack>
<PackagePath>build;</PackagePath>
</None>
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz" Condition="$(ProjectType) == 'Program'">
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz" Condition="$(ProjectType) == 'Program' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != '' And ( '$(TargetFramework)' != 'net6.0' ) And ( '$(TargetFramework)' != 'net8.0' )">
<Pack>true</Pack>
<PackagePath>build;</PackagePath>
</None>
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cplz" Condition="$(ProjectType) == 'ProgramLibrary'">
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cplz" Condition="$(ProjectType) == 'ProgramLibrary' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != ''">
<Pack>true</Pack>
<PackagePath>build;</PackagePath>
</None>

View File

@@ -0,0 +1,36 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Allows pre-registration of Crestron service implementations before the <c>Debug</c>
/// static class initialises. Call <see cref="Register"/> from the composition root
/// (e.g. ControlSystem constructor) <em>before</em> any code touches <c>Debug.*</c>.
/// Test projects should call it with no-op / in-memory implementations so that the
/// <c>Debug</c> static constructor never tries to reach the real Crestron SDK.
/// </summary>
public static class DebugServiceRegistration
{
/// <summary>Gets the registered environment abstraction, or <c>null</c> if not registered.</summary>
public static ICrestronEnvironment? Environment { get; private set; }
/// <summary>Gets the registered console abstraction, or <c>null</c> if not registered.</summary>
public static ICrestronConsole? Console { get; private set; }
/// <summary>Gets the registered data-store abstraction, or <c>null</c> if not registered.</summary>
public static ICrestronDataStore? DataStore { get; private set; }
/// <summary>
/// Registers the service implementations that <c>Debug</c> will use when its
/// static constructor runs. Any parameter may be <c>null</c> to leave the
/// corresponding service unregistered (the <c>Debug</c> class will skip that
/// capability gracefully).
/// </summary>
public static void Register(
ICrestronEnvironment? environment,
ICrestronConsole? console,
ICrestronDataStore? dataStore)
{
Environment = environment;
Console = console;
DataStore = dataStore;
}
}

View File

@@ -0,0 +1,100 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Mirrors Crestron's <c>eDevicePlatform</c> without requiring the Crestron SDK.
/// </summary>
public enum DevicePlatform
{
/// <summary>Hardware appliance (e.g. CP4, MC4).</summary>
Appliance,
/// <summary>Crestron Virtual Control / server runtime.</summary>
Server,
}
/// <summary>
/// Mirrors Crestron's <c>eRuntimeEnvironment</c>.
/// </summary>
public enum RuntimeEnvironment
{
/// <summary>SimplSharpPro program slot (hardware 4-series).</summary>
SimplSharpPro,
/// <summary>SimplSharp (older 3-series or server environments).</summary>
SimplSharp,
/// <summary>Any other environment — check for completeness.</summary>
Other,
}
/// <summary>
/// Mirrors Crestron's <c>ConsoleAccessLevelEnum</c>.
/// </summary>
public enum ConsoleAccessLevel
{
AccessAdministrator = 0,
AccessOperator = 1,
AccessProgrammer = 2,
}
/// <summary>
/// Mirrors Crestron's <c>eProgramStatusEventType</c>.
/// </summary>
public enum ProgramStatusEventType
{
Starting,
Stopping,
Paused,
Resumed,
}
/// <summary>
/// Mirrors the event type used by Crestron's <c>EthernetEventArgs</c>.
/// </summary>
public enum EthernetEventType
{
LinkDown = 0,
LinkUp = 1,
}
/// <summary>
/// Event args for Crestron ethernet link events.
/// </summary>
public class PepperDashEthernetEventArgs : EventArgs
{
public EthernetEventType EthernetEventType { get; }
public short EthernetAdapter { get; }
public PepperDashEthernetEventArgs(EthernetEventType eventType, short adapter)
{
EthernetEventType = eventType;
EthernetAdapter = adapter;
}
}
/// <summary>
/// Mirrors the set of <c>CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET</c> values
/// used across this codebase — does not aim to be exhaustive.
/// </summary>
public enum EthernetParameterType
{
GetCurrentIpAddress,
GetHostname,
GetDomainName,
GetLinkStatus,
GetCurrentDhcpState,
GetCurrentIpMask,
GetCurrentRouter,
GetMacAddress,
GetDnsServer,
}
/// <summary>
/// Mirrors Crestron's <c>SocketStatus</c> without requiring the Crestron SDK.
/// </summary>
public enum PepperDashSocketStatus
{
SocketNotConnected = 0,
SocketConnected = 2,
SocketConnectionInProgress = 6,
SocketConnectFailed = 11,
SocketDisconnecting = 12,
SocketBrokenRemotely = 7,
}

View File

@@ -0,0 +1,32 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Abstracts <c>Crestron.SimplSharp.CrestronConsole</c> to allow unit testing
/// without the Crestron SDK.
/// </summary>
public interface ICrestronConsole
{
/// <summary>Prints a line to the Crestron console/telnet output.</summary>
void PrintLine(string message);
/// <summary>Prints text (without newline) to the Crestron console/telnet output.</summary>
void Print(string message);
/// <summary>
/// Sends a response string to the console for the currently-executing console command.
/// </summary>
void ConsoleCommandResponse(string message);
/// <summary>
/// Registers a new command with the Crestron console.
/// </summary>
/// <param name="callback">Handler invoked when the command is typed.</param>
/// <param name="command">Command name (no spaces).</param>
/// <param name="helpText">Help text shown by the Crestron console.</param>
/// <param name="accessLevel">Minimum access level required to run the command.</param>
void AddNewConsoleCommand(
Action<string> callback,
string command,
string helpText,
ConsoleAccessLevel accessLevel);
}

View File

@@ -0,0 +1,31 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Abstracts <c>Crestron.SimplSharp.CrestronDataStore.CrestronDataStoreStatic</c>
/// to allow unit testing without the Crestron SDK.
/// </summary>
public interface ICrestronDataStore
{
/// <summary>Initialises the data store. Must be called once before any other operation.</summary>
void InitStore();
/// <summary>Reads an integer value from the local (program-slot) store.</summary>
/// <returns><c>true</c> if the value was found and read successfully.</returns>
bool TryGetLocalInt(string key, out int value);
/// <summary>Writes an integer value to the local (program-slot) store.</summary>
/// <returns><c>true</c> on success.</returns>
bool SetLocalInt(string key, int value);
/// <summary>Writes an unsigned integer value to the local (program-slot) store.</summary>
/// <returns><c>true</c> on success.</returns>
bool SetLocalUint(string key, uint value);
/// <summary>Reads a boolean value from the local (program-slot) store.</summary>
/// <returns><c>true</c> if the value was found and read successfully.</returns>
bool TryGetLocalBool(string key, out bool value);
/// <summary>Writes a boolean value to the local (program-slot) store.</summary>
/// <returns><c>true</c> on success.</returns>
bool SetLocalBool(string key, bool value);
}

View File

@@ -0,0 +1,52 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Abstracts <c>Crestron.SimplSharp.CrestronEnvironment</c> to allow unit testing
/// without the Crestron SDK.
/// </summary>
public interface ICrestronEnvironment
{
/// <summary>Gets the platform the program is executing on.</summary>
DevicePlatform DevicePlatform { get; }
/// <summary>Gets the current runtime environment.</summary>
RuntimeEnvironment RuntimeEnvironment { get; }
/// <summary>Gets the platform-appropriate newline string.</summary>
string NewLine { get; }
/// <summary>Gets the application number (program slot).</summary>
uint ApplicationNumber { get; }
/// <summary>Gets the room ID (used in Crestron Virtual Control / server environments).</summary>
uint RoomId { get; }
/// <summary>Raised when program status changes (starting, stopping, etc.).</summary>
event EventHandler<ProgramStatusEventArgs> ProgramStatusChanged;
/// <summary>Raised when the ethernet link changes state.</summary>
event EventHandler<PepperDashEthernetEventArgs> EthernetEventReceived;
/// <summary>Gets the application root directory path.</summary>
string GetApplicationRootDirectory();
/// <summary>
/// Returns <c>true</c> when running on real Crestron hardware.
/// Returns <c>false</c> in test / dev environments so that SDK-specific
/// sinks and enrichers can be safely skipped.
/// </summary>
bool IsHardwareRuntime { get; }
}
/// <summary>
/// Event args for <see cref="ICrestronEnvironment.ProgramStatusChanged"/>.
/// </summary>
public class ProgramStatusEventArgs : EventArgs
{
public ProgramStatusEventType EventType { get; }
public ProgramStatusEventArgs(ProgramStatusEventType eventType)
{
EventType = eventType;
}
}

View File

@@ -0,0 +1,16 @@
namespace PepperDash.Core.Abstractions;
/// <summary>
/// Abstracts <c>Crestron.SimplSharp.CrestronEthernetHelper</c> to allow unit testing
/// without the Crestron SDK.
/// </summary>
public interface IEthernetHelper
{
/// <summary>
/// Returns a network parameter string for the specified adapter.
/// </summary>
/// <param name="parameter">The parameter to retrieve.</param>
/// <param name="ethernetAdapterId">Ethernet adapter index (0 = LAN A).</param>
/// <returns>String value of the requested parameter.</returns>
string GetEthernetParameter(EthernetParameterType parameter, short ethernetAdapterId);
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>PepperDash.Core.Abstractions</RootNamespace>
<AssemblyName>PepperDash.Core.Abstractions</AssemblyName>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Deterministic>true</Deterministic>
<NeutralLanguage>en</NeutralLanguage>
<Title>PepperDash Core Abstractions</Title>
<Company>PepperDash Technologies</Company>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/PepperDash/PepperDashCore</RepositoryUrl>
<NullableContextOptions>enable</NullableContextOptions>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<InformationalVersion>$(Version)</InformationalVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<!-- No Crestron SDK reference — this project must remain hardware-agnostic so test projects can reference it -->
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,323 @@
using FluentAssertions;
using PepperDash.Core;
using Xunit;
namespace PepperDash.Core.Tests.Devices;
/// <summary>
/// Tests for <see cref="Device"/> — the base class for all PepperDash devices.
/// These run without Crestron hardware; Debug is initialized with fakes via TestInitializer.
/// </summary>
public class DeviceTests
{
// -----------------------------------------------------------------------
// Construction
// -----------------------------------------------------------------------
[Fact]
public void Constructor_SingleArg_SetsKey()
{
var device = new Device("my-device");
device.Key.Should().Be("my-device");
}
[Fact]
public void Constructor_SingleArg_SetsNameToEmpty()
{
var device = new Device("my-device");
device.Name.Should().BeEmpty();
}
[Fact]
public void Constructor_TwoArg_SetsKeyAndName()
{
var device = new Device("my-device", "My Device");
device.Key.Should().Be("my-device");
device.Name.Should().Be("My Device");
}
[Fact]
public void Constructor_KeyWithDot_StillSetsKey()
{
// The dot triggers a debug log warning but must not prevent construction.
var device = new Device("parent.child");
device.Key.Should().Be("parent.child");
}
// -----------------------------------------------------------------------
// ToString
// -----------------------------------------------------------------------
[Fact]
public void ToString_WithName_FormatsKeyDashName()
{
var device = new Device("cam-01", "Front Camera");
device.ToString().Should().Be("cam-01 - Front Camera");
}
[Fact]
public void ToString_WithoutName_UsesDashPlaceholder()
{
var device = new Device("cam-01");
device.ToString().Should().Be("cam-01 - ---");
}
// -----------------------------------------------------------------------
// DefaultDevice
// -----------------------------------------------------------------------
[Fact]
public void DefaultDevice_IsNotNull()
{
Device.DefaultDevice.Should().NotBeNull();
}
[Fact]
public void DefaultDevice_HasKeyDefault()
{
Device.DefaultDevice.Key.Should().Be("Default");
}
// -----------------------------------------------------------------------
// CustomActivate / Activate / Deactivate / Initialize
// -----------------------------------------------------------------------
[Fact]
public void CustomActivate_DefaultReturnTrue()
{
var device = new TestDevice("d1");
device.CallCustomActivate().Should().BeTrue();
}
[Fact]
public void Deactivate_DefaultReturnsTrue()
{
var device = new Device("d1");
device.Deactivate().Should().BeTrue();
}
[Fact]
public void Activate_CallsCustomActivate_AndReturnsItsResult()
{
var stub = new ActivateTrackingDevice("d1", result: false);
stub.Activate().Should().BeFalse();
stub.CustomActivateCalled.Should().BeTrue();
}
[Fact]
public void Activate_TrueWhenCustomActivateReturnsTrue()
{
var stub = new ActivateTrackingDevice("d1", result: true);
stub.Activate().Should().BeTrue();
}
[Fact]
public void Initialize_DoesNotThrow()
{
var device = new TestDevice("d1");
var act = () => device.CallInitialize();
act.Should().NotThrow();
}
// -----------------------------------------------------------------------
// PreActivate
// -----------------------------------------------------------------------
[Fact]
public void PreActivate_NoActions_DoesNotThrow()
{
var device = new TestDevice("d1");
var act = () => device.PreActivate();
act.Should().NotThrow();
}
[Fact]
public void PreActivate_RunsRegisteredActionsInOrder()
{
var device = new TestDevice("d1");
var order = new List<int>();
device.AddPreActivationAction(() => order.Add(1));
device.AddPreActivationAction(() => order.Add(2));
device.AddPreActivationAction(() => order.Add(3));
device.PreActivate();
order.Should().Equal(1, 2, 3);
}
[Fact]
public void PreActivate_ContinuesAfterFaultingAction()
{
var device = new TestDevice("d1");
var reached = false;
device.AddPreActivationAction(() => throw new InvalidOperationException("boom"));
device.AddPreActivationAction(() => reached = true);
var act = () => device.PreActivate();
act.Should().NotThrow("exceptions in individual actions must be caught internally");
reached.Should().BeTrue("actions after a faulting action must still run");
}
// -----------------------------------------------------------------------
// PostActivate
// -----------------------------------------------------------------------
[Fact]
public void PostActivate_NoActions_DoesNotThrow()
{
var device = new TestDevice("d1");
var act = () => device.PostActivate();
act.Should().NotThrow();
}
[Fact]
public void PostActivate_RunsRegisteredActionsInOrder()
{
var device = new TestDevice("d1");
var order = new List<int>();
device.AddPostActivationAction(() => order.Add(1));
device.AddPostActivationAction(() => order.Add(2));
device.PostActivate();
order.Should().Equal(1, 2);
}
[Fact]
public void PostActivate_ContinuesAfterFaultingAction()
{
var device = new TestDevice("d1");
var reached = false;
device.AddPostActivationAction(() => throw new Exception("boom"));
device.AddPostActivationAction(() => reached = true);
var act = () => device.PostActivate();
act.Should().NotThrow();
reached.Should().BeTrue();
}
// -----------------------------------------------------------------------
// Pre and Post actions are independent lists
// -----------------------------------------------------------------------
[Fact]
public void PreActivationActions_DoNotRunOnPostActivate()
{
var device = new TestDevice("d1");
var preRan = false;
device.AddPreActivationAction(() => preRan = true);
device.PostActivate();
preRan.Should().BeFalse();
}
[Fact]
public void PostActivationActions_DoNotRunOnPreActivate()
{
var device = new TestDevice("d1");
var postRan = false;
device.AddPostActivationAction(() => postRan = true);
device.PreActivate();
postRan.Should().BeFalse();
}
// -----------------------------------------------------------------------
// OnFalse
// -----------------------------------------------------------------------
[Fact]
public void OnFalse_FiresAction_WhenBoolIsFalse()
{
var device = new Device("d1");
var fired = false;
device.OnFalse(false, () => fired = true);
fired.Should().BeTrue();
}
[Fact]
public void OnFalse_DoesNotFireAction_WhenBoolIsTrue()
{
var device = new Device("d1");
var fired = false;
device.OnFalse(true, () => fired = true);
fired.Should().BeFalse();
}
[Fact]
public void OnFalse_DoesNotFireAction_ForNonBoolType()
{
var device = new Device("d1");
var fired = false;
device.OnFalse("not a bool", () => fired = true);
device.OnFalse(0, () => fired = true);
device.OnFalse(null!, () => fired = true);
fired.Should().BeFalse();
}
// -----------------------------------------------------------------------
// Helpers
// -----------------------------------------------------------------------
/// <summary>
/// Exposes protected Device members so test methods can call them directly.
/// </summary>
private class TestDevice : Device
{
public TestDevice(string key) : base(key) { }
public TestDevice(string key, string name) : base(key, name) { }
public void AddPreActivationAction(Action act) => base.AddPreActivationAction(act);
public void AddPostActivationAction(Action act) => base.AddPostActivationAction(act);
public bool CallCustomActivate() => base.CustomActivate();
public void CallInitialize() => base.Initialize();
}
/// <summary>
/// Records whether CustomActivate was invoked and returns a configured result.
/// Used to verify Activate() correctly delegates to CustomActivate().
/// </summary>
private sealed class ActivateTrackingDevice : Device
{
private readonly bool _result;
public bool CustomActivateCalled { get; private set; }
public ActivateTrackingDevice(string key, bool result = true) : base(key)
{
_result = result;
}
protected override bool CustomActivate()
{
CustomActivateCalled = true;
return _result;
}
}
}

View File

@@ -0,0 +1,38 @@
using PepperDash.Core.Abstractions;
namespace PepperDash.Core.Tests.Fakes;
/// <summary>
/// No-op ICrestronConsole that captures output for test assertions.
/// </summary>
public class CapturingCrestronConsole : ICrestronConsole
{
public List<string> Lines { get; } = new();
public List<string> CommandResponses { get; } = new();
public List<(string Command, string HelpText)> RegisteredCommands { get; } = new();
public void PrintLine(string message) => Lines.Add(message);
public void Print(string message) => Lines.Add(message);
public void ConsoleCommandResponse(string message) => CommandResponses.Add(message);
public void AddNewConsoleCommand(
Action<string> callback,
string command,
string helpText,
ConsoleAccessLevel accessLevel)
{
RegisteredCommands.Add((command, helpText));
}
}
/// <summary>
/// Minimal no-op ICrestronConsole that discards all output. Useful when you only
/// care about the system under test and not what it logs.
/// </summary>
public class NoOpCrestronConsole : ICrestronConsole
{
public void PrintLine(string message) { }
public void Print(string message) { }
public void ConsoleCommandResponse(string message) { }
public void AddNewConsoleCommand(Action<string> _, string __, string ___, ConsoleAccessLevel ____) { }
}

View File

@@ -0,0 +1,49 @@
using PepperDash.Core.Abstractions;
namespace PepperDash.Core.Tests.Fakes;
/// <summary>
/// Configurable ICrestronEnvironment for unit tests.
/// Defaults: Appliance / SimplSharpPro / ApplicationNumber=1.
/// </summary>
public class FakeCrestronEnvironment : ICrestronEnvironment
{
public DevicePlatform DevicePlatform { get; set; } = DevicePlatform.Appliance;
public RuntimeEnvironment RuntimeEnvironment { get; set; } = RuntimeEnvironment.SimplSharpPro;
public string NewLine { get; set; } = "\r\n";
public uint ApplicationNumber { get; set; } = 1;
public uint RoomId { get; set; } = 0;
public event EventHandler<ProgramStatusEventArgs>? ProgramStatusChanged;
public event EventHandler<PepperDashEthernetEventArgs>? EthernetEventReceived;
public string GetApplicationRootDirectory() => System.IO.Path.GetTempPath();
/// <inheritdoc/>
public bool IsHardwareRuntime => false;
/// <summary>Simulates a program status event for tests.</summary>
public void RaiseProgramStatus(ProgramStatusEventType type) =>
ProgramStatusChanged?.Invoke(this, new ProgramStatusEventArgs(type));
/// <summary>Simulates an ethernet event for tests.</summary>
public void RaiseEthernetEvent(EthernetEventType type, short adapter = 0) =>
EthernetEventReceived?.Invoke(this, new PepperDashEthernetEventArgs(type, adapter));
}
/// <summary>
/// No-op IEthernetHelper that returns configurable values.
/// </summary>
public class FakeEthernetHelper : IEthernetHelper
{
private readonly Dictionary<EthernetParameterType, string> _values = new();
public FakeEthernetHelper Seed(EthernetParameterType param, string value)
{
_values[param] = value;
return this;
}
public string GetEthernetParameter(EthernetParameterType parameter, short ethernetAdapterId) =>
_values.TryGetValue(parameter, out var v) ? v : string.Empty;
}

View File

@@ -0,0 +1,59 @@
using PepperDash.Core.Abstractions;
namespace PepperDash.Core.Tests.Fakes;
/// <summary>
/// In-memory ICrestronDataStore backed by a dictionary.
/// Use in unit tests to verify that keys are read from and written to the store correctly.
/// </summary>
public class InMemoryCrestronDataStore : ICrestronDataStore
{
private readonly Dictionary<string, object> _store = new();
public bool Initialized { get; private set; }
public void InitStore() => Initialized = true;
public bool TryGetLocalInt(string key, out int value)
{
if (_store.TryGetValue(key, out var raw) && raw is int i)
{
value = i;
return true;
}
value = 0;
return false;
}
public bool SetLocalInt(string key, int value)
{
_store[key] = value;
return true;
}
public bool SetLocalUint(string key, uint value)
{
_store[key] = (int)value;
return true;
}
public bool TryGetLocalBool(string key, out bool value)
{
if (_store.TryGetValue(key, out var raw) && raw is bool b)
{
value = b;
return true;
}
value = false;
return false;
}
public bool SetLocalBool(string key, bool value)
{
_store[key] = value;
return true;
}
/// <summary>Seeds a key for testing read paths.</summary>
public void Seed(string key, object value) => _store[key] = value;
}

View File

@@ -0,0 +1,171 @@
using FluentAssertions;
using PepperDash.Core.Abstractions;
using PepperDash.Core.Tests.Fakes;
using Xunit;
namespace PepperDash.Core.Tests.Logging;
/// <summary>
/// Tests for Debug-related service interfaces and implementations.
/// These tests verify the behaviour of the abstractions in isolation (no Crestron SDK required).
/// </summary>
public class DebugServiceTests
{
// -----------------------------------------------------------------------
// ICrestronDataStore — InMemoryCrestronDataStore
// -----------------------------------------------------------------------
[Fact]
public void DataStore_InitStore_SetsInitializedFlag()
{
var store = new InMemoryCrestronDataStore();
store.Initialized.Should().BeFalse("not yet initialized");
store.InitStore();
store.Initialized.Should().BeTrue();
}
[Fact]
public void DataStore_SetAndGetLocalInt_RoundTrips()
{
var store = new InMemoryCrestronDataStore();
store.SetLocalInt("MyKey", 42).Should().BeTrue();
store.TryGetLocalInt("MyKey", out var value).Should().BeTrue();
value.Should().Be(42);
}
[Fact]
public void DataStore_TryGetLocalInt_ReturnsFalse_WhenKeyAbsent()
{
var store = new InMemoryCrestronDataStore();
store.TryGetLocalInt("Missing", out var value).Should().BeFalse();
value.Should().Be(0);
}
[Fact]
public void DataStore_SetAndGetLocalBool_RoundTrips()
{
var store = new InMemoryCrestronDataStore();
store.SetLocalBool("FlagKey", true).Should().BeTrue();
store.TryGetLocalBool("FlagKey", out var value).Should().BeTrue();
value.Should().BeTrue();
}
[Fact]
public void DataStore_TryGetLocalBool_ReturnsFalse_WhenKeyAbsent()
{
var store = new InMemoryCrestronDataStore();
store.TryGetLocalBool("Missing", out var value).Should().BeFalse();
value.Should().BeFalse();
}
[Fact]
public void DataStore_SetLocalUint_CanBeReadBackAsInt()
{
var store = new InMemoryCrestronDataStore();
store.SetLocalUint("UintKey", 3u).Should().BeTrue();
store.TryGetLocalInt("UintKey", out var value).Should().BeTrue();
value.Should().Be(3);
}
[Fact]
public void DataStore_Seed_AllowsTestSetupOfReadPaths()
{
var store = new InMemoryCrestronDataStore();
store.Seed("MyLevel", 2);
store.TryGetLocalInt("MyLevel", out var level).Should().BeTrue();
level.Should().Be(2);
}
// -----------------------------------------------------------------------
// DebugServiceRegistration
// -----------------------------------------------------------------------
[Fact]
public void ServiceRegistration_Register_StoresAllThreeServices()
{
var env = new FakeCrestronEnvironment();
var console = new NoOpCrestronConsole();
var store = new InMemoryCrestronDataStore();
DebugServiceRegistration.Register(env, console, store);
DebugServiceRegistration.Environment.Should().BeSameAs(env);
DebugServiceRegistration.Console.Should().BeSameAs(console);
DebugServiceRegistration.DataStore.Should().BeSameAs(store);
}
[Fact]
public void ServiceRegistration_Register_AcceptsNullsWithoutThrowing()
{
var act = () => DebugServiceRegistration.Register(null, null, null);
act.Should().NotThrow();
}
// -----------------------------------------------------------------------
// ICrestronEnvironment — FakeCrestronEnvironment
// -----------------------------------------------------------------------
[Fact]
public void FakeEnvironment_DefaultsToAppliance()
{
var env = new FakeCrestronEnvironment();
env.DevicePlatform.Should().Be(DevicePlatform.Appliance);
}
[Fact]
public void FakeEnvironment_RaiseProgramStatus_FiresEvent()
{
var env = new FakeCrestronEnvironment();
ProgramStatusEventType? received = null;
env.ProgramStatusChanged += (_, e) => received = e.EventType;
env.RaiseProgramStatus(ProgramStatusEventType.Stopping);
received.Should().Be(ProgramStatusEventType.Stopping);
}
[Fact]
public void FakeEnvironment_RaiseEthernetEvent_FiresEvent()
{
var env = new FakeCrestronEnvironment();
EthernetEventType? received = null;
env.EthernetEventReceived += (_, e) => received = e.EthernetEventType;
env.RaiseEthernetEvent(EthernetEventType.LinkUp, adapter: 0);
received.Should().Be(EthernetEventType.LinkUp);
}
// -----------------------------------------------------------------------
// ICrestronConsole — CapturingCrestronConsole
// -----------------------------------------------------------------------
[Fact]
public void CapturingConsole_PrintLine_CapturesMessage()
{
var console = new CapturingCrestronConsole();
console.PrintLine("hello world");
console.Lines.Should().ContainSingle().Which.Should().Be("hello world");
}
[Fact]
public void CapturingConsole_AddNewConsoleCommand_RecordsCommandName()
{
var console = new CapturingCrestronConsole();
console.AddNewConsoleCommand(_ => { }, "appdebug", "Sets debug level", ConsoleAccessLevel.AccessOperator);
console.RegisteredCommands.Should().ContainSingle()
.Which.Command.Should().Be("appdebug");
}
}

View File

@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
</ItemGroup>
<!-- Reference the Abstractions project only — no Crestron SDK dependency -->
<ItemGroup>
<ProjectReference Include="..\PepperDash.Core.Abstractions\PepperDash.Core.Abstractions.csproj" />
<!-- PepperDash.Core is referenced so we can test Device and other concrete types.
DebugServiceRegistration.Register() is called via a [ModuleInitializer] before any
test runs, so Debug's static constructor uses fakes and never touches the Crestron SDK. -->
<ProjectReference Include="..\PepperDash.Core\PepperDash.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,29 @@
using System.Runtime.CompilerServices;
using PepperDash.Core.Abstractions;
using PepperDash.Core.Tests.Fakes;
namespace PepperDash.Core.Tests;
/// <summary>
/// Runs once before any type in this assembly is accessed.
/// Registers fake Crestron service implementations with <see cref="DebugServiceRegistration"/>
/// so that the <c>Debug</c> static constructor uses them instead of the real Crestron SDK.
/// This must remain a module initializer (not a test fixture) because the static constructor
/// fires the first time <em>any</em> type in PepperDash.Core is referenced — before xUnit
/// has a chance to run fixture setup code.
/// </summary>
internal static class TestInitializer
{
[ModuleInitializer]
internal static void Initialize()
{
DebugServiceRegistration.Register(
new FakeCrestronEnvironment
{
DevicePlatform = DevicePlatform.Server, // avoids any appliance-only code paths
RuntimeEnvironment = RuntimeEnvironment.Other, // skips console command registration
},
new NoOpCrestronConsole(),
new InMemoryCrestronDataStore());
}
}

View File

@@ -0,0 +1,35 @@
using System;
using Crestron.SimplSharp;
using PdCore = PepperDash.Core.Abstractions;
namespace PepperDash.Core.Adapters;
/// <summary>
/// Production adapter — delegates ICrestronConsole calls to the real Crestron SDK.
/// </summary>
public sealed class CrestronConsoleAdapter : PdCore.ICrestronConsole
{
public void PrintLine(string message) => CrestronConsole.PrintLine(message);
public void Print(string message) => CrestronConsole.Print(message);
public void ConsoleCommandResponse(string message) =>
CrestronConsole.ConsoleCommandResponse(message);
public void AddNewConsoleCommand(
Action<string> callback,
string command,
string helpText,
PdCore.ConsoleAccessLevel accessLevel)
{
var crestronLevel = accessLevel switch
{
PdCore.ConsoleAccessLevel.AccessAdministrator => ConsoleAccessLevelEnum.AccessAdministrator,
PdCore.ConsoleAccessLevel.AccessProgrammer => ConsoleAccessLevelEnum.AccessProgrammer,
_ => ConsoleAccessLevelEnum.AccessOperator,
};
// Wrap Action<string> in a lambda — Crestron's delegate is not a standard Action<string>.
CrestronConsole.AddNewConsoleCommand(s => callback(s), command, helpText, crestronLevel);
}
}

View File

@@ -0,0 +1,42 @@
using Crestron.SimplSharp.CrestronDataStore;
using PepperDash.Core.Abstractions;
namespace PepperDash.Core.Adapters;
/// <summary>
/// Production adapter — delegates ICrestronDataStore calls to the real Crestron SDK.
/// </summary>
public sealed class CrestronDataStoreAdapter : ICrestronDataStore
{
public void InitStore() => CrestronDataStoreStatic.InitCrestronDataStore();
public bool TryGetLocalInt(string key, out int value)
{
var err = CrestronDataStoreStatic.GetLocalIntValue(key, out value);
return err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
}
public bool SetLocalInt(string key, int value)
{
var err = CrestronDataStoreStatic.SetLocalIntValue(key, value);
return err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
}
public bool SetLocalUint(string key, uint value)
{
var err = CrestronDataStoreStatic.SetLocalUintValue(key, value);
return err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
}
public bool TryGetLocalBool(string key, out bool value)
{
var err = CrestronDataStoreStatic.GetLocalBoolValue(key, out value);
return err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
}
public bool SetLocalBool(string key, bool value)
{
var err = CrestronDataStoreStatic.SetLocalBoolValue(key, value);
return err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS;
}
}

View File

@@ -0,0 +1,71 @@
using System;
using Crestron.SimplSharp;
using PdCore = PepperDash.Core.Abstractions;
namespace PepperDash.Core.Adapters;
/// <summary>
/// Production adapter — delegates ICrestronEnvironment calls to the real Crestron SDK.
/// </summary>
public sealed class CrestronEnvironmentAdapter : PdCore.ICrestronEnvironment
{
// Subscribe once in constructor and re-raise as our event types.
private event EventHandler<PdCore.ProgramStatusEventArgs>? _programStatusChanged;
private event EventHandler<PdCore.PepperDashEthernetEventArgs>? _ethernetEventReceived;
public CrestronEnvironmentAdapter()
{
CrestronEnvironment.ProgramStatusEventHandler += type =>
_programStatusChanged?.Invoke(this, new PdCore.ProgramStatusEventArgs(MapProgramStatus(type)));
CrestronEnvironment.EthernetEventHandler += args =>
_ethernetEventReceived?.Invoke(this, new PdCore.PepperDashEthernetEventArgs(
args.EthernetEventType == eEthernetEventType.LinkDown
? PdCore.EthernetEventType.LinkDown
: PdCore.EthernetEventType.LinkUp,
(short)args.EthernetAdapter));
}
public PdCore.DevicePlatform DevicePlatform =>
CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance
? PdCore.DevicePlatform.Appliance
: PdCore.DevicePlatform.Server;
public PdCore.RuntimeEnvironment RuntimeEnvironment =>
CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro
? PdCore.RuntimeEnvironment.SimplSharpPro
: PdCore.RuntimeEnvironment.Other;
public string NewLine => CrestronEnvironment.NewLine;
public uint ApplicationNumber => InitialParametersClass.ApplicationNumber;
public uint RoomId => uint.TryParse(InitialParametersClass.RoomId, out var r) ? r : 0;
public event EventHandler<PdCore.ProgramStatusEventArgs> ProgramStatusChanged
{
add => _programStatusChanged += value;
remove => _programStatusChanged -= value;
}
public event EventHandler<PdCore.PepperDashEthernetEventArgs> EthernetEventReceived
{
add => _ethernetEventReceived += value;
remove => _ethernetEventReceived -= value;
}
public string GetApplicationRootDirectory() =>
Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory();
/// <inheritdoc/>
public bool IsHardwareRuntime => true;
private static PdCore.ProgramStatusEventType MapProgramStatus(eProgramStatusEventType type) =>
type switch
{
eProgramStatusEventType.Stopping => PdCore.ProgramStatusEventType.Stopping,
eProgramStatusEventType.Paused => PdCore.ProgramStatusEventType.Paused,
eProgramStatusEventType.Resumed => PdCore.ProgramStatusEventType.Resumed,
_ => PdCore.ProgramStatusEventType.Starting,
};
}

View File

@@ -0,0 +1,39 @@
using System;
using Crestron.SimplSharp;
using PepperDash.Core.Abstractions;
namespace PepperDash.Core.Adapters;
/// <summary>
/// Production adapter — delegates IEthernetHelper calls to the real Crestron SDK.
/// </summary>
public sealed class CrestronEthernetAdapter : IEthernetHelper
{
public string GetEthernetParameter(EthernetParameterType parameter, short ethernetAdapterId)
{
var crestronParam = parameter switch
{
EthernetParameterType.GetCurrentIpAddress =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS,
EthernetParameterType.GetHostname =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME,
EthernetParameterType.GetDomainName =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME,
EthernetParameterType.GetLinkStatus =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_LINK_STATUS,
EthernetParameterType.GetCurrentDhcpState =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE,
EthernetParameterType.GetCurrentIpMask =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_MASK,
EthernetParameterType.GetCurrentRouter =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER,
EthernetParameterType.GetMacAddress =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS,
EthernetParameterType.GetDnsServer =>
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DNS_SERVER,
_ => throw new ArgumentOutOfRangeException(nameof(parameter), parameter, null),
};
return CrestronEthernetHelper.GetEthernetParameter(crestronParam, ethernetAdapterId);
}
}

View File

@@ -1,43 +0,0 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace PepperDash.Core
{
/// <summary>
/// Helper class for formatting communication text and byte data for debugging purposes.
/// </summary>
public class ComTextHelper
{
/// <summary>
/// Gets escaped text for a byte array
/// </summary>
/// <param name="bytes"></param>
/// <returns>string with all bytes escaped</returns>
public static string GetEscapedText(byte[] bytes)
{
return string.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets escaped text for a string
/// </summary>
/// <param name="text"></param>
/// <returns>string with all bytes escaped</returns>
public static string GetEscapedText(string text)
{
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
return string.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets debug text for a string
/// </summary>
/// <param name="text"></param>
/// <returns>string with all non-printable characters escaped</returns>
public static string GetDebugText(string text)
{
return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value));
}
}
}

View File

@@ -8,8 +8,8 @@ using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Core
{
namespace PepperDash.Core;
/// <summary>
/// Defines the string event handler for line events on the gather
/// </summary>
@@ -30,7 +30,7 @@ namespace PepperDash.Core
/// <summary>
/// The communication port that this gathers on
/// </summary>
public ICommunicationReceiver Port { get; private set; }
public ICommunicationReceiver Port { get; private set; }
/// <summary>
/// Default false. If true, the delimiter will be included in the line output
@@ -67,22 +67,22 @@ namespace PepperDash.Core
/// </summary>
/// <param name="port"></param>
/// <param name="delimiter"></param>
public CommunicationGather(ICommunicationReceiver port, string delimiter)
:this(port, new string[] { delimiter} )
public CommunicationGather(ICommunicationReceiver port, string delimiter)
:this(port, new string[] { delimiter} )
{
}
/// <summary>
/// Constructor for using an array of string delimiters
/// </summary>
/// <param name="port"></param>
/// <param name="delimiters"></param>
public CommunicationGather(ICommunicationReceiver port, string[] delimiters)
{
Port = port;
StringDelimiters = delimiters;
port.TextReceived += Port_TextReceivedStringDelimiter;
}
/// <summary>
/// Constructor for using an array of string delimiters
/// </summary>
/// <param name="port"></param>
/// <param name="delimiters"></param>
public CommunicationGather(ICommunicationReceiver port, string[] delimiters)
{
Port = port;
StringDelimiters = delimiters;
port.TextReceived += Port_TextReceivedStringDelimiter;
}
/// <summary>
/// Stop method
@@ -135,35 +135,35 @@ namespace PepperDash.Core
ReceiveBuffer.Append(args.Text);
var str = ReceiveBuffer.ToString();
// Case: Receiving DEVICE get version\x0d\0x0a+OK "value":"1234"\x0d\x0a
// Case: Receiving DEVICE get version\x0d\0x0a+OK "value":"1234"\x0d\x0a
// RX: DEV
// Split: (1) "DEV"
// RX: I
// Split: (1) "DEVI"
// RX: CE get version
// Split: (1) "DEVICE get version"
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
// Split: (2) DEVICE get version, +OK "value":"1234"
// RX: DEV
// Split: (1) "DEV"
// RX: I
// Split: (1) "DEVI"
// RX: CE get version
// Split: (1) "DEVICE get version"
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
// Split: (2) DEVICE get version, +OK "value":"1234"
// Iterate the delimiters and fire an event for any matching delimiter
foreach (var delimiter in StringDelimiters)
// Iterate the delimiters and fire an event for any matching delimiter
foreach (var delimiter in StringDelimiters)
{
var lines = Regex.Split(str, delimiter);
if (lines.Length == 1)
continue;
for (int i = 0; i < lines.Length - 1; i++)
{
var lines = Regex.Split(str, delimiter);
if (lines.Length == 1)
continue;
for (int i = 0; i < lines.Length - 1; i++)
{
string strToSend = null;
if (IncludeDelimiter)
strToSend = lines[i] + delimiter;
else
strToSend = lines[i];
handler(this, new GenericCommMethodReceiveTextArgs(strToSend, delimiter));
}
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
string strToSend = null;
if (IncludeDelimiter)
strToSend = lines[i] + delimiter;
else
strToSend = lines[i];
handler(this, new GenericCommMethodReceiveTextArgs(strToSend, delimiter));
}
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
}
}
}
@@ -174,5 +174,4 @@ namespace PepperDash.Core
{
Stop();
}
}
}
}

View File

@@ -1,138 +1,159 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using System.Timers;
using PepperDash.Core;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// Controls the ability to disable/enable debugging of TX/RX data sent to/from a device with a built in timer to disable
/// </summary>
public class CommunicationStreamDebugging
{
/// <summary>
/// Controls the ability to disable/enable debugging of TX/RX data sent to/from a device with a built in timer to disable
/// Device Key that this instance configures
/// </summary>
public class CommunicationStreamDebugging
public string ParentDeviceKey { get; private set; }
/// <summary>
/// Timer to disable automatically if not manually disabled
/// </summary>
private Timer DebugExpiryPeriod;
/// <summary>
/// The current debug setting
/// </summary>
public eStreamDebuggingSetting DebugSetting { get; private set; }
private uint _DebugTimeoutInMs;
private const uint _DefaultDebugTimeoutMin = 30;
/// <summary>
/// Timeout in Minutes
/// </summary>
public uint DebugTimeoutMinutes
{
/// <summary>
/// Device Key that this instance configures
/// </summary>
public string ParentDeviceKey { get; private set; }
/// <summary>
/// Timer to disable automatically if not manually disabled
/// </summary>
private CTimer DebugExpiryPeriod;
/// <summary>
/// Gets or sets the DebugSetting
/// </summary>
public eStreamDebuggingSetting DebugSetting { get; private set; }
private uint _DebugTimeoutInMs;
private const uint _DefaultDebugTimeoutMin = 30;
/// <summary>
/// Timeout in Minutes
/// </summary>
public uint DebugTimeoutMinutes
get
{
get
{
return _DebugTimeoutInMs / 60000;
}
}
/// <summary>
/// Gets or sets the RxStreamDebuggingIsEnabled
/// </summary>
public bool RxStreamDebuggingIsEnabled { get; private set; }
/// <summary>
/// Indicates that transmit stream debugging is enabled
/// </summary>
public bool TxStreamDebuggingIsEnabled { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="parentDeviceKey"></param>
public CommunicationStreamDebugging(string parentDeviceKey)
{
ParentDeviceKey = parentDeviceKey;
}
/// <summary>
/// Sets the debugging setting and if not setting to off, assumes the default of 30 mintues
/// </summary>
/// <param name="setting"></param>
/// <summary>
/// SetDebuggingWithDefaultTimeout method
/// </summary>
public void SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting setting)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
SetDebuggingWithSpecificTimeout(setting, _DefaultDebugTimeoutMin);
}
/// <summary>
/// Sets the debugging setting for the specified number of minutes
/// </summary>
/// <param name="setting"></param>
/// <param name="minutes"></param>
/// <summary>
/// SetDebuggingWithSpecificTimeout method
/// </summary>
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
_DebugTimeoutInMs = minutes * 60000;
StopDebugTimer();
DebugExpiryPeriod = new CTimer((o) => DisableDebugging(), _DebugTimeoutInMs);
if ((setting & eStreamDebuggingSetting.Rx) == eStreamDebuggingSetting.Rx)
RxStreamDebuggingIsEnabled = true;
if ((setting & eStreamDebuggingSetting.Tx) == eStreamDebuggingSetting.Tx)
TxStreamDebuggingIsEnabled = true;
Debug.SetDeviceDebugSettings(ParentDeviceKey, setting);
}
/// <summary>
/// Disabled debugging
/// </summary>
private void DisableDebugging()
{
StopDebugTimer();
Debug.SetDeviceDebugSettings(ParentDeviceKey, eStreamDebuggingSetting.Off);
}
private void StopDebugTimer()
{
RxStreamDebuggingIsEnabled = false;
TxStreamDebuggingIsEnabled = false;
if (DebugExpiryPeriod == null)
{
return;
}
DebugExpiryPeriod.Stop();
DebugExpiryPeriod.Dispose();
DebugExpiryPeriod = null;
return _DebugTimeoutInMs/60000;
}
}
/// <summary>
/// Indicates that receive stream debugging is enabled
/// </summary>
public bool RxStreamDebuggingIsEnabled{ get; private set; }
/// <summary>
/// Indicates that transmit stream debugging is enabled
/// </summary>
public bool TxStreamDebuggingIsEnabled { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="parentDeviceKey"></param>
public CommunicationStreamDebugging(string parentDeviceKey)
{
ParentDeviceKey = parentDeviceKey;
}
/// <summary>
/// Sets the debugging setting and if not setting to off, assumes the default of 30 mintues
/// </summary>
/// <param name="setting"></param>
public void SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting setting)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
SetDebuggingWithSpecificTimeout(setting, _DefaultDebugTimeoutMin);
}
/// <summary>
/// Sets the debugging setting for the specified number of minutes
/// </summary>
/// <param name="setting"></param>
/// <param name="minutes"></param>
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
_DebugTimeoutInMs = minutes * 60000;
StopDebugTimer();
DebugExpiryPeriod = new Timer(_DebugTimeoutInMs) { AutoReset = false };
DebugExpiryPeriod.Elapsed += (s, e) => DisableDebugging();
DebugExpiryPeriod.Start();
if ((setting & eStreamDebuggingSetting.Rx) == eStreamDebuggingSetting.Rx)
RxStreamDebuggingIsEnabled = true;
if ((setting & eStreamDebuggingSetting.Tx) == eStreamDebuggingSetting.Tx)
TxStreamDebuggingIsEnabled = true;
Debug.SetDeviceDebugSettings(ParentDeviceKey, setting);
}
/// <summary>
/// Disabled debugging
/// </summary>
private void DisableDebugging()
{
StopDebugTimer();
Debug.SetDeviceDebugSettings(ParentDeviceKey, eStreamDebuggingSetting.Off);
}
private void StopDebugTimer()
{
RxStreamDebuggingIsEnabled = false;
TxStreamDebuggingIsEnabled = false;
if (DebugExpiryPeriod == null)
{
return;
}
DebugExpiryPeriod.Stop();
DebugExpiryPeriod.Dispose();
DebugExpiryPeriod = null;
}
}
/// <summary>
/// The available settings for stream debugging
/// </summary>
[Flags]
public enum eStreamDebuggingSetting
{
/// <summary>
/// Debug off
/// </summary>
Off = 0,
/// <summary>
/// Debug received data
/// </summary>
Rx = 1,
/// <summary>
/// Debug transmitted data
/// </summary>
Tx = 2,
/// <summary>
/// Debug both received and transmitted data
/// </summary>
Both = Rx | Tx
}

View File

@@ -1,93 +1,97 @@
using System;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
extern alias NewtonsoftJson;
namespace PepperDash.Core
using System;
using Crestron.SimplSharp;
using JsonConverter = NewtonsoftJson::Newtonsoft.Json.JsonConverterAttribute;
using JsonIgnore = NewtonsoftJson::Newtonsoft.Json.JsonIgnoreAttribute;
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
using NullValueHandling = NewtonsoftJson::Newtonsoft.Json.NullValueHandling;
using StringEnumConverter = NewtonsoftJson::Newtonsoft.Json.Converters.StringEnumConverter;
namespace PepperDash.Core;
/// <summary>
/// Config properties that indicate how to communicate with a device for control
/// </summary>
public class ControlPropertiesConfig
{
/// <summary>
/// Represents a ControlPropertiesConfig
/// The method of control
/// </summary>
public class ControlPropertiesConfig
{
/// <summary>
/// The method of control
/// </summary>
[JsonProperty("method")]
[JsonConverter(typeof(StringEnumConverter))]
public eControlMethod Method { get; set; }
[JsonProperty("method")]
[JsonConverter(typeof(StringEnumConverter))]
public eControlMethod Method { get; set; }
/// <summary>
/// The key of the device that contains the control port
/// </summary>
[JsonProperty("controlPortDevKey", NullValueHandling = NullValueHandling.Ignore)]
public string ControlPortDevKey { get; set; }
/// <summary>
/// The key of the device that contains the control port
/// </summary>
[JsonProperty("controlPortDevKey", NullValueHandling = NullValueHandling.Ignore)]
public string ControlPortDevKey { get; set; }
/// <summary>
/// The number of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortNumber", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public uint? ControlPortNumber { get; set; }
/// <summary>
/// The number of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortNumber", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public uint? ControlPortNumber { get; set; }
/// <summary>
/// The name of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortName", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public string ControlPortName { get; set; }
/// <summary>
/// The name of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortName", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public string ControlPortName { get; set; }
/// <summary>
/// Properties for ethernet based communications
/// </summary>
[JsonProperty("tcpSshProperties", NullValueHandling = NullValueHandling.Ignore)]
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
/// <summary>
/// Properties for ethernet based communications
/// </summary>
[JsonProperty("tcpSshProperties", NullValueHandling = NullValueHandling.Ignore)]
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
/// <summary>
/// The filename and path for the IR file
/// </summary>
[JsonProperty("irFile", NullValueHandling = NullValueHandling.Ignore)]
public string IrFile { get; set; }
/// <summary>
/// The filename and path for the IR file
/// </summary>
[JsonProperty("irFile", NullValueHandling = NullValueHandling.Ignore)]
public string IrFile { get; set; }
/// <summary>
/// The IpId of a Crestron device
/// </summary>
[JsonProperty("ipId", NullValueHandling = NullValueHandling.Ignore)]
public string IpId { get; set; }
/// <summary>
/// The IpId of a Crestron device
/// </summary>
[JsonProperty("ipId", NullValueHandling = NullValueHandling.Ignore)]
public string IpId { get; set; }
/// <summary>
/// Readonly uint representation of the IpId
/// </summary>
[JsonIgnore]
public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } }
/// <summary>
/// Readonly uint representation of the IpId
/// </summary>
[JsonIgnore]
public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } }
/// <summary>
/// Char indicating end of line
/// </summary>
[JsonProperty("endOfLineChar", NullValueHandling = NullValueHandling.Ignore)]
public char EndOfLineChar { get; set; }
/// <summary>
/// Char indicating end of line
/// </summary>
[JsonProperty("endOfLineChar", NullValueHandling = NullValueHandling.Ignore)]
public char EndOfLineChar { get; set; }
/// <summary>
/// Defaults to Environment.NewLine;
/// </summary>
[JsonProperty("endOfLineString", NullValueHandling = NullValueHandling.Ignore)]
public string EndOfLineString { get; set; }
/// <summary>
/// Defaults to Environment.NewLine;
/// </summary>
[JsonProperty("endOfLineString", NullValueHandling = NullValueHandling.Ignore)]
public string EndOfLineString { get; set; }
/// <summary>
/// Indicates
/// </summary>
[JsonProperty("deviceReadyResponsePattern", NullValueHandling = NullValueHandling.Ignore)]
public string DeviceReadyResponsePattern { get; set; }
/// <summary>
/// Indicates
/// </summary>
[JsonProperty("deviceReadyResponsePattern", NullValueHandling = NullValueHandling.Ignore)]
public string DeviceReadyResponsePattern { get; set; }
/// <summary>
/// Used when communcating to programs running in VC-4
/// </summary>
[JsonProperty("roomId", NullValueHandling = NullValueHandling.Ignore)]
public string RoomId { get; set; }
/// <summary>
/// Used when communcating to programs running in VC-4
/// </summary>
[JsonProperty("roomId", NullValueHandling = NullValueHandling.Ignore)]
public string RoomId { get; set; }
/// <summary>
/// Constructor
/// </summary>
public ControlPropertiesConfig()
{
}
/// <summary>
/// Constructor
/// </summary>
public ControlPropertiesConfig()
{
}
}

View File

@@ -16,236 +16,237 @@ using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// Delegate for notifying of socket status changes
/// </summary>
/// <param name="client"></param>
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
/// <summary>
/// EventArgs class for socket status changes
/// </summary>
public class GenericSocketStatusChageEventArgs : EventArgs
{
/// <summary>
/// Delegate for notifying of socket status changes
/// Gets or sets the Client
/// </summary>
public ISocketStatus Client { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="client"></param>
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
/// <summary>
/// EventArgs class for socket status changes
/// </summary>
public class GenericSocketStatusChageEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the Client
/// </summary>
public ISocketStatus Client { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="client"></param>
public GenericSocketStatusChageEventArgs(ISocketStatus client)
{
Client = client;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericSocketStatusChageEventArgs() { }
public GenericSocketStatusChageEventArgs(ISocketStatus client)
{
Client = client;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericSocketStatusChageEventArgs() { }
}
/// <summary>
/// Delegate for notifying of TCP Server state changes
/// </summary>
/// <param name="state"></param>
public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state);
/// <summary>
/// EventArgs class for TCP Server state changes
/// </summary>
public class GenericTcpServerStateChangedEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the State
/// </summary>
public ServerState State { get; private set; }
/// <summary>
/// Delegate for notifying of TCP Server state changes
/// Constructor
/// </summary>
/// <param name="state"></param>
public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state);
public GenericTcpServerStateChangedEventArgs(ServerState state)
{
State = state;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerStateChangedEventArgs() { }
}
/// <summary>
/// Delegate for TCP Server socket status changes
/// </summary>
/// <param name="socket"></param>
/// <param name="clientIndex"></param>
/// <param name="clientStatus"></param>
public delegate void GenericTcpServerSocketStatusChangeEventDelegate(object socket, uint clientIndex, SocketStatus clientStatus);
/// <summary>
/// EventArgs for TCP server socket status changes
/// </summary>
public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the Socket
/// </summary>
public object Socket { get; private set; }
/// <summary>
/// EventArgs class for TCP Server state changes
/// Gets or sets the index of the client from which the status change was received
/// </summary>
public class GenericTcpServerStateChangedEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the State
/// </summary>
public ServerState State { get; private set; }
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="state"></param>
public GenericTcpServerStateChangedEventArgs(ServerState state)
{
State = state;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerStateChangedEventArgs() { }
/// <summary>
/// Gets or sets the ClientStatus
/// </summary>
public SocketStatus ClientStatus { get; set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="socket"></param>
/// <param name="clientStatus"></param>
public GenericTcpServerSocketStatusChangeEventArgs(object socket, SocketStatus clientStatus)
{
Socket = socket;
ClientStatus = clientStatus;
}
/// <summary>
/// Delegate for TCP Server socket status changes
/// Constructor
/// </summary>
/// <param name="socket"></param>
/// <param name="clientIndex"></param>
/// <param name="clientStatus"></param>
public delegate void GenericTcpServerSocketStatusChangeEventDelegate(object socket, uint clientIndex, SocketStatus clientStatus);
/// <summary>
/// EventArgs for TCP server socket status changes
/// </summary>
public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs
public GenericTcpServerSocketStatusChangeEventArgs(object socket, uint clientIndex, SocketStatus clientStatus)
{
/// <summary>
///
/// </summary>
public object Socket { get; private set; }
/// <summary>
///
/// </summary>
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
public SocketStatus ClientStatus { get; set; }
Socket = socket;
ReceivedFromClientIndex = clientIndex;
ClientStatus = clientStatus;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerSocketStatusChangeEventArgs() { }
}
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="clientStatus"></param>
public GenericTcpServerSocketStatusChangeEventArgs(object socket, SocketStatus clientStatus)
{
Socket = socket;
ClientStatus = clientStatus;
}
/// <summary>
/// EventArgs for TCP server com method receive text
/// </summary>
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
{
/// <summary>
/// Gets or sets the index of the client from which the text was received
/// </summary>
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="clientIndex"></param>
/// <param name="clientStatus"></param>
public GenericTcpServerSocketStatusChangeEventArgs(object socket, uint clientIndex, SocketStatus clientStatus)
/// <summary>
/// Gets the index of the client from which the text was received as a ushort
/// </summary>
public ushort ReceivedFromClientIndexShort
{
get
{
Socket = socket;
ReceivedFromClientIndex = clientIndex;
ClientStatus = clientStatus;
return (ushort)ReceivedFromClientIndex;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerSocketStatusChangeEventArgs() { }
}
/// <summary>
/// EventArgs for TCP server com method receive text
/// Gets or sets the Text
/// </summary>
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
public string Text { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="text"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text)
{
/// <summary>
///
/// </summary>
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
public ushort ReceivedFromClientIndexShort
{
get
{
return (ushort)ReceivedFromClientIndex;
}
}
/// <summary>
/// Gets or sets the Text
/// </summary>
public string Text { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text)
{
Text = text;
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="clientIndex"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text, uint clientIndex)
{
Text = text;
ReceivedFromClientIndex = clientIndex;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerCommMethodReceiveTextArgs() { }
Text = text;
}
/// <summary>
/// EventArgs for TCP server client ready for communication
/// Constructor
/// </summary>
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
/// <param name="text"></param>
/// <param name="clientIndex"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text, uint clientIndex)
{
/// <summary>
///
/// </summary>
public bool IsReady;
Text = text;
ReceivedFromClientIndex = clientIndex;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerCommMethodReceiveTextArgs() { }
}
/// <summary>
///
/// </summary>
/// <param name="isReady"></param>
public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady)
{
IsReady = isReady;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerClientReadyForcommunicationsEventArgs() { }
/// <summary>
/// EventArgs for TCP server client ready for communication
/// </summary>
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
{
/// <summary>
/// Gets or sets IsReady
/// </summary>
public bool IsReady;
/// <summary>
/// Constructor
/// </summary>
/// <param name="isReady"></param>
public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady)
{
IsReady = isReady;
}
/// <summary>
/// EventArgs for UDP connected
/// S+ Constructor
/// </summary>
public class GenericUdpConnectedEventArgs : EventArgs
public GenericTcpServerClientReadyForcommunicationsEventArgs() { }
}
/// <summary>
/// EventArgs for UDP connected
/// </summary>
public class GenericUdpConnectedEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the UConnected
/// </summary>
public ushort UConnected;
/// <summary>
/// Gets or sets the Connected status
/// </summary>
public bool Connected;
/// <summary>
/// Constructor
/// </summary>
public GenericUdpConnectedEventArgs() { }
/// <summary>
/// Constructor
/// </summary>
/// <param name="uconnected"></param>
public GenericUdpConnectedEventArgs(ushort uconnected)
{
/// <summary>
///
/// </summary>
public ushort UConnected;
/// <summary>
///
/// </summary>
public bool Connected;
/// <summary>
/// Constructor
/// </summary>
public GenericUdpConnectedEventArgs() { }
/// <summary>
///
/// </summary>
/// <param name="uconnected"></param>
public GenericUdpConnectedEventArgs(ushort uconnected)
{
UConnected = uconnected;
}
/// <summary>
///
/// </summary>
/// <param name="connected"></param>
public GenericUdpConnectedEventArgs(bool connected)
{
Connected = connected;
}
UConnected = uconnected;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="connected"></param>
public GenericUdpConnectedEventArgs(bool connected)
{
Connected = connected;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,371 +1,357 @@
extern alias NewtonsoftJson;
using System;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets;
using Newtonsoft.Json;
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
using PepperDash.Core.Logging;
using Required = NewtonsoftJson::Newtonsoft.Json.Required;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// Generic UDP Server device
/// </summary>
public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging
{
private const string SplusKey = "Uninitialized Udp Server";
/// <summary>
/// Generic UDP Server device
/// Object to enable stream debugging
/// </summary>
public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging
{
private const string SplusKey = "Uninitialized Udp Server";
/// <summary>
/// Object to enable stream debugging
/// </summary>
public CommunicationStreamDebugging StreamDebugging { get; private set; }
/// <summary>
///
/// </summary>
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
public CommunicationStreamDebugging StreamDebugging { get; private set; }
/// <summary>
///
/// </summary>
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
///
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
///
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// This event will fire when a message is dequeued that includes the source IP and Port info if needed to determine the source of the received data.
/// </summary>
/// <summary>
/// This event will fire when a message is dequeued that includes the source IP and Port info if needed to determine the source of the received data.
/// </summary>
public event EventHandler<GenericUdpReceiveTextExtraArgs> DataRecievedExtra;
/// <summary>
///
/// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
///
/// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
///
/// </summary>
public event EventHandler<GenericUdpConnectedEventArgs> UpdateConnectionStatus;
/// <summary>
///
/// </summary>
public event EventHandler<GenericUdpConnectedEventArgs> UpdateConnectionStatus;
/// <summary>
///
/// </summary>
public SocketStatus ClientStatus
/// <summary>
///
/// </summary>
public SocketStatus ClientStatus
{
get
{
get
{
return Server.ServerStatus;
}
return Server.ServerStatus;
}
/// <summary>
///
/// </summary>
public ushort UStatus
{
get { return (ushort)Server.ServerStatus; }
}
/// <summary>
/// Address of server
/// </summary>
public string Hostname { get; set; }
/// <summary>
/// Port on server
/// </summary>
public int Port { get; set; }
/// <summary>
/// Another damn S+ helper because S+ seems to treat large port nums as signed ints
/// which screws up things
/// </summary>
public ushort UPort
{
get { return Convert.ToUInt16(Port); }
set { Port = Convert.ToInt32(value); }
}
/// <summary>
/// Indicates that the UDP Server is enabled
/// </summary>
public bool IsConnected
{
get;
private set;
}
/// <summary>
/// Numeric value indicating
/// </summary>
public ushort UIsConnected
{
get { return IsConnected ? (ushort)1 : (ushort)0; }
}
/// <summary>
/// Defaults to 2000
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// The server
/// </summary>
public UDPServer Server { get; private set; }
/// <summary>
/// Constructor for S+. Make sure to set key, address, port, and buffersize using init method
/// </summary>
public GenericUdpServer()
: base(SplusKey)
{
StreamDebugging = new CommunicationStreamDebugging(SplusKey);
BufferSize = 5000;
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <param name="bufferSize"></param>
public GenericUdpServer(string key, string address, int port, int bufferSize)
: base(key)
{
StreamDebugging = new CommunicationStreamDebugging(key);
Hostname = address;
Port = port;
BufferSize = bufferSize;
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
}
/// <summary>
/// Call from S+ to initialize values
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <summary>
/// Initialize method
/// </summary>
public void Initialize(string key, string address, ushort port)
{
Key = key;
Hostname = address;
UPort = port;
}
/// <summary>
///
/// </summary>
/// <param name="ethernetEventArgs"></param>
void CrestronEnvironment_EthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{
// Re-enable the server if the link comes back up and the status should be connected
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp
&& IsConnected)
{
Connect();
}
}
/// <summary>
///
/// </summary>
/// <param name="programEventType"></param>
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType != eProgramStatusEventType.Stopping)
return;
Debug.Console(1, this, "Program stopping. Disabling Server");
Disconnect();
}
/// <summary>
/// Connect method
/// </summary>
public void Connect()
{
if (Server == null)
{
try
{
var address = IPAddress.Parse(Hostname);
Server = new UDPServer(address, Port, BufferSize);
}
catch (Exception ex)
{
this.LogError("Error parsing IP Address '{ipAddress}': message: {message}", Hostname, ex.Message);
this.LogInformation("Creating UDPServer with default buffersize");
Server = new UDPServer();
}
}
if (string.IsNullOrEmpty(Hostname))
{
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericUdpServer '{0}': No address set", Key);
return;
}
if (Port < 1 || Port > 65535)
{
{
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericUdpServer '{0}': Invalid port", Key);
return;
}
}
var status = Server.EnableUDPServer(Hostname, Port);
Debug.Console(2, this, "SocketErrorCode: {0}", status);
if (status == SocketErrorCodes.SOCKET_OK)
IsConnected = true;
var handler = UpdateConnectionStatus;
if (handler != null)
handler(this, new GenericUdpConnectedEventArgs(UIsConnected));
// Start receiving data
Server.ReceiveDataAsync(Receive);
}
/// <summary>
/// Disconnect method
/// </summary>
public void Disconnect()
{
if (Server != null)
Server.DisableUDPServer();
IsConnected = false;
var handler = UpdateConnectionStatus;
if (handler != null)
handler(this, new GenericUdpConnectedEventArgs(UIsConnected));
}
/// <summary>
/// Recursive method to receive data
/// </summary>
/// <param name="server"></param>
/// <param name="numBytes"></param>
void Receive(UDPServer server, int numBytes)
{
Debug.Console(2, this, "Received {0} bytes", numBytes);
try
{
if (numBytes <= 0)
return;
var sourceIp = Server.IPAddressLastMessageReceivedFrom;
var sourcePort = Server.IPPortLastMessageReceivedFrom;
var bytes = server.IncomingDataBuffer.Take(numBytes).ToArray();
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
var dataRecivedExtra = DataRecievedExtra;
if (dataRecivedExtra != null)
dataRecivedExtra(this, new GenericUdpReceiveTextExtraArgs(str, sourceIp, sourcePort, bytes));
Debug.Console(2, this, "Bytes: {0}", bytes.ToString());
var bytesHandler = BytesReceived;
if (bytesHandler != null)
{
this.PrintReceivedBytes(bytes);
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
}
var textHandler = TextReceived;
if (textHandler != null)
{
this.PrintReceivedText(str);
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
}
}
catch (Exception ex)
{
this.LogException(ex, "GenericUdpServer Receive error");
}
finally
{
server.ReceiveDataAsync(Receive);
}
}
/// <summary>
/// General send method
/// </summary>
/// <param name="text"></param>
/// <summary>
/// SendText method
/// </summary>
public void SendText(string text)
{
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
if (IsConnected && Server != null)
{
this.PrintSentText(text);
Server.SendData(bytes, bytes.Length);
}
}
/// <summary>
///
/// </summary>
/// <param name="bytes"></param>
/// <summary>
/// SendBytes method
/// </summary>
public void SendBytes(byte[] bytes)
{
this.PrintSentBytes(bytes);
if (IsConnected && Server != null)
Server.SendData(bytes, bytes.Length);
}
}
/// <summary>
/// Represents a GenericUdpReceiveTextExtraArgs
/// </summary>
public class GenericUdpReceiveTextExtraArgs : EventArgs
public ushort UStatus
{
/// <summary>
///
/// </summary>
get { return (ushort)Server.ServerStatus; }
}
/// <summary>
/// Address of server
/// </summary>
public string Hostname { get; set; }
/// <summary>
/// Port on server
/// </summary>
public int Port { get; set; }
/// <summary>
/// Another damn S+ helper because S+ seems to treat large port nums as signed ints
/// which screws up things
/// </summary>
public ushort UPort
{
get { return Convert.ToUInt16(Port); }
set { Port = Convert.ToInt32(value); }
}
/// <summary>
/// Indicates that the UDP Server is enabled
/// </summary>
public bool IsConnected
{
get;
private set;
}
/// <summary>
/// Numeric value indicating
/// </summary>
public ushort UIsConnected
{
get { return IsConnected ? (ushort)1 : (ushort)0; }
}
/// <summary>
/// Defaults to 2000
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// The server
/// </summary>
public UDPServer Server { get; private set; }
/// <summary>
/// Constructor for S+. Make sure to set key, address, port, and buffersize using init method
/// </summary>
public GenericUdpServer()
: base(SplusKey)
{
StreamDebugging = new CommunicationStreamDebugging(SplusKey);
BufferSize = 5000;
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <param name="buffefSize"></param>
public GenericUdpServer(string key, string address, int port, int buffefSize)
: base(key)
{
StreamDebugging = new CommunicationStreamDebugging(key);
Hostname = address;
Port = port;
BufferSize = buffefSize;
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
}
/// <summary>
/// Call from S+ to initialize values
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
public void Initialize(string key, string address, ushort port)
{
Key = key;
Hostname = address;
UPort = port;
}
/// <summary>
///
/// </summary>
/// <param name="ethernetEventArgs"></param>
void CrestronEnvironment_EthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{
// Re-enable the server if the link comes back up and the status should be connected
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp
&& IsConnected)
{
Connect();
}
}
/// <summary>
///
/// </summary>
/// <param name="programEventType"></param>
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType != eProgramStatusEventType.Stopping)
return;
this.LogInformation("Program stopping. Disabling Server");
Disconnect();
}
/// <summary>
/// Enables the UDP Server
/// </summary>
public void Connect()
{
if (Server == null)
{
Server = new UDPServer();
}
if (string.IsNullOrEmpty(Hostname))
{
this.LogWarning("GenericUdpServer '{0}': No address set", Key);
return;
}
if (Port < 1 || Port > 65535)
{
{
this.LogWarning("GenericUdpServer '{0}': Invalid port", Key);
return;
}
}
var status = Server.EnableUDPServer(Hostname, Port);
this.LogVerbose("SocketErrorCode: {0}", status);
if (status == SocketErrorCodes.SOCKET_OK)
IsConnected = true;
var handler = UpdateConnectionStatus;
if (handler != null)
handler(this, new GenericUdpConnectedEventArgs(UIsConnected));
// Start receiving data
Server.ReceiveDataAsync(Receive);
}
/// <summary>
/// Disabled the UDP Server
/// </summary>
public void Disconnect()
{
if(Server != null)
Server.DisableUDPServer();
IsConnected = false;
var handler = UpdateConnectionStatus;
if (handler != null)
handler(this, new GenericUdpConnectedEventArgs(UIsConnected));
}
/// <summary>
/// Recursive method to receive data
/// </summary>
/// <param name="server"></param>
/// <param name="numBytes"></param>
void Receive(UDPServer server, int numBytes)
{
this.LogVerbose("Received {0} bytes", numBytes);
try
{
if (numBytes <= 0)
return;
var sourceIp = Server.IPAddressLastMessageReceivedFrom;
var sourcePort = Server.IPPortLastMessageReceivedFrom;
var bytes = server.IncomingDataBuffer.Take(numBytes).ToArray();
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
var dataRecivedExtra = DataRecievedExtra;
if (dataRecivedExtra != null)
dataRecivedExtra(this, new GenericUdpReceiveTextExtraArgs(str, sourceIp, sourcePort, bytes));
this.LogVerbose("Bytes: {0}", bytes.ToString());
var bytesHandler = BytesReceived;
if (bytesHandler != null)
{
if (StreamDebugging.RxStreamDebuggingIsEnabled)
{
this.LogInformation("Received {1} bytes: '{0}'", ComTextHelper.GetEscapedText(bytes), bytes.Length);
}
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
}
var textHandler = TextReceived;
if (textHandler != null)
{
if (StreamDebugging.RxStreamDebuggingIsEnabled)
this.LogInformation("Received {1} characters of text: '{0}'", ComTextHelper.GetDebugText(str), str.Length);
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
}
}
catch (Exception ex)
{
this.LogException(ex, "GenericUdpServer Receive error");
}
finally
{
server.ReceiveDataAsync(Receive);
}
}
/// <summary>
/// General send method
/// </summary>
/// <param name="text"></param>
public void SendText(string text)
{
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
if (IsConnected && Server != null)
{
if (StreamDebugging.TxStreamDebuggingIsEnabled)
this.LogVerbose("Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
Server.SendData(bytes, bytes.Length);
}
}
/// <summary>
///
/// </summary>
/// <param name="bytes"></param>
public void SendBytes(byte[] bytes)
{
if (StreamDebugging.TxStreamDebuggingIsEnabled)
this.LogInformation("Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
if (IsConnected && Server != null)
Server.SendData(bytes, bytes.Length);
}
}
/// <summary>
///
/// </summary>
public class GenericUdpReceiveTextExtraArgs : EventArgs
{
/// <summary>
///
/// </summary>
public string Text { get; private set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string IpAddress { get; private set; }
/// <summary>
///
/// </summary>
public int Port { get; private set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int Port { get; private set; }
/// <summary>
///
/// </summary>
public byte[] Bytes { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="bytes"></param>
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="ipAddress"></param>
/// <param name="port"></param>
/// <param name="bytes"></param>
public GenericUdpReceiveTextExtraArgs(string text, string ipAddress, int port, byte[] bytes)
{
Text = text;
@@ -380,34 +366,33 @@ namespace PepperDash.Core
public GenericUdpReceiveTextExtraArgs() { }
}
/// <summary>
///
/// </summary>
public class UdpServerPropertiesConfig
{
/// <summary>
///
/// </summary>
public class UdpServerPropertiesConfig
[JsonProperty(Required = Required.Always)]
public string Address { get; set; }
/// <summary>
///
/// </summary>
[JsonProperty(Required = Required.Always)]
public int Port { get; set; }
/// <summary>
/// Defaults to 32768
/// </summary>
public int BufferSize { get; set; }
/// <summary>
///
/// </summary>
public UdpServerPropertiesConfig()
{
/// <summary>
///
/// </summary>
[JsonProperty(Required = Required.Always)]
public string Address { get; set; }
/// <summary>
///
/// </summary>
[JsonProperty(Required = Required.Always)]
public int Port { get; set; }
/// <summary>
/// Defaults to 32768
/// </summary>
public int BufferSize { get; set; }
/// <summary>
///
/// </summary>
public UdpServerPropertiesConfig()
{
BufferSize = 32768;
}
BufferSize = 32768;
}
}

View File

@@ -1,59 +1,60 @@
using Newtonsoft.Json;
extern alias NewtonsoftJson;
namespace PepperDash.Core
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
namespace PepperDash.Core;
/// <summary>
/// Client config object for TCP client with server that inherits from TcpSshPropertiesConfig and adds properties for shared key and heartbeat
/// </summary>
public class TcpClientConfigObject
{
/// <summary>
/// Represents a TcpClientConfigObject
/// TcpSsh Properties
/// </summary>
public class TcpClientConfigObject
{
/// <summary>
/// TcpSsh Properties
/// </summary>
[JsonProperty("control")]
public ControlPropertiesConfig Control { get; set; }
[JsonProperty("control")]
public ControlPropertiesConfig Control { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
[JsonProperty("secure")]
public bool Secure { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
[JsonProperty("secure")]
public bool Secure { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
[JsonProperty("sharedKeyRequired")]
public bool SharedKeyRequired { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
[JsonProperty("sharedKeyRequired")]
public bool SharedKeyRequired { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
[JsonProperty("sharedKey")]
public string SharedKey { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
[JsonProperty("sharedKey")]
public string SharedKey { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
[JsonProperty("heartbeatRequired")]
public bool HeartbeatRequired { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
[JsonProperty("heartbeatRequired")]
public bool HeartbeatRequired { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
[JsonProperty("heartbeatRequiredIntervalInSeconds")]
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
[JsonProperty("heartbeatRequiredIntervalInSeconds")]
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
[JsonProperty("heartbeatStringToMatch")]
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
[JsonProperty("heartbeatStringToMatch")]
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
[JsonProperty("receiveQueueSize")]
public int ReceiveQueueSize { get; set; }
}
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
[JsonProperty("receiveQueueSize")]
public int ReceiveQueueSize { get; set; }
}

View File

@@ -4,57 +4,56 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// Tcp Server Config object with properties for a tcp server with shared key and heartbeat capabilities
/// </summary>
public class TcpServerConfigObject
{
/// <summary>
/// Tcp Server Config object with properties for a tcp server with shared key and heartbeat capabilities
/// Uique key
/// </summary>
public class TcpServerConfigObject
{
/// <summary>
/// Uique key
/// </summary>
public string Key { get; set; }
/// <summary>
/// Max Clients that the server will allow to connect.
/// </summary>
public ushort MaxClients { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
public bool Secure { get; set; }
/// <summary>
/// Port for the server to listen on
/// </summary>
public int Port { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
public bool SharedKeyRequired { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
public string SharedKey { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
public bool HeartbeatRequired { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// Client buffer size. See Crestron help. defaults to 2000 if not greater than 2000
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
public int ReceiveQueueSize { get; set; }
}
public string Key { get; set; }
/// <summary>
/// Max Clients that the server will allow to connect.
/// </summary>
public ushort MaxClients { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
public bool Secure { get; set; }
/// <summary>
/// Port for the server to listen on
/// </summary>
public int Port { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
public bool SharedKeyRequired { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
public string SharedKey { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
public bool HeartbeatRequired { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// Client buffer size. See Crestron help. defaults to 2000 if not greater than 2000
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
public int ReceiveQueueSize { get; set; }
}

View File

@@ -4,84 +4,83 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// Crestron Control Methods for a comm object
/// </summary>
public enum eControlMethod
{
/// <summary>
/// Crestron Control Methods for a comm object
///
/// </summary>
public enum eControlMethod
{
/// <summary>
///
/// </summary>
None = 0,
/// <summary>
/// RS232/422/485
/// </summary>
Com,
/// <summary>
/// Crestron IpId (most Crestron ethernet devices)
/// </summary>
IpId,
/// <summary>
/// Crestron IpIdTcp (HD-MD series, etc.)
/// </summary>
IpidTcp,
/// <summary>
/// Crestron IR control
/// </summary>
IR,
/// <summary>
/// SSH client
/// </summary>
Ssh,
/// <summary>
/// TCP/IP client
/// </summary>
Tcpip,
/// <summary>
/// Telnet
/// </summary>
Telnet,
/// <summary>
/// Crestnet device
/// </summary>
Cresnet,
/// <summary>
/// CEC Control, via a DM HDMI port
/// </summary>
Cec,
/// <summary>
/// UDP Server
/// </summary>
Udp,
/// <summary>
/// HTTP client
/// </summary>
Http,
/// <summary>
/// HTTPS client
/// </summary>
Https,
/// <summary>
/// Websocket client
/// </summary>
Ws,
/// <summary>
/// Secure Websocket client
/// </summary>
Wss,
/// <summary>
/// Secure TCP/IP
/// </summary>
SecureTcpIp,
/// <summary>
/// Used when comms needs to be handled in SIMPL and bridged opposite the normal direction
/// </summary>
ComBridge,
/// <summary>
/// InfinetEX control
/// </summary>
InfinetEx
}
None = 0,
/// <summary>
/// RS232/422/485
/// </summary>
Com,
/// <summary>
/// Crestron IpId (most Crestron ethernet devices)
/// </summary>
IpId,
/// <summary>
/// Crestron IpIdTcp (HD-MD series, etc.)
/// </summary>
IpidTcp,
/// <summary>
/// Crestron IR control
/// </summary>
IR,
/// <summary>
/// SSH client
/// </summary>
Ssh,
/// <summary>
/// TCP/IP client
/// </summary>
Tcpip,
/// <summary>
/// Telnet
/// </summary>
Telnet,
/// <summary>
/// Crestnet device
/// </summary>
Cresnet,
/// <summary>
/// CEC Control, via a DM HDMI port
/// </summary>
Cec,
/// <summary>
/// UDP Server
/// </summary>
Udp,
/// <summary>
/// HTTP client
/// </summary>
Http,
/// <summary>
/// HTTPS client
/// </summary>
Https,
/// <summary>
/// Websocket client
/// </summary>
Ws,
/// <summary>
/// Secure Websocket client
/// </summary>
Wss,
/// <summary>
/// Secure TCP/IP
/// </summary>
SecureTcpIp,
/// <summary>
/// Crestron COM bridge
/// </summary>
ComBridge,
/// <summary>
/// Crestron Infinet EX device
/// </summary>
InfinetEx
}

View File

@@ -1,28 +0,0 @@
using System;
namespace PepperDash.Core
{
/// <summary>
/// The available settings for stream debugging
/// </summary>
[Flags]
public enum eStreamDebuggingSetting
{
/// <summary>
/// Debug off
/// </summary>
Off = 0,
/// <summary>
/// Debug received data
/// </summary>
Rx = 1,
/// <summary>
/// Debug transmitted data
/// </summary>
Tx = 2,
/// <summary>
/// Debug both received and transmitted data
/// </summary>
Both = Rx | Tx
}
}

View File

@@ -1,136 +1,143 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets;
using Newtonsoft.Json;
using JsonConverter = NewtonsoftJson::Newtonsoft.Json.JsonConverterAttribute;
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
using StringEnumConverter = NewtonsoftJson::Newtonsoft.Json.Converters.StringEnumConverter;
namespace PepperDash.Core
namespace PepperDash.Core;
/// <summary>
/// An incoming communication stream
/// </summary>
public interface ICommunicationReceiver : IKeyed
{
/// <summary>
/// An incoming communication stream
/// Notifies of bytes received
/// </summary>
public interface ICommunicationReceiver : IKeyed
{
/// <summary>
/// Notifies of bytes received
/// </summary>
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies of text received
/// </summary>
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Indicates connection status
/// </summary>
[JsonProperty("isConnected")]
bool IsConnected { get; }
/// <summary>
/// Connect to the device
/// </summary>
void Connect();
/// <summary>
/// Disconnect from the device
/// </summary>
void Disconnect();
}
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies of text received
/// </summary>
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Defines the contract for IBasicCommunication
/// Indicates connection status
/// </summary>
public interface IBasicCommunication : ICommunicationReceiver
{
/// <summary>
/// Send text to the device
/// </summary>
/// <param name="text"></param>
[JsonProperty("isConnected")]
bool IsConnected { get; }
/// <summary>
/// Connect to the device
/// </summary>
void Connect();
/// <summary>
/// Disconnect from the device
/// </summary>
void Disconnect();
}
/// <summary>
/// Extends <see cref="ICommunicationReceiver"/> with methods for sending text and bytes to a device.
/// </summary>
public interface IBasicCommunication : ICommunicationReceiver
{
/// <summary>
/// Send text to the device
/// </summary>
/// <param name="text"></param>
void SendText(string text);
/// <summary>
/// Send bytes to the device
/// </summary>
/// <param name="bytes"></param>
/// <summary>
/// Send bytes to the device
/// </summary>
/// <param name="bytes"></param>
void SendBytes(byte[] bytes);
}
/// <summary>
/// Represents a device that implements IBasicCommunication and IStreamDebugging
/// </summary>
public interface IBasicCommunicationWithStreamDebugging : IBasicCommunication, IStreamDebugging
{
/// <summary>
/// Represents a device that implements IBasicCommunication and IStreamDebugging
/// </summary>
public interface IBasicCommunicationWithStreamDebugging : IBasicCommunication, IStreamDebugging
{
}
}
/// <summary>
/// Represents a device with stream debugging capablities
/// </summary>
public interface IStreamDebugging : IKeyed
{
/// <summary>
/// Represents a device with stream debugging capablities
/// Object to enable stream debugging
/// </summary>
public interface IStreamDebugging : IKeyed
{
/// <summary>
/// Object to enable stream debugging
/// </summary>
[JsonProperty("streamDebugging")]
CommunicationStreamDebugging StreamDebugging { get; }
}
[JsonProperty("streamDebugging")]
CommunicationStreamDebugging StreamDebugging { get; }
}
/// <summary>
/// For IBasicCommunication classes that have SocketStatus. GenericSshClient,
/// GenericTcpIpClient
/// </summary>
public interface ISocketStatus : IBasicCommunication
{
/// <summary>
/// For IBasicCommunication classes that have SocketStatus. GenericSshClient,
/// GenericTcpIpClient
/// Notifies of socket status changes
/// </summary>
public interface ISocketStatus : IBasicCommunication
{
/// <summary>
/// Notifies of socket status changes
/// </summary>
event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
/// The current socket status of the client
/// </summary>
[JsonProperty("clientStatus")]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
SocketStatus ClientStatus { get; }
}
/// <summary>
/// Describes a device that implements ISocketStatus and IStreamDebugging
/// The current socket status of the client
/// </summary>
public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging
{
[JsonProperty("clientStatus")]
[JsonConverter(typeof(StringEnumConverter))]
SocketStatus ClientStatus { get; }
}
}
/// <summary>
/// Describes a device that implements ISocketStatus and IStreamDebugging
/// </summary>
public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging
{
/// <summary>
/// Describes a device that can automatically attempt to reconnect
/// </summary>
}
/// <summary>
/// Describes a device that can automatically attempt to reconnect
/// </summary>
public interface IAutoReconnect
{
/// <summary>
/// Enable automatic recconnect
/// </summary>
[JsonProperty("autoReconnect")]
bool AutoReconnect { get; set; }
/// <summary>
/// Interval in ms to attempt automatic recconnections
/// </summary>
[JsonProperty("autoReconnectIntervalMs")]
int AutoReconnectIntervalMs { get; set; }
}
{
/// <summary>
///
/// Enable automatic recconnect
/// </summary>
[JsonProperty("autoReconnect")]
bool AutoReconnect { get; set; }
/// <summary>
/// Interval in ms to attempt automatic recconnections
/// </summary>
[JsonProperty("autoReconnectIntervalMs")]
int AutoReconnectIntervalMs { get; set; }
}
/// <summary>
///
/// </summary>
public enum eGenericCommMethodStatusChangeType
{
/// <summary>
/// Connected
/// </summary>
public enum eGenericCommMethodStatusChangeType
{
/// <summary>
/// Connected
/// </summary>
Connected,
/// <summary>
/// Disconnected
/// </summary>
Disconnected
}
/// <summary>
/// Disconnected
/// </summary>
Disconnected
}
/// <summary>
/// This delegate defines handler for IBasicCommunication status changes
@@ -139,20 +146,20 @@ namespace PepperDash.Core
/// <param name="status"></param>
public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status);
/// <summary>
/// Event args for bytes received from a communication method
/// </summary>
public class GenericCommMethodReceiveBytesArgs : EventArgs
{
/// <summary>
///
/// The bytes received
/// </summary>
public class GenericCommMethodReceiveBytesArgs : EventArgs
{
/// <summary>
/// Gets or sets the Bytes
/// </summary>
public byte[] Bytes { get; private set; }
public byte[] Bytes { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="bytes"></param>
/// <summary>
/// Constructor
/// </summary>
/// <param name="bytes"></param>
public GenericCommMethodReceiveBytesArgs(byte[] bytes)
{
Bytes = bytes;
@@ -164,42 +171,81 @@ namespace PepperDash.Core
public GenericCommMethodReceiveBytesArgs() { }
}
/// <summary>
/// Event args for text received
/// </summary>
public class GenericCommMethodReceiveTextArgs : EventArgs
{
/// <summary>
///
/// The text received
/// </summary>
public class GenericCommMethodReceiveTextArgs : EventArgs
{
/// <summary>
///
/// </summary>
public string Text { get; private set; }
/// <summary>
///
/// </summary>
public string Delimiter { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <summary>
/// The delimiter used to determine the end of a message, if applicable
/// </summary>
public string Delimiter { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="text"></param>
public GenericCommMethodReceiveTextArgs(string text)
{
Text = text;
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="delimiter"></param>
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
: this(text)
{
Delimiter = delimiter;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveTextArgs() { }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="delimiter"></param>
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
:this(text)
{
Delimiter = delimiter;
}
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveTextArgs() { }
}
/// <summary>
/// Helper class to get escaped text for debugging communication streams
/// </summary>
public class ComTextHelper
{
/// <summary>
/// Gets escaped text for a byte array
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static string GetEscapedText(byte[] bytes)
{
return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets escaped text for a string
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string GetEscapedText(string text)
{
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets debug text for a string
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string GetDebugText(string text)
{
return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value));
}
}

View File

@@ -1,19 +1,21 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Formatting = NewtonsoftJson::Newtonsoft.Json.Formatting;
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
using JToken = NewtonsoftJson::Newtonsoft.Json.Linq.JToken;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Core.Config
{
namespace PepperDash.Core.Config;
/// <summary>
/// Reads a Portal formatted config file
/// </summary>
/// <summary>
/// Reads a Portal formatted config file
/// </summary>
public class PortalConfigReader
{
const string template = "template";
@@ -56,12 +58,12 @@ namespace PepperDash.Core.Config
var merged = MergeConfigs(jsonObj);
if (jsonObj[systemUrl] != null)
{
merged[systemUrl] = jsonObj[systemUrl].Value<string>();
merged[systemUrl] = (string)jsonObj[systemUrl];
}
if (jsonObj[templateUrl] != null)
{
merged[templateUrl] = jsonObj[templateUrl].Value<string>();
merged[templateUrl] = (string)jsonObj[templateUrl];
}
jsonObj = merged;
@@ -122,38 +124,37 @@ namespace PepperDash.Core.Config
Merge(template[destinationLists], system[destinationLists], destinationLists));
if (system[cameraLists] == null)
merged.Add(cameraLists, template[cameraLists]);
else
merged.Add(cameraLists, Merge(template[cameraLists], system[cameraLists], cameraLists));
if (system["cameraLists"] == null)
merged.Add("cameraLists", template["cameraLists"]);
else
merged.Add("cameraLists", Merge(template["cameraLists"], system["cameraLists"], "cameraLists"));
if (system[audioControlPointLists] == null)
merged.Add(audioControlPointLists, template[audioControlPointLists]);
else
merged.Add(audioControlPointLists,
Merge(template[audioControlPointLists], system[audioControlPointLists], audioControlPointLists));
if (system["audioControlPointLists"] == null)
merged.Add("audioControlPointLists", template["audioControlPointLists"]);
else
merged.Add("audioControlPointLists",
Merge(template["audioControlPointLists"], system["audioControlPointLists"], "audioControlPointLists"));
// Template tie lines take precedence. Config tool doesn't do them at system
// level anyway...
if (template[tieLines] != null)
merged.Add(tieLines, template[tieLines]);
else if (system[tieLines] != null)
merged.Add(tieLines, system[tieLines]);
// Template tie lines take precedence. Config tool doesn't do them at system
// level anyway...
if (template["tieLines"] != null)
merged.Add("tieLines", template["tieLines"]);
else if (system["tieLines"] != null)
merged.Add("tieLines", system["tieLines"]);
else
merged.Add(tieLines, new JArray());
if (template[joinMaps] != null)
merged.Add(joinMaps, template[joinMaps]);
else
merged.Add(joinMaps, new JObject());
if (template["joinMaps"] != null)
merged.Add("joinMaps", template["joinMaps"]);
else
merged.Add("joinMaps", new JObject());
if (system[global] != null)
merged.Add(global, Merge(template[global], system[global], global));
else
merged.Add(global, template[global]);
//Debug.Console(2, "MERGED CONFIG RESULT: \x0d\x0a{0}", merged);
return merged;
}
@@ -169,26 +170,26 @@ namespace PepperDash.Core.Config
return a1;
else if (a1 != null)
{
if (a2[0]["key"] == null) // If the first item in the system array has no key, overwrite the template array
{ // with the system array
return a2;
}
else // The arrays are keyed, merge them by key
if (a2[0]["key"] == null) // If the first item in the system array has no key, overwrite the template array
{ // with the system array
return a2;
}
else // The arrays are keyed, merge them by key
{
for (int i = 0; i < a1.Count(); i++)
{
for (int i = 0; i < a1.Count(); i++)
var a1Dev = a1[i];
// Try to get a system device and if found, merge it onto template
var a2Match = a2.FirstOrDefault(t => t[propertyName].Equals(a1Dev[propertyName]));// t.Value<int>("uid") == tmplDev.Value<int>("uid"));
if (a2Match != null)
{
var a1Dev = a1[i];
// Try to get a system device and if found, merge it onto template
var a2Match = a2.FirstOrDefault(t => t[propertyName].Equals(a1Dev[propertyName]));// t.Value<int>("uid") == tmplDev.Value<int>("uid"));
if (a2Match != null)
{
var mergedItem = Merge(a1Dev, a2Match, string.Format("{0}[{1}].", path, i));// Merge(JObject.FromObject(a1Dev), JObject.FromObject(a2Match));
result.Add(mergedItem);
}
else
result.Add(a1Dev);
var mergedItem = Merge(a1Dev, a2Match, string.Format("{0}[{1}].", path, i));// Merge(JObject.FromObject(a1Dev), JObject.FromObject(a2Match));
result.Add(mergedItem);
}
else
result.Add(a1Dev);
}
}
}
return result;
}
@@ -205,9 +206,9 @@ namespace PepperDash.Core.Config
/// <summary>
/// Merge o2 onto o1
/// </summary>
/// <param name="o1"></param>
/// <param name="o2"></param>
/// <param name="path"></param>
/// <param name="o1"></param>
/// <param name="o2"></param>
/// <param name="path"></param>
static JObject Merge(JObject o1, JObject o2, string path)
{
foreach (var o2Prop in o2)
@@ -253,5 +254,4 @@ namespace PepperDash.Core.Config
}
return o1;
}
}
}
}

View File

@@ -4,28 +4,18 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core
namespace PepperDash.Core;
public class EncodingHelper
{
/// <summary>
/// Represents a EncodingHelper
/// </summary>
public class EncodingHelper
public static string ConvertUtf8ToAscii(string utf8String)
{
/// <summary>
/// ConvertUtf8ToAscii method
/// </summary>
public static string ConvertUtf8ToAscii(string utf8String)
{
return Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
}
/// <summary>
/// ConvertUtf8ToUtf16 method
/// </summary>
public static string ConvertUtf8ToUtf16(string utf8String)
{
return Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
}
return Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
}
public static string ConvertUtf8ToUtf16(string utf8String)
{
return Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
}
}

View File

@@ -1,35 +1,35 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
using Serilog;
namespace PepperDash.Core
{
/// <summary>
/// Unique key interface to require a unique key for the class
/// </summary>
namespace PepperDash.Core;
/// <summary>
/// Unique key interface to require a unique key for the class
/// </summary>
public interface IKeyed
{
/// <summary>
/// Unique Key
/// </summary>
[JsonProperty("key")]
string Key { get; }
}
/// <summary>
/// Named Keyed device interface. Forces the device to have a Unique Key and a name.
/// <summary>
/// Gets the unique key associated with the object.
/// </summary>
public interface IKeyName : IKeyed
{
/// <summary>
/// Isn't it obvious :)
/// </summary>
[JsonProperty("name")]
string Name { get; }
}
[JsonProperty("key")]
string Key { get; }
}
/// <summary>
/// Named Keyed device interface. Forces the device to have a Unique Key and a name.
/// </summary>
public interface IKeyName : IKeyed
{
/// <summary>
/// Gets the name associated with the current object.
/// </summary>
[JsonProperty("name")]
string Name { get; }
}

View File

@@ -2,198 +2,193 @@
using System.Collections.Generic;
using Serilog.Events;
namespace PepperDash.Core
namespace PepperDash.Core;
//*********************************************************************************************************
/// <summary>
/// Represents a Device
/// </summary>
public class Device : IKeyName
{
//*********************************************************************************************************
/// <summary>
/// Represents a Device
/// </summary>
public class Device : IKeyName
/// <summary>
/// Unique Key
/// </summary>
public string Key { get; protected set; }
/// <summary>
/// Gets or sets the Name
/// </summary>
public string Name { get; protected set; }
/// <summary>
///
/// </summary>
public bool Enabled { get; protected set; }
/// <summary>
/// A place to store reference to the original config object, if any. These values should
/// NOT be used as properties on the device as they are all publicly-settable values.
/// </summary>
//public DeviceConfig Config { get; private set; }
/// <summary>
/// Helper method to check if Config exists
/// </summary>
//public bool HasConfig { get { return Config != null; } }
List<Action> _PreActivationActions;
List<Action> _PostActivationActions;
/// <summary>
///
/// </summary>
public static Device DefaultDevice { get { return _DefaultDevice; } }
static Device _DefaultDevice = new Device("Default", "Default");
/// <summary>
/// Base constructor for all Devices.
/// </summary>
/// <param name="key"></param>
public Device(string key)
{
Key = key;
if (key.Contains(".")) Debug.LogMessage(LogEventLevel.Information, "WARNING: Device key should not include '.'", this);
Name = "";
}
/// <summary>
/// Unique Key
/// </summary>
public string Key { get; protected set; }
/// <summary>
/// Gets or sets the Name
/// </summary>
public string Name { get; protected set; }
/// <summary>
///
/// </summary>
public bool Enabled { get; protected set; }
/// <summary>
/// Constructor with key and name
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public Device(string key, string name) : this(key)
{
Name = name;
}
/// <summary>
/// A place to store reference to the original config object, if any. These values should
/// NOT be used as properties on the device as they are all publicly-settable values.
/// </summary>
//public DeviceConfig Config { get; private set; }
/// <summary>
/// Helper method to check if Config exists
/// </summary>
//public bool HasConfig { get { return Config != null; } }
//public Device(DeviceConfig config)
// : this(config.Key, config.Name)
//{
// Config = config;
//}
List<Action> _PreActivationActions;
List<Action> _PostActivationActions;
/// <summary>
/// Adds a pre activation action
/// </summary>
/// <param name="act"></param>
protected void AddPreActivationAction(Action act)
{
if (_PreActivationActions == null)
_PreActivationActions = new List<Action>();
_PreActivationActions.Add(act);
}
/// <summary>
///
/// </summary>
public static Device DefaultDevice { get { return _DefaultDevice; } }
static Device _DefaultDevice = new Device("Default", "Default");
/// <summary>
/// Adds a post activation action
/// </summary>
/// <param name="act"></param>
/// <summary>
/// AddPostActivationAction method
/// </summary>
protected void AddPostActivationAction(Action act)
{
if (_PostActivationActions == null)
_PostActivationActions = new List<Action>();
_PostActivationActions.Add(act);
}
/// <summary>
/// Base constructor for all Devices.
/// </summary>
/// <param name="key"></param>
public Device(string key)
{
Key = key;
if (key.Contains(".")) Debug.LogMessage(LogEventLevel.Information, "WARNING: Device key should not include '.'", this);
Name = "";
}
/// <summary>
/// Constructor with key and name
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public Device(string key, string name) : this(key)
{
Name = name;
}
//public Device(DeviceConfig config)
// : this(config.Key, config.Name)
//{
// Config = config;
//}
/// <summary>
/// Adds a pre activation action
/// </summary>
/// <param name="act"></param>
public void AddPreActivationAction(Action act)
{
if (_PreActivationActions == null)
_PreActivationActions = new List<Action>();
_PreActivationActions.Add(act);
}
/// <summary>
/// Adds a post activation action
/// </summary>
/// <param name="act"></param>
/// <summary>
/// AddPostActivationAction method
/// </summary>
public void AddPostActivationAction(Action act)
{
if (_PostActivationActions == null)
_PostActivationActions = new List<Action>();
_PostActivationActions.Add(act);
}
/// <summary>
/// PreActivate method
/// </summary>
public void PreActivate()
{
if (_PreActivationActions != null)
_PreActivationActions.ForEach(a =>
/// <summary>
/// PreActivate method
/// </summary>
public void PreActivate()
{
if (_PreActivationActions != null)
_PreActivationActions.ForEach(a =>
{
try
{
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
}
});
}
/// <summary>
/// Activate method
/// </summary>
public bool Activate()
{
//if (_PreActivationActions != null)
// _PreActivationActions.ForEach(a => a.Invoke());
var result = CustomActivate();
//if(result && _PostActivationActions != null)
// _PostActivationActions.ForEach(a => a.Invoke());
return result;
}
/// <summary>
/// PostActivate method
/// </summary>
public void PostActivate()
{
if (_PostActivationActions != null)
_PostActivationActions.ForEach(a =>
a.Invoke();
}
catch (Exception e)
{
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
}
});
}
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
}
});
}
/// <summary>
/// Called in between Pre and PostActivationActions when Activate() is called.
/// Override to provide addtitional setup when calling activation. Overriding classes
/// do not need to call base.CustomActivate()
/// </summary>
/// <returns>true if device activated successfully.</returns>
/// <summary>
/// CustomActivate method
/// </summary>
public virtual bool CustomActivate() { return true; }
/// <summary>
/// Activate method
/// </summary>
public bool Activate()
{
//if (_PreActivationActions != null)
// _PreActivationActions.ForEach(a => a.Invoke());
var result = CustomActivate();
//if(result && _PostActivationActions != null)
// _PostActivationActions.ForEach(a => a.Invoke());
return result;
}
/// <summary>
/// Call to deactivate device - unlink events, etc. Overriding classes do not
/// need to call base.Deactivate()
/// </summary>
/// <returns></returns>
public virtual bool Deactivate() { return true; }
/// <summary>
/// PostActivate method
/// </summary>
public void PostActivate()
{
if (_PostActivationActions != null)
_PostActivationActions.ForEach(a =>
{
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
}
});
}
/// <summary>
/// Call this method to start communications with a device. Overriding classes do not need to call base.Initialize()
/// </summary>
public virtual void Initialize()
{
}
/// <summary>
/// Called in between Pre and PostActivationActions when Activate() is called.
/// Override to provide addtitional setup when calling activation. Overriding classes
/// do not need to call base.CustomActivate()
/// </summary>
/// <returns>true if device activated successfully.</returns>
/// <summary>
/// CustomActivate method
/// </summary>
protected virtual bool CustomActivate() { return true; }
/// <summary>
/// Helper method to check object for bool value false and fire an Action method
/// </summary>
/// <param name="o">Should be of type bool, others will be ignored</param>
/// <param name="a">Action to be run when o is false</param>
public void OnFalse(object o, Action a)
{
if (o is bool && !(bool)o) a();
}
/// <summary>
/// Call to deactivate device - unlink events, etc. Overriding classes do not
/// need to call base.Deactivate()
/// </summary>
/// <returns></returns>
public virtual bool Deactivate() { return true; }
/// <summary>
/// Returns a string representation of the object, including its key and name.
/// </summary>
/// <remarks>The returned string is formatted as "{Key} - {Name}". If the <c>Name</c> property is
/// null or empty, "---" is used in place of the name.</remarks>
/// <returns>A string that represents the object, containing the key and name in the format "{Key} - {Name}".</returns>
/// <summary>
/// ToString method
/// </summary>
public override string ToString()
{
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
}
/// <summary>
/// Call this method to start communications with a device. Overriding classes do not need to call base.Initialize()
/// </summary>
protected virtual void Initialize()
{
}
/// <summary>
/// Helper method to check object for bool value false and fire an Action method
/// </summary>
/// <param name="o">Should be of type bool, others will be ignored</param>
/// <param name="a">Action to be run when o is false</param>
public void OnFalse(object o, Action a)
{
if (o is bool && !(bool)o) a();
}
/// <summary>
/// Returns a string representation of the object, including its key and name.
/// </summary>
/// <remarks>The returned string is formatted as "{Key} - {Name}". If the <c>Name</c> property is
/// null or empty, "---" is used in place of the name.</remarks>
/// <returns>A string that represents the object, containing the key and name in the format "{Key} - {Name}".</returns>
public override string ToString()
{
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
}
}

View File

@@ -1,12 +1,14 @@
using Crestron.SimplSharp;
using Newtonsoft.Json;
extern alias NewtonsoftJson;
using Crestron.SimplSharp;
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
using Serilog.Events;
namespace PepperDash.Core
{
/// <summary>
/// Represents a EthernetHelper
/// </summary>
namespace PepperDash.Core;
/// <summary>
/// Represents an EthernetHelper.
/// </summary>
public class EthernetHelper
{
/// <summary>
@@ -113,5 +115,4 @@ namespace PepperDash.Core
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_ROUTER, 0);
}
}
}
}
}

View File

@@ -4,8 +4,8 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core
{
namespace PepperDash.Core;
/// <summary>
/// Bool change event args
/// </summary>
@@ -168,5 +168,4 @@ namespace PepperDash.Core
Type = type;
Index = index;
}
}
}
}

View File

@@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core.GenericRESTfulCommunications
{
/// <summary>
/// Constants
/// </summary>
public class GenericRESTfulConstants
{
/// <summary>
/// Generic boolean change
/// </summary>
public const ushort BoolValueChange = 1;
/// <summary>
/// Generic Ushort change
/// </summary>
public const ushort UshrtValueChange = 101;
/// <summary>
/// Response Code Ushort change
/// </summary>
public const ushort ResponseCodeChange = 102;
/// <summary>
/// Generic String chagne
/// </summary>
public const ushort StringValueChange = 201;
/// <summary>
/// Response string change
/// </summary>
public const ushort ResponseStringChange = 202;
/// <summary>
/// Error string change
/// </summary>
public const ushort ErrorStringChange = 203;
}
}

View File

@@ -1,256 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Net.Http;
using Crestron.SimplSharp.Net.Https;
namespace PepperDash.Core.GenericRESTfulCommunications
{
/// <summary>
/// Generic RESTful communication class
/// </summary>
public class GenericRESTfulClient
{
/// <summary>
/// Boolean event handler
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Ushort event handler
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UshrtChange;
/// <summary>
/// String event handler
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// Constructor
/// </summary>
public GenericRESTfulClient()
{
}
/// <summary>
/// Generic RESTful submit request
/// </summary>
/// <param name="url"></param>
/// <param name="port"></param>
/// <param name="requestType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="contentType"></param>
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
{
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
{
SubmitRequestHttps(url, port, requestType, contentType, username, password);
}
else if (url.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
{
SubmitRequestHttp(url, port, requestType, contentType, username, password);
}
else
{
OnStringChange(string.Format("Invalid URL {0}", url), 0, GenericRESTfulConstants.ErrorStringChange);
}
}
/// <summary>
/// Private HTTP submit request
/// </summary>
/// <param name="url"></param>
/// <param name="port"></param>
/// <param name="requestType"></param>
/// <param name="contentType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
private void SubmitRequestHttp(string url, ushort port, ushort requestType, string contentType, string username, string password)
{
try
{
HttpClient client = new HttpClient();
HttpClientRequest request = new HttpClientRequest();
HttpClientResponse response;
client.KeepAlive = false;
if(port >= 1 || port <= 65535)
client.Port = port;
else
client.Port = 80;
var authorization = "";
if (!string.IsNullOrEmpty(username))
authorization = EncodeBase64(username, password);
if (!string.IsNullOrEmpty(authorization))
request.Header.SetHeaderValue("Authorization", authorization);
if (!string.IsNullOrEmpty(contentType))
request.Header.ContentType = contentType;
request.Url.Parse(url);
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
response = client.Dispatch(request);
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
if (!string.IsNullOrEmpty(response.ContentString.ToString()))
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
if (response.Code > 0)
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
}
catch (Exception e)
{
//var msg = string.Format("SubmitRequestHttp({0}, {1}, {2}) failed:{3}", url, port, requestType, e.Message);
//CrestronConsole.PrintLine(msg);
//ErrorLog.Error(msg);
CrestronConsole.PrintLine(e.Message);
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
}
}
/// <summary>
/// Private HTTPS submit request
/// </summary>
/// <param name="url"></param>
/// <param name="port"></param>
/// <param name="requestType"></param>
/// <param name="contentType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
private void SubmitRequestHttps(string url, ushort port, ushort requestType, string contentType, string username, string password)
{
try
{
HttpsClient client = new HttpsClient();
HttpsClientRequest request = new HttpsClientRequest();
HttpsClientResponse response;
client.KeepAlive = false;
client.HostVerification = false;
client.PeerVerification = false;
var authorization = "";
if (!string.IsNullOrEmpty(username))
authorization = EncodeBase64(username, password);
if (!string.IsNullOrEmpty(authorization))
request.Header.SetHeaderValue("Authorization", authorization);
if (!string.IsNullOrEmpty(contentType))
request.Header.ContentType = contentType;
request.Url.Parse(url);
request.RequestType = (Crestron.SimplSharp.Net.Https.RequestType)requestType;
response = client.Dispatch(request);
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
if(!string.IsNullOrEmpty(response.ContentString.ToString()))
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
if(response.Code > 0)
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
}
catch (Exception e)
{
//var msg = string.Format("SubmitRequestHttps({0}, {1}, {2}, {3}, {4}) failed:{5}", url, port, requestType, username, password, e.Message);
//CrestronConsole.PrintLine(msg);
//ErrorLog.Error(msg);
CrestronConsole.PrintLine(e.Message);
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
}
}
/// <summary>
/// Private method to encode username and password to Base64 string
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns>authorization</returns>
private string EncodeBase64(string username, string password)
{
var authorization = "";
try
{
if (!string.IsNullOrEmpty(username))
{
string base64String = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(string.Format("{0}:{1}", username, password)));
authorization = string.Format("Basic {0}", base64String);
}
}
catch (Exception e)
{
var msg = string.Format("EncodeBase64({0}, {1}) failed:\r{2}", username, password, e);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
return "" ;
}
return authorization;
}
/// <summary>
/// Protected method to handle boolean change events
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnBoolChange(bool state, ushort index, ushort type)
{
var handler = BoolChange;
if (handler != null)
{
var args = new BoolChangeEventArgs(state, type);
args.Index = index;
BoolChange(this, args);
}
}
/// <summary>
/// Protected mehtod to handle ushort change events
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnUshrtChange(ushort value, ushort index, ushort type)
{
var handler = UshrtChange;
if (handler != null)
{
var args = new UshrtChangeEventArgs(value, type);
args.Index = index;
UshrtChange(this, args);
}
}
/// <summary>
/// Protected method to handle string change events
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnStringChange(string value, ushort index, ushort type)
{
var handler = StringChange;
if (handler != null)
{
var args = new StringChangeEventArgs(value, type);
args.Index = index;
StringChange(this, args);
}
}
}
}

View File

@@ -4,8 +4,8 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core.JsonStandardObjects
{
namespace PepperDash.Core.JsonStandardObjects;
/// <summary>
/// Constants for simpl modules
/// </summary>
@@ -73,5 +73,4 @@ namespace PepperDash.Core.JsonStandardObjects
Type = type;
Index = index;
}
}
}
}

View File

@@ -4,8 +4,8 @@ using Crestron.SimplSharp;
using PepperDash.Core.JsonToSimpl;
using Serilog.Events;
namespace PepperDash.Core.JsonStandardObjects
{
namespace PepperDash.Core.JsonStandardObjects;
/// <summary>
/// Device class
/// </summary>
@@ -182,5 +182,4 @@ namespace PepperDash.Core.JsonStandardObjects
}
#endregion EventHandler Helpers
}
}
}

View File

@@ -4,8 +4,8 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core.JsonStandardObjects
{
namespace PepperDash.Core.JsonStandardObjects;
/*
Convert JSON snippt to C#: http://json2csharp.com/#
@@ -52,55 +52,55 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class ComParamsConfig
{
/// <summary>
/// Gets or sets the baudRate
/// </summary>
/// <summary>
///
/// </summary>
public int baudRate { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int dataBits { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int stopBits { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string parity { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string protocol { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string hardwareHandshake { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string softwareHandshake { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int pacing { get; set; }
// convert properties for simpl
/// <summary>
/// Gets or sets the simplBaudRate
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
/// <summary>
/// Gets or sets the simplDataBits
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplPacing { get { return Convert.ToUInt16(pacing); } }
/// <summary>
@@ -117,43 +117,43 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class TcpSshPropertiesConfig
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string address { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int port { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string username { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string password { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public bool autoReconnect { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int autoReconnectIntervalMs { get; set; }
// convert properties for simpl
/// <summary>
/// Gets or sets the simplPort
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplPort { get { return Convert.ToUInt16(port); } }
/// <summary>
/// Gets or sets the simplAutoReconnect
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } }
/// <summary>
@@ -170,31 +170,31 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class ControlConfig
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string method { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string controlPortDevKey { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int controlPortNumber { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ComParamsConfig comParams { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public TcpSshPropertiesConfig tcpSshProperties { get; set; }
// convert properties for simpl
/// <summary>
/// Gets or sets the simplControlPortNumber
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
/// <summary>
@@ -212,27 +212,27 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class PropertiesConfig
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public int deviceId { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public bool enabled { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ControlConfig control { get; set; }
// convert properties for simpl
/// <summary>
/// Gets or sets the simplDeviceId
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
/// <summary>
/// Gets or sets the simplEnabled
/// </summary>
/// <summary>
///
/// </summary>
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
/// <summary>
@@ -249,9 +249,8 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class RootObject
{
/// <summary>
/// The collection of devices
/// </summary>
/// <summary>
/// The collection of devices
/// </summary>
public List<DeviceConfig> devices { get; set; }
}
}
}

View File

@@ -4,78 +4,78 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core.JsonToSimpl
{
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Constants for Simpl modules
/// </summary>
public class JsonToSimplConstants
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort BoolValueChange = 1;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort JsonIsValidBoolChange = 2;
/// <summary>
/// Reports the if the device is 3-series compatible
/// </summary>
public const ushort ProgramCompatibility3SeriesChange = 3;
/// <summary>
/// Reports the if the device is 3-series compatible
/// </summary>
public const ushort ProgramCompatibility3SeriesChange = 3;
/// <summary>
/// Reports the if the device is 4-series compatible
/// </summary>
public const ushort ProgramCompatibility4SeriesChange = 4;
/// <summary>
/// Reports the if the device is 4-series compatible
/// </summary>
public const ushort ProgramCompatibility4SeriesChange = 4;
/// <summary>
/// Reports the device platform enum value
/// </summary>
public const ushort DevicePlatformValueChange = 5;
/// <summary>
/// Reports the device platform enum value
/// </summary>
public const ushort DevicePlatformValueChange = 5;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort UshortValueChange = 101;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort StringValueChange = 201;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort FullPathToArrayChange = 202;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort ActualFilePathChange = 203;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort FilenameResolvedChange = 204;
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public const ushort FilePathResolvedChange = 205;
/// <summary>
/// Reports the root directory change
/// </summary>
public const ushort RootDirectoryChange = 206;
/// <summary>
/// Reports the root directory change
/// </summary>
public const ushort RootDirectoryChange = 206;
/// <summary>
/// Reports the room ID change
/// </summary>
public const ushort RoomIdChange = 207;
/// <summary>
/// Reports the room ID change
/// </summary>
public const ushort RoomIdChange = 207;
/// <summary>
/// Reports the room name change
/// </summary>
public const ushort RoomNameChange = 208;
/// <summary>
/// Reports the room name change
/// </summary>
public const ushort RoomNameChange = 208;
}
/// <summary>
@@ -88,33 +88,33 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public class SPlusValueWrapper
{
/// <summary>
/// Gets or sets the ValueType
/// </summary>
/// <summary>
///
/// </summary>
public SPlusType ValueType { get; private set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ushort Index { get; private set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public ushort BoolUShortValue { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string StringValue { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public SPlusValueWrapper() {}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="index"></param>
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="index"></param>
public SPlusValueWrapper(SPlusType type, ushort index)
{
ValueType = type;
@@ -127,17 +127,16 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public enum SPlusType
{
/// <summary>
/// Digital
/// </summary>
/// <summary>
/// Digital
/// </summary>
Digital,
/// <summary>
/// Analog
/// </summary>
Analog,
/// <summary>
/// String
/// </summary>
String
}
}
/// <summary>
/// Analog
/// </summary>
Analog,
/// <summary>
/// String
/// </summary>
String
}

View File

@@ -7,11 +7,11 @@ using Serilog.Events;
//using PepperDash.Core;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// The global class to manage all the instances of JsonToSimplMaster
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// The global class to manage all the instances of JsonToSimplMaster
/// </summary>
public class J2SGlobal
{
static List<JsonToSimplMaster> Masters = new List<JsonToSimplMaster>();
@@ -22,10 +22,7 @@ namespace PepperDash.Core.JsonToSimpl
/// master, this will fail
/// </summary>
/// <param name="master">New master to add</param>
///
/// <summary>
/// AddMaster method
/// </summary>
///
public static void AddMaster(JsonToSimplMaster master)
{
if (master == null)
@@ -59,5 +56,4 @@ namespace PepperDash.Core.JsonToSimpl
{
return Masters.FirstOrDefault(m => m.UniqueID.Equals(file, StringComparison.OrdinalIgnoreCase));
}
}
}
}

View File

@@ -1,22 +1,24 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Linq;
using Newtonsoft.Json.Linq;
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
using Serilog.Events;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Represents a JsonToSimplArrayLookupChild
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Used to interact with an array of values with the S+ modules
/// </summary>
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
{
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string SearchPropertyName { get; set; }
/// <summary>
///
/// </summary>
/// <summary>
///
/// </summary>
public string SearchPropertyValue { get; set; }
int ArrayIndex;
@@ -76,10 +78,9 @@ namespace PepperDash.Core.JsonToSimpl
PathSuffix == null ? "" : PathSuffix);
}
/// <summary>
/// ProcessAll method
/// </summary>
/// <inheritdoc />
/// <summary>
/// Process all values
/// </summary>
public override void ProcessAll()
{
if (FindInArray())
@@ -129,7 +130,7 @@ namespace PepperDash.Core.JsonToSimpl
var item = array.FirstOrDefault(o =>
{
var prop = o[SearchPropertyName];
return prop != null && prop.Value<string>()
return prop != null && ((string)prop)
.Equals(SearchPropertyValue, StringComparison.OrdinalIgnoreCase);
});
if (item == null)
@@ -159,5 +160,4 @@ namespace PepperDash.Core.JsonToSimpl
return false;
}
}
}
}

View File

@@ -1,31 +1,34 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using PepperDash.Core.Logging;
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Base class for JSON objects
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Base class for JSON objects
/// </summary>
public abstract class JsonToSimplChildObjectBase : IKeyed
{
/// <summary>
/// Notifies of bool change
/// </summary>
/// <summary>
/// Notifies of bool change
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Notifies of ushort change
/// </summary>
/// <summary>
/// Notifies of ushort change
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UShortChange;
/// <summary>
/// Notifies of string change
/// </summary>
/// <summary>
/// Notifies of string change
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// Delegate to get all values
/// </summary>
/// <summary>
/// Delegate to get all values
/// </summary>
public SPlusValuesDelegate GetAllValuesDelegate { get; set; }
/// <summary>
@@ -33,9 +36,9 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public SPlusValuesDelegate SetAllPathsDelegate { get; set; }
/// <summary>
/// Gets or sets the Key
/// </summary>
/// <summary>
/// Unique identifier for instance
/// </summary>
public string Key { get; protected set; }
/// <summary>
@@ -49,33 +52,33 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string PathSuffix { get; protected set; }
/// <summary>
/// Gets or sets the LinkedToObject
/// </summary>
/// <summary>
/// Indicates if the instance is linked to an object
/// </summary>
public bool LinkedToObject { get; protected set; }
/// <summary>
/// Reference to Master instance
/// </summary>
/// <summary>
/// Reference to Master instance
/// </summary>
protected JsonToSimplMaster Master;
/// <summary>
/// Paths to boolean values in JSON structure
/// </summary>
protected Dictionary<ushort, string> BoolPaths = new Dictionary<ushort, string>();
/// <summary>
/// Paths to numeric values in JSON structure
/// </summary>
/// <summary>
/// Paths to boolean values in JSON structure
/// </summary>
protected Dictionary<ushort, string> BoolPaths = new Dictionary<ushort, string>();
/// <summary>
/// Paths to numeric values in JSON structure
/// </summary>
protected Dictionary<ushort, string> UshortPaths = new Dictionary<ushort, string>();
/// <summary>
/// Paths to string values in JSON structure
/// </summary>
/// <summary>
/// Paths to string values in JSON structure
/// </summary>
protected Dictionary<ushort, string> StringPaths = new Dictionary<ushort, string>();
/// <summary>
/// Call this before doing anything else
/// </summary>
/// <param name="masterUniqueId"></param>
/// <param name="masterUniqueId"></param>
/// <param name="key"></param>
/// <param name="pathPrefix"></param>
/// <param name="pathSuffix"></param>
@@ -89,16 +92,13 @@ namespace PepperDash.Core.JsonToSimpl
if (Master != null)
Master.AddChild(this);
else
Debug.Console(1, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
this.LogWarning("JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
}
/// <summary>
/// Sets the path prefix for the object
/// </summary>
/// <param name="pathPrefix"></param>
/// <summary>
/// SetPathPrefix method
/// </summary>
/// <summary>
/// Sets the path prefix for the object
/// </summary>
/// <param name="pathPrefix"></param>
public void SetPathPrefix(string pathPrefix)
{
PathPrefix = pathPrefix;
@@ -108,7 +108,7 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public void SetBoolPath(ushort index, string path)
{
Debug.Console(1, "JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path);
this.LogDebug("JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return;
BoolPaths[index] = path;
}
@@ -118,7 +118,7 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public void SetUshortPath(ushort index, string path)
{
Debug.Console(1, "JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path);
this.LogDebug("JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return;
UshortPaths[index] = path;
}
@@ -128,7 +128,7 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public void SetStringPath(ushort index, string path)
{
Debug.Console(1, "JSON Child[{0}] SetStringPath {1}={2}", Key, index, path);
this.LogDebug("JSON Child[{0}] SetStringPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return;
StringPaths[index] = path;
}
@@ -141,13 +141,13 @@ namespace PepperDash.Core.JsonToSimpl
{
if (!LinkedToObject)
{
Debug.Console(1, this, "Not linked to object in file. Skipping");
this.LogDebug("Not linked to object in file. Skipping");
return;
}
if (SetAllPathsDelegate == null)
{
Debug.Console(1, this, "No SetAllPathsDelegate set. Ignoring ProcessAll");
this.LogDebug("No SetAllPathsDelegate set. Ignoring ProcessAll");
return;
}
SetAllPathsDelegate();
@@ -173,18 +173,18 @@ namespace PepperDash.Core.JsonToSimpl
}
// Processes the path to a ushort, converting to ushort if able, twos complement if necessary, firing off UshrtChange event
void ProcessUshortPath(ushort index) {
string response;
if (Process(UshortPaths[index], out response)) {
ushort val;
try { val = Convert.ToInt32(response) < 0 ? (ushort)(Convert.ToInt16(response) + 65536) : Convert.ToUInt16(response); }
catch { val = 0; }
void ProcessUshortPath(ushort index) {
string response;
if (Process(UshortPaths[index], out response)) {
ushort val;
try { val = Convert.ToInt32(response) < 0 ? (ushort)(Convert.ToInt16(response) + 65536) : Convert.ToUInt16(response); }
catch { val = 0; }
OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange);
}
else { }
// OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange);
OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange);
}
else { }
// OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange);
}
// Processes the path to a string property and fires of a StringChange event.
void ProcessStringPath(ushort index)
@@ -207,11 +207,11 @@ namespace PepperDash.Core.JsonToSimpl
bool Process(string path, out string response)
{
path = GetFullPath(path);
Debug.Console(1, "JSON Child[{0}] Processing {1}", Key, path);
this.LogDebug("JSON Child[{0}] Processing {1}", Key, path);
response = "";
if (Master == null)
{
Debug.Console(1, "JSONChild[{0}] cannot process without Master attached", Key);
this.LogWarning("JSONChild[{0}] cannot process without Master attached", Key);
return false;
}
@@ -233,8 +233,8 @@ namespace PepperDash.Core.JsonToSimpl
if (isCount)
response = (t.HasValues ? t.Children().Count() : 0).ToString();
else
response = t.Value<string>();
Debug.Console(1, " ='{0}'", response);
response = (string)t;
this.LogDebug(" ='{0}'", response);
return true;
}
}
@@ -260,13 +260,13 @@ namespace PepperDash.Core.JsonToSimpl
{
if (!LinkedToObject)
{
Debug.Console(1, this, "Not linked to object in file. Skipping");
this.LogDebug("Not linked to object in file. Skipping");
return;
}
if (SetAllPathsDelegate == null)
{
Debug.Console(1, this, "No SetAllPathsDelegate set. Ignoring UpdateInputsForMaster");
this.LogDebug("No SetAllPathsDelegate set. Ignoring UpdateInputsForMaster");
return;
}
SetAllPathsDelegate();
@@ -275,75 +275,60 @@ namespace PepperDash.Core.JsonToSimpl
GetAllValuesDelegate();
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
/// <summary>
/// USetBoolValue method
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void USetBoolValue(ushort key, ushort theValue)
{
SetBoolValue(key, theValue == 1);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
/// <summary>
/// SetBoolValue method
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetBoolValue(ushort key, bool theValue)
{
if (BoolPaths.ContainsKey(key))
SetValueOnMaster(BoolPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
/// <summary>
/// SetUShortValue method
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetUShortValue(ushort key, ushort theValue)
{
if (UshortPaths.ContainsKey(key))
SetValueOnMaster(UshortPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
/// <summary>
/// SetStringValue method
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetStringValue(ushort key, string theValue)
{
if (StringPaths.ContainsKey(key))
SetValueOnMaster(StringPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="keyPath"></param>
/// <param name="valueToSave"></param>
/// <summary>
/// SetValueOnMaster method
/// </summary>
/// <summary>
///
/// </summary>
/// <param name="keyPath"></param>
/// <param name="valueToSave"></param>
public void SetValueOnMaster(string keyPath, JValue valueToSave)
{
var path = GetFullPath(keyPath);
try
{
Debug.Console(1, "JSON Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave);
this.LogDebug("JSON Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave);
//var token = Master.JsonObject.SelectToken(path);
//if (token != null) // The path exists in the file
@@ -351,7 +336,7 @@ namespace PepperDash.Core.JsonToSimpl
}
catch (Exception e)
{
Debug.Console(1, "JSON Child[{0}] Failed setting value for path '{1}'\r{2}", Key, path, e);
this.LogDebug("JSON Child[{0}] Failed setting value for path '{1}'\r{2}", Key, path, e);
}
}
@@ -367,12 +352,12 @@ namespace PepperDash.Core.JsonToSimpl
// Helpers for events
//******************************************************************************************
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnBoolChange(bool state, ushort index, ushort type)
{
var handler = BoolChange;
@@ -385,12 +370,12 @@ namespace PepperDash.Core.JsonToSimpl
}
//******************************************************************************************
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnUShortChange(ushort state, ushort index, ushort type)
{
var handler = UShortChange;
@@ -402,12 +387,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Event helper
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
/// <summary>
/// Event helper
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnStringChange(string value, ushort index, ushort type)
{
var handler = StringChange;
@@ -418,5 +403,4 @@ namespace PepperDash.Core.JsonToSimpl
StringChange(this, args);
}
}
}
}
}

View File

@@ -1,292 +1,263 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json.Linq;
using PepperDash.Core.Logging;
using Formatting = NewtonsoftJson::Newtonsoft.Json.Formatting;
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
namespace PepperDash.Core.JsonToSimpl
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Represents a JSON file that can be read and written to
/// </summary>
public class JsonToSimplFileMaster : JsonToSimplMaster
{
/// <summary>
/// Represents a JSON file that can be read and written to
/// Sets the filepath as well as registers this with the Global.Masters list
/// </summary>
public class JsonToSimplFileMaster : JsonToSimplMaster
public string Filepath { get; private set; }
/// <summary>
/// Filepath to the actual file that will be read (Portal or local)
/// </summary>
public string ActualFilePath { get; private set; }
/// <summary>
///
/// </summary>
public string Filename { get; private set; }
/// <summary>
///
/// </summary>
public string FilePathName { get; private set; }
/*****************************************************************************************/
/** Privates **/
// The JSON file in JObject form
// For gathering the incoming data
object StringBuilderLock = new object();
// To prevent multiple same-file access
static object FileLock = new object();
/*****************************************************************************************/
/// <summary>
/// SIMPL+ default constructor.
/// </summary>
public JsonToSimplFileMaster()
{
/// <summary>
/// Sets the filepath as well as registers this with the Global.Masters list
/// </summary>
public string Filepath { get; private set; }
}
/// <summary>
/// Gets or sets the ActualFilePath
/// </summary>
public string ActualFilePath { get; private set; }
/// <summary>
/// Gets or sets the Filename
/// </summary>
public string Filename { get; private set; }
/// <summary>
///
/// </summary>
public string FilePathName { get; private set; }
/*****************************************************************************************/
/** Privates **/
// The JSON file in JObject form
// For gathering the incoming data
object StringBuilderLock = new object();
// To prevent multiple same-file access
static object FileLock = new object();
/*****************************************************************************************/
/// <summary>
/// SIMPL+ default constructor.
/// </summary>
public JsonToSimplFileMaster()
/// <summary>
/// Read, evaluate and udpate status
/// </summary>
public void EvaluateFile(string filepath)
{
try
{
}
OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange);
/// <summary>
/// Read, evaluate and udpate status
/// </summary>
public void EvaluateFile(string filepath)
{
try
var dirSeparator = Path.DirectorySeparatorChar;
var dirSeparatorAlt = Path.AltDirectorySeparatorChar;
var series = CrestronEnvironment.ProgramCompatibility;
var is3Series = (eCrestronSeries.Series3 == (series & eCrestronSeries.Series3));
OnBoolChange(is3Series, 0,
JsonToSimplConstants.ProgramCompatibility3SeriesChange);
var is4Series = (eCrestronSeries.Series4 == (series & eCrestronSeries.Series4));
OnBoolChange(is4Series, 0,
JsonToSimplConstants.ProgramCompatibility4SeriesChange);
var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server;
OnBoolChange(isServer, 0,
JsonToSimplConstants.DevicePlatformValueChange);
// get the roomID
var roomId = Crestron.SimplSharp.InitialParametersClass.RoomId;
if (!string.IsNullOrEmpty(roomId))
{
OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange);
OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange);
}
var dirSeparator = Path.DirectorySeparatorChar;
var dirSeparatorAlt = Path.AltDirectorySeparatorChar;
// get the roomName
var roomName = Crestron.SimplSharp.InitialParametersClass.RoomName;
if (!string.IsNullOrEmpty(roomName))
{
OnStringChange(roomName, 0, JsonToSimplConstants.RoomNameChange);
}
var series = CrestronEnvironment.ProgramCompatibility;
var rootDirectory = Directory.GetApplicationRootDirectory();
OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectoryChange);
var splusPath = string.Empty;
if (Regex.IsMatch(filepath, @"user", RegexOptions.IgnoreCase))
{
if (is4Series)
splusPath = Regex.Replace(filepath, "user", "user", RegexOptions.IgnoreCase);
else if (isServer)
splusPath = Regex.Replace(filepath, "user", "User", RegexOptions.IgnoreCase);
else
splusPath = filepath;
}
var is3Series = (eCrestronSeries.Series3 == (series & eCrestronSeries.Series3));
OnBoolChange(is3Series, 0,
JsonToSimplConstants.ProgramCompatibility3SeriesChange);
filepath = splusPath.Replace(dirSeparatorAlt, dirSeparator);
Filepath = string.Format("{1}{0}{2}", dirSeparator, rootDirectory,
filepath.TrimStart(dirSeparator, dirSeparatorAlt));
OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.StringValueChange);
var is4Series = (eCrestronSeries.Series4 == (series & eCrestronSeries.Series4));
OnBoolChange(is4Series, 0,
JsonToSimplConstants.ProgramCompatibility4SeriesChange);
if (string.IsNullOrEmpty(Filepath))
{
OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set");
return;
}
var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server;
OnBoolChange(isServer, 0,
JsonToSimplConstants.DevicePlatformValueChange);
// get file directory and name to search
var fileDirectory = Path.GetDirectoryName(Filepath);
var fileName = Path.GetFileName(Filepath);
// get the roomID
var roomId = Crestron.SimplSharp.InitialParametersClass.RoomId;
if (!string.IsNullOrEmpty(roomId))
OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange);
this.LogInformation("Checking '{0}' for '{1}'", fileDirectory, fileName);
if (Directory.Exists(fileDirectory))
{
// get the directory info
var directoryInfo = new DirectoryInfo(fileDirectory);
// get the file to be read
var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault();
if (actualFile == null)
{
OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange);
}
// get the roomName
var roomName = Crestron.SimplSharp.InitialParametersClass.RoomName;
if (!string.IsNullOrEmpty(roomName))
{
OnStringChange(roomName, 0, JsonToSimplConstants.RoomNameChange);
}
var rootDirectory = Directory.GetApplicationRootDirectory();
OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectoryChange);
var splusPath = string.Empty;
if (Regex.IsMatch(filepath, @"user", RegexOptions.IgnoreCase))
{
if (is4Series)
splusPath = Regex.Replace(filepath, "user", "user", RegexOptions.IgnoreCase);
else if (isServer)
splusPath = Regex.Replace(filepath, "user", "User", RegexOptions.IgnoreCase);
else
splusPath = filepath;
}
filepath = splusPath.Replace(dirSeparatorAlt, dirSeparator);
Filepath = string.Format("{1}{0}{2}", dirSeparator, rootDirectory,
filepath.TrimStart(dirSeparator, dirSeparatorAlt));
OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.StringValueChange);
if (string.IsNullOrEmpty(Filepath))
{
OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set");
var msg = string.Format("JSON file not found: {0}", Filepath);
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(msg);
this.LogError(msg);
return;
}
// get file directory and name to search
var fileDirectory = Path.GetDirectoryName(Filepath);
var fileName = Path.GetFileName(Filepath);
// \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
// \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
ActualFilePath = actualFile.FullName;
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange);
this.LogInformation("Actual JSON file is {0}", ActualFilePath);
OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange);
Debug.Console(1, "Checking '{0}' for '{1}'", fileDirectory, fileName);
if (Directory.Exists(fileDirectory))
{
// get the directory info
var directoryInfo = new DirectoryInfo(fileDirectory);
// get the file to be read
var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault();
if (actualFile == null)
{
var msg = string.Format("JSON file not found: {0}", Filepath);
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
return;
}
// \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
// \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
ActualFilePath = actualFile.FullName;
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange);
Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
Filename = actualFile.Name;
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange);
Debug.Console(1, "JSON Filename is {0}", Filename);
Filename = actualFile.Name;
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange);
this.LogInformation("JSON Filename is {0}", Filename);
FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator);
OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange);
OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange);
Debug.Console(1, "JSON File Path is {0}", FilePathName);
FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator);
OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange);
OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange);
this.LogInformation("JSON File Path is {0}", FilePathName);
var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
JsonObject = JObject.Parse(json);
foreach (var child in Children)
child.ProcessAll();
JsonObject = JObject.Parse(json);
foreach (var child in Children)
child.ProcessAll();
OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange);
}
else
{
OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange);
Debug.Console(1, "'{0}' not found", fileDirectory);
}
OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange);
}
catch (Exception e)
else
{
var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message);
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(stackTrace);
ErrorLog.Error(stackTrace);
OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange);
this.LogError("'{0}' not found", fileDirectory);
}
}
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"></param>
/// <summary>
/// setDebugLevel method
/// </summary>
public void setDebugLevel(uint level)
catch (Exception e)
{
Debug.SetDebugLevel(level);
var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message);
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(msg);
this.LogException(e, "EvaluateFile Exception: {0}", e.Message);
var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange);
CrestronConsole.PrintLine(stackTrace);
this.LogVerbose("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
}
}
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"></param>
public void setDebugLevel(uint level)
{
Debug.SetDebugLevel(level);
}
/// <summary>
/// Saves the values to the file
/// </summary>
public override void Save()
{
// this code is duplicated in the other masters!!!!!!!!!!!!!
UnsavedValues = new Dictionary<string, JValue>();
// Make each child update their values into master object
foreach (var child in Children)
{
this.LogInformation("Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
child.UpdateInputsForMaster();
}
/// <summary>
/// Saves the values to the file
/// </summary>
public override void Save()
if (UnsavedValues == null || UnsavedValues.Count == 0)
{
// this code is duplicated in the other masters!!!!!!!!!!!!!
UnsavedValues = new Dictionary<string, JValue>();
// Make each child update their values into master object
foreach (var child in Children)
this.LogInformation("Master [{0}] No updated values to save. Skipping", UniqueID);
return;
}
lock (FileLock)
{
this.LogInformation("Saving");
foreach (var path in UnsavedValues.Keys)
{
Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
child.UpdateInputsForMaster();
}
if (UnsavedValues == null || UnsavedValues.Count == 0)
{
Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID);
return;
}
lock (FileLock)
{
Debug.Console(1, "Saving");
foreach (var path in UnsavedValues.Keys)
{
var tokenToReplace = JsonObject.SelectToken(path);
if (tokenToReplace != null)
{// It's found
tokenToReplace.Replace(UnsavedValues[path]);
Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path);
}
else // No token. Let's make one
{
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
// JContainer jpart = JsonObject;
// // walk down the path and find where it goes
//#warning Does not handle arrays.
// foreach (var part in path.Split('.'))
// {
// var openPos = part.IndexOf('[');
// if (openPos > -1)
// {
// openPos++; // move to number
// var closePos = part.IndexOf(']');
// var arrayName = part.Substring(0, openPos - 1); // get the name
// var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos));
// // Check if the array itself exists and add the item if so
// if (jpart[arrayName] != null)
// {
// var arrayObj = jpart[arrayName] as JArray;
// var item = arrayObj[index];
// if (item == null)
// arrayObj.Add(new JObject());
// }
// Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW");
// continue;
// }
// // Build the
// if (jpart[part] == null)
// jpart.Add(new JProperty(part, new JObject()));
// jpart = jpart[part] as JContainer;
// }
// jpart.Replace(UnsavedValues[path]);
}
var tokenToReplace = JsonObject.SelectToken(path);
if (tokenToReplace != null)
{// It's found
tokenToReplace.Replace(UnsavedValues[path]);
this.LogInformation("JSON Master[{0}] Updating '{1}'", UniqueID, path);
}
using (StreamWriter sw = new StreamWriter(ActualFilePath))
else // No token. Let's make one
{
try
{
sw.Write(JsonObject.ToString());
sw.Flush();
}
catch (Exception e)
{
string err = string.Format("Error writing JSON file:\r{0}", e);
Debug.Console(0, err);
ErrorLog.Warn(err);
return;
}
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
this.LogWarning("JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
}
}
using (StreamWriter sw = new StreamWriter(ActualFilePath))
{
try
{
sw.Write(JsonObject.ToString());
sw.Flush();
}
catch (Exception e)
{
string err = string.Format("Error writing JSON file:\r{0}", e);
this.LogException(e, "Error writing JSON file: {0}", e.Message);
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
return;
}
}
}
}
}

View File

@@ -1,18 +1,17 @@
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Represents a JsonToSimplFixedPathObject
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
///
/// </summary>
public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase
{
/// <summary>
/// Constructor
/// </summary>
/// <summary>
/// Constructor
/// </summary>
public JsonToSimplFixedPathObject()
{
this.LinkedToObject = true;
}
}
}
}

View File

@@ -1,37 +1,42 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using Crestron.SimplSharp;
using Newtonsoft.Json.Linq;
using PepperDash.Core.Logging;
using Renci.SshNet.Messages;
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Represents a JsonToSimplGenericMaster
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Generic Master
/// </summary>
public class JsonToSimplGenericMaster : JsonToSimplMaster
{
{
/*****************************************************************************************/
/** Privates **/
// The JSON file in JObject form
// For gathering the incoming data
object StringBuilderLock = new object();
// To prevent multiple same-file access
static object WriteLock = new object();
/// <summary>
/// Gets or sets the SaveCallback
/// </summary>
/// <summary>
/// Callback action for saving
/// </summary>
public Action<string> SaveCallback { get; set; }
/*****************************************************************************************/
/// <summary>
/// SIMPL+ default constructor.
/// </summary>
/// SIMPL+ default constructor.
/// </summary>
public JsonToSimplGenericMaster()
{
{
}
/// <summary>
@@ -71,7 +76,8 @@ namespace PepperDash.Core.JsonToSimpl
}
catch (Exception e)
{
Debug.Console(0, this, "JSON parsing failed:\r{0}", e);
this.LogException(e, "JSON parsing failed:\r{0}", e.Message);
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
}
}
@@ -82,41 +88,40 @@ namespace PepperDash.Core.JsonToSimpl
public override void Save()
{
// this code is duplicated in the other masters!!!!!!!!!!!!!
UnsavedValues = new Dictionary<string, JValue>();
UnsavedValues = new Dictionary<string, JValue>();
// Make each child update their values into master object
foreach (var child in Children)
{
Debug.Console(1, this, "Master. checking child [{0}] for updates to save", child.Key);
this.LogDebug("Master. checking child [{0}] for updates to save", child.Key);
child.UpdateInputsForMaster();
}
if (UnsavedValues == null || UnsavedValues.Count == 0)
{
Debug.Console(1, this, "Master. No updated values to save. Skipping");
this.LogDebug("Master. No updated values to save. Skipping");
return;
}
lock (WriteLock)
{
Debug.Console(1, this, "Saving");
this.LogDebug("Saving");
foreach (var path in UnsavedValues.Keys)
{
var tokenToReplace = JsonObject.SelectToken(path);
if (tokenToReplace != null)
{// It's found
tokenToReplace.Replace(UnsavedValues[path]);
Debug.Console(1, this, "Master Updating '{0}'", path);
this.LogDebug("Master Updating '{0}'", path);
}
else // No token. Let's make one
{
Debug.Console(1, "Master Cannot write value onto missing property: '{0}'", path);
this.LogDebug("Master Cannot write value onto missing property: '{0}'", path);
}
}
}
if (SaveCallback != null)
SaveCallback(JsonObject.ToString());
else
Debug.Console(0, this, "WARNING: No save callback defined.");
this.LogDebug("WARNING: No save callback defined.");
}
}
}
}

View File

@@ -1,34 +1,40 @@
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.IO;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
using JsonSerializationException = NewtonsoftJson::Newtonsoft.Json.JsonSerializationException;
using JsonTextReader = NewtonsoftJson::Newtonsoft.Json.JsonTextReader;
using PepperDash.Core.Logging;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Abstract base class for JsonToSimpl interactions
/// </summary>
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Abstract base class for JsonToSimpl interactions
/// </summary>
public abstract class JsonToSimplMaster : IKeyed
{
/// <summary>
/// Notifies of bool change
/// </summary>
/// <summary>
/// Notifies of bool change
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Notifies of ushort change
/// </summary>
/// <summary>
/// Notifies of ushort change
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UshrtChange;
/// <summary>
/// Notifies of string change
/// </summary>
/// <summary>
/// Notifies of string change
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// A collection of associated child modules
/// </summary>
/// <summary>
/// A collection of associated child modules
/// </summary>
protected List<JsonToSimplChildObjectBase> Children = new List<JsonToSimplChildObjectBase>();
/*****************************************************************************************/
@@ -38,9 +44,9 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string Key { get { return UniqueID; } }
/// <summary>
/// Gets or sets the UniqueID
/// </summary>
/// <summary>
/// A unique ID
/// </summary>
public string UniqueID { get; protected set; }
/// <summary>
@@ -82,9 +88,9 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Gets or sets the JsonObject
/// </summary>
/// <summary>
///
/// </summary>
public JObject JsonObject { get; protected set; }
/*****************************************************************************************/
@@ -137,16 +143,15 @@ namespace PepperDash.Core.JsonToSimpl
{
if (UnsavedValues.ContainsKey(path))
{
Debug.Console(0, "Master[{0}] WARNING - Attempt to add duplicate value for path '{1}'.\r Ingoring. Please ensure that path does not exist on multiple modules.", UniqueID, path);
this.LogWarning("Master[{0}] WARNING - Attempt to add duplicate value for path '{1}'.\r Ingoring. Please ensure that path does not exist on multiple modules.", UniqueID, path);
}
else
UnsavedValues.Add(path, value);
//Debug.Console(0, "Master[{0}] Unsaved size={1}", UniqueID, UnsavedValues.Count);
}
/// <summary>
/// Saves the file
/// </summary>
/// <summary>
/// Saves the file
/// </summary>
public abstract void Save();
@@ -155,18 +160,14 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public static class JsonFixes
{
/// <summary>
/// Deserializes a string into a JObject
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
/// <summary>
/// Deserializes a string into a JObject
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static JObject ParseObject(string json)
{
#if NET6_0
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
#else
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
#endif
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
{
var startDepth = reader.Depth;
var obj = JObject.Load(reader);
@@ -176,21 +177,15 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Deserializes a string into a JArray
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
/// <summary>
/// ParseArray method
/// </summary>
/// <summary>
/// Deserializes a string into a JArray
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static JArray ParseArray(string json)
{
#if NET6_0
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
#else
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
#endif
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
{
var startDepth = reader.Depth;
var obj = JArray.Load(reader);
@@ -233,12 +228,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Helper event
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
/// <summary>
/// Helper event
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnStringChange(string value, ushort index, ushort type)
{
if (StringChange != null)
@@ -249,4 +244,3 @@ namespace PepperDash.Core.JsonToSimpl
}
}
}
}

View File

@@ -1,27 +1,31 @@
using System;
extern alias NewtonsoftJson;
using System;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json.Linq;
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
using PepperDash.Core.Config;
using PepperDash.Core.Logging;
namespace PepperDash.Core.JsonToSimpl
namespace PepperDash.Core.JsonToSimpl;
/// <summary>
/// Portal File Master
/// </summary>
public class JsonToSimplPortalFileMaster : JsonToSimplMaster
{
/// <summary>
/// Portal File Master
/// </summary>
public class JsonToSimplPortalFileMaster : JsonToSimplMaster
{
/// <summary>
/// Sets the filepath as well as registers this with the Global.Masters list
/// </summary>
public string PortalFilepath { get; private set; }
/// <summary>
/// Gets or sets the ActualFilePath
/// </summary>
public string ActualFilePath { get; private set; }
/// <summary>
/// File path of the actual file being read (Portal or local)
/// </summary>
public string ActualFilePath { get; private set; }
/*****************************************************************************************/
/** Privates **/
@@ -33,10 +37,10 @@ namespace PepperDash.Core.JsonToSimpl
/*****************************************************************************************/
/// <summary>
/// SIMPL+ default constructor.
/// </summary>
/// SIMPL+ default constructor.
/// </summary>
public JsonToSimplPortalFileMaster()
{
{
}
/// <summary>
@@ -58,19 +62,19 @@ namespace PepperDash.Core.JsonToSimpl
// If the portal file is xyz.json, then
// the file we want to check for first will be called xyz.local.json
var localFilepath = Path.ChangeExtension(PortalFilepath, "local.json");
Debug.Console(0, this, "Checking for local file {0}", localFilepath);
this.LogInformation("Checking for local file {0}", localFilepath);
var actualLocalFile = GetActualFileInfoFromPath(localFilepath);
if (actualLocalFile != null)
{
ActualFilePath = actualLocalFile.FullName;
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
}
// If the local file does not exist, then read the portal file xyz.json
// and create the local.
else
{
Debug.Console(1, this, "Local JSON file not found {0}\rLoading portal JSON file", localFilepath);
this.LogInformation("Local JSON file not found {0}\rLoading portal JSON file", localFilepath);
var actualPortalFile = GetActualFileInfoFromPath(portalFilepath);
if (actualPortalFile != null)
{
@@ -78,19 +82,18 @@ namespace PepperDash.Core.JsonToSimpl
// got the portal file, hand off to the merge / save method
PortalConfigReader.ReadAndMergeFileIfNecessary(actualPortalFile.FullName, newLocalPath);
ActualFilePath = newLocalPath;
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
}
else
{
var msg = string.Format("Portal JSON file not found: {0}", PortalFilepath);
Debug.Console(1, this, msg);
ErrorLog.Error(msg);
this.LogError(msg);
return;
}
}
// At this point we should have a local file. Do it.
Debug.Console(1, "Reading local JSON file {0}", ActualFilePath);
this.LogInformation("Reading local JSON file {0}", ActualFilePath);
string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
@@ -104,8 +107,7 @@ namespace PepperDash.Core.JsonToSimpl
catch (Exception e)
{
var msg = string.Format("JSON parsing failed:\r{0}", e);
CrestronConsole.PrintLine(msg);
ErrorLog.Error(msg);
this.LogError(msg);
return;
}
}
@@ -146,30 +148,30 @@ namespace PepperDash.Core.JsonToSimpl
// Make each child update their values into master object
foreach (var child in Children)
{
Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
this.LogInformation("Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
child.UpdateInputsForMaster();
}
if (UnsavedValues == null || UnsavedValues.Count == 0)
{
Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID);
this.LogInformation("Master [{0}] No updated values to save. Skipping", UniqueID);
return;
}
lock (FileLock)
{
Debug.Console(1, "Saving");
this.LogInformation("Saving");
foreach (var path in UnsavedValues.Keys)
{
var tokenToReplace = JsonObject.SelectToken(path);
if (tokenToReplace != null)
{// It's found
tokenToReplace.Replace(UnsavedValues[path]);
Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path);
this.LogInformation("JSON Master[{0}] Updating '{1}'", UniqueID, path);
}
else // No token. Let's make one
{
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
this.LogWarning("JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
}
}
@@ -183,12 +185,11 @@ namespace PepperDash.Core.JsonToSimpl
catch (Exception e)
{
string err = string.Format("Error writing JSON file:\r{0}", e);
Debug.Console(0, err);
ErrorLog.Warn(err);
this.LogException(e, "Error writing JSON file: {0}", e.Message);
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
return;
}
}
}
}
}
}

View File

@@ -7,37 +7,38 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Core.Logging
namespace PepperDash.Core.Logging;
/// <summary>
/// Enriches log events with Crestron-specific context properties, such as the application name based on the device platform.
/// </summary>
public class CrestronEnricher : ILogEventEnricher
{
/// <summary>
/// Represents a CrestronEnricher
/// </summary>
public class CrestronEnricher : ILogEventEnricher
static readonly string _appName;
static CrestronEnricher()
{
static readonly string _appName;
static CrestronEnricher()
switch (CrestronEnvironment.DevicePlatform)
{
switch (CrestronEnvironment.DevicePlatform)
{
case eDevicePlatform.Appliance:
_appName = $"App {InitialParametersClass.ApplicationNumber}";
break;
case eDevicePlatform.Server:
_appName = $"{InitialParametersClass.RoomId}";
break;
}
}
/// <summary>
/// Enrich method
/// </summary>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var property = propertyFactory.CreateProperty("App", _appName);
logEvent.AddOrUpdateProperty(property);
case eDevicePlatform.Appliance:
_appName = $"App {InitialParametersClass.ApplicationNumber}";
break;
case eDevicePlatform.Server:
_appName = $"{InitialParametersClass.RoomId}";
break;
}
}
/// <summary>
/// Enriches the log event with Crestron-specific properties.
/// </summary>
/// <param name="logEvent"></param>
/// <param name="propertyFactory"></param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var property = propertyFactory.CreateProperty("App", _appName);
logEvent.AddOrUpdateProperty(property);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -9,56 +9,45 @@ using System.IO;
using System.Text;
namespace PepperDash.Core
namespace PepperDash.Core;
public class DebugConsoleSink : ILogEventSink
{
/// <summary>
/// Represents a DebugConsoleSink
/// </summary>
public class DebugConsoleSink : ILogEventSink
private readonly ITextFormatter _textFormatter;
public void Emit(LogEvent logEvent)
{
private readonly ITextFormatter _textFormatter;
if (!Debug.IsRunningOnAppliance) return;
/// <summary>
/// Emit method
/// </summary>
public void Emit(LogEvent logEvent)
/*string message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}]{logEvent.RenderMessage()}";
if(logEvent.Properties.TryGetValue("Key",out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
if (!Debug.IsRunningOnAppliance) return;
message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}][{rawValue,3}]: {logEvent.RenderMessage()}";
}*/
/*string message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}]{logEvent.RenderMessage()}";
var buffer = new StringWriter(new StringBuilder(256));
if(logEvent.Properties.TryGetValue("Key",out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}][{rawValue,3}]: {logEvent.RenderMessage()}";
}*/
_textFormatter.Format(logEvent, buffer);
var buffer = new StringWriter(new StringBuilder(256));
_textFormatter.Format(logEvent, buffer);
var message = buffer.ToString();
CrestronConsole.PrintLine(message);
}
public DebugConsoleSink(ITextFormatter formatProvider )
{
_textFormatter = formatProvider ?? new JsonFormatter();
}
var message = buffer.ToString();
CrestronConsole.PrintLine(message);
}
public static class DebugConsoleSinkExtensions
public DebugConsoleSink(ITextFormatter formatProvider )
{
/// <summary>
/// DebugConsoleSink method
/// </summary>
public static LoggerConfiguration DebugConsoleSink(
this LoggerSinkConfiguration loggerConfiguration,
ITextFormatter formatProvider = null)
{
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
}
_textFormatter = formatProvider ?? new JsonFormatter();
}
}
public static class DebugConsoleSinkExtensions
{
public static LoggerConfiguration DebugConsoleSink(
this LoggerSinkConfiguration loggerConfiguration,
ITextFormatter formatProvider = null)
{
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
}
}

View File

@@ -1,293 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
namespace PepperDash.Core
{
/// <summary>
/// Represents a debugging context
/// </summary>
public class DebugContext
{
/// <summary>
/// Describes the folder location where a given program stores it's debug level memory. By default, the
/// file written will be named appNdebug where N is 1-10.
/// </summary>
public string Key { get; private set; }
/// <summary>
/// The name of the file containing the current debug settings.
/// </summary>
//string FileName = string.Format(@"\nvram\debug\app{0}Debug.json", InitialParametersClass.ApplicationNumber);
DebugContextSaveData SaveData;
int SaveTimeoutMs = 30000;
CTimer SaveTimer;
static List<DebugContext> Contexts = new List<DebugContext>();
/// <summary>
/// Creates or gets a debug context
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <summary>
/// GetDebugContext method
/// </summary>
public static DebugContext GetDebugContext(string key)
{
var context = Contexts.FirstOrDefault(c => c.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
if (context == null)
{
context = new DebugContext(key);
Contexts.Add(context);
}
return context;
}
/// <summary>
/// Do not use. For S+ access.
/// </summary>
public DebugContext() { }
DebugContext(string key)
{
Key = key;
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro)
{
// Add command to console
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
"appdebug:P [0-2]: Sets the application's console debug message level",
ConsoleAccessLevelEnum.AccessOperator);
}
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
LoadMemory();
}
/// <summary>
/// Used to save memory when shutting down
/// </summary>
/// <param name="programEventType"></param>
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType == eProgramStatusEventType.Stopping)
{
if (SaveTimer != null)
{
SaveTimer.Stop();
SaveTimer = null;
}
Console(0, "Saving debug settings");
SaveMemory();
}
}
/// <summary>
/// Callback for console command
/// </summary>
/// <param name="levelString"></param>
/// <summary>
/// SetDebugFromConsole method
/// </summary>
public void SetDebugFromConsole(string levelString)
{
try
{
if (string.IsNullOrEmpty(levelString.Trim()))
{
CrestronConsole.ConsoleCommandResponse("AppDebug level = {0}", SaveData.Level);
return;
}
SetDebugLevel(Convert.ToInt32(levelString));
}
catch
{
CrestronConsole.PrintLine("Usage: appdebug:P [0-2]");
}
}
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
/// <summary>
/// SetDebugLevel method
/// </summary>
public void SetDebugLevel(int level)
{
if (level <= 2)
{
SaveData.Level = level;
SaveMemoryOnTimeout();
CrestronConsole.PrintLine("[Application {0}], Debug level set to {1}",
InitialParametersClass.ApplicationNumber, SaveData.Level);
}
}
/// <summary>
/// Prints message to console if current debug level is equal to or higher than the level of this message.
/// Uses CrestronConsole.PrintLine.
/// </summary>
/// <param name="level"></param>
/// <param name="format">Console format string</param>
/// <param name="items">Object parameters</param>
public void Console(uint level, string format, params object[] items)
{
if (SaveData.Level >= level)
CrestronConsole.PrintLine("App {0}:{1}", InitialParametersClass.ApplicationNumber,
string.Format(format, items));
}
/// <summary>
/// Console method
/// </summary>
public void Console(uint level, IKeyed dev, string format, params object[] items)
{
if (SaveData.Level >= level)
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
}
/// <summary>
///
/// </summary>
/// <param name="level"></param>
/// <param name="dev"></param>
/// <param name="errorLogLevel"></param>
/// <param name="format"></param>
/// <param name="items"></param>
public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (SaveData.Level >= level)
{
var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items));
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
///
/// </summary>
/// <param name="level"></param>
/// <param name="errorLogLevel"></param>
/// <param name="format"></param>
/// <param name="items"></param>
public void Console(uint level, Debug.ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (SaveData.Level >= level)
{
var str = string.Format(format, items);
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
///
/// </summary>
/// <param name="errorLogLevel"></param>
/// <param name="str"></param>
/// <summary>
/// LogError method
/// </summary>
public void LogError(Debug.ErrorLogLevel errorLogLevel, string str)
{
string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
switch (errorLogLevel)
{
case Debug.ErrorLogLevel.Error:
ErrorLog.Error(msg);
break;
case Debug.ErrorLogLevel.Warning:
ErrorLog.Warn(msg);
break;
case Debug.ErrorLogLevel.Notice:
ErrorLog.Notice(msg);
break;
}
}
/// <summary>
/// Writes the memory object after timeout
/// </summary>
void SaveMemoryOnTimeout()
{
if (SaveTimer == null)
SaveTimer = new CTimer(o =>
{
SaveTimer = null;
SaveMemory();
}, SaveTimeoutMs);
else
SaveTimer.Reset(SaveTimeoutMs);
}
/// <summary>
/// Writes the memory - use SaveMemoryOnTimeout
/// </summary>
void SaveMemory()
{
using (StreamWriter sw = new StreamWriter(GetMemoryFileName()))
{
var json = JsonConvert.SerializeObject(SaveData);
sw.Write(json);
sw.Flush();
}
}
/// <summary>
///
/// </summary>
void LoadMemory()
{
var file = GetMemoryFileName();
if (File.Exists(file))
{
using (StreamReader sr = new StreamReader(file))
{
var data = JsonConvert.DeserializeObject<DebugContextSaveData>(sr.ReadToEnd());
if (data != null)
{
SaveData = data;
Debug.Console(1, "Debug memory restored from file");
return;
}
else
SaveData = new DebugContextSaveData();
}
}
}
/// <summary>
/// Helper to get the file path for this app's debug memory
/// </summary>
string GetMemoryFileName()
{
return string.Format(@"\NVRAM\debugSettings\program{0}-{1}", InitialParametersClass.ApplicationNumber, Key);
}
}
/// <summary>
///
/// </summary>
public class DebugContextSaveData
{
/// <summary>
///
/// </summary>
public int Level { get; set; }
}
}

View File

@@ -3,33 +3,26 @@ using Crestron.SimplSharp.CrestronLogger;
using Serilog.Core;
using Serilog.Events;
namespace PepperDash.Core.Logging
namespace PepperDash.Core.Logging;
public class DebugCrestronLoggerSink : ILogEventSink
{
/// <summary>
/// Represents a DebugCrestronLoggerSink
/// </summary>
public class DebugCrestronLoggerSink : ILogEventSink
public void Emit(LogEvent logEvent)
{
/// <summary>
/// Emit method
/// </summary>
public void Emit(LogEvent logEvent)
if (!Debug.IsRunningOnAppliance) return;
string message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}]{logEvent.RenderMessage()}";
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
if (!Debug.IsRunningOnAppliance) return;
string message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}]{logEvent.RenderMessage()}";
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}][{rawValue}]: {logEvent.RenderMessage()}";
}
CrestronLogger.WriteToLog(message, (uint)logEvent.Level);
message = $"[{logEvent.Timestamp}][{logEvent.Level}][App {InitialParametersClass.ApplicationNumber}][{rawValue}]: {logEvent.RenderMessage()}";
}
public DebugCrestronLoggerSink()
{
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
}
CrestronLogger.WriteToLog(message, (uint)logEvent.Level);
}
public DebugCrestronLoggerSink()
{
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
}
}

View File

@@ -9,63 +9,56 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PepperDash.Core.Logging
namespace PepperDash.Core.Logging;
public class DebugErrorLogSink : ILogEventSink
{
/// <summary>
/// Represents a DebugErrorLogSink
/// </summary>
public class DebugErrorLogSink : ILogEventSink
private ITextFormatter _formatter;
private Dictionary<LogEventLevel, Action<string>> _errorLogMap = new Dictionary<LogEventLevel, Action<string>>
{
private ITextFormatter _formatter;
{ LogEventLevel.Verbose, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Debug, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Information, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Warning, (msg) => ErrorLog.Warn(msg) },
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) },
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) }
};
public void Emit(LogEvent logEvent)
{
string message;
private Dictionary<LogEventLevel, Action<string>> _errorLogMap = new Dictionary<LogEventLevel, Action<string>>
if (_formatter == null)
{
{ LogEventLevel.Verbose, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Debug, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Information, (msg) => ErrorLog.Notice(msg) },
{LogEventLevel.Warning, (msg) => ErrorLog.Warn(msg) },
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) },
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) }
};
/// <summary>
/// Emit method
/// </summary>
public void Emit(LogEvent logEvent)
var programId = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance
? $"App {InitialParametersClass.ApplicationNumber}"
: $"Room {InitialParametersClass.RoomId}";
message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}]{logEvent.RenderMessage()}";
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}][{rawValue}]: {logEvent.RenderMessage()}";
}
} else
{
string message;
var buffer = new StringWriter(new StringBuilder(256));
if (_formatter == null)
{
var programId = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance
? $"App {InitialParametersClass.ApplicationNumber}"
: $"Room {InitialParametersClass.RoomId}";
_formatter.Format(logEvent, buffer);
message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}]{logEvent.RenderMessage()}";
if (logEvent.Properties.TryGetValue("Key", out var value) && value is ScalarValue sv && sv.Value is string rawValue)
{
message = $"[{logEvent.Timestamp}][{logEvent.Level}][{programId}][{rawValue}]: {logEvent.RenderMessage()}";
}
} else
{
var buffer = new StringWriter(new StringBuilder(256));
_formatter.Format(logEvent, buffer);
message = buffer.ToString();
}
if(!_errorLogMap.TryGetValue(logEvent.Level, out var handler))
{
return;
}
handler(message);
message = buffer.ToString();
}
public DebugErrorLogSink(ITextFormatter formatter = null)
if(!_errorLogMap.TryGetValue(logEvent.Level, out var handler))
{
_formatter = formatter;
return;
}
handler(message);
}
public DebugErrorLogSink(ITextFormatter formatter = null)
{
_formatter = formatter;
}
}

View File

@@ -2,112 +2,72 @@
using Serilog.Events;
using Log = PepperDash.Core.Debug;
namespace PepperDash.Core.Logging
namespace PepperDash.Core.Logging;
public static class DebugExtensions
{
public static class DebugExtensions
public static void LogException(this IKeyed device, Exception ex, string message, params object[] args)
{
/// <summary>
/// LogException method
/// </summary>
public static void LogException(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(ex, message, device: device, args);
}
Log.LogMessage(ex, message, device, args);
}
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogVerbose(ex, device, message, args);
}
public static void LogVerbose(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Verbose, ex, message, device, args);
}
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(this IKeyed device, string message, params object[] args)
{
Log.LogVerbose(device, message, args);
}
public static void LogVerbose(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Verbose, device, message, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogDebug(ex, device, message, args);
}
public static void LogDebug(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Debug, ex, message, device, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(this IKeyed device, string message, params object[] args)
{
Log.LogDebug(device, message, args);
}
public static void LogDebug(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Debug, device, message, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogInformation(ex, device, message, args);
}
public static void LogInformation(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Information, ex, message, device, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(this IKeyed device, string message, params object[] args)
{
Log.LogInformation(device, message, args);
}
public static void LogInformation(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Information, device, message, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogWarning(ex, device, message, args);
}
public static void LogWarning(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Warning, ex, message, device, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(this IKeyed device, string message, params object[] args)
{
Log.LogWarning(device, message, args);
}
public static void LogWarning(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Warning, device, message, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogError(ex, device, message, args);
}
public static void LogError(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Error, ex, message, device, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(this IKeyed device, string message, params object[] args)
{
Log.LogError(device, message, args);
}
public static void LogError(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Error, device, message, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogFatal(ex, device, message, args);
}
public static void LogFatal(this IKeyed device, Exception ex, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Fatal, ex, message, device, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(this IKeyed device, string message, params object[] args)
{
Log.LogFatal(device, message, args);
}
public static void LogFatal(this IKeyed device, string message, params object[] args)
{
Log.LogMessage(LogEventLevel.Fatal, device, message, args);
}
}

Some files were not shown because too many files have changed in this diff Show More