mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-06 04:54:59 +00:00
Compare commits
138 Commits
v2.20.1-st
...
dev/v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bec96e68b | ||
|
|
7076eafc21 | ||
|
|
b4d53dbe0e | ||
|
|
43a9661e08 | ||
|
|
7137945c94 | ||
|
|
ac393c4885 | ||
|
|
346a5e9e57 | ||
|
|
426ef4ad6b | ||
|
|
bcb65c7fa4 | ||
|
|
c2ff65dce3 | ||
|
|
3feab2593d | ||
|
|
5d90fafbd7 | ||
|
|
7f60dcb4cf | ||
|
|
574e4dfb0f | ||
|
|
76759d35cc | ||
|
|
3ece4f0b7b | ||
|
|
aaa5b0532b | ||
|
|
04c4557528 | ||
|
|
9febbf2557 | ||
|
|
eafade9569 | ||
|
|
4e5b8f3897 | ||
|
|
7bd3ccd54b | ||
|
|
790b5a6fb9 | ||
|
|
fbcd9c84da | ||
|
|
4a2c9fe311 | ||
|
|
bdd398e2e6 | ||
|
|
8be5481ac9 | ||
|
|
dbab427d69 | ||
|
|
db4f540710 | ||
|
|
b64f63ac6b | ||
|
|
b21be608f0 | ||
|
|
6ab3ed9911 | ||
|
|
a9fdf30880 | ||
|
|
963925ffef | ||
|
|
e162ed208b | ||
|
|
bd38475b10 | ||
|
|
a704e48ae6 | ||
|
|
b40200ecae | ||
|
|
9de14da201 | ||
|
|
633608c8c6 | ||
|
|
f8a81de177 | ||
|
|
39ebf6f63d | ||
|
|
3ed0bd52d8 | ||
|
|
afc5cf1a14 | ||
|
|
8ff9de817c | ||
|
|
b35d2b47cf | ||
|
|
10579f1424 | ||
|
|
f88bb13367 | ||
|
|
2924ce6916 | ||
|
|
4437074f07 | ||
|
|
0764685c51 | ||
|
|
1fb5d3e5ee | ||
|
|
1404899342 | ||
|
|
a4759c3e67 | ||
|
|
a1029cd7c7 | ||
|
|
b1a5136ec6 | ||
|
|
a7c4e2fd60 | ||
|
|
c0971a4f8e | ||
|
|
8bc6d4392b | ||
|
|
4fa7a42330 | ||
|
|
9bad3ae21b | ||
|
|
f49901d3fa | ||
|
|
7910b7931e | ||
|
|
3fb30d5561 | ||
|
|
57cd77f019 | ||
|
|
7f2bb078c8 | ||
|
|
316bb849b4 | ||
|
|
a983e2c87f | ||
|
|
babb9a77df | ||
|
|
7629921113 | ||
|
|
3878c85a7a | ||
|
|
7ad8218af0 | ||
|
|
0c4aec14d1 | ||
|
|
7d3f871460 | ||
|
|
78c9381108 | ||
|
|
a7ff2e8903 | ||
|
|
ae0b2fe086 | ||
|
|
bd11c827da | ||
|
|
7ea1efbabf | ||
|
|
9d6aaa2a0e | ||
|
|
53e7a30224 | ||
|
|
ce8b08e312 | ||
|
|
39c1f60a4d | ||
|
|
2cc37a4e40 | ||
|
|
076e5dfa9d | ||
|
|
092896bb25 | ||
|
|
7c8f0586e6 | ||
|
|
c5b0872a4c | ||
|
|
a7b88ec38d | ||
|
|
210b398a13 | ||
|
|
bce1e3610e | ||
|
|
13e833b797 | ||
|
|
6a33e7c99d | ||
|
|
2048e3f65d | ||
|
|
81df2738de | ||
|
|
08fbec416f | ||
|
|
7594b22096 | ||
|
|
d1babf6b9b | ||
|
|
2187c9fb0d | ||
|
|
a5e6059160 | ||
|
|
9ef4aedcce | ||
|
|
f7c7160bf0 | ||
|
|
dbf5740841 | ||
|
|
c07e099a79 | ||
|
|
06cb508f3a | ||
|
|
e93b5b34cc | ||
|
|
4f5d4ef87a | ||
|
|
636da8cc8c | ||
|
|
5de1e2d7bb | ||
|
|
2be078da18 | ||
|
|
03bbb84894 | ||
|
|
d17394cdd7 | ||
|
|
8467afde38 | ||
|
|
5c016fb4b8 | ||
|
|
2fbc32947c | ||
|
|
c06b57a5f9 | ||
|
|
6d64fffc50 | ||
|
|
0c4ebdaf1d | ||
|
|
2c49fb9321 | ||
|
|
c55de61da9 | ||
|
|
42444ede0a | ||
|
|
3d50f5f5ac | ||
|
|
11d62aebe1 | ||
|
|
edc10a9c2a | ||
|
|
9be5823956 | ||
|
|
35371dde22 | ||
|
|
d3ceb4d7e7 | ||
|
|
a782b57100 | ||
|
|
1360de599f | ||
|
|
fd95f5fed1 | ||
|
|
9426dff5df | ||
|
|
0d083e63c6 | ||
|
|
314570d6c3 | ||
|
|
ff609dfecd | ||
|
|
7330ae2e30 | ||
|
|
a57dddba5e | ||
|
|
0bfec16622 | ||
|
|
94e7b8210f |
13
.config/dotnet-tools.json
Normal file
13
.config/dotnet-tools.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"csharpier": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"commands": [
|
||||||
|
"csharpier"
|
||||||
|
],
|
||||||
|
"rollForward": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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 "=================================="
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
"_appLogoPath": "docs/images/favicon-32x32.png",
|
"_appLogoPath": "docs/images/favicon-32x32.png",
|
||||||
"_appFaviconPath": "docs/images/favicon.ico",
|
"_appFaviconPath": "docs/images/favicon.ico",
|
||||||
"_disableToc": false,
|
"_disableToc": false,
|
||||||
|
"_enableNewTab": true,
|
||||||
"pdf": false
|
"pdf": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,44 @@
|
|||||||
[YouTube Video - Getting Started with PepperDash Essentials](https://youtu.be/FxEZtbpCwiQ)
|
[YouTube Video - Getting Started with PepperDash Essentials](https://youtu.be/FxEZtbpCwiQ)
|
||||||
***
|
***
|
||||||
|
|
||||||
## Download or clone
|
## Get a CPZ
|
||||||
|
|
||||||
You may clone Essentials at <https://github.com/PepperDash/Essentials.git>
|
### Prerequisites
|
||||||
|
|
||||||
|
* [VS Code](https://code.visualstudio.com/)
|
||||||
|
* [.NET 9 SDK](https://dotnet.microsoft.com/en-us/download)
|
||||||
|
* [Git](https://git-scm.com/)
|
||||||
|
|
||||||
|
> Note: Essentials 2.x.x uses .NET Framework 4.7.2 currently. The .NET 9 SDK will build the project with the appropriate references
|
||||||
|
|
||||||
|
### Build From Source
|
||||||
|
|
||||||
|
1. Clone the repo: `git clone https://github.com/PepperDash/Essentials.git`
|
||||||
|
2. Open the folder in VS Code
|
||||||
|
3. Build using the dotnet CLI: `dotnet build`
|
||||||
|
|
||||||
|
### Download the latest release
|
||||||
|
|
||||||
|
The latest release can be found on [Github](https://github.com/PepperDash/Essentials/releases/latest)
|
||||||
|
|
||||||
## How to Get Started
|
## How to Get Started
|
||||||
|
|
||||||
This section assumes knowledge of loading programs to and working with the file system on a Crestron processor.
|
2. Using an SFTP client or Crestron Toolbox, load the downloaded (or built) cpz to the processor in program slot 1
|
||||||
|
1. If using SFTP, connect via SSH and start the program by sending console command `progload -p:1`
|
||||||
|
3. On first boot, the Essentials Application will build the necessary configuration folder structure in the user/program1/ path.
|
||||||
|
4. The application has some example configuration files included. Copy `/Program01/Example Configuration/EssentialsSpaceHuddleRoom/configurationFile-HuddleSpace-2-Source.json` to the `/User/Program1/` folder.
|
||||||
|
6. Reset the program via console `progreset -p:1`. The program will load the example configuration file.
|
||||||
|
|
||||||
1. Using an SFTP client, load `PepperDashEssentials1.4.32.cpz` to the processor in program slot 1 and start the program by sending console command `progload -p:1`
|
Once Essentials is running with a valid configuration, the following console commands can be used to see what's going on:
|
||||||
1. On first boot, the Essentials Application will build the necessary configuration folder structure in the User/Program1/ path.
|
|
||||||
1. The application has some example configuration files included. Copy `/Program01/Example Configuration/EssentialsSpaceHuddleRoom/configurationFile-HuddleSpace-2-Source.json` to the `/User/Program1/` folder.
|
|
||||||
1. Copy the SGD files from `/Program01/SGD` to `/User/Program1/sgd`
|
|
||||||
1. Reset the program via console `progreset -p:1`. The program will load the example configuration file.
|
|
||||||
1. Via console, you can run the `devlist:1` command to get some insight into what has been loaded from the configuration file into the system . This will print the basic device information in the form of ["key"] "Name". The "key" value is what we can use to interact with each device uniquely.
|
|
||||||
1. Run the command `devprops:1 display-1`. This will print the real-time property values of the device with key "display-1".
|
|
||||||
1. Run the command `devmethods:1 display-1`. This will print the public methods available for the device with key "display-1".
|
|
||||||
1. Run the command `devjson:1 {"deviceKey":"display-1","methodName":"PowerOn", "params": []}`. This will call the method PowerOn() on the device with key "display-1".
|
|
||||||
1. Run the provided example XPanel SmartGraphics project and connect to your processor at the appropriate IPID.
|
|
||||||
|
|
||||||
Next: [Standalone use](~/docs/Standalone-Use.md)
|
* ```devlist:1```
|
||||||
|
* Print the list of devices in [{key}] {name} format
|
||||||
|
* The key of a device can be used with the rest of the commands to get more information
|
||||||
|
* `devprops:1 {deviceKey}`
|
||||||
|
* Print the real-time property values of the device with key "display-1".
|
||||||
|
* `devmethods:1 display-1`
|
||||||
|
* Print the public methods available for the device with key "display-1".
|
||||||
|
* `devjson:1 {"deviceKey":"display-1","methodName":"PowerOn", "params": []}`
|
||||||
|
* Call the method `PowerOn()` on the device with key "display-1".
|
||||||
|
|
||||||
|
Next: [Standalone use](~/docs/usage/Standalone-Use.md)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Thanks!
|
|||||||
|
|
||||||
## Collaboration
|
## Collaboration
|
||||||
|
|
||||||
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/Plugins.md)
|
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/technical-docs/Plugins.md)
|
||||||
|
|
||||||
### Open-source-collaborative workflow
|
### Open-source-collaborative workflow
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Deprecated
|
# Deprecated
|
||||||
|
|
||||||
**Note : this entry is out of date - please see [Plugins](~/docs/Plugins.md)**
|
**Note : this entry is out of date - please see [Plugins](~/docs/technical-docs/Plugins.md)**
|
||||||
|
|
||||||
## What are Essentials Plugins?
|
## What are Essentials Plugins?
|
||||||
|
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
||||||
|
|
||||||
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
|
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
|
||||||
|
|
||||||
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
|
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
|
||||||
|
|
||||||
@@ -474,4 +474,4 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
||||||
|
|
||||||
Next: [Essentials architecture](~/docs/Arch-summary.md)
|
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# SIMPL Windows Bridging
|
# SIMPL Windows Bridging
|
||||||
|
|
||||||
**Note : this entry is out of date - please see [SIMPL Windows Bridging - Updated](~/docs/SIMPL-Bridging-Updated.md)**
|
**Note : this entry is out of date - please see [SIMPL Windows Bridging - Updated](~/docs/usage/SIMPL-Bridging-Updated.md)**
|
||||||
|
|
||||||
Essentials allows for devices defined within the SIMPL# Pro application to be bridged to a SIMPL Windows application over Ethernet Intersystem Communication (EISC). This allows a SIMPL Windows program to take advantage of some of the features of the SIMPL# Pro environment, without requiring the entire application to be written in C#.
|
Essentials allows for devices defined within the SIMPL# Pro application to be bridged to a SIMPL Windows application over Ethernet Intersystem Communication (EISC). This allows a SIMPL Windows program to take advantage of some of the features of the SIMPL# Pro environment, without requiring the entire application to be written in C#.
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
1. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
||||||
|
|
||||||
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
|
1. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
|
||||||
|
|
||||||
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
|
1. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing DisplayControllerJoinMap. This way, you can swap plugins without needing any change on the Simpl Windows side. This is extremely powerful when maintaining Simpl Windows code bases for large deployments that may utilize differing equipment per room. If you can build a Simpl Windows program that interacts with established join maps, you can swap out the device via config without any change needed to Simpl Windows.
|
||||||
|
|
||||||
@@ -472,4 +472,4 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
||||||
|
|
||||||
Next: [Essentials architecture](~/docs/Arch-summary.md)
|
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)
|
||||||
|
|||||||
148
docs/docs/how-to/how-to-add-docs.md
Normal file
148
docs/docs/how-to/how-to-add-docs.md
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
# How to Add Documentation to Essentials
|
||||||
|
|
||||||
|
This guide explains how to add new documentation articles to the Essentials docFx site.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The Essentials documentation uses [docFx](https://dotnet.github.io/docfx/) to generate a static documentation website. Documentation files are organized in a hierarchical structure with a table of contents (TOC) file that defines the site navigation. Documentation should be organized and written to fit into the [Diátaxis](https://diataxis.fr/start-here/) conceptual framework.
|
||||||
|
|
||||||
|
## Documentation Structure
|
||||||
|
|
||||||
|
Documentation files are located in `/docs/docs/` and organized into the following subdirectories:
|
||||||
|
|
||||||
|
- **how-to/** - Step-by-step guides and tutorials
|
||||||
|
- **usage/** - Usage documentation for SIMPL bridging, standalone use, and hardware integration
|
||||||
|
- **technical-docs/** - Technical documentation including architecture, plugins, and API references
|
||||||
|
- **images/** - Image assets used in documentation
|
||||||
|
|
||||||
|
## Adding a New Document
|
||||||
|
|
||||||
|
### Step 1: Create Your Markdown File
|
||||||
|
|
||||||
|
1. Determine which category your document belongs to (how-to, usage, or technical-docs)
|
||||||
|
2. Create a new `.md` file in the appropriate subdirectory
|
||||||
|
3. Use a descriptive filename with hyphens (e.g., `my-new-feature.md`)
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
```bash
|
||||||
|
# For a how-to guide
|
||||||
|
touch /docs/docs/how-to/configure-audio-settings.md
|
||||||
|
|
||||||
|
# For usage documentation
|
||||||
|
touch /docs/docs/usage/video-switcher-control.md
|
||||||
|
|
||||||
|
# For technical documentation
|
||||||
|
touch /docs/docs/technical-docs/custom-device-plugin.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: Write Your Content
|
||||||
|
|
||||||
|
Start your markdown file with a level 1 heading (`#`) that serves as the page title:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# Your Document Title
|
||||||
|
|
||||||
|
Brief introduction to the topic.
|
||||||
|
|
||||||
|
## Section Heading
|
||||||
|
|
||||||
|
Content goes here...
|
||||||
|
|
||||||
|
### Subsection
|
||||||
|
|
||||||
|
More detailed content...
|
||||||
|
```
|
||||||
|
|
||||||
|
**Markdown Features:**
|
||||||
|
- Use standard markdown syntax
|
||||||
|
- Include code blocks with language specifiers (```csharp, ```json, etc.)
|
||||||
|
- Add images: ``
|
||||||
|
- Link to other docs: `[Link text](../usage/related-doc.md)`
|
||||||
|
|
||||||
|
### Step 3: Add to Table of Contents
|
||||||
|
|
||||||
|
Edit `/docs/docs/toc.yml` to add your new document to the navigation:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: How-to's
|
||||||
|
items:
|
||||||
|
- href: how-to/how-to-add-docs.md
|
||||||
|
- href: how-to/your-new-doc.md # Add your document here
|
||||||
|
```
|
||||||
|
|
||||||
|
**TOC Structure:**
|
||||||
|
- `name:` - Display name in the navigation menu
|
||||||
|
- `href:` - Relative path to the markdown file
|
||||||
|
- `items:` - Nested items for hierarchical navigation
|
||||||
|
|
||||||
|
**Example with nested items:**
|
||||||
|
```yaml
|
||||||
|
- name: Usage
|
||||||
|
items:
|
||||||
|
- name: SIMPL Bridging
|
||||||
|
href: usage/SIMPL-Bridging-Updated.md
|
||||||
|
items:
|
||||||
|
- name: Your Sub-Topic
|
||||||
|
href: usage/your-sub-topic.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 4: Test Locally
|
||||||
|
|
||||||
|
Build and preview the docFx site locally to verify your changes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Navigate to the docs directory
|
||||||
|
cd docs
|
||||||
|
|
||||||
|
# Build the documentation
|
||||||
|
docfx build
|
||||||
|
|
||||||
|
# Serve the site locally
|
||||||
|
docfx serve _site
|
||||||
|
```
|
||||||
|
|
||||||
|
Then open your browser to `http://localhost:8080` to view the site.
|
||||||
|
|
||||||
|
## Best Practices
|
||||||
|
|
||||||
|
### File Naming
|
||||||
|
- Use lowercase with hyphens: `my-document-name.md`
|
||||||
|
- Be descriptive but concise
|
||||||
|
- Avoid special characters
|
||||||
|
|
||||||
|
### Content Guidelines
|
||||||
|
- Start with a clear introduction
|
||||||
|
- Use hierarchical headings (H1 → H2 → H3)
|
||||||
|
- Include code examples where appropriate
|
||||||
|
- Add images to illustrate complex concepts
|
||||||
|
- Link to related documentation
|
||||||
|
|
||||||
|
### TOC Organization
|
||||||
|
- Group related documents under the same parent
|
||||||
|
- Order items logically (basic → advanced)
|
||||||
|
- Keep the TOC hierarchy shallow (2-3 levels max)
|
||||||
|
- Use clear, descriptive names for navigation items
|
||||||
|
|
||||||
|
## Common Issues
|
||||||
|
|
||||||
|
### Document Not Appearing
|
||||||
|
- Verify the file path in `toc.yml` is correct and uses forward slashes
|
||||||
|
- Ensure the markdown file exists in the specified location
|
||||||
|
- Check for YAML syntax errors in `toc.yml`
|
||||||
|
|
||||||
|
### Images Not Loading
|
||||||
|
- Verify image path is relative to the markdown file location
|
||||||
|
- Use `../images/` for files in the images directory
|
||||||
|
- Ensure image files are committed to the repository
|
||||||
|
|
||||||
|
### Broken Links
|
||||||
|
- Use relative paths for internal links
|
||||||
|
- Test all links after building the site
|
||||||
|
- Use `.md` extension when linking to other documentation files
|
||||||
|
|
||||||
|
## Additional Resources
|
||||||
|
|
||||||
|
- [docFx Documentation](https://dotnet.github.io/docfx/)
|
||||||
|
- [Markdown Guide](https://www.markdownguide.org/)
|
||||||
|
- [YAML Syntax](https://yaml.org/spec/1.2/spec.html)
|
||||||
|
- [Diátaxis](https://diataxis.fr/start-here/)
|
||||||
@@ -26,7 +26,7 @@ Types of things in `DeviceManager`:
|
|||||||
|
|
||||||
A Device doesn't always represent a physical piece of hardware, but rather a logical construct that "does something" and is used by one or more other devices in the running program. For example, we create a room device, and its corresponding Fusion device, and that room has a Cisco codec device, with an attached SSh client device. All of these lie in a flat collection in the `DeviceManager`.
|
A Device doesn't always represent a physical piece of hardware, but rather a logical construct that "does something" and is used by one or more other devices in the running program. For example, we create a room device, and its corresponding Fusion device, and that room has a Cisco codec device, with an attached SSh client device. All of these lie in a flat collection in the `DeviceManager`.
|
||||||
|
|
||||||
> The `DeviceManager` is nothing more than a modified collection of things, and technically those things don't have to be Devices, but must at least implement the `IKeyed` (`PepperDash.Core.IKeyed`) interface (simply so items can be looked up by their key.) Items in the `DeviceManager` that are Devices are run through additional steps of [activation](~/docs/Arch-activate.md#2-pre-activation) at startup. This collection of devices is all interrelated by their string keys.
|
> The `DeviceManager` is nothing more than a modified collection of things, and technically those things don't have to be Devices, but must at least implement the `IKeyed` (`PepperDash.Core.IKeyed`) interface (simply so items can be looked up by their key.) Items in the `DeviceManager` that are Devices are run through additional steps of [activation](~/docs/technical-docs/Arch-activate.md#2-pre-activation) at startup. This collection of devices is all interrelated by their string keys.
|
||||||
|
|
||||||
In this flat design, we spin up devices, and then introduce them to their "coworkers and bosses" - the other devices and logical units that they will interact with - and get them all operating together to form a running unit. For example: A room configuration will contain a "VideoCodecKey" property and a "DefaultDisplayKey" property. The `DeviceManager` provides the room with the codec or displays having the appropriate keys. What the room does with those is dependent on its coding.
|
In this flat design, we spin up devices, and then introduce them to their "coworkers and bosses" - the other devices and logical units that they will interact with - and get them all operating together to form a running unit. For example: A room configuration will contain a "VideoCodecKey" property and a "DefaultDisplayKey" property. The `DeviceManager` provides the room with the codec or displays having the appropriate keys. What the room does with those is dependent on its coding.
|
||||||
|
|
||||||
@@ -38,4 +38,4 @@ This flat structure ensures that every device in a system exists in one place an
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Next: [Configurable lifecycle](~/docs/Arch-lifecycle.md)
|
Next: [Configurable lifecycle](~/docs/technical-docs/Arch-lifecycle.md)
|
||||||
@@ -105,7 +105,7 @@ Each of the three activation phases operates in a try/catch block for each devic
|
|||||||
|
|
||||||
In any real-world system, devices and business logic need to talk to each other, otherwise, what's the point of all this coding? When creating your classes and configuration, it is best practice to _try_ not to "plug" one device into another during construction or activation. For example your touchpanel controller class has a `Display1` property that holds the display-1 object. Rather, it may be better to refer to the device as it is stored in the `DeviceManager` when it's needed using the static `DeviceManager.GetDeviceForKey(key)` method to get a reference to the device, which can be cast using various interfaces/class types, and then interacted with. This prevents objects from being referenced in places where the developer may later forget to dereference them, causing memory leak. This will become more important as Essentials becomes more able to be reconfigured at runtime.
|
In any real-world system, devices and business logic need to talk to each other, otherwise, what's the point of all this coding? When creating your classes and configuration, it is best practice to _try_ not to "plug" one device into another during construction or activation. For example your touchpanel controller class has a `Display1` property that holds the display-1 object. Rather, it may be better to refer to the device as it is stored in the `DeviceManager` when it's needed using the static `DeviceManager.GetDeviceForKey(key)` method to get a reference to the device, which can be cast using various interfaces/class types, and then interacted with. This prevents objects from being referenced in places where the developer may later forget to dereference them, causing memory leak. This will become more important as Essentials becomes more able to be reconfigured at runtime.
|
||||||
|
|
||||||
As an example, [connection-based routing](~/docs/Connection-based-routing.md#essentials-connection-based-routing) uses these methods. When a route is requested, the collection of tielines and devices is searched for the devices and paths necessary to complete a route, but there are no devices or tie lines that are object-referenced in running code. It can all be torn down and reconfigured without any memory-management dereferencing, setting things to null.
|
As an example, [connection-based routing](~/docs/technical-docs/Connection-based-routing.md#essentials-connection-based-routing) uses these methods. When a route is requested, the collection of tielines and devices is searched for the devices and paths necessary to complete a route, but there are no devices or tie lines that are object-referenced in running code. It can all be torn down and reconfigured without any memory-management dereferencing, setting things to null.
|
||||||
|
|
||||||
## Device Initialization
|
## Device Initialization
|
||||||
|
|
||||||
@@ -155,4 +155,4 @@ Robust C#-based system code should not depend on "order" or "time" to get runnin
|
|||||||
|
|
||||||
When designing new Device-based classes, be it rooms, devices, port controllers, bridges, make them as independent as possible. They could exist alone in a program with no required partner objects, and just quietly exist without failing. We want the system to be fast and flexible, and keeping the interdependence between objects at a minimum improves this flexibility into the future.
|
When designing new Device-based classes, be it rooms, devices, port controllers, bridges, make them as independent as possible. They could exist alone in a program with no required partner objects, and just quietly exist without failing. We want the system to be fast and flexible, and keeping the interdependence between objects at a minimum improves this flexibility into the future.
|
||||||
|
|
||||||
Next: [More architecture](~/docs/Arch-topics.md)
|
Next: [More architecture](~/docs/technical-docs/Arch-topics.md)
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
The diagram below describes how Essentials gets a program up and running.
|
The diagram below describes how Essentials gets a program up and running.
|
||||||
|
|
||||||
(The various activation phases are covered in more detail on the [next page](~/docs/Arch-activate.md))
|
(The various activation phases are covered in more detail on the [next page](~/docs/technical-docs/Arch-activate.md))
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Next: [Activation phases](~/docs/Arch-activate.md)
|
Next: [Activation phases](~/docs/technical-docs/Arch-activate.md)
|
||||||
@@ -16,4 +16,4 @@ The diagram below shows the reference dependencies that exist between the differ
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Next: [Architecture](~/docs/Arch-1.md)
|
Next: [Architecture](~/docs/technical-docs/Arch-1.md)
|
||||||
@@ -1,48 +1,52 @@
|
|||||||
- name: Get Started With Essentials
|
- name: Get Started With Essentials
|
||||||
- href: ../index.md
|
- href: ../index.md
|
||||||
- href: Get-started.md
|
- href: Get-started.md
|
||||||
|
- name: How-to's
|
||||||
|
items:
|
||||||
|
- name: How to add an article or doc page
|
||||||
|
href: how-to/how-to-add-docs.md
|
||||||
- name: Usage
|
- name: Usage
|
||||||
items:
|
items:
|
||||||
- href: Standalone-Use.md
|
- href: usage/Standalone-Use.md
|
||||||
- href: SIMPL-Bridging-Updated.md
|
- href: usage/SIMPL-Bridging-Updated.md
|
||||||
items:
|
items:
|
||||||
- name: Join Maps
|
- name: Join Maps
|
||||||
href: JoinMaps.md
|
href: usage/JoinMaps.md
|
||||||
- name: Bridging to Hardware Resources
|
- name: Bridging to Hardware Resources
|
||||||
href: Bridging-To-Hardware-Resources.md
|
href: usage/Bridging-To-Hardware-Resources.md
|
||||||
items:
|
items:
|
||||||
- name: GenericComm Bridging
|
- name: GenericComm Bridging
|
||||||
href: GenericComm.md
|
href: usage/GenericComm.md
|
||||||
- name: RelayOutput Bridging
|
- name: RelayOutput Bridging
|
||||||
href: RelayOutput.md
|
href: usage/RelayOutput.md
|
||||||
- name: Digital Input Bridging
|
- name: Digital Input Bridging
|
||||||
href: DigitalInput.md
|
href: usage/DigitalInput.md
|
||||||
- name: IR Driver Bridging
|
- name: IR Driver Bridging
|
||||||
href: IR-Driver-Bridging.md
|
href: usage/IR-Driver-Bridging.md
|
||||||
- name: Technical documentation
|
- name: Technical documentation
|
||||||
items:
|
items:
|
||||||
- href: Arch-summary.md
|
- href: technical-docs/Arch-summary.md
|
||||||
- name: Devices and DeviceManager
|
- name: Devices and DeviceManager
|
||||||
href: Arch-1.md
|
href: technical-docs/Arch-1.md
|
||||||
- name: Configurable lifecycle
|
- name: Configurable lifecycle
|
||||||
href: Arch-lifecycle.md
|
href: technical-docs/Arch-lifecycle.md
|
||||||
- name: Activation phases
|
- name: Activation phases
|
||||||
href: Arch-activate.md
|
href: technical-docs/Arch-activate.md
|
||||||
- name: More
|
- name: More
|
||||||
href: Arch-topics.md
|
href: technical-docs/Arch-topics.md
|
||||||
- name: Plugins
|
- name: Plugins
|
||||||
href: Plugins.md
|
href: technical-docs/Plugins.md
|
||||||
- name: Communication Basics
|
- name: Communication Basics
|
||||||
href: Communication-Basics.md
|
href: technical-docs/Communication-Basics.md
|
||||||
- name: Debugging
|
- name: Debugging
|
||||||
href: Debugging.md
|
href: technical-docs/Debugging.md
|
||||||
- name: Feedback Classes
|
- name: Feedback Classes
|
||||||
href: Feedback-Classes.md
|
href: technical-docs/Feedback-Classes.md
|
||||||
- name: Connection Based Routing
|
- name: Connection Based Routing
|
||||||
href: Connection-Based-Routing.md
|
href: technical-docs/Connection-Based-Routing.md
|
||||||
- name: Configuration Structure
|
- name: Configuration Structure
|
||||||
href: ConfigurationStructure.md
|
href: technical-docs/ConfigurationStructure.md
|
||||||
- name: Supported Devices
|
- name: Supported Devices
|
||||||
href: Supported-Devices.md
|
href: technical-docs/Supported-Devices.md
|
||||||
- name: Glossary of Terms
|
- name: Glossary of Terms
|
||||||
href: Glossary-of-Terms.md
|
href: technical-docs/Glossary-of-Terms.md
|
||||||
@@ -6,10 +6,10 @@ One of the most powerful features of Essentials is the ability to bridge SIMPL t
|
|||||||
|
|
||||||
Follow the links below for examples of bridging to hardware and network resources.
|
Follow the links below for examples of bridging to hardware and network resources.
|
||||||
|
|
||||||
**[GenericComm Bridging](~/docs/GenericComm.md)**
|
**[GenericComm Bridging](~/docs/usage/GenericComm.md)**
|
||||||
|
|
||||||
**[RelayOutput Bridging](~/docs/RelayOutput.md)**
|
**[RelayOutput Bridging](~/docs/usage/RelayOutput.md)**
|
||||||
|
|
||||||
**[Digital Input Bridging](~/docs/DigitalInput.md)**
|
**[Digital Input Bridging](~/docs/usage/DigitalInput.md)**
|
||||||
|
|
||||||
**[Card Frame Bridging](~/docs/CardFrame.md)**
|
**[Card Frame Bridging](~/docs/CardFrame.md)**
|
||||||
@@ -286,7 +286,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
3. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
3. A bridge need not only bridge between applications on the same processor. A bridge may bridge to an application on a completely separate processor; simply define the ip address in the Bridge control properties accordingly.
|
||||||
|
|
||||||
4. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/Feedback-Classes.md) for this.
|
4. For devices included in Essentials, you will be able to find defined join maps below. If you are building your own plugins, you will need to build the join map yourself. It would be beneficial to review the wiki entry on the [Feedback Class](~/docs/technical-docs/Feedback-Classes.md) for this.
|
||||||
|
|
||||||
5. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing `DisplayControllerJoinMap`. This way, you can swap plugins without needing any change on the SIMPL Windows side. This is extremely powerful when maintaining SIMPL Windows code bases for large deployments that may utilize differing equipment per room. If you can build a SIMPL Windows program that interacts with established join maps, you can swap out the device via config without any change needed to SIMPL Windows.
|
5. When building plugins, we highly recommend reusing JoinMaps, as this will make code more easily interchangeable. For example; if you were to build a display plugin, we'd recommend you use/extend the existing `DisplayControllerJoinMap`. This way, you can swap plugins without needing any change on the SIMPL Windows side. This is extremely powerful when maintaining SIMPL Windows code bases for large deployments that may utilize differing equipment per room. If you can build a SIMPL Windows program that interacts with established join maps, you can swap out the device via config without any change needed to SIMPL Windows.
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ Example device config: <https://github.com/PepperDash/Essentials/blob/main/Peppe
|
|||||||
|
|
||||||
## Join Map Documentation
|
## Join Map Documentation
|
||||||
|
|
||||||
[Join Map Documentation](~/docs/JoinMaps.md)
|
[Join Map Documentation](~/docs/usage/JoinMaps.md)
|
||||||
|
|
||||||
## Device Type Join Maps
|
## Device Type Join Maps
|
||||||
|
|
||||||
@@ -408,4 +408,4 @@ Please note that these joinmaps _may_ be using a deprecated implementation. The
|
|||||||
|
|
||||||
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
We've provided an [example program](https://github.com/PepperDash/EssentialsSIMPLWindowsBridgeExample) for SIMPL Windows that works with the provided example Essentials configuration file [SIMPLBridgeExample_configurationFile.json](https://github.com/PepperDash/Essentials/blob/main/PepperDashEssentials/Example%20Configuration/SIMPLBridging/SIMPLBridgeExample_configurationFile.json). Load Essentials and the example SIMPL program to two slots on the same processor and you can get a better idea of how to take advantage of SIMPL Windows bridging.
|
||||||
|
|
||||||
Next: [Essentials architecture](~/docs/Arch-summary.md)
|
Next: [Essentials architecture](~/docs/technical-docs/Arch-summary.md)
|
||||||
@@ -8,7 +8,7 @@ By defining devices and a room in a JSON configuration file, Essentials can cont
|
|||||||
|
|
||||||
### Devices
|
### Devices
|
||||||
|
|
||||||
Essentials supports device plugins for communicating with various devices using both standard Crestron CIP communications, Cresnet, SSH, or other TCP/IP-based communication methods. See [the Plugins section](~/docs/Plugins.md) for more details
|
Essentials supports device plugins for communicating with various devices using both standard Crestron CIP communications, Cresnet, SSH, or other TCP/IP-based communication methods. See [the Plugins section](~/docs/technical-docs/Plugins.md) for more details
|
||||||
|
|
||||||
### Rooms
|
### Rooms
|
||||||
|
|
||||||
@@ -16,4 +16,4 @@ In order to tie together equipment into a unit that comprises what devices are u
|
|||||||
|
|
||||||
See Also: [[Supported Devices|Supported-Devices]]
|
See Also: [[Supported Devices|Supported-Devices]]
|
||||||
|
|
||||||
Next: [Simpl Windows bridging](~/docs/SIMPL-Bridging-Updated.md)
|
Next: [Simpl Windows bridging](~/docs/usage/SIMPL-Bridging-Updated.md)
|
||||||
@@ -8,12 +8,12 @@ Essentials is a collection of C# libraries that can be used in many ways. It is
|
|||||||
|
|
||||||
## Get started
|
## Get started
|
||||||
|
|
||||||
- [Download essentials build or clone repo](~/docs/Get-started.md)
|
- [Download an Essentials build or clone the repo](~/docs/Get-started.md)
|
||||||
- [How to get started](~/docs/Get-started.md)
|
- [Get started](~/docs/Get-started.md)
|
||||||
- [YouTube Video Series Playlist](https://youtube.com/playlist?list=PLKOoNNwgPFZdV5wDEBDZxTHu1KROspaBu)
|
- [YouTube Video Series Playlist](https://youtube.com/playlist?list=PLKOoNNwgPFZdV5wDEBDZxTHu1KROspaBu)
|
||||||
- [Discord Server](https://discord.gg/6Vh3ssDdPs)
|
- [Discord Server](https://discord.gg/6Vh3ssDdPs)
|
||||||
|
|
||||||
Or use the links to the right to navigate our documentation.
|
Or use the links to the left to navigate our documentation.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -25,21 +25,12 @@ Or use the links to the right to navigate our documentation.
|
|||||||
- Shared resources made easily available
|
- Shared resources made easily available
|
||||||
- More flexibility with less code
|
- More flexibility with less code
|
||||||
- Configurable using simple JSON files
|
- Configurable using simple JSON files
|
||||||
- Is awesome
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Comment
|
|
||||||
|
|
||||||
The Essentials wiki is clearly in-progress right now. Take a look at the links to the right. We are actively working on this documentation, so please be patient with us. If you have any comments on or suggestions for the documentation, please file an issue here, with as much detail as you can provide: <https://github.com/PepperDash/Essentials/issues>
|
|
||||||
|
|
||||||
Thanks!
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Collaboration
|
## Collaboration
|
||||||
|
|
||||||
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/Plugins.md)
|
Essentials is an open-source project and we encourage collaboration on this community project. For features that may not be useful to the greater community, or for just-plain learning, we want to remind developers to try writing plugins for Essentials. More information can be found here: [Plugins](~/docs/technical-docs/Plugins.md)
|
||||||
|
|
||||||
### Open-source-collaborative workflow
|
### Open-source-collaborative workflow
|
||||||
|
|
||||||
@@ -52,7 +43,7 @@ The `main` branch always contain the latest stable version. The `development` br
|
|||||||
- Example: `feature/add-awesomeness` or `hotfix/really-big-oops`
|
- Example: `feature/add-awesomeness` or `hotfix/really-big-oops`
|
||||||
- When working on a new feature or bugfix, branch from the `development` branch. When working on a hotfix, branch from `main`.
|
- When working on a new feature or bugfix, branch from the `development` branch. When working on a hotfix, branch from `main`.
|
||||||
3. Make commits as necessary (often is better). And use concise, descriptive language, leveraging issue notation and/or [Closing Keywords](https://help.github.com/articles/closing-issues-using-keywords) to ensure any issues addressed by your work are referenced accordingly.
|
3. Make commits as necessary (often is better). And use concise, descriptive language, leveraging issue notation and/or [Closing Keywords](https://help.github.com/articles/closing-issues-using-keywords) to ensure any issues addressed by your work are referenced accordingly.
|
||||||
4. When the scope of the work for your branch is complete, make sure to rebase your branch in case further progress has been made since the repo was forked
|
4. When the scope of the work for your branch is complete, make sure to update your branch in case further progress has been made since the repo was forked
|
||||||
5. Create a Pull Request to pull your branch into the appropriate branch in the main repository.
|
5. Create a Pull Request to pull your branch into the appropriate branch in the main repository.
|
||||||
6. Your Pull Request will be reviewed by our team and evaluated for inclusion into the main repository.
|
6. Your Pull Request will be reviewed by our team and evaluated for inclusion into the main repository.
|
||||||
|
|
||||||
|
|||||||
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>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.19.4-local</Version>
|
<Version>3.0.0-local</Version>
|
||||||
<InformationalVersion>$(Version)</InformationalVersion>
|
<InformationalVersion>$(Version)</InformationalVersion>
|
||||||
<Authors>PepperDash Technology</Authors>
|
<Authors>PepperDash Technology</Authors>
|
||||||
<Company>PepperDash Technology</Company>
|
<Company>PepperDash Technology</Company>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).clz" Condition="$(ProjectType) == 'Library'">
|
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).clz" Condition="$(ProjectType) == 'Library' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != ''">
|
||||||
<Pack>true</Pack>
|
<Pack>true</Pack>
|
||||||
<PackagePath>build;</PackagePath>
|
<PackagePath>build;</PackagePath>
|
||||||
</None>
|
</None>
|
||||||
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz" Condition="$(ProjectType) == 'Program'">
|
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cpz" Condition="$(ProjectType) == 'Program' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != '' And ( '$(TargetFramework)' != 'net6.0' ) And ( '$(TargetFramework)' != 'net8.0' )">
|
||||||
<Pack>true</Pack>
|
<Pack>true</Pack>
|
||||||
<PackagePath>build;</PackagePath>
|
<PackagePath>build;</PackagePath>
|
||||||
</None>
|
</None>
|
||||||
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cplz" Condition="$(ProjectType) == 'ProgramLibrary'">
|
<None Include="$(TargetDir)$(TargetName).$(Version).$(TargetFramework).cplz" Condition="$(ProjectType) == 'ProgramLibrary' And '$(TargetFramework)' != '' And '$(TargetName)' != '' And '$(TargetDir)' != ''">
|
||||||
<Pack>true</Pack>
|
<Pack>true</Pack>
|
||||||
<PackagePath>build;</PackagePath>
|
<PackagePath>build;</PackagePath>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </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;
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the string event handler for line events on the gather
|
/// Defines the string event handler for line events on the gather
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -175,4 +175,3 @@ namespace PepperDash.Core
|
|||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using System.Timers;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controls the ability to disable/enable debugging of TX/RX data sent to/from a device with a built in timer to disable
|
/// Controls the ability to disable/enable debugging of TX/RX data sent to/from a device with a built in timer to disable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,10 +20,10 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer to disable automatically if not manually disabled
|
/// Timer to disable automatically if not manually disabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private CTimer DebugExpiryPeriod;
|
private Timer DebugExpiryPeriod;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the DebugSetting
|
/// The current debug setting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public eStreamDebuggingSetting DebugSetting { get; private set; }
|
public eStreamDebuggingSetting DebugSetting { get; private set; }
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the RxStreamDebuggingIsEnabled
|
/// Indicates that receive stream debugging is enabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool RxStreamDebuggingIsEnabled{ get; private set; }
|
public bool RxStreamDebuggingIsEnabled{ get; private set; }
|
||||||
|
|
||||||
@@ -64,9 +65,6 @@ namespace PepperDash.Core
|
|||||||
/// Sets the debugging setting and if not setting to off, assumes the default of 30 mintues
|
/// Sets the debugging setting and if not setting to off, assumes the default of 30 mintues
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="setting"></param>
|
/// <param name="setting"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetDebuggingWithDefaultTimeout method
|
|
||||||
/// </summary>
|
|
||||||
public void SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting setting)
|
public void SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting setting)
|
||||||
{
|
{
|
||||||
if (setting == eStreamDebuggingSetting.Off)
|
if (setting == eStreamDebuggingSetting.Off)
|
||||||
@@ -83,9 +81,6 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="setting"></param>
|
/// <param name="setting"></param>
|
||||||
/// <param name="minutes"></param>
|
/// <param name="minutes"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetDebuggingWithSpecificTimeout method
|
|
||||||
/// </summary>
|
|
||||||
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
|
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
|
||||||
{
|
{
|
||||||
if (setting == eStreamDebuggingSetting.Off)
|
if (setting == eStreamDebuggingSetting.Off)
|
||||||
@@ -98,7 +93,9 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
StopDebugTimer();
|
StopDebugTimer();
|
||||||
|
|
||||||
DebugExpiryPeriod = new CTimer((o) => DisableDebugging(), _DebugTimeoutInMs);
|
DebugExpiryPeriod = new Timer(_DebugTimeoutInMs) { AutoReset = false };
|
||||||
|
DebugExpiryPeriod.Elapsed += (s, e) => DisableDebugging();
|
||||||
|
DebugExpiryPeriod.Start();
|
||||||
|
|
||||||
if ((setting & eStreamDebuggingSetting.Rx) == eStreamDebuggingSetting.Rx)
|
if ((setting & eStreamDebuggingSetting.Rx) == eStreamDebuggingSetting.Rx)
|
||||||
RxStreamDebuggingIsEnabled = true;
|
RxStreamDebuggingIsEnabled = true;
|
||||||
@@ -135,4 +132,28 @@ namespace PepperDash.Core
|
|||||||
DebugExpiryPeriod = null;
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Newtonsoft.Json;
|
using System;
|
||||||
using Newtonsoft.Json.Converters;
|
using Crestron.SimplSharp;
|
||||||
|
using JsonConverter = NewtonsoftJson::Newtonsoft.Json.JsonConverterAttribute;
|
||||||
|
using JsonIgnore = NewtonsoftJson::Newtonsoft.Json.JsonIgnoreAttribute;
|
||||||
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
|
using NullValueHandling = NewtonsoftJson::Newtonsoft.Json.NullValueHandling;
|
||||||
|
using StringEnumConverter = NewtonsoftJson::Newtonsoft.Json.Converters.StringEnumConverter;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a ControlPropertiesConfig
|
/// Config properties that indicate how to communicate with a device for control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ControlPropertiesConfig
|
public class ControlPropertiesConfig
|
||||||
{
|
{
|
||||||
@@ -90,4 +95,3 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -16,8 +16,8 @@ using Crestron.SimplSharp;
|
|||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delegate for notifying of socket status changes
|
/// Delegate for notifying of socket status changes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -35,7 +35,7 @@ namespace PepperDash.Core
|
|||||||
public ISocketStatus Client { get; private set; }
|
public ISocketStatus Client { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
public GenericSocketStatusChageEventArgs(ISocketStatus client)
|
public GenericSocketStatusChageEventArgs(ISocketStatus client)
|
||||||
@@ -65,7 +65,7 @@ namespace PepperDash.Core
|
|||||||
public ServerState State { get; private set; }
|
public ServerState State { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state"></param>
|
/// <param name="state"></param>
|
||||||
public GenericTcpServerStateChangedEventArgs(ServerState state)
|
public GenericTcpServerStateChangedEventArgs(ServerState state)
|
||||||
@@ -91,20 +91,22 @@ namespace PepperDash.Core
|
|||||||
public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs
|
public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the Socket
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Socket { get; private set; }
|
public object Socket { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the index of the client from which the status change was received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint ReceivedFromClientIndex { get; private set; }
|
public uint ReceivedFromClientIndex { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the ClientStatus
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SocketStatus ClientStatus { get; set; }
|
public SocketStatus ClientStatus { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="socket"></param>
|
/// <param name="socket"></param>
|
||||||
/// <param name="clientStatus"></param>
|
/// <param name="clientStatus"></param>
|
||||||
@@ -115,7 +117,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="socket"></param>
|
/// <param name="socket"></param>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
@@ -138,12 +140,12 @@ namespace PepperDash.Core
|
|||||||
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
|
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the index of the client from which the text was received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint ReceivedFromClientIndex { get; private set; }
|
public uint ReceivedFromClientIndex { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets the index of the client from which the text was received as a ushort
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort ReceivedFromClientIndexShort
|
public ushort ReceivedFromClientIndexShort
|
||||||
{
|
{
|
||||||
@@ -159,7 +161,7 @@ namespace PepperDash.Core
|
|||||||
public string Text { get; private set; }
|
public string Text { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
public GenericTcpServerCommMethodReceiveTextArgs(string text)
|
public GenericTcpServerCommMethodReceiveTextArgs(string text)
|
||||||
@@ -168,7 +170,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
@@ -189,18 +191,19 @@ namespace PepperDash.Core
|
|||||||
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
|
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets IsReady
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsReady;
|
public bool IsReady;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="isReady"></param>
|
/// <param name="isReady"></param>
|
||||||
public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady)
|
public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady)
|
||||||
{
|
{
|
||||||
IsReady = isReady;
|
IsReady = isReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// S+ Constructor
|
/// S+ Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -213,11 +216,12 @@ namespace PepperDash.Core
|
|||||||
public class GenericUdpConnectedEventArgs : EventArgs
|
public class GenericUdpConnectedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the UConnected
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort UConnected;
|
public ushort UConnected;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets or sets the Connected status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Connected;
|
public bool Connected;
|
||||||
|
|
||||||
@@ -227,7 +231,7 @@ namespace PepperDash.Core
|
|||||||
public GenericUdpConnectedEventArgs() { }
|
public GenericUdpConnectedEventArgs() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uconnected"></param>
|
/// <param name="uconnected"></param>
|
||||||
public GenericUdpConnectedEventArgs(ushort uconnected)
|
public GenericUdpConnectedEventArgs(ushort uconnected)
|
||||||
@@ -236,7 +240,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connected"></param>
|
/// <param name="connected"></param>
|
||||||
public GenericUdpConnectedEventArgs(bool connected)
|
public GenericUdpConnectedEventArgs(bool connected)
|
||||||
@@ -246,6 +250,3 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,13 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A class to handle secure TCP/IP communications with a server
|
/// A class to handle secure TCP/IP communications with a server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -79,7 +80,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// Port on server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ namespace PepperDash.Core
|
|||||||
public string ConnectionFailure { get { return ClientStatus.ToString(); } }
|
public string ConnectionFailure { get { return ClientStatus.ToString(); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the AutoReconnect
|
/// bool to track if auto reconnect should be set on the socket
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AutoReconnect { get; set; }
|
public bool AutoReconnect { get; set; }
|
||||||
|
|
||||||
@@ -181,14 +182,14 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
// private Timer for auto reconnect
|
// private Timer for auto reconnect
|
||||||
private CTimer RetryTimer;
|
private Timer RetryTimer;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GenericSecureTcpIpClient properties
|
#region GenericSecureTcpIpClient properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the SharedKeyRequired
|
/// Bool to show whether the server requires a preshared key. This is used in the DynamicTCPServer class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SharedKeyRequired { get; set; }
|
public bool SharedKeyRequired { get; set; }
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public string SharedKey { get; set; }
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
@@ -222,7 +223,7 @@ namespace PepperDash.Core
|
|||||||
bool IsTryingToConnect;
|
bool IsTryingToConnect;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the IsReadyForCommunication
|
/// Bool showing if socket is ready for communication after shared key exchange
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsReadyForCommunication { get; set; }
|
public bool IsReadyForCommunication { get; set; }
|
||||||
|
|
||||||
@@ -264,12 +265,12 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatInterval = (value * 1000); } }
|
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatInterval = (value * 1000); } }
|
||||||
|
|
||||||
CTimer HeartbeatSendTimer;
|
Timer HeartbeatSendTimer;
|
||||||
CTimer HeartbeatAckTimer;
|
Timer HeartbeatAckTimer;
|
||||||
|
|
||||||
// Used to force disconnection on a dead connect attempt
|
// Used to force disconnection on a dead connect attempt
|
||||||
CTimer ConnectFailTimer;
|
Timer ConnectFailTimer;
|
||||||
CTimer WaitForSharedKey;
|
Timer WaitForSharedKey;
|
||||||
private int ConnectionCount;
|
private int ConnectionCount;
|
||||||
|
|
||||||
bool ProgramIsStopping;
|
bool ProgramIsStopping;
|
||||||
@@ -277,7 +278,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue lock
|
/// Queue lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CCriticalSection DequeueLock = new CCriticalSection();
|
private readonly object _dequeueLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
||||||
@@ -342,7 +343,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize method
|
/// Just to help S+ set the key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
@@ -357,7 +358,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (config == null)
|
if (config == null)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Could not initialize client with key: {0}", Key);
|
this.LogWarning( "Could not initialize client with key: {0}", Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -397,7 +398,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Exception initializing client with key: {0}\rException: {1}", Key, ex);
|
this.LogError("Exception initializing client with key: {0}\rException: {1}", Key, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +411,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Program stopping. Closing _client connection");
|
this.LogInformation("Program stopping. Closing _client connection");
|
||||||
ProgramIsStopping = true;
|
ProgramIsStopping = true;
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
@@ -421,9 +422,6 @@ namespace PepperDash.Core
|
|||||||
/// Deactivate the client
|
/// Deactivate the client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// Deactivate method
|
|
||||||
/// </summary>
|
|
||||||
public override bool Deactivate()
|
public override bool Deactivate()
|
||||||
{
|
{
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
@@ -435,22 +433,22 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
ConnectionCount++;
|
ConnectionCount++;
|
||||||
Debug.Console(2, this, "Attempting connect Count:{0}", ConnectionCount);
|
this.LogVerbose("Attempting connect Count:{0}", ConnectionCount);
|
||||||
|
|
||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already connected. Ignoring.");
|
this.LogInformation("Already connected. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already trying to connect. Ignoring.");
|
this.LogInformation("Already trying to connect. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -463,17 +461,17 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No address set");
|
this.LogWarning("DynamicTcpClient: No address set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: Invalid port");
|
this.LogWarning("DynamicTcpClient: Invalid port");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No Shared Key set");
|
this.LogWarning("DynamicTcpClient: No Shared Key set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,9 +492,10 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
||||||
|
|
||||||
ConnectFailTimer = new CTimer(o =>
|
ConnectFailTimer = new Timer(30000) { AutoReset = false };
|
||||||
|
ConnectFailTimer.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
this.LogError("Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
@@ -508,12 +507,13 @@ namespace PepperDash.Core
|
|||||||
//SecureClient.DisconnectFromServer();
|
//SecureClient.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}, 30000);
|
};
|
||||||
|
ConnectFailTimer.Start();
|
||||||
|
|
||||||
Debug.Console(2, this, "Making Connection Count:{0}", ConnectionCount);
|
this.LogVerbose("Making Connection Count:{0}", ConnectionCount);
|
||||||
_client.ConnectToServerAsync(o =>
|
_client.ConnectToServerAsync(o =>
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
this.LogVerbose("ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
||||||
|
|
||||||
if (ConnectFailTimer != null)
|
if (ConnectFailTimer != null)
|
||||||
{
|
{
|
||||||
@@ -523,22 +523,22 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "_client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
this.LogVerbose("_client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
||||||
o.ReceiveDataAsync(Receive);
|
o.ReceiveDataAsync(Receive);
|
||||||
|
|
||||||
if (SharedKeyRequired)
|
if (SharedKeyRequired)
|
||||||
{
|
{
|
||||||
WaitingForSharedKeyResponse = true;
|
WaitingForSharedKeyResponse = true;
|
||||||
WaitForSharedKey = new CTimer(timer =>
|
WaitForSharedKey = new Timer(15000) { AutoReset = false };
|
||||||
|
WaitForSharedKey.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
|
this.LogWarning("Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
|
||||||
// Debug.Console(1, this, "Connect attempt failed {0}", c.ClientStatus);
|
|
||||||
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
||||||
o.DisconnectFromServer();
|
o.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
//OnClientReadyForcommunications(false); // Should send false event
|
//OnClientReadyForcommunications(false); // Should send false event
|
||||||
}, 15000);
|
};
|
||||||
|
WaitForSharedKey.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -552,21 +552,21 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Connect attempt failed {0}", o.ClientStatus);
|
this.LogWarning("Connect attempt failed {0}", o.ClientStatus);
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "_client connection exception: {0}", ex.Message);
|
this.LogError("_client connection exception: {0}", ex.Message);
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
@@ -589,20 +589,20 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DisconnectClient method
|
/// Does the actual disconnect business
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DisconnectClient()
|
public void DisconnectClient()
|
||||||
{
|
{
|
||||||
if (_client == null) return;
|
if (_client == null) return;
|
||||||
|
|
||||||
Debug.Console(1, this, "Disconnecting client");
|
this.LogInformation("Disconnecting client");
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
_client.DisconnectFromServer();
|
_client.DisconnectFromServer();
|
||||||
|
|
||||||
// close up client. ALWAYS use this when disconnecting.
|
// close up client. ALWAYS use this when disconnecting.
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
|
|
||||||
Debug.Console(2, this, "Disconnecting _client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
this.LogVerbose("Disconnecting _client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
||||||
_client.SocketStatusChange -= Client_SocketStatusChange;
|
_client.SocketStatusChange -= Client_SocketStatusChange;
|
||||||
_client.Dispose();
|
_client.Dispose();
|
||||||
_client = null;
|
_client = null;
|
||||||
@@ -623,14 +623,14 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Cleaning up remotely closed/failed connection.");
|
this.LogVerbose("Cleaning up remotely closed/failed connection.");
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
if (!DisconnectCalledByUser && AutoReconnect)
|
if (!DisconnectCalledByUser && AutoReconnect)
|
||||||
{
|
{
|
||||||
var halfInterval = AutoReconnectIntervalMs / 2;
|
var halfInterval = AutoReconnectIntervalMs / 2;
|
||||||
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
||||||
Debug.Console(2, this, "Attempting reconnect in {0} ms, randomized", rndTime);
|
this.LogVerbose("Attempting reconnect in {0} ms, randomized", rndTime);
|
||||||
if (RetryTimer != null)
|
if (RetryTimer != null)
|
||||||
{
|
{
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
@@ -638,7 +638,9 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (AutoReconnectTriggered != null)
|
if (AutoReconnectTriggered != null)
|
||||||
AutoReconnectTriggered(this, new EventArgs());
|
AutoReconnectTriggered(this, new EventArgs());
|
||||||
RetryTimer = new CTimer(o => Connect(), rndTime);
|
RetryTimer = new Timer(rndTime) { AutoReset = false };
|
||||||
|
RetryTimer.Elapsed += (s, e) => Connect();
|
||||||
|
RetryTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,13 +659,13 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
||||||
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
||||||
Debug.Console(2, this, "_client Received:\r--------\r{0}\r--------", str);
|
this.LogVerbose("_client Received:\r--------\r{0}\r--------", str);
|
||||||
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (SharedKeyRequired && str == "SharedKey:")
|
if (SharedKeyRequired && str == "SharedKey:")
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Server asking for shared key, sending");
|
this.LogVerbose("Server asking for shared key, sending");
|
||||||
SendText(SharedKey + "\n");
|
SendText(SharedKey + "\n");
|
||||||
}
|
}
|
||||||
else if (SharedKeyRequired && str == "Shared Key Match")
|
else if (SharedKeyRequired && str == "Shared Key Match")
|
||||||
@@ -671,7 +673,7 @@ namespace PepperDash.Core
|
|||||||
StopWaitForSharedKeyTimer();
|
StopWaitForSharedKeyTimer();
|
||||||
|
|
||||||
|
|
||||||
Debug.Console(2, this, "Shared key confirmed. Ready for communication");
|
this.LogVerbose("Shared key confirmed. Ready for communication");
|
||||||
OnClientReadyForcommunications(true); // Successful key exchange
|
OnClientReadyForcommunications(true); // Successful key exchange
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -691,7 +693,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error receiving data: {1}. Error: {0}", ex.Message, str);
|
this.LogError("Error receiving data: {1}. Error: {0}", str, ex.Message);
|
||||||
}
|
}
|
||||||
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
client.ReceiveDataAsync(Receive);
|
client.ReceiveDataAsync(Receive);
|
||||||
@@ -699,9 +701,8 @@ namespace PepperDash.Core
|
|||||||
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var gotLock = DequeueLock.TryEnter();
|
if (System.Threading.Monitor.TryEnter(_dequeueLock))
|
||||||
if (gotLock)
|
System.Threading.Tasks.Task.Run(() => DequeueEvent());
|
||||||
CrestronInvoke.BeginInvoke((o) => DequeueEvent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //JAG added this as I believe the error return is 0 bytes like the server. See help when hover on ReceiveAsync
|
else //JAG added this as I believe the error return is 0 bytes like the server. See help when hover on ReceiveAsync
|
||||||
@@ -711,7 +712,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method gets spooled up in its own thread an protected by a CCriticalSection to prevent multiple threads from running concurrently.
|
/// This method gets spooled up in its own thread an protected by a lock to prevent multiple threads from running concurrently.
|
||||||
/// It will dequeue items as they are enqueued automatically.
|
/// It will dequeue items as they are enqueued automatically.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DequeueEvent()
|
void DequeueEvent()
|
||||||
@@ -731,13 +732,10 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
this.LogException(e, "DequeueEvent error");
|
this.LogError(e, "DequeueEvent error: {0}", e.Message);
|
||||||
}
|
|
||||||
// Make sure to leave the CCritical section in case an exception above stops this thread, or we won't be able to restart it.
|
|
||||||
if (DequeueLock != null)
|
|
||||||
{
|
|
||||||
DequeueLock.Leave();
|
|
||||||
}
|
}
|
||||||
|
// Make sure to release the lock in case an exception above stops this thread, or we won't be able to restart it.
|
||||||
|
System.Threading.Monitor.Exit(_dequeueLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartbeatStart()
|
void HeartbeatStart()
|
||||||
@@ -748,11 +746,15 @@ namespace PepperDash.Core
|
|||||||
if (HeartbeatSendTimer == null)
|
if (HeartbeatSendTimer == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
HeartbeatSendTimer = new CTimer(this.SendHeartbeat, null, HeartbeatInterval, HeartbeatInterval);
|
HeartbeatSendTimer = new Timer(HeartbeatInterval) { AutoReset = true };
|
||||||
|
HeartbeatSendTimer.Elapsed += (s, e) => SendHeartbeat(null);
|
||||||
|
HeartbeatSendTimer.Start();
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer == null)
|
if (HeartbeatAckTimer == null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,13 +764,13 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (HeartbeatSendTimer != null)
|
if (HeartbeatSendTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Send");
|
this.LogVerbose("Stoping Heartbeat Send");
|
||||||
HeartbeatSendTimer.Stop();
|
HeartbeatSendTimer.Stop();
|
||||||
HeartbeatSendTimer = null;
|
HeartbeatSendTimer = null;
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Ack");
|
this.LogVerbose("Stoping Heartbeat Ack");
|
||||||
HeartbeatAckTimer.Stop();
|
HeartbeatAckTimer.Stop();
|
||||||
HeartbeatAckTimer = null;
|
HeartbeatAckTimer = null;
|
||||||
}
|
}
|
||||||
@@ -777,7 +779,7 @@ namespace PepperDash.Core
|
|||||||
void SendHeartbeat(object notused)
|
void SendHeartbeat(object notused)
|
||||||
{
|
{
|
||||||
this.SendText(HeartbeatString);
|
this.SendText(HeartbeatString);
|
||||||
Debug.Console(2, this, "Sending Heartbeat");
|
this.LogVerbose("Sending Heartbeat");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,13 +798,17 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer.Reset(HeartbeatInterval * 2);
|
HeartbeatAckTimer.Stop();
|
||||||
|
HeartbeatAckTimer.Interval = HeartbeatInterval * 2;
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
Debug.Console(2, this, "Heartbeat Received: {0}, from Server", HeartbeatString);
|
this.LogVerbose("Heartbeat Received: {0}, from Server", HeartbeatString);
|
||||||
return remainingText;
|
return remainingText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -810,7 +816,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error checking heartbeat: {0}", ex.Message);
|
this.LogError(ex, "Error checking heartbeat: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@@ -824,7 +830,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
this.LogWarning("Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
||||||
SendText("Heartbeat not received by server, closing connection");
|
SendText("Heartbeat not received by server, closing connection");
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
@@ -832,7 +838,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ErrorLog.Error("Heartbeat timeout Error on _client: {0}, {1}", Key, ex);
|
this.LogError(ex, "Heartbeat timeout Error on _client: {0}, {1}", Key, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -849,7 +855,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendText method
|
/// General send method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
@@ -865,20 +871,20 @@ namespace PepperDash.Core
|
|||||||
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "[{0}] Sent zero bytes. Was there an error?", this.Key);
|
this.LogWarning("[{0}] Sent zero bytes. Was there an error?", this.Key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending text: {1}. Error: {0}", ex.Message, text);
|
this.LogError(ex, "Error sending text: {1}. Error: {0}", ex.Message, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendBytes method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
@@ -891,7 +897,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending bytes. Error: {0}", ex.Message);
|
this.LogError(ex, "Error sending bytes. Error: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -910,7 +916,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
this.LogVerbose("Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
||||||
|
|
||||||
OnConnectionChange();
|
OnConnectionChange();
|
||||||
// The client could be null or disposed by this time...
|
// The client could be null or disposed by this time...
|
||||||
@@ -923,7 +929,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Error in socket status change callback. Error: {0}\r\r{1}", ex, ex.InnerException);
|
this.LogError(ex, "Error in socket status change callback. Error: {0}\r\r{1}", ex, ex.InnerException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -954,5 +960,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -15,12 +15,15 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic secure TCP/IP client for server
|
/// Generic secure TCP/IP client for server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -80,7 +83,7 @@ namespace PepperDash.Core
|
|||||||
public string Hostname { get; set; }
|
public string Hostname { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// The port number on which the server is listening.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -113,7 +116,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the SharedKey
|
/// SharedKey is sent for verification 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>
|
/// </summary>
|
||||||
public string SharedKey { get; set; }
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
@@ -123,7 +126,7 @@ namespace PepperDash.Core
|
|||||||
private bool WaitingForSharedKeyResponse { get; set; }
|
private bool WaitingForSharedKeyResponse { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the BufferSize
|
/// Defaults to 2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BufferSize { get; set; }
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
@@ -221,7 +224,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// private Timer for auto reconnect
|
/// private Timer for auto reconnect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer RetryTimer;
|
System.Timers.Timer RetryTimer;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -253,13 +256,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatInterval = (value * 1000); } }
|
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatInterval = (value * 1000); } }
|
||||||
|
|
||||||
CTimer HeartbeatSendTimer;
|
System.Timers.Timer HeartbeatSendTimer;
|
||||||
CTimer HeartbeatAckTimer;
|
System.Timers.Timer HeartbeatAckTimer;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to force disconnection on a dead connect attempt
|
/// Used to force disconnection on a dead connect attempt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer ConnectFailTimer;
|
System.Timers.Timer ConnectFailTimer;
|
||||||
CTimer WaitForSharedKey;
|
System.Timers.Timer WaitForSharedKey;
|
||||||
private int ConnectionCount;
|
private int ConnectionCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal secure client
|
/// Internal secure client
|
||||||
@@ -271,7 +274,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue lock
|
/// Queue lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CCriticalSection DequeueLock = new CCriticalSection();
|
private readonly object _dequeueLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
||||||
@@ -336,8 +339,9 @@ namespace PepperDash.Core
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize method
|
/// Initializes the client's key property, which is used to identify this client instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="key">The unique key that identifies this client instance.</param>
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
@@ -346,7 +350,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize called by the constructor that accepts a client config object. Can be called later to reset properties of client.
|
/// Initialize called by the constructor that accepts a client config object. Can be called later to reset properties of client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientConfigObject"></param>
|
/// <param name="clientConfigObject">The configuration object containing the client's settings.</param>
|
||||||
public void Initialize(TcpClientConfigObject clientConfigObject)
|
public void Initialize(TcpClientConfigObject clientConfigObject)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -387,7 +391,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Program stopping. Closing Client connection");
|
this.LogInformation("Program stopping. Closing Client connection");
|
||||||
ProgramIsStopping = true;
|
ProgramIsStopping = true;
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
@@ -395,22 +399,22 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
ConnectionCount++;
|
ConnectionCount++;
|
||||||
Debug.Console(2, this, "Attempting connect Count:{0}", ConnectionCount);
|
this.LogVerbose("Attempting connect Count:{0}", ConnectionCount);
|
||||||
|
|
||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already connected. Ignoring.");
|
this.LogInformation("Already connected. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already trying to connect. Ignoring.");
|
this.LogInformation("Already trying to connect. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -423,17 +427,17 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No address set");
|
this.LogWarning("DynamicTcpClient: No address set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: Invalid port");
|
this.LogWarning("DynamicTcpClient: Invalid port");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No Shared Key set");
|
this.LogWarning("DynamicTcpClient: No Shared Key set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,9 +458,10 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
||||||
|
|
||||||
ConnectFailTimer = new CTimer(o =>
|
ConnectFailTimer = new System.Timers.Timer(30000) { AutoReset = false };
|
||||||
|
ConnectFailTimer.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
this.LogError("Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
@@ -468,12 +473,13 @@ namespace PepperDash.Core
|
|||||||
//SecureClient.DisconnectFromServer();
|
//SecureClient.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}, 30000);
|
};
|
||||||
|
ConnectFailTimer.Start();
|
||||||
|
|
||||||
Debug.Console(2, this, "Making Connection Count:{0}", ConnectionCount);
|
this.LogVerbose("Making Connection Count:{0}", ConnectionCount);
|
||||||
Client.ConnectToServerAsync(o =>
|
Client.ConnectToServerAsync(o =>
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
this.LogVerbose("ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
||||||
|
|
||||||
if (ConnectFailTimer != null)
|
if (ConnectFailTimer != null)
|
||||||
{
|
{
|
||||||
@@ -483,22 +489,22 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
this.LogVerbose("Client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
||||||
o.ReceiveDataAsync(Receive);
|
o.ReceiveDataAsync(Receive);
|
||||||
|
|
||||||
if (SharedKeyRequired)
|
if (SharedKeyRequired)
|
||||||
{
|
{
|
||||||
WaitingForSharedKeyResponse = true;
|
WaitingForSharedKeyResponse = true;
|
||||||
WaitForSharedKey = new CTimer(timer =>
|
WaitForSharedKey = new System.Timers.Timer(15000) { AutoReset = false };
|
||||||
|
WaitForSharedKey.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
|
this.LogWarning("Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
|
||||||
// Debug.Console(1, this, "Connect attempt failed {0}", c.ClientStatus);
|
|
||||||
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
||||||
o.DisconnectFromServer();
|
o.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
//OnClientReadyForcommunications(false); // Should send false event
|
//OnClientReadyForcommunications(false); // Should send false event
|
||||||
}, 15000);
|
};
|
||||||
|
WaitForSharedKey.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -512,21 +518,21 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Connect attempt failed {0}", o.ClientStatus);
|
this.LogWarning("Connect attempt failed {0}", o.ClientStatus);
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Client connection exception: {0}", ex.Message);
|
this.LogError("Client connection exception: {0}", ex.Message);
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
@@ -556,7 +562,7 @@ namespace PepperDash.Core
|
|||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
//SecureClient.DisconnectFromServer();
|
//SecureClient.DisconnectFromServer();
|
||||||
Debug.Console(2, this, "Disconnecting Client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
this.LogVerbose("Disconnecting Client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
||||||
Client.SocketStatusChange -= Client_SocketStatusChange;
|
Client.SocketStatusChange -= Client_SocketStatusChange;
|
||||||
Client.Dispose();
|
Client.Dispose();
|
||||||
Client = null;
|
Client = null;
|
||||||
@@ -578,14 +584,14 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Cleaning up remotely closed/failed connection.");
|
this.LogVerbose("Cleaning up remotely closed/failed connection.");
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
if (!DisconnectCalledByUser && AutoReconnect)
|
if (!DisconnectCalledByUser && AutoReconnect)
|
||||||
{
|
{
|
||||||
var halfInterval = AutoReconnectIntervalMs / 2;
|
var halfInterval = AutoReconnectIntervalMs / 2;
|
||||||
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
||||||
Debug.Console(2, this, "Attempting reconnect in {0} ms, randomized", rndTime);
|
this.LogVerbose("Attempting reconnect in {0} ms, randomized", rndTime);
|
||||||
if (RetryTimer != null)
|
if (RetryTimer != null)
|
||||||
{
|
{
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
@@ -593,7 +599,9 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (AutoReconnectTriggered != null)
|
if (AutoReconnectTriggered != null)
|
||||||
AutoReconnectTriggered(this, new EventArgs());
|
AutoReconnectTriggered(this, new EventArgs());
|
||||||
RetryTimer = new CTimer(o => Connect(), rndTime);
|
RetryTimer = new System.Timers.Timer(rndTime) { AutoReset = false };
|
||||||
|
RetryTimer.Elapsed += (s, e) => Connect();
|
||||||
|
RetryTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,13 +620,13 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
||||||
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
||||||
Debug.Console(2, this, "Client Received:\r--------\r{0}\r--------", str);
|
this.LogVerbose("Client Received:\r--------\r{0}\r--------", str);
|
||||||
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (SharedKeyRequired && str == "SharedKey:")
|
if (SharedKeyRequired && str == "SharedKey:")
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Server asking for shared key, sending");
|
this.LogVerbose("Server asking for shared key, sending");
|
||||||
SendText(SharedKey + "\n");
|
SendText(SharedKey + "\n");
|
||||||
}
|
}
|
||||||
else if (SharedKeyRequired && str == "Shared Key Match")
|
else if (SharedKeyRequired && str == "Shared Key Match")
|
||||||
@@ -626,7 +634,7 @@ namespace PepperDash.Core
|
|||||||
StopWaitForSharedKeyTimer();
|
StopWaitForSharedKeyTimer();
|
||||||
|
|
||||||
|
|
||||||
Debug.Console(2, this, "Shared key confirmed. Ready for communication");
|
this.LogVerbose("Shared key confirmed. Ready for communication");
|
||||||
OnClientReadyForcommunications(true); // Successful key exchange
|
OnClientReadyForcommunications(true); // Successful key exchange
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -646,7 +654,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error receiving data: {1}. Error: {0}", ex.Message, str);
|
this.LogError("Error receiving data: {1}. Error: {0}", ex.Message, str);
|
||||||
}
|
}
|
||||||
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
client.ReceiveDataAsync(Receive);
|
client.ReceiveDataAsync(Receive);
|
||||||
@@ -654,9 +662,8 @@ namespace PepperDash.Core
|
|||||||
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var gotLock = DequeueLock.TryEnter();
|
if (Monitor.TryEnter(_dequeueLock))
|
||||||
if (gotLock)
|
Task.Run(() => DequeueEvent());
|
||||||
CrestronInvoke.BeginInvoke((o) => DequeueEvent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //JAG added this as I believe the error return is 0 bytes like the server. See help when hover on ReceiveAsync
|
else //JAG added this as I believe the error return is 0 bytes like the server. See help when hover on ReceiveAsync
|
||||||
@@ -666,7 +673,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method gets spooled up in its own thread an protected by a CCriticalSection to prevent multiple threads from running concurrently.
|
/// This method gets spooled up in its own thread an protected by a lock to prevent multiple threads from running concurrently.
|
||||||
/// It will dequeue items as they are enqueued automatically.
|
/// It will dequeue items as they are enqueued automatically.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DequeueEvent()
|
void DequeueEvent()
|
||||||
@@ -686,28 +693,29 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
this.LogException(e, "DequeueEvent error");
|
this.LogError("DequeueEvent error: {0}", e.Message, e);
|
||||||
}
|
|
||||||
// Make sure to leave the CCritical section in case an exception above stops this thread, or we won't be able to restart it.
|
|
||||||
if (DequeueLock != null)
|
|
||||||
{
|
|
||||||
DequeueLock.Leave();
|
|
||||||
}
|
}
|
||||||
|
// Make sure to release the lock in case an exception above stops this thread, or we won't be able to restart it.
|
||||||
|
Monitor.Exit(_dequeueLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartbeatStart()
|
void HeartbeatStart()
|
||||||
{
|
{
|
||||||
if (HeartbeatEnabled)
|
if (HeartbeatEnabled)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Starting Heartbeat");
|
this.LogVerbose("Starting Heartbeat");
|
||||||
if (HeartbeatSendTimer == null)
|
if (HeartbeatSendTimer == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
HeartbeatSendTimer = new CTimer(this.SendHeartbeat, null, HeartbeatInterval, HeartbeatInterval);
|
HeartbeatSendTimer = new System.Timers.Timer(HeartbeatInterval) { AutoReset = true };
|
||||||
|
HeartbeatSendTimer.Elapsed += (s, e) => SendHeartbeat(null);
|
||||||
|
HeartbeatSendTimer.Start();
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer == null)
|
if (HeartbeatAckTimer == null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new System.Timers.Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,13 +725,13 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (HeartbeatSendTimer != null)
|
if (HeartbeatSendTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Send");
|
this.LogVerbose("Stopping Heartbeat Send");
|
||||||
HeartbeatSendTimer.Stop();
|
HeartbeatSendTimer.Stop();
|
||||||
HeartbeatSendTimer = null;
|
HeartbeatSendTimer = null;
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Ack");
|
this.LogVerbose("Stopping Heartbeat Ack");
|
||||||
HeartbeatAckTimer.Stop();
|
HeartbeatAckTimer.Stop();
|
||||||
HeartbeatAckTimer = null;
|
HeartbeatAckTimer = null;
|
||||||
}
|
}
|
||||||
@@ -732,7 +740,7 @@ namespace PepperDash.Core
|
|||||||
void SendHeartbeat(object notused)
|
void SendHeartbeat(object notused)
|
||||||
{
|
{
|
||||||
this.SendText(HeartbeatString);
|
this.SendText(HeartbeatString);
|
||||||
Debug.Console(2, this, "Sending Heartbeat");
|
this.LogVerbose("Sending Heartbeat");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,13 +759,17 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer.Reset(HeartbeatInterval * 2);
|
HeartbeatAckTimer.Stop();
|
||||||
|
HeartbeatAckTimer.Interval = HeartbeatInterval * 2;
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new System.Timers.Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
Debug.Console(2, this, "Heartbeat Received: {0}, from Server", HeartbeatString);
|
this.LogVerbose("Heartbeat Received: {0}, from Server", HeartbeatString);
|
||||||
return remainingText;
|
return remainingText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -765,7 +777,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error checking heartbeat: {0}", ex.Message);
|
this.LogError("Error checking heartbeat: {0}", ex.Message, ex);
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@@ -779,7 +791,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
this.LogWarning("Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
||||||
SendText("Heartbeat not received by server, closing connection");
|
SendText("Heartbeat not received by server, closing connection");
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
@@ -787,7 +799,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ErrorLog.Error("Heartbeat timeout Error on Client: {0}, {1}", Key, ex);
|
this.LogError("Heartbeat timeout Error on Client: {0}, {1}", Key, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,7 +816,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendText method
|
/// General send method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
@@ -820,20 +832,20 @@ namespace PepperDash.Core
|
|||||||
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "[{0}] Sent zero bytes. Was there an error?", this.Key);
|
this.LogWarning("[{0}] Sent zero bytes. Was there an error?", this.Key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending text: {1}. Error: {0}", ex.Message, text);
|
this.LogError("Error sending text: {1}. Error: {0}", text, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendBytes method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
@@ -846,7 +858,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending bytes. Error: {0}", ex.Message);
|
this.LogError("Error sending bytes. Error: {0}", ex.Message, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -865,7 +877,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
this.LogDebug("Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
||||||
|
|
||||||
OnConnectionChange();
|
OnConnectionChange();
|
||||||
// The client could be null or disposed by this time...
|
// The client could be null or disposed by this time...
|
||||||
@@ -878,7 +890,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Error in socket status change callback. Error: {0}\r\r{1}", ex, ex.InnerException);
|
this.LogError("Error in socket status change callback. Error: {0}\r\r{1}", ex, ex.InnerException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,5 +917,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +1,14 @@
|
|||||||
/*PepperDash Technology Corp.
|
using System;
|
||||||
JAG
|
|
||||||
Copyright: 2017
|
|
||||||
------------------------------------
|
|
||||||
***Notice of Ownership and Copyright***
|
|
||||||
The material in which this notice appears is the property of PepperDash Technology Corporation,
|
|
||||||
which claims copyright under the laws of the United States of America in the entire body of material
|
|
||||||
and in all parts thereof, regardless of the use to which it is being put. Any use, in whole or in part,
|
|
||||||
of this material by another party without the express written permission of PepperDash Technology Corporation is prohibited.
|
|
||||||
PepperDash Technology Corporation reserves all rights under applicable laws.
|
|
||||||
------------------------------------ */
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic secure TCP/IP server
|
/// Generic secure TCP/IP server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,7 +48,7 @@ namespace PepperDash.Core
|
|||||||
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delegate for ServerHasChokedCallbackDelegate
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate void ServerHasChokedCallbackDelegate();
|
public delegate void ServerHasChokedCallbackDelegate();
|
||||||
|
|
||||||
@@ -69,12 +59,17 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server listen lock
|
/// Server listen lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CCriticalSection ServerCCSection = new CCriticalSection();
|
private readonly object _serverLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue lock
|
/// Queue lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CCriticalSection DequeueLock = new CCriticalSection();
|
private readonly object _dequeueLock = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Broadcast lock
|
||||||
|
/// </summary>
|
||||||
|
private readonly object _broadcastLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
/// Receive Queue size. Defaults to 20. Will set to 20 if QueueSize property is less than 20. Use constructor or set queue size property before
|
||||||
@@ -96,7 +91,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer to operate the bandaid monitor client in a loop.
|
/// Timer to operate the bandaid monitor client in a loop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer MonitorClientTimer;
|
Timer MonitorClientTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -104,7 +99,7 @@ namespace PepperDash.Core
|
|||||||
int MonitorClientFailureCount;
|
int MonitorClientFailureCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the MonitorClientMaxFailureCount
|
/// 3 by default
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MonitorClientMaxFailureCount { get; set; }
|
public int MonitorClientMaxFailureCount { get; set; }
|
||||||
|
|
||||||
@@ -190,7 +185,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// Port Server should listen on
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -223,7 +218,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public string SharedKey { get; set; }
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
@@ -247,7 +243,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HeartbeatRequiredIntervalMs
|
/// Milliseconds before server expects another heartbeat. Set by property HeartbeatRequiredIntervalInSeconds which is driven from S+
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int HeartbeatRequiredIntervalMs { get; set; }
|
public int HeartbeatRequiredIntervalMs { get; set; }
|
||||||
|
|
||||||
@@ -257,12 +253,12 @@ namespace PepperDash.Core
|
|||||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HeartbeatStringToMatch
|
/// String to Match for heartbeat. If null or empty any string will reset heartbeat timer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string HeartbeatStringToMatch { get; set; }
|
public string HeartbeatStringToMatch { get; set; }
|
||||||
|
|
||||||
//private timers for Heartbeats per client
|
//private timers for Heartbeats per client
|
||||||
Dictionary<uint, CTimer> HeartbeatTimerDictionary = new Dictionary<uint, CTimer>();
|
Dictionary<uint, Timer> HeartbeatTimerDictionary = new Dictionary<uint, Timer>();
|
||||||
|
|
||||||
//flags to show the secure server is waiting for client at index to send the shared key
|
//flags to show the secure server is waiting for client at index to send the shared key
|
||||||
List<uint> WaitingForSharedKey = new List<uint>();
|
List<uint> WaitingForSharedKey = new List<uint>();
|
||||||
@@ -275,7 +271,7 @@ namespace PepperDash.Core
|
|||||||
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the BufferSize
|
/// Defaults to 2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BufferSize { get; set; }
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
@@ -338,7 +334,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
#region Methods - Server Actions
|
#region Methods - Server Actions
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// KillServer method
|
/// Disconnects all clients and stops the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void KillServer()
|
public void KillServer()
|
||||||
{
|
{
|
||||||
@@ -355,9 +351,6 @@ namespace PepperDash.Core
|
|||||||
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <summary>
|
|
||||||
/// Initialize method
|
|
||||||
/// </summary>
|
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
@@ -397,22 +390,23 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listen method
|
/// Start listening on the specified port
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Listen()
|
public void Listen()
|
||||||
{
|
{
|
||||||
ServerCCSection.Enter();
|
lock (_serverLock)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Server '{0}': Invalid port", Key);
|
this.LogError("Server '{0}': Invalid port", Key);
|
||||||
ErrorLog.Warn(string.Format("Server '{0}': Invalid port", Key));
|
ErrorLog.Warn(string.Format("Server '{0}': Invalid port", Key));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Server '{0}': No Shared Key set", Key);
|
this.LogError("Server '{0}': No Shared Key set", Key);
|
||||||
ErrorLog.Warn(string.Format("Server '{0}': No Shared Key set", Key));
|
ErrorLog.Warn(string.Format("Server '{0}': No Shared Key set", Key));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -436,43 +430,42 @@ namespace PepperDash.Core
|
|||||||
SocketErrorCodes status = SecureServer.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
SocketErrorCodes status = SecureServer.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
||||||
if (status != SocketErrorCodes.SOCKET_OPERATION_PENDING)
|
if (status != SocketErrorCodes.SOCKET_OPERATION_PENDING)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error starting WaitForConnectionAsync {0}", status);
|
this.LogError("Error starting WaitForConnectionAsync {0}", status);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ServerStopped = false;
|
ServerStopped = false;
|
||||||
}
|
}
|
||||||
OnServerStateChange(SecureServer.State);
|
OnServerStateChange(SecureServer.State);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Secure Server Status: {0}, Socket Status: {1}", SecureServer.State, SecureServer.ServerSocketStatus);
|
this.LogInformation("Secure Server Status: {0}, Socket Status: {1}", SecureServer.State, SecureServer.ServerSocketStatus);
|
||||||
ServerCCSection.Leave();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ServerCCSection.Leave();
|
this.LogException(ex, "{1} Error with Dynamic Server: {0}", ex.ToString(), Key);
|
||||||
ErrorLog.Error("{1} Error with Dynamic Server: {0}", ex.ToString(), Key);
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StopListening method
|
/// Stop Listeneing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StopListening()
|
public void StopListening()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Stopping Listener");
|
this.LogVerbose("Stopping Listener");
|
||||||
if (SecureServer != null)
|
if (SecureServer != null)
|
||||||
{
|
{
|
||||||
SecureServer.Stop();
|
SecureServer.Stop();
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Server State: {0}", SecureServer.State);
|
this.LogVerbose("Server State: {0}", SecureServer.State);
|
||||||
OnServerStateChange(SecureServer.State);
|
OnServerStateChange(SecureServer.State);
|
||||||
}
|
}
|
||||||
ServerStopped = true;
|
ServerStopped = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error stopping server. Error: {0}", ex);
|
this.LogException(ex, "Error stopping server. Error: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,27 +473,24 @@ namespace PepperDash.Core
|
|||||||
/// Disconnects Client
|
/// Disconnects Client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
/// <summary>
|
|
||||||
/// DisconnectClient method
|
|
||||||
/// </summary>
|
|
||||||
public void DisconnectClient(uint client)
|
public void DisconnectClient(uint client)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SecureServer.Disconnect(client);
|
SecureServer.Disconnect(client);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected client index: {0}", client);
|
this.LogVerbose("Disconnected client index: {0}", client);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Disconnecting client index: {0}. Error: {1}", client, ex);
|
this.LogException(ex, "Error Disconnecting client index: {0}. Error: {1}", client, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DisconnectAllClientsForShutdown method
|
/// Disconnect All Clients
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DisconnectAllClientsForShutdown()
|
public void DisconnectAllClientsForShutdown()
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Disconnecting All Clients");
|
this.LogInformation("Disconnecting All Clients");
|
||||||
if (SecureServer != null)
|
if (SecureServer != null)
|
||||||
{
|
{
|
||||||
SecureServer.SocketStatusChange -= SecureServer_SocketStatusChange;
|
SecureServer.SocketStatusChange -= SecureServer_SocketStatusChange;
|
||||||
@@ -512,17 +502,17 @@ namespace PepperDash.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
SecureServer.Disconnect(i);
|
SecureServer.Disconnect(i);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected client index: {0}", i);
|
this.LogInformation("Disconnected client index: {0}", i);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Disconnecting client index: {0}. Error: {1}", i, ex);
|
this.LogException(ex, "Error Disconnecting client index: {0}. Error: {1}", i, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Server Status: {0}", SecureServer.ServerSocketStatus);
|
this.LogInformation("Server Status: {0}", SecureServer.ServerSocketStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected All Clients");
|
this.LogInformation("Disconnected All Clients");
|
||||||
ConnectedClientsIndexes.Clear();
|
ConnectedClientsIndexes.Clear();
|
||||||
|
|
||||||
if (!ProgramIsStopping)
|
if (!ProgramIsStopping)
|
||||||
@@ -538,13 +528,10 @@ namespace PepperDash.Core
|
|||||||
/// Broadcast text from server to all connected clients
|
/// Broadcast text from server to all connected clients
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <summary>
|
|
||||||
/// BroadcastText method
|
|
||||||
/// </summary>
|
|
||||||
public void BroadcastText(string text)
|
public void BroadcastText(string text)
|
||||||
{
|
{
|
||||||
CCriticalSection CCBroadcast = new CCriticalSection();
|
lock (_broadcastLock)
|
||||||
CCBroadcast.Enter();
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ConnectedClientsIndexes.Count > 0)
|
if (ConnectedClientsIndexes.Count > 0)
|
||||||
@@ -560,13 +547,12 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCBroadcast.Leave();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
CCBroadcast.Leave();
|
this.LogException(ex, "Error Broadcasting messages from server. Error: {0}", ex.Message);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Broadcasting messages from server. Error: {0}", ex.Message);
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -574,9 +560,6 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
/// <summary>
|
|
||||||
/// SendTextToClient method
|
|
||||||
/// </summary>
|
|
||||||
public void SendTextToClient(string text, uint clientIndex)
|
public void SendTextToClient(string text, uint clientIndex)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -590,7 +573,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Error sending text to client. Text: {1}. Error: {0}", ex.Message, text);
|
this.LogException(ex, "Error sending text to client. Text: {1}. Error: {0}", ex.Message, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,13 +591,19 @@ namespace PepperDash.Core
|
|||||||
if (noDelimiter.Contains(HeartbeatStringToMatch))
|
if (noDelimiter.Contains(HeartbeatStringToMatch))
|
||||||
{
|
{
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
HeartbeatTimerDictionary[clientIndex].Reset(HeartbeatRequiredIntervalMs);
|
{
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Stop();
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Interval = HeartbeatRequiredIntervalMs;
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Start();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CTimer HeartbeatTimer = new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs);
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, HeartbeatTimer);
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
Debug.Console(1, this, "Heartbeat Received: {0}, from client index: {1}", HeartbeatStringToMatch, clientIndex);
|
this.LogDebug("Heartbeat Received: {0}, from client index: {1}", HeartbeatStringToMatch, clientIndex);
|
||||||
// Return Heartbeat
|
// Return Heartbeat
|
||||||
SendTextToClient(HeartbeatStringToMatch, clientIndex);
|
SendTextToClient(HeartbeatStringToMatch, clientIndex);
|
||||||
return remainingText;
|
return remainingText;
|
||||||
@@ -623,19 +612,25 @@ namespace PepperDash.Core
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
HeartbeatTimerDictionary[clientIndex].Reset(HeartbeatRequiredIntervalMs);
|
{
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Stop();
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Interval = HeartbeatRequiredIntervalMs;
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Start();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CTimer HeartbeatTimer = new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs);
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, HeartbeatTimer);
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
Debug.Console(1, this, "Heartbeat Received: {0}, from client index: {1}", received, clientIndex);
|
this.LogInformation("Heartbeat Received: {0}, from client index: {1}", received, clientIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error checking heartbeat: {0}", ex.Message);
|
this.LogException(ex, "Error checking heartbeat: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@@ -645,16 +640,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// GetClientIPAddress method
|
|
||||||
/// </summary>
|
|
||||||
public string GetClientIPAddress(uint clientIndex)
|
public string GetClientIPAddress(uint clientIndex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
|
this.LogInformation("GetClientIPAddress Index: {0}", clientIndex);
|
||||||
if (!SharedKeyRequired || (SharedKeyRequired && ClientReadyAfterKeyExchange.Contains(clientIndex)))
|
if (!SharedKeyRequired || (SharedKeyRequired && ClientReadyAfterKeyExchange.Contains(clientIndex)))
|
||||||
{
|
{
|
||||||
var ipa = this.SecureServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
var ipa = this.SecureServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress IPAddreess: {0}", ipa);
|
this.LogInformation("GetClientIPAddress IPAddreess: {0}", ipa);
|
||||||
return ipa;
|
return ipa;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -677,14 +669,13 @@ namespace PepperDash.Core
|
|||||||
clientIndex = (uint)o;
|
clientIndex = (uint)o;
|
||||||
address = SecureServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
address = SecureServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Heartbeat not received for Client index {2} IP: {0}, DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE {1}",
|
this.LogInformation("Heartbeat not received for Client index {2} IP: {0}, DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE {1}",
|
||||||
address, string.IsNullOrEmpty(HeartbeatStringToMatch) ? "" : ("HeartbeatStringToMatch: " + HeartbeatStringToMatch), clientIndex);
|
address, string.IsNullOrEmpty(HeartbeatStringToMatch) ? "" : ("HeartbeatStringToMatch: " + HeartbeatStringToMatch), clientIndex);
|
||||||
|
|
||||||
if (SecureServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (SecureServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
SendTextToClient("Heartbeat not received by server, closing connection", clientIndex);
|
SendTextToClient("Heartbeat not received by server, closing connection", clientIndex);
|
||||||
|
|
||||||
var discoResult = SecureServer.Disconnect(clientIndex);
|
var discoResult = SecureServer.Disconnect(clientIndex);
|
||||||
//Debug.Console(1, this, "{0}", discoResult);
|
|
||||||
|
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
{
|
{
|
||||||
@@ -713,11 +704,9 @@ namespace PepperDash.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "SecureServerSocketStatusChange Index:{0} status:{1} Port:{2} IP:{3}", clientIndex, serverSocketStatus, this.SecureServer.GetPortNumberServerAcceptedConnectionFromForSpecificClient(clientIndex), this.SecureServer.GetLocalAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
|
||||||
if (serverSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (serverSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "SecureServerSocketStatusChange ConnectedCLients: {0} ServerState: {1} Port: {2}", SecureServer.NumberOfClientsConnected, SecureServer.State, SecureServer.PortNumber);
|
this.LogInformation("SecureServerSocketStatusChange ConnectedCLients: {0} ServerState: {1} Port: {2}", SecureServer.NumberOfClientsConnected, SecureServer.State, SecureServer.PortNumber);
|
||||||
|
|
||||||
if (ConnectedClientsIndexes.Contains(clientIndex))
|
if (ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
ConnectedClientsIndexes.Remove(clientIndex);
|
ConnectedClientsIndexes.Remove(clientIndex);
|
||||||
@@ -739,12 +728,12 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error in Socket Status Change Callback. Error: {0}", ex);
|
this.LogException(ex, "Error in Socket Status Change Callback. Error: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
//Use a thread for this event so that the server state updates to listening while this event is processed. Listening must be added to the server state
|
//Use a thread for this event so that the server state updates to listening while this event is processed. Listening must be added to the server state
|
||||||
//after every client connection so that the server can check and see if it is at max clients. Due to this the event fires and server listening enum bit flag
|
//after every client connection so that the server can check and see if it is at max clients. Due to this the event fires and server listening enum bit flag
|
||||||
//is not set. Putting in a thread allows the state to update before this event processes so that the subscribers to this event get accurate isListening in the event.
|
//is not set. Putting in a thread allows the state to update before this event processes so that the subscribers to this event get accurate isListening in the event.
|
||||||
CrestronInvoke.BeginInvoke(o => onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex)), null);
|
System.Threading.Tasks.Task.Run(() => onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -759,7 +748,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "ConnectCallback: IPAddress: {0}. Index: {1}. Status: {2}",
|
this.LogInformation("ConnectCallback: IPAddress: {0}. Index: {1}. Status: {2}",
|
||||||
server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex),
|
server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex),
|
||||||
clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
||||||
if (clientIndex != 0)
|
if (clientIndex != 0)
|
||||||
@@ -779,7 +768,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
byte[] b = Encoding.GetEncoding(28591).GetBytes("SharedKey:");
|
byte[] b = Encoding.GetEncoding(28591).GetBytes("SharedKey:");
|
||||||
server.SendDataAsync(clientIndex, b, b.Length, (x, y, z) => { });
|
server.SendDataAsync(clientIndex, b, b.Length, (x, y, z) => { });
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Sent Shared Key Request to client at {0}", server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
this.LogInformation("Sent Shared Key Request to client at {0}", server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -789,7 +778,10 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (!HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (!HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
{
|
{
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs));
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -798,19 +790,19 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Client attempt faulty.");
|
this.LogError("Client attempt faulty.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error in Socket Status Connect Callback. Error: {0}", ex);
|
this.LogException(ex, "Error in Socket Status Connect Callback. Error: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rearm the listner
|
// Rearm the listner
|
||||||
SocketErrorCodes status = server.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
SocketErrorCodes status = server.WaitForConnectionAsync(IPAddress.Any, SecureConnectCallback);
|
||||||
if (status != SocketErrorCodes.SOCKET_OPERATION_PENDING)
|
if (status != SocketErrorCodes.SOCKET_OPERATION_PENDING)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Socket status connect callback status {0}", status);
|
this.LogError("Socket status connect callback status {0}", status);
|
||||||
if (status == SocketErrorCodes.SOCKET_CONNECTION_IN_PROGRESS)
|
if (status == SocketErrorCodes.SOCKET_CONNECTION_IN_PROGRESS)
|
||||||
{
|
{
|
||||||
// There is an issue where on a failed negotiation we need to stop and start the server. This should still leave connected clients intact.
|
// There is an issue where on a failed negotiation we need to stop and start the server. This should still leave connected clients intact.
|
||||||
@@ -847,7 +839,7 @@ namespace PepperDash.Core
|
|||||||
if (received != SharedKey)
|
if (received != SharedKey)
|
||||||
{
|
{
|
||||||
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
this.LogWarning("Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
||||||
mySecureTCPServer.SendData(clientIndex, b, b.Length);
|
mySecureTCPServer.SendData(clientIndex, b, b.Length);
|
||||||
mySecureTCPServer.Disconnect(clientIndex);
|
mySecureTCPServer.Disconnect(clientIndex);
|
||||||
|
|
||||||
@@ -858,7 +850,7 @@ namespace PepperDash.Core
|
|||||||
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
||||||
mySecureTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
mySecureTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
||||||
OnServerClientReadyForCommunications(clientIndex);
|
OnServerClientReadyForCommunications(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
this.LogInformation("Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
||||||
{
|
{
|
||||||
@@ -871,7 +863,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
this.LogException(ex, "Error Receiving data: {0}. Error: {1}", received, ex.Message);
|
||||||
}
|
}
|
||||||
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (mySecureTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedDataAsyncCallback);
|
mySecureTCPServer.ReceiveDataAsync(clientIndex, SecureReceivedDataAsyncCallback);
|
||||||
@@ -879,9 +871,8 @@ namespace PepperDash.Core
|
|||||||
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
//Check to see if there is a subscription to the TextReceivedQueueInvoke event. If there is start the dequeue thread.
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
{
|
{
|
||||||
var gotLock = DequeueLock.TryEnter();
|
if (System.Threading.Monitor.TryEnter(_dequeueLock))
|
||||||
if (gotLock)
|
System.Threading.Tasks.Task.Run(() => DequeueEvent());
|
||||||
CrestronInvoke.BeginInvoke((o) => DequeueEvent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -891,7 +882,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method gets spooled up in its own thread an protected by a CCriticalSection to prevent multiple threads from running concurrently.
|
/// This method gets spooled up in its own thread an protected by a lock to prevent multiple threads from running concurrently.
|
||||||
/// It will dequeue items as they are enqueued automatically.
|
/// It will dequeue items as they are enqueued automatically.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DequeueEvent()
|
void DequeueEvent()
|
||||||
@@ -911,13 +902,10 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
this.LogException(e, "DequeueEvent error");
|
this.LogError(e, "DequeueEvent error");
|
||||||
}
|
|
||||||
// Make sure to leave the CCritical section in case an exception above stops this thread, or we won't be able to restart it.
|
|
||||||
if (DequeueLock != null)
|
|
||||||
{
|
|
||||||
DequeueLock.Leave();
|
|
||||||
}
|
}
|
||||||
|
// Make sure to release the lock in case an exception above stops this thread, or we won't be able to restart it.
|
||||||
|
System.Threading.Monitor.Exit(_dequeueLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -988,7 +976,7 @@ namespace PepperDash.Core
|
|||||||
if (MonitorClient != null)
|
if (MonitorClient != null)
|
||||||
MonitorClient.Disconnect();
|
MonitorClient.Disconnect();
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Program stopping. Closing server");
|
this.LogInformation("Program stopping. Closing server");
|
||||||
KillServer();
|
KillServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1014,7 +1002,9 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MonitorClientTimer = new CTimer(o => RunMonitorClient(), 60000);
|
MonitorClientTimer = new Timer(60000) { AutoReset = false };
|
||||||
|
MonitorClientTimer.Elapsed += (s, e) => RunMonitorClient();
|
||||||
|
MonitorClientTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1029,7 +1019,7 @@ namespace PepperDash.Core
|
|||||||
//MonitorClient.ConnectionChange += MonitorClient_ConnectionChange;
|
//MonitorClient.ConnectionChange += MonitorClient_ConnectionChange;
|
||||||
MonitorClient.ClientReadyForCommunications += MonitorClient_IsReadyForComm;
|
MonitorClient.ClientReadyForCommunications += MonitorClient_IsReadyForComm;
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Starting monitor check");
|
this.LogInformation("Starting monitor check");
|
||||||
|
|
||||||
MonitorClient.Connect();
|
MonitorClient.Connect();
|
||||||
// From here MonitorCLient either connects or hangs, MonitorClient will call back
|
// From here MonitorCLient either connects or hangs, MonitorClient will call back
|
||||||
@@ -1056,7 +1046,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (args.IsReady)
|
if (args.IsReady)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Monitor client connection success. Disconnecting in 2s");
|
this.LogInformation("Monitor client connection success. Disconnecting in 2s");
|
||||||
MonitorClientTimer.Stop();
|
MonitorClientTimer.Stop();
|
||||||
MonitorClientTimer = null;
|
MonitorClientTimer = null;
|
||||||
MonitorClientFailureCount = 0;
|
MonitorClientFailureCount = 0;
|
||||||
@@ -1077,13 +1067,13 @@ namespace PepperDash.Core
|
|||||||
StopMonitorClient();
|
StopMonitorClient();
|
||||||
if (MonitorClientFailureCount < MonitorClientMaxFailureCount)
|
if (MonitorClientFailureCount < MonitorClientMaxFailureCount)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Warning, "Monitor client connection has hung {0} time{1}, maximum {2}",
|
this.LogWarning("Monitor client connection has hung {0} time{1}, maximum {2}",
|
||||||
MonitorClientFailureCount, MonitorClientFailureCount > 1 ? "s" : "", MonitorClientMaxFailureCount);
|
MonitorClientFailureCount, MonitorClientFailureCount > 1 ? "s" : "", MonitorClientMaxFailureCount);
|
||||||
StartMonitorClient();
|
StartMonitorClient();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error,
|
this.LogError(
|
||||||
"\r***************************\rMonitor client connection has hung a maximum of {0} times. \r***************************",
|
"\r***************************\rMonitor client connection has hung a maximum of {0} times. \r***************************",
|
||||||
MonitorClientMaxFailureCount);
|
MonitorClientMaxFailureCount);
|
||||||
|
|
||||||
@@ -1095,4 +1085,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using Org.BouncyCastle.Utilities;
|
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
using Renci.SshNet;
|
using Renci.SshNet;
|
||||||
using Renci.SshNet.Common;
|
using Renci.SshNet.Common;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,13 +35,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
|
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/////
|
/////
|
||||||
///// </summary>
|
///// </summary>
|
||||||
//public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
//public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Hostname
|
/// Address of server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Hostname { get; set; }
|
public string Hostname { get; set; }
|
||||||
|
|
||||||
@@ -52,12 +51,12 @@ namespace PepperDash.Core
|
|||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Username
|
/// Username for server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Password
|
/// And... Password for server. That was worth documenting!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Socket status change event
|
/// SSH Client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SocketStatus ClientStatus
|
public SocketStatus ClientStatus
|
||||||
{
|
{
|
||||||
@@ -123,7 +122,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the AutoReconnectIntervalMs
|
/// Millisecond value, determines the timeout period in between reconnect attempts.
|
||||||
|
/// Set to 5000 by default
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int AutoReconnectIntervalMs { get; set; }
|
public int AutoReconnectIntervalMs { get; set; }
|
||||||
|
|
||||||
@@ -131,11 +131,9 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
ShellStream TheStream;
|
ShellStream TheStream;
|
||||||
|
|
||||||
CTimer ReconnectTimer;
|
Timer ReconnectTimer;
|
||||||
|
|
||||||
//Lock object to prevent simulatneous connect/disconnect operations
|
private System.Threading.SemaphoreSlim connectLock = new System.Threading.SemaphoreSlim(1);
|
||||||
//private CCriticalSection connectLock = new CCriticalSection();
|
|
||||||
private SemaphoreSlim connectLock = new SemaphoreSlim(1);
|
|
||||||
|
|
||||||
private bool DisconnectLogged = false;
|
private bool DisconnectLogged = false;
|
||||||
|
|
||||||
@@ -154,13 +152,14 @@ namespace PepperDash.Core
|
|||||||
Password = password;
|
Password = password;
|
||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
|
|
||||||
ReconnectTimer = new CTimer(o =>
|
ReconnectTimer = new Timer { AutoReset = false, Enabled = false };
|
||||||
|
ReconnectTimer.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
if (ConnectEnabled)
|
if (ConnectEnabled)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
}
|
}
|
||||||
}, System.Threading.Timeout.Infinite);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -172,13 +171,14 @@ namespace PepperDash.Core
|
|||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
|
|
||||||
ReconnectTimer = new CTimer(o =>
|
ReconnectTimer = new Timer { AutoReset = false, Enabled = false };
|
||||||
|
ReconnectTimer.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
if (ConnectEnabled)
|
if (ConnectEnabled)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
}
|
}
|
||||||
}, System.Threading.Timeout.Infinite);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -197,7 +197,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Connect to the server, using the provided properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
@@ -223,7 +223,10 @@ namespace PepperDash.Core
|
|||||||
this.LogDebug("Attempting connect");
|
this.LogDebug("Attempting connect");
|
||||||
|
|
||||||
// Cancel reconnect if running.
|
// Cancel reconnect if running.
|
||||||
ReconnectTimer?.Stop();
|
if (ReconnectTimer != null)
|
||||||
|
{
|
||||||
|
ReconnectTimer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup the old client if it already exists
|
// Cleanup the old client if it already exists
|
||||||
if (Client != null)
|
if (Client != null)
|
||||||
@@ -261,37 +264,32 @@ namespace PepperDash.Core
|
|||||||
catch (SshConnectionException e)
|
catch (SshConnectionException e)
|
||||||
{
|
{
|
||||||
var ie = e.InnerException; // The details are inside!!
|
var ie = e.InnerException; // The details are inside!!
|
||||||
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
|
|
||||||
|
|
||||||
if (ie is SocketException)
|
if (ie is SocketException)
|
||||||
{
|
{
|
||||||
this.LogError("CONNECTION failure: Cannot reach host");
|
this.LogException(ie, "CONNECTION failure: Cannot reach host");
|
||||||
this.LogVerbose(ie, "Exception details: ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ie is System.Net.Sockets.SocketException socketException)
|
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);
|
Hostname, Port);
|
||||||
this.LogVerbose(socketException, "SocketException details: ");
|
|
||||||
}
|
}
|
||||||
if (ie is SshAuthenticationException)
|
if (ie is SshAuthenticationException)
|
||||||
{
|
{
|
||||||
this.LogError("Authentication failure for username {userName}", Username);
|
this.LogException(ie, "Authentication failure for username {userName}", Username);
|
||||||
this.LogVerbose(ie, "AuthenticationException details: ");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
this.LogException(ie, "Error on connect");
|
||||||
this.LogError("Error on connect: {error}", ie.Message);
|
|
||||||
this.LogVerbose(ie, "Exception details: ");
|
|
||||||
}
|
|
||||||
|
|
||||||
DisconnectLogged = true;
|
DisconnectLogged = true;
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
if (AutoReconnect)
|
if (AutoReconnect)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {autoReconnect}, {autoReconnectInterval}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {autoReconnect}, {autoReconnectInterval}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Interval = AutoReconnectIntervalMs;
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SshOperationTimeoutException ex)
|
catch (SshOperationTimeoutException ex)
|
||||||
@@ -303,20 +301,22 @@ namespace PepperDash.Core
|
|||||||
if (AutoReconnect)
|
if (AutoReconnect)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Interval = AutoReconnectIntervalMs;
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var errorLogLevel = DisconnectLogged == true ? Debug.ErrorLogLevel.None : Debug.ErrorLogLevel.Error;
|
this.LogException(e, "Unhandled exception on connect");
|
||||||
this.LogError("Unhandled exception on connect: {error}", e.Message);
|
|
||||||
this.LogVerbose(e, "Exception details: ");
|
|
||||||
DisconnectLogged = true;
|
DisconnectLogged = true;
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
if (AutoReconnect)
|
if (AutoReconnect)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Interval = AutoReconnectIntervalMs;
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,11 +334,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
ConnectEnabled = false;
|
ConnectEnabled = false;
|
||||||
// Stop trying reconnects, if we are
|
// Stop trying reconnects, if we are
|
||||||
if (ReconnectTimer != null)
|
|
||||||
{
|
|
||||||
ReconnectTimer.Stop();
|
ReconnectTimer.Stop();
|
||||||
// ReconnectTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
KillClient(SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY);
|
||||||
}
|
}
|
||||||
@@ -416,14 +412,18 @@ namespace PepperDash.Core
|
|||||||
if (bytesHandler != null)
|
if (bytesHandler != null)
|
||||||
{
|
{
|
||||||
var bytes = Encoding.UTF8.GetBytes(response);
|
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));
|
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
var textHandler = TextReceived;
|
var textHandler = TextReceived;
|
||||||
if (textHandler != null)
|
if (textHandler != null)
|
||||||
{
|
{
|
||||||
this.PrintReceivedText(response);
|
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||||
|
this.LogInformation("Received: '{0}'", ComTextHelper.GetDebugText(response));
|
||||||
|
|
||||||
textHandler(this, new GenericCommMethodReceiveTextArgs(response));
|
textHandler(this, new GenericCommMethodReceiveTextArgs(response));
|
||||||
}
|
}
|
||||||
@@ -437,7 +437,7 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void Client_ErrorOccurred(object sender, ExceptionEventArgs e)
|
void Client_ErrorOccurred(object sender, ExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
CrestronInvoke.BeginInvoke(o =>
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (e.Exception is SshConnectionException || e.Exception is System.Net.Sockets.SocketException)
|
if (e.Exception is SshConnectionException || e.Exception is System.Net.Sockets.SocketException)
|
||||||
this.LogError("Disconnected by remote");
|
this.LogError("Disconnected by remote");
|
||||||
@@ -455,7 +455,9 @@ namespace PepperDash.Core
|
|||||||
if (AutoReconnect && ConnectEnabled)
|
if (AutoReconnect && ConnectEnabled)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
ReconnectTimer.Reset(AutoReconnectIntervalMs);
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Interval = AutoReconnectIntervalMs;
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -465,7 +467,8 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void OnConnectionChange()
|
void OnConnectionChange()
|
||||||
{
|
{
|
||||||
ConnectionChange?.Invoke(this, new GenericSocketStatusChageEventArgs(this));
|
if (ConnectionChange != null)
|
||||||
|
ConnectionChange(this, new GenericSocketStatusChageEventArgs(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBasicCommunication Members
|
#region IBasicCommunication Members
|
||||||
@@ -473,14 +476,18 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends text to the server
|
/// Sends text to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to send</param>
|
/// <param name="text"></param>
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Client != null && TheStream != 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));
|
||||||
|
|
||||||
TheStream.Write(text);
|
TheStream.Write(text);
|
||||||
TheStream.Flush();
|
TheStream.Flush();
|
||||||
@@ -495,7 +502,8 @@ namespace PepperDash.Core
|
|||||||
this.LogError("ObjectDisposedException sending '{message}'. Restarting connection...", text.Trim());
|
this.LogError("ObjectDisposedException sending '{message}'. Restarting connection...", text.Trim());
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
ReconnectTimer.Reset();
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -506,14 +514,15 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends Bytes to the server
|
/// Sends Bytes to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes">The bytes to send</param>
|
/// <param name="bytes"></param>
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Client != null && TheStream != 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));
|
||||||
|
|
||||||
TheStream.Write(bytes, 0, bytes.Length);
|
TheStream.Write(bytes, 0, bytes.Length);
|
||||||
TheStream.Flush();
|
TheStream.Flush();
|
||||||
@@ -528,7 +537,8 @@ namespace PepperDash.Core
|
|||||||
this.LogException(ex, "ObjectDisposedException sending {message}", ComTextHelper.GetEscapedText(bytes));
|
this.LogException(ex, "ObjectDisposedException sending {message}", ComTextHelper.GetEscapedText(bytes));
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
ReconnectTimer.Reset();
|
ReconnectTimer.Stop();
|
||||||
|
ReconnectTimer.Start();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -537,12 +547,10 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//*****************************************************************************************************
|
//*****************************************************************************************************
|
||||||
//*****************************************************************************************************
|
//*****************************************************************************************************
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a SshConnectionChangeEventArgs
|
/// Fired when connection changes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SshConnectionChangeEventArgs : EventArgs
|
public class SshConnectionChangeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
@@ -552,17 +560,17 @@ namespace PepperDash.Core
|
|||||||
public bool IsConnected { get; private set; }
|
public bool IsConnected { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the UIsConnected
|
/// Connection Status represented as a ushort
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort UIsConnected { get { return (ushort)(Client.IsConnected ? 1 : 0); } }
|
public ushort UIsConnected { get { return (ushort)(Client.IsConnected ? 1 : 0); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Client
|
/// The client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GenericSshClient Client { get; private set; }
|
public GenericSshClient Client { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Status
|
/// Socket Status as represented by
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort Status { get { return Client.UStatus; } }
|
public ushort Status { get { return Client.UStatus; } }
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using Newtonsoft.Json;
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
|
using Required = NewtonsoftJson::Newtonsoft.Json.Required;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A class to handle basic TCP/IP communications with a server
|
/// A class to handle basic TCP/IP communications with a server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,7 +66,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// Port on server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -124,12 +131,6 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ClientStatusText { get { return ClientStatus.ToString(); } }
|
public string ClientStatusText { get { return ClientStatus.ToString(); } }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ushort representation of client status
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete]
|
|
||||||
public ushort UClientStatus { get { return (ushort)ClientStatus; } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connection failure reason
|
/// Connection failure reason
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -168,10 +169,10 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Lock object to prevent simulatneous connect/disconnect operations
|
//Lock object to prevent simulatneous connect/disconnect operations
|
||||||
private CCriticalSection connectLock = new CCriticalSection();
|
private readonly object _connectLock = new();
|
||||||
|
|
||||||
// private Timer for auto reconnect
|
// private Timer for auto reconnect
|
||||||
private CTimer RetryTimer;
|
private Timer RetryTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
@@ -190,10 +191,7 @@ namespace PepperDash.Core
|
|||||||
Port = port;
|
Port = port;
|
||||||
BufferSize = bufferSize;
|
BufferSize = bufferSize;
|
||||||
|
|
||||||
RetryTimer = new CTimer(o =>
|
SetupRetryTimer();
|
||||||
{
|
|
||||||
Reconnect();
|
|
||||||
}, Timeout.Infinite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -208,10 +206,7 @@ namespace PepperDash.Core
|
|||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
BufferSize = 2000;
|
BufferSize = 2000;
|
||||||
|
|
||||||
RetryTimer = new CTimer(o =>
|
SetupRetryTimer();
|
||||||
{
|
|
||||||
Reconnect();
|
|
||||||
}, Timeout.Infinite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -225,14 +220,19 @@ namespace PepperDash.Core
|
|||||||
AutoReconnectIntervalMs = 5000;
|
AutoReconnectIntervalMs = 5000;
|
||||||
BufferSize = 2000;
|
BufferSize = 2000;
|
||||||
|
|
||||||
RetryTimer = new CTimer(o =>
|
SetupRetryTimer();
|
||||||
{
|
|
||||||
Reconnect();
|
|
||||||
}, Timeout.Infinite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetupRetryTimer()
|
||||||
|
{
|
||||||
|
RetryTimer = new Timer { AutoReset = false, Enabled = false };
|
||||||
|
RetryTimer.Elapsed += (s, e) => Reconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize method
|
/// Just to help S+ set the key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
@@ -246,7 +246,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping)
|
if (programEventType == eProgramStatusEventType.Stopping)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Program stopping. Closing connection");
|
this.LogInformation("Program stopping. Closing connection");
|
||||||
Deactivate();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,9 +255,6 @@ namespace PepperDash.Core
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// Deactivate method
|
|
||||||
/// </summary>
|
|
||||||
public override bool Deactivate()
|
public override bool Deactivate()
|
||||||
{
|
{
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
@@ -271,29 +268,28 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Attempts to connect to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericTcpIpClient '{0}': No address set", Key);
|
this.LogWarning("GenericTcpIpClient '{0}': No address set", Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericTcpIpClient '{0}': Invalid port", Key);
|
this.LogWarning("GenericTcpIpClient '{0}': Invalid port", Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
lock (_connectLock)
|
||||||
{
|
{
|
||||||
connectLock.Enter();
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Connection already connected. Exiting Connect()");
|
this.LogInformation("Connection already connected. Exiting Connect()");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -306,10 +302,6 @@ namespace PepperDash.Core
|
|||||||
_client.ConnectToServerAsync(ConnectToServerCallback);
|
_client.ConnectToServerAsync(ConnectToServerCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
connectLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Reconnect()
|
private void Reconnect()
|
||||||
@@ -318,53 +310,43 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
lock (_connectLock)
|
||||||
{
|
{
|
||||||
connectLock.Enter();
|
|
||||||
if (IsConnected || DisconnectCalledByUser == true)
|
if (IsConnected || DisconnectCalledByUser == true)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Reconnect no longer needed. Exiting Reconnect()");
|
this.LogInformation("Reconnect no longer needed. Exiting Reconnect()");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Attempting reconnect now");
|
this.LogInformation("Attempting reconnect now");
|
||||||
_client.ConnectToServerAsync(ConnectToServerCallback);
|
_client.ConnectToServerAsync(ConnectToServerCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
connectLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect method
|
/// Attempts to disconnect the client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
try
|
lock (_connectLock)
|
||||||
{
|
{
|
||||||
connectLock.Enter();
|
|
||||||
DisconnectCalledByUser = true;
|
DisconnectCalledByUser = true;
|
||||||
|
|
||||||
// Stop trying reconnects, if we are
|
// Stop trying reconnects, if we are
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
DisconnectClient();
|
DisconnectClient();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
connectLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DisconnectClient method
|
/// Does the actual disconnect business
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DisconnectClient()
|
public void DisconnectClient()
|
||||||
{
|
{
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Disconnecting client");
|
this.LogInformation("Disconnecting client");
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
_client.DisconnectFromServer();
|
_client.DisconnectFromServer();
|
||||||
}
|
}
|
||||||
@@ -378,12 +360,12 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (c.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (c.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Server connection result: {0}", c.ClientStatus);
|
this.LogInformation("Server connection result: {0}", c.ClientStatus);
|
||||||
WaitAndTryReconnect();
|
WaitAndTryReconnect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Server connection result: {0}", c.ClientStatus);
|
this.LogInformation("Server connection result: {0}", c.ClientStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,22 +374,19 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void WaitAndTryReconnect()
|
void WaitAndTryReconnect()
|
||||||
{
|
{
|
||||||
CrestronInvoke.BeginInvoke(o =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
lock (_connectLock)
|
||||||
{
|
{
|
||||||
connectLock.Enter();
|
|
||||||
if (!IsConnected && AutoReconnect && !DisconnectCalledByUser && _client != null)
|
if (!IsConnected && AutoReconnect && !DisconnectCalledByUser && _client != null)
|
||||||
{
|
{
|
||||||
DisconnectClient();
|
DisconnectClient();
|
||||||
Debug.Console(1, this, "Attempting reconnect, status={0}", _client.ClientStatus);
|
this.LogInformation("Attempting reconnect, status={0}", _client.ClientStatus);
|
||||||
RetryTimer.Reset(AutoReconnectIntervalMs);
|
RetryTimer.Stop();
|
||||||
|
RetryTimer.Interval = AutoReconnectIntervalMs;
|
||||||
|
RetryTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
connectLock.Leave();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +405,10 @@ namespace PepperDash.Core
|
|||||||
var bytesHandler = BytesReceived;
|
var bytesHandler = BytesReceived;
|
||||||
if (bytesHandler != null)
|
if (bytesHandler != null)
|
||||||
{
|
{
|
||||||
this.PrintReceivedBytes(bytes);
|
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||||
|
{
|
||||||
|
this.LogInformation("Received {1} bytes: '{0}'", ComTextHelper.GetEscapedText(bytes), bytes.Length);
|
||||||
|
}
|
||||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||||
}
|
}
|
||||||
var textHandler = TextReceived;
|
var textHandler = TextReceived;
|
||||||
@@ -434,7 +416,10 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
var str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
this.PrintReceivedText(str);
|
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||||
|
{
|
||||||
|
this.LogInformation("Received {1} characters of text: '{0}'", ComTextHelper.GetDebugText(str), str.Length);
|
||||||
|
}
|
||||||
|
|
||||||
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
||||||
}
|
}
|
||||||
@@ -444,13 +429,14 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendText method
|
/// General send method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
||||||
// Check debug level before processing byte array
|
// Check debug level before processing byte array
|
||||||
this.PrintSentText(text);
|
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||||
|
this.LogInformation("Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
_client.SendData(bytes, bytes.Length);
|
_client.SendData(bytes, bytes.Length);
|
||||||
}
|
}
|
||||||
@@ -472,13 +458,10 @@ namespace PepperDash.Core
|
|||||||
/// Sends Bytes to the server
|
/// Sends Bytes to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes"></param>
|
/// <param name="bytes"></param>
|
||||||
/// <summary>
|
|
||||||
/// SendBytes method
|
|
||||||
/// </summary>
|
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||||
Debug.Console(0, this, "Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
this.LogInformation("Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
||||||
if (_client != null)
|
if (_client != null)
|
||||||
_client.SendData(bytes, bytes.Length);
|
_client.SendData(bytes, bytes.Length);
|
||||||
}
|
}
|
||||||
@@ -492,12 +475,12 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (clientSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (clientSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
this.LogDebug("Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
||||||
WaitAndTryReconnect();
|
WaitAndTryReconnect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
this.LogDebug("Socket status change {0} ({1})", clientSocketStatus, ClientStatusText);
|
||||||
_client.ReceiveDataAsync(Receive);
|
_client.ReceiveDataAsync(Receive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +491,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a TcpSshPropertiesConfig
|
/// Configuration properties for TCP/SSH Connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpSshPropertiesConfig
|
public class TcpSshPropertiesConfig
|
||||||
{
|
{
|
||||||
@@ -529,7 +512,7 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Password
|
/// Passord credential
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
@@ -548,6 +531,12 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int AutoReconnectIntervalMs { get; set; }
|
public int AutoReconnectIntervalMs { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When true, turns off echo for the SSH session
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("disableSshEcho")]
|
||||||
|
public bool DisableSshEcho { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -561,5 +550,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ PepperDash Technology Corporation reserves all rights under applicable laws.
|
|||||||
------------------------------------ */
|
------------------------------------ */
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic TCP/IP client for server
|
/// Generic TCP/IP client for server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -69,7 +68,7 @@ namespace PepperDash.Core
|
|||||||
public string Hostname { get; set; }
|
public string Hostname { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// Port on server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -102,7 +101,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public string SharedKey { get; set; }
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
@@ -112,7 +111,7 @@ namespace PepperDash.Core
|
|||||||
private bool WaitingForSharedKeyResponse { get; set; }
|
private bool WaitingForSharedKeyResponse { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the BufferSize
|
/// Defaults to 2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BufferSize { get; set; }
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
@@ -210,7 +209,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// private Timer for auto reconnect
|
/// private Timer for auto reconnect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer RetryTimer;
|
Timer RetryTimer;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -237,13 +236,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int HeartbeatInterval = 50000;
|
public int HeartbeatInterval = 50000;
|
||||||
|
|
||||||
CTimer HeartbeatSendTimer;
|
Timer HeartbeatSendTimer;
|
||||||
CTimer HeartbeatAckTimer;
|
Timer HeartbeatAckTimer;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to force disconnection on a dead connect attempt
|
/// Used to force disconnection on a dead connect attempt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer ConnectFailTimer;
|
Timer ConnectFailTimer;
|
||||||
CTimer WaitForSharedKey;
|
Timer WaitForSharedKey;
|
||||||
private int ConnectionCount;
|
private int ConnectionCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal secure client
|
/// Internal secure client
|
||||||
@@ -289,7 +288,7 @@ namespace PepperDash.Core
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize method
|
/// Just to help S+ set the key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
@@ -303,7 +302,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
if (programEventType == eProgramStatusEventType.Stopping || programEventType == eProgramStatusEventType.Paused)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Program stopping. Closing Client connection");
|
this.LogInformation("Program stopping. Closing Client connection");
|
||||||
ProgramIsStopping = true;
|
ProgramIsStopping = true;
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
@@ -311,22 +310,22 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Connect Method. Will return if already connected. Will write errors if missing address, port, or unique key/name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
ConnectionCount++;
|
ConnectionCount++;
|
||||||
Debug.Console(2, this, "Attempting connect Count:{0}", ConnectionCount);
|
this.LogDebug("Attempting connect Count:{0}", ConnectionCount);
|
||||||
|
|
||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already connected. Ignoring.");
|
this.LogInformation("Already connected. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Already trying to connect. Ignoring.");
|
this.LogInformation("Already trying to connect. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -339,17 +338,17 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No address set");
|
this.LogWarning("DynamicTcpClient: No address set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: Invalid port");
|
this.LogWarning("DynamicTcpClient: Invalid port");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "DynamicTcpClient: No Shared Key set");
|
this.LogWarning("DynamicTcpClient: No Shared Key set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,9 +369,10 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
//var timeOfConnect = DateTime.Now.ToString("HH:mm:ss.fff");
|
||||||
|
|
||||||
ConnectFailTimer = new CTimer(o =>
|
ConnectFailTimer = new Timer(30000) { AutoReset = false };
|
||||||
|
ConnectFailTimer.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
this.LogError("Connect attempt has not finished after 30sec Count:{0}", ConnectionCount);
|
||||||
if (IsTryingToConnect)
|
if (IsTryingToConnect)
|
||||||
{
|
{
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
@@ -384,12 +384,13 @@ namespace PepperDash.Core
|
|||||||
//SecureClient.DisconnectFromServer();
|
//SecureClient.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}, 30000);
|
};
|
||||||
|
ConnectFailTimer.Start();
|
||||||
|
|
||||||
Debug.Console(2, this, "Making Connection Count:{0}", ConnectionCount);
|
this.LogDebug("Making Connection Count:{0}", ConnectionCount);
|
||||||
Client.ConnectToServerAsync(o =>
|
Client.ConnectToServerAsync(o =>
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
this.LogDebug("ConnectToServerAsync Count:{0} Ran!", ConnectionCount);
|
||||||
|
|
||||||
if (ConnectFailTimer != null)
|
if (ConnectFailTimer != null)
|
||||||
{
|
{
|
||||||
@@ -399,22 +400,22 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (o.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
this.LogVerbose("Client connected to {0} on port {1}", o.AddressClientConnectedTo, o.LocalPortNumberOfClient);
|
||||||
o.ReceiveDataAsync(Receive);
|
o.ReceiveDataAsync(Receive);
|
||||||
|
|
||||||
if (SharedKeyRequired)
|
if (SharedKeyRequired)
|
||||||
{
|
{
|
||||||
WaitingForSharedKeyResponse = true;
|
WaitingForSharedKeyResponse = true;
|
||||||
WaitForSharedKey = new CTimer(timer =>
|
WaitForSharedKey = new Timer(15000) { AutoReset = false };
|
||||||
|
WaitForSharedKey.Elapsed += (s, e) =>
|
||||||
{
|
{
|
||||||
|
this.LogWarning("Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Shared key exchange timer expired. IsReadyForCommunication={0}", IsReadyForCommunication);
|
|
||||||
// Debug.Console(1, this, "Connect attempt failed {0}", c.ClientStatus);
|
|
||||||
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
// This is the only case where we should call DisconectFromServer...Event handeler will trigger the cleanup
|
||||||
o.DisconnectFromServer();
|
o.DisconnectFromServer();
|
||||||
//CheckClosedAndTryReconnect();
|
//CheckClosedAndTryReconnect();
|
||||||
//OnClientReadyForcommunications(false); // Should send false event
|
//OnClientReadyForcommunications(false); // Should send false event
|
||||||
}, 15000);
|
};
|
||||||
|
WaitForSharedKey.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -428,21 +429,22 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Connect attempt failed {0}", o.ClientStatus);
|
this.LogWarning("Connect attempt failed {0}", o.ClientStatus);
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Client connection exception: {0}", ex.Message);
|
this.LogException(ex, "Client connection exception: {0}", ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
IsTryingToConnect = false;
|
IsTryingToConnect = false;
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
@@ -472,7 +474,7 @@ namespace PepperDash.Core
|
|||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
//SecureClient.DisconnectFromServer();
|
//SecureClient.DisconnectFromServer();
|
||||||
Debug.Console(2, this, "Disconnecting Client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
this.LogVerbose("Disconnecting Client {0}", DisconnectCalledByUser ? ", Called by user" : "");
|
||||||
Client.SocketStatusChange -= Client_SocketStatusChange;
|
Client.SocketStatusChange -= Client_SocketStatusChange;
|
||||||
Client.Dispose();
|
Client.Dispose();
|
||||||
Client = null;
|
Client = null;
|
||||||
@@ -494,20 +496,22 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (Client != null)
|
if (Client != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Cleaning up remotely closed/failed connection.");
|
this.LogVerbose("Cleaning up remotely closed/failed connection.");
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
if (!DisconnectCalledByUser && AutoReconnect)
|
if (!DisconnectCalledByUser && AutoReconnect)
|
||||||
{
|
{
|
||||||
var halfInterval = AutoReconnectIntervalMs / 2;
|
var halfInterval = AutoReconnectIntervalMs / 2;
|
||||||
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
var rndTime = new Random().Next(-halfInterval, halfInterval) + AutoReconnectIntervalMs;
|
||||||
Debug.Console(2, this, "Attempting reconnect in {0} ms, randomized", rndTime);
|
this.LogVerbose("Attempting reconnect in {0} ms, randomized", rndTime);
|
||||||
if (RetryTimer != null)
|
if (RetryTimer != null)
|
||||||
{
|
{
|
||||||
RetryTimer.Stop();
|
RetryTimer.Stop();
|
||||||
RetryTimer = null;
|
RetryTimer = null;
|
||||||
}
|
}
|
||||||
RetryTimer = new CTimer(o => Connect(), rndTime);
|
RetryTimer = new Timer(rndTime) { AutoReset = false };
|
||||||
|
RetryTimer.Elapsed += (s, e) => Connect();
|
||||||
|
RetryTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,18 +530,18 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
var bytes = client.IncomingDataBuffer.Take(numBytes).ToArray();
|
||||||
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
str = Encoding.GetEncoding(28591).GetString(bytes, 0, bytes.Length);
|
||||||
Debug.Console(2, this, "Client Received:\r--------\r{0}\r--------", str);
|
this.LogVerbose("Client Received:\r--------\r{0}\r--------", str);
|
||||||
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
if (!string.IsNullOrEmpty(checkHeartbeat(str)))
|
||||||
{
|
{
|
||||||
if (SharedKeyRequired && str == "SharedKey:")
|
if (SharedKeyRequired && str == "SharedKey:")
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Server asking for shared key, sending");
|
this.LogVerbose("Server asking for shared key, sending");
|
||||||
SendText(SharedKey + "\n");
|
SendText(SharedKey + "\n");
|
||||||
}
|
}
|
||||||
else if (SharedKeyRequired && str == "Shared Key Match")
|
else if (SharedKeyRequired && str == "Shared Key Match")
|
||||||
{
|
{
|
||||||
StopWaitForSharedKeyTimer();
|
StopWaitForSharedKeyTimer();
|
||||||
Debug.Console(2, this, "Shared key confirmed. Ready for communication");
|
this.LogVerbose("Shared key confirmed. Ready for communication");
|
||||||
OnClientReadyForcommunications(true); // Successful key exchange
|
OnClientReadyForcommunications(true); // Successful key exchange
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -553,7 +557,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error receiving data: {1}. Error: {0}", ex.Message, str);
|
this.LogException(ex, "Error receiving data: {1}. Error: {0}", ex.Message, str);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
@@ -564,15 +569,19 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (HeartbeatEnabled)
|
if (HeartbeatEnabled)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Starting Heartbeat");
|
this.LogVerbose("Starting Heartbeat");
|
||||||
if (HeartbeatSendTimer == null)
|
if (HeartbeatSendTimer == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
HeartbeatSendTimer = new CTimer(this.SendHeartbeat, null, HeartbeatInterval, HeartbeatInterval);
|
HeartbeatSendTimer = new Timer(HeartbeatInterval) { AutoReset = true };
|
||||||
|
HeartbeatSendTimer.Elapsed += (s, e) => SendHeartbeat(null);
|
||||||
|
HeartbeatSendTimer.Start();
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer == null)
|
if (HeartbeatAckTimer == null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,13 +591,13 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (HeartbeatSendTimer != null)
|
if (HeartbeatSendTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Send");
|
this.LogVerbose("Stoping Heartbeat Send");
|
||||||
HeartbeatSendTimer.Stop();
|
HeartbeatSendTimer.Stop();
|
||||||
HeartbeatSendTimer = null;
|
HeartbeatSendTimer = null;
|
||||||
}
|
}
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Stoping Heartbeat Ack");
|
this.LogVerbose("Stoping Heartbeat Ack");
|
||||||
HeartbeatAckTimer.Stop();
|
HeartbeatAckTimer.Stop();
|
||||||
HeartbeatAckTimer = null;
|
HeartbeatAckTimer = null;
|
||||||
}
|
}
|
||||||
@@ -597,7 +606,7 @@ namespace PepperDash.Core
|
|||||||
void SendHeartbeat(object notused)
|
void SendHeartbeat(object notused)
|
||||||
{
|
{
|
||||||
this.SendText(HeartbeatString);
|
this.SendText(HeartbeatString);
|
||||||
Debug.Console(2, this, "Sending Heartbeat");
|
this.LogVerbose("Sending Heartbeat");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,13 +625,17 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (HeartbeatAckTimer != null)
|
if (HeartbeatAckTimer != null)
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer.Reset(HeartbeatInterval * 2);
|
HeartbeatAckTimer.Stop();
|
||||||
|
HeartbeatAckTimer.Interval = HeartbeatInterval * 2;
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HeartbeatAckTimer = new CTimer(HeartbeatAckTimerFail, null, (HeartbeatInterval * 2), (HeartbeatInterval * 2));
|
HeartbeatAckTimer = new Timer(HeartbeatInterval * 2) { AutoReset = true };
|
||||||
|
HeartbeatAckTimer.Elapsed += (s, e) => HeartbeatAckTimerFail(null);
|
||||||
|
HeartbeatAckTimer.Start();
|
||||||
}
|
}
|
||||||
Debug.Console(2, this, "Heartbeat Received: {0}, from Server", HeartbeatString);
|
this.LogVerbose("Heartbeat Received: {0}, from Server", HeartbeatString);
|
||||||
return remainingText;
|
return remainingText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,7 +643,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error checking heartbeat: {0}", ex.Message);
|
this.LogException(ex, "Error checking heartbeat: {0}", ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@@ -644,7 +658,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
this.LogWarning("Heartbeat not received from Server...DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE");
|
||||||
SendText("Heartbeat not received by server, closing connection");
|
SendText("Heartbeat not received by server, closing connection");
|
||||||
CheckClosedAndTryReconnect();
|
CheckClosedAndTryReconnect();
|
||||||
}
|
}
|
||||||
@@ -652,7 +666,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ErrorLog.Error("Heartbeat timeout Error on Client: {0}, {1}", Key, ex);
|
this.LogException(ex, "Heartbeat timeout Error on Client: {0}, {1}", Key, ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,7 +684,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendText method
|
/// General send method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
@@ -685,20 +700,21 @@ namespace PepperDash.Core
|
|||||||
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
// HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "[{0}] Sent zero bytes. Was there an error?", this.Key);
|
this.LogWarning("[{0}] Sent zero bytes. Was there an error?", this.Key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending text: {1}. Error: {0}", ex.Message, text);
|
this.LogException(ex, "Error sending text: {1}. Error: {0}", ex.Message, text);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SendBytes method
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
@@ -711,7 +727,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "Error sending bytes. Error: {0}", ex.Message);
|
this.LogException(ex, "Error sending bytes. Error: {0}", ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -730,7 +747,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
this.LogVerbose("Socket status change: {0} ({1})", client.ClientStatus, (ushort)(client.ClientStatus));
|
||||||
|
|
||||||
OnConnectionChange();
|
OnConnectionChange();
|
||||||
|
|
||||||
@@ -744,7 +761,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Error in socket status change callback. Error: {0}\r\r{1}", ex, ex.InnerException);
|
this.LogException(ex, "Error in socket status change callback. Error: {0}", ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace: {0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,5 +789,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -13,12 +13,13 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Timers;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic TCP/IP server device
|
/// Generic TCP/IP server device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,7 +53,7 @@ namespace PepperDash.Core
|
|||||||
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delegate for ServerHasChokedCallbackDelegate
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate void ServerHasChokedCallbackDelegate();
|
public delegate void ServerHasChokedCallbackDelegate();
|
||||||
|
|
||||||
@@ -61,9 +62,14 @@ namespace PepperDash.Core
|
|||||||
#region Properties/Variables
|
#region Properties/Variables
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Server listen lock
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CCriticalSection ServerCCSection = new CCriticalSection();
|
object _serverLock = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Broadcast lock
|
||||||
|
/// </summary>
|
||||||
|
private readonly object _broadcastLock = new();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -74,7 +80,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer to operate the bandaid monitor client in a loop.
|
/// Timer to operate the bandaid monitor client in a loop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer MonitorClientTimer;
|
Timer MonitorClientTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -82,7 +88,7 @@ namespace PepperDash.Core
|
|||||||
int MonitorClientFailureCount;
|
int MonitorClientFailureCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the MonitorClientMaxFailureCount
|
/// 3 by default
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MonitorClientMaxFailureCount { get; set; }
|
public int MonitorClientMaxFailureCount { get; set; }
|
||||||
|
|
||||||
@@ -171,7 +177,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Port
|
/// Port Server should listen on
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
|
|
||||||
@@ -204,7 +210,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public string SharedKey { get; set; }
|
public string SharedKey { get; set; }
|
||||||
|
|
||||||
@@ -228,7 +235,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HeartbeatRequiredIntervalMs
|
/// Milliseconds before server expects another heartbeat. Set by property HeartbeatRequiredIntervalInSeconds which is driven from S+
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int HeartbeatRequiredIntervalMs { get; set; }
|
public int HeartbeatRequiredIntervalMs { get; set; }
|
||||||
|
|
||||||
@@ -238,12 +245,12 @@ namespace PepperDash.Core
|
|||||||
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
public ushort HeartbeatRequiredIntervalInSeconds { set { HeartbeatRequiredIntervalMs = (value * 1000); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the HeartbeatStringToMatch
|
/// String to Match for heartbeat. If null or empty any string will reset heartbeat timer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string HeartbeatStringToMatch { get; set; }
|
public string HeartbeatStringToMatch { get; set; }
|
||||||
|
|
||||||
//private timers for Heartbeats per client
|
//private timers for Heartbeats per client
|
||||||
Dictionary<uint, CTimer> HeartbeatTimerDictionary = new Dictionary<uint, CTimer>();
|
Dictionary<uint, Timer> HeartbeatTimerDictionary = new Dictionary<uint, Timer>();
|
||||||
|
|
||||||
//flags to show the secure server is waiting for client at index to send the shared key
|
//flags to show the secure server is waiting for client at index to send the shared key
|
||||||
List<uint> WaitingForSharedKey = new List<uint>();
|
List<uint> WaitingForSharedKey = new List<uint>();
|
||||||
@@ -256,7 +263,7 @@ namespace PepperDash.Core
|
|||||||
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
public List<uint> ConnectedClientsIndexes = new List<uint>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the BufferSize
|
/// Defaults to 2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BufferSize { get; set; }
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
@@ -319,7 +326,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
#region Methods - Server Actions
|
#region Methods - Server Actions
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// KillServer method
|
/// Disconnects all clients and stops the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void KillServer()
|
public void KillServer()
|
||||||
{
|
{
|
||||||
@@ -336,9 +343,6 @@ namespace PepperDash.Core
|
|||||||
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
/// Initialize Key for device using client name from SIMPL+. Called on Listen from SIMPL+
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <summary>
|
|
||||||
/// Initialize method
|
|
||||||
/// </summary>
|
|
||||||
public void Initialize(string key)
|
public void Initialize(string key)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
@@ -367,33 +371,32 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ErrorLog.Error("Could not initialize server with key: {0}", serverConfigObject.Key);
|
this.LogError("Could not initialize server with key: {0}", serverConfigObject.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
ErrorLog.Error("Could not initialize server with key: {0}", serverConfigObject.Key);
|
this.LogError("Could not initialize server with key: {0}", serverConfigObject.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listen method
|
/// Start listening on the specified port
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Listen()
|
public void Listen()
|
||||||
{
|
{
|
||||||
ServerCCSection.Enter();
|
lock (_serverLock)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Server '{0}': Invalid port", Key);
|
this.LogError("Server '{0}': Invalid port", Key);
|
||||||
ErrorLog.Warn(string.Format("Server '{0}': Invalid port", Key));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
if (string.IsNullOrEmpty(SharedKey) && SharedKeyRequired)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Server '{0}': No Shared Key set", Key);
|
this.LogError("Server '{0}': No Shared Key set", Key);
|
||||||
ErrorLog.Warn(string.Format("Server '{0}': No Shared Key set", Key));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsListening)
|
if (IsListening)
|
||||||
@@ -419,39 +422,36 @@ namespace PepperDash.Core
|
|||||||
ServerStopped = false;
|
ServerStopped = false;
|
||||||
myTcpServer.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
myTcpServer.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
||||||
OnServerStateChange(myTcpServer.State);
|
OnServerStateChange(myTcpServer.State);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "TCP Server Status: {0}, Socket Status: {1}", myTcpServer.State, myTcpServer.ServerSocketStatus);
|
this.LogInformation("TCP Server Status: {0}, Socket Status: {1}", myTcpServer.State, myTcpServer.ServerSocketStatus);
|
||||||
|
|
||||||
// StartMonitorClient();
|
// StartMonitorClient();
|
||||||
|
|
||||||
|
|
||||||
ServerCCSection.Leave();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ServerCCSection.Leave();
|
this.LogException(ex, "Error with Dynamic Server: {0}", ex.Message);
|
||||||
ErrorLog.Error("{1} Error with Dynamic Server: {0}", ex.ToString(), Key);
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StopListening method
|
/// Stop Listening
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void StopListening()
|
public void StopListening()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Stopping Listener");
|
this.LogDebug("Stopping Listener");
|
||||||
if (myTcpServer != null)
|
if (myTcpServer != null)
|
||||||
{
|
{
|
||||||
myTcpServer.Stop();
|
myTcpServer.Stop();
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Server State: {0}", myTcpServer.State);
|
this.LogDebug("Server State: {0}", myTcpServer.State);
|
||||||
OnServerStateChange(myTcpServer.State);
|
OnServerStateChange(myTcpServer.State);
|
||||||
}
|
}
|
||||||
ServerStopped = true;
|
ServerStopped = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error stopping server. Error: {0}", ex);
|
this.LogException(ex, "Error stopping server. Error: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,27 +459,24 @@ namespace PepperDash.Core
|
|||||||
/// Disconnects Client
|
/// Disconnects Client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
/// <summary>
|
|
||||||
/// DisconnectClient method
|
|
||||||
/// </summary>
|
|
||||||
public void DisconnectClient(uint client)
|
public void DisconnectClient(uint client)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
myTcpServer.Disconnect(client);
|
myTcpServer.Disconnect(client);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected client index: {0}", client);
|
this.LogVerbose("Disconnected client index: {0}", client);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Disconnecting client index: {0}. Error: {1}", client, ex);
|
this.LogException(ex, "Error Disconnecting client index: {0}. Error: {1}", client, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DisconnectAllClientsForShutdown method
|
/// Disconnect All Clients
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DisconnectAllClientsForShutdown()
|
public void DisconnectAllClientsForShutdown()
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Disconnecting All Clients");
|
this.LogInformation("Disconnecting All Clients");
|
||||||
if (myTcpServer != null)
|
if (myTcpServer != null)
|
||||||
{
|
{
|
||||||
myTcpServer.SocketStatusChange -= TcpServer_SocketStatusChange;
|
myTcpServer.SocketStatusChange -= TcpServer_SocketStatusChange;
|
||||||
@@ -491,17 +488,17 @@ namespace PepperDash.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
myTcpServer.Disconnect(i);
|
myTcpServer.Disconnect(i);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected client index: {0}", i);
|
this.LogVerbose("Disconnected client index: {0}", i);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Disconnecting client index: {0}. Error: {1}", i, ex);
|
this.LogException(ex, "Error Disconnecting client index: {0}. Error: {1}", i, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Server Status: {0}", myTcpServer.ServerSocketStatus);
|
this.LogVerbose("Server Status: {0}", myTcpServer.ServerSocketStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Notice, "Disconnected All Clients");
|
this.LogInformation("Disconnected All Clients");
|
||||||
ConnectedClientsIndexes.Clear();
|
ConnectedClientsIndexes.Clear();
|
||||||
|
|
||||||
if (!ProgramIsStopping)
|
if (!ProgramIsStopping)
|
||||||
@@ -517,13 +514,10 @@ namespace PepperDash.Core
|
|||||||
/// Broadcast text from server to all connected clients
|
/// Broadcast text from server to all connected clients
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <summary>
|
|
||||||
/// BroadcastText method
|
|
||||||
/// </summary>
|
|
||||||
public void BroadcastText(string text)
|
public void BroadcastText(string text)
|
||||||
{
|
{
|
||||||
CCriticalSection CCBroadcast = new CCriticalSection();
|
lock (_broadcastLock)
|
||||||
CCBroadcast.Enter();
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ConnectedClientsIndexes.Count > 0)
|
if (ConnectedClientsIndexes.Count > 0)
|
||||||
@@ -539,13 +533,12 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCBroadcast.Leave();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
CCBroadcast.Leave();
|
this.LogException(ex, "Error Broadcasting messages from server. Error: {0}", ex.Message);
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Broadcasting messages from server. Error: {0}", ex.Message);
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -553,9 +546,6 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
/// <summary>
|
|
||||||
/// SendTextToClient method
|
|
||||||
/// </summary>
|
|
||||||
public void SendTextToClient(string text, uint clientIndex)
|
public void SendTextToClient(string text, uint clientIndex)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -569,7 +559,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Error sending text to client. Text: {1}. Error: {0}", ex.Message, text);
|
this.LogException(ex, "Error sending text to client. Text: {1}. Error: {0}", ex.Message, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,13 +577,19 @@ namespace PepperDash.Core
|
|||||||
if (noDelimiter.Contains(HeartbeatStringToMatch))
|
if (noDelimiter.Contains(HeartbeatStringToMatch))
|
||||||
{
|
{
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
HeartbeatTimerDictionary[clientIndex].Reset(HeartbeatRequiredIntervalMs);
|
{
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Stop();
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Interval = HeartbeatRequiredIntervalMs;
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Start();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CTimer HeartbeatTimer = new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs);
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, HeartbeatTimer);
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
Debug.Console(1, this, "Heartbeat Received: {0}, from client index: {1}", HeartbeatStringToMatch, clientIndex);
|
this.LogVerbose("Heartbeat Received: {0}, from client index: {1}", HeartbeatStringToMatch, clientIndex);
|
||||||
// Return Heartbeat
|
// Return Heartbeat
|
||||||
SendTextToClient(HeartbeatStringToMatch, clientIndex);
|
SendTextToClient(HeartbeatStringToMatch, clientIndex);
|
||||||
return remainingText;
|
return remainingText;
|
||||||
@@ -602,19 +598,25 @@ namespace PepperDash.Core
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
HeartbeatTimerDictionary[clientIndex].Reset(HeartbeatRequiredIntervalMs);
|
{
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Stop();
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Interval = HeartbeatRequiredIntervalMs;
|
||||||
|
HeartbeatTimerDictionary[clientIndex].Start();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CTimer HeartbeatTimer = new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs);
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, HeartbeatTimer);
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
Debug.Console(1, this, "Heartbeat Received: {0}, from client index: {1}", received, clientIndex);
|
this.LogVerbose("Heartbeat Received: {0}, from client index: {1}", received, clientIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Error checking heartbeat: {0}", ex.Message);
|
this.LogException(ex, "Error checking heartbeat: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
return received;
|
return received;
|
||||||
}
|
}
|
||||||
@@ -624,16 +626,13 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientIndex"></param>
|
/// <param name="clientIndex"></param>
|
||||||
/// <returns>IP address of the client</returns>
|
/// <returns>IP address of the client</returns>
|
||||||
/// <summary>
|
|
||||||
/// GetClientIPAddress method
|
|
||||||
/// </summary>
|
|
||||||
public string GetClientIPAddress(uint clientIndex)
|
public string GetClientIPAddress(uint clientIndex)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
|
this.LogVerbose("GetClientIPAddress Index: {0}", clientIndex);
|
||||||
if (!SharedKeyRequired || (SharedKeyRequired && ClientReadyAfterKeyExchange.Contains(clientIndex)))
|
if (!SharedKeyRequired || (SharedKeyRequired && ClientReadyAfterKeyExchange.Contains(clientIndex)))
|
||||||
{
|
{
|
||||||
var ipa = this.myTcpServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
var ipa = this.myTcpServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress IPAddreess: {0}", ipa);
|
this.LogVerbose("GetClientIPAddress IPAddreess: {0}", ipa);
|
||||||
return ipa;
|
return ipa;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -656,14 +655,13 @@ namespace PepperDash.Core
|
|||||||
clientIndex = (uint)o;
|
clientIndex = (uint)o;
|
||||||
address = myTcpServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
address = myTcpServer.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex);
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Heartbeat not received for Client index {2} IP: {0}, DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE {1}",
|
this.LogWarning("Heartbeat not received for Client index {2} IP: {0}, DISCONNECTING BECAUSE HEARTBEAT REQUIRED IS TRUE {1}",
|
||||||
address, string.IsNullOrEmpty(HeartbeatStringToMatch) ? "" : ("HeartbeatStringToMatch: " + HeartbeatStringToMatch), clientIndex);
|
address, string.IsNullOrEmpty(HeartbeatStringToMatch) ? "" : ("HeartbeatStringToMatch: " + HeartbeatStringToMatch), clientIndex);
|
||||||
|
|
||||||
if (myTcpServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (myTcpServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
SendTextToClient("Heartbeat not received by server, closing connection", clientIndex);
|
SendTextToClient("Heartbeat not received by server, closing connection", clientIndex);
|
||||||
|
|
||||||
var discoResult = myTcpServer.Disconnect(clientIndex);
|
var discoResult = myTcpServer.Disconnect(clientIndex);
|
||||||
//Debug.Console(1, this, "{0}", discoResult);
|
|
||||||
|
|
||||||
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
{
|
{
|
||||||
@@ -674,7 +672,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ErrorLog.Error("{3}: Heartbeat timeout Error on Client Index: {0}, at address: {1}, error: {2}", clientIndex, address, ex.Message, Key);
|
this.LogException(ex, "Heartbeat timeout Error on Client Index: {0}, at address: {1}, error: {2}", clientIndex, address, ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace:\r{0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,7 +691,7 @@ namespace PepperDash.Core
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "SecureServerSocketStatusChange Index:{0} status:{1} Port:{2} IP:{3}", clientIndex, serverSocketStatus, this.myTcpServer.GetPortNumberServerAcceptedConnectionFromForSpecificClient(clientIndex), this.myTcpServer.GetLocalAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
this.LogInformation("SecureServerSocketStatusChange Index:{0} status:{1} Port:{2} IP:{3}", clientIndex, serverSocketStatus, this.myTcpServer.GetPortNumberServerAcceptedConnectionFromForSpecificClient(clientIndex), this.myTcpServer.GetLocalAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
||||||
if (serverSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (serverSocketStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
{
|
{
|
||||||
if (ConnectedClientsIndexes.Contains(clientIndex))
|
if (ConnectedClientsIndexes.Contains(clientIndex))
|
||||||
@@ -711,7 +710,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error in Socket Status Change Callback. Error: {0}", ex);
|
this.LogException(ex, "Error in Socket Status Change Callback. Error: {0}", ex);
|
||||||
}
|
}
|
||||||
onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
onConnectionChange(clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
||||||
}
|
}
|
||||||
@@ -728,7 +727,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "ConnectCallback: IPAddress: {0}. Index: {1}. Status: {2}",
|
this.LogDebug("ConnectCallback: IPAddress: {0}. Index: {1}. Status: {2}",
|
||||||
server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex),
|
server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex),
|
||||||
clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
clientIndex, server.GetServerSocketStatusForSpecificClient(clientIndex));
|
||||||
if (clientIndex != 0)
|
if (clientIndex != 0)
|
||||||
@@ -748,17 +747,21 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
byte[] b = Encoding.GetEncoding(28591).GetBytes("SharedKey:");
|
byte[] b = Encoding.GetEncoding(28591).GetBytes("SharedKey:");
|
||||||
server.SendDataAsync(clientIndex, b, b.Length, (x, y, z) => { });
|
server.SendDataAsync(clientIndex, b, b.Length, (x, y, z) => { });
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Sent Shared Key Request to client at {0}", server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
this.LogDebug("Sent Shared Key Request to client at {0}", server.GetAddressServerAcceptedConnectionFromForSpecificClient(clientIndex));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
this.LogDebug("Client at index {0} is ready for communications", clientIndex);
|
||||||
OnServerClientReadyForCommunications(clientIndex);
|
OnServerClientReadyForCommunications(clientIndex);
|
||||||
}
|
}
|
||||||
if (HeartbeatRequired)
|
if (HeartbeatRequired)
|
||||||
{
|
{
|
||||||
if (!HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
if (!HeartbeatTimerDictionary.ContainsKey(clientIndex))
|
||||||
{
|
{
|
||||||
HeartbeatTimerDictionary.Add(clientIndex, new CTimer(HeartbeatTimer_CallbackFunction, clientIndex, HeartbeatRequiredIntervalMs));
|
var heartbeatTimer = new Timer(HeartbeatRequiredIntervalMs) { AutoReset = false };
|
||||||
|
heartbeatTimer.Elapsed += (s, e) => HeartbeatTimer_CallbackFunction(clientIndex);
|
||||||
|
heartbeatTimer.Start();
|
||||||
|
HeartbeatTimerDictionary.Add(clientIndex, heartbeatTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,7 +770,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Client attempt faulty.");
|
this.LogError("Client attempt faulty.");
|
||||||
if (!ServerStopped)
|
if (!ServerStopped)
|
||||||
{
|
{
|
||||||
server.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
server.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
||||||
@@ -777,15 +780,15 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error in Socket Status Connect Callback. Error: {0}", ex);
|
this.LogException(ex, "Error in Socket Status Connect Callback. Error: {0}", ex.Message);
|
||||||
|
this.LogVerbose("Stack Trace:\r{0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
//Debug.Console(1, this, Debug.ErrorLogLevel, "((((((Server State bitfield={0}; maxclient={1}; ServerStopped={2}))))))",
|
|
||||||
// server.State,
|
// server.State,
|
||||||
// MaxClients,
|
// MaxClients,
|
||||||
// ServerStopped);
|
// ServerStopped);
|
||||||
if ((server.State & ServerState.SERVER_LISTENING) != ServerState.SERVER_LISTENING && MaxClients > 1 && !ServerStopped)
|
if ((server.State & ServerState.SERVER_LISTENING) != ServerState.SERVER_LISTENING && MaxClients > 1 && !ServerStopped)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Waiting for next connection");
|
this.LogDebug("Waiting for next connection");
|
||||||
server.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
server.WaitForConnectionAsync(IPAddress.Any, TcpConnectCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -816,7 +819,7 @@ namespace PepperDash.Core
|
|||||||
if (received != SharedKey)
|
if (received != SharedKey)
|
||||||
{
|
{
|
||||||
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
byte[] b = Encoding.GetEncoding(28591).GetBytes("Shared key did not match server. Disconnecting");
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Warning, "Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
this.LogWarning("Client at index {0} Shared key did not match the server, disconnecting client. Key: {1}", clientIndex, received);
|
||||||
myTCPServer.SendData(clientIndex, b, b.Length);
|
myTCPServer.SendData(clientIndex, b, b.Length);
|
||||||
myTCPServer.Disconnect(clientIndex);
|
myTCPServer.Disconnect(clientIndex);
|
||||||
return;
|
return;
|
||||||
@@ -826,7 +829,7 @@ namespace PepperDash.Core
|
|||||||
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
byte[] success = Encoding.GetEncoding(28591).GetBytes("Shared Key Match");
|
||||||
myTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
myTCPServer.SendDataAsync(clientIndex, success, success.Length, null);
|
||||||
OnServerClientReadyForCommunications(clientIndex);
|
OnServerClientReadyForCommunications(clientIndex);
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
this.LogDebug("Client with index {0} provided the shared key and successfully connected to the server", clientIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
else if (!string.IsNullOrEmpty(checkHeartbeat(clientIndex, received)))
|
||||||
@@ -834,7 +837,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error, "Error Receiving data: {0}. Error: {1}", received, ex);
|
this.LogException(ex, "Error Receiving data: {0}. Error: {1}", received, ex);
|
||||||
}
|
}
|
||||||
if (myTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
if (myTCPServer.GetServerSocketStatusForSpecificClient(clientIndex) == SocketStatus.SOCKET_STATUS_CONNECTED)
|
||||||
myTCPServer.ReceiveDataAsync(clientIndex, TcpServerReceivedDataAsyncCallback);
|
myTCPServer.ReceiveDataAsync(clientIndex, TcpServerReceivedDataAsyncCallback);
|
||||||
@@ -915,7 +918,7 @@ namespace PepperDash.Core
|
|||||||
if (MonitorClient != null)
|
if (MonitorClient != null)
|
||||||
MonitorClient.Disconnect();
|
MonitorClient.Disconnect();
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Program stopping. Closing server");
|
this.LogInformation("Program stopping. Closing server");
|
||||||
KillServer();
|
KillServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -941,7 +944,9 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MonitorClientTimer = new CTimer(o => RunMonitorClient(), 60000);
|
MonitorClientTimer = new Timer(60000) { AutoReset = false };
|
||||||
|
MonitorClientTimer.Elapsed += (s, e) => RunMonitorClient();
|
||||||
|
MonitorClientTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -956,7 +961,7 @@ namespace PepperDash.Core
|
|||||||
//MonitorClient.ConnectionChange += MonitorClient_ConnectionChange;
|
//MonitorClient.ConnectionChange += MonitorClient_ConnectionChange;
|
||||||
MonitorClient.ClientReadyForCommunications += MonitorClient_IsReadyForComm;
|
MonitorClient.ClientReadyForCommunications += MonitorClient_IsReadyForComm;
|
||||||
|
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Starting monitor check");
|
this.LogDebug("Starting monitor check");
|
||||||
|
|
||||||
MonitorClient.Connect();
|
MonitorClient.Connect();
|
||||||
// From here MonitorCLient either connects or hangs, MonitorClient will call back
|
// From here MonitorCLient either connects or hangs, MonitorClient will call back
|
||||||
@@ -983,7 +988,7 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (args.IsReady)
|
if (args.IsReady)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Monitor client connection success. Disconnecting in 2s");
|
this.LogInformation("Monitor client connection success. Disconnecting in 2s");
|
||||||
MonitorClientTimer.Stop();
|
MonitorClientTimer.Stop();
|
||||||
MonitorClientTimer = null;
|
MonitorClientTimer = null;
|
||||||
MonitorClientFailureCount = 0;
|
MonitorClientFailureCount = 0;
|
||||||
@@ -1004,13 +1009,13 @@ namespace PepperDash.Core
|
|||||||
StopMonitorClient();
|
StopMonitorClient();
|
||||||
if (MonitorClientFailureCount < MonitorClientMaxFailureCount)
|
if (MonitorClientFailureCount < MonitorClientMaxFailureCount)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Warning, "Monitor client connection has hung {0} time{1}, maximum {2}",
|
this.LogWarning("Monitor client connection has hung {0} time{1}, maximum {2}",
|
||||||
MonitorClientFailureCount, MonitorClientFailureCount > 1 ? "s" : "", MonitorClientMaxFailureCount);
|
MonitorClientFailureCount, MonitorClientFailureCount > 1 ? "s" : "", MonitorClientMaxFailureCount);
|
||||||
StartMonitorClient();
|
StartMonitorClient();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, Debug.ErrorLogLevel.Error,
|
this.LogError(
|
||||||
"\r***************************\rMonitor client connection has hung a maximum of {0} times.\r***************************",
|
"\r***************************\rMonitor client connection has hung a maximum of {0} times.\r***************************",
|
||||||
MonitorClientMaxFailureCount);
|
MonitorClientMaxFailureCount);
|
||||||
|
|
||||||
@@ -1022,4 +1027,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
|
|
||||||
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using Newtonsoft.Json;
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
using PepperDash.Core.Logging;
|
using PepperDash.Core.Logging;
|
||||||
|
using Required = NewtonsoftJson::Newtonsoft.Json.Required;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic UDP Server device
|
/// Generic UDP Server device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -57,7 +60,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Represents a GenericUdpReceiveTextExtraArgs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort UStatus
|
public ushort UStatus
|
||||||
{
|
{
|
||||||
@@ -131,14 +134,14 @@ namespace PepperDash.Core
|
|||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="address"></param>
|
/// <param name="address"></param>
|
||||||
/// <param name="port"></param>
|
/// <param name="port"></param>
|
||||||
/// <param name="bufferSize"></param>
|
/// <param name="buffefSize"></param>
|
||||||
public GenericUdpServer(string key, string address, int port, int bufferSize)
|
public GenericUdpServer(string key, string address, int port, int buffefSize)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
StreamDebugging = new CommunicationStreamDebugging(key);
|
StreamDebugging = new CommunicationStreamDebugging(key);
|
||||||
Hostname = address;
|
Hostname = address;
|
||||||
Port = port;
|
Port = port;
|
||||||
BufferSize = bufferSize;
|
BufferSize = buffefSize;
|
||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||||
@@ -150,9 +153,6 @@ namespace PepperDash.Core
|
|||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="address"></param>
|
/// <param name="address"></param>
|
||||||
/// <param name="port"></param>
|
/// <param name="port"></param>
|
||||||
/// <summary>
|
|
||||||
/// Initialize method
|
|
||||||
/// </summary>
|
|
||||||
public void Initialize(string key, string address, ushort port)
|
public void Initialize(string key, string address, ushort port)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
@@ -183,50 +183,36 @@ namespace PepperDash.Core
|
|||||||
if (programEventType != eProgramStatusEventType.Stopping)
|
if (programEventType != eProgramStatusEventType.Stopping)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Console(1, this, "Program stopping. Disabling Server");
|
this.LogInformation("Program stopping. Disabling Server");
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect method
|
/// Enables the UDP Server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Connect()
|
public void Connect()
|
||||||
{
|
{
|
||||||
if (Server == null)
|
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();
|
Server = new UDPServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericUdpServer '{0}': No address set", Key);
|
this.LogWarning("GenericUdpServer '{0}': No address set", Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Port < 1 || Port > 65535)
|
if (Port < 1 || Port > 65535)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Debug.Console(1, Debug.ErrorLogLevel.Warning, "GenericUdpServer '{0}': Invalid port", Key);
|
this.LogWarning("GenericUdpServer '{0}': Invalid port", Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var status = Server.EnableUDPServer(Hostname, Port);
|
var status = Server.EnableUDPServer(Hostname, Port);
|
||||||
|
|
||||||
Debug.Console(2, this, "SocketErrorCode: {0}", status);
|
this.LogVerbose("SocketErrorCode: {0}", status);
|
||||||
if (status == SocketErrorCodes.SOCKET_OK)
|
if (status == SocketErrorCodes.SOCKET_OK)
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
|
|
||||||
@@ -239,7 +225,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect method
|
/// Disabled the UDP Server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
@@ -261,7 +247,7 @@ namespace PepperDash.Core
|
|||||||
/// <param name="numBytes"></param>
|
/// <param name="numBytes"></param>
|
||||||
void Receive(UDPServer server, int numBytes)
|
void Receive(UDPServer server, int numBytes)
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Received {0} bytes", numBytes);
|
this.LogVerbose("Received {0} bytes", numBytes);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -277,17 +263,21 @@ namespace PepperDash.Core
|
|||||||
if (dataRecivedExtra != null)
|
if (dataRecivedExtra != null)
|
||||||
dataRecivedExtra(this, new GenericUdpReceiveTextExtraArgs(str, sourceIp, sourcePort, bytes));
|
dataRecivedExtra(this, new GenericUdpReceiveTextExtraArgs(str, sourceIp, sourcePort, bytes));
|
||||||
|
|
||||||
Debug.Console(2, this, "Bytes: {0}", bytes.ToString());
|
this.LogVerbose("Bytes: {0}", bytes.ToString());
|
||||||
var bytesHandler = BytesReceived;
|
var bytesHandler = BytesReceived;
|
||||||
if (bytesHandler != null)
|
if (bytesHandler != null)
|
||||||
{
|
{
|
||||||
this.PrintReceivedBytes(bytes);
|
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||||
|
{
|
||||||
|
this.LogInformation("Received {1} bytes: '{0}'", ComTextHelper.GetEscapedText(bytes), bytes.Length);
|
||||||
|
}
|
||||||
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
bytesHandler(this, new GenericCommMethodReceiveBytesArgs(bytes));
|
||||||
}
|
}
|
||||||
var textHandler = TextReceived;
|
var textHandler = TextReceived;
|
||||||
if (textHandler != null)
|
if (textHandler != null)
|
||||||
{
|
{
|
||||||
this.PrintReceivedText(str);
|
if (StreamDebugging.RxStreamDebuggingIsEnabled)
|
||||||
|
this.LogInformation("Received {1} characters of text: '{0}'", ComTextHelper.GetDebugText(str), str.Length);
|
||||||
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
textHandler(this, new GenericCommMethodReceiveTextArgs(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,16 +295,14 @@ namespace PepperDash.Core
|
|||||||
/// General send method
|
/// General send method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <summary>
|
|
||||||
/// SendText method
|
|
||||||
/// </summary>
|
|
||||||
public void SendText(string text)
|
public void SendText(string text)
|
||||||
{
|
{
|
||||||
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
||||||
|
|
||||||
if (IsConnected && Server != null)
|
if (IsConnected && Server != null)
|
||||||
{
|
{
|
||||||
this.PrintSentText(text);
|
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||||
|
this.LogVerbose("Sending {0} characters of text: '{1}'", text.Length, ComTextHelper.GetDebugText(text));
|
||||||
|
|
||||||
Server.SendData(bytes, bytes.Length);
|
Server.SendData(bytes, bytes.Length);
|
||||||
}
|
}
|
||||||
@@ -324,12 +312,10 @@ namespace PepperDash.Core
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes"></param>
|
/// <param name="bytes"></param>
|
||||||
/// <summary>
|
|
||||||
/// SendBytes method
|
|
||||||
/// </summary>
|
|
||||||
public void SendBytes(byte[] bytes)
|
public void SendBytes(byte[] bytes)
|
||||||
{
|
{
|
||||||
this.PrintSentBytes(bytes);
|
if (StreamDebugging.TxStreamDebuggingIsEnabled)
|
||||||
|
this.LogInformation("Sending {0} bytes: '{1}'", bytes.Length, ComTextHelper.GetEscapedText(bytes));
|
||||||
|
|
||||||
if (IsConnected && Server != null)
|
if (IsConnected && Server != null)
|
||||||
Server.SendData(bytes, bytes.Length);
|
Server.SendData(bytes, bytes.Length);
|
||||||
@@ -338,7 +324,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a GenericUdpReceiveTextExtraArgs
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GenericUdpReceiveTextExtraArgs : EventArgs
|
public class GenericUdpReceiveTextExtraArgs : EventArgs
|
||||||
{
|
{
|
||||||
@@ -410,4 +396,3 @@ namespace PepperDash.Core
|
|||||||
BufferSize = 32768;
|
BufferSize = 32768;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using Newtonsoft.Json;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a TcpClientConfigObject
|
/// Client config object for TCP client with server that inherits from TcpSshPropertiesConfig and adds properties for shared key and heartbeat
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpClientConfigObject
|
public class TcpClientConfigObject
|
||||||
{
|
{
|
||||||
@@ -56,4 +58,3 @@ namespace PepperDash.Core
|
|||||||
[JsonProperty("receiveQueueSize")]
|
[JsonProperty("receiveQueueSize")]
|
||||||
public int ReceiveQueueSize { get; set; }
|
public int ReceiveQueueSize { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tcp Server Config object with properties for a tcp server with shared key and heartbeat capabilities
|
/// Tcp Server Config object with properties for a tcp server with shared key and heartbeat capabilities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -57,4 +57,3 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int ReceiveQueueSize { get; set; }
|
public int ReceiveQueueSize { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Crestron Control Methods for a comm object
|
/// Crestron Control Methods for a comm object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -76,12 +76,11 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
SecureTcpIp,
|
SecureTcpIp,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used when comms needs to be handled in SIMPL and bridged opposite the normal direction
|
/// Crestron COM bridge
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ComBridge,
|
ComBridge,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// InfinetEX control
|
/// Crestron Infinet EX device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
InfinetEx
|
InfinetEx
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
namespace PepperDash.Core
|
namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The available settings for stream debugging response types
|
/// The available settings for stream debugging data format types
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum eStreamDebuggingDataTypeSettings
|
public enum eStreamDebuggingDataTypeSettings
|
||||||
@@ -19,6 +19,6 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Debug data in both byte and text formats
|
/// Debug data in both byte and text formats
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Both = Bytes | Text,
|
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,11 +1,18 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using Newtonsoft.Json;
|
using JsonConverter = NewtonsoftJson::Newtonsoft.Json.JsonConverterAttribute;
|
||||||
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
|
using StringEnumConverter = NewtonsoftJson::Newtonsoft.Json.Converters.StringEnumConverter;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An incoming communication stream
|
/// An incoming communication stream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,7 +43,7 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the contract for IBasicCommunication
|
/// Extends <see cref="ICommunicationReceiver"/> with methods for sending text and bytes to a device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBasicCommunication : ICommunicationReceiver
|
public interface IBasicCommunication : ICommunicationReceiver
|
||||||
{
|
{
|
||||||
@@ -88,7 +95,7 @@ namespace PepperDash.Core
|
|||||||
/// The current socket status of the client
|
/// The current socket status of the client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("clientStatus")]
|
[JsonProperty("clientStatus")]
|
||||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
SocketStatus ClientStatus { get; }
|
SocketStatus ClientStatus { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,17 +147,17 @@ namespace PepperDash.Core
|
|||||||
public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status);
|
public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Event args for bytes received from a communication method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GenericCommMethodReceiveBytesArgs : EventArgs
|
public class GenericCommMethodReceiveBytesArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Bytes
|
/// The bytes received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] Bytes { get; private set; }
|
public byte[] Bytes { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes"></param>
|
/// <param name="bytes"></param>
|
||||||
public GenericCommMethodReceiveBytesArgs(byte[] bytes)
|
public GenericCommMethodReceiveBytesArgs(byte[] bytes)
|
||||||
@@ -165,20 +172,21 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Event args for text received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GenericCommMethodReceiveTextArgs : EventArgs
|
public class GenericCommMethodReceiveTextArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// The text received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Text { get; private set; }
|
public string Text { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// The delimiter used to determine the end of a message, if applicable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Delimiter { get; private set; }
|
public string Delimiter { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
public GenericCommMethodReceiveTextArgs(string text)
|
public GenericCommMethodReceiveTextArgs(string text)
|
||||||
@@ -202,4 +210,42 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public GenericCommMethodReceiveTextArgs() { }
|
public GenericCommMethodReceiveTextArgs() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper class to get escaped text for debugging communication streams
|
||||||
|
/// </summary>
|
||||||
|
public class ComTextHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets escaped text for a byte array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bytes"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetEscapedText(byte[] bytes)
|
||||||
|
{
|
||||||
|
return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets escaped text for a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetEscapedText(string text)
|
||||||
|
{
|
||||||
|
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
|
||||||
|
return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets debug text for a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetDebugText(string text)
|
||||||
|
{
|
||||||
|
return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json;
|
using Formatting = NewtonsoftJson::Newtonsoft.Json.Formatting;
|
||||||
using Newtonsoft.Json.Linq;
|
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
|
||||||
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
|
using JToken = NewtonsoftJson::Newtonsoft.Json.Linq.JToken;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core.Config
|
namespace PepperDash.Core.Config;
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a Portal formatted config file
|
/// Reads a Portal formatted config file
|
||||||
@@ -56,12 +58,12 @@ namespace PepperDash.Core.Config
|
|||||||
var merged = MergeConfigs(jsonObj);
|
var merged = MergeConfigs(jsonObj);
|
||||||
if (jsonObj[systemUrl] != null)
|
if (jsonObj[systemUrl] != null)
|
||||||
{
|
{
|
||||||
merged[systemUrl] = jsonObj[systemUrl].Value<string>();
|
merged[systemUrl] = (string)jsonObj[systemUrl];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonObj[templateUrl] != null)
|
if (jsonObj[templateUrl] != null)
|
||||||
{
|
{
|
||||||
merged[templateUrl] = jsonObj[templateUrl].Value<string>();
|
merged[templateUrl] = (string)jsonObj[templateUrl];
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonObj = merged;
|
jsonObj = merged;
|
||||||
@@ -122,38 +124,37 @@ namespace PepperDash.Core.Config
|
|||||||
Merge(template[destinationLists], system[destinationLists], destinationLists));
|
Merge(template[destinationLists], system[destinationLists], destinationLists));
|
||||||
|
|
||||||
|
|
||||||
if (system[cameraLists] == null)
|
if (system["cameraLists"] == null)
|
||||||
merged.Add(cameraLists, template[cameraLists]);
|
merged.Add("cameraLists", template["cameraLists"]);
|
||||||
else
|
else
|
||||||
merged.Add(cameraLists, Merge(template[cameraLists], system[cameraLists], cameraLists));
|
merged.Add("cameraLists", Merge(template["cameraLists"], system["cameraLists"], "cameraLists"));
|
||||||
|
|
||||||
if (system[audioControlPointLists] == null)
|
if (system["audioControlPointLists"] == null)
|
||||||
merged.Add(audioControlPointLists, template[audioControlPointLists]);
|
merged.Add("audioControlPointLists", template["audioControlPointLists"]);
|
||||||
else
|
else
|
||||||
merged.Add(audioControlPointLists,
|
merged.Add("audioControlPointLists",
|
||||||
Merge(template[audioControlPointLists], system[audioControlPointLists], audioControlPointLists));
|
Merge(template["audioControlPointLists"], system["audioControlPointLists"], "audioControlPointLists"));
|
||||||
|
|
||||||
|
|
||||||
// Template tie lines take precedence. Config tool doesn't do them at system
|
// Template tie lines take precedence. Config tool doesn't do them at system
|
||||||
// level anyway...
|
// level anyway...
|
||||||
if (template[tieLines] != null)
|
if (template["tieLines"] != null)
|
||||||
merged.Add(tieLines, template[tieLines]);
|
merged.Add("tieLines", template["tieLines"]);
|
||||||
else if (system[tieLines] != null)
|
else if (system["tieLines"] != null)
|
||||||
merged.Add(tieLines, system[tieLines]);
|
merged.Add("tieLines", system["tieLines"]);
|
||||||
else
|
else
|
||||||
merged.Add(tieLines, new JArray());
|
merged.Add(tieLines, new JArray());
|
||||||
|
|
||||||
if (template[joinMaps] != null)
|
if (template["joinMaps"] != null)
|
||||||
merged.Add(joinMaps, template[joinMaps]);
|
merged.Add("joinMaps", template["joinMaps"]);
|
||||||
else
|
else
|
||||||
merged.Add(joinMaps, new JObject());
|
merged.Add("joinMaps", new JObject());
|
||||||
|
|
||||||
if (system[global] != null)
|
if (system[global] != null)
|
||||||
merged.Add(global, Merge(template[global], system[global], global));
|
merged.Add(global, Merge(template[global], system[global], global));
|
||||||
else
|
else
|
||||||
merged.Add(global, template[global]);
|
merged.Add(global, template[global]);
|
||||||
|
|
||||||
//Debug.Console(2, "MERGED CONFIG RESULT: \x0d\x0a{0}", merged);
|
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,4 +255,3 @@ namespace PepperDash.Core.Config
|
|||||||
return o1;
|
return o1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,28 +4,18 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a EncodingHelper
|
|
||||||
/// </summary>
|
|
||||||
public class EncodingHelper
|
public class EncodingHelper
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// ConvertUtf8ToAscii method
|
|
||||||
/// </summary>
|
|
||||||
public static string ConvertUtf8ToAscii(string utf8String)
|
public static string ConvertUtf8ToAscii(string utf8String)
|
||||||
{
|
{
|
||||||
return Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
|
return Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ConvertUtf8ToUtf16 method
|
|
||||||
/// </summary>
|
|
||||||
public static string ConvertUtf8ToUtf16(string utf8String)
|
public static string ConvertUtf8ToUtf16(string utf8String)
|
||||||
{
|
{
|
||||||
return Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
|
return Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String), 0, utf8String.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Newtonsoft.Json;
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique key interface to require a unique key for the class
|
/// Unique key interface to require a unique key for the class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IKeyed
|
public interface IKeyed
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique Key
|
/// Gets the unique key associated with the object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("key")]
|
[JsonProperty("key")]
|
||||||
string Key { get; }
|
string Key { get; }
|
||||||
@@ -26,10 +28,8 @@ namespace PepperDash.Core
|
|||||||
public interface IKeyName : IKeyed
|
public interface IKeyName : IKeyed
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Isn't it obvious :)
|
/// Gets the name associated with the current object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
//*********************************************************************************************************
|
//*********************************************************************************************************
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a Device
|
/// Represents a Device
|
||||||
@@ -188,12 +188,8 @@ namespace PepperDash.Core
|
|||||||
/// <remarks>The returned string is formatted as "{Key} - {Name}". If the <c>Name</c> property is
|
/// <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>
|
/// 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>
|
/// <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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
|
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
using Crestron.SimplSharp;
|
extern alias NewtonsoftJson;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a EthernetHelper
|
/// Represents an EthernetHelper.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EthernetHelper
|
public class EthernetHelper
|
||||||
{
|
{
|
||||||
@@ -114,4 +116,3 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bool change event args
|
/// Bool change event args
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -169,4 +169,3 @@ namespace PepperDash.Core
|
|||||||
Index = index;
|
Index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
namespace PepperDash.Core.GenericRESTfulCommunications
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Constants
|
|
||||||
/// </summary>
|
|
||||||
public class GenericRESTfulConstants
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Generic boolean change
|
|
||||||
/// </summary>
|
|
||||||
public const ushort BoolValueChange = 1;
|
|
||||||
/// <summary>
|
|
||||||
/// Generic Ushort change
|
|
||||||
/// </summary>
|
|
||||||
public const ushort UshrtValueChange = 101;
|
|
||||||
/// <summary>
|
|
||||||
/// Response Code Ushort change
|
|
||||||
/// </summary>
|
|
||||||
public const ushort ResponseCodeChange = 102;
|
|
||||||
/// <summary>
|
|
||||||
/// Generic String chagne
|
|
||||||
/// </summary>
|
|
||||||
public const ushort StringValueChange = 201;
|
|
||||||
/// <summary>
|
|
||||||
/// Response string change
|
|
||||||
/// </summary>
|
|
||||||
public const ushort ResponseStringChange = 202;
|
|
||||||
/// <summary>
|
|
||||||
/// Error string change
|
|
||||||
/// </summary>
|
|
||||||
public const ushort ErrorStringChange = 203;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Crestron.SimplSharp.Net.Http;
|
|
||||||
using Crestron.SimplSharp.Net.Https;
|
|
||||||
|
|
||||||
namespace PepperDash.Core.GenericRESTfulCommunications
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Generic RESTful communication class
|
|
||||||
/// </summary>
|
|
||||||
public class GenericRESTfulClient
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Boolean event handler
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler<BoolChangeEventArgs> BoolChange;
|
|
||||||
/// <summary>
|
|
||||||
/// Ushort event handler
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler<UshrtChangeEventArgs> UshrtChange;
|
|
||||||
/// <summary>
|
|
||||||
/// String event handler
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler<StringChangeEventArgs> StringChange;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public GenericRESTfulClient()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generic RESTful submit request
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url"></param>
|
|
||||||
/// <param name="port"></param>
|
|
||||||
/// <param name="requestType"></param>
|
|
||||||
/// <param name="username"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
/// <param name="contentType"></param>
|
|
||||||
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
|
||||||
{
|
|
||||||
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
SubmitRequestHttps(url, port, requestType, contentType, username, password);
|
|
||||||
}
|
|
||||||
else if (url.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
SubmitRequestHttp(url, port, requestType, contentType, username, password);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OnStringChange(string.Format("Invalid URL {0}", url), 0, GenericRESTfulConstants.ErrorStringChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Private HTTP submit request
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url"></param>
|
|
||||||
/// <param name="port"></param>
|
|
||||||
/// <param name="requestType"></param>
|
|
||||||
/// <param name="contentType"></param>
|
|
||||||
/// <param name="username"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
private void SubmitRequestHttp(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
HttpClientRequest request = new HttpClientRequest();
|
|
||||||
HttpClientResponse response;
|
|
||||||
|
|
||||||
client.KeepAlive = false;
|
|
||||||
|
|
||||||
if(port >= 1 || port <= 65535)
|
|
||||||
client.Port = port;
|
|
||||||
else
|
|
||||||
client.Port = 80;
|
|
||||||
|
|
||||||
var authorization = "";
|
|
||||||
if (!string.IsNullOrEmpty(username))
|
|
||||||
authorization = EncodeBase64(username, password);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(authorization))
|
|
||||||
request.Header.SetHeaderValue("Authorization", authorization);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(contentType))
|
|
||||||
request.Header.ContentType = contentType;
|
|
||||||
|
|
||||||
request.Url.Parse(url);
|
|
||||||
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
|
|
||||||
|
|
||||||
response = client.Dispatch(request);
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(response.ContentString.ToString()))
|
|
||||||
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
|
||||||
|
|
||||||
if (response.Code > 0)
|
|
||||||
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
//var msg = string.Format("SubmitRequestHttp({0}, {1}, {2}) failed:{3}", url, port, requestType, e.Message);
|
|
||||||
//CrestronConsole.PrintLine(msg);
|
|
||||||
//ErrorLog.Error(msg);
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine(e.Message);
|
|
||||||
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Private HTTPS submit request
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="url"></param>
|
|
||||||
/// <param name="port"></param>
|
|
||||||
/// <param name="requestType"></param>
|
|
||||||
/// <param name="contentType"></param>
|
|
||||||
/// <param name="username"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
private void SubmitRequestHttps(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HttpsClient client = new HttpsClient();
|
|
||||||
HttpsClientRequest request = new HttpsClientRequest();
|
|
||||||
HttpsClientResponse response;
|
|
||||||
|
|
||||||
client.KeepAlive = false;
|
|
||||||
client.HostVerification = false;
|
|
||||||
client.PeerVerification = false;
|
|
||||||
|
|
||||||
var authorization = "";
|
|
||||||
if (!string.IsNullOrEmpty(username))
|
|
||||||
authorization = EncodeBase64(username, password);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(authorization))
|
|
||||||
request.Header.SetHeaderValue("Authorization", authorization);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(contentType))
|
|
||||||
request.Header.ContentType = contentType;
|
|
||||||
|
|
||||||
request.Url.Parse(url);
|
|
||||||
request.RequestType = (Crestron.SimplSharp.Net.Https.RequestType)requestType;
|
|
||||||
|
|
||||||
response = client.Dispatch(request);
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
|
||||||
|
|
||||||
if(!string.IsNullOrEmpty(response.ContentString.ToString()))
|
|
||||||
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
|
||||||
|
|
||||||
if(response.Code > 0)
|
|
||||||
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
//var msg = string.Format("SubmitRequestHttps({0}, {1}, {2}, {3}, {4}) failed:{5}", url, port, requestType, username, password, e.Message);
|
|
||||||
//CrestronConsole.PrintLine(msg);
|
|
||||||
//ErrorLog.Error(msg);
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine(e.Message);
|
|
||||||
OnStringChange(e.Message, 0, GenericRESTfulConstants.ErrorStringChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Private method to encode username and password to Base64 string
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="username"></param>
|
|
||||||
/// <param name="password"></param>
|
|
||||||
/// <returns>authorization</returns>
|
|
||||||
private string EncodeBase64(string username, string password)
|
|
||||||
{
|
|
||||||
var authorization = "";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(username))
|
|
||||||
{
|
|
||||||
string base64String = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(string.Format("{0}:{1}", username, password)));
|
|
||||||
authorization = string.Format("Basic {0}", base64String);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
var msg = string.Format("EncodeBase64({0}, {1}) failed:\r{2}", username, password, e);
|
|
||||||
CrestronConsole.PrintLine(msg);
|
|
||||||
ErrorLog.Error(msg);
|
|
||||||
return "" ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return authorization;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Protected method to handle boolean change events
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="state"></param>
|
|
||||||
/// <param name="index"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
protected void OnBoolChange(bool state, ushort index, ushort type)
|
|
||||||
{
|
|
||||||
var handler = BoolChange;
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
var args = new BoolChangeEventArgs(state, type);
|
|
||||||
args.Index = index;
|
|
||||||
BoolChange(this, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Protected mehtod to handle ushort change events
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <param name="index"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
protected void OnUshrtChange(ushort value, ushort index, ushort type)
|
|
||||||
{
|
|
||||||
var handler = UshrtChange;
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
var args = new UshrtChangeEventArgs(value, type);
|
|
||||||
args.Index = index;
|
|
||||||
UshrtChange(this, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Protected method to handle string change events
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <param name="index"></param>
|
|
||||||
/// <param name="type"></param>
|
|
||||||
protected void OnStringChange(string value, ushort index, ushort type)
|
|
||||||
{
|
|
||||||
var handler = StringChange;
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
var args = new StringChangeEventArgs(value, type);
|
|
||||||
args.Index = index;
|
|
||||||
StringChange(this, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonStandardObjects
|
namespace PepperDash.Core.JsonStandardObjects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants for simpl modules
|
/// Constants for simpl modules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -74,4 +74,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
Index = index;
|
Index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using Crestron.SimplSharp;
|
|||||||
using PepperDash.Core.JsonToSimpl;
|
using PepperDash.Core.JsonToSimpl;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonStandardObjects
|
namespace PepperDash.Core.JsonStandardObjects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Device class
|
/// Device class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -183,4 +183,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
|
|
||||||
#endregion EventHandler Helpers
|
#endregion EventHandler Helpers
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonStandardObjects
|
namespace PepperDash.Core.JsonStandardObjects;
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
Convert JSON snippt to C#: http://json2csharp.com/#
|
Convert JSON snippt to C#: http://json2csharp.com/#
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
public class ComParamsConfig
|
public class ComParamsConfig
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the baudRate
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int baudRate { get; set; }
|
public int baudRate { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -87,11 +87,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
|
|
||||||
// convert properties for simpl
|
// convert properties for simpl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplBaudRate
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
|
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplDataBits
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
|
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -144,11 +144,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
|
|
||||||
// convert properties for simpl
|
// convert properties for simpl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplPort
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplPort { get { return Convert.ToUInt16(port); } }
|
public ushort simplPort { get { return Convert.ToUInt16(port); } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplAutoReconnect
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
|
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -193,7 +193,7 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
|
|
||||||
// convert properties for simpl
|
// convert properties for simpl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplControlPortNumber
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
|
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
|
||||||
|
|
||||||
@@ -227,11 +227,11 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
|
|
||||||
// convert properties for simpl
|
// convert properties for simpl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplDeviceId
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
|
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the simplEnabled
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
|
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
|
||||||
|
|
||||||
@@ -254,4 +254,3 @@ namespace PepperDash.Core.JsonStandardObjects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<DeviceConfig> devices { get; set; }
|
public List<DeviceConfig> devices { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants for Simpl modules
|
/// Constants for Simpl modules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -89,7 +89,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public class SPlusValueWrapper
|
public class SPlusValueWrapper
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ValueType
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SPlusType ValueType { get; private set; }
|
public SPlusType ValueType { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -140,4 +140,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
String
|
String
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,8 +7,8 @@ using Serilog.Events;
|
|||||||
|
|
||||||
//using PepperDash.Core;
|
//using PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The global class to manage all the instances of JsonToSimplMaster
|
/// The global class to manage all the instances of JsonToSimplMaster
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,9 +23,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="master">New master to add</param>
|
/// <param name="master">New master to add</param>
|
||||||
///
|
///
|
||||||
/// <summary>
|
|
||||||
/// AddMaster method
|
|
||||||
/// </summary>
|
|
||||||
public static void AddMaster(JsonToSimplMaster master)
|
public static void AddMaster(JsonToSimplMaster master)
|
||||||
{
|
{
|
||||||
if (master == null)
|
if (master == null)
|
||||||
@@ -60,4 +57,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
return Masters.FirstOrDefault(m => m.UniqueID.Equals(file, StringComparison.OrdinalIgnoreCase));
|
return Masters.FirstOrDefault(m => m.UniqueID.Equals(file, StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a JsonToSimplArrayLookupChild
|
/// Used to interact with an array of values with the S+ modules
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
|
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
|
||||||
{
|
{
|
||||||
@@ -77,9 +79,8 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ProcessAll method
|
/// Process all values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc />
|
|
||||||
public override void ProcessAll()
|
public override void ProcessAll()
|
||||||
{
|
{
|
||||||
if (FindInArray())
|
if (FindInArray())
|
||||||
@@ -129,7 +130,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
var item = array.FirstOrDefault(o =>
|
var item = array.FirstOrDefault(o =>
|
||||||
{
|
{
|
||||||
var prop = o[SearchPropertyName];
|
var prop = o[SearchPropertyName];
|
||||||
return prop != null && prop.Value<string>()
|
return prop != null && ((string)prop)
|
||||||
.Equals(SearchPropertyValue, StringComparison.OrdinalIgnoreCase);
|
.Equals(SearchPropertyValue, StringComparison.OrdinalIgnoreCase);
|
||||||
});
|
});
|
||||||
if (item == null)
|
if (item == null)
|
||||||
@@ -160,4 +161,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using PepperDash.Core.Logging;
|
||||||
|
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for JSON objects
|
/// Base class for JSON objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,7 +37,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public SPlusValuesDelegate SetAllPathsDelegate { get; set; }
|
public SPlusValuesDelegate SetAllPathsDelegate { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Key
|
/// Unique identifier for instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Key { get; protected set; }
|
public string Key { get; protected set; }
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public string PathSuffix { get; protected set; }
|
public string PathSuffix { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the LinkedToObject
|
/// Indicates if the instance is linked to an object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LinkedToObject { get; protected set; }
|
public bool LinkedToObject { get; protected set; }
|
||||||
|
|
||||||
@@ -89,16 +92,13 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
if (Master != null)
|
if (Master != null)
|
||||||
Master.AddChild(this);
|
Master.AddChild(this);
|
||||||
else
|
else
|
||||||
Debug.Console(1, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
|
this.LogWarning("JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the path prefix for the object
|
/// Sets the path prefix for the object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pathPrefix"></param>
|
/// <param name="pathPrefix"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetPathPrefix method
|
|
||||||
/// </summary>
|
|
||||||
public void SetPathPrefix(string pathPrefix)
|
public void SetPathPrefix(string pathPrefix)
|
||||||
{
|
{
|
||||||
PathPrefix = pathPrefix;
|
PathPrefix = pathPrefix;
|
||||||
@@ -108,7 +108,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetBoolPath(ushort index, string path)
|
public void SetBoolPath(ushort index, string path)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path);
|
this.LogDebug("JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path);
|
||||||
if (path == null || path.Trim() == string.Empty) return;
|
if (path == null || path.Trim() == string.Empty) return;
|
||||||
BoolPaths[index] = path;
|
BoolPaths[index] = path;
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetUshortPath(ushort index, string path)
|
public void SetUshortPath(ushort index, string path)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path);
|
this.LogDebug("JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path);
|
||||||
if (path == null || path.Trim() == string.Empty) return;
|
if (path == null || path.Trim() == string.Empty) return;
|
||||||
UshortPaths[index] = path;
|
UshortPaths[index] = path;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetStringPath(ushort index, string path)
|
public void SetStringPath(ushort index, string path)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] SetStringPath {1}={2}", Key, index, path);
|
this.LogDebug("JSON Child[{0}] SetStringPath {1}={2}", Key, index, path);
|
||||||
if (path == null || path.Trim() == string.Empty) return;
|
if (path == null || path.Trim() == string.Empty) return;
|
||||||
StringPaths[index] = path;
|
StringPaths[index] = path;
|
||||||
}
|
}
|
||||||
@@ -141,13 +141,13 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
{
|
{
|
||||||
if (!LinkedToObject)
|
if (!LinkedToObject)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Not linked to object in file. Skipping");
|
this.LogDebug("Not linked to object in file. Skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SetAllPathsDelegate == null)
|
if (SetAllPathsDelegate == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "No SetAllPathsDelegate set. Ignoring ProcessAll");
|
this.LogDebug("No SetAllPathsDelegate set. Ignoring ProcessAll");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetAllPathsDelegate();
|
SetAllPathsDelegate();
|
||||||
@@ -207,11 +207,11 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
bool Process(string path, out string response)
|
bool Process(string path, out string response)
|
||||||
{
|
{
|
||||||
path = GetFullPath(path);
|
path = GetFullPath(path);
|
||||||
Debug.Console(1, "JSON Child[{0}] Processing {1}", Key, path);
|
this.LogDebug("JSON Child[{0}] Processing {1}", Key, path);
|
||||||
response = "";
|
response = "";
|
||||||
if (Master == null)
|
if (Master == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSONChild[{0}] cannot process without Master attached", Key);
|
this.LogWarning("JSONChild[{0}] cannot process without Master attached", Key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +233,8 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
if (isCount)
|
if (isCount)
|
||||||
response = (t.HasValues ? t.Children().Count() : 0).ToString();
|
response = (t.HasValues ? t.Children().Count() : 0).ToString();
|
||||||
else
|
else
|
||||||
response = t.Value<string>();
|
response = (string)t;
|
||||||
Debug.Console(1, " ='{0}'", response);
|
this.LogDebug(" ='{0}'", response);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,13 +260,13 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
{
|
{
|
||||||
if (!LinkedToObject)
|
if (!LinkedToObject)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Not linked to object in file. Skipping");
|
this.LogDebug("Not linked to object in file. Skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SetAllPathsDelegate == null)
|
if (SetAllPathsDelegate == null)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "No SetAllPathsDelegate set. Ignoring UpdateInputsForMaster");
|
this.LogDebug("No SetAllPathsDelegate set. Ignoring UpdateInputsForMaster");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetAllPathsDelegate();
|
SetAllPathsDelegate();
|
||||||
@@ -280,9 +280,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="theValue"></param>
|
/// <param name="theValue"></param>
|
||||||
/// <summary>
|
|
||||||
/// USetBoolValue method
|
|
||||||
/// </summary>
|
|
||||||
public void USetBoolValue(ushort key, ushort theValue)
|
public void USetBoolValue(ushort key, ushort theValue)
|
||||||
{
|
{
|
||||||
SetBoolValue(key, theValue == 1);
|
SetBoolValue(key, theValue == 1);
|
||||||
@@ -293,9 +290,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="theValue"></param>
|
/// <param name="theValue"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetBoolValue method
|
|
||||||
/// </summary>
|
|
||||||
public void SetBoolValue(ushort key, bool theValue)
|
public void SetBoolValue(ushort key, bool theValue)
|
||||||
{
|
{
|
||||||
if (BoolPaths.ContainsKey(key))
|
if (BoolPaths.ContainsKey(key))
|
||||||
@@ -307,9 +301,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="theValue"></param>
|
/// <param name="theValue"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetUShortValue method
|
|
||||||
/// </summary>
|
|
||||||
public void SetUShortValue(ushort key, ushort theValue)
|
public void SetUShortValue(ushort key, ushort theValue)
|
||||||
{
|
{
|
||||||
if (UshortPaths.ContainsKey(key))
|
if (UshortPaths.ContainsKey(key))
|
||||||
@@ -321,9 +312,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="theValue"></param>
|
/// <param name="theValue"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetStringValue method
|
|
||||||
/// </summary>
|
|
||||||
public void SetStringValue(ushort key, string theValue)
|
public void SetStringValue(ushort key, string theValue)
|
||||||
{
|
{
|
||||||
if (StringPaths.ContainsKey(key))
|
if (StringPaths.ContainsKey(key))
|
||||||
@@ -335,15 +323,12 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyPath"></param>
|
/// <param name="keyPath"></param>
|
||||||
/// <param name="valueToSave"></param>
|
/// <param name="valueToSave"></param>
|
||||||
/// <summary>
|
|
||||||
/// SetValueOnMaster method
|
|
||||||
/// </summary>
|
|
||||||
public void SetValueOnMaster(string keyPath, JValue valueToSave)
|
public void SetValueOnMaster(string keyPath, JValue valueToSave)
|
||||||
{
|
{
|
||||||
var path = GetFullPath(keyPath);
|
var path = GetFullPath(keyPath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave);
|
this.LogDebug("JSON Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave);
|
||||||
|
|
||||||
//var token = Master.JsonObject.SelectToken(path);
|
//var token = Master.JsonObject.SelectToken(path);
|
||||||
//if (token != null) // The path exists in the file
|
//if (token != null) // The path exists in the file
|
||||||
@@ -351,7 +336,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] Failed setting value for path '{1}'\r{2}", Key, path, e);
|
this.LogDebug("JSON Child[{0}] Failed setting value for path '{1}'\r{2}", Key, path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,4 +404,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json.Linq;
|
using PepperDash.Core.Logging;
|
||||||
|
using Formatting = NewtonsoftJson::Newtonsoft.Json.Formatting;
|
||||||
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
|
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a JSON file that can be read and written to
|
/// Represents a JSON file that can be read and written to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -20,12 +25,12 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public string Filepath { get; private set; }
|
public string Filepath { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ActualFilePath
|
/// Filepath to the actual file that will be read (Portal or local)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ActualFilePath { get; private set; }
|
public string ActualFilePath { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Filename
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Filename { get; private set; }
|
public string Filename { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -125,7 +130,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
var fileName = Path.GetFileName(Filepath);
|
var fileName = Path.GetFileName(Filepath);
|
||||||
|
|
||||||
OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "Checking '{0}' for '{1}'", fileDirectory, fileName);
|
this.LogInformation("Checking '{0}' for '{1}'", fileDirectory, fileName);
|
||||||
|
|
||||||
if (Directory.Exists(fileDirectory))
|
if (Directory.Exists(fileDirectory))
|
||||||
{
|
{
|
||||||
@@ -139,7 +144,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
var msg = string.Format("JSON file not found: {0}", Filepath);
|
var msg = string.Format("JSON file not found: {0}", Filepath);
|
||||||
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
ErrorLog.Error(msg);
|
this.LogError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,18 +153,18 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
ActualFilePath = actualFile.FullName;
|
ActualFilePath = actualFile.FullName;
|
||||||
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
|
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
|
||||||
OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
|
this.LogInformation("Actual JSON file is {0}", ActualFilePath);
|
||||||
|
|
||||||
Filename = actualFile.Name;
|
Filename = actualFile.Name;
|
||||||
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
|
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
|
||||||
OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "JSON Filename is {0}", Filename);
|
this.LogInformation("JSON Filename is {0}", Filename);
|
||||||
|
|
||||||
|
|
||||||
FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator);
|
FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator);
|
||||||
OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange);
|
OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange);
|
||||||
OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "JSON File Path is {0}", FilePathName);
|
this.LogInformation("JSON File Path is {0}", FilePathName);
|
||||||
|
|
||||||
var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
||||||
|
|
||||||
@@ -172,7 +177,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "'{0}' not found", fileDirectory);
|
this.LogError("'{0}' not found", fileDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -180,12 +185,12 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message);
|
var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message);
|
||||||
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
ErrorLog.Error(msg);
|
this.LogException(e, "EvaluateFile Exception: {0}", e.Message);
|
||||||
|
|
||||||
var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
|
var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
|
||||||
OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange);
|
OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine(stackTrace);
|
CrestronConsole.PrintLine(stackTrace);
|
||||||
ErrorLog.Error(stackTrace);
|
this.LogVerbose("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,9 +199,6 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// Sets the debug level
|
/// Sets the debug level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="level"></param>
|
/// <param name="level"></param>
|
||||||
/// <summary>
|
|
||||||
/// setDebugLevel method
|
|
||||||
/// </summary>
|
|
||||||
public void setDebugLevel(uint level)
|
public void setDebugLevel(uint level)
|
||||||
{
|
{
|
||||||
Debug.SetDebugLevel(level);
|
Debug.SetDebugLevel(level);
|
||||||
@@ -212,63 +214,31 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// Make each child update their values into master object
|
// Make each child update their values into master object
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
|
this.LogInformation("Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
|
||||||
child.UpdateInputsForMaster();
|
child.UpdateInputsForMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID);
|
this.LogInformation("Master [{0}] No updated values to save. Skipping", UniqueID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lock (FileLock)
|
lock (FileLock)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Saving");
|
this.LogInformation("Saving");
|
||||||
foreach (var path in UnsavedValues.Keys)
|
foreach (var path in UnsavedValues.Keys)
|
||||||
{
|
{
|
||||||
var tokenToReplace = JsonObject.SelectToken(path);
|
var tokenToReplace = JsonObject.SelectToken(path);
|
||||||
if (tokenToReplace != null)
|
if (tokenToReplace != null)
|
||||||
{// It's found
|
{// It's found
|
||||||
tokenToReplace.Replace(UnsavedValues[path]);
|
tokenToReplace.Replace(UnsavedValues[path]);
|
||||||
Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path);
|
this.LogInformation("JSON Master[{0}] Updating '{1}'", UniqueID, path);
|
||||||
}
|
}
|
||||||
else // No token. Let's make one
|
else // No token. Let's make one
|
||||||
{
|
{
|
||||||
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
|
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
|
||||||
Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
|
this.LogWarning("JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
|
||||||
|
|
||||||
// JContainer jpart = JsonObject;
|
|
||||||
// // walk down the path and find where it goes
|
|
||||||
//#warning Does not handle arrays.
|
|
||||||
// foreach (var part in path.Split('.'))
|
|
||||||
// {
|
|
||||||
|
|
||||||
// var openPos = part.IndexOf('[');
|
|
||||||
// if (openPos > -1)
|
|
||||||
// {
|
|
||||||
// openPos++; // move to number
|
|
||||||
// var closePos = part.IndexOf(']');
|
|
||||||
// var arrayName = part.Substring(0, openPos - 1); // get the name
|
|
||||||
// var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos));
|
|
||||||
|
|
||||||
// // Check if the array itself exists and add the item if so
|
|
||||||
// if (jpart[arrayName] != null)
|
|
||||||
// {
|
|
||||||
// var arrayObj = jpart[arrayName] as JArray;
|
|
||||||
// var item = arrayObj[index];
|
|
||||||
// if (item == null)
|
|
||||||
// arrayObj.Add(new JObject());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW");
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// // Build the
|
|
||||||
// if (jpart[part] == null)
|
|
||||||
// jpart.Add(new JProperty(part, new JObject()));
|
|
||||||
// jpart = jpart[part] as JContainer;
|
|
||||||
// }
|
|
||||||
// jpart.Replace(UnsavedValues[path]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using (StreamWriter sw = new StreamWriter(ActualFilePath))
|
using (StreamWriter sw = new StreamWriter(ActualFilePath))
|
||||||
@@ -281,12 +251,13 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
string err = string.Format("Error writing JSON file:\r{0}", e);
|
string err = string.Format("Error writing JSON file:\r{0}", e);
|
||||||
Debug.Console(0, err);
|
this.LogException(e, "Error writing JSON file: {0}", e.Message);
|
||||||
ErrorLog.Warn(err);
|
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a JsonToSimplFixedPathObject
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase
|
public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase
|
||||||
{
|
{
|
||||||
@@ -15,4 +15,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
this.LinkedToObject = true;
|
this.LinkedToObject = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Newtonsoft.Json.Linq;
|
using PepperDash.Core.Logging;
|
||||||
|
using Renci.SshNet.Messages;
|
||||||
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
|
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a JsonToSimplGenericMaster
|
/// Generic Master
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonToSimplGenericMaster : JsonToSimplMaster
|
public class JsonToSimplGenericMaster : JsonToSimplMaster
|
||||||
{
|
{
|
||||||
@@ -21,7 +26,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
static object WriteLock = new object();
|
static object WriteLock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the SaveCallback
|
/// Callback action for saving
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<string> SaveCallback { get; set; }
|
public Action<string> SaveCallback { get; set; }
|
||||||
|
|
||||||
@@ -71,7 +76,8 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.Console(0, this, "JSON parsing failed:\r{0}", e);
|
this.LogException(e, "JSON parsing failed:\r{0}", e.Message);
|
||||||
|
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,37 +92,36 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// Make each child update their values into master object
|
// Make each child update their values into master object
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Master. checking child [{0}] for updates to save", child.Key);
|
this.LogDebug("Master. checking child [{0}] for updates to save", child.Key);
|
||||||
child.UpdateInputsForMaster();
|
child.UpdateInputsForMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Master. No updated values to save. Skipping");
|
this.LogDebug("Master. No updated values to save. Skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (WriteLock)
|
lock (WriteLock)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Saving");
|
this.LogDebug("Saving");
|
||||||
foreach (var path in UnsavedValues.Keys)
|
foreach (var path in UnsavedValues.Keys)
|
||||||
{
|
{
|
||||||
var tokenToReplace = JsonObject.SelectToken(path);
|
var tokenToReplace = JsonObject.SelectToken(path);
|
||||||
if (tokenToReplace != null)
|
if (tokenToReplace != null)
|
||||||
{// It's found
|
{// It's found
|
||||||
tokenToReplace.Replace(UnsavedValues[path]);
|
tokenToReplace.Replace(UnsavedValues[path]);
|
||||||
Debug.Console(1, this, "Master Updating '{0}'", path);
|
this.LogDebug("Master Updating '{0}'", path);
|
||||||
}
|
}
|
||||||
else // No token. Let's make one
|
else // No token. Let's make one
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Master Cannot write value onto missing property: '{0}'", path);
|
this.LogDebug("Master Cannot write value onto missing property: '{0}'", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SaveCallback != null)
|
if (SaveCallback != null)
|
||||||
SaveCallback(JsonObject.ToString());
|
SaveCallback(JsonObject.ToString());
|
||||||
else
|
else
|
||||||
Debug.Console(0, this, "WARNING: No save callback defined.");
|
this.LogDebug("WARNING: No save callback defined.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json;
|
using JArray = NewtonsoftJson::Newtonsoft.Json.Linq.JArray;
|
||||||
using Newtonsoft.Json.Linq;
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
|
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
|
||||||
|
using JsonSerializationException = NewtonsoftJson::Newtonsoft.Json.JsonSerializationException;
|
||||||
|
using JsonTextReader = NewtonsoftJson::Newtonsoft.Json.JsonTextReader;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base class for JsonToSimpl interactions
|
/// Abstract base class for JsonToSimpl interactions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,7 +45,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public string Key { get { return UniqueID; } }
|
public string Key { get { return UniqueID; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the UniqueID
|
/// A unique ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UniqueID { get; protected set; }
|
public string UniqueID { get; protected set; }
|
||||||
|
|
||||||
@@ -83,7 +89,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the JsonObject
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public JObject JsonObject { get; protected set; }
|
public JObject JsonObject { get; protected set; }
|
||||||
|
|
||||||
@@ -137,11 +143,10 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
{
|
{
|
||||||
if (UnsavedValues.ContainsKey(path))
|
if (UnsavedValues.ContainsKey(path))
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Master[{0}] WARNING - Attempt to add duplicate value for path '{1}'.\r Ingoring. Please ensure that path does not exist on multiple modules.", UniqueID, path);
|
this.LogWarning("Master[{0}] WARNING - Attempt to add duplicate value for path '{1}'.\r Ingoring. Please ensure that path does not exist on multiple modules.", UniqueID, path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
UnsavedValues.Add(path, value);
|
UnsavedValues.Add(path, value);
|
||||||
//Debug.Console(0, "Master[{0}] Unsaved size={1}", UniqueID, UnsavedValues.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -162,11 +167,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static JObject ParseObject(string json)
|
public static JObject ParseObject(string json)
|
||||||
{
|
{
|
||||||
#if NET6_0
|
|
||||||
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
|
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
|
||||||
#else
|
|
||||||
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
var startDepth = reader.Depth;
|
var startDepth = reader.Depth;
|
||||||
var obj = JObject.Load(reader);
|
var obj = JObject.Load(reader);
|
||||||
@@ -181,16 +182,10 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json"></param>
|
/// <param name="json"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// ParseArray method
|
|
||||||
/// </summary>
|
|
||||||
public static JArray ParseArray(string json)
|
public static JArray ParseArray(string json)
|
||||||
{
|
{
|
||||||
#if NET6_0
|
|
||||||
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
|
using (var reader = new JsonTextReader(new System.IO.StringReader(json)))
|
||||||
#else
|
|
||||||
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
var startDepth = reader.Depth;
|
var startDepth = reader.Depth;
|
||||||
var obj = JArray.Load(reader);
|
var obj = JArray.Load(reader);
|
||||||
@@ -249,4 +244,3 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json.Linq;
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
|
using JValue = NewtonsoftJson::Newtonsoft.Json.Linq.JValue;
|
||||||
using PepperDash.Core.Config;
|
using PepperDash.Core.Config;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.JsonToSimpl;
|
||||||
|
|
||||||
namespace PepperDash.Core.JsonToSimpl
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Portal File Master
|
/// Portal File Master
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,7 +23,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public string PortalFilepath { get; private set; }
|
public string PortalFilepath { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ActualFilePath
|
/// File path of the actual file being read (Portal or local)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ActualFilePath { get; private set; }
|
public string ActualFilePath { get; private set; }
|
||||||
|
|
||||||
@@ -58,7 +62,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// If the portal file is xyz.json, then
|
// If the portal file is xyz.json, then
|
||||||
// the file we want to check for first will be called xyz.local.json
|
// the file we want to check for first will be called xyz.local.json
|
||||||
var localFilepath = Path.ChangeExtension(PortalFilepath, "local.json");
|
var localFilepath = Path.ChangeExtension(PortalFilepath, "local.json");
|
||||||
Debug.Console(0, this, "Checking for local file {0}", localFilepath);
|
this.LogInformation("Checking for local file {0}", localFilepath);
|
||||||
var actualLocalFile = GetActualFileInfoFromPath(localFilepath);
|
var actualLocalFile = GetActualFileInfoFromPath(localFilepath);
|
||||||
|
|
||||||
if (actualLocalFile != null)
|
if (actualLocalFile != null)
|
||||||
@@ -70,7 +74,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// and create the local.
|
// and create the local.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Local JSON file not found {0}\rLoading portal JSON file", localFilepath);
|
this.LogInformation("Local JSON file not found {0}\rLoading portal JSON file", localFilepath);
|
||||||
var actualPortalFile = GetActualFileInfoFromPath(portalFilepath);
|
var actualPortalFile = GetActualFileInfoFromPath(portalFilepath);
|
||||||
if (actualPortalFile != null)
|
if (actualPortalFile != null)
|
||||||
{
|
{
|
||||||
@@ -83,14 +87,13 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var msg = string.Format("Portal JSON file not found: {0}", PortalFilepath);
|
var msg = string.Format("Portal JSON file not found: {0}", PortalFilepath);
|
||||||
Debug.Console(1, this, msg);
|
this.LogError(msg);
|
||||||
ErrorLog.Error(msg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point we should have a local file. Do it.
|
// At this point we should have a local file. Do it.
|
||||||
Debug.Console(1, "Reading local JSON file {0}", ActualFilePath);
|
this.LogInformation("Reading local JSON file {0}", ActualFilePath);
|
||||||
|
|
||||||
string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
||||||
|
|
||||||
@@ -104,8 +107,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var msg = string.Format("JSON parsing failed:\r{0}", e);
|
var msg = string.Format("JSON parsing failed:\r{0}", e);
|
||||||
CrestronConsole.PrintLine(msg);
|
this.LogError(msg);
|
||||||
ErrorLog.Error(msg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,30 +148,30 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// Make each child update their values into master object
|
// Make each child update their values into master object
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
|
this.LogInformation("Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
|
||||||
child.UpdateInputsForMaster();
|
child.UpdateInputsForMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
if (UnsavedValues == null || UnsavedValues.Count == 0)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID);
|
this.LogInformation("Master [{0}] No updated values to save. Skipping", UniqueID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lock (FileLock)
|
lock (FileLock)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Saving");
|
this.LogInformation("Saving");
|
||||||
foreach (var path in UnsavedValues.Keys)
|
foreach (var path in UnsavedValues.Keys)
|
||||||
{
|
{
|
||||||
var tokenToReplace = JsonObject.SelectToken(path);
|
var tokenToReplace = JsonObject.SelectToken(path);
|
||||||
if (tokenToReplace != null)
|
if (tokenToReplace != null)
|
||||||
{// It's found
|
{// It's found
|
||||||
tokenToReplace.Replace(UnsavedValues[path]);
|
tokenToReplace.Replace(UnsavedValues[path]);
|
||||||
Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path);
|
this.LogInformation("JSON Master[{0}] Updating '{1}'", UniqueID, path);
|
||||||
}
|
}
|
||||||
else // No token. Let's make one
|
else // No token. Let's make one
|
||||||
{
|
{
|
||||||
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
|
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
|
||||||
Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
|
this.LogWarning("JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,12 +185,11 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
string err = string.Format("Error writing JSON file:\r{0}", e);
|
string err = string.Format("Error writing JSON file:\r{0}", e);
|
||||||
Debug.Console(0, err);
|
this.LogException(e, "Error writing JSON file: {0}", e.Message);
|
||||||
ErrorLog.Warn(err);
|
this.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PepperDash.Core.Logging
|
namespace PepperDash.Core.Logging;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a CrestronEnricher
|
/// Enriches log events with Crestron-specific context properties, such as the application name based on the device platform.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CrestronEnricher : ILogEventEnricher
|
public class CrestronEnricher : ILogEventEnricher
|
||||||
{
|
{
|
||||||
@@ -31,8 +31,10 @@ namespace PepperDash.Core.Logging
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enrich method
|
/// Enriches the log event with Crestron-specific properties.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="logEvent"></param>
|
||||||
|
/// <param name="propertyFactory"></param>
|
||||||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
|
||||||
{
|
{
|
||||||
var property = propertyFactory.CreateProperty("App", _appName);
|
var property = propertyFactory.CreateProperty("App", _appName);
|
||||||
@@ -40,4 +42,3 @@ namespace PepperDash.Core.Logging
|
|||||||
logEvent.AddOrUpdateProperty(property);
|
logEvent.AddOrUpdateProperty(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,18 +9,12 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a DebugConsoleSink
|
|
||||||
/// </summary>
|
|
||||||
public class DebugConsoleSink : ILogEventSink
|
public class DebugConsoleSink : ILogEventSink
|
||||||
{
|
{
|
||||||
private readonly ITextFormatter _textFormatter;
|
private readonly ITextFormatter _textFormatter;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Emit method
|
|
||||||
/// </summary>
|
|
||||||
public void Emit(LogEvent logEvent)
|
public void Emit(LogEvent logEvent)
|
||||||
{
|
{
|
||||||
if (!Debug.IsRunningOnAppliance) return;
|
if (!Debug.IsRunningOnAppliance) return;
|
||||||
@@ -50,9 +44,6 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
public static class DebugConsoleSinkExtensions
|
public static class DebugConsoleSinkExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// DebugConsoleSink method
|
|
||||||
/// </summary>
|
|
||||||
public static LoggerConfiguration DebugConsoleSink(
|
public static LoggerConfiguration DebugConsoleSink(
|
||||||
this LoggerSinkConfiguration loggerConfiguration,
|
this LoggerSinkConfiguration loggerConfiguration,
|
||||||
ITextFormatter formatProvider = null)
|
ITextFormatter formatProvider = null)
|
||||||
@@ -60,5 +51,3 @@ namespace PepperDash.Core
|
|||||||
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
|
return loggerConfiguration.Sink(new DebugConsoleSink(formatProvider));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,293 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a debugging context
|
|
||||||
/// </summary>
|
|
||||||
public class DebugContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Describes the folder location where a given program stores it's debug level memory. By default, the
|
|
||||||
/// file written will be named appNdebug where N is 1-10.
|
|
||||||
/// </summary>
|
|
||||||
public string Key { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The name of the file containing the current debug settings.
|
|
||||||
/// </summary>
|
|
||||||
//string FileName = string.Format(@"\nvram\debug\app{0}Debug.json", InitialParametersClass.ApplicationNumber);
|
|
||||||
|
|
||||||
DebugContextSaveData SaveData;
|
|
||||||
|
|
||||||
int SaveTimeoutMs = 30000;
|
|
||||||
|
|
||||||
CTimer SaveTimer;
|
|
||||||
|
|
||||||
|
|
||||||
static List<DebugContext> Contexts = new List<DebugContext>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates or gets a debug context
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <summary>
|
|
||||||
/// GetDebugContext method
|
|
||||||
/// </summary>
|
|
||||||
public static DebugContext GetDebugContext(string key)
|
|
||||||
{
|
|
||||||
var context = Contexts.FirstOrDefault(c => c.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
|
||||||
if (context == null)
|
|
||||||
{
|
|
||||||
context = new DebugContext(key);
|
|
||||||
Contexts.Add(context);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Do not use. For S+ access.
|
|
||||||
/// </summary>
|
|
||||||
public DebugContext() { }
|
|
||||||
|
|
||||||
DebugContext(string key)
|
|
||||||
{
|
|
||||||
Key = key;
|
|
||||||
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro)
|
|
||||||
{
|
|
||||||
// Add command to console
|
|
||||||
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
|
|
||||||
"appdebug:P [0-2]: Sets the application's console debug message level",
|
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
|
||||||
}
|
|
||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
|
||||||
|
|
||||||
LoadMemory();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used to save memory when shutting down
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="programEventType"></param>
|
|
||||||
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
|
||||||
{
|
|
||||||
if (programEventType == eProgramStatusEventType.Stopping)
|
|
||||||
{
|
|
||||||
if (SaveTimer != null)
|
|
||||||
{
|
|
||||||
SaveTimer.Stop();
|
|
||||||
SaveTimer = null;
|
|
||||||
}
|
|
||||||
Console(0, "Saving debug settings");
|
|
||||||
SaveMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Callback for console command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="levelString"></param>
|
|
||||||
/// <summary>
|
|
||||||
/// SetDebugFromConsole method
|
|
||||||
/// </summary>
|
|
||||||
public void SetDebugFromConsole(string levelString)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(levelString.Trim()))
|
|
||||||
{
|
|
||||||
CrestronConsole.ConsoleCommandResponse("AppDebug level = {0}", SaveData.Level);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetDebugLevel(Convert.ToInt32(levelString));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
CrestronConsole.PrintLine("Usage: appdebug:P [0-2]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the debug level
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
|
|
||||||
/// <summary>
|
|
||||||
/// SetDebugLevel method
|
|
||||||
/// </summary>
|
|
||||||
public void SetDebugLevel(int level)
|
|
||||||
{
|
|
||||||
if (level <= 2)
|
|
||||||
{
|
|
||||||
SaveData.Level = level;
|
|
||||||
SaveMemoryOnTimeout();
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine("[Application {0}], Debug level set to {1}",
|
|
||||||
InitialParametersClass.ApplicationNumber, SaveData.Level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prints message to console if current debug level is equal to or higher than the level of this message.
|
|
||||||
/// Uses CrestronConsole.PrintLine.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="level"></param>
|
|
||||||
/// <param name="format">Console format string</param>
|
|
||||||
/// <param name="items">Object parameters</param>
|
|
||||||
public void Console(uint level, string format, params object[] items)
|
|
||||||
{
|
|
||||||
if (SaveData.Level >= level)
|
|
||||||
CrestronConsole.PrintLine("App {0}:{1}", InitialParametersClass.ApplicationNumber,
|
|
||||||
string.Format(format, items));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Console method
|
|
||||||
/// </summary>
|
|
||||||
public void Console(uint level, IKeyed dev, string format, params object[] items)
|
|
||||||
{
|
|
||||||
if (SaveData.Level >= level)
|
|
||||||
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="level"></param>
|
|
||||||
/// <param name="dev"></param>
|
|
||||||
/// <param name="errorLogLevel"></param>
|
|
||||||
/// <param name="format"></param>
|
|
||||||
/// <param name="items"></param>
|
|
||||||
public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel,
|
|
||||||
string format, params object[] items)
|
|
||||||
{
|
|
||||||
if (SaveData.Level >= level)
|
|
||||||
{
|
|
||||||
var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items));
|
|
||||||
Console(level, str);
|
|
||||||
LogError(errorLogLevel, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="level"></param>
|
|
||||||
/// <param name="errorLogLevel"></param>
|
|
||||||
/// <param name="format"></param>
|
|
||||||
/// <param name="items"></param>
|
|
||||||
public void Console(uint level, Debug.ErrorLogLevel errorLogLevel,
|
|
||||||
string format, params object[] items)
|
|
||||||
{
|
|
||||||
if (SaveData.Level >= level)
|
|
||||||
{
|
|
||||||
var str = string.Format(format, items);
|
|
||||||
Console(level, str);
|
|
||||||
LogError(errorLogLevel, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="errorLogLevel"></param>
|
|
||||||
/// <param name="str"></param>
|
|
||||||
/// <summary>
|
|
||||||
/// LogError method
|
|
||||||
/// </summary>
|
|
||||||
public void LogError(Debug.ErrorLogLevel errorLogLevel, string str)
|
|
||||||
{
|
|
||||||
string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
|
|
||||||
switch (errorLogLevel)
|
|
||||||
{
|
|
||||||
case Debug.ErrorLogLevel.Error:
|
|
||||||
ErrorLog.Error(msg);
|
|
||||||
break;
|
|
||||||
case Debug.ErrorLogLevel.Warning:
|
|
||||||
ErrorLog.Warn(msg);
|
|
||||||
break;
|
|
||||||
case Debug.ErrorLogLevel.Notice:
|
|
||||||
ErrorLog.Notice(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes the memory object after timeout
|
|
||||||
/// </summary>
|
|
||||||
void SaveMemoryOnTimeout()
|
|
||||||
{
|
|
||||||
if (SaveTimer == null)
|
|
||||||
SaveTimer = new CTimer(o =>
|
|
||||||
{
|
|
||||||
SaveTimer = null;
|
|
||||||
SaveMemory();
|
|
||||||
}, SaveTimeoutMs);
|
|
||||||
else
|
|
||||||
SaveTimer.Reset(SaveTimeoutMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes the memory - use SaveMemoryOnTimeout
|
|
||||||
/// </summary>
|
|
||||||
void SaveMemory()
|
|
||||||
{
|
|
||||||
using (StreamWriter sw = new StreamWriter(GetMemoryFileName()))
|
|
||||||
{
|
|
||||||
var json = JsonConvert.SerializeObject(SaveData);
|
|
||||||
sw.Write(json);
|
|
||||||
sw.Flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
void LoadMemory()
|
|
||||||
{
|
|
||||||
var file = GetMemoryFileName();
|
|
||||||
if (File.Exists(file))
|
|
||||||
{
|
|
||||||
using (StreamReader sr = new StreamReader(file))
|
|
||||||
{
|
|
||||||
var data = JsonConvert.DeserializeObject<DebugContextSaveData>(sr.ReadToEnd());
|
|
||||||
if (data != null)
|
|
||||||
{
|
|
||||||
SaveData = data;
|
|
||||||
Debug.Console(1, "Debug memory restored from file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SaveData = new DebugContextSaveData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Helper to get the file path for this app's debug memory
|
|
||||||
/// </summary>
|
|
||||||
string GetMemoryFileName()
|
|
||||||
{
|
|
||||||
return string.Format(@"\NVRAM\debugSettings\program{0}-{1}", InitialParametersClass.ApplicationNumber, Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class DebugContextSaveData
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public int Level { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,16 +3,10 @@ using Crestron.SimplSharp.CrestronLogger;
|
|||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace PepperDash.Core.Logging
|
namespace PepperDash.Core.Logging;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a DebugCrestronLoggerSink
|
|
||||||
/// </summary>
|
|
||||||
public class DebugCrestronLoggerSink : ILogEventSink
|
public class DebugCrestronLoggerSink : ILogEventSink
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Emit method
|
|
||||||
/// </summary>
|
|
||||||
public void Emit(LogEvent logEvent)
|
public void Emit(LogEvent logEvent)
|
||||||
{
|
{
|
||||||
if (!Debug.IsRunningOnAppliance) return;
|
if (!Debug.IsRunningOnAppliance) return;
|
||||||
@@ -32,4 +26,3 @@ namespace PepperDash.Core.Logging
|
|||||||
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
|
CrestronLogger.Initialize(1, LoggerModeEnum.RM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PepperDash.Core.Logging
|
namespace PepperDash.Core.Logging;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a DebugErrorLogSink
|
|
||||||
/// </summary>
|
|
||||||
public class DebugErrorLogSink : ILogEventSink
|
public class DebugErrorLogSink : ILogEventSink
|
||||||
{
|
{
|
||||||
private ITextFormatter _formatter;
|
private ITextFormatter _formatter;
|
||||||
@@ -27,9 +24,6 @@ namespace PepperDash.Core.Logging
|
|||||||
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) },
|
{LogEventLevel.Error, (msg) => ErrorLog.Error(msg) },
|
||||||
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) }
|
{LogEventLevel.Fatal, (msg) => ErrorLog.Error(msg) }
|
||||||
};
|
};
|
||||||
/// <summary>
|
|
||||||
/// Emit method
|
|
||||||
/// </summary>
|
|
||||||
public void Emit(LogEvent logEvent)
|
public void Emit(LogEvent logEvent)
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
@@ -68,4 +62,3 @@ namespace PepperDash.Core.Logging
|
|||||||
_formatter = formatter;
|
_formatter = formatter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,112 +2,72 @@
|
|||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using Log = PepperDash.Core.Debug;
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
public static void LogFatal(this IKeyed device, string message, params object[] args)
|
||||||
{
|
{
|
||||||
Log.LogFatal(device, message, args);
|
Log.LogMessage(LogEventLevel.Fatal, device, message, args);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
using System.Collections.Generic;
|
extern alias NewtonsoftJson;
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Newtonsoft.Json;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using JsonProperty = NewtonsoftJson::Newtonsoft.Json.JsonPropertyAttribute;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.Logging;
|
||||||
|
|
||||||
namespace PepperDash.Core.Logging
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DebugContextCollection
|
/// Class to persist current Debug settings across program restarts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DebugContextCollection
|
public class DebugContextCollection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// To prevent threading issues with the DeviceDebugSettings collection
|
/// To prevent threading issues with the DeviceDebugSettings collection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly CCriticalSection _deviceDebugSettingsLock;
|
private readonly object _deviceDebugSettingsLock = new();
|
||||||
|
|
||||||
[JsonProperty("items")] private readonly Dictionary<string, DebugContextItem> _items;
|
[JsonProperty("items")]
|
||||||
|
private readonly Dictionary<string, DebugContextItem> _items = new Dictionary<string, DebugContextItem>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collection of the debug settings for each device where the dictionary key is the device key
|
/// Collection of the debug settings for each device where the dictionary key is the device key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("deviceDebugSettings")]
|
[JsonProperty("deviceDebugSettings")]
|
||||||
private Dictionary<string, object> DeviceDebugSettings { get; set; }
|
private Dictionary<string, object> DeviceDebugSettings { get; set; } = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,9 +32,7 @@ namespace PepperDash.Core.Logging
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DebugContextCollection()
|
public DebugContextCollection()
|
||||||
{
|
{
|
||||||
_deviceDebugSettingsLock = new CCriticalSection();
|
|
||||||
DeviceDebugSettings = new Dictionary<string, object>();
|
|
||||||
_items = new Dictionary<string, DebugContextItem>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,15 +73,10 @@ namespace PepperDash.Core.Logging
|
|||||||
/// <param name="deviceKey"></param>
|
/// <param name="deviceKey"></param>
|
||||||
/// <param name="settings"></param>
|
/// <param name="settings"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// SetDebugSettingsForKey method
|
|
||||||
/// </summary>
|
|
||||||
public void SetDebugSettingsForKey(string deviceKey, object settings)
|
public void SetDebugSettingsForKey(string deviceKey, object settings)
|
||||||
{
|
{
|
||||||
try
|
lock (_deviceDebugSettingsLock)
|
||||||
{
|
{
|
||||||
_deviceDebugSettingsLock.Enter();
|
|
||||||
|
|
||||||
if (DeviceDebugSettings.ContainsKey(deviceKey))
|
if (DeviceDebugSettings.ContainsKey(deviceKey))
|
||||||
{
|
{
|
||||||
DeviceDebugSettings[deviceKey] = settings;
|
DeviceDebugSettings[deviceKey] = settings;
|
||||||
@@ -87,10 +84,6 @@ namespace PepperDash.Core.Logging
|
|||||||
else
|
else
|
||||||
DeviceDebugSettings.Add(deviceKey, settings);
|
DeviceDebugSettings.Add(deviceKey, settings);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_deviceDebugSettingsLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -98,9 +91,6 @@ namespace PepperDash.Core.Logging
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deviceKey"></param>
|
/// <param name="deviceKey"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <summary>
|
|
||||||
/// GetDebugSettingsForKey method
|
|
||||||
/// </summary>
|
|
||||||
public object GetDebugSettingsForKey(string deviceKey)
|
public object GetDebugSettingsForKey(string deviceKey)
|
||||||
{
|
{
|
||||||
return DeviceDebugSettings[deviceKey];
|
return DeviceDebugSettings[deviceKey];
|
||||||
@@ -124,4 +114,3 @@ namespace PepperDash.Core.Logging
|
|||||||
[JsonProperty("doNotLoadOnNextBoot")]
|
[JsonProperty("doNotLoadOnNextBoot")]
|
||||||
public bool DoNotLoadOnNextBoot { get; set; }
|
public bool DoNotLoadOnNextBoot { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,37 +1,42 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System;
|
||||||
using System.Text;
|
using Crestron.SimplSharp;
|
||||||
using System.Threading.Tasks;
|
using Org.BouncyCastle.Asn1.X509;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Serilog.Configuration;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
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 Serilog.Formatting;
|
||||||
using Newtonsoft.Json.Linq;
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
using Serilog.Formatting.Json;
|
using Serilog.Formatting.Json;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Authentication;
|
||||||
|
using WebSocketSharp;
|
||||||
|
using WebSocketSharp.Server;
|
||||||
|
using X509Certificate2 = System.Security.Cryptography.X509Certificates.X509Certificate2;
|
||||||
|
using WebSocketSharp.Net;
|
||||||
|
|
||||||
|
namespace PepperDash.Core;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DebugWebsocketSink
|
/// Provides a WebSocket-based logging sink for debugging purposes, allowing log events to be broadcast to connected
|
||||||
|
/// WebSocket clients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DebugWebsocketSink : ILogEventSink
|
/// <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
|
||||||
{
|
{
|
||||||
private HttpServer _httpsServer;
|
private HttpServer _httpsServer;
|
||||||
|
|
||||||
private string _path = "/debug/join/";
|
private readonly string _path = "/debug/join/";
|
||||||
private const string _certificateName = "selfCres";
|
private const string _certificateName = "selfCres";
|
||||||
private const string _certificatePassword = "cres12345";
|
private const string _certificatePassword = "cres12345";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the port number on which the HTTPS server is currently running.
|
||||||
|
/// </summary>
|
||||||
public int Port
|
public int Port
|
||||||
{ get
|
{ get
|
||||||
{
|
{
|
||||||
@@ -41,6 +46,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
|
public string Url
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -51,20 +61,30 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the IsRunning
|
/// Gets a value indicating whether the HTTPS server is currently listening for incoming connections.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsRunning { get => _httpsServer?.IsListening ?? false; }
|
public bool IsRunning { get => _httpsServer?.IsListening ?? false; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public string Key => "DebugWebsocketSink";
|
||||||
|
|
||||||
private readonly ITextFormatter _textFormatter;
|
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)
|
public DebugWebsocketSink(ITextFormatter formatProvider)
|
||||||
{
|
{
|
||||||
|
|
||||||
_textFormatter = formatProvider ?? new JsonFormatter();
|
_textFormatter = formatProvider ?? new JsonFormatter();
|
||||||
|
|
||||||
if (!File.Exists($"\\user\\{_certificateName}.pfx"))
|
if (!File.Exists($"\\user\\{_certificateName}.pfx"))
|
||||||
CreateCert(null);
|
CreateCert();
|
||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += type =>
|
CrestronEnvironment.ProgramStatusEventHandler += type =>
|
||||||
{
|
{
|
||||||
@@ -75,45 +95,41 @@ namespace PepperDash.Core
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateCert(string[] args)
|
private static void CreateCert()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Debug.Console(0,"CreateCert Creating Utility");
|
|
||||||
CrestronConsole.PrintLine("CreateCert Creating Utility");
|
|
||||||
//var utility = new CertificateUtility();
|
|
||||||
var utility = new BouncyCertificate();
|
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 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 hostName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
|
||||||
var domainName = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_DOMAIN_NAME, 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);
|
Debug.LogInformation("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), [string.Format("{0}.{1}", hostName, domainName), ipAddress], [KeyPurposeID.id_kp_serverAuth, KeyPurposeID.id_kp_clientAuth]);
|
||||||
|
|
||||||
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 });
|
|
||||||
//Crestron fails to let us do this...perhaps it should be done through their Dll's but haven't tested
|
//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);
|
var separator = Path.DirectorySeparatorChar;
|
||||||
//Debug.Console(0, "CreateCert Saving Cert to \\user\\");
|
|
||||||
CrestronConsole.PrintLine("CreateCert Saving Cert to \\user\\");
|
|
||||||
utility.CertificatePassword = _certificatePassword;
|
utility.CertificatePassword = _certificatePassword;
|
||||||
utility.WriteCertificate(certificate, @"\user\", _certificateName);
|
utility.WriteCertificate(certificate, @$"{separator}user{separator}", _certificateName);
|
||||||
//Debug.Console(0, "CreateCert Ending CreateCert");
|
|
||||||
CrestronConsole.PrintLine("CreateCert Ending CreateCert");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//Debug.Console(0, "WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace);
|
Debug.LogError(ex, "WSS CreateCert Failed: {0}", ex.Message);
|
||||||
CrestronConsole.PrintLine(string.Format("WSS CreateCert Failed\r\n{0}\r\n{1}", ex.Message, ex.StackTrace));
|
Debug.LogVerbose("Stack Trace:\r{0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Emit method
|
/// Sends a log event to all connected WebSocket clients.
|
||||||
/// </summary>
|
/// </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)
|
public void Emit(LogEvent logEvent)
|
||||||
{
|
{
|
||||||
if (_httpsServer == null || !_httpsServer.IsListening) return;
|
if (_httpsServer == null || !_httpsServer.IsListening) return;
|
||||||
@@ -121,16 +137,19 @@ namespace PepperDash.Core
|
|||||||
var sw = new StringWriter();
|
var sw = new StringWriter();
|
||||||
_textFormatter.Format(logEvent, sw);
|
_textFormatter.Format(logEvent, sw);
|
||||||
|
|
||||||
_httpsServer.WebSocketServices.Broadcast(sw.ToString());
|
_httpsServer.WebSocketServices[_path].Sessions.Broadcast(sw.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StartServerAndSetPort method
|
/// Starts the WebSocket server on the specified port and configures it with the appropriate certificate.
|
||||||
/// </summary>
|
/// </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)
|
public void StartServerAndSetPort(int port)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Starting Websocket Server on port: {0}", port);
|
Debug.LogInformation("Starting Websocket Server on port: {0}", port);
|
||||||
|
|
||||||
|
|
||||||
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword);
|
Start(port, $"\\user\\{_certificateName}.pfx", _certificatePassword);
|
||||||
@@ -142,26 +161,24 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
_httpsServer = new HttpServer(port, true);
|
_httpsServer = new HttpServer(port, true);
|
||||||
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(certPath))
|
if (!string.IsNullOrWhiteSpace(certPath))
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Assigning SSL Configuration");
|
Debug.LogInformation("Assigning SSL Configuration");
|
||||||
_httpsServer.SslConfiguration = new ServerSslConfiguration(new X509Certificate2(certPath, certPassword))
|
|
||||||
{
|
_httpsServer.SslConfiguration.ServerCertificate = new X509Certificate2(certPath, certPassword);
|
||||||
ClientCertificateRequired = false,
|
_httpsServer.SslConfiguration.ClientCertificateRequired = false;
|
||||||
CheckCertificateRevocation = false,
|
_httpsServer.SslConfiguration.CheckCertificateRevocation = false;
|
||||||
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls,
|
_httpsServer.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
|
||||||
//this is just to test, you might want to actually validate
|
//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");
|
Debug.LogInformation("HTTPS ClientCerticateValidation Callback triggered");
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Debug.Console(0, "Adding Debug Client Service");
|
Debug.LogInformation("Adding Debug Client Service");
|
||||||
_httpsServer.AddWebSocketService<DebugClient>(_path);
|
_httpsServer.AddWebSocketService<DebugClient>(_path);
|
||||||
Debug.Console(0, "Assigning Log Info");
|
Debug.LogInformation("Assigning Log Info");
|
||||||
_httpsServer.Log.Level = LogLevel.Trace;
|
_httpsServer.Log.Level = LogLevel.Trace;
|
||||||
_httpsServer.Log.Output = (d, s) =>
|
_httpsServer.Log.Output = (d, s) =>
|
||||||
{
|
{
|
||||||
@@ -191,37 +208,49 @@ namespace PepperDash.Core
|
|||||||
level = 4;
|
level = 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Debug.LogInformation("{1} {0}\rCaller:{2}\rMessage:{3}\rs:{4}", d.Level.ToString(), d.Date.ToString(), d.Caller.ToString(), d.Message, s);
|
||||||
Debug.Console(level, "{1} {0}\rCaller:{2}\rMessage:{3}\rs:{4}", d.Level.ToString(), d.Date.ToString(), d.Caller.ToString(), d.Message, s);
|
|
||||||
};
|
};
|
||||||
Debug.Console(0, "Starting");
|
Debug.LogInformation("Starting");
|
||||||
|
|
||||||
_httpsServer.Start();
|
_httpsServer.Start();
|
||||||
Debug.Console(0, "Ready");
|
Debug.LogInformation("Ready");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(0, "WebSocket Failed to start {0}", ex.Message);
|
Debug.LogError(ex, "WebSocket Failed to start {0}", ex.Message);
|
||||||
|
Debug.LogVerbose("Stack Trace:\r{0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StopServer method
|
/// Stops the WebSocket server if it is currently running.
|
||||||
/// </summary>
|
/// </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()
|
public void StopServer()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "Stopping Websocket Server");
|
Debug.LogInformation("Stopping Websocket Server");
|
||||||
_httpsServer?.Stop();
|
_httpsServer?.Stop();
|
||||||
|
|
||||||
_httpsServer = null;
|
_httpsServer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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
|
public static class DebugWebsocketSinkExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DebugWebsocketSink method
|
/// Configures a logger to write log events to a debug WebSocket sink.
|
||||||
/// </summary>
|
/// </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(
|
public static LoggerConfiguration DebugWebsocketSink(
|
||||||
this LoggerSinkConfiguration loggerConfiguration,
|
this LoggerSinkConfiguration loggerConfiguration,
|
||||||
ITextFormatter formatProvider = null)
|
ITextFormatter formatProvider = null)
|
||||||
@@ -231,12 +260,19 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DebugClient
|
/// Represents a WebSocket client for debugging purposes, providing connection lifecycle management and message
|
||||||
|
/// handling functionality.
|
||||||
/// </summary>
|
/// </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
|
public class DebugClient : WebSocketBehavior
|
||||||
{
|
{
|
||||||
private DateTime _connectionTime;
|
private DateTime _connectionTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the duration of time the WebSocket connection has been active.
|
||||||
|
/// </summary>
|
||||||
public TimeSpan ConnectedDuration
|
public TimeSpan ConnectedDuration
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -252,41 +288,47 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="DebugClient"/> class.
|
||||||
|
/// </summary>
|
||||||
public DebugClient()
|
public DebugClient()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "DebugClient Created");
|
Debug.LogInformation("DebugClient Created");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
protected override void OnOpen()
|
protected override void OnOpen()
|
||||||
{
|
{
|
||||||
base.OnOpen();
|
base.OnOpen();
|
||||||
|
|
||||||
var url = Context.WebSocket.Url;
|
var url = Context.WebSocket.Url;
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WebSocket Connection from: {0}", url);
|
Debug.LogInformation("New WebSocket Connection from: {0}", url);
|
||||||
|
|
||||||
_connectionTime = DateTime.Now;
|
_connectionTime = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
protected override void OnMessage(MessageEventArgs e)
|
protected override void OnMessage(MessageEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMessage(e);
|
base.OnMessage(e);
|
||||||
|
|
||||||
Debug.Console(0, "WebSocket UiClient Message: {0}", e.Data);
|
Debug.LogVerbose("WebSocket UiClient Message: {0}", e.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
protected override void OnClose(CloseEventArgs e)
|
protected override void OnClose(CloseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnClose(e);
|
base.OnClose(e);
|
||||||
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Closing: {0} reason: {1}", e.Code, e.Reason);
|
Debug.LogDebug("WebSocket UiClient Closing: {0} reason: {1}", e.Code, e.Reason);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
|
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnError(e);
|
base.OnError(e);
|
||||||
|
|
||||||
Debug.Console(2, Debug.ErrorLogLevel.Notice, "WebSocket UiClient Error: {0} message: {1}", e.Exception, e.Message);
|
Debug.LogError(e.Exception, "WebSocket UiClient Error: {0} message: {1}", e.Exception, e.Message);
|
||||||
}
|
Debug.LogVerbose("Stack Trace:\r{0}", e.Exception.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Not in use
|
/// Not in use
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -18,5 +18,3 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.PasswordManagement
|
namespace PepperDash.Core.PasswordManagement;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// JSON password configuration
|
/// JSON password configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,4 +23,3 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.PasswordManagement
|
namespace PepperDash.Core.PasswordManagement;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants
|
/// Constants
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -54,4 +54,3 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const ushort StringValueChange = 201;
|
public const ushort StringValueChange = 201;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace PepperDash.Core.PasswordManagement
|
namespace PepperDash.Core.PasswordManagement;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a PasswordClient
|
/// A class to allow user interaction with the PasswordManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PasswordClient
|
public class PasswordClient
|
||||||
{
|
{
|
||||||
@@ -193,4 +193,3 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp;
|
using System.Timers;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.PasswordManagement;
|
||||||
|
|
||||||
namespace PepperDash.Core.PasswordManagement
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a PasswordManager
|
/// Allows passwords to be stored and managed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PasswordManager
|
public class PasswordManager
|
||||||
{
|
{
|
||||||
@@ -21,7 +21,7 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer used to wait until password changes have stopped before updating the dictionary
|
/// Timer used to wait until password changes have stopped before updating the dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CTimer PasswordTimer;
|
Timer PasswordTimer;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer length
|
/// Timer length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -79,7 +79,7 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
// validate the parameters
|
// validate the parameters
|
||||||
if (key > 0 && string.IsNullOrEmpty(password))
|
if (key > 0 && string.IsNullOrEmpty(password))
|
||||||
{
|
{
|
||||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: key [{0}] or password are not valid", key, password));
|
Debug.LogDebug("PasswordManager.UpdatePassword: key [{0}] or password are not valid", key, password);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,47 +92,52 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
else
|
else
|
||||||
_passwords.Add(key, password);
|
_passwords.Add(key, password);
|
||||||
|
|
||||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: _password[{0}] = {1}", key, _passwords[key]));
|
Debug.LogDebug("PasswordManager.UpdatePassword: _password[{0}] = {1}", key, _passwords[key]);
|
||||||
|
|
||||||
if (PasswordTimer == null)
|
if (PasswordTimer == null)
|
||||||
{
|
{
|
||||||
PasswordTimer = new CTimer((o) => PasswordTimerElapsed(), PasswordTimerElapsedMs);
|
PasswordTimer = new Timer(PasswordTimerElapsedMs) { AutoReset = false };
|
||||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: CTimer Started"));
|
PasswordTimer.Elapsed += (s, e) => PasswordTimerElapsed(s, e);
|
||||||
|
PasswordTimer.Start();
|
||||||
|
Debug.LogDebug("PasswordManager.UpdatePassword: Timer Started");
|
||||||
OnBoolChange(true, 0, PasswordManagementConstants.PasswordUpdateBusyChange);
|
OnBoolChange(true, 0, PasswordManagementConstants.PasswordUpdateBusyChange);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PasswordTimer.Reset(PasswordTimerElapsedMs);
|
PasswordTimer.Stop();
|
||||||
Debug.Console(1, string.Format("PasswordManager.UpdatePassword: CTimer Reset"));
|
PasswordTimer.Interval = PasswordTimerElapsedMs;
|
||||||
|
PasswordTimer.Start();
|
||||||
|
Debug.LogDebug("PasswordManager.UpdatePassword: Timer Reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var msg = string.Format("PasswordManager.UpdatePassword key-value[{0}, {1}] failed:\r{2}", key, password, e);
|
var msg = string.Format("PasswordManager.UpdatePassword key-value[{0}, {1}] failed:\r{2}", key, password, e);
|
||||||
Debug.Console(1, msg);
|
Debug.LogError(e, msg);
|
||||||
|
Debug.LogVerbose("Stack Trace:\r{0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CTimer callback function
|
/// Timer callback function
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void PasswordTimerElapsed()
|
private void PasswordTimerElapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PasswordTimer.Stop();
|
PasswordTimer.Stop();
|
||||||
Debug.Console(1, string.Format("PasswordManager.PasswordTimerElapsed: CTimer Stopped"));
|
Debug.LogDebug("PasswordManager.PasswordTimerElapsed: Timer Stopped");
|
||||||
OnBoolChange(false, 0, PasswordManagementConstants.PasswordUpdateBusyChange);
|
OnBoolChange(false, 0, PasswordManagementConstants.PasswordUpdateBusyChange);
|
||||||
foreach (var pw in _passwords)
|
foreach (var pw in _passwords)
|
||||||
{
|
{
|
||||||
// if key exists, continue
|
// if key exists, continue
|
||||||
if (Passwords.ContainsKey(pw.Key))
|
if (Passwords.ContainsKey(pw.Key))
|
||||||
{
|
{
|
||||||
Debug.Console(1, string.Format("PasswordManager.PasswordTimerElapsed: pw.key[{0}] = {1}", pw.Key, pw.Value));
|
Debug.LogDebug("PasswordManager.PasswordTimerElapsed: pw.key[{0}] = {1}", pw.Key, pw.Value);
|
||||||
if (Passwords[pw.Key] != _passwords[pw.Key])
|
if (Passwords[pw.Key] != _passwords[pw.Key])
|
||||||
{
|
{
|
||||||
Passwords[pw.Key] = _passwords[pw.Key];
|
Passwords[pw.Key] = _passwords[pw.Key];
|
||||||
Debug.Console(1, string.Format("PasswordManager.PasswordTimerElapsed: Updated Password[{0} = {1}", pw.Key, Passwords[pw.Key]));
|
Debug.LogDebug("PasswordManager.PasswordTimerElapsed: Updated Password[{0} = {1}", pw.Key, Passwords[pw.Key]);
|
||||||
OnPasswordChange(Passwords[pw.Key], (ushort)pw.Key, PasswordManagementConstants.StringValueChange);
|
OnPasswordChange(Passwords[pw.Key], (ushort)pw.Key, PasswordManagementConstants.StringValueChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,10 +149,11 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
}
|
}
|
||||||
OnUshrtChange((ushort)Passwords.Count, 0, PasswordManagementConstants.PasswordManagerCountChange);
|
OnUshrtChange((ushort)Passwords.Count, 0, PasswordManagementConstants.PasswordManagerCountChange);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = string.Format("PasswordManager.PasswordTimerElapsed failed:\r{0}", e);
|
var msg = string.Format("PasswordManager.PasswordTimerElapsed failed:\r{0}", ex.Message);
|
||||||
Debug.Console(1, msg);
|
Debug.LogError(ex, msg);
|
||||||
|
Debug.LogVerbose("Stack Trace:\r{0}", ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,12 +174,12 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ListPasswords()
|
public void ListPasswords()
|
||||||
{
|
{
|
||||||
Debug.Console(0, "PasswordManager.ListPasswords:\r");
|
Debug.LogInformation("PasswordManager.ListPasswords:\r");
|
||||||
foreach (var pw in Passwords)
|
foreach (var pw in Passwords)
|
||||||
Debug.Console(0, "Passwords[{0}]: {1}\r", pw.Key, pw.Value);
|
Debug.LogInformation("Passwords[{0}]: {1}\r", pw.Key, pw.Value);
|
||||||
Debug.Console(0, "\n");
|
Debug.LogInformation("\n");
|
||||||
foreach (var pw in _passwords)
|
foreach (var pw in _passwords)
|
||||||
Debug.Console(0, "_passwords[{0}]: {1}\r", pw.Key, pw.Value);
|
Debug.LogInformation("_passwords[{0}]: {1}\r", pw.Key, pw.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -244,4 +250,3 @@ namespace PepperDash.Core.PasswordManagement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<RootNamespace>PepperDash.Core</RootNamespace>
|
<RootNamespace>PepperDash.Core</RootNamespace>
|
||||||
<AssemblyName>PepperDashCore</AssemblyName>
|
<AssemblyName>PepperDashCore</AssemblyName>
|
||||||
<TargetFramework>net472</TargetFramework>
|
<TargetFramework>net8</TargetFramework>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<NeutralLanguage>en</NeutralLanguage>
|
<NeutralLanguage>en</NeutralLanguage>
|
||||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||||
@@ -37,23 +37,18 @@
|
|||||||
<None Remove="Properties\**" />
|
<None Remove="Properties\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<PackageReference Include="Crestron.SimplSharp.SDK.Library" Version="2.21.128" />
|
||||||
<Reference Include="System.Net.Http" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4">
|
||||||
</ItemGroup>
|
<Aliases>global,NewtonsoftJson</Aliases>
|
||||||
<ItemGroup>
|
</PackageReference>
|
||||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||||
<PackageReference Include="Crestron.SimplSharp.SDK.Library" Version="2.21.90" />
|
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
|
||||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
|
||||||
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
|
||||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
|
||||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6'">
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Comm\._GenericSshClient.cs" />
|
<Compile Remove="Comm\._GenericSshClient.cs" />
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.SystemInfo
|
namespace PepperDash.Core.SystemInfo;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants
|
/// Constants
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -261,4 +261,3 @@ namespace PepperDash.Core.SystemInfo
|
|||||||
Index = index;
|
Index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.SystemInfo
|
namespace PepperDash.Core.SystemInfo;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processor info class
|
/// Processor info class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -201,4 +201,3 @@ namespace PepperDash.Core.SystemInfo
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
namespace PepperDash.Core.SystemInfo
|
namespace PepperDash.Core.SystemInfo;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// System Info class
|
/// System Info class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -468,4 +468,3 @@ namespace PepperDash.Core.SystemInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -20,8 +20,8 @@ using Org.BouncyCastle.Crypto.Operators;
|
|||||||
using BigInteger = Org.BouncyCastle.Math.BigInteger;
|
using BigInteger = Org.BouncyCastle.Math.BigInteger;
|
||||||
using X509Certificate = Org.BouncyCastle.X509.X509Certificate;
|
using X509Certificate = Org.BouncyCastle.X509.X509Certificate;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Taken From https://github.com/rlipscombe/bouncy-castle-csharp/
|
/// Taken From https://github.com/rlipscombe/bouncy-castle-csharp/
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -35,9 +35,6 @@ namespace PepperDash.Core
|
|||||||
return issuerCertificate;
|
return issuerCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IssueCertificate method
|
|
||||||
/// </summary>
|
|
||||||
public X509Certificate2 IssueCertificate(string subjectName, X509Certificate2 issuerCertificate, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
public X509Certificate2 IssueCertificate(string subjectName, X509Certificate2 issuerCertificate, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||||
{
|
{
|
||||||
// It's self-signed, so these are the same.
|
// It's self-signed, so these are the same.
|
||||||
@@ -59,9 +56,6 @@ namespace PepperDash.Core
|
|||||||
return ConvertCertificate(certificate, subjectKeyPair, random);
|
return ConvertCertificate(certificate, subjectKeyPair, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// CreateCertificateAuthorityCertificate method
|
|
||||||
/// </summary>
|
|
||||||
public X509Certificate2 CreateCertificateAuthorityCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
public X509Certificate2 CreateCertificateAuthorityCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||||
{
|
{
|
||||||
// It's self-signed, so these are the same.
|
// It's self-signed, so these are the same.
|
||||||
@@ -84,9 +78,6 @@ namespace PepperDash.Core
|
|||||||
return ConvertCertificate(certificate, subjectKeyPair, random);
|
return ConvertCertificate(certificate, subjectKeyPair, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// CreateSelfSignedCertificate method
|
|
||||||
/// </summary>
|
|
||||||
public X509Certificate2 CreateSelfSignedCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
public X509Certificate2 CreateSelfSignedCertificate(string subjectName, string[] subjectAlternativeNames, KeyPurposeID[] usages)
|
||||||
{
|
{
|
||||||
// It's self-signed, so these are the same.
|
// It's self-signed, so these are the same.
|
||||||
@@ -314,9 +305,6 @@ namespace PepperDash.Core
|
|||||||
return convertedCertificate;
|
return convertedCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WriteCertificate method
|
|
||||||
/// </summary>
|
|
||||||
public void WriteCertificate(X509Certificate2 certificate, string outputDirectory, string certName)
|
public void WriteCertificate(X509Certificate2 certificate, string outputDirectory, string certName)
|
||||||
{
|
{
|
||||||
// This password is the one attached to the PFX file. Use 'null' for no password.
|
// 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)
|
public bool AddCertToStore(X509Certificate2 cert, System.Security.Cryptography.X509Certificates.StoreName st, System.Security.Cryptography.X509Certificates.StoreLocation sl)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
@@ -368,4 +353,3 @@ namespace PepperDash.Core
|
|||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
|
||||||
namespace PepperDash.Core.Web.RequestHandlers
|
namespace PepperDash.Core.Web.RequestHandlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DefaultRequestHandler
|
/// Web API default request handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultRequestHandler : WebApiBaseRequestHandler
|
public class DefaultRequestHandler : WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
@@ -14,4 +14,3 @@ namespace PepperDash.Core.Web.RequestHandlers
|
|||||||
: base(true)
|
: base(true)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
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;
|
private readonly Dictionary<string, Func<HttpCwsContext, Task>> _handlers;
|
||||||
@@ -142,9 +142,6 @@ namespace PepperDash.Core.Web.RequestHandlers
|
|||||||
/// Process request
|
/// Process request
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
/// <summary>
|
|
||||||
/// ProcessRequest method
|
|
||||||
/// </summary>
|
|
||||||
public void ProcessRequest(HttpCwsContext context)
|
public void ProcessRequest(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
if (!_handlers.TryGetValue(context.Request.HttpMethod, out Func<HttpCwsContext, Task> handler))
|
if (!_handlers.TryGetValue(context.Request.HttpMethod, out Func<HttpCwsContext, Task> handler))
|
||||||
@@ -163,4 +160,3 @@ namespace PepperDash.Core.Web.RequestHandlers
|
|||||||
handlerTask.GetAwaiter().GetResult();
|
handlerTask.GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp.WebScripting;
|
||||||
|
|
||||||
namespace PepperDash.Core.Web.RequestHandlers
|
namespace PepperDash.Core.Web.RequestHandlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CWS Base Handler, implements IHttpCwsHandler
|
/// CWS Base Handler, implements IHttpCwsHandler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -165,4 +165,3 @@ namespace PepperDash.Core.Web.RequestHandlers
|
|||||||
handler(context);
|
handler(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
using System;
|
extern alias NewtonsoftJson;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp.WebScripting;
|
||||||
using Newtonsoft.Json;
|
using Formatting = NewtonsoftJson::Newtonsoft.Json.Formatting;
|
||||||
using Newtonsoft.Json.Linq;
|
using JsonConvert = NewtonsoftJson::Newtonsoft.Json.JsonConvert;
|
||||||
|
using JObject = NewtonsoftJson::Newtonsoft.Json.Linq.JObject;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
|
||||||
|
namespace PepperDash.Core.Web;
|
||||||
|
|
||||||
namespace PepperDash.Core.Web
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Web API server
|
/// Web API server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -18,11 +23,7 @@ namespace PepperDash.Core.Web
|
|||||||
private const string DefaultName = "Web API Server";
|
private const string DefaultName = "Web API Server";
|
||||||
private const string DefaultBasePath = "/api";
|
private const string DefaultBasePath = "/api";
|
||||||
|
|
||||||
private const uint DebugTrace = 0;
|
private readonly object _serverLock = new();
|
||||||
private const uint DebugInfo = 1;
|
|
||||||
private const uint DebugVerbose = 2;
|
|
||||||
|
|
||||||
private readonly CCriticalSection _serverLock = new CCriticalSection();
|
|
||||||
private HttpCwsServer _server;
|
private HttpCwsServer _server;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -45,28 +46,6 @@ namespace PepperDash.Core.Web
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsRegistered { get; private set; }
|
public bool IsRegistered { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Http request handler
|
|
||||||
/// </summary>
|
|
||||||
//public IHttpCwsHandler HttpRequestHandler
|
|
||||||
//{
|
|
||||||
// get { return _server.HttpRequestHandler; }
|
|
||||||
// set
|
|
||||||
// {
|
|
||||||
// if (_server == null) return;
|
|
||||||
// _server.HttpRequestHandler = value;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Received request event handler
|
|
||||||
/// </summary>
|
|
||||||
//public event EventHandler<HttpCwsRequestEventArgs> ReceivedRequestEvent
|
|
||||||
//{
|
|
||||||
// add { _server.ReceivedRequestEvent += new HttpCwsRequestEventHandler(value); }
|
|
||||||
// remove { _server.ReceivedRequestEvent -= new HttpCwsRequestEventHandler(value); }
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for S+. Make sure to set necessary properties using init method
|
/// Constructor for S+. Make sure to set necessary properties using init method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -114,7 +93,7 @@ namespace PepperDash.Core.Web
|
|||||||
{
|
{
|
||||||
if (programEventType != eProgramStatusEventType.Stopping) return;
|
if (programEventType != eProgramStatusEventType.Stopping) return;
|
||||||
|
|
||||||
Debug.Console(DebugInfo, this, "Program stopping. stopping server");
|
this.LogInformation("Program stopping. stopping server");
|
||||||
|
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
@@ -128,11 +107,11 @@ namespace PepperDash.Core.Web
|
|||||||
// Re-enable the server if the link comes back up and the status should be connected
|
// Re-enable the server if the link comes back up and the status should be connected
|
||||||
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp && IsRegistered)
|
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp && IsRegistered)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Ethernet link up. Server is alreedy registered.");
|
this.LogInformation("Ethernet link up. Server is already registered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(DebugInfo, this, "Ethernet link up. Starting server");
|
this.LogInformation("Ethernet link up. Starting server");
|
||||||
|
|
||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
@@ -153,7 +132,7 @@ namespace PepperDash.Core.Web
|
|||||||
{
|
{
|
||||||
if (route == null)
|
if (route == null)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Failed to add route, route parameter is null");
|
this.LogWarning("Failed to add route, route parameter is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +151,7 @@ namespace PepperDash.Core.Web
|
|||||||
{
|
{
|
||||||
if (route == null)
|
if (route == null)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Failed to remote route, orute parameter is null");
|
this.LogWarning("Failed to remove route, route parameter is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,73 +170,62 @@ namespace PepperDash.Core.Web
|
|||||||
/// Starts CWS instance
|
/// Starts CWS instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
public void Start()
|
||||||
|
{
|
||||||
|
lock (_serverLock)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_serverLock.Enter();
|
|
||||||
|
|
||||||
if (_server == null)
|
if (_server == null)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server is null, unable to start");
|
this.LogDebug("Server is null, unable to start");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsRegistered)
|
if (IsRegistered)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server has already been started");
|
this.LogDebug("Server has already been started");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsRegistered = _server.Register();
|
IsRegistered = _server.Register();
|
||||||
|
|
||||||
Debug.Console(DebugInfo, this, "Starting server, registration {0}", IsRegistered ? "was successful" : "failed");
|
this.LogDebug("Starting server, registration {0}", IsRegistered ? "was successful" : "failed");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Start Exception Message: {0}", ex.Message);
|
this.LogException(ex, "Start Exception Message: {0}", ex.Message);
|
||||||
Debug.Console(DebugVerbose, this, "Start Exception StackTrace: {0}", ex.StackTrace);
|
this.LogVerbose("Start Exception StackTrace: {0}", ex.StackTrace);
|
||||||
if (ex.InnerException != null)
|
|
||||||
Debug.Console(DebugVerbose, this, "Start Exception InnerException: {0}", ex.InnerException);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_serverLock.Leave();
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop method
|
/// Stop method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
{
|
||||||
|
lock (_serverLock)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_serverLock.Enter();
|
|
||||||
|
|
||||||
if (_server == null)
|
if (_server == null)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server is null or has already been stopped");
|
this.LogDebug("Server is null or has already been stopped");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsRegistered = _server.Unregister() == false;
|
IsRegistered = _server.Unregister() == false;
|
||||||
|
|
||||||
Debug.Console(DebugInfo, this, "Stopping server, unregistration {0}", IsRegistered ? "failed" : "was successful");
|
this.LogDebug("Stopping server, unregistration {0}", IsRegistered ? "failed" : "was successful");
|
||||||
|
|
||||||
_server.Dispose();
|
_server.Dispose();
|
||||||
_server = null;
|
_server = null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server Stop Exception Message: {0}", ex.Message);
|
this.LogException(ex, "Server Stop Exception Message: {0}", ex.Message);
|
||||||
Debug.Console(DebugVerbose, this, "Server Stop Exception StackTrace: {0}", ex.StackTrace);
|
|
||||||
if (ex.InnerException != null)
|
|
||||||
Debug.Console(DebugVerbose, this, "Server Stop Exception InnerException: {0}", ex.InnerException);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_serverLock.Leave();
|
|
||||||
}
|
}
|
||||||
|
} // end lock
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -273,15 +241,12 @@ namespace PepperDash.Core.Web
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var j = JsonConvert.SerializeObject(args.Context, Formatting.Indented);
|
var j = JsonConvert.SerializeObject(args.Context, Formatting.Indented);
|
||||||
Debug.Console(DebugVerbose, this, "RecieveRequestEventHandler Context:\x0d\x0a{0}", j);
|
this.LogVerbose("RecieveRequestEventHandler Context:\x0d\x0a{0}", j);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "ReceivedRequestEventHandler Exception Message: {0}", ex.Message);
|
this.LogException(ex, "ReceivedRequestEventHandler Exception Message: {0}", ex.Message);
|
||||||
Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception StackTrace: {0}", ex.StackTrace);
|
this.LogVerbose("ReceivedRequestEventHandler Exception StackTrace: {0}", ex.StackTrace);
|
||||||
if (ex.InnerException != null)
|
|
||||||
Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace PepperDash.Core.WebApi.Presets
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a Preset
|
|
||||||
/// </summary>
|
|
||||||
public class Preset
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// ID of preset
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the UserId
|
|
||||||
/// </summary>
|
|
||||||
public int UserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the RoomTypeId
|
|
||||||
/// </summary>
|
|
||||||
public int RoomTypeId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the PresetName
|
|
||||||
/// </summary>
|
|
||||||
public string PresetName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the PresetNumber
|
|
||||||
/// </summary>
|
|
||||||
public int PresetNumber { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the Data
|
|
||||||
/// </summary>
|
|
||||||
public string Data { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
public Preset()
|
|
||||||
{
|
|
||||||
PresetName = "";
|
|
||||||
PresetNumber = 1;
|
|
||||||
Data = "{}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a PresetReceivedEventArgs
|
|
||||||
/// </summary>
|
|
||||||
public class PresetReceivedEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// True when the preset is found
|
|
||||||
/// </summary>
|
|
||||||
public bool LookupSuccess { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the ULookupSuccess
|
|
||||||
/// </summary>
|
|
||||||
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the Preset
|
|
||||||
/// </summary>
|
|
||||||
public Preset Preset { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// For Simpl+
|
|
||||||
/// </summary>
|
|
||||||
public PresetReceivedEventArgs() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="preset"></param>
|
|
||||||
/// <param name="success"></param>
|
|
||||||
public PresetReceivedEventArgs(Preset preset, bool success)
|
|
||||||
{
|
|
||||||
LookupSuccess = success;
|
|
||||||
Preset = preset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
namespace PepperDash.Core.WebApi.Presets
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class User
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public class UserReceivedEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// True when user is found
|
|
||||||
/// </summary>
|
|
||||||
public bool LookupSuccess { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the ULookupSuccess
|
|
||||||
/// </summary>
|
|
||||||
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the User
|
|
||||||
/// </summary>
|
|
||||||
public User User { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// For Simpl+
|
|
||||||
/// </summary>
|
|
||||||
public UserReceivedEventArgs() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="user"></param>
|
|
||||||
/// <param name="success"></param>
|
|
||||||
public UserReceivedEventArgs(User user, bool success)
|
|
||||||
{
|
|
||||||
LookupSuccess = success;
|
|
||||||
User = user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a UserAndRoomMessage
|
|
||||||
/// </summary>
|
|
||||||
public class UserAndRoomMessage
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user