mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-21 07:35:04 +00:00
Compare commits
20 Commits
v2.20.7-wo
...
v3.0.0-net
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90b6f258f0 | ||
|
|
e1e32cea6f | ||
|
|
e31df338d6 | ||
|
|
d14058fc32 | ||
|
|
04d6508c80 | ||
|
|
1cbc8194ec | ||
|
|
6d2cd75cbe | ||
|
|
8b873b7248 | ||
|
|
58a2a5c008 | ||
|
|
cc7e2ab675 | ||
|
|
dc900f3f31 | ||
|
|
562f0ba793 | ||
|
|
9c3c924a29 | ||
|
|
9b5af60a46 | ||
|
|
a99b0a1fac | ||
|
|
7591913a9c | ||
|
|
66a6612b65 | ||
|
|
688cf34153 | ||
|
|
0c59237232 | ||
|
|
88eec9a3f1 |
@@ -10,8 +10,7 @@ jobs:
|
||||
uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-getversion.yml@main
|
||||
secrets: inherit
|
||||
build-4Series:
|
||||
# uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-4Series-builds.yml@main
|
||||
uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-4Series-builds.yml@reorder-steps
|
||||
uses: PepperDash/workflow-templates/.github/workflows/essentialsplugins-4Series-builds.yml@main
|
||||
secrets: inherit
|
||||
needs: getVersion
|
||||
if: needs.getVersion.outputs.newVersion == 'true'
|
||||
|
||||
56
.github/workflows/ci.yml
vendored
Normal file
56
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: CI Build and Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop, net8-updates ]
|
||||
pull_request:
|
||||
branches: [ main, develop, net8-updates ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
|
||||
|
||||
- name: Generate coverage report
|
||||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0
|
||||
with:
|
||||
reports: coverage/**/coverage.cobertura.xml
|
||||
targetdir: coverage-report
|
||||
reporttypes: Html;Cobertura;MarkdownSummary
|
||||
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
file: ./coverage-report/Cobertura.xml
|
||||
flags: unittests
|
||||
name: codecov-umbrella
|
||||
fail_ci_if_error: false
|
||||
|
||||
- name: Write coverage summary
|
||||
run: cat coverage-report/Summary.md >> $GITHUB_STEP_SUMMARY
|
||||
if: always()
|
||||
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
with:
|
||||
name: test-results
|
||||
path: |
|
||||
coverage/
|
||||
coverage-report/
|
||||
247
.github/workflows/essentials-3-dev-build.yml
vendored
Normal file
247
.github/workflows/essentials-3-dev-build.yml
vendored
Normal 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 "=================================="
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -394,6 +394,3 @@ essentials-framework/Essentials Interfaces/PepperDash_Essentials_Interfaces/Pepp
|
||||
.vscode/settings.json
|
||||
_site/
|
||||
api/
|
||||
*.DS_Store
|
||||
/._PepperDash.Essentials.4Series.sln
|
||||
dotnet
|
||||
|
||||
9
.vscode/extensions.json
vendored
9
.vscode/extensions.json
vendored
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"ms-dotnettools.vscode-dotnet-runtime",
|
||||
"ms-dotnettools.csharp",
|
||||
"ms-dotnettools.csdevkit",
|
||||
"vivaxy.vscode-conventional-commits",
|
||||
"mhutchie.git-graph"
|
||||
]
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
# Crestron Library Usage Analysis - PepperDash Essentials
|
||||
|
||||
This document provides a comprehensive analysis of Crestron classes and interfaces used throughout the PepperDash Essentials framework, organized by namespace and library component.
|
||||
|
||||
## Executive Summary
|
||||
|
||||
The PepperDash Essentials framework extensively leverages Crestron SDK components across 100+ files, providing abstractions for:
|
||||
- Control system hardware (processors, touchpanels, IO devices)
|
||||
- Communication interfaces (Serial, TCP/IP, SSH, CEC, IR)
|
||||
- Device management and routing
|
||||
- User interface components and smart objects
|
||||
- System monitoring and diagnostics
|
||||
|
||||
## 1. Core Crestron Libraries
|
||||
|
||||
### 1.1 Crestron.SimplSharp
|
||||
|
||||
**Primary Usage**: Foundational framework components, collections, and basic types.
|
||||
|
||||
**Key Files**:
|
||||
- Multiple files across all projects use `Crestron.SimplSharp` namespaces
|
||||
- Provides basic C# runtime support for Crestron processors
|
||||
|
||||
### 1.2 Crestron.SimplSharpPro
|
||||
|
||||
**Primary Usage**: Main hardware abstraction layer for Crestron devices.
|
||||
|
||||
**Key Classes Used**:
|
||||
|
||||
#### CrestronControlSystem
|
||||
- **File**: `/src/PepperDash.Essentials/ControlSystem.cs`
|
||||
- **Usage**: Base class for the main control system implementation
|
||||
- **Implementation**: `public class ControlSystem : CrestronControlSystem, ILoadConfig`
|
||||
|
||||
#### Device (Base Class)
|
||||
- **Files**: 50+ files inherit from or use this class
|
||||
- **Key Implementations**:
|
||||
- `/src/PepperDash.Core/Device.cs` - Core device abstraction
|
||||
- `/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs` - Extended device base
|
||||
- `/src/PepperDash.Essentials.Core/Room/Room.cs` - Room device implementation
|
||||
- `/src/PepperDash.Essentials.Core/Devices/CrestronProcessor.cs` - Processor device wrapper
|
||||
|
||||
#### BasicTriList
|
||||
- **Files**: 30+ files use this class extensively
|
||||
- **Primary Usage**: Touchpanel communication and SIMPL bridging
|
||||
- **Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Touchpanels/TriListExtensions.cs` - Extension methods for signal handling
|
||||
- `/src/PepperDash.Essentials.Core/Devices/EssentialsBridgeableDevice.cs` - Bridge interface
|
||||
- `/src/PepperDash.Essentials.Core/Touchpanels/ModalDialog.cs` - UI dialog implementation
|
||||
|
||||
#### BasicTriListWithSmartObject
|
||||
- **Files**: Multiple touchpanel and UI files
|
||||
- **Usage**: Enhanced touchpanel support with smart object integration
|
||||
- **Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Touchpanels/Interfaces.cs` - Interface definitions
|
||||
- `/src/PepperDash.Essentials.Core/SmartObjects/SubpageReferenceList/SubpageReferenceList.cs`
|
||||
|
||||
## 2. Communication Hardware
|
||||
|
||||
### 2.1 Serial Communication (ComPort)
|
||||
|
||||
**Primary Class**: `ComPort`
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Comm and IR/ComPortController.cs`
|
||||
- `/src/PepperDash.Essentials.Core/Comm and IR/CommFactory.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public class ComPortController : Device, IBasicCommunicationWithStreamDebugging
|
||||
public static ComPort GetComPort(EssentialsControlPropertiesConfig config)
|
||||
```
|
||||
|
||||
**Interface Support**: `IComPorts` - Used for devices that provide multiple COM ports
|
||||
|
||||
### 2.2 IR Communication (IROutputPort)
|
||||
|
||||
**Primary Class**: `IROutputPort`
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Devices/IrOutputPortController.cs`
|
||||
- `/src/PepperDash.Essentials.Core/Devices/GenericIRController.cs`
|
||||
- `/src/PepperDash.Essentials.Core/Comm and IR/IRPortHelper.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public class IrOutputPortController : Device
|
||||
IROutputPort IrPort;
|
||||
public IrOutputPortController(string key, IROutputPort port, string irDriverFilepath)
|
||||
```
|
||||
|
||||
### 2.3 CEC Communication (ICec)
|
||||
|
||||
**Primary Interface**: `ICec`
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Comm and IR/CecPortController.cs`
|
||||
- `/src/PepperDash.Essentials.Core/Comm and IR/CommFactory.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public class CecPortController : Device, IBasicCommunicationWithStreamDebugging
|
||||
public static ICec GetCecPort(ControlPropertiesConfig config)
|
||||
```
|
||||
|
||||
## 3. Input/Output Hardware
|
||||
|
||||
### 3.1 Digital Input
|
||||
|
||||
**Primary Interface**: `IDigitalInput`
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/CrestronIO/GenericDigitalInputDevice.cs`
|
||||
- `/src/PepperDash.Essentials.Core/Microphone Privacy/MicrophonePrivacyController.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public List<IDigitalInput> Inputs { get; private set; }
|
||||
void AddInput(IDigitalInput input)
|
||||
```
|
||||
|
||||
### 3.2 Versiport Support
|
||||
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/CrestronIO/GenericVersiportInputDevice.cs`
|
||||
- `/src/PepperDash.Essentials.Core/CrestronIO/GenericVersiportAnalogInputDevice.cs`
|
||||
- `/src/PepperDash.Essentials.Core/CrestronIO/GenericVersiportOutputDevice.cs`
|
||||
|
||||
**Usage**: Provides flexible I/O port configuration for various signal types
|
||||
|
||||
## 4. Touchpanel Hardware
|
||||
|
||||
### 4.1 MPC3 Touchpanel
|
||||
|
||||
**Primary Class**: `MPC3Basic`
|
||||
**Key File**: `/src/PepperDash.Essentials.Core/Touchpanels/Mpc3Touchpanel.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public class Mpc3TouchpanelController : Device
|
||||
readonly MPC3Basic _touchpanel;
|
||||
_touchpanel = processor.ControllerTouchScreenSlotDevice as MPC3Basic;
|
||||
```
|
||||
|
||||
### 4.2 TSW Series Support
|
||||
|
||||
**Evidence**: References found in messenger files and mobile control components
|
||||
**Usage**: Integrated through mobile control messaging system for TSW touchpanel features
|
||||
|
||||
## 5. Timer and Threading
|
||||
|
||||
### 5.1 CTimer
|
||||
|
||||
**Primary Class**: `CTimer`
|
||||
**Key File**: `/src/PepperDash.Core/PasswordManagement/PasswordManager.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: CTimer Started"));
|
||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: CTimer Reset"));
|
||||
```
|
||||
|
||||
## 6. Networking and Communication
|
||||
|
||||
### 6.1 Ethernet Communication
|
||||
|
||||
**Libraries Used**:
|
||||
- `Crestron.SimplSharpPro.EthernetCommunication`
|
||||
- `Crestron.SimplSharp.Net.Utilities.EthernetHelper`
|
||||
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Core/Comm/GenericTcpIpClient.cs`
|
||||
- `/src/PepperDash.Core/Comm/GenericTcpIpServer.cs`
|
||||
- `/src/PepperDash.Core/Comm/GenericSecureTcpIpClient.cs`
|
||||
- `/src/PepperDash.Core/Comm/GenericSshClient.cs`
|
||||
- `/src/PepperDash.Core/Comm/GenericUdpServer.cs`
|
||||
|
||||
**Usage Pattern**:
|
||||
```csharp
|
||||
public class GenericTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
public class GenericSecureTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
```
|
||||
|
||||
## 7. Device Management Libraries
|
||||
|
||||
### 7.1 DeviceSupport
|
||||
|
||||
**Library**: `Crestron.SimplSharpPro.DeviceSupport`
|
||||
**Usage**: Core device support infrastructure used throughout the framework
|
||||
|
||||
### 7.2 DM (DigitalMedia)
|
||||
|
||||
**Library**: `Crestron.SimplSharpPro.DM`
|
||||
**Usage**: Digital media routing and switching support
|
||||
**Evidence**: Found in routing configuration and DM output card references
|
||||
|
||||
## 8. User Interface Libraries
|
||||
|
||||
### 8.1 UI Components
|
||||
|
||||
**Library**: `Crestron.SimplSharpPro.UI`
|
||||
**Usage**: User interface elements and touchpanel controls
|
||||
|
||||
### 8.2 Smart Objects
|
||||
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/SmartObjects/SmartObjectDynamicList.cs`
|
||||
- `/src/PepperDash.Essentials.Core/SmartObjects/SubpageReferenceList/SubpageReferenceList.cs`
|
||||
|
||||
**Usage**: Advanced UI components with dynamic content
|
||||
|
||||
## 9. System Monitoring and Diagnostics
|
||||
|
||||
### 9.1 Diagnostics
|
||||
|
||||
**Library**: `Crestron.SimplSharpPro.Diagnostics`
|
||||
**Usage**: System health monitoring and performance tracking
|
||||
|
||||
### 9.2 System Information
|
||||
|
||||
**Key Files**:
|
||||
- `/src/PepperDash.Essentials.Core/Monitoring/SystemMonitorController.cs`
|
||||
|
||||
**Usage**: Provides system status, Ethernet information, and program details
|
||||
|
||||
## 10. Integration Patterns
|
||||
|
||||
### 10.1 SIMPL Bridging
|
||||
|
||||
**Pattern**: Extensive use of `BasicTriList` for SIMPL integration
|
||||
**Files**: Bridge classes throughout the framework implement `LinkToApi` methods:
|
||||
```csharp
|
||||
public abstract void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge);
|
||||
```
|
||||
|
||||
### 10.2 Device Factory Pattern
|
||||
|
||||
**Implementation**: Factory classes create hardware-specific implementations
|
||||
**Example**: `CommFactory.cs` provides communication device creation
|
||||
|
||||
### 10.3 Extension Methods
|
||||
|
||||
**Pattern**: Extensive use of extension methods for Crestron classes
|
||||
**Example**: `TriListExtensions.cs` adds 30+ extension methods to `BasicTriList`
|
||||
|
||||
## 11. Signal Processing
|
||||
|
||||
### 11.1 Signal Types
|
||||
|
||||
**Bool Signals**: Digital control and feedback
|
||||
**UShort Signals**: Analog values and numeric data
|
||||
**String Signals**: Text and configuration data
|
||||
|
||||
**Implementation**: Comprehensive signal handling in `TriListExtensions.cs`
|
||||
|
||||
## 12. Error Handling and Logging
|
||||
|
||||
**Pattern**: Consistent use of Crestron's Debug logging throughout
|
||||
**Examples**:
|
||||
```csharp
|
||||
Debug.LogMessage(LogEventLevel.Information, "Device {0} is not a valid device", dc.PortDeviceKey);
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Error Waking Panel. Maybe testing with Xpanel?");
|
||||
```
|
||||
|
||||
## 13. Threading and Synchronization
|
||||
|
||||
**Components**:
|
||||
- CTimer for time-based operations
|
||||
- Thread-safe collections and patterns
|
||||
- Event-driven programming models
|
||||
|
||||
## Conclusion
|
||||
|
||||
The PepperDash Essentials framework demonstrates sophisticated integration with the Crestron ecosystem, leveraging:
|
||||
|
||||
- **Core Infrastructure**: CrestronControlSystem, Device base classes
|
||||
- **Communication**: COM, IR, CEC, TCP/IP, SSH protocols
|
||||
- **Hardware Abstraction**: Touchpanels, I/O devices, processors
|
||||
- **User Interface**: Smart objects, signal processing, SIMPL bridging
|
||||
- **System Services**: Monitoring, diagnostics, device management
|
||||
|
||||
This analysis shows that Essentials serves as a comprehensive middleware layer, abstracting Crestron hardware complexities while providing modern software development patterns and practices.
|
||||
|
||||
---
|
||||
*Generated: [Current Date]*
|
||||
*Framework Version: PepperDash Essentials (Based on codebase analysis)*
|
||||
|
||||
42
PepperDash.Essentials.Tests.sln
Normal file
42
PepperDash.Essentials.Tests.sln
Normal file
@@ -0,0 +1,42 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A8B8F24D-3181-45BF-9ED3-F734E04F0BC8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PepperDash.Core", "src\PepperDash.Core\PepperDash.Core.csproj", "{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PepperDash.Essentials.Core", "src\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj", "{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B8B8F24D-3181-45BF-9ED3-F734E04F0BC9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PepperDash.Essentials.Core.Tests", "tests\PepperDash.Essentials.Core.Tests\PepperDash.Essentials.Core.Tests.csproj", "{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{1E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7A} = {A8B8F24D-3181-45BF-9ED3-F734E04F0BC8}
|
||||
{2E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7B} = {A8B8F24D-3181-45BF-9ED3-F734E04F0BC8}
|
||||
{3E5D8C7C-A4D0-4D0E-A6B0-9E3F3D9C8B7C} = {B8B8F24D-3181-45BF-9ED3-F734E04F0BC9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
166
TESTING_STRATEGY.md
Normal file
166
TESTING_STRATEGY.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# PepperDash Essentials Unit Testing Strategy
|
||||
|
||||
## Problem Statement
|
||||
The PepperDash Essentials framework is tightly coupled to Crestron hardware libraries that only run on Crestron devices, making it impossible to run unit tests on development machines or in CI/CD pipelines.
|
||||
|
||||
## Solution: Abstraction Layer Pattern
|
||||
|
||||
### 1. Core Abstractions Created
|
||||
We've implemented abstraction interfaces that decouple business logic from Crestron hardware:
|
||||
|
||||
- **`ICrestronControlSystem`** - Abstracts the control system hardware
|
||||
- **`IRelayPort`** - Abstracts relay functionality
|
||||
- **`IDigitalInput`** - Abstracts digital inputs with event handling
|
||||
- **`IVersiPort`** - Abstracts VersiPort I/O
|
||||
|
||||
### 2. Adapter Pattern Implementation
|
||||
Created adapter classes that wrap Crestron objects in production:
|
||||
|
||||
```csharp
|
||||
// Production code uses adapters
|
||||
var controlSystem = new CrestronControlSystemAdapter(Global.ControlSystem);
|
||||
var processor = new CrestronProcessorTestable("key", controlSystem);
|
||||
|
||||
// Test code uses mocks
|
||||
var mockControlSystem = new Mock<ICrestronControlSystem>();
|
||||
var processor = new CrestronProcessorTestable("key", mockControlSystem.Object);
|
||||
```
|
||||
|
||||
### 3. Testable Classes
|
||||
Refactored classes to accept abstractions via dependency injection:
|
||||
|
||||
- **`CrestronProcessorTestable`** - Accepts `ICrestronControlSystem`
|
||||
- **`GenericRelayDeviceTestable`** - Accepts `IRelayPort`
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
### Step 1: Identify Dependencies
|
||||
```bash
|
||||
# Find Crestron dependencies
|
||||
grep -r "using Crestron" --include="*.cs"
|
||||
```
|
||||
|
||||
### Step 2: Create Abstractions
|
||||
Define interfaces that mirror the Crestron API surface you need:
|
||||
```csharp
|
||||
public interface IRelayPort
|
||||
{
|
||||
void Open();
|
||||
void Close();
|
||||
void Pulse(int delayMs);
|
||||
bool State { get; }
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Implement Adapters
|
||||
Wrap Crestron objects with adapters:
|
||||
```csharp
|
||||
public class RelayPortAdapter : IRelayPort
|
||||
{
|
||||
private readonly Relay _relay;
|
||||
public void Open() => _relay.Open();
|
||||
// ... other methods
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: Refactor Classes
|
||||
Accept abstractions in constructors:
|
||||
```csharp
|
||||
public class CrestronProcessorTestable
|
||||
{
|
||||
public CrestronProcessorTestable(string key, ICrestronControlSystem processor)
|
||||
{
|
||||
// Use abstraction instead of concrete type
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5: Write Tests
|
||||
Use mocking frameworks to test business logic:
|
||||
```csharp
|
||||
[Fact]
|
||||
public void OpenRelay_CallsRelayPortOpen()
|
||||
{
|
||||
var mockRelay = new Mock<IRelayPort>();
|
||||
var device = new GenericRelayDeviceTestable("test", mockRelay.Object);
|
||||
|
||||
device.OpenRelay();
|
||||
|
||||
mockRelay.Verify(r => r.Open(), Times.Once);
|
||||
}
|
||||
```
|
||||
|
||||
## Test Project Structure
|
||||
```
|
||||
tests/
|
||||
├── PepperDash.Essentials.Core.Tests/
|
||||
│ ├── Abstractions/ # Tests for abstraction adapters
|
||||
│ ├── Devices/ # Device-specific tests
|
||||
│ └── *.csproj # Test project file
|
||||
└── README.md # Testing documentation
|
||||
```
|
||||
|
||||
## CI/CD Integration
|
||||
|
||||
### GitHub Actions Workflow
|
||||
The `.github/workflows/ci.yml` file runs tests automatically on:
|
||||
- Push to main/develop branches
|
||||
- Pull requests
|
||||
- Generates code coverage reports
|
||||
|
||||
### Running Tests Locally
|
||||
```bash
|
||||
# Run all tests
|
||||
dotnet test
|
||||
|
||||
# Run with coverage
|
||||
dotnet test --collect:"XPlat Code Coverage"
|
||||
|
||||
# Run specific tests
|
||||
dotnet test --filter "FullyQualifiedName~CrestronProcessor"
|
||||
```
|
||||
|
||||
## Benefits
|
||||
|
||||
1. **Unit Testing Without Hardware** - Tests run on any machine
|
||||
2. **CI/CD Integration** - Automated testing in pipelines
|
||||
3. **Better Design** - Encourages SOLID principles
|
||||
4. **Faster Development** - No need for hardware to test logic
|
||||
5. **Higher Code Quality** - Catch bugs before deployment
|
||||
|
||||
## Migration Guide
|
||||
|
||||
### For Existing Code
|
||||
1. Identify classes with Crestron dependencies
|
||||
2. Create abstraction interfaces
|
||||
3. Implement adapters
|
||||
4. Create testable versions accepting abstractions
|
||||
5. Write unit tests
|
||||
|
||||
### For New Code
|
||||
1. Always code against abstractions, not Crestron types
|
||||
2. Use dependency injection
|
||||
3. Write tests first (TDD approach)
|
||||
|
||||
## Current Test Coverage
|
||||
- ✅ CrestronProcessor relay management
|
||||
- ✅ GenericRelayDevice operations
|
||||
- ✅ Digital input event handling
|
||||
- ✅ VersiPort analog/digital operations
|
||||
|
||||
## Next Steps
|
||||
1. Expand abstractions for more Crestron components
|
||||
2. Increase test coverage across all modules
|
||||
3. Add integration tests with mock hardware
|
||||
4. Document testing best practices
|
||||
5. Create code generation tools for adapters
|
||||
|
||||
## Tools Used
|
||||
- **xUnit** - Test framework
|
||||
- **Moq** - Mocking library
|
||||
- **FluentAssertions** - Readable assertions
|
||||
- **Coverlet** - Code coverage
|
||||
- **GitHub Actions** - CI/CD
|
||||
|
||||
## Summary
|
||||
By introducing an abstraction layer between the business logic and Crestron hardware dependencies, we've successfully enabled unit testing for the PepperDash Essentials framework. This approach allows development and testing without physical hardware while maintaining full compatibility with Crestron systems in production.
|
||||
7
runtimeconfig.json
Normal file
7
runtimeconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"configProperties": {
|
||||
"System.Globalization.Invariant": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -23,32 +23,23 @@
|
||||
<FileName>$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz</FileName>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="DeleteCLZ" BeforeTargets="CoreBuild" Condition="$(ProjectType) == 'Library' And $(TargetDir) != ''">
|
||||
<ItemGroup>
|
||||
<OldCLZFiles Include="$(TargetDir)$(TargetName).*.$(TargetFramework).clz" />
|
||||
</ItemGroup>
|
||||
<Delete Files="@(OldCLZFiles)" Condition="@(OldCLZFiles) != ''">
|
||||
<Target Name="DeleteCLZ" BeforeTargets="PreBuildEvent" Condition="$(ProjectType) == 'Library' And $(TargetDir) != '' And Exists($(FileName))">
|
||||
<Delete Files="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).clz">
|
||||
<Output TaskParameter="DeletedFiles" ItemName="DeletedList"/>
|
||||
</Delete>
|
||||
<Message Text="Deleted old CLZ files: '@(DeletedList)'" Condition="@(DeletedList) != ''" />
|
||||
<Message Text="Deleted files: '@(DeletedList)'" />
|
||||
</Target>
|
||||
<Target Name="DeleteCPZ" BeforeTargets="CoreBuild" Condition="$(ProjectType) == 'Program' And $(TargetDir) != ''">
|
||||
<ItemGroup>
|
||||
<OldCPZFiles Include="$(TargetDir)$(TargetName).*.$(TargetFramework).cpz" />
|
||||
</ItemGroup>
|
||||
<Delete Files="@(OldCPZFiles)" Condition="@(OldCPZFiles) != ''">
|
||||
<Target Name="DeleteCPZ" BeforeTargets="PreBuildEvent" Condition="$(ProjectType) == 'Program' And $(TargetDir) != '' And Exists($(FileName))">
|
||||
<Delete Files="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz">
|
||||
<Output TaskParameter="DeletedFiles" ItemName="DeletedList"/>
|
||||
</Delete>
|
||||
<Message Text="Deleted old CPZ files: '@(DeletedList)'" Condition="@(DeletedList) != ''" />
|
||||
<Message Text="Deleted files: '@(DeletedList)'" />
|
||||
</Target>
|
||||
<Target Name="DeleteCPLZ" BeforeTargets="CoreBuild" Condition="$(ProjectType) == 'ProgramLibrary' And $(TargetDir) != ''">
|
||||
<ItemGroup>
|
||||
<OldCPLZFiles Include="$(TargetDir)$(TargetName).*.$(TargetFramework).cplz" />
|
||||
</ItemGroup>
|
||||
<Delete Files="@(OldCPLZFiles)" Condition="@(OldCPLZFiles) != ''">
|
||||
<Target Name="DeleteCPLZ" BeforeTargets="PreBuildEvent" Condition="$(ProjectType) == 'ProgramLibrary' And $(TargetDir) != '' And Exists($(FileName))">
|
||||
<Delete Files="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cplz">
|
||||
<Output TaskParameter="DeletedFiles" ItemName="DeletedList"/>
|
||||
</Delete>
|
||||
<Message Text="Deleted old CPLZ files: '@(DeletedList)'" Condition="@(DeletedList) != ''" />
|
||||
<Message Text="Deleted files: '@(DeletedList)'" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CreateCPLZ" AfterTargets="Build" Condition="$(ProjectType) == 'ProgramLibrary' And $(TargetDir) != ''" DependsOnTargets="DeleteCPLZ">
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -85,7 +85,8 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop method
|
||||
/// Disconnects this gather from the Port's TextReceived event. This will not fire LineReceived
|
||||
/// after the this call.
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
@@ -175,4 +176,3 @@ namespace PepperDash.Core
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
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
|
||||
/// </summary>
|
||||
public class CommunicationStreamDebugging
|
||||
{
|
||||
/// <summary>
|
||||
/// Device Key that this instance configures
|
||||
/// </summary>
|
||||
@@ -22,7 +23,7 @@ namespace PepperDash.Core
|
||||
private CTimer DebugExpiryPeriod;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the DebugSetting
|
||||
/// The current debug setting
|
||||
/// </summary>
|
||||
public eStreamDebuggingSetting DebugSetting { get; private set; }
|
||||
|
||||
@@ -36,14 +37,14 @@ namespace PepperDash.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
return _DebugTimeoutInMs / 60000;
|
||||
return _DebugTimeoutInMs/60000;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RxStreamDebuggingIsEnabled
|
||||
/// Indicates that receive stream debugging is enabled
|
||||
/// </summary>
|
||||
public bool RxStreamDebuggingIsEnabled { get; private set; }
|
||||
public bool RxStreamDebuggingIsEnabled{ get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that transmit stream debugging is enabled
|
||||
@@ -64,9 +65,6 @@ namespace PepperDash.Core
|
||||
/// 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)
|
||||
@@ -83,9 +81,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="setting"></param>
|
||||
/// <param name="minutes"></param>
|
||||
/// <summary>
|
||||
/// SetDebuggingWithSpecificTimeout method
|
||||
/// </summary>
|
||||
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
|
||||
{
|
||||
if (setting == eStreamDebuggingSetting.Off)
|
||||
@@ -134,5 +129,48 @@ namespace PepperDash.Core
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The available settings for stream debugging response types
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum eStreamDebuggingDataTypeSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug data in byte format
|
||||
/// </summary>
|
||||
Bytes = 0,
|
||||
/// <summary>
|
||||
/// Debug data in text format
|
||||
/// </summary>
|
||||
Text = 1,
|
||||
/// <summary>
|
||||
/// Debug data in both byte and text formats
|
||||
/// </summary>
|
||||
Both = Bytes | Text,
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ using Crestron.SimplSharp;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Config properties that indicate how to communicate with a device for control
|
||||
/// </summary>
|
||||
public class ControlPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a ControlPropertiesConfig
|
||||
/// </summary>
|
||||
public class ControlPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// The method of control
|
||||
/// </summary>
|
||||
@@ -89,5 +89,4 @@ namespace PepperDash.Core
|
||||
public ControlPropertiesConfig()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,21 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate for notifying of socket status changes
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs class for socket status changes
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// Gets or sets the Client
|
||||
///
|
||||
/// </summary>
|
||||
public ISocketStatus Client { get; private set; }
|
||||
|
||||
@@ -46,21 +46,21 @@ namespace PepperDash.Core
|
||||
/// 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>
|
||||
/// 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>
|
||||
/// 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; }
|
||||
|
||||
@@ -76,20 +76,20 @@ namespace PepperDash.Core
|
||||
/// 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>
|
||||
/// 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>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -130,13 +130,13 @@ namespace PepperDash.Core
|
||||
/// S+ Constructor
|
||||
/// </summary>
|
||||
public GenericTcpServerSocketStatusChangeEventArgs() { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs for TCP server com method receive text
|
||||
/// </summary>
|
||||
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// EventArgs for TCP server com method receive text
|
||||
/// </summary>
|
||||
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -154,7 +154,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Text
|
||||
///
|
||||
/// </summary>
|
||||
public string Text { get; private set; }
|
||||
|
||||
@@ -181,13 +181,13 @@ namespace PepperDash.Core
|
||||
/// S+ Constructor
|
||||
/// </summary>
|
||||
public GenericTcpServerCommMethodReceiveTextArgs() { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs for TCP server client ready for communication
|
||||
/// </summary>
|
||||
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// EventArgs for TCP server client ready for communication
|
||||
/// </summary>
|
||||
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -205,13 +205,13 @@ namespace PepperDash.Core
|
||||
/// S+ Constructor
|
||||
/// </summary>
|
||||
public GenericTcpServerClientReadyForcommunicationsEventArgs() { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EventArgs for UDP connected
|
||||
/// </summary>
|
||||
public class GenericUdpConnectedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// EventArgs for UDP connected
|
||||
/// </summary>
|
||||
public class GenericUdpConnectedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -244,8 +244,5 @@ namespace PepperDash.Core
|
||||
Connected = connected;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// A class to handle secure TCP/IP communications with a server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to handle secure TCP/IP communications with a server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
{
|
||||
private const string SplusKey = "Uninitialized Secure Tcp _client";
|
||||
/// <summary>
|
||||
/// Stream debugging
|
||||
@@ -79,7 +79,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port on server
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace PepperDash.Core
|
||||
public string ConnectionFailure { get { return ClientStatus.ToString(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AutoReconnect
|
||||
/// bool to track if auto reconnect should be set on the socket
|
||||
/// </summary>
|
||||
public bool AutoReconnect { get; set; }
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace PepperDash.Core
|
||||
#region GenericSecureTcpIpClient properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKeyRequired
|
||||
/// Bool to show whether the server requires a preshared key. This is used in the DynamicTCPServer class
|
||||
/// </summary>
|
||||
public bool SharedKeyRequired { get; set; }
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKey
|
||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module
|
||||
/// </summary>
|
||||
public string SharedKey { get; set; }
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace PepperDash.Core
|
||||
bool IsTryingToConnect;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IsReadyForCommunication
|
||||
/// Bool showing if socket is ready for communication after shared key exchange
|
||||
/// </summary>
|
||||
public bool IsReadyForCommunication { get; set; }
|
||||
|
||||
@@ -342,7 +342,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// Just to help S+ set the key
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
@@ -421,9 +421,6 @@ namespace PepperDash.Core
|
||||
/// Deactivate the client
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// Deactivate method
|
||||
/// </summary>
|
||||
public override bool Deactivate()
|
||||
{
|
||||
if (_client != null)
|
||||
@@ -435,7 +432,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
@@ -566,7 +563,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
///
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
@@ -589,7 +586,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DisconnectClient method
|
||||
/// Does the actual disconnect business
|
||||
/// </summary>
|
||||
public void DisconnectClient()
|
||||
{
|
||||
@@ -849,7 +846,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendText method
|
||||
/// General send method
|
||||
/// </summary>
|
||||
public void SendText(string text)
|
||||
{
|
||||
@@ -878,7 +875,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendBytes method
|
||||
///
|
||||
/// </summary>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
@@ -953,6 +950,4 @@ namespace PepperDash.Core
|
||||
handler(this, new GenericTcpServerClientReadyForcommunicationsEventArgs(IsReadyForCommunication));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,13 +19,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Generic secure TCP/IP client for server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpClient_ForServer : Device, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic secure TCP/IP client for server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpClient_ForServer : Device, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Band aid delegate for choked server
|
||||
/// </summary>
|
||||
@@ -80,7 +80,7 @@ namespace PepperDash.Core
|
||||
public string Hostname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port on server
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKey
|
||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module
|
||||
/// </summary>
|
||||
public string SharedKey { get; set; }
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace PepperDash.Core
|
||||
private bool WaitingForSharedKeyResponse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BufferSize
|
||||
/// Defaults to 2000
|
||||
/// </summary>
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
@@ -336,7 +336,7 @@ namespace PepperDash.Core
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// Just to help S+ set the key
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
@@ -395,7 +395,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
@@ -526,7 +526,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
///
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
@@ -804,7 +804,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendText method
|
||||
/// General send method
|
||||
/// </summary>
|
||||
public void SendText(string text)
|
||||
{
|
||||
@@ -833,7 +833,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendBytes method
|
||||
///
|
||||
/// </summary>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
@@ -904,6 +904,4 @@ namespace PepperDash.Core
|
||||
handler(this, new GenericTcpServerClientReadyForcommunicationsEventArgs(IsReadyForCommunication));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,13 +17,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Generic secure TCP/IP server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpServer : Device
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic secure TCP/IP server
|
||||
/// </summary>
|
||||
public class GenericSecureTcpIpServer : Device
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Event for Receiving text
|
||||
@@ -58,7 +58,7 @@ namespace PepperDash.Core
|
||||
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for ServerHasChokedCallbackDelegate
|
||||
///
|
||||
/// </summary>
|
||||
public delegate void ServerHasChokedCallbackDelegate();
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace PepperDash.Core
|
||||
int MonitorClientFailureCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MonitorClientMaxFailureCount
|
||||
/// 3 by default
|
||||
/// </summary>
|
||||
public int MonitorClientMaxFailureCount { get; set; }
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port Server should listen on
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -223,7 +223,8 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKey
|
||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module.
|
||||
/// If SharedKey changes while server is listening or clients are connected, disconnect and stop listening will be called
|
||||
/// </summary>
|
||||
public string SharedKey { get; set; }
|
||||
|
||||
@@ -247,7 +248,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HeartbeatRequiredIntervalMs
|
||||
/// Milliseconds before server expects another heartbeat. Set by property HeartbeatRequiredIntervalInSeconds which is driven from S+
|
||||
/// </summary>
|
||||
public int HeartbeatRequiredIntervalMs { get; set; }
|
||||
|
||||
@@ -257,7 +258,7 @@ namespace PepperDash.Core
|
||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HeartbeatStringToMatch
|
||||
/// String to Match for heartbeat. If null or empty any string will reset heartbeat timer
|
||||
/// </summary>
|
||||
public string HeartbeatStringToMatch { get; set; }
|
||||
|
||||
@@ -275,7 +276,7 @@ namespace PepperDash.Core
|
||||
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BufferSize
|
||||
/// Defaults to 2000
|
||||
/// </summary>
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
@@ -338,7 +339,7 @@ namespace PepperDash.Core
|
||||
|
||||
#region Methods - Server Actions
|
||||
/// <summary>
|
||||
/// KillServer method
|
||||
/// Disconnects all clients and stops the server
|
||||
/// </summary>
|
||||
public void KillServer()
|
||||
{
|
||||
@@ -355,9 +356,6 @@ namespace PepperDash.Core
|
||||
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
Key = key;
|
||||
@@ -397,7 +395,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Listen method
|
||||
/// Start listening on the specified port
|
||||
/// </summary>
|
||||
public void Listen()
|
||||
{
|
||||
@@ -455,7 +453,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// StopListening method
|
||||
/// Stop Listeneing
|
||||
/// </summary>
|
||||
public void StopListening()
|
||||
{
|
||||
@@ -480,9 +478,6 @@ namespace PepperDash.Core
|
||||
/// Disconnects Client
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <summary>
|
||||
/// DisconnectClient method
|
||||
/// </summary>
|
||||
public void DisconnectClient(uint client)
|
||||
{
|
||||
try
|
||||
@@ -496,7 +491,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DisconnectAllClientsForShutdown method
|
||||
/// Disconnect All Clients
|
||||
/// </summary>
|
||||
public void DisconnectAllClientsForShutdown()
|
||||
{
|
||||
@@ -538,9 +533,6 @@ namespace PepperDash.Core
|
||||
/// Broadcast text from server to all connected clients
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <summary>
|
||||
/// BroadcastText method
|
||||
/// </summary>
|
||||
public void BroadcastText(string text)
|
||||
{
|
||||
CCriticalSection CCBroadcast = new CCriticalSection();
|
||||
@@ -574,9 +566,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="clientIndex"></param>
|
||||
/// <summary>
|
||||
/// SendTextToClient method
|
||||
/// </summary>
|
||||
public void SendTextToClient(string text, uint clientIndex)
|
||||
{
|
||||
try
|
||||
@@ -645,9 +634,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="clientIndex"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetClientIPAddress method
|
||||
/// </summary>
|
||||
public string GetClientIPAddress(uint clientIndex)
|
||||
{
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
|
||||
@@ -1094,5 +1080,4 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Crestron.SimplSharp;
|
||||
@@ -9,15 +8,14 @@ using PepperDash.Core.Logging;
|
||||
using Renci.SshNet;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// SSH Client
|
||||
/// </summary>
|
||||
public class GenericSshClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
{
|
||||
private const string SPlusKey = "Uninitialized SshClient";
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GenericSshClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
{
|
||||
private const string SPlusKey = "Uninitialized SshClient";
|
||||
/// <summary>
|
||||
/// Object to enable stream debugging
|
||||
/// </summary>
|
||||
@@ -38,8 +36,13 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
|
||||
|
||||
///// <summary>
|
||||
/////
|
||||
///// </summary>
|
||||
//public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Hostname
|
||||
/// Address of server
|
||||
/// </summary>
|
||||
public string Hostname { get; set; }
|
||||
|
||||
@@ -49,12 +52,12 @@ namespace PepperDash.Core
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Username
|
||||
/// Username for server
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Password
|
||||
/// And... Password for server. That was worth documenting!
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
@@ -64,7 +67,7 @@ namespace PepperDash.Core
|
||||
public bool IsConnected
|
||||
{
|
||||
// returns false if no client or not connected
|
||||
get { return client != null && ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||
get { return Client != null && ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,30 +79,20 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Socket status change event
|
||||
///
|
||||
/// </summary>
|
||||
public SocketStatus ClientStatus
|
||||
{
|
||||
get { lock (_stateLock) { return _ClientStatus; } }
|
||||
get { return _ClientStatus; }
|
||||
private set
|
||||
{
|
||||
bool shouldFireEvent = false;
|
||||
lock (_stateLock)
|
||||
{
|
||||
if (_ClientStatus != value)
|
||||
{
|
||||
if (_ClientStatus == value)
|
||||
return;
|
||||
_ClientStatus = value;
|
||||
shouldFireEvent = true;
|
||||
}
|
||||
}
|
||||
// Fire event outside lock to avoid deadlock
|
||||
if (shouldFireEvent)
|
||||
OnConnectionChange();
|
||||
}
|
||||
}
|
||||
|
||||
private SocketStatus _ClientStatus;
|
||||
private bool _ConnectEnabled;
|
||||
SocketStatus _ClientStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
|
||||
@@ -107,7 +100,7 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public ushort UStatus
|
||||
{
|
||||
get { lock (_stateLock) { return (ushort)_ClientStatus; } }
|
||||
get { return (ushort)_ClientStatus; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,11 +111,7 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Will be set and unset by connect and disconnect only
|
||||
/// </summary>
|
||||
public bool ConnectEnabled
|
||||
{
|
||||
get { lock (_stateLock) { return _ConnectEnabled; } }
|
||||
private set { lock (_stateLock) { _ConnectEnabled = value; } }
|
||||
}
|
||||
public bool ConnectEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// S+ helper for AutoReconnect
|
||||
@@ -134,29 +123,22 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AutoReconnectIntervalMs
|
||||
/// Millisecond value, determines the timeout period in between reconnect attempts.
|
||||
/// Set to 5000 by default
|
||||
/// </summary>
|
||||
public int AutoReconnectIntervalMs { get; set; }
|
||||
|
||||
private SshClient client;
|
||||
SshClient Client;
|
||||
|
||||
private ShellStream shellStream;
|
||||
ShellStream TheStream;
|
||||
|
||||
private readonly Timer reconnectTimer;
|
||||
CTimer ReconnectTimer;
|
||||
|
||||
//Lock object to prevent simulatneous connect/disconnect operations
|
||||
//private CCriticalSection connectLock = new CCriticalSection();
|
||||
private readonly SemaphoreSlim connectLock = new SemaphoreSlim(1);
|
||||
private SemaphoreSlim connectLock = new SemaphoreSlim(1);
|
||||
|
||||
// Thread-safety lock for state changes
|
||||
private readonly object _stateLock = new object();
|
||||
|
||||
private bool disconnectLogged = false;
|
||||
|
||||
/// <summary>
|
||||
/// When true, turns off echo for the SSH session
|
||||
/// </summary>
|
||||
public bool DisableEcho { get; set; }
|
||||
private bool DisconnectLogged = false;
|
||||
|
||||
/// <summary>
|
||||
/// Typical constructor.
|
||||
@@ -173,13 +155,13 @@ namespace PepperDash.Core
|
||||
Password = password;
|
||||
AutoReconnectIntervalMs = 5000;
|
||||
|
||||
reconnectTimer = new Timer(o =>
|
||||
ReconnectTimer = new CTimer(o =>
|
||||
{
|
||||
if (ConnectEnabled) // Now thread-safe property access
|
||||
if (ConnectEnabled)
|
||||
{
|
||||
Connect();
|
||||
}
|
||||
}, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
|
||||
}, System.Threading.Timeout.Infinite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -191,23 +173,23 @@ namespace PepperDash.Core
|
||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||
AutoReconnectIntervalMs = 5000;
|
||||
|
||||
reconnectTimer = new Timer(o =>
|
||||
ReconnectTimer = new CTimer(o =>
|
||||
{
|
||||
if (ConnectEnabled) // Now thread-safe property access
|
||||
if (ConnectEnabled)
|
||||
{
|
||||
Connect();
|
||||
}
|
||||
}, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
|
||||
}, System.Threading.Timeout.Infinite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles closing this up when the program shuts down
|
||||
/// </summary>
|
||||
private void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
||||
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
||||
{
|
||||
if (programEventType == eProgramStatusEventType.Stopping)
|
||||
{
|
||||
if (client != null)
|
||||
if (Client != null)
|
||||
{
|
||||
this.LogDebug("Program stopping. Closing connection");
|
||||
Disconnect();
|
||||
@@ -216,7 +198,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Connect to the server, using the provided properties.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
@@ -242,10 +224,13 @@ namespace PepperDash.Core
|
||||
this.LogDebug("Attempting connect");
|
||||
|
||||
// Cancel reconnect if running.
|
||||
StopReconnectTimer();
|
||||
if (ReconnectTimer != null)
|
||||
{
|
||||
ReconnectTimer.Stop();
|
||||
}
|
||||
|
||||
// Cleanup the old client if it already exists
|
||||
if (client != null)
|
||||
if (Client != null)
|
||||
{
|
||||
this.LogDebug("Cleaning up disconnected client");
|
||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
||||
@@ -258,90 +243,77 @@ namespace PepperDash.Core
|
||||
|
||||
this.LogDebug("Creating new SshClient");
|
||||
ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
|
||||
client = new SshClient(connectionInfo);
|
||||
client.ErrorOccurred += Client_ErrorOccurred;
|
||||
Client = new SshClient(connectionInfo);
|
||||
Client.ErrorOccurred += Client_ErrorOccurred;
|
||||
|
||||
//Attempt to connect
|
||||
ClientStatus = SocketStatus.SOCKET_STATUS_WAITING;
|
||||
try
|
||||
{
|
||||
client.Connect();
|
||||
|
||||
var modes = new Dictionary<TerminalModes, uint>();
|
||||
|
||||
if (DisableEcho)
|
||||
{
|
||||
modes.Add(TerminalModes.ECHO, 0);
|
||||
}
|
||||
|
||||
shellStream = client.CreateShellStream("PDTShell", 0, 0, 0, 0, 65534, modes);
|
||||
if (shellStream.DataAvailable)
|
||||
Client.Connect();
|
||||
TheStream = Client.CreateShellStream("PDTShell", 0, 0, 0, 0, 65534);
|
||||
if (TheStream.DataAvailable)
|
||||
{
|
||||
// empty the buffer if there is data
|
||||
shellStream.Read();
|
||||
string str = TheStream.Read();
|
||||
}
|
||||
shellStream.DataReceived += Stream_DataReceived;
|
||||
TheStream.DataReceived += Stream_DataReceived;
|
||||
this.LogInformation("Connected");
|
||||
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
||||
disconnectLogged = false;
|
||||
DisconnectLogged = false;
|
||||
}
|
||||
catch (SshConnectionException e)
|
||||
{
|
||||
var ie = e.InnerException; // The details are inside!!
|
||||
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
|
||||
|
||||
if (ie is SocketException)
|
||||
{
|
||||
this.LogError("CONNECTION failure: Cannot reach host");
|
||||
this.LogVerbose(ie, "Exception details: ");
|
||||
this.LogException(ie, "CONNECTION failure: Cannot reach host");
|
||||
}
|
||||
|
||||
if (ie is System.Net.Sockets.SocketException socketException)
|
||||
{
|
||||
this.LogError("Connection failure: Cannot reach {host} on {port}",
|
||||
this.LogException(ie, "Connection failure: Cannot reach {host} on {port}",
|
||||
Hostname, Port);
|
||||
this.LogVerbose(socketException, "SocketException details: ");
|
||||
}
|
||||
if (ie is SshAuthenticationException)
|
||||
{
|
||||
this.LogError("Authentication failure for username {userName}", Username);
|
||||
this.LogVerbose(ie, "AuthenticationException details: ");
|
||||
this.LogException(ie, "Authentication failure for username {userName}", Username);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LogError("Error on connect: {error}", ie.Message);
|
||||
this.LogVerbose(ie, "Exception details: ");
|
||||
}
|
||||
this.LogException(ie, "Error on connect");
|
||||
|
||||
disconnectLogged = true;
|
||||
DisconnectLogged = true;
|
||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||
if (AutoReconnect)
|
||||
{
|
||||
this.LogDebug("Checking autoreconnect: {autoReconnect}, {autoReconnectInterval}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
||||
}
|
||||
}
|
||||
catch (SshOperationTimeoutException ex)
|
||||
catch(SshOperationTimeoutException ex)
|
||||
{
|
||||
this.LogWarning("Connection attempt timed out: {message}", ex.Message);
|
||||
|
||||
disconnectLogged = true;
|
||||
DisconnectLogged = true;
|
||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||
if (AutoReconnect)
|
||||
{
|
||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.LogError("Unhandled exception on connect: {error}", e.Message);
|
||||
this.LogVerbose(e, "Exception details: ");
|
||||
disconnectLogged = true;
|
||||
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
|
||||
this.LogException(e, "Unhandled exception on connect");
|
||||
DisconnectLogged = true;
|
||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||
if (AutoReconnect)
|
||||
{
|
||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,13 +325,17 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
/// Disconnect the clients and put away it's resources.
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
ConnectEnabled = false;
|
||||
// Stop trying reconnects, if we are
|
||||
StopReconnectTimer();
|
||||
if (ReconnectTimer != null)
|
||||
{
|
||||
ReconnectTimer.Stop();
|
||||
// ReconnectTimer = null;
|
||||
}
|
||||
|
||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
||||
}
|
||||
@@ -373,35 +349,35 @@ namespace PepperDash.Core
|
||||
|
||||
try
|
||||
{
|
||||
if (client != null)
|
||||
if (Client != null)
|
||||
{
|
||||
client.ErrorOccurred -= Client_ErrorOccurred;
|
||||
client.Disconnect();
|
||||
client.Dispose();
|
||||
client = null;
|
||||
Client.ErrorOccurred -= Client_ErrorOccurred;
|
||||
Client.Disconnect();
|
||||
Client.Dispose();
|
||||
Client = null;
|
||||
ClientStatus = status;
|
||||
this.LogDebug("Disconnected");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogException(ex, "Exception in Kill Client");
|
||||
this.LogException(ex,"Exception in Kill Client");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kills the stream
|
||||
/// </summary>
|
||||
private void KillStream()
|
||||
void KillStream()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (shellStream != null)
|
||||
if (TheStream != null)
|
||||
{
|
||||
shellStream.DataReceived -= Stream_DataReceived;
|
||||
shellStream.Close();
|
||||
shellStream.Dispose();
|
||||
shellStream = null;
|
||||
TheStream.DataReceived -= Stream_DataReceived;
|
||||
TheStream.Close();
|
||||
TheStream.Dispose();
|
||||
TheStream = null;
|
||||
this.LogDebug("Disconnected stream");
|
||||
}
|
||||
}
|
||||
@@ -414,7 +390,7 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Handles the keyboard interactive authentication, should it be required.
|
||||
/// </summary>
|
||||
private void kauth_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
|
||||
void kauth_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
|
||||
{
|
||||
foreach (AuthenticationPrompt prompt in e.Prompts)
|
||||
if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
|
||||
@@ -424,7 +400,7 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Handler for data receive on ShellStream. Passes data across to queue for line parsing.
|
||||
/// </summary>
|
||||
private void Stream_DataReceived(object sender, ShellDataEventArgs e)
|
||||
void Stream_DataReceived(object sender, ShellDataEventArgs e)
|
||||
{
|
||||
if (((ShellStream)sender).Length <= 0L)
|
||||
{
|
||||
@@ -437,14 +413,18 @@ namespace PepperDash.Core
|
||||
if (bytesHandler != null)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(response);
|
||||
this.PrintReceivedBytes(bytes);
|
||||
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)
|
||||
{
|
||||
this.PrintReceivedText(response);
|
||||
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||
this.LogInformation("Received: '{0}'", ComTextHelper.GetDebugText(response));
|
||||
|
||||
textHandler(this, new GenericCommMethodReceiveTextArgs(response));
|
||||
}
|
||||
@@ -456,7 +436,7 @@ namespace PepperDash.Core
|
||||
/// Error event handler for client events - disconnect, etc. Will forward those events via ConnectionChange
|
||||
/// event
|
||||
/// </summary>
|
||||
private void Client_ErrorOccurred(object sender, ExceptionEventArgs e)
|
||||
void Client_ErrorOccurred(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
CrestronInvoke.BeginInvoke(o =>
|
||||
{
|
||||
@@ -476,7 +456,7 @@ namespace PepperDash.Core
|
||||
if (AutoReconnect && ConnectEnabled)
|
||||
{
|
||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -484,9 +464,10 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Helper for ConnectionChange event
|
||||
/// </summary>
|
||||
private void OnConnectionChange()
|
||||
void OnConnectionChange()
|
||||
{
|
||||
ConnectionChange?.Invoke(this, new GenericSocketStatusChageEventArgs(this));
|
||||
if (ConnectionChange != null)
|
||||
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
|
||||
}
|
||||
|
||||
#region IBasicCommunication Members
|
||||
@@ -494,17 +475,21 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Sends text to the server
|
||||
/// </summary>
|
||||
/// <param name="text">The text to send</param>
|
||||
/// <param name="text"></param>
|
||||
public void SendText(string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (client != null && shellStream != null && IsConnected)
|
||||
if (Client != null && TheStream != null && IsConnected)
|
||||
{
|
||||
this.PrintSentText(text);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
this.LogInformation(
|
||||
"Sending {length} characters of text: '{text}'",
|
||||
text.Length,
|
||||
ComTextHelper.GetDebugText(text));
|
||||
|
||||
shellStream.Write(text);
|
||||
shellStream.Flush();
|
||||
TheStream.Write(text);
|
||||
TheStream.Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -516,7 +501,7 @@ namespace PepperDash.Core
|
||||
this.LogError("ObjectDisposedException sending '{message}'. Restarting connection...", text.Trim());
|
||||
|
||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -527,17 +512,18 @@ namespace PepperDash.Core
|
||||
/// <summary>
|
||||
/// Sends Bytes to the server
|
||||
/// </summary>
|
||||
/// <param name="bytes">The bytes to send</param>
|
||||
/// <param name="bytes"></param>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (client != null && shellStream != null && IsConnected)
|
||||
if (Client != null && TheStream != null && IsConnected)
|
||||
{
|
||||
this.PrintSentBytes(bytes);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
this.LogInformation("Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
||||
|
||||
shellStream.Write(bytes, 0, bytes.Length);
|
||||
shellStream.Flush();
|
||||
TheStream.Write(bytes, 0, bytes.Length);
|
||||
TheStream.Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -549,100 +535,23 @@ namespace PepperDash.Core
|
||||
this.LogException(ex, "ObjectDisposedException sending {message}", ComTextHelper.GetEscapedText(bytes));
|
||||
|
||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||
StartReconnectTimer();
|
||||
ReconnectTimer.Reset();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogException(ex, "Exception sending {message}", ComTextHelper.GetEscapedText(bytes));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Safely starts the reconnect timer with exception handling
|
||||
/// </summary>
|
||||
private void StartReconnectTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
reconnectTimer?.Change(AutoReconnectIntervalMs, System.Threading.Timeout.Infinite);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// Timer was disposed, ignore
|
||||
this.LogDebug("Attempted to start timer but it was already disposed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safely stops the reconnect timer with exception handling
|
||||
/// </summary>
|
||||
private void StopReconnectTimer()
|
||||
{
|
||||
try
|
||||
{
|
||||
reconnectTimer?.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// Timer was disposed, ignore
|
||||
this.LogDebug("Attempted to stop timer but it was already disposed");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivate method - properly dispose of resources
|
||||
/// </summary>
|
||||
public override bool Deactivate()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.LogDebug("Deactivating SSH client - disposing resources");
|
||||
|
||||
// Stop trying reconnects
|
||||
ConnectEnabled = false;
|
||||
StopReconnectTimer();
|
||||
|
||||
// Disconnect and cleanup client
|
||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
||||
|
||||
// Dispose timer
|
||||
try
|
||||
{
|
||||
reconnectTimer?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// Already disposed, ignore
|
||||
}
|
||||
|
||||
// Dispose semaphore
|
||||
try
|
||||
{
|
||||
connectLock?.Dispose();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// Already disposed, ignore
|
||||
}
|
||||
|
||||
return base.Deactivate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogException(ex, "Error during SSH client deactivation");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*****************************************************************************************************
|
||||
//*****************************************************************************************************
|
||||
/// <summary>
|
||||
/// Represents a SshConnectionChangeEventArgs
|
||||
/// </summary>
|
||||
public class SshConnectionChangeEventArgs : EventArgs
|
||||
//*****************************************************************************************************
|
||||
//*****************************************************************************************************
|
||||
/// <summary>
|
||||
/// Fired when connection changes
|
||||
/// </summary>
|
||||
public class SshConnectionChangeEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection State
|
||||
@@ -650,17 +559,17 @@ namespace PepperDash.Core
|
||||
public bool IsConnected { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the UIsConnected
|
||||
/// Connection Status represented as a ushort
|
||||
/// </summary>
|
||||
public ushort UIsConnected { get { return (ushort)(Client.IsConnected ? 1 : 0); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Client
|
||||
/// The client
|
||||
/// </summary>
|
||||
public GenericSshClient Client { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Status
|
||||
/// Socket Status as represented by
|
||||
/// </summary>
|
||||
public ushort Status { get { return Client.UStatus; } }
|
||||
|
||||
@@ -679,5 +588,4 @@ namespace PepperDash.Core
|
||||
IsConnected = isConnected;
|
||||
Client = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A class to handle basic TCP/IP communications with a server
|
||||
/// </summary>
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// A class to handle basic TCP/IP communications with a server
|
||||
/// </summary>
|
||||
public class GenericTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
|
||||
{
|
||||
{
|
||||
private const string SplusKey = "Uninitialized TcpIpClient";
|
||||
/// <summary>
|
||||
/// Object to enable stream debugging
|
||||
@@ -59,7 +59,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port on server
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace PepperDash.Core
|
||||
public string ConnectionFailure { get { return ClientStatus.ToString(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AutoReconnect
|
||||
/// bool to track if auto reconnect should be set on the socket
|
||||
/// </summary>
|
||||
public bool AutoReconnect { get; set; }
|
||||
|
||||
@@ -232,7 +232,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// Just to help S+ set the key
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
@@ -255,9 +255,6 @@ namespace PepperDash.Core
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// Deactivate method
|
||||
/// </summary>
|
||||
public override bool Deactivate()
|
||||
{
|
||||
RetryTimer.Stop();
|
||||
@@ -271,7 +268,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Attempts to connect to the server
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
@@ -338,7 +335,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
/// Attempts to disconnect the client
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
@@ -358,7 +355,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DisconnectClient method
|
||||
/// Does the actual disconnect business
|
||||
/// </summary>
|
||||
public void DisconnectClient()
|
||||
{
|
||||
@@ -426,7 +423,10 @@ namespace PepperDash.Core
|
||||
var bytesHandler = BytesReceived;
|
||||
if (bytesHandler != null)
|
||||
{
|
||||
this.PrintReceivedBytes(bytes);
|
||||
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||
{
|
||||
Debug.Console(0, this, "Received {1} bytes: '{0}'", ComTextHelper.GetEscapedText(bytes), bytes.Length);
|
||||
}
|
||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||
}
|
||||
var textHandler = TextReceived;
|
||||
@@ -434,7 +434,10 @@ namespace PepperDash.Core
|
||||
{
|
||||
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
||||
|
||||
this.PrintReceivedText(str);
|
||||
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||
{
|
||||
Debug.Console(0, this, "Received {1} characters of text: '{0}'", ComTextHelper.GetDebugText(str), str.Length);
|
||||
}
|
||||
|
||||
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
||||
}
|
||||
@@ -444,19 +447,20 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendText method
|
||||
/// General send method
|
||||
/// </summary>
|
||||
public void SendText(string text)
|
||||
{
|
||||
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
||||
// Check debug level before processing byte array
|
||||
this.PrintSentText(text);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
|
||||
if (_client != null)
|
||||
_client.SendData(bytes, bytes.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendEscapedText method
|
||||
/// This is useful from console and...?
|
||||
/// </summary>
|
||||
public void SendEscapedText(string text)
|
||||
{
|
||||
@@ -472,12 +476,10 @@ namespace PepperDash.Core
|
||||
/// Sends Bytes to the server
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <summary>
|
||||
/// SendBytes method
|
||||
/// </summary>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
this.PrintSentBytes(bytes);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
||||
if (_client != null)
|
||||
_client.SendData(bytes, bytes.Length);
|
||||
}
|
||||
@@ -506,9 +508,9 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a TcpSshPropertiesConfig
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Configuration properties for TCP/SSH Connections
|
||||
/// </summary>
|
||||
public class TcpSshPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
@@ -528,7 +530,7 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the Password
|
||||
/// Passord credential
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
@@ -538,21 +540,15 @@ namespace PepperDash.Core
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AutoReconnect
|
||||
/// Defaults to true
|
||||
/// </summary>
|
||||
public bool AutoReconnect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AutoReconnectIntervalMs
|
||||
/// Defaults to 5000ms
|
||||
/// </summary>
|
||||
public int AutoReconnectIntervalMs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When true, turns off echo for the SSH session
|
||||
/// </summary>
|
||||
[JsonProperty("disableSshEcho")]
|
||||
public bool DisableSshEcho { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
@@ -563,7 +559,6 @@ namespace PepperDash.Core
|
||||
AutoReconnectIntervalMs = 5000;
|
||||
Username = "";
|
||||
Password = "";
|
||||
DisableSshEcho = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Generic TCP/IP client for server
|
||||
/// </summary>
|
||||
public class GenericTcpIpClient_ForServer : Device, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic TCP/IP client for server
|
||||
/// </summary>
|
||||
public class GenericTcpIpClient_ForServer : Device, IAutoReconnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Band aid delegate for choked server
|
||||
/// </summary>
|
||||
@@ -69,7 +69,7 @@ namespace PepperDash.Core
|
||||
public string Hostname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port on server
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKey
|
||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module
|
||||
/// </summary>
|
||||
public string SharedKey { get; set; }
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace PepperDash.Core
|
||||
private bool WaitingForSharedKeyResponse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BufferSize
|
||||
/// Defaults to 2000
|
||||
/// </summary>
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace PepperDash.Core
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// Just to help S+ set the key
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
@@ -311,7 +311,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
@@ -442,7 +442,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
///
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
@@ -669,7 +669,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendText method
|
||||
/// General send method
|
||||
/// </summary>
|
||||
public void SendText(string text)
|
||||
{
|
||||
@@ -698,7 +698,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SendBytes method
|
||||
///
|
||||
/// </summary>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
@@ -770,6 +770,4 @@ namespace PepperDash.Core
|
||||
handler(this, new GenericTcpServerClientReadyForcommunicationsEventArgs(IsReadyForCommunication));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,13 +17,13 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Generic TCP/IP server device
|
||||
/// </summary>
|
||||
public class GenericTcpIpServer : Device
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic TCP/IP server device
|
||||
/// </summary>
|
||||
public class GenericTcpIpServer : Device
|
||||
{
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Event for Receiving text
|
||||
@@ -52,7 +52,7 @@ namespace PepperDash.Core
|
||||
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for ServerHasChokedCallbackDelegate
|
||||
///
|
||||
/// </summary>
|
||||
public delegate void ServerHasChokedCallbackDelegate();
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace PepperDash.Core
|
||||
int MonitorClientFailureCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MonitorClientMaxFailureCount
|
||||
/// 3 by default
|
||||
/// </summary>
|
||||
public int MonitorClientMaxFailureCount { get; set; }
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Port
|
||||
/// Port Server should listen on
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
@@ -204,7 +204,8 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SharedKey
|
||||
/// SharedKey is sent for varification to the server. Shared key can be any text (255 char limit in SIMPL+ Module), but must match the Shared Key on the Server module.
|
||||
/// If SharedKey changes while server is listening or clients are connected, disconnect and stop listening will be called
|
||||
/// </summary>
|
||||
public string SharedKey { get; set; }
|
||||
|
||||
@@ -228,7 +229,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HeartbeatRequiredIntervalMs
|
||||
/// Milliseconds before server expects another heartbeat. Set by property HeartbeatRequiredIntervalInSeconds which is driven from S+
|
||||
/// </summary>
|
||||
public int HeartbeatRequiredIntervalMs { get; set; }
|
||||
|
||||
@@ -238,7 +239,7 @@ namespace PepperDash.Core
|
||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HeartbeatStringToMatch
|
||||
/// String to Match for heartbeat. If null or empty any string will reset heartbeat timer
|
||||
/// </summary>
|
||||
public string HeartbeatStringToMatch { get; set; }
|
||||
|
||||
@@ -256,7 +257,7 @@ namespace PepperDash.Core
|
||||
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BufferSize
|
||||
/// Defaults to 2000
|
||||
/// </summary>
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
@@ -319,7 +320,7 @@ namespace PepperDash.Core
|
||||
|
||||
#region Methods - Server Actions
|
||||
/// <summary>
|
||||
/// KillServer method
|
||||
/// Disconnects all clients and stops the server
|
||||
/// </summary>
|
||||
public void KillServer()
|
||||
{
|
||||
@@ -336,9 +337,6 @@ namespace PepperDash.Core
|
||||
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// </summary>
|
||||
public void Initialize(string key)
|
||||
{
|
||||
Key = key;
|
||||
@@ -377,7 +375,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Listen method
|
||||
/// Start listening on the specified port
|
||||
/// </summary>
|
||||
public void Listen()
|
||||
{
|
||||
@@ -434,7 +432,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// StopListening method
|
||||
/// Stop Listening
|
||||
/// </summary>
|
||||
public void StopListening()
|
||||
{
|
||||
@@ -459,9 +457,6 @@ namespace PepperDash.Core
|
||||
/// Disconnects Client
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <summary>
|
||||
/// DisconnectClient method
|
||||
/// </summary>
|
||||
public void DisconnectClient(uint client)
|
||||
{
|
||||
try
|
||||
@@ -475,7 +470,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DisconnectAllClientsForShutdown method
|
||||
/// Disconnect All Clients
|
||||
/// </summary>
|
||||
public void DisconnectAllClientsForShutdown()
|
||||
{
|
||||
@@ -517,9 +512,6 @@ namespace PepperDash.Core
|
||||
/// Broadcast text from server to all connected clients
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <summary>
|
||||
/// BroadcastText method
|
||||
/// </summary>
|
||||
public void BroadcastText(string text)
|
||||
{
|
||||
CCriticalSection CCBroadcast = new CCriticalSection();
|
||||
@@ -553,9 +545,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="clientIndex"></param>
|
||||
/// <summary>
|
||||
/// SendTextToClient method
|
||||
/// </summary>
|
||||
public void SendTextToClient(string text, uint clientIndex)
|
||||
{
|
||||
try
|
||||
@@ -624,9 +613,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="clientIndex"></param>
|
||||
/// <returns>IP address of the client</returns>
|
||||
/// <summary>
|
||||
/// GetClientIPAddress method
|
||||
/// </summary>
|
||||
public string GetClientIPAddress(uint clientIndex)
|
||||
{
|
||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
|
||||
@@ -1021,5 +1007,4 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ using Crestron.SimplSharp.CrestronSockets;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Logging;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Generic UDP Server device
|
||||
/// </summary>
|
||||
public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic UDP Server device
|
||||
/// </summary>
|
||||
public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging
|
||||
{
|
||||
private const string SplusKey = "Uninitialized Udp Server";
|
||||
/// <summary>
|
||||
/// Object to enable stream debugging
|
||||
@@ -131,14 +131,14 @@ namespace PepperDash.Core
|
||||
/// <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)
|
||||
/// <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 = bufferSize;
|
||||
BufferSize = buffefSize;
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||
@@ -150,9 +150,6 @@ namespace PepperDash.Core
|
||||
/// <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;
|
||||
@@ -188,29 +185,15 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect method
|
||||
/// Enables the UDP Server
|
||||
/// </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);
|
||||
@@ -239,11 +222,11 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect method
|
||||
/// Disabled the UDP Server
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
if (Server != null)
|
||||
if(Server != null)
|
||||
Server.DisableUDPServer();
|
||||
|
||||
IsConnected = false;
|
||||
@@ -281,13 +264,17 @@ namespace PepperDash.Core
|
||||
var bytesHandler = BytesReceived;
|
||||
if (bytesHandler != null)
|
||||
{
|
||||
this.PrintReceivedBytes(bytes);
|
||||
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||
{
|
||||
Debug.Console(0, this, "Received {1} bytes: '{0}'", ComTextHelper.GetEscapedText(bytes), bytes.Length);
|
||||
}
|
||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||
}
|
||||
var textHandler = TextReceived;
|
||||
if (textHandler != null)
|
||||
{
|
||||
this.PrintReceivedText(str);
|
||||
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||
Debug.Console(0, this, "Received {1} characters of text: '{0}'", ComTextHelper.GetDebugText(str), str.Length);
|
||||
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
||||
}
|
||||
}
|
||||
@@ -305,16 +292,14 @@ namespace PepperDash.Core
|
||||
/// 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);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
|
||||
|
||||
Server.SendData(bytes, bytes.Length);
|
||||
}
|
||||
@@ -324,22 +309,20 @@ namespace PepperDash.Core
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <summary>
|
||||
/// SendBytes method
|
||||
/// </summary>
|
||||
public void SendBytes(byte[] bytes)
|
||||
{
|
||||
this.PrintSentBytes(bytes);
|
||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||
Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
||||
|
||||
if (IsConnected && Server != null)
|
||||
Server.SendData(bytes, bytes.Length);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a GenericUdpReceiveTextExtraArgs
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GenericUdpReceiveTextExtraArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
@@ -380,11 +363,11 @@ namespace PepperDash.Core
|
||||
public GenericUdpReceiveTextExtraArgs() { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class UdpServerPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class UdpServerPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -409,5 +392,4 @@ namespace PepperDash.Core
|
||||
{
|
||||
BufferSize = 32768;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for stream debugging
|
||||
/// </summary>
|
||||
public static class StreamDebuggingExtensions
|
||||
{
|
||||
private static readonly string app = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance ? $"App {InitialParametersClass.ApplicationNumber}" : $"{InitialParametersClass.RoomId}";
|
||||
|
||||
/// <summary>
|
||||
/// Print the sent bytes to the console
|
||||
/// </summary>
|
||||
/// <param name="comms">comms device</param>
|
||||
/// <param name="bytes">bytes to print</param>
|
||||
public static void PrintSentBytes(this IStreamDebugging comms, byte[] bytes)
|
||||
{
|
||||
if (!comms.StreamDebugging.TxStreamDebuggingIsEnabled) return;
|
||||
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
CrestronConsole.PrintLine($"[{timestamp}][{app}][{comms.Key}] Sending {bytes.Length} bytes: '{ComTextHelper.GetEscapedText(bytes)}'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print the received bytes to the console
|
||||
/// </summary>
|
||||
/// <param name="comms">comms device</param>
|
||||
/// <param name="bytes">bytes to print</param>
|
||||
public static void PrintReceivedBytes(this IStreamDebugging comms, byte[] bytes)
|
||||
{
|
||||
if (!comms.StreamDebugging.RxStreamDebuggingIsEnabled) return;
|
||||
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
CrestronConsole.PrintLine($"[{timestamp}][{app}][{comms.Key}] Received {bytes.Length} bytes: '{ComTextHelper.GetEscapedText(bytes)}'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print the sent text to the console
|
||||
/// </summary>
|
||||
/// <param name="comms">comms device</param>
|
||||
/// <param name="text">text to print</param>
|
||||
public static void PrintSentText(this IStreamDebugging comms, string text)
|
||||
{
|
||||
if (!comms.StreamDebugging.TxStreamDebuggingIsEnabled) return;
|
||||
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
CrestronConsole.PrintLine($"[{timestamp}][{app}][{comms.Key}] Sending Text: '{ComTextHelper.GetDebugText(text)}'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print the received text to the console
|
||||
/// </summary>
|
||||
/// <param name="comms">comms device</param>
|
||||
/// <param name="text">text to print</param>
|
||||
public static void PrintReceivedText(this IStreamDebugging comms, string text)
|
||||
{
|
||||
if (!comms.StreamDebugging.RxStreamDebuggingIsEnabled) return;
|
||||
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
CrestronConsole.PrintLine($"[{timestamp}][{app}][{comms.Key}] Received Text: '{ComTextHelper.GetDebugText(text)}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Core
|
||||
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
|
||||
/// </summary>
|
||||
public class TcpClientConfigObject
|
||||
{
|
||||
/// <summary>
|
||||
/// TcpSsh Properties
|
||||
/// </summary>
|
||||
@@ -55,5 +55,4 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
[JsonProperty("receiveQueueSize")]
|
||||
public int ReceiveQueueSize { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ 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
|
||||
/// </summary>
|
||||
public class TcpServerConfigObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Uique key
|
||||
/// </summary>
|
||||
@@ -56,5 +56,4 @@ namespace PepperDash.Core
|
||||
/// Receive Queue size must be greater than 20 or defaults to 20
|
||||
/// </summary>
|
||||
public int ReceiveQueueSize { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ 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>
|
||||
@@ -74,14 +74,5 @@ namespace PepperDash.Core
|
||||
/// <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
|
||||
}
|
||||
SecureTcpIp
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// The available settings for stream debugging data format types
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum eStreamDebuggingDataTypeSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug data in byte format
|
||||
/// </summary>
|
||||
Bytes = 0,
|
||||
/// <summary>
|
||||
/// Debug data in text format
|
||||
/// </summary>
|
||||
Text = 1,
|
||||
/// <summary>
|
||||
/// Debug data in both byte and text formats
|
||||
/// </summary>
|
||||
Both = Bytes | Text
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronSockets;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// An incoming communication stream
|
||||
/// </summary>
|
||||
public interface ICommunicationReceiver : IKeyed
|
||||
{
|
||||
/// <summary>
|
||||
/// An incoming communication stream
|
||||
/// </summary>
|
||||
public interface ICommunicationReceiver : IKeyed
|
||||
{
|
||||
/// <summary>
|
||||
/// Notifies of bytes received
|
||||
/// </summary>
|
||||
@@ -33,12 +36,12 @@ namespace PepperDash.Core
|
||||
/// Disconnect from the device
|
||||
/// </summary>
|
||||
void Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the contract for IBasicCommunication
|
||||
/// Represents a device that uses basic connection
|
||||
/// </summary>
|
||||
public interface IBasicCommunication : ICommunicationReceiver
|
||||
public interface IBasicCommunication : ICommunicationReceiver
|
||||
{
|
||||
/// <summary>
|
||||
/// Send text to the device
|
||||
@@ -53,25 +56,25 @@ namespace PepperDash.Core
|
||||
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
|
||||
/// </summary>
|
||||
public interface IStreamDebugging
|
||||
{
|
||||
/// <summary>
|
||||
/// Object to enable stream debugging
|
||||
/// </summary>
|
||||
[JsonProperty("streamDebugging")]
|
||||
CommunicationStreamDebugging StreamDebugging { get; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For IBasicCommunication classes that have SocketStatus. GenericSshClient,
|
||||
@@ -92,17 +95,17 @@ namespace PepperDash.Core
|
||||
SocketStatus ClientStatus { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a device that implements ISocketStatus and IStreamDebugging
|
||||
/// </summary>
|
||||
public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging
|
||||
{
|
||||
/// <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>
|
||||
@@ -145,7 +148,7 @@ namespace PepperDash.Core
|
||||
public class GenericCommMethodReceiveBytesArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Bytes
|
||||
///
|
||||
/// </summary>
|
||||
public byte[] Bytes { get; private set; }
|
||||
|
||||
@@ -192,7 +195,7 @@ namespace PepperDash.Core
|
||||
/// <param name="text"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
|
||||
: this(text)
|
||||
:this(text)
|
||||
{
|
||||
Delimiter = delimiter;
|
||||
}
|
||||
@@ -202,4 +205,42 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public GenericCommMethodReceiveTextArgs() { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </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));
|
||||
}
|
||||
}
|
||||
@@ -7,32 +7,13 @@ using Newtonsoft.Json.Linq;
|
||||
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";
|
||||
const string system = "system";
|
||||
const string systemUrl = "system_url";
|
||||
const string templateUrl = "template_url";
|
||||
const string info = "info";
|
||||
const string devices = "devices";
|
||||
const string rooms = "rooms";
|
||||
const string sourceLists = "sourceLists";
|
||||
const string destinationLists = "destinationLists";
|
||||
const string cameraLists = "cameraLists";
|
||||
const string audioControlPointLists = "audioControlPointLists";
|
||||
|
||||
const string tieLines = "tieLines";
|
||||
const string joinMaps = "joinMaps";
|
||||
const string global = "global";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads the config file, checks if it needs a merge, merges and saves, then returns the merged Object.
|
||||
/// </summary>
|
||||
@@ -43,25 +24,25 @@ namespace PepperDash.Core.Config
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Debug.LogError(
|
||||
Debug.Console(1, Debug.ErrorLogLevel.Error,
|
||||
"ERROR: Configuration file not present. Please load file to {0} and reset program", filePath);
|
||||
}
|
||||
|
||||
using (StreamReader fs = new StreamReader(filePath))
|
||||
{
|
||||
var jsonObj = JObject.Parse(fs.ReadToEnd());
|
||||
if(jsonObj[template] != null && jsonObj[system] != null)
|
||||
if(jsonObj["template"] != null && jsonObj["system"] != null)
|
||||
{
|
||||
// it's a double-config, merge it.
|
||||
var merged = MergeConfigs(jsonObj);
|
||||
if (jsonObj[systemUrl] != null)
|
||||
if (jsonObj["system_url"] != null)
|
||||
{
|
||||
merged[systemUrl] = jsonObj[systemUrl].Value<string>();
|
||||
merged["systemUrl"] = jsonObj["system_url"].Value<string>();
|
||||
}
|
||||
|
||||
if (jsonObj[templateUrl] != null)
|
||||
if (jsonObj["template_url"] != null)
|
||||
{
|
||||
merged[templateUrl] = jsonObj[templateUrl].Value<string>();
|
||||
merged["templateUrl"] = jsonObj["template_url"].Value<string>();
|
||||
}
|
||||
|
||||
jsonObj = merged;
|
||||
@@ -86,9 +67,6 @@ namespace PepperDash.Core.Config
|
||||
/// </summary>
|
||||
/// <param name="doubleConfig"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// MergeConfigs method
|
||||
/// </summary>
|
||||
public static JObject MergeConfigs(JObject doubleConfig)
|
||||
{
|
||||
var system = JObject.FromObject(doubleConfig["system"]);
|
||||
@@ -96,62 +74,62 @@ namespace PepperDash.Core.Config
|
||||
var merged = new JObject();
|
||||
|
||||
// Put together top-level objects
|
||||
if (system[info] != null)
|
||||
merged.Add(info, Merge(template[info], system[info], info));
|
||||
if (system["info"] != null)
|
||||
merged.Add("info", Merge(template["info"], system["info"], "infO"));
|
||||
else
|
||||
merged.Add(info, template[info]);
|
||||
merged.Add("info", template["info"]);
|
||||
|
||||
merged.Add(devices, MergeArraysOnTopLevelProperty(template[devices] as JArray,
|
||||
system[devices] as JArray, "key", devices));
|
||||
merged.Add("devices", MergeArraysOnTopLevelProperty(template["devices"] as JArray,
|
||||
system["devices"] as JArray, "key", "devices"));
|
||||
|
||||
if (system[rooms] == null)
|
||||
merged.Add(rooms, template[rooms]);
|
||||
if (system["rooms"] == null)
|
||||
merged.Add("rooms", template["rooms"]);
|
||||
else
|
||||
merged.Add(rooms, MergeArraysOnTopLevelProperty(template[rooms] as JArray,
|
||||
system[rooms] as JArray, "key", rooms));
|
||||
merged.Add("rooms", MergeArraysOnTopLevelProperty(template["rooms"] as JArray,
|
||||
system["rooms"] as JArray, "key", "rooms"));
|
||||
|
||||
if (system[sourceLists] == null)
|
||||
merged.Add(sourceLists, template[sourceLists]);
|
||||
if (system["sourceLists"] == null)
|
||||
merged.Add("sourceLists", template["sourceLists"]);
|
||||
else
|
||||
merged.Add(sourceLists, Merge(template[sourceLists], system[sourceLists], sourceLists));
|
||||
merged.Add("sourceLists", Merge(template["sourceLists"], system["sourceLists"], "sourceLists"));
|
||||
|
||||
if (system[destinationLists] == null)
|
||||
merged.Add(destinationLists, template[destinationLists]);
|
||||
if (system["destinationLists"] == null)
|
||||
merged.Add("destinationLists", template["destinationLists"]);
|
||||
else
|
||||
merged.Add(destinationLists,
|
||||
Merge(template[destinationLists], system[destinationLists], destinationLists));
|
||||
merged.Add("destinationLists",
|
||||
Merge(template["destinationLists"], system["destinationLists"], "destinationLists"));
|
||||
|
||||
|
||||
if (system[cameraLists] == null)
|
||||
merged.Add(cameraLists, template[cameraLists]);
|
||||
if (system["cameraLists"] == null)
|
||||
merged.Add("cameraLists", template["cameraLists"]);
|
||||
else
|
||||
merged.Add(cameraLists, Merge(template[cameraLists], system[cameraLists], cameraLists));
|
||||
merged.Add("cameraLists", Merge(template["cameraLists"], system["cameraLists"], "cameraLists"));
|
||||
|
||||
if (system[audioControlPointLists] == null)
|
||||
merged.Add(audioControlPointLists, template[audioControlPointLists]);
|
||||
if (system["audioControlPointLists"] == null)
|
||||
merged.Add("audioControlPointLists", template["audioControlPointLists"]);
|
||||
else
|
||||
merged.Add(audioControlPointLists,
|
||||
Merge(template[audioControlPointLists], system[audioControlPointLists], audioControlPointLists));
|
||||
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]);
|
||||
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());
|
||||
merged.Add("tieLines", new JArray());
|
||||
|
||||
if (template[joinMaps] != null)
|
||||
merged.Add(joinMaps, template[joinMaps]);
|
||||
if (template["joinMaps"] != null)
|
||||
merged.Add("joinMaps", template["joinMaps"]);
|
||||
else
|
||||
merged.Add(joinMaps, new JObject());
|
||||
merged.Add("joinMaps", new JObject());
|
||||
|
||||
if (system[global] != null)
|
||||
merged.Add(global, Merge(template[global], system[global], global));
|
||||
if (system["global"] != null)
|
||||
merged.Add("global", Merge(template["global"], system["global"], "global"));
|
||||
else
|
||||
merged.Add(global, template[global]);
|
||||
merged.Add("global", template["global"]);
|
||||
|
||||
//Debug.Console(2, "MERGED CONFIG RESULT: \x0d\x0a{0}", merged);
|
||||
return merged;
|
||||
@@ -247,11 +225,10 @@ namespace PepperDash.Core.Config
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Cannot merge items at path {propPath}: \r{e}");
|
||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "Cannot merge items at path {0}: \r{1}", propPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return o1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,30 +6,28 @@ using Crestron.SimplSharp;
|
||||
using Newtonsoft.Json;
|
||||
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
|
||||
/// Gets the unique key associated with the object.
|
||||
/// </summary>
|
||||
[JsonProperty("key")]
|
||||
string Key { get; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Named Keyed device interface. Forces the device to have a Unique Key and a name.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Named Keyed device interface. Forces the device to have a Unique Key and a name.
|
||||
/// </summary>
|
||||
public interface IKeyName : IKeyed
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Isn't it obvious :)
|
||||
/// Gets the name associated with the current object.
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
namespace PepperDash.Core;
|
||||
|
||||
//*********************************************************************************************************
|
||||
/// <summary>
|
||||
/// Represents a Device
|
||||
/// The core event and status-bearing class that most if not all device and connectors can derive from.
|
||||
/// </summary>
|
||||
public class Device : IKeyName
|
||||
{
|
||||
@@ -16,7 +16,7 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public string Key { get; protected set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the Name
|
||||
/// Name of the devie
|
||||
/// </summary>
|
||||
public string Name { get; protected set; }
|
||||
/// <summary>
|
||||
@@ -24,14 +24,14 @@ namespace PepperDash.Core
|
||||
/// </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>
|
||||
///// <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>
|
||||
///// <summary>
|
||||
///// Helper method to check if Config exists
|
||||
///// </summary>
|
||||
//public bool HasConfig { get { return Config != null; } }
|
||||
|
||||
List<Action> _PreActivationActions;
|
||||
@@ -86,9 +86,6 @@ namespace PepperDash.Core
|
||||
/// Adds a post activation action
|
||||
/// </summary>
|
||||
/// <param name="act"></param>
|
||||
/// <summary>
|
||||
/// AddPostActivationAction method
|
||||
/// </summary>
|
||||
public void AddPostActivationAction(Action act)
|
||||
{
|
||||
if (_PostActivationActions == null)
|
||||
@@ -97,7 +94,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PreActivate method
|
||||
/// Executes the preactivation actions
|
||||
/// </summary>
|
||||
public void PreActivate()
|
||||
{
|
||||
@@ -116,7 +113,9 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activate method
|
||||
/// Gets this device ready to be used in the system. Runs any added pre-activation items, and
|
||||
/// all post-activation at end. Classes needing additional logic to
|
||||
/// run should override CustomActivate()
|
||||
/// </summary>
|
||||
public bool Activate()
|
||||
{
|
||||
@@ -129,7 +128,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PostActivate method
|
||||
/// Executes the postactivation actions
|
||||
/// </summary>
|
||||
public void PostActivate()
|
||||
{
|
||||
@@ -153,9 +152,6 @@ namespace PepperDash.Core
|
||||
/// 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>
|
||||
@@ -188,12 +184,8 @@ namespace PepperDash.Core
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
using Newtonsoft.Json;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a EthernetHelper
|
||||
/// </summary>
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Class to help with accessing values from the CrestronEthernetHelper class
|
||||
/// </summary>
|
||||
public class EthernetHelper
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,7 +25,7 @@ namespace PepperDash.Core
|
||||
// ADD OTHER HELPERS HERE
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PortNumber
|
||||
///
|
||||
/// </summary>
|
||||
public int PortNumber { get; private set; }
|
||||
|
||||
@@ -114,4 +114,3 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -17,17 +17,17 @@ namespace PepperDash.Core
|
||||
public bool State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IntValue
|
||||
/// Boolean ushort value property
|
||||
/// </summary>
|
||||
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type
|
||||
/// Boolean change event args type
|
||||
/// </summary>
|
||||
public ushort Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Index
|
||||
/// Boolean change event args index
|
||||
/// </summary>
|
||||
public ushort Index { get; set; }
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a UshrtChangeEventArgs
|
||||
/// Ushort change event args
|
||||
/// </summary>
|
||||
public class UshrtChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -75,12 +75,12 @@ namespace PepperDash.Core
|
||||
public ushort IntValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type
|
||||
/// Ushort change event args type
|
||||
/// </summary>
|
||||
public ushort Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Index
|
||||
/// Ushort change event args index
|
||||
/// </summary>
|
||||
public ushort Index { get; set; }
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a StringChangeEventArgs
|
||||
/// String change event args
|
||||
/// </summary>
|
||||
public class StringChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -128,12 +128,12 @@ namespace PepperDash.Core
|
||||
public string StringValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type
|
||||
/// String change event args type
|
||||
/// </summary>
|
||||
public ushort Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Index
|
||||
/// string change event args index
|
||||
/// </summary>
|
||||
public ushort Index { get; set; }
|
||||
|
||||
@@ -169,4 +169,3 @@ namespace PepperDash.Core
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
namespace PepperDash.Core.GenericRESTfulCommunications;
|
||||
|
||||
/// <summary>
|
||||
/// Constants
|
||||
/// </summary>
|
||||
public class GenericRESTfulConstants
|
||||
{
|
||||
public class GenericRESTfulConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic boolean change
|
||||
/// </summary>
|
||||
@@ -35,5 +35,4 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
/// Error string change
|
||||
/// </summary>
|
||||
public const ushort ErrorStringChange = 203;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.Net.Http;
|
||||
using Crestron.SimplSharp.Net.Https;
|
||||
|
||||
namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
namespace PepperDash.Core.GenericRESTfulCommunications;
|
||||
|
||||
/// <summary>
|
||||
/// Generic RESTful communication class
|
||||
/// </summary>
|
||||
@@ -253,4 +253,3 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -33,12 +33,12 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
public DeviceConfig Device { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type
|
||||
/// Device change event args type
|
||||
/// </summary>
|
||||
public ushort Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Index
|
||||
/// Device change event args index
|
||||
/// </summary>
|
||||
public ushort Index { get; set; }
|
||||
|
||||
@@ -74,4 +74,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -58,9 +58,6 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
/// </summary>
|
||||
/// <param name="uniqueID"></param>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// </summary>
|
||||
public void Initialize(string uniqueID, string deviceKey)
|
||||
{
|
||||
// S+ set EvaluateFb low
|
||||
@@ -183,4 +180,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
|
||||
#endregion EventHandler Helpers
|
||||
}
|
||||
}
|
||||
@@ -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/#
|
||||
|
||||
@@ -48,12 +48,12 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
}
|
||||
*/
|
||||
/// <summary>
|
||||
/// Represents a ComParamsConfig
|
||||
/// Device communication parameter class
|
||||
/// </summary>
|
||||
public class ComParamsConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the baudRate
|
||||
///
|
||||
/// </summary>
|
||||
public int baudRate { get; set; }
|
||||
/// <summary>
|
||||
@@ -87,11 +87,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
|
||||
// convert properties for simpl
|
||||
/// <summary>
|
||||
/// Gets or sets the simplBaudRate
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
|
||||
/// <summary>
|
||||
/// Gets or sets the simplDataBits
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
|
||||
/// <summary>
|
||||
@@ -144,11 +144,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
|
||||
// convert properties for simpl
|
||||
/// <summary>
|
||||
/// Gets or sets the simplPort
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplPort { get { return Convert.ToUInt16(port); } }
|
||||
/// <summary>
|
||||
/// Gets or sets the simplAutoReconnect
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
|
||||
/// <summary>
|
||||
@@ -193,7 +193,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
|
||||
// convert properties for simpl
|
||||
/// <summary>
|
||||
/// Gets or sets the simplControlPortNumber
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a PropertiesConfig
|
||||
/// Device properties class
|
||||
/// </summary>
|
||||
public class PropertiesConfig
|
||||
{
|
||||
@@ -227,11 +227,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
|
||||
// convert properties for simpl
|
||||
/// <summary>
|
||||
/// Gets or sets the simplDeviceId
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
|
||||
/// <summary>
|
||||
/// Gets or sets the simplEnabled
|
||||
///
|
||||
/// </summary>
|
||||
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
|
||||
|
||||
@@ -254,4 +254,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
||||
/// </summary>
|
||||
public List<DeviceConfig> devices { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.JsonToSimpl
|
||||
{
|
||||
namespace PepperDash.Core.JsonToSimpl;
|
||||
|
||||
/// <summary>
|
||||
/// Constants for Simpl modules
|
||||
/// </summary>
|
||||
@@ -89,7 +89,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
public class SPlusValueWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the ValueType
|
||||
///
|
||||
/// </summary>
|
||||
public SPlusType ValueType { get; private set; }
|
||||
/// <summary>
|
||||
@@ -123,7 +123,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of SPlusType values
|
||||
/// S+ types enum
|
||||
/// </summary>
|
||||
public enum SPlusType
|
||||
{
|
||||
@@ -140,4 +140,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
String
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
@@ -23,9 +23,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="master">New master to add</param>
|
||||
///
|
||||
/// <summary>
|
||||
/// AddMaster method
|
||||
/// </summary>
|
||||
public static void AddMaster(JsonToSimplMaster master)
|
||||
{
|
||||
if (master == null)
|
||||
@@ -53,11 +50,10 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetMasterByFile method
|
||||
/// Gets a master by its key. Case-insensitive
|
||||
/// </summary>
|
||||
public static JsonToSimplMaster GetMasterByFile(string file)
|
||||
{
|
||||
return Masters.FirstOrDefault(m => m.UniqueID.Equals(file, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@ using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
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>
|
||||
@@ -77,9 +77,8 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ProcessAll method
|
||||
/// Process all values
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void ProcessAll()
|
||||
{
|
||||
if (FindInArray())
|
||||
@@ -160,4 +159,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
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>
|
||||
@@ -29,12 +29,12 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
public SPlusValuesDelegate GetAllValuesDelegate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SetAllPathsDelegate
|
||||
/// Use a callback to reduce task switch/threading
|
||||
/// </summary>
|
||||
public SPlusValuesDelegate SetAllPathsDelegate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Key
|
||||
/// Unique identifier for instance
|
||||
/// </summary>
|
||||
public string Key { get; protected set; }
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
public string PathSuffix { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the LinkedToObject
|
||||
/// Indicates if the instance is linked to an object
|
||||
/// </summary>
|
||||
public bool LinkedToObject { get; protected set; }
|
||||
|
||||
@@ -96,9 +96,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// Sets the path prefix for the object
|
||||
/// </summary>
|
||||
/// <param name="pathPrefix"></param>
|
||||
/// <summary>
|
||||
/// SetPathPrefix method
|
||||
/// </summary>
|
||||
public void SetPathPrefix(string pathPrefix)
|
||||
{
|
||||
PathPrefix = pathPrefix;
|
||||
@@ -114,7 +111,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetUshortPath method
|
||||
/// Set the JPath for a ushort out index.
|
||||
/// </summary>
|
||||
public void SetUshortPath(ushort index, string path)
|
||||
{
|
||||
@@ -124,7 +121,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetStringPath method
|
||||
/// Set the JPath for a string output index.
|
||||
/// </summary>
|
||||
public void SetStringPath(ushort index, string path)
|
||||
{
|
||||
@@ -134,9 +131,9 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ProcessAll method
|
||||
/// Evalutates all outputs with defined paths. called by S+ when paths are ready to process
|
||||
/// and by Master when file is read.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public virtual void ProcessAll()
|
||||
{
|
||||
if (!LinkedToObject)
|
||||
@@ -280,9 +277,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="theValue"></param>
|
||||
/// <summary>
|
||||
/// USetBoolValue method
|
||||
/// </summary>
|
||||
public void USetBoolValue(ushort key, ushort theValue)
|
||||
{
|
||||
SetBoolValue(key, theValue == 1);
|
||||
@@ -293,9 +287,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="theValue"></param>
|
||||
/// <summary>
|
||||
/// SetBoolValue method
|
||||
/// </summary>
|
||||
public void SetBoolValue(ushort key, bool theValue)
|
||||
{
|
||||
if (BoolPaths.ContainsKey(key))
|
||||
@@ -307,9 +298,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="theValue"></param>
|
||||
/// <summary>
|
||||
/// SetUShortValue method
|
||||
/// </summary>
|
||||
public void SetUShortValue(ushort key, ushort theValue)
|
||||
{
|
||||
if (UshortPaths.ContainsKey(key))
|
||||
@@ -321,9 +309,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="theValue"></param>
|
||||
/// <summary>
|
||||
/// SetStringValue method
|
||||
/// </summary>
|
||||
public void SetStringValue(ushort key, string theValue)
|
||||
{
|
||||
if (StringPaths.ContainsKey(key))
|
||||
@@ -335,9 +320,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="keyPath"></param>
|
||||
/// <param name="valueToSave"></param>
|
||||
/// <summary>
|
||||
/// SetValueOnMaster method
|
||||
/// </summary>
|
||||
public void SetValueOnMaster(string keyPath, JValue valueToSave)
|
||||
{
|
||||
var path = GetFullPath(keyPath);
|
||||
@@ -419,4 +401,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,25 +7,25 @@ using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
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
|
||||
/// </summary>
|
||||
public class JsonToSimplFileMaster : JsonToSimplMaster
|
||||
{
|
||||
/// <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
|
||||
/// Filepath to the actual file that will be read (Portal or local)
|
||||
/// </summary>
|
||||
public string ActualFilePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Filename
|
||||
///
|
||||
/// </summary>
|
||||
public string Filename { get; private set; }
|
||||
/// <summary>
|
||||
@@ -194,9 +194,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// Sets the debug level
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <summary>
|
||||
/// setDebugLevel method
|
||||
/// </summary>
|
||||
public void setDebugLevel(uint level)
|
||||
{
|
||||
Debug.SetDebugLevel(level);
|
||||
@@ -288,5 +285,4 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
|
||||
namespace PepperDash.Core.JsonToSimpl
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a JsonToSimplFixedPathObject
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.JsonToSimpl;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,4 +15,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
this.LinkedToObject = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ using System.Collections.Generic;
|
||||
using Crestron.SimplSharp;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace PepperDash.Core.JsonToSimpl
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a JsonToSimplGenericMaster
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.JsonToSimpl;
|
||||
|
||||
/// <summary>
|
||||
/// Generic Master
|
||||
/// </summary>
|
||||
public class JsonToSimplGenericMaster : JsonToSimplMaster
|
||||
{
|
||||
{
|
||||
/*****************************************************************************************/
|
||||
/** Privates **/
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
static object WriteLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SaveCallback
|
||||
/// Callback action for saving
|
||||
/// </summary>
|
||||
public Action<string> SaveCallback { get; set; }
|
||||
|
||||
@@ -60,9 +60,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// Loads JSON into JsonObject, but does not trigger evaluation by children
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
/// <summary>
|
||||
/// SetJsonWithoutEvaluating method
|
||||
/// </summary>
|
||||
public void SetJsonWithoutEvaluating(string json)
|
||||
{
|
||||
try
|
||||
@@ -76,9 +73,8 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save method
|
||||
///
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void Save()
|
||||
{
|
||||
// this code is duplicated in the other masters!!!!!!!!!!!!!
|
||||
@@ -119,4 +115,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
Debug.Console(0, this, "WARNING: No save callback defined.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
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>
|
||||
@@ -39,7 +38,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
public string Key { get { return UniqueID; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the UniqueID
|
||||
/// A unique ID
|
||||
/// </summary>
|
||||
public string UniqueID { get; protected set; }
|
||||
|
||||
@@ -54,7 +53,8 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
string _DebugName = "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PathPrefix
|
||||
/// This will be prepended to all paths to allow path swapping or for more organized
|
||||
/// sub-paths
|
||||
/// </summary>
|
||||
public string PathPrefix { get; set; }
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JsonObject
|
||||
///
|
||||
/// </summary>
|
||||
public JObject JsonObject { get; protected set; }
|
||||
|
||||
@@ -119,9 +119,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// Adds a child "module" to this master
|
||||
/// </summary>
|
||||
/// <param name="child"></param>
|
||||
/// <summary>
|
||||
/// AddChild method
|
||||
/// </summary>
|
||||
public void AddChild(JsonToSimplChildObjectBase child)
|
||||
{
|
||||
if (!Children.Contains(child))
|
||||
@@ -131,7 +128,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddUnsavedValue method
|
||||
/// Called from the child to add changed or new values for saving
|
||||
/// </summary>
|
||||
public void AddUnsavedValue(string path, JValue value)
|
||||
{
|
||||
@@ -162,11 +159,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// <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 StringReader(json)))
|
||||
{
|
||||
var startDepth = reader.Depth;
|
||||
var obj = JObject.Load(reader);
|
||||
@@ -181,16 +174,10 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ParseArray method
|
||||
/// </summary>
|
||||
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 StringReader(json)))
|
||||
{
|
||||
var startDepth = reader.Depth;
|
||||
var obj = JArray.Load(reader);
|
||||
@@ -249,4 +236,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,20 +6,20 @@ using Crestron.SimplSharp.CrestronIO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core.Config;
|
||||
|
||||
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
|
||||
/// File path of the actual file being read (Portal or local)
|
||||
/// </summary>
|
||||
public string ActualFilePath { get; private set; }
|
||||
|
||||
@@ -128,9 +128,6 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <summary>
|
||||
/// setDebugLevel method
|
||||
/// </summary>
|
||||
public void setDebugLevel(uint level)
|
||||
{
|
||||
Debug.SetDebugLevel(level);
|
||||
@@ -191,4 +188,3 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PepperDash.Core.Logging
|
||||
namespace PepperDash.Core.Logging;
|
||||
|
||||
public class CrestronEnricher : ILogEventEnricher
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a CrestronEnricher
|
||||
/// </summary>
|
||||
public class CrestronEnricher : ILogEventEnricher
|
||||
{
|
||||
static readonly string _appName;
|
||||
|
||||
static CrestronEnricher()
|
||||
@@ -30,14 +27,10 @@ namespace PepperDash.Core.Logging
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enrich method
|
||||
/// </summary>
|
||||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
||||
{
|
||||
var property = propertyFactory.CreateProperty("App", _appName);
|
||||
|
||||
logEvent.AddOrUpdateProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Crestron.SimplSharp;
|
||||
@@ -17,16 +16,18 @@ using Serilog.Formatting.Compact;
|
||||
using Serilog.Formatting.Json;
|
||||
using Serilog.Templates;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Contains debug commands for use in various situations
|
||||
/// </summary>
|
||||
public static class Debug
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public static class Debug
|
||||
{
|
||||
private static readonly string LevelStoreKey = "ConsoleDebugLevel";
|
||||
private static readonly string WebSocketLevelStoreKey = "WebsocketDebugLevel";
|
||||
private static readonly string ErrorLogLevelStoreKey = "ErrorLogDebugLevel";
|
||||
private static readonly string FileLevelStoreKey = "FileDebugLevel";
|
||||
private static readonly string DoNotLoadOnNextBootKey = "DoNotLoadOnNextBoot";
|
||||
|
||||
private static readonly Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
|
||||
{
|
||||
@@ -40,27 +41,21 @@ namespace PepperDash.Core
|
||||
|
||||
private static ILogger _logger;
|
||||
|
||||
private static readonly LoggingLevelSwitch _consoleLogLevelSwitch;
|
||||
private static readonly LoggingLevelSwitch _consoleLoggingLevelSwitch;
|
||||
|
||||
private static readonly LoggingLevelSwitch _websocketLogLevelSwitch;
|
||||
private static readonly LoggingLevelSwitch _websocketLoggingLevelSwitch;
|
||||
|
||||
private static readonly LoggingLevelSwitch _errorLogLevelSwitch;
|
||||
|
||||
private static readonly LoggingLevelSwitch _fileLogLevelSwitch;
|
||||
private static readonly LoggingLevelSwitch _fileLevelSwitch;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum log level for the websocket sink.
|
||||
/// </summary>
|
||||
public static LogEventLevel WebsocketMinimumLogLevel
|
||||
{
|
||||
get { return _websocketLogLevelSwitch.MinimumLevel; }
|
||||
get { return _websocketLoggingLevelSwitch.MinimumLevel; }
|
||||
}
|
||||
|
||||
private static readonly DebugWebsocketSink _websocketSink;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the websocket sink for debug logging.
|
||||
/// </summary>
|
||||
public static DebugWebsocketSink WebsocketSink
|
||||
{
|
||||
get { return _websocketSink; }
|
||||
@@ -84,12 +79,12 @@ namespace PepperDash.Core
|
||||
public static string FileName = string.Format(@"app{0}Debug.json", InitialParametersClass.ApplicationNumber);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Level
|
||||
/// Debug level to set for a given program.
|
||||
/// </summary>
|
||||
public static int Level { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the DoNotLoadConfigOnNextBoot
|
||||
/// When this is true, the configuration file will NOT be loaded until triggered by either a console command or a signal
|
||||
/// </summary>
|
||||
public static bool DoNotLoadConfigOnNextBoot { get; private set; }
|
||||
|
||||
@@ -97,13 +92,10 @@ namespace PepperDash.Core
|
||||
|
||||
private const int SaveTimeoutMs = 30000;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the system is running on an appliance.
|
||||
/// </summary>
|
||||
public static bool IsRunningOnAppliance = CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PepperDashCoreVersion
|
||||
/// Version for the currently loaded PepperDashCore dll
|
||||
/// </summary>
|
||||
public static string PepperDashCoreVersion { get; private set; }
|
||||
|
||||
@@ -115,18 +107,19 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
private static bool _excludeAllMode;
|
||||
|
||||
//static bool ExcludeNoKeyMessages;
|
||||
|
||||
private static readonly Dictionary<string, object> IncludedExcludedKeys;
|
||||
|
||||
private static readonly LoggerConfiguration _defaultLoggerConfiguration;
|
||||
|
||||
private static LoggerConfiguration _loggerConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the logger configuration for the debug logging.
|
||||
/// </summary>
|
||||
public static LoggerConfiguration LoggerConfiguration => _loggerConfiguration;
|
||||
|
||||
static Debug()
|
||||
{
|
||||
try
|
||||
{
|
||||
CrestronDataStoreStatic.InitCrestronDataStore();
|
||||
|
||||
@@ -138,13 +131,13 @@ namespace PepperDash.Core
|
||||
|
||||
var defaultFileLogLevel = GetStoredLogEventLevel(FileLevelStoreKey);
|
||||
|
||||
_consoleLogLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultConsoleLevel);
|
||||
_consoleLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultConsoleLevel);
|
||||
|
||||
_websocketLogLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultWebsocketLevel);
|
||||
_websocketLoggingLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultWebsocketLevel);
|
||||
|
||||
_errorLogLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultErrorLogLevel);
|
||||
|
||||
_fileLogLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultFileLogLevel);
|
||||
_fileLevelSwitch = new LoggingLevelSwitch(initialMinimumLevel: defaultFileLogLevel);
|
||||
|
||||
_websocketSink = new DebugWebsocketSink(new JsonFormatter(renderMessage: true));
|
||||
|
||||
@@ -162,31 +155,16 @@ namespace PepperDash.Core
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.With(new CrestronEnricher())
|
||||
.WriteTo.Sink(new DebugConsoleSink(new ExpressionTemplate("[{@t:yyyy-MM-dd HH:mm:ss.fff}][{@l:u4}][{App}]{#if Key is not null}[{Key}]{#end} {@m}{#if @x is not null}\r\n{@x}{#end}")), levelSwitch: _consoleLogLevelSwitch)
|
||||
.WriteTo.Sink(_websocketSink, levelSwitch: _websocketLogLevelSwitch)
|
||||
.WriteTo.Sink(new DebugConsoleSink(new ExpressionTemplate("[{@t:yyyy-MM-dd HH:mm:ss.fff}][{@l:u4}][{App}]{#if Key is not null}[{Key}]{#end} {@m}{#if @x is not null}\r\n{@x}{#end}")), levelSwitch: _consoleLoggingLevelSwitch)
|
||||
.WriteTo.Sink(_websocketSink, levelSwitch: _websocketLoggingLevelSwitch)
|
||||
.WriteTo.Sink(new DebugErrorLogSink(new ExpressionTemplate(errorLogTemplate)), levelSwitch: _errorLogLevelSwitch)
|
||||
.WriteTo.File(new RenderedCompactJsonFormatter(), logFilePath,
|
||||
rollingInterval: RollingInterval.Day,
|
||||
restrictedToMinimumLevel: LogEventLevel.Debug,
|
||||
retainedFileCountLimit: CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance ? 7 : 14,
|
||||
levelSwitch: _fileLogLevelSwitch
|
||||
retainedFileCountLimit: CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance ? 30 : 60,
|
||||
levelSwitch: _fileLevelSwitch
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
if (InitialParametersClass.NumberOfRemovableDrives > 0)
|
||||
{
|
||||
CrestronConsole.PrintLine("{0} RM Drive(s) Present. Initializing CrestronLogger", InitialParametersClass.NumberOfRemovableDrives);
|
||||
_defaultLoggerConfiguration.WriteTo.Sink(new DebugCrestronLoggerSink());
|
||||
}
|
||||
else
|
||||
CrestronConsole.PrintLine("No RM Drive(s) Present. Not using Crestron Logger");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CrestronConsole.PrintLine("Initializing of CrestronLogger failed: {0}", e);
|
||||
}
|
||||
|
||||
// Instantiate the root logger
|
||||
_loggerConfiguration = _defaultLoggerConfiguration;
|
||||
|
||||
@@ -228,27 +206,35 @@ namespace PepperDash.Core
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
||||
|
||||
LoadMemory();
|
||||
|
||||
var context = _contexts.GetOrCreateItem("DEFAULT");
|
||||
Level = context.Level;
|
||||
DoNotLoadConfigOnNextBoot = context.DoNotLoadOnNextBoot;
|
||||
DoNotLoadConfigOnNextBoot = GetDoNotLoadOnNextBoot();
|
||||
|
||||
if (DoNotLoadConfigOnNextBoot)
|
||||
CrestronConsole.PrintLine(string.Format("Program {0} will not load config after next boot. Use console command go:{0} to load the config manually", InitialParametersClass.ApplicationNumber));
|
||||
|
||||
_errorLogLevelSwitch.MinimumLevelChanged += (sender, args) =>
|
||||
_consoleLoggingLevelSwitch.MinimumLevelChanged += (sender, args) =>
|
||||
{
|
||||
LogMessage(LogEventLevel.Information, "Error log debug level set to {minimumLevel}", _errorLogLevelSwitch.MinimumLevel);
|
||||
LogMessage(LogEventLevel.Information, "Console debug level set to {minimumLevel}", _consoleLoggingLevelSwitch.MinimumLevel);
|
||||
};
|
||||
|
||||
// Set initial error log level based on platform && stored level. If appliance, use stored level, otherwise default to verbose
|
||||
SetErrorLogMinimumDebugLevel(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance ? _errorLogLevelSwitch.MinimumLevel : LogEventLevel.Verbose);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError(ex, "Exception in Debug static constructor: {message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GetDoNotLoadOnNextBoot()
|
||||
{
|
||||
var err = CrestronDataStoreStatic.GetLocalBoolValue(DoNotLoadOnNextBootKey, out var doNotLoad);
|
||||
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
{
|
||||
LogError("Error retrieving DoNotLoadOnNextBoot value: {err}", err);
|
||||
doNotLoad = false;
|
||||
}
|
||||
|
||||
return doNotLoad;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UpdateLoggerConfiguration method
|
||||
/// </summary>
|
||||
public static void UpdateLoggerConfiguration(LoggerConfiguration config)
|
||||
{
|
||||
_loggerConfiguration = config;
|
||||
@@ -256,9 +242,6 @@ namespace PepperDash.Core
|
||||
_logger = config.CreateLogger();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ResetLoggerConfiguration method
|
||||
/// </summary>
|
||||
public static void ResetLoggerConfiguration()
|
||||
{
|
||||
_loggerConfiguration = _defaultLoggerConfiguration;
|
||||
@@ -275,10 +258,7 @@ namespace PepperDash.Core
|
||||
if (result != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
{
|
||||
CrestronConsole.Print($"Unable to retrieve stored log level for {levelStoreKey}.\r\nError: {result}.\r\nSetting level to {LogEventLevel.Information}\r\n");
|
||||
|
||||
CrestronDataStoreStatic.SetLocalIntValue(levelStoreKey, levelStoreKey == ErrorLogLevelStoreKey ? (int)LogEventLevel.Warning : (int)LogEventLevel.Information);
|
||||
|
||||
return levelStoreKey == ErrorLogLevelStoreKey ? LogEventLevel.Warning : LogEventLevel.Information;
|
||||
return LogEventLevel.Information;
|
||||
}
|
||||
|
||||
if (logLevel < 0 || logLevel > 5)
|
||||
@@ -287,8 +267,6 @@ namespace PepperDash.Core
|
||||
return LogEventLevel.Information;
|
||||
}
|
||||
|
||||
CrestronConsole.PrintLine($"Stored log level for {levelStoreKey} is {logLevel}");
|
||||
|
||||
return (LogEventLevel)logLevel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -344,9 +322,6 @@ namespace PepperDash.Core
|
||||
/// Callback for console command
|
||||
/// </summary>
|
||||
/// <param name="levelString"></param>
|
||||
/// <summary>
|
||||
/// SetDebugFromConsole method
|
||||
/// </summary>
|
||||
public static void SetDebugFromConsole(string levelString)
|
||||
{
|
||||
try
|
||||
@@ -354,11 +329,7 @@ namespace PepperDash.Core
|
||||
if (levelString.Trim() == "?")
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse(
|
||||
"Used to set the minimum level of debug messages:\r\n" +
|
||||
"Usage: appdebug:P [sink] [level]\r\n" +
|
||||
" sink: console (default), errorlog, file, all\r\n" +
|
||||
" all: sets all sinks to the specified level\r\n" +
|
||||
" level: 0-5 or LogEventLevel name\r\n" +
|
||||
"Used to set the minimum level of debug messages to be printed to the console:\r\n" +
|
||||
$"{_logLevels[0]} = 0\r\n" +
|
||||
$"{_logLevels[1]} = 1\r\n" +
|
||||
$"{_logLevels[2]} = 2\r\n" +
|
||||
@@ -370,88 +341,32 @@ namespace PepperDash.Core
|
||||
|
||||
if (string.IsNullOrEmpty(levelString.Trim()))
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse("Console log level = {0}\r\n", _consoleLogLevelSwitch.MinimumLevel);
|
||||
CrestronConsole.ConsoleCommandResponse("File log level = {0}\r\n", _fileLogLevelSwitch.MinimumLevel);
|
||||
CrestronConsole.ConsoleCommandResponse("Error log level = {0}\r\n", _errorLogLevelSwitch.MinimumLevel);
|
||||
CrestronConsole.ConsoleCommandResponse("AppDebug level = {0}", _consoleLoggingLevelSwitch.MinimumLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse tokens: first token is sink (defaults to console), second token is level
|
||||
var tokens = levelString.Trim().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
string sinkName;
|
||||
string levelToken;
|
||||
|
||||
if (tokens.Length == 1)
|
||||
{
|
||||
// Single token - assume it's a level for console sink
|
||||
sinkName = "console";
|
||||
levelToken = tokens[0];
|
||||
}
|
||||
else if (tokens.Length == 2)
|
||||
{
|
||||
// Two tokens - first is sink, second is level
|
||||
sinkName = tokens[0].ToLowerInvariant();
|
||||
levelToken = tokens[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [sink] [level]");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse the level using the same logic as before
|
||||
LogEventLevel level;
|
||||
|
||||
if (int.TryParse(levelToken, out var levelInt))
|
||||
if (int.TryParse(levelString, out var levelInt))
|
||||
{
|
||||
if (levelInt < 0 || levelInt > 5)
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelToken} to valid log level. If using a number, value must be between 0-5");
|
||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level. If using a number, value must be between 0-5");
|
||||
return;
|
||||
}
|
||||
SetDebugLevel((uint)levelInt);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_logLevels.TryGetValue((uint)levelInt, out level))
|
||||
if (Enum.TryParse<LogEventLevel>(levelString, out var levelEnum))
|
||||
{
|
||||
level = LogEventLevel.Information;
|
||||
CrestronConsole.ConsoleCommandResponse($"{levelInt} not valid. Setting level to {level}");
|
||||
}
|
||||
}
|
||||
else if (Enum.TryParse(levelToken, true, out level))
|
||||
{
|
||||
// Successfully parsed as LogEventLevel enum
|
||||
}
|
||||
else
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelToken} to valid log level");
|
||||
SetDebugLevel(levelEnum);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the level for the specified sink
|
||||
switch (sinkName)
|
||||
{
|
||||
case "console":
|
||||
SetDebugLevel(level);
|
||||
break;
|
||||
case "errorlog":
|
||||
SetErrorLogMinimumDebugLevel(level);
|
||||
break;
|
||||
case "file":
|
||||
SetFileMinimumDebugLevel(level);
|
||||
break;
|
||||
case "all":
|
||||
SetDebugLevel(level);
|
||||
SetErrorLogMinimumDebugLevel(level);
|
||||
SetFileMinimumDebugLevel(level);
|
||||
break;
|
||||
default:
|
||||
CrestronConsole.ConsoleCommandResponse($"Error: Unknown sink '{sinkName}'. Valid sinks: console, errorlog, file");
|
||||
break;
|
||||
}
|
||||
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level");
|
||||
}
|
||||
catch
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [sink] [level]");
|
||||
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [0-5]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,9 +374,6 @@ namespace PepperDash.Core
|
||||
/// Sets the debug level
|
||||
/// </summary>
|
||||
/// <param name="level"> Valid values 0-5</param>
|
||||
/// <summary>
|
||||
/// SetDebugLevel method
|
||||
/// </summary>
|
||||
public static void SetDebugLevel(uint level)
|
||||
{
|
||||
if (!_logLevels.TryGetValue(level, out var logLevel))
|
||||
@@ -476,15 +388,12 @@ namespace PepperDash.Core
|
||||
SetDebugLevel(logLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetDebugLevel method
|
||||
/// </summary>
|
||||
public static void SetDebugLevel(LogEventLevel level)
|
||||
{
|
||||
_consoleLogLevelSwitch.MinimumLevel = level;
|
||||
_consoleLoggingLevelSwitch.MinimumLevel = level;
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}] Debug level set to {1}\r\n",
|
||||
InitialParametersClass.ApplicationNumber, _consoleLogLevelSwitch.MinimumLevel);
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}\r\n",
|
||||
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse($"Storing level {level}:{(int)level}");
|
||||
|
||||
@@ -496,68 +405,46 @@ namespace PepperDash.Core
|
||||
CrestronConsole.PrintLine($"Error saving console debug level setting: {err}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetWebSocketMinimumDebugLevel method
|
||||
/// </summary>
|
||||
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
||||
{
|
||||
_websocketLogLevelSwitch.MinimumLevel = level;
|
||||
_websocketLoggingLevelSwitch.MinimumLevel = level;
|
||||
|
||||
var err = CrestronDataStoreStatic.SetLocalUintValue(WebSocketLevelStoreKey, (uint)level);
|
||||
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
LogMessage(LogEventLevel.Information, "Error saving websocket debug level setting: {erro}", err);
|
||||
|
||||
LogMessage(LogEventLevel.Information, "Websocket debug level set to {0}", _websocketLogLevelSwitch.MinimumLevel);
|
||||
LogMessage(LogEventLevel.Information, "Websocket debug level set to {0}", _websocketLoggingLevelSwitch.MinimumLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetErrorLogMinimumDebugLevel method
|
||||
/// </summary>
|
||||
public static void SetErrorLogMinimumDebugLevel(LogEventLevel level)
|
||||
{
|
||||
_errorLogLevelSwitch.MinimumLevel = level;
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}] Error log level set to {1}\r\n",
|
||||
InitialParametersClass.ApplicationNumber, _errorLogLevelSwitch.MinimumLevel);
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse($"Storing level {level}:{(int)level}");
|
||||
|
||||
var err = CrestronDataStoreStatic.SetLocalIntValue(ErrorLogLevelStoreKey, (int)level);
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse($"Store result: {err}:{(int)level}");
|
||||
var err = CrestronDataStoreStatic.SetLocalUintValue(ErrorLogLevelStoreKey, (uint)level);
|
||||
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
CrestronConsole.PrintLine($"Error saving error log debug level setting: {err}");
|
||||
LogMessage(LogEventLevel.Information, "Error saving Error Log debug level setting: {error}", err);
|
||||
|
||||
LogMessage(LogEventLevel.Information, "Error log debug level set to {0}", _websocketLoggingLevelSwitch.MinimumLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SetFileMinimumDebugLevel method
|
||||
/// </summary>
|
||||
public static void SetFileMinimumDebugLevel(LogEventLevel level)
|
||||
{
|
||||
_fileLogLevelSwitch.MinimumLevel = level;
|
||||
_errorLogLevelSwitch.MinimumLevel = level;
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}] File log level set to {1}\r\n",
|
||||
InitialParametersClass.ApplicationNumber, _fileLogLevelSwitch.MinimumLevel);
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse($"Storing level {level}:{(int)level}");
|
||||
|
||||
var err = CrestronDataStoreStatic.SetLocalIntValue(FileLevelStoreKey, (int)level);
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse($"Store result: {err}:{(int)level}");
|
||||
var err = CrestronDataStoreStatic.SetLocalUintValue(ErrorLogLevelStoreKey, (uint)level);
|
||||
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
CrestronConsole.PrintLine($"Error saving file debug level setting: {err}");
|
||||
LogMessage(LogEventLevel.Information, "Error saving File debug level setting: {error}", err);
|
||||
|
||||
LogMessage(LogEventLevel.Information, "File debug level set to {0}", _websocketLoggingLevelSwitch.MinimumLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for console command
|
||||
/// </summary>
|
||||
/// <param name="stateString"></param>
|
||||
/// <summary>
|
||||
/// SetDoNotLoadOnNextBootFromConsole method
|
||||
/// </summary>
|
||||
public static void SetDoNotLoadOnNextBootFromConsole(string stateString)
|
||||
{
|
||||
try
|
||||
@@ -580,9 +467,6 @@ namespace PepperDash.Core
|
||||
/// Callback for console command
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <summary>
|
||||
/// SetDebugFilterFromConsole method
|
||||
/// </summary>
|
||||
public static void SetDebugFilterFromConsole(string items)
|
||||
{
|
||||
var str = items.Trim();
|
||||
@@ -678,9 +562,6 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetDeviceDebugSettingsForKey method
|
||||
/// </summary>
|
||||
public static object GetDeviceDebugSettingsForKey(string deviceKey)
|
||||
{
|
||||
return _contexts.GetDebugSettingsForKey(deviceKey);
|
||||
@@ -693,15 +574,17 @@ namespace PepperDash.Core
|
||||
public static void SetDoNotLoadConfigOnNextBoot(bool state)
|
||||
{
|
||||
DoNotLoadConfigOnNextBoot = state;
|
||||
_contexts.GetOrCreateItem("DEFAULT").DoNotLoadOnNextBoot = state;
|
||||
SaveMemoryOnTimeout();
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Do Not Load Config on Next Boot set to {1}",
|
||||
InitialParametersClass.ApplicationNumber, DoNotLoadConfigOnNextBoot);
|
||||
var err = CrestronDataStoreStatic.SetLocalBoolValue(DoNotLoadOnNextBootKey, state);
|
||||
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
LogError("Error saving console debug level setting: {err}", err);
|
||||
|
||||
LogInformation("Do Not Load Config on Next Boot set to {state}", DoNotLoadConfigOnNextBoot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ShowDebugLog method
|
||||
///
|
||||
/// </summary>
|
||||
public static void ShowDebugLog(string s)
|
||||
{
|
||||
@@ -717,9 +600,6 @@ namespace PepperDash.Core
|
||||
/// <param name="message">Message template</param>
|
||||
/// <param name="device">Optional IKeyed device. If provided, the Key of the device will be added to the log message</param>
|
||||
/// <param name="args">Args to put into message template</param>
|
||||
/// <summary>
|
||||
/// LogMessage method
|
||||
/// </summary>
|
||||
public static void LogMessage(Exception ex, string message, IKeyed device = null, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", device?.Key))
|
||||
@@ -743,36 +623,21 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs a message at the specified log level.
|
||||
/// </summary>
|
||||
/// <param name="level">Level to log at</param>
|
||||
/// <param name="message">Message template</param>
|
||||
/// <param name="args">Args to put into message template</param>
|
||||
public static void LogMessage(LogEventLevel level, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(level, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogMessage method
|
||||
/// </summary>
|
||||
public static void LogMessage(LogEventLevel level, Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(level, ex, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogMessage method
|
||||
/// </summary>
|
||||
public static void LogMessage(LogEventLevel level, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
LogMessage(level, message, keyed, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogMessage method
|
||||
/// </summary>
|
||||
public static void LogMessage(LogEventLevel level, Exception ex, IKeyed device, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", device?.Key))
|
||||
@@ -782,9 +647,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
#region Explicit methods for logging levels
|
||||
/// <summary>
|
||||
/// LogVerbose method
|
||||
/// </summary>
|
||||
public static void LogVerbose(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -793,9 +655,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogVerbose method
|
||||
/// </summary>
|
||||
public static void LogVerbose(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -804,25 +663,16 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogVerbose method
|
||||
/// </summary>
|
||||
public static void LogVerbose(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Verbose, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogVerbose method
|
||||
/// </summary>
|
||||
public static void LogVerbose(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Verbose, ex, message, args);
|
||||
_logger.Write(LogEventLevel.Verbose, ex, null, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogDebug method
|
||||
/// </summary>
|
||||
public static void LogDebug(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -831,9 +681,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogDebug method
|
||||
/// </summary>
|
||||
public static void LogDebug(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -842,25 +689,16 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogDebug method
|
||||
/// </summary>
|
||||
public static void LogDebug(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Debug, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogDebug method
|
||||
/// </summary>
|
||||
public static void LogDebug(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Debug, ex, null, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogInformation method
|
||||
/// </summary>
|
||||
public static void LogInformation(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -869,9 +707,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogInformation method
|
||||
/// </summary>
|
||||
public static void LogInformation(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -880,25 +715,16 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogInformation method
|
||||
/// </summary>
|
||||
public static void LogInformation(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Information, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogInformation method
|
||||
/// </summary>
|
||||
public static void LogInformation(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Information, ex, message, args);
|
||||
_logger.Write(LogEventLevel.Information, ex, null, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogWarning method
|
||||
/// </summary>
|
||||
public static void LogWarning(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -907,9 +733,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogWarning method
|
||||
/// </summary>
|
||||
public static void LogWarning(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -918,25 +741,16 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogWarning method
|
||||
/// </summary>
|
||||
public static void LogWarning(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Warning, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogWarning method
|
||||
/// </summary>
|
||||
public static void LogWarning(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Warning, ex, message, args);
|
||||
_logger.Write(LogEventLevel.Warning, ex, null, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogError method
|
||||
/// </summary>
|
||||
public static void LogError(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -945,9 +759,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogError method
|
||||
/// </summary>
|
||||
public static void LogError(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -956,25 +767,16 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogError method
|
||||
/// </summary>
|
||||
public static void LogError(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogError method
|
||||
/// </summary>
|
||||
public static void LogError(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Error, ex, message, args);
|
||||
_logger.Write(LogEventLevel.Error, ex, null, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogFatal method
|
||||
/// </summary>
|
||||
public static void LogFatal(IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -983,9 +785,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogFatal method
|
||||
/// </summary>
|
||||
public static void LogFatal(Exception ex, IKeyed keyed, string message, params object[] args)
|
||||
{
|
||||
using (LogContext.PushProperty("Key", keyed?.Key))
|
||||
@@ -994,20 +793,14 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogFatal method
|
||||
/// </summary>
|
||||
public static void LogFatal(string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Fatal, message, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogFatal method
|
||||
/// </summary>
|
||||
public static void LogFatal(Exception ex, string message, params object[] args)
|
||||
{
|
||||
_logger.Write(LogEventLevel.Fatal, ex, message, args);
|
||||
_logger.Write(LogEventLevel.Fatal, ex, null, message, args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1215,7 +1008,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of ErrorLogLevel values
|
||||
/// Error level to for message to be logged at
|
||||
/// </summary>
|
||||
public enum ErrorLogLevel
|
||||
{
|
||||
@@ -1236,5 +1029,4 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,12 @@ 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;
|
||||
|
||||
/// <summary>
|
||||
/// Emit method
|
||||
/// </summary>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
if (!Debug.IsRunningOnAppliance) return;
|
||||
@@ -46,19 +40,14 @@ namespace PepperDash.Core
|
||||
_textFormatter = formatProvider ?? new JsonFormatter();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class DebugConsoleSinkExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// DebugConsoleSink method
|
||||
/// </summary>
|
||||
public static class DebugConsoleSinkExtensions
|
||||
{
|
||||
public static LoggerConfiguration DebugConsoleSink(
|
||||
this LoggerSinkConfiguration loggerConfiguration,
|
||||
ITextFormatter formatProvider = null)
|
||||
{
|
||||
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,22 +6,22 @@ using Crestron.SimplSharp.CrestronIO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a debugging context
|
||||
/// </summary>
|
||||
public class DebugContext
|
||||
{
|
||||
/// <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>
|
||||
///// <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;
|
||||
@@ -38,9 +38,6 @@ namespace PepperDash.Core
|
||||
/// </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));
|
||||
@@ -95,9 +92,6 @@ namespace PepperDash.Core
|
||||
/// Callback for console command
|
||||
/// </summary>
|
||||
/// <param name="levelString"></param>
|
||||
/// <summary>
|
||||
/// SetDebugFromConsole method
|
||||
/// </summary>
|
||||
public void SetDebugFromConsole(string levelString)
|
||||
{
|
||||
try
|
||||
@@ -120,9 +114,6 @@ namespace PepperDash.Core
|
||||
/// 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)
|
||||
@@ -150,7 +141,7 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console method
|
||||
/// Appends a device Key to the beginning of a message
|
||||
/// </summary>
|
||||
public void Console(uint level, IKeyed dev, string format, params object[] items)
|
||||
{
|
||||
@@ -200,9 +191,6 @@ namespace PepperDash.Core
|
||||
/// </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);
|
||||
@@ -278,16 +266,15 @@ namespace PepperDash.Core
|
||||
{
|
||||
return string.Format(@"\NVRAM\debugSettings\program{0}-{1}", InitialParametersClass.ApplicationNumber, Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DebugContextSaveData
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DebugContextSaveData
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Level { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,10 @@ 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Emit method
|
||||
/// </summary>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
if (!Debug.IsRunningOnAppliance) return;
|
||||
@@ -31,5 +25,4 @@ namespace PepperDash.Core.Logging
|
||||
{
|
||||
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,10 @@ 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>>
|
||||
@@ -27,9 +24,6 @@ namespace PepperDash.Core.Logging
|
||||
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) },
|
||||
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) }
|
||||
};
|
||||
/// <summary>
|
||||
/// Emit method
|
||||
/// </summary>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
string message;
|
||||
@@ -67,5 +61,4 @@ namespace PepperDash.Core.Logging
|
||||
{
|
||||
_formatter = formatter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,113 +1,73 @@
|
||||
using System;
|
||||
using Serilog.Events;
|
||||
using Serilog.Events;
|
||||
using System;
|
||||
using Log = PepperDash.Core.Debug;
|
||||
|
||||
namespace PepperDash.Core.Logging
|
||||
namespace PepperDash.Core.Logging;
|
||||
|
||||
public static class DebugExtensions
|
||||
{
|
||||
public static class DebugExtensions
|
||||
{
|
||||
/// <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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
Log.LogMessage(LogEventLevel.Fatal, device, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
using Crestron.SimplSharp;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Core.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DebugContextCollection
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.Logging;
|
||||
|
||||
/// <summary>
|
||||
/// Class to persist current Debug settings across program restarts
|
||||
/// </summary>
|
||||
public class DebugContextCollection
|
||||
{
|
||||
/// <summary>
|
||||
@@ -39,9 +39,6 @@ namespace PepperDash.Core.Logging
|
||||
/// </summary>
|
||||
/// <param name="contextKey"></param>
|
||||
/// <param name="level"></param>
|
||||
/// <summary>
|
||||
/// SetLevel method
|
||||
/// </summary>
|
||||
public void SetLevel(string contextKey, int level)
|
||||
{
|
||||
if (level < 0 || level > 2)
|
||||
@@ -54,9 +51,6 @@ namespace PepperDash.Core.Logging
|
||||
/// </summary>
|
||||
/// <param name="contextKey"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetOrCreateItem method
|
||||
/// </summary>
|
||||
public DebugContextItem GetOrCreateItem(string contextKey)
|
||||
{
|
||||
if (!_items.ContainsKey(contextKey))
|
||||
@@ -71,9 +65,6 @@ namespace PepperDash.Core.Logging
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <param name="settings"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// SetDebugSettingsForKey method
|
||||
/// </summary>
|
||||
public void SetDebugSettingsForKey(string deviceKey, object settings)
|
||||
{
|
||||
try
|
||||
@@ -98,9 +89,6 @@ namespace PepperDash.Core.Logging
|
||||
/// </summary>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetDebugSettingsForKey method
|
||||
/// </summary>
|
||||
public object GetDebugSettingsForKey(string deviceKey)
|
||||
{
|
||||
return DeviceDebugSettings[deviceKey];
|
||||
@@ -124,4 +112,3 @@ namespace PepperDash.Core.Logging
|
||||
[JsonProperty("doNotLoadOnNextBoot")]
|
||||
public bool DoNotLoadOnNextBoot { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Crestron.SimplSharp;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Serilog;
|
||||
using Serilog.Configuration;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Serilog.Configuration;
|
||||
using WebSocketSharp.Server;
|
||||
using Crestron.SimplSharp;
|
||||
using WebSocketSharp;
|
||||
using System.Security.Authentication;
|
||||
using WebSocketSharp.Net;
|
||||
using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2;
|
||||
using System.IO;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Serilog.Formatting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog.Formatting.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Authentication;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a WebSocket-based logging sink for debugging purposes, allowing log events to be broadcast to connected
|
||||
/// WebSocket clients.
|
||||
/// </summary>
|
||||
/// <remarks>This class implements the <see cref="ILogEventSink"/> interface and is designed to send
|
||||
/// formatted log events to WebSocket clients connected to a secure WebSocket server. The server is hosted locally
|
||||
/// and uses a self-signed certificate for SSL/TLS encryption.</remarks>
|
||||
public class DebugWebsocketSink : ILogEventSink, IKeyed
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DebugWebsocketSink
|
||||
/// </summary>
|
||||
public class DebugWebsocketSink : ILogEventSink
|
||||
{
|
||||
private HttpServer _httpsServer;
|
||||
|
||||
private string _path = "/debug/join/";
|
||||
private readonly string _path = "/debug/join/";
|
||||
private const string _certificateName = "selfCres";
|
||||
private const string _certificatePassword = "cres12345";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the port number on which the HTTPS server is currently running.
|
||||
/// </summary>
|
||||
public int Port
|
||||
{ get
|
||||
{
|
||||
@@ -41,6 +42,11 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSocket URL for the current server instance.
|
||||
/// </summary>
|
||||
/// <remarks>The URL is dynamically constructed based on the server's current IP address, port,
|
||||
/// and WebSocket path.</remarks>
|
||||
public string Url
|
||||
{
|
||||
get
|
||||
@@ -51,20 +57,30 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IsRunning
|
||||
/// Gets a value indicating whether the HTTPS server is currently listening for incoming connections.
|
||||
/// </summary>
|
||||
public bool IsRunning { get => _httpsServer?.IsListening ?? false; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Key => "DebugWebsocketSink";
|
||||
|
||||
private readonly ITextFormatter _textFormatter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DebugWebsocketSink"/> class with the specified text formatter.
|
||||
/// </summary>
|
||||
/// <remarks>This constructor initializes the WebSocket sink and ensures that a certificate is
|
||||
/// available for secure communication. If the required certificate does not exist, it will be created
|
||||
/// automatically. Additionally, the sink is configured to stop the server when the program is
|
||||
/// stopping.</remarks>
|
||||
/// <param name="formatProvider">The text formatter used to format log messages. If null, a default JSON formatter is used.</param>
|
||||
public DebugWebsocketSink(ITextFormatter formatProvider)
|
||||
{
|
||||
|
||||
_textFormatter = formatProvider ?? new JsonFormatter();
|
||||
|
||||
if (!File.Exists($"\\user\\{_certificateName}.pfx"))
|
||||
CreateCert(null);
|
||||
CreateCert();
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler += type =>
|
||||
{
|
||||
@@ -75,45 +91,41 @@ namespace PepperDash.Core
|
||||
};
|
||||
}
|
||||
|
||||
private void CreateCert(string[] args)
|
||||
private static void CreateCert()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Debug.Console(0,"CreateCert Creating Utility");
|
||||
CrestronConsole.PrintLine("CreateCert Creating Utility");
|
||||
//var utility = new CertificateUtility();
|
||||
var utility = new BouncyCertificate();
|
||||
//Debug.Console(0, "CreateCert Calling CreateCert");
|
||||
CrestronConsole.PrintLine("CreateCert Calling CreateCert");
|
||||
//utility.CreateCert();
|
||||
|
||||
var ipAddress = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
var hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||
var domainName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, 0);
|
||||
|
||||
//Debug.Console(0, "DomainName: {0} | HostName: {1} | {1}.{0}@{2}", domainName, hostName, ipAddress);
|
||||
CrestronConsole.PrintLine(string.Format("DomainName: {0} | HostName: {1} | {1}.{0}@{2}", domainName, hostName, ipAddress));
|
||||
|
||||
var certificate = utility.CreateSelfSignedCertificate(string.Format("CN={0}.{1}", hostName, domainName), new[] { string.Format("{0}.{1}", hostName, domainName), ipAddress }, new[] { KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth });
|
||||
var certificate = utility.CreateSelfSignedCertificate(string.Format("CN={0}.{1}", hostName, domainName), [string.Format("{0}.{1}", hostName, domainName), ipAddress], [KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth]);
|
||||
|
||||
//Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested
|
||||
//Debug.Print($"CreateCert Storing Certificate To My.LocalMachine");
|
||||
//utility.AddCertToStore(certificate, StoreName.My, StoreLocation.LocalMachine);
|
||||
//Debug.Console(0, "CreateCert Saving Cert to \\user\\");
|
||||
CrestronConsole.PrintLine("CreateCert Saving Cert to \\user\\");
|
||||
|
||||
var separator = Path.DirectorySeparatorChar;
|
||||
|
||||
utility.CertificatePassword = _certificatePassword;
|
||||
utility.WriteCertificate(certificate, @"\user\", _certificateName);
|
||||
//Debug.Console(0, "CreateCert Ending CreateCert");
|
||||
CrestronConsole.PrintLine("CreateCert Ending CreateCert");
|
||||
utility.WriteCertificate(certificate, @$"{separator}user{separator}", _certificateName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Debug.Console(0, "WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace);
|
||||
CrestronConsole.PrintLine(string.Format("WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace));
|
||||
CrestronConsole.PrintLine("WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emit method
|
||||
/// Sends a log event to all connected WebSocket clients.
|
||||
/// </summary>
|
||||
/// <remarks>The log event is formatted using the configured text formatter and then broadcasted
|
||||
/// to all clients connected to the WebSocket server. If the WebSocket server is not initialized or not
|
||||
/// listening, the method exits without performing any action.</remarks>
|
||||
/// <param name="logEvent">The log event to be formatted and broadcasted. Cannot be null.</param>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
if (_httpsServer == null || !_httpsServer.IsListening) return;
|
||||
@@ -121,13 +133,16 @@ namespace PepperDash.Core
|
||||
var sw = new StringWriter();
|
||||
_textFormatter.Format(logEvent, sw);
|
||||
|
||||
_httpsServer.WebSocketServices.Broadcast(sw.ToString());
|
||||
|
||||
_httpsServer.WebSocketServices[_path].Sessions.Broadcast(sw.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// StartServerAndSetPort method
|
||||
/// Starts the WebSocket server on the specified port and configures it with the appropriate certificate.
|
||||
/// </summary>
|
||||
/// <remarks>This method initializes the WebSocket server and binds it to the specified port. It
|
||||
/// also applies the server's certificate for secure communication. Ensure that the port is not already in use
|
||||
/// and that the certificate file is accessible.</remarks>
|
||||
/// <param name="port">The port number on which the WebSocket server will listen. Must be a valid, non-negative port number.</param>
|
||||
public void StartServerAndSetPort(int port)
|
||||
{
|
||||
Debug.Console(0, "Starting Websocket Server on port: {0}", port);
|
||||
@@ -142,21 +157,19 @@ namespace PepperDash.Core
|
||||
{
|
||||
_httpsServer = new HttpServer(port, true);
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(certPath))
|
||||
{
|
||||
Debug.Console(0, "Assigning SSL Configuration");
|
||||
_httpsServer.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(certPath, certPassword))
|
||||
{
|
||||
ClientCertificateRequired = false,
|
||||
CheckCertificateRevocation = false,
|
||||
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls,
|
||||
|
||||
_httpsServer.SslConfiguration.ServerCertificate = new X509Certificate2(certPath, certPassword);
|
||||
_httpsServer.SslConfiguration.ClientCertificateRequired = false;
|
||||
_httpsServer.SslConfiguration.CheckCertificateRevocation = false;
|
||||
_httpsServer.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
|
||||
//this is just to test, you might want to actually validate
|
||||
ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
_httpsServer.SslConfiguration.ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
Debug.Console(0, "HTTPS ClientCerticateValidation Callback triggered");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
Debug.Console(0, "Adding Debug Client Service");
|
||||
@@ -206,8 +219,10 @@ namespace PepperDash.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// StopServer method
|
||||
/// Stops the WebSocket server if it is currently running.
|
||||
/// </summary>
|
||||
/// <remarks>This method halts the WebSocket server and releases any associated resources. After
|
||||
/// calling this method, the server will no longer accept or process incoming connections.</remarks>
|
||||
public void StopServer()
|
||||
{
|
||||
Debug.Console(0, "Stopping Websocket Server");
|
||||
@@ -215,28 +230,45 @@ namespace PepperDash.Core
|
||||
|
||||
_httpsServer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DebugWebsocketSinkExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the logger to write log events to a debug WebSocket sink.
|
||||
/// </summary>
|
||||
/// <remarks>This extension method allows you to direct log events to a WebSocket sink for debugging
|
||||
/// purposes.</remarks>
|
||||
public static class DebugWebsocketSinkExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// DebugWebsocketSink method
|
||||
/// Configures a logger to write log events to a debug WebSocket sink.
|
||||
/// </summary>
|
||||
/// <remarks>This method adds a sink that writes log events to a WebSocket for debugging purposes.
|
||||
/// It is typically used during development to stream log events in real-time.</remarks>
|
||||
/// <param name="loggerConfiguration">The logger sink configuration to apply the WebSocket sink to.</param>
|
||||
/// <param name="formatProvider">An optional text formatter to format the log events. If not provided, a default formatter will be used.</param>
|
||||
/// <returns>A <see cref="LoggerConfiguration"/> object that can be used to further configure the logger.</returns>
|
||||
public static LoggerConfiguration DebugWebsocketSink(
|
||||
this LoggerSinkConfiguration loggerConfiguration,
|
||||
ITextFormatter formatProvider = null)
|
||||
{
|
||||
return loggerConfiguration.Sink(new DebugWebsocketSink(formatProvider));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a DebugClient
|
||||
/// </summary>
|
||||
public class DebugClient : WebSocketBehavior
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a WebSocket client for debugging purposes, providing connection lifecycle management and message
|
||||
/// handling functionality.
|
||||
/// </summary>
|
||||
/// <remarks>The <see cref="DebugClient"/> class extends <see cref="WebSocketBehavior"/> to handle
|
||||
/// WebSocket connections, including events for opening, closing, receiving messages, and errors. It tracks the
|
||||
/// duration of the connection and logs relevant events for debugging.</remarks>
|
||||
public class DebugClient : WebSocketBehavior
|
||||
{
|
||||
private DateTime _connectionTime;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the duration of time the WebSocket connection has been active.
|
||||
/// </summary>
|
||||
public TimeSpan ConnectedDuration
|
||||
{
|
||||
get
|
||||
@@ -252,11 +284,17 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DebugClient"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>This constructor creates a new <see cref="DebugClient"/> instance and logs its
|
||||
/// creation using the <see cref="Debug.Console(int, string)"/> method with a debug level of 0.</remarks>
|
||||
public DebugClient()
|
||||
{
|
||||
Debug.Console(0, "DebugClient Created");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnOpen()
|
||||
{
|
||||
base.OnOpen();
|
||||
@@ -267,6 +305,7 @@ namespace PepperDash.Core
|
||||
_connectionTime = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnMessage(MessageEventArgs e)
|
||||
{
|
||||
base.OnMessage(e);
|
||||
@@ -274,6 +313,7 @@ namespace PepperDash.Core
|
||||
Debug.Console(0, "WebSocket UiClient Message: {0}", e.Data);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnClose(CloseEventArgs e)
|
||||
{
|
||||
base.OnClose(e);
|
||||
@@ -282,11 +322,11 @@ namespace PepperDash.Core
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
|
||||
{
|
||||
base.OnError(e);
|
||||
|
||||
Debug.Console(2, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Error: {0} message: {1}", e.Exception, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Not in use
|
||||
/// </summary>
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Not in use
|
||||
/// </summary>
|
||||
public static class NetworkComm
|
||||
{
|
||||
/// <summary>
|
||||
@@ -18,5 +18,3 @@ namespace PepperDash.Core
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.PasswordManagement
|
||||
{
|
||||
namespace PepperDash.Core.PasswordManagement;
|
||||
|
||||
/// <summary>
|
||||
/// JSON password configuration
|
||||
/// </summary>
|
||||
@@ -23,4 +23,3 @@ namespace PepperDash.Core.PasswordManagement
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.PasswordManagement
|
||||
{
|
||||
namespace PepperDash.Core.PasswordManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Constants
|
||||
/// </summary>
|
||||
@@ -54,4 +54,3 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// </summary>
|
||||
public const ushort StringValueChange = 201;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core.PasswordManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a PasswordClient
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.PasswordManagement;
|
||||
|
||||
/// <summary>
|
||||
/// A class to allow user interaction with the PasswordManager
|
||||
/// </summary>
|
||||
public class PasswordClient
|
||||
{
|
||||
/// <summary>
|
||||
@@ -59,9 +59,6 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// Retrieve password by index
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <summary>
|
||||
/// GetPasswordByIndex method
|
||||
/// </summary>
|
||||
public void GetPasswordByIndex(ushort key)
|
||||
{
|
||||
OnUshrtChange((ushort)PasswordManager.Passwords.Count, 0, PasswordManagementConstants.PasswordManagerCountChange);
|
||||
@@ -84,9 +81,6 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// Password validation method
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <summary>
|
||||
/// ValidatePassword method
|
||||
/// </summary>
|
||||
public void ValidatePassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
@@ -105,9 +99,6 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// password against the selected password when the length of the 2 are equal
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <summary>
|
||||
/// BuildPassword method
|
||||
/// </summary>
|
||||
public void BuildPassword(string data)
|
||||
{
|
||||
PasswordToValidate = String.Concat(PasswordToValidate, data);
|
||||
@@ -118,7 +109,7 @@ namespace PepperDash.Core.PasswordManagement
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ClearPassword method
|
||||
/// Clears the user entered password and resets the LEDs
|
||||
/// </summary>
|
||||
public void ClearPassword()
|
||||
{
|
||||
@@ -193,4 +184,3 @@ namespace PepperDash.Core.PasswordManagement
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.PasswordManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a PasswordManager
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.PasswordManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Allows passwords to be stored and managed
|
||||
/// </summary>
|
||||
public class PasswordManager
|
||||
{
|
||||
/// <summary>
|
||||
@@ -71,9 +71,6 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <summary>
|
||||
/// UpdatePassword method
|
||||
/// </summary>
|
||||
public void UpdatePassword(ushort key, string password)
|
||||
{
|
||||
// validate the parameters
|
||||
@@ -155,9 +152,6 @@ namespace PepperDash.Core.PasswordManagement
|
||||
/// Method to change the default timer value, (default 5000ms/5s)
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <summary>
|
||||
/// PasswordTimerMs method
|
||||
/// </summary>
|
||||
public void PasswordTimerMs(ushort time)
|
||||
{
|
||||
PasswordTimerElapsedMs = Convert.ToInt64(time);
|
||||
@@ -244,4 +238,3 @@ namespace PepperDash.Core.PasswordManagement
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<PropertyGroup>
|
||||
<RootNamespace>PepperDash.Core</RootNamespace>
|
||||
<AssemblyName>PepperDashCore</AssemblyName>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<TargetFramework>net8</TargetFramework>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
@@ -42,15 +42,16 @@
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
||||
<PackageReference Include="Crestron.SimplSharp.SDK.Library" Version="2.21.90" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" />
|
||||
<PackageReference Include="Crestron.SimplSharp.SDK.Library" Version="2.21.128" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
||||
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6'">
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.SystemInfo
|
||||
{
|
||||
namespace PepperDash.Core.SystemInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Constants
|
||||
/// </summary>
|
||||
@@ -69,7 +69,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a ProcessorChangeEventArgs
|
||||
/// Processor Change Event Args Class
|
||||
/// </summary>
|
||||
public class ProcessorChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -115,7 +115,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EthernetChangeEventArgs
|
||||
/// Ethernet Change Event Args Class
|
||||
/// </summary>
|
||||
public class EthernetChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -166,7 +166,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a ControlSubnetChangeEventArgs
|
||||
/// Control Subnet Chage Event Args Class
|
||||
/// </summary>
|
||||
public class ControlSubnetChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -212,7 +212,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a ProgramChangeEventArgs
|
||||
/// Program Change Event Args Class
|
||||
/// </summary>
|
||||
public class ProgramChangeEventArgs : EventArgs
|
||||
{
|
||||
@@ -261,4 +261,3 @@ namespace PepperDash.Core.SystemInfo
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.SystemInfo
|
||||
{
|
||||
namespace PepperDash.Core.SystemInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Processor info class
|
||||
/// </summary>
|
||||
@@ -201,4 +201,3 @@ namespace PepperDash.Core.SystemInfo
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.SystemInfo
|
||||
{
|
||||
namespace PepperDash.Core.SystemInfo;
|
||||
|
||||
/// <summary>
|
||||
/// System Info class
|
||||
/// </summary>
|
||||
@@ -101,7 +101,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetEthernetInfo method
|
||||
/// Gets the current ethernet info
|
||||
/// </summary>
|
||||
public void GetEthernetInfo()
|
||||
{
|
||||
@@ -162,7 +162,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetControlSubnetInfo method
|
||||
/// Gets the current control subnet info
|
||||
/// </summary>
|
||||
public void GetControlSubnetInfo()
|
||||
{
|
||||
@@ -206,9 +206,6 @@ namespace PepperDash.Core.SystemInfo
|
||||
/// Gets the program info by index
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <summary>
|
||||
/// GetProgramInfoByIndex method
|
||||
/// </summary>
|
||||
public void GetProgramInfoByIndex(ushort index)
|
||||
{
|
||||
if (index < 1 || index > 10)
|
||||
@@ -267,7 +264,7 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RefreshProcessorUptime method
|
||||
/// Gets the processor uptime and passes it to S+
|
||||
/// </summary>
|
||||
public void RefreshProcessorUptime()
|
||||
{
|
||||
@@ -290,9 +287,6 @@ namespace PepperDash.Core.SystemInfo
|
||||
/// Gets the program uptime, by index, and passes it to S+
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <summary>
|
||||
/// RefreshProgramUptimeByIndex method
|
||||
/// </summary>
|
||||
public void RefreshProgramUptimeByIndex(int index)
|
||||
{
|
||||
try
|
||||
@@ -314,9 +308,6 @@ namespace PepperDash.Core.SystemInfo
|
||||
/// Sends command to console, passes response back using string change event
|
||||
/// </summary>
|
||||
/// <param name="cmd"></param>
|
||||
/// <summary>
|
||||
/// SendConsoleCommand method
|
||||
/// </summary>
|
||||
public void SendConsoleCommand(string cmd)
|
||||
{
|
||||
if (string.IsNullOrEmpty(cmd))
|
||||
@@ -468,4 +459,3 @@ namespace PepperDash.Core.SystemInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,13 @@ using Org.BouncyCastle.Crypto.Operators;
|
||||
using BigInteger = Org.BouncyCastle.Math.BigInteger;
|
||||
using X509Certificate = Org.BouncyCastle.X509.X509Certificate;
|
||||
|
||||
namespace PepperDash.Core
|
||||
namespace PepperDash.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Taken From https://github.com/rlipscombe/bouncy-castle-csharp/
|
||||
/// </summary>
|
||||
internal class BouncyCertificate
|
||||
{
|
||||
/// <summary>
|
||||
/// Taken From https://github.com/rlipscombe/bouncy-castle-csharp/
|
||||
/// </summary>
|
||||
internal class BouncyCertificate
|
||||
{
|
||||
public string CertificatePassword { get; set; } = "password";
|
||||
public X509Certificate2 LoadCertificate(string issuerFileName, string password)
|
||||
{
|
||||
@@ -35,9 +35,6 @@ namespace PepperDash.Core
|
||||
return issuerCertificate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IssueCertificate method
|
||||
/// </summary>
|
||||
public X509Certificate2 IssueCertificate(string subjectName, X509Certificate2 issuerCertificate, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||
{
|
||||
// It's self-signed, so these are the same.
|
||||
@@ -59,9 +56,6 @@ namespace PepperDash.Core
|
||||
return ConvertCertificate(certificate, subjectKeyPair, random);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CreateCertificateAuthorityCertificate method
|
||||
/// </summary>
|
||||
public X509Certificate2 CreateCertificateAuthorityCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||
{
|
||||
// It's self-signed, so these are the same.
|
||||
@@ -84,9 +78,6 @@ namespace PepperDash.Core
|
||||
return ConvertCertificate(certificate, subjectKeyPair, random);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CreateSelfSignedCertificate method
|
||||
/// </summary>
|
||||
public X509Certificate2 CreateSelfSignedCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||
{
|
||||
// It's self-signed, so these are the same.
|
||||
@@ -314,9 +305,6 @@ namespace PepperDash.Core
|
||||
return convertedCertificate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WriteCertificate method
|
||||
/// </summary>
|
||||
public void WriteCertificate(X509Certificate2 certificate, string outputDirectory, string certName)
|
||||
{
|
||||
// This password is the one attached to the PFX file. Use 'null' for no password.
|
||||
@@ -344,9 +332,6 @@ namespace PepperDash.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// AddCertToStore method
|
||||
/// </summary>
|
||||
public bool AddCertToStore(X509Certificate2 cert, System.Security.Cryptography.X509Certificates.StoreName st, System.Security.Cryptography.X509Certificates.StoreLocation sl)
|
||||
{
|
||||
bool bRet = false;
|
||||
@@ -367,5 +352,4 @@ namespace PepperDash.Core
|
||||
|
||||
return bRet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
|
||||
namespace PepperDash.Core.Web.RequestHandlers
|
||||
{
|
||||
namespace PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a DefaultRequestHandler
|
||||
/// Web API default request handler
|
||||
/// </summary>
|
||||
public class DefaultRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
@@ -14,4 +14,3 @@ namespace PepperDash.Core.Web.RequestHandlers
|
||||
: base(true)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PepperDash.Core.Web.RequestHandlers
|
||||
namespace PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
public abstract class WebApiBaseRequestAsyncHandler:IHttpCwsHandler
|
||||
{
|
||||
public abstract class WebApiBaseRequestAsyncHandler:IHttpCwsHandler
|
||||
{
|
||||
private readonly Dictionary<string, Func<HttpCwsContext, Task>> _handlers;
|
||||
protected readonly bool EnableCors;
|
||||
|
||||
@@ -142,9 +142,6 @@ namespace PepperDash.Core.Web.RequestHandlers
|
||||
/// Process request
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <summary>
|
||||
/// ProcessRequest method
|
||||
/// </summary>
|
||||
public void ProcessRequest(HttpCwsContext context)
|
||||
{
|
||||
if (!_handlers.TryGetValue(context.Request.HttpMethod, out Func<HttpCwsContext, Task> handler))
|
||||
@@ -162,5 +159,4 @@ namespace PepperDash.Core.Web.RequestHandlers
|
||||
|
||||
handlerTask.GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
|
||||
namespace PepperDash.Core.Web.RequestHandlers
|
||||
{
|
||||
namespace PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// CWS Base Handler, implements IHttpCwsHandler
|
||||
/// </summary>
|
||||
@@ -144,9 +144,6 @@ namespace PepperDash.Core.Web.RequestHandlers
|
||||
/// Process request
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <summary>
|
||||
/// ProcessRequest method
|
||||
/// </summary>
|
||||
public void ProcessRequest(HttpCwsContext context)
|
||||
{
|
||||
Action<HttpCwsContext> handler;
|
||||
@@ -165,4 +162,3 @@ namespace PepperDash.Core.Web.RequestHandlers
|
||||
handler(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Core.Web
|
||||
{
|
||||
namespace PepperDash.Core.Web;
|
||||
|
||||
/// <summary>
|
||||
/// Web API server
|
||||
/// </summary>
|
||||
@@ -26,22 +26,22 @@ namespace PepperDash.Core.Web
|
||||
private HttpCwsServer _server;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Key
|
||||
/// Web API server key
|
||||
/// </summary>
|
||||
public string Key { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name
|
||||
/// Web API server name
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the BasePath
|
||||
/// CWS base path, will default to "/api" if not set via initialize method
|
||||
/// </summary>
|
||||
public string BasePath { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IsRegistered
|
||||
/// Indicates CWS is registered with base path
|
||||
/// </summary>
|
||||
public bool IsRegistered { get; private set; }
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace PepperDash.Core.Web
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize method
|
||||
/// Initializes CWS class
|
||||
/// </summary>
|
||||
public void Initialize(string key, string basePath)
|
||||
{
|
||||
@@ -165,9 +165,6 @@ namespace PepperDash.Core.Web
|
||||
/// Removes a route from CWS
|
||||
/// </summary>
|
||||
/// <param name="route"></param>
|
||||
/// <summary>
|
||||
/// RemoveRoute method
|
||||
/// </summary>
|
||||
public void RemoveRoute(HttpCwsRoute route)
|
||||
{
|
||||
if (route == null)
|
||||
@@ -180,7 +177,7 @@ namespace PepperDash.Core.Web
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetRouteCollection method
|
||||
/// Returns a list of the current routes
|
||||
/// </summary>
|
||||
public HttpCwsRouteCollection GetRouteCollection()
|
||||
{
|
||||
@@ -226,7 +223,7 @@ namespace PepperDash.Core.Web
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop method
|
||||
/// Stop CWS instance
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
@@ -284,4 +281,3 @@ namespace PepperDash.Core.Web
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core.WebApi.Presets
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Preset
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.WebApi.Presets;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a preset
|
||||
/// </summary>
|
||||
public class Preset
|
||||
{
|
||||
/// <summary>
|
||||
@@ -13,27 +13,27 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the UserId
|
||||
/// User ID
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RoomTypeId
|
||||
/// Room Type ID
|
||||
/// </summary>
|
||||
public int RoomTypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PresetName
|
||||
/// Preset Name
|
||||
/// </summary>
|
||||
public string PresetName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PresetNumber
|
||||
/// Preset Number
|
||||
/// </summary>
|
||||
public int PresetNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Data
|
||||
/// Preset Data
|
||||
/// </summary>
|
||||
public string Data { get; set; }
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a PresetReceivedEventArgs
|
||||
///
|
||||
/// </summary>
|
||||
public class PresetReceivedEventArgs : EventArgs
|
||||
{
|
||||
@@ -59,12 +59,12 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public bool LookupSuccess { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ULookupSuccess
|
||||
/// S+ helper
|
||||
/// </summary>
|
||||
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Preset
|
||||
/// The preset
|
||||
/// </summary>
|
||||
public Preset Preset { get; private set; }
|
||||
|
||||
@@ -84,4 +84,3 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
Preset = preset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.WebApi.Presets
|
||||
{
|
||||
namespace PepperDash.Core.WebApi.Presets;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -17,17 +17,17 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ExternalId
|
||||
///
|
||||
/// </summary>
|
||||
public string ExternalId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the FirstName
|
||||
///
|
||||
/// </summary>
|
||||
public string FirstName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the LastName
|
||||
///
|
||||
/// </summary>
|
||||
public string LastName { get; set; }
|
||||
}
|
||||
@@ -44,12 +44,12 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public bool LookupSuccess { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ULookupSuccess
|
||||
/// For stupid S+
|
||||
/// </summary>
|
||||
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the User
|
||||
///
|
||||
/// </summary>
|
||||
public User User { get; private set; }
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a UserAndRoomMessage
|
||||
///
|
||||
/// </summary>
|
||||
public class UserAndRoomMessage
|
||||
{
|
||||
@@ -81,13 +81,12 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RoomTypeId
|
||||
///
|
||||
/// </summary>
|
||||
public int RoomTypeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the PresetNumber
|
||||
///
|
||||
/// </summary>
|
||||
public int PresetNumber { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core.JsonToSimpl;
|
||||
|
||||
|
||||
namespace PepperDash.Core.WebApi.Presets
|
||||
{
|
||||
/// <summary>
|
||||
/// Passcode client for the WebApi
|
||||
/// </summary>
|
||||
namespace PepperDash.Core.WebApi.Presets;
|
||||
|
||||
/// <summary>
|
||||
/// Passcode client for the WebApi
|
||||
/// </summary>
|
||||
public class WebApiPasscodeClient : IKeyed
|
||||
{
|
||||
/// <summary>
|
||||
@@ -26,7 +26,7 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
public event EventHandler<PresetReceivedEventArgs> PresetReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Key
|
||||
/// Unique identifier for this instance
|
||||
/// </summary>
|
||||
public string Key { get; private set; }
|
||||
|
||||
@@ -77,9 +77,6 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
/// Gets the user for a passcode
|
||||
/// </summary>
|
||||
/// <param name="passcode"></param>
|
||||
/// <summary>
|
||||
/// GetUserForPasscode method
|
||||
/// </summary>
|
||||
public void GetUserForPasscode(string passcode)
|
||||
{
|
||||
// Bullshit duplicate code here... These two cases should be the same
|
||||
@@ -118,9 +115,6 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
/// </summary>
|
||||
/// <param name="roomTypeId"></param>
|
||||
/// <param name="presetNumber"></param>
|
||||
/// <summary>
|
||||
/// GetPresetForThisUser method
|
||||
/// </summary>
|
||||
public void GetPresetForThisUser(int roomTypeId, int presetNumber)
|
||||
{
|
||||
if (CurrentUser == null)
|
||||
@@ -218,9 +212,6 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
/// </summary>
|
||||
/// <param name="roomTypeId"></param>
|
||||
/// <param name="presetNumber"></param>
|
||||
/// <summary>
|
||||
/// SavePresetForThisUser method
|
||||
/// </summary>
|
||||
public void SavePresetForThisUser(int roomTypeId, int presetNumber)
|
||||
{
|
||||
if (CurrentPreset == null)
|
||||
@@ -279,4 +270,3 @@ namespace PepperDash.Core.WebApi.Presets
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
namespace PepperDash.Core.Intersystem.Serialization
|
||||
namespace PepperDash.Core.Intersystem.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface to determine XSig serialization for an object.
|
||||
/// </summary>
|
||||
public interface IXSigSerialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface to determine XSig serialization for an object.
|
||||
/// </summary>
|
||||
public interface IXSigSerialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialize the sig data
|
||||
/// </summary>
|
||||
@@ -21,5 +21,4 @@ namespace PepperDash.Core.Intersystem.Serialization
|
||||
/// <param name="tokens"></param>
|
||||
/// <returns></returns>
|
||||
T Deserialize<T>(IEnumerable<XSigToken> tokens) where T : class, IXSigSerialization;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core.Intersystem.Serialization
|
||||
namespace PepperDash.Core.Intersystem.Serialization;
|
||||
|
||||
/// <summary>
|
||||
/// Class to handle this specific exception type
|
||||
/// </summary>
|
||||
public class XSigSerializationException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to handle this specific exception type
|
||||
/// </summary>
|
||||
public class XSigSerializationException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
@@ -24,5 +24,4 @@ namespace PepperDash.Core.Intersystem.Serialization
|
||||
/// <param name="message"></param>
|
||||
/// <param name="inner"></param>
|
||||
public XSigSerializationException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core.Intersystem.Tokens
|
||||
namespace PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an XSigAnalogToken
|
||||
/// </summary>
|
||||
public sealed class XSigAnalogToken : XSigToken, IFormattable
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an XSigAnalogToken
|
||||
/// </summary>
|
||||
public sealed class XSigAnalogToken : XSigToken, IFormattable
|
||||
{
|
||||
private readonly ushort _value;
|
||||
|
||||
/// <summary>
|
||||
@@ -59,9 +59,6 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetTokenWithOffset method
|
||||
/// </summary>
|
||||
public override XSigToken GetTokenWithOffset(int offset)
|
||||
{
|
||||
if (offset == 0) return this;
|
||||
@@ -72,10 +69,6 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ToString method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return Index + " = 0x" + Value.ToString("X4");
|
||||
@@ -87,12 +80,8 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// <param name="format"></param>
|
||||
/// <param name="formatProvider"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ToString method
|
||||
/// </summary>
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
return Value.ToString(format, formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Core.Intersystem.Tokens
|
||||
namespace PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an XSigDigitalToken
|
||||
/// </summary>
|
||||
public sealed class XSigDigitalToken : XSigToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an XSigDigitalToken
|
||||
/// </summary>
|
||||
public sealed class XSigDigitalToken : XSigToken
|
||||
{
|
||||
private readonly bool _value;
|
||||
|
||||
/// <summary>
|
||||
@@ -57,9 +57,6 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetTokenWithOffset method
|
||||
/// </summary>
|
||||
public override XSigToken GetTokenWithOffset(int offset)
|
||||
{
|
||||
if (offset == 0) return this;
|
||||
@@ -70,10 +67,6 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ToString method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return Index + " = " + (Value ? "High" : "Low");
|
||||
@@ -84,12 +77,8 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// </summary>
|
||||
/// <param name="formatProvider"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ToString method
|
||||
/// </summary>
|
||||
public string ToString(IFormatProvider formatProvider)
|
||||
{
|
||||
return Value.ToString(formatProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace PepperDash.Core.Intersystem.Tokens
|
||||
namespace PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an XSigSerialToken
|
||||
/// </summary>
|
||||
public sealed class XSigSerialToken : XSigToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an XSigSerialToken
|
||||
/// </summary>
|
||||
public sealed class XSigSerialToken : XSigToken
|
||||
{
|
||||
private readonly string _value;
|
||||
|
||||
/// <summary>
|
||||
@@ -63,9 +63,6 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// GetTokenWithOffset method
|
||||
/// </summary>
|
||||
public override XSigToken GetTokenWithOffset(int offset)
|
||||
{
|
||||
if (offset == 0) return this;
|
||||
@@ -76,13 +73,8 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// ToString method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return Index + " = \"" + Value + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace PepperDash.Core.Intersystem.Tokens
|
||||
namespace PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the base class for all XSig datatypes.
|
||||
/// </summary>
|
||||
public abstract class XSigToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the base class for all XSig datatypes.
|
||||
/// </summary>
|
||||
public abstract class XSigToken
|
||||
{
|
||||
private readonly int _index;
|
||||
|
||||
/// <summary>
|
||||
@@ -41,5 +41,4 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// <param name="offset">Offset to adjust the index with.</param>
|
||||
/// <returns>XSigToken</returns>
|
||||
public abstract XSigToken GetTokenWithOffset(int offset);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace PepperDash.Core.Intersystem.Tokens
|
||||
namespace PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
/// <summary>
|
||||
/// XSig token types.
|
||||
/// </summary>
|
||||
public enum XSigTokenType
|
||||
{
|
||||
/// <summary>
|
||||
/// XSig token types.
|
||||
/// </summary>
|
||||
public enum XSigTokenType
|
||||
{
|
||||
/// <summary>
|
||||
/// Digital signal datatype.
|
||||
/// </summary>
|
||||
@@ -19,5 +19,4 @@ namespace PepperDash.Core.Intersystem.Tokens
|
||||
/// Serial signal datatype.
|
||||
/// </summary>
|
||||
Serial
|
||||
}
|
||||
}
|
||||
@@ -18,17 +18,17 @@ using PepperDash.Core.Intersystem.Tokens;
|
||||
11111111 <- denotes end of data
|
||||
*/
|
||||
|
||||
namespace PepperDash.Core.Intersystem
|
||||
namespace PepperDash.Core.Intersystem;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for creating XSig byte sequences compatible with the Intersystem Communications (ISC) symbol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Indexing is not from the start of each signal type but rather from the beginning of the first defined signal
|
||||
/// the Intersystem Communications (ISC) symbol.
|
||||
/// </remarks>
|
||||
public static class XSigHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for creating XSig byte sequences compatible with the Intersystem Communications (ISC) symbol.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Indexing is not from the start of each signal type but rather from the beginning of the first defined signal
|
||||
/// the Intersystem Communications (ISC) symbol.
|
||||
/// </remarks>
|
||||
public static class XSigHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Forces all outputs to 0.
|
||||
/// </summary>
|
||||
@@ -52,9 +52,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// </summary>
|
||||
/// <param name="xSigSerialization">XSig state resolver.</param>
|
||||
/// <returns>Bytes in XSig format for each token within the state representation.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(IXSigSerialization xSigSerialization)
|
||||
{
|
||||
return GetBytes(xSigSerialization, 0);
|
||||
@@ -66,9 +63,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="xSigSerialization">XSig state resolver.</param>
|
||||
/// <param name="offset">Offset to which the data will be aligned.</param>
|
||||
/// <returns>Bytes in XSig format for each token within the state representation.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(IXSigSerialization xSigSerialization, int offset)
|
||||
{
|
||||
var tokens = xSigSerialization.Serialize();
|
||||
@@ -88,9 +82,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="index">1-based digital index</param>
|
||||
/// <param name="value">Digital data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for digtial information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, bool value)
|
||||
{
|
||||
return GetBytes(index, 0, value);
|
||||
@@ -103,9 +94,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="value">Digital data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for digtial information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, int offset, bool value)
|
||||
{
|
||||
return new XSigDigitalToken(index + offset, value).GetBytes();
|
||||
@@ -117,9 +105,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="startIndex">Starting index of the sequence.</param>
|
||||
/// <param name="values">Digital signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for digital signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, bool[] values)
|
||||
{
|
||||
return GetBytes(startIndex, 0, values);
|
||||
@@ -132,9 +117,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="values">Digital signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for digital signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, int offset, bool[] values)
|
||||
{
|
||||
// Digital XSig data is 2 bytes per value
|
||||
@@ -152,9 +134,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="index">1-based analog index</param>
|
||||
/// <param name="value">Analog data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for analog signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, ushort value)
|
||||
{
|
||||
return GetBytes(index, 0, value);
|
||||
@@ -167,9 +146,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="value">Analog data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for analog signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, int offset, ushort value)
|
||||
{
|
||||
return new XSigAnalogToken(index + offset, value).GetBytes();
|
||||
@@ -181,9 +157,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="startIndex">Starting index of the sequence.</param>
|
||||
/// <param name="values">Analog signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for analog signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, ushort[] values)
|
||||
{
|
||||
return GetBytes(startIndex, 0, values);
|
||||
@@ -196,9 +169,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="values">Analog signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for analog signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, int offset, ushort[] values)
|
||||
{
|
||||
// Analog XSig data is 4 bytes per value
|
||||
@@ -216,9 +186,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="index">1-based serial index</param>
|
||||
/// <param name="value">Serial data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for serial signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, string value)
|
||||
{
|
||||
return GetBytes(index, 0, value);
|
||||
@@ -231,9 +198,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="value">Serial data to be encoded</param>
|
||||
/// <returns>Bytes in XSig format for serial signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int index, int offset, string value)
|
||||
{
|
||||
return new XSigSerialToken(index + offset, value).GetBytes();
|
||||
@@ -245,9 +209,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="startIndex">Starting index of the sequence.</param>
|
||||
/// <param name="values">Serial signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for serial signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, string[] values)
|
||||
{
|
||||
return GetBytes(startIndex, 0, values);
|
||||
@@ -260,9 +221,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="offset">Index offset.</param>
|
||||
/// <param name="values">Serial signal value array.</param>
|
||||
/// <returns>Byte sequence in XSig format for serial signal information.</returns>
|
||||
/// <summary>
|
||||
/// GetBytes method
|
||||
/// </summary>
|
||||
public static byte[] GetBytes(int startIndex, int offset, string[] values)
|
||||
{
|
||||
// Serial XSig data is not fixed-length like the other formats
|
||||
@@ -277,5 +235,4 @@ namespace PepperDash.Core.Intersystem
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ using Crestron.SimplSharp.CrestronIO;
|
||||
using PepperDash.Core.Intersystem.Serialization;
|
||||
using PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
namespace PepperDash.Core.Intersystem
|
||||
namespace PepperDash.Core.Intersystem;
|
||||
|
||||
/// <summary>
|
||||
/// XSigToken stream reader.
|
||||
/// </summary>
|
||||
public sealed class XSigTokenStreamReader : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// XSigToken stream reader.
|
||||
/// </summary>
|
||||
public sealed class XSigTokenStreamReader : IDisposable
|
||||
{
|
||||
private readonly Stream _stream;
|
||||
private readonly bool _leaveOpen;
|
||||
|
||||
@@ -48,9 +48,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// <param name="stream">Input stream</param>
|
||||
/// <param name="value">Result</param>
|
||||
/// <returns>True if successful, otherwise false.</returns>
|
||||
/// <summary>
|
||||
/// TryReadUInt16BE method
|
||||
/// </summary>
|
||||
public static bool TryReadUInt16BE(Stream stream, out ushort value)
|
||||
{
|
||||
value = 0;
|
||||
@@ -68,9 +65,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// </summary>
|
||||
/// <returns>XSigToken</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Offset is less than 0.</exception>
|
||||
/// <summary>
|
||||
/// ReadXSigToken method
|
||||
/// </summary>
|
||||
public XSigToken ReadXSigToken()
|
||||
{
|
||||
ushort prefix;
|
||||
@@ -120,9 +114,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// Reads all available XSig tokens from the stream.
|
||||
/// </summary>
|
||||
/// <returns>XSigToken collection.</returns>
|
||||
/// <summary>
|
||||
/// ReadAllXSigTokens method
|
||||
/// </summary>
|
||||
public IEnumerable<XSigToken> ReadAllXSigTokens()
|
||||
{
|
||||
var tokens = new List<XSigToken>();
|
||||
@@ -152,5 +143,4 @@ namespace PepperDash.Core.Intersystem
|
||||
if (!_leaveOpen)
|
||||
_stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,13 @@ using Crestron.SimplSharp.CrestronIO;
|
||||
using PepperDash.Core.Intersystem.Serialization;
|
||||
using PepperDash.Core.Intersystem.Tokens;
|
||||
|
||||
namespace PepperDash.Core.Intersystem
|
||||
namespace PepperDash.Core.Intersystem;
|
||||
|
||||
/// <summary>
|
||||
/// XSigToken stream writer.
|
||||
/// </summary>
|
||||
public sealed class XSigTokenStreamWriter : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// XSigToken stream writer.
|
||||
/// </summary>
|
||||
public sealed class XSigTokenStreamWriter : IDisposable
|
||||
{
|
||||
private readonly Stream _stream;
|
||||
private readonly bool _leaveOpen;
|
||||
|
||||
@@ -47,9 +47,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// Write XSig data gathered from an IXSigStateResolver to the stream.
|
||||
/// </summary>
|
||||
/// <param name="xSigSerialization">IXSigStateResolver object.</param>
|
||||
/// <summary>
|
||||
/// WriteXSigData method
|
||||
/// </summary>
|
||||
public void WriteXSigData(IXSigSerialization xSigSerialization)
|
||||
{
|
||||
WriteXSigData(xSigSerialization, 0);
|
||||
@@ -60,9 +57,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// </summary>
|
||||
/// <param name="xSigSerialization">IXSigStateResolver object.</param>
|
||||
/// <param name="offset">Index offset for each XSigToken.</param>
|
||||
/// <summary>
|
||||
/// WriteXSigData method
|
||||
/// </summary>
|
||||
public void WriteXSigData(IXSigSerialization xSigSerialization, int offset)
|
||||
{
|
||||
if (xSigSerialization == null)
|
||||
@@ -76,9 +70,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// Write XSigToken to the stream.
|
||||
/// </summary>
|
||||
/// <param name="token">XSigToken object.</param>
|
||||
/// <summary>
|
||||
/// WriteXSigData method
|
||||
/// </summary>
|
||||
public void WriteXSigData(XSigToken token)
|
||||
{
|
||||
WriteXSigData(token, 0);
|
||||
@@ -89,9 +80,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// </summary>
|
||||
/// <param name="token">XSigToken object.</param>
|
||||
/// <param name="offset">Index offset for each XSigToken.</param>
|
||||
/// <summary>
|
||||
/// WriteXSigData method
|
||||
/// </summary>
|
||||
public void WriteXSigData(XSigToken token, int offset)
|
||||
{
|
||||
WriteXSigData(new[] { token }, offset);
|
||||
@@ -120,9 +108,6 @@ namespace PepperDash.Core.Intersystem
|
||||
/// </summary>
|
||||
/// <param name="tokens">XSigToken objects.</param>
|
||||
/// <param name="offset">Index offset for each XSigToken.</param>
|
||||
/// <summary>
|
||||
/// WriteXSigData method
|
||||
/// </summary>
|
||||
public void WriteXSigData(IEnumerable<XSigToken> tokens, int offset)
|
||||
{
|
||||
if (offset < 0)
|
||||
@@ -140,12 +125,11 @@ namespace PepperDash.Core.Intersystem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose method
|
||||
/// Disposes of the internal stream if specified to not leave open.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_leaveOpen)
|
||||
_stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharpPro;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adapter that wraps actual Crestron Control System for production use
|
||||
/// </summary>
|
||||
public class CrestronControlSystemAdapter : ICrestronControlSystem
|
||||
{
|
||||
private readonly CrestronControlSystem _controlSystem;
|
||||
private readonly Dictionary<uint, IRelayPort> _relayPorts;
|
||||
|
||||
public CrestronControlSystemAdapter(CrestronControlSystem controlSystem)
|
||||
{
|
||||
_controlSystem = controlSystem ?? throw new ArgumentNullException(nameof(controlSystem));
|
||||
_relayPorts = new Dictionary<uint, IRelayPort>();
|
||||
|
||||
if (_controlSystem.SupportsRelay)
|
||||
{
|
||||
for (uint i = 1; i <= (uint)_controlSystem.NumberOfRelayPorts; i++)
|
||||
{
|
||||
_relayPorts[i] = new RelayPortAdapter(_controlSystem.RelayPorts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsRelay => _controlSystem.SupportsRelay;
|
||||
public uint NumberOfRelayPorts => (uint)_controlSystem.NumberOfRelayPorts;
|
||||
public Dictionary<uint, IRelayPort> RelayPorts => _relayPorts;
|
||||
public string ProgramIdTag => "TestProgram"; // Simplified for now
|
||||
public string ControllerPrompt => _controlSystem.ControllerPrompt;
|
||||
public bool SupportsEthernet => _controlSystem.SupportsEthernet;
|
||||
public bool SupportsDigitalInput => _controlSystem.SupportsDigitalInput;
|
||||
public uint NumberOfDigitalInputPorts => (uint)_controlSystem.NumberOfDigitalInputPorts;
|
||||
public bool SupportsVersiPort => _controlSystem.SupportsVersiport;
|
||||
public uint NumberOfVersiPorts => (uint)_controlSystem.NumberOfVersiPorts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adapter for Crestron relay port
|
||||
/// </summary>
|
||||
public class RelayPortAdapter : IRelayPort
|
||||
{
|
||||
private readonly Crestron.SimplSharpPro.Relay _relay;
|
||||
|
||||
public RelayPortAdapter(Crestron.SimplSharpPro.Relay relay)
|
||||
{
|
||||
_relay = relay ?? throw new ArgumentNullException(nameof(relay));
|
||||
}
|
||||
|
||||
public void Open() => _relay.Open();
|
||||
public void Close() => _relay.Close();
|
||||
public void Pulse(int delayMs)
|
||||
{
|
||||
// Crestron Relay.Pulse() doesn't take parameters
|
||||
// We'll just call the basic Pulse method
|
||||
_relay.Close();
|
||||
System.Threading.Thread.Sleep(delayMs);
|
||||
_relay.Open();
|
||||
}
|
||||
public bool State => _relay.State;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adapter for Crestron digital input
|
||||
/// </summary>
|
||||
public class DigitalInputAdapter : IDigitalInput
|
||||
{
|
||||
private readonly Crestron.SimplSharpPro.DigitalInput _digitalInput;
|
||||
|
||||
public DigitalInputAdapter(Crestron.SimplSharpPro.DigitalInput digitalInput)
|
||||
{
|
||||
_digitalInput = digitalInput ?? throw new ArgumentNullException(nameof(digitalInput));
|
||||
_digitalInput.StateChange += OnStateChange;
|
||||
}
|
||||
|
||||
public bool State => _digitalInput.State;
|
||||
public event EventHandler<DigitalInputEventArgs> StateChange;
|
||||
|
||||
private void OnStateChange(DigitalInput digitalInput, Crestron.SimplSharpPro.DigitalInputEventArgs args)
|
||||
{
|
||||
StateChange?.Invoke(this, new Abstractions.DigitalInputEventArgs(args.State));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adapter for Crestron VersiPort
|
||||
/// </summary>
|
||||
public class VersiPortAdapter : IVersiPort
|
||||
{
|
||||
private readonly Crestron.SimplSharpPro.Versiport _versiPort;
|
||||
|
||||
public VersiPortAdapter(Crestron.SimplSharpPro.Versiport versiPort)
|
||||
{
|
||||
_versiPort = versiPort ?? throw new ArgumentNullException(nameof(versiPort));
|
||||
_versiPort.VersiportChange += OnVersiportChange;
|
||||
}
|
||||
|
||||
public bool DigitalIn => _versiPort.DigitalIn;
|
||||
public void SetDigitalOut(bool value) => _versiPort.DigitalOut = value;
|
||||
public ushort AnalogIn => _versiPort.AnalogIn;
|
||||
public event EventHandler<VersiPortEventArgs> VersiportChange;
|
||||
|
||||
private void OnVersiportChange(Versiport port, VersiportEventArgs args)
|
||||
{
|
||||
var eventType = args.Event == eVersiportEvent.DigitalInChange
|
||||
? VersiPortEventType.DigitalInChange
|
||||
: VersiPortEventType.AnalogInChange;
|
||||
|
||||
VersiportChange?.Invoke(this, new Abstractions.VersiPortEventArgs
|
||||
{
|
||||
EventType = eventType,
|
||||
Value = args.Event == eVersiportEvent.DigitalInChange ? (object)port.DigitalIn : port.AnalogIn
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstraction for Crestron Control System to enable unit testing
|
||||
/// </summary>
|
||||
public interface ICrestronControlSystem
|
||||
{
|
||||
bool SupportsRelay { get; }
|
||||
uint NumberOfRelayPorts { get; }
|
||||
Dictionary<uint, IRelayPort> RelayPorts { get; }
|
||||
string ProgramIdTag { get; }
|
||||
string ControllerPrompt { get; }
|
||||
bool SupportsEthernet { get; }
|
||||
bool SupportsDigitalInput { get; }
|
||||
uint NumberOfDigitalInputPorts { get; }
|
||||
bool SupportsVersiPort { get; }
|
||||
uint NumberOfVersiPorts { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstraction for relay port
|
||||
/// </summary>
|
||||
public interface IRelayPort
|
||||
{
|
||||
void Open();
|
||||
void Close();
|
||||
void Pulse(int delayMs);
|
||||
bool State { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstraction for digital input
|
||||
/// </summary>
|
||||
public interface IDigitalInput
|
||||
{
|
||||
bool State { get; }
|
||||
event EventHandler<DigitalInputEventArgs> StateChange;
|
||||
}
|
||||
|
||||
public class DigitalInputEventArgs : EventArgs
|
||||
{
|
||||
public bool State { get; set; }
|
||||
public DigitalInputEventArgs(bool state)
|
||||
{
|
||||
State = state;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstraction for VersiPort
|
||||
/// </summary>
|
||||
public interface IVersiPort
|
||||
{
|
||||
bool DigitalIn { get; }
|
||||
void SetDigitalOut(bool value);
|
||||
ushort AnalogIn { get; }
|
||||
event EventHandler<VersiPortEventArgs> VersiportChange;
|
||||
}
|
||||
|
||||
public class VersiPortEventArgs : EventArgs
|
||||
{
|
||||
public VersiPortEventType EventType { get; set; }
|
||||
public object Value { get; set; }
|
||||
}
|
||||
|
||||
public enum VersiPortEventType
|
||||
{
|
||||
DigitalInChange,
|
||||
AnalogInChange
|
||||
}
|
||||
}
|
||||
@@ -2,37 +2,39 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Crestron.SimplSharp;
|
||||
using System.Reflection;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using Serilog.Events;
|
||||
|
||||
//using PepperDash.Essentials.Devices.Common.Cameras;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for bridge API variants
|
||||
/// </summary>
|
||||
public abstract class BridgeApi : EssentialsDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for bridge API variants
|
||||
/// </summary>
|
||||
public abstract class BridgeApi : EssentialsDevice
|
||||
{
|
||||
protected BridgeApi(string key) :
|
||||
base(key)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EiscApiAdvanced
|
||||
/// </summary>
|
||||
public class EiscApiAdvanced : BridgeApi, ICommunicationMonitor
|
||||
{
|
||||
/// <summary>
|
||||
/// Bridge API using EISC
|
||||
/// </summary>
|
||||
public class EiscApiAdvanced : BridgeApi, ICommunicationMonitor
|
||||
{
|
||||
public EiscApiPropertiesConfig PropertiesConfig { get; private set; }
|
||||
|
||||
public Dictionary<string, JoinMapBaseAdvanced> JoinMaps { get; private set; }
|
||||
@@ -58,19 +60,12 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
AddPostActivationAction(RegisterEisc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CustomActivate method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override bool CustomActivate()
|
||||
{
|
||||
CommunicationMonitor.Start();
|
||||
return base.CustomActivate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivate method
|
||||
/// </summary>
|
||||
public override bool Deactivate()
|
||||
{
|
||||
CommunicationMonitor.Stop();
|
||||
@@ -128,9 +123,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
Debug.LogMessage(LogEventLevel.Debug, this, "EISC registration successful");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LinkRooms method
|
||||
/// </summary>
|
||||
public void LinkRooms()
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, this, "Linking Rooms...");
|
||||
@@ -161,9 +153,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// </summary>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <param name="joinMap"></param>
|
||||
/// <summary>
|
||||
/// AddJoinMap method
|
||||
/// </summary>
|
||||
public void AddJoinMap(string deviceKey, JoinMapBaseAdvanced joinMap)
|
||||
{
|
||||
if (!JoinMaps.ContainsKey(deviceKey))
|
||||
@@ -177,9 +166,8 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PrintJoinMaps method
|
||||
/// Prints all the join maps on this bridge
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public virtual void PrintJoinMaps()
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse("Join Maps for EISC IPID: {0}\r\n", Eisc.ID.ToString("X"));
|
||||
@@ -191,9 +179,8 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// MarkdownForBridge method
|
||||
/// Generates markdown for all join maps on this bridge
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public virtual void MarkdownForBridge(string bridgeKey)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Information, this, "Writing Joinmaps to files for EISC IPID: {0}", Eisc.ID.ToString("X"));
|
||||
@@ -209,9 +196,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// Prints the join map for a device by key
|
||||
/// </summary>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <summary>
|
||||
/// PrintJoinMapForDevice method
|
||||
/// </summary>
|
||||
public void PrintJoinMapForDevice(string deviceKey)
|
||||
{
|
||||
var joinMap = JoinMaps[deviceKey];
|
||||
@@ -229,9 +213,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// Prints the join map for a device by key
|
||||
/// </summary>
|
||||
/// <param name="deviceKey"></param>
|
||||
/// <summary>
|
||||
/// MarkdownJoinMapForDevice method
|
||||
/// </summary>
|
||||
public void MarkdownJoinMapForDevice(string deviceKey, string bridgeKey)
|
||||
{
|
||||
var joinMap = JoinMaps[deviceKey];
|
||||
@@ -252,9 +233,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// <param name="join"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <summary>
|
||||
/// ExecuteJoinAction method
|
||||
/// </summary>
|
||||
public void ExecuteJoinAction(uint join, string type, object state)
|
||||
{
|
||||
try
|
||||
@@ -340,102 +318,56 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
|
||||
#region Implementation of ICommunicationMonitor
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the CommunicationMonitor
|
||||
/// </summary>
|
||||
public StatusMonitorBase CommunicationMonitor { get; private set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EiscApiPropertiesConfig
|
||||
/// </summary>
|
||||
public class EiscApiPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Control
|
||||
/// </summary>
|
||||
public class EiscApiPropertiesConfig
|
||||
{
|
||||
[JsonProperty("control")]
|
||||
public EssentialsControlPropertiesConfig Control { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Devices
|
||||
/// </summary>
|
||||
[JsonProperty("devices")]
|
||||
public List<ApiDevicePropertiesConfig> Devices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Rooms
|
||||
/// </summary>
|
||||
[JsonProperty("rooms")]
|
||||
public List<ApiRoomPropertiesConfig> Rooms { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Represents a ApiDevicePropertiesConfig
|
||||
/// </summary>
|
||||
public class ApiDevicePropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DeviceKey
|
||||
/// </summary>
|
||||
[JsonProperty("deviceKey")]
|
||||
public string DeviceKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JoinStart
|
||||
/// </summary>
|
||||
[JsonProperty("joinStart")]
|
||||
public uint JoinStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JoinMapKey
|
||||
/// </summary>
|
||||
[JsonProperty("joinMapKey")]
|
||||
public string JoinMapKey { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a ApiRoomPropertiesConfig
|
||||
/// </summary>
|
||||
public class ApiRoomPropertiesConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the RoomKey
|
||||
/// </summary>
|
||||
[JsonProperty("roomKey")]
|
||||
public string RoomKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JoinStart
|
||||
/// </summary>
|
||||
[JsonProperty("joinStart")]
|
||||
public uint JoinStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the JoinMapKey
|
||||
/// </summary>
|
||||
[JsonProperty("joinMapKey")]
|
||||
public string JoinMapKey { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a EiscApiAdvancedFactory
|
||||
/// </summary>
|
||||
public class EiscApiAdvancedFactory : EssentialsDeviceFactory<EiscApiAdvanced>
|
||||
{
|
||||
public class EiscApiAdvancedFactory : EssentialsDeviceFactory<EiscApiAdvanced>
|
||||
{
|
||||
public EiscApiAdvancedFactory()
|
||||
{
|
||||
TypeNames = new List<string> { "eiscapiadv", "eiscapiadvanced", "eiscapiadvancedserver", "eiscapiadvancedclient", "vceiscapiadv", "vceiscapiadvanced" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BuildDevice method
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new EiscApiAdvanced Device");
|
||||
@@ -488,6 +420,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
|
||||
return new EiscApiAdvanced(dc, eisc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,13 @@ using Serilog.Events;
|
||||
|
||||
//using PepperDash.Essentials.Devices.Common.Cameras;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for bridges
|
||||
/// </summary>
|
||||
public static class BridgeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for bridges
|
||||
/// </summary>
|
||||
public static class BridgeHelper
|
||||
{
|
||||
public static void PrintJoinMap(string command)
|
||||
{
|
||||
var targets = command.Split(' ');
|
||||
@@ -34,9 +34,6 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
bridge.PrintJoinMaps();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// JoinmapMarkdown method
|
||||
/// </summary>
|
||||
public static void JoinmapMarkdown(string command)
|
||||
{
|
||||
var targets = command.Split(' ');
|
||||
@@ -64,6 +61,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
using Crestron.SimplSharpPro.DeviceSupport;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a device that uses JoinMapBaseAdvanced for its join map
|
||||
/// </summary>
|
||||
public interface IBridgeAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the contract for IBridgeAdvanced
|
||||
/// </summary>
|
||||
public interface IBridgeAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Links the bridge to the API using the provided trilist, join start, join map key, and bridge.
|
||||
/// </summary>
|
||||
/// <param name="trilist">The trilist to link to.</param>
|
||||
/// <param name="joinStart">The starting join number.</param>
|
||||
/// <param name="joinMapKey">The key for the join map.</param>
|
||||
/// <param name="bridge">The EISC API bridge.</param>
|
||||
void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class AirMediaControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a AirMediaControllerJoinMap
|
||||
/// </summary>
|
||||
public class AirMediaControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 },
|
||||
new JoinMetadata { Description = "Air Media Online", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital });
|
||||
@@ -70,5 +67,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// <param name="joinStart">Join this join map will start at</param>
|
||||
/// <param name="type">Type of the child join map</param>
|
||||
protected AirMediaControllerJoinMap(uint joinStart, Type type) : base(joinStart, type){}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class AppleTvJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a AppleTvJoinMap
|
||||
/// </summary>
|
||||
public class AppleTvJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("UpArrow")]
|
||||
public JoinDataComplete UpArrow = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 },
|
||||
new JoinMetadata { Description = "AppleTv Nav Up", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
|
||||
@@ -52,5 +49,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
public AppleTvJoinMap(uint joinStart, Type type) : base(joinStart, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class C2nRthsControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a C2nRthsControllerJoinMap
|
||||
/// </summary>
|
||||
public class C2nRthsControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 },
|
||||
new JoinMetadata { Description = "Temp Sensor Online", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Digital });
|
||||
@@ -44,5 +41,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
protected C2nRthsControllerJoinMap(uint joinStart, Type type) : base(joinStart, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
/// <summary>
|
||||
/// Join map for CameraBase devices
|
||||
/// </summary>
|
||||
public class CameraControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a CameraControllerJoinMap
|
||||
/// </summary>
|
||||
public class CameraControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("TiltUp")]
|
||||
public JoinDataComplete TiltUp = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 }, new JoinMetadata { Description = "Tilt Up", JoinCapabilities = eJoinCapabilities.FromSIMPL, JoinType = eJoinType.Digital });
|
||||
[JoinName("TiltDown")]
|
||||
@@ -65,5 +65,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
/// <param name="joinStart">Join this join map will start at</param>
|
||||
/// <param name="type">Type of the child join map</param>
|
||||
protected CameraControllerJoinMap(uint joinStart, Type type) : base(joinStart, type){}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class CenOdtOccupancySensorBaseJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a CenOdtOccupancySensorBaseJoinMap
|
||||
/// </summary>
|
||||
public class CenOdtOccupancySensorBaseJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
#region Digitals
|
||||
|
||||
[JoinName("Online")]
|
||||
@@ -196,6 +193,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
protected CenOdtOccupancySensorBaseJoinMap(uint joinStart, Type type) : base(joinStart, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class DisplayControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DisplayControllerJoinMap
|
||||
/// </summary>
|
||||
public class DisplayControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("Name")]
|
||||
public JoinDataComplete Name = new JoinDataComplete(new JoinData { JoinNumber = 1, JoinSpan = 1 },
|
||||
new JoinMetadata { Description = "Name", JoinCapabilities = eJoinCapabilities.ToSIMPL, JoinType = eJoinType.Serial });
|
||||
@@ -84,5 +81,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
protected DisplayControllerJoinMap(uint joinStart, Type type) : base(joinStart, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges {
|
||||
/// <summary>
|
||||
/// Represents a DmBladeChassisControllerJoinMap
|
||||
/// </summary>
|
||||
public class DmBladeChassisControllerJoinMap : JoinMapBaseAdvanced {
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
public class DmBladeChassisControllerJoinMap : JoinMapBaseAdvanced {
|
||||
|
||||
[JoinName("IsOnline")]
|
||||
public JoinDataComplete IsOnline = new JoinDataComplete(new JoinData { JoinNumber = 11, JoinSpan = 1 },
|
||||
@@ -73,5 +70,4 @@ namespace PepperDash.Essentials.Core.Bridges {
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Bridges
|
||||
namespace PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
public class DmChassisControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a DmChassisControllerJoinMap
|
||||
/// </summary>
|
||||
public class DmChassisControllerJoinMap : JoinMapBaseAdvanced
|
||||
{
|
||||
[JoinName("EnableAudioBreakaway")]
|
||||
public JoinDataComplete EnableAudioBreakaway = new JoinDataComplete(
|
||||
new JoinData {JoinNumber = 4, JoinSpan = 1},
|
||||
@@ -169,5 +166,4 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
protected DmChassisControllerJoinMap(uint joinStart, Type type) : base(joinStart, type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user