From 88ebad1368a193b56f94c186d418205b2069510e Mon Sep 17 00:00:00 2001 From: Clive Galway Date: Wed, 14 Feb 2018 18:56:56 +0000 Subject: [PATCH 01/30] Change to using IProvider namespace --- UCR.Core/Managers/SubscriptionsManager.cs | 2 +- UCR.Core/Models/Binding/DeviceBinding.cs | 2 +- UCR.Core/Models/Device/Device.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index e980b34d..0fb531c7 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -1,6 +1,6 @@ using System; using NLog; -using Providers; +using IProvider; using UCR.Core.Models.Binding; using UCR.Core.Models.Device; using UCR.Core.Models.Profile; diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index 03c68199..cd9f66e0 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -1,6 +1,6 @@ using System; using System.Xml.Serialization; -using Providers; +using IProvider; using UCR.Core.Models.Device; namespace UCR.Core.Models.Binding diff --git a/UCR.Core/Models/Device/Device.cs b/UCR.Core/Models/Device/Device.cs index 6e4aa29e..055a8e7e 100644 --- a/UCR.Core/Models/Device/Device.cs +++ b/UCR.Core/Models/Device/Device.cs @@ -5,7 +5,7 @@ using System.Resources; using System.Xml.Serialization; using NLog; -using Providers; +using IProvider; using UCR.Core.Models.Binding; namespace UCR.Core.Models.Device From 06c0a73058007e266febb36c8d240618c13f2b96 Mon Sep 17 00:00:00 2001 From: Clive Galway Date: Wed, 14 Feb 2018 23:51:37 +0000 Subject: [PATCH 02/30] Update for new DLL locations --- UCR.Core/Context.cs | 2 +- UCR.Core/Managers/SubscriptionsManager.cs | 2 +- UCR.Core/Models/Binding/DeviceBinding.cs | 2 +- UCR.Core/Models/Device/Device.cs | 2 +- UCR.Core/UCR.Core.csproj | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/UCR.Core/Context.cs b/UCR.Core/Context.cs index 33fb76cd..061ecce5 100644 --- a/UCR.Core/Context.cs +++ b/UCR.Core/Context.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Xml.Serialization; -using IOWrapper; +using HidWizards.IOWrapper.Core; using Mono.Options; using NLog; using UCR.Core.Managers; diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index 0fb531c7..a8593cfd 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -1,6 +1,6 @@ using System; using NLog; -using IProvider; +using HidWizards.IOWrapper.DataTransferObjects; using UCR.Core.Models.Binding; using UCR.Core.Models.Device; using UCR.Core.Models.Profile; diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index cd9f66e0..acf0d368 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -1,6 +1,6 @@ using System; using System.Xml.Serialization; -using IProvider; +using HidWizards.IOWrapper.DataTransferObjects; using UCR.Core.Models.Device; namespace UCR.Core.Models.Binding diff --git a/UCR.Core/Models/Device/Device.cs b/UCR.Core/Models/Device/Device.cs index 055a8e7e..99850509 100644 --- a/UCR.Core/Models/Device/Device.cs +++ b/UCR.Core/Models/Device/Device.cs @@ -5,7 +5,7 @@ using System.Resources; using System.Xml.Serialization; using NLog; -using IProvider; +using HidWizards.IOWrapper.DataTransferObjects; using UCR.Core.Models.Binding; namespace UCR.Core.Models.Device diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index cd1b2c8f..4134c215 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -30,11 +30,11 @@ 4 - - ..\dependencies\IOController\IOWrapper.dll + + ..\dependencies\IOWrapper\IOWrapper.Core.dll - - ..\dependencies\IOController\IProvider.dll + + ..\dependencies\IOWrapper\IOWrapper.DTOs.dll ..\packages\Mono.Options.5.3.0.1\lib\net4-client\Mono.Options.dll From f625c4b7194ee1512be12212d294214e5293a245 Mon Sep 17 00:00:00 2001 From: Clive Galway Date: Sun, 18 Feb 2018 17:08:04 +0000 Subject: [PATCH 03/30] Grab providers from dependencies --- UCR/UCR.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index 1768a43e..ae61ffbf 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -254,4 +254,8 @@ + + if exist "$(SolutionDir)dependencies\Providers" xcopy /Y /S /i "$(SolutionDir)dependencies\Providers" "$(TargetDir)Providers" + + \ No newline at end of file From 6faf5b267d95f6be6db71c788630abe3c62c0462 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Wed, 28 Feb 2018 21:35:11 +0100 Subject: [PATCH 04/30] Preparing nuke deployment --- .nuke | Bin 0 -> 24 bytes UCR.Core/Properties/AssemblyInfo.cs | 8 +- UCR.Core/UCR.Core.csproj | 2 +- UCR.Plugins/Properties/AssemblyInfo.cs | 8 +- UCR.Tests/Properties/AssemblyInfo.cs | 8 +- UCR/Properties/AssemblyInfo.cs | 8 +- build.cmd | 2 + build.ps1 | 248 ++++--------------------- build.sh | 50 +++++ build_cake.ps1 | 234 +++++++++++++++++++++++ 10 files changed, 336 insertions(+), 232 deletions(-) create mode 100644 .nuke create mode 100644 build.cmd create mode 100644 build.sh create mode 100644 build_cake.ps1 diff --git a/.nuke b/.nuke new file mode 100644 index 0000000000000000000000000000000000000000..a12280b71bb74ee8a48af4269a086f83560ec38c GIT binary patch literal 24 fcmezWPme*LA(X+HA&5bbp_n0uA&-HVfr|kEQThbe literal 0 HcmV?d00001 diff --git a/UCR.Core/Properties/AssemblyInfo.cs b/UCR.Core/Properties/AssemblyInfo.cs index 3752d3d6..6d5ec423 100644 --- a/UCR.Core/Properties/AssemblyInfo.cs +++ b/UCR.Core/Properties/AssemblyInfo.cs @@ -31,11 +31,11 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] +// [assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyFileVersion("0.2.1.0")] // Make internal visible for tests [assembly: InternalsVisibleTo("UCR")] [assembly: InternalsVisibleTo("UCR.Tests")] -[assembly: AssemblyInformationalVersion("0.1.0+92.Branch.master.Sha.243cf89d1765596e93767c63363e9548ab86fdc2")] +[assembly: AssemblyInformationalVersion("0.2.1-Restructure.1+3.Branch.Restructure.Sha.88ebad1368a193b56f94c186d418205b2069510e")] diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 4134c215..36d39f40 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -35,7 +35,7 @@ ..\dependencies\IOWrapper\IOWrapper.DTOs.dll - + ..\packages\Mono.Options.5.3.0.1\lib\net4-client\Mono.Options.dll True diff --git a/UCR.Plugins/Properties/AssemblyInfo.cs b/UCR.Plugins/Properties/AssemblyInfo.cs index 21c2798b..a6ad8d64 100644 --- a/UCR.Plugins/Properties/AssemblyInfo.cs +++ b/UCR.Plugins/Properties/AssemblyInfo.cs @@ -31,8 +31,8 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] +// [assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyFileVersion("0.2.1.0")] -[assembly: AssemblyInformationalVersion("0.1.0+92.Branch.master.Sha.243cf89d1765596e93767c63363e9548ab86fdc2")] +[assembly: AssemblyInformationalVersion("0.2.1-Restructure.1+3.Branch.Restructure.Sha.88ebad1368a193b56f94c186d418205b2069510e")] diff --git a/UCR.Tests/Properties/AssemblyInfo.cs b/UCR.Tests/Properties/AssemblyInfo.cs index 72ccd8d0..d2f17773 100644 --- a/UCR.Tests/Properties/AssemblyInfo.cs +++ b/UCR.Tests/Properties/AssemblyInfo.cs @@ -31,8 +31,8 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] +// [assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyFileVersion("0.2.1.0")] -[assembly: AssemblyInformationalVersion("0.1.0+92.Branch.master.Sha.243cf89d1765596e93767c63363e9548ab86fdc2")] +[assembly: AssemblyInformationalVersion("0.2.1-Restructure.1+3.Branch.Restructure.Sha.88ebad1368a193b56f94c186d418205b2069510e")] diff --git a/UCR/Properties/AssemblyInfo.cs b/UCR/Properties/AssemblyInfo.cs index ace0739b..2b3af1b5 100644 --- a/UCR/Properties/AssemblyInfo.cs +++ b/UCR/Properties/AssemblyInfo.cs @@ -50,7 +50,7 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] -[assembly: AssemblyInformationalVersion("0.1.0+92.Branch.master.Sha.243cf89d1765596e93767c63363e9548ab86fdc2")] +// [assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.1.0")] +[assembly: AssemblyFileVersion("0.2.1.0")] +[assembly: AssemblyInformationalVersion("0.2.1-Restructure.1+3.Branch.Restructure.Sha.88ebad1368a193b56f94c186d418205b2069510e")] diff --git a/build.cmd b/build.cmd new file mode 100644 index 00000000..be343cfb --- /dev/null +++ b/build.cmd @@ -0,0 +1,2 @@ +@echo off +powershell %0\..\build.ps1 %* \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 265bd123..0aba4850 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,234 +1,52 @@ -########################################################################## -# This is the Cake bootstrapper script for PowerShell. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -<# - -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. - -.DESCRIPTION -This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) -and execute your Cake build script with the parameters you provide. - -.PARAMETER Script -The build script to execute. -.PARAMETER Target -The build script target to run. -.PARAMETER Configuration -The build configuration to use. -.PARAMETER Verbosity -Specifies the amount of information to be displayed. -.PARAMETER ShowDescription -Shows description about tasks. -.PARAMETER DryRun -Performs a dry run. -.PARAMETER Experimental -Uses the nightly builds of the Roslyn script engine. -.PARAMETER Mono -Uses the Mono Compiler rather than the Roslyn script engine. -.PARAMETER SkipToolPackageRestore -Skips restoring of packages. -.PARAMETER ScriptArgs -Remaining arguments are added here. - -.LINK -https://cakebuild.net - -#> - [CmdletBinding()] Param( - [string]$Script = "build.cake", - [string]$Target, - [string]$Configuration, - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity, - [switch]$ShowDescription, - [Alias("WhatIf", "Noop")] - [switch]$DryRun, - [switch]$Experimental, - [switch]$Mono, - [switch]$SkipToolPackageRestore, + [switch]$NoInit, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs + [string[]]$BuildArguments ) -[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) -{ - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) - { - return $null - } - - [System.IO.Stream] $file = $null; - [System.Security.Cryptography.MD5] $md5 = $null; - try - { - $md5 = [System.Security.Cryptography.MD5]::Create() - $file = [System.IO.File]::OpenRead($filePath) - return [System.BitConverter]::ToString($md5.ComputeHash($file)) - } - finally - { - if ($file -ne $null) - { - $file.Dispose() - } - } -} - -function GetProxyEnabledWebClient -{ - $wc = New-Object System.Net.WebClient - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $wc.Proxy = $proxy - return $wc -} - -Write-Host "Preparing to run build script..." - -if(!$PSScriptRoot){ - $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -} - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" -$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" -$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" -$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null -} - -# Make sure that packages.config exist. -if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { - Throw "Could not download packages.config." - } -} +Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { $host.SetShouldExit(1) } +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -# Try find NuGet.exe in path if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { - Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." - $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName - } -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Downloading NuGet.exe..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } catch { - Throw "Could not download NuGet.exe." - } -} +########################################################################### +# CONFIGURATION +########################################################################### -# Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE +$NuGetVersion = "latest" +$SolutionDirectory = "$PSScriptRoot\..\UCR" +$BuildProjectFile = "$PSScriptRoot\.\build\.build.csproj" +$BuildExeFile = "$PSScriptRoot\.\build\bin\debug\.build.exe" -# Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { - Push-Location - Set-Location $TOOLS_DIR +$TempDirectory = "$PSScriptRoot\.tmp" - # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) - if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed package.config hash..." - Remove-Item * -Recurse -Exclude packages.config,nuget.exe - } +$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/$NuGetVersion/nuget.exe" +$NuGetFile = "$TempDirectory\nuget.exe" +$env:NUGET_EXE = $NuGetFile - Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" +########################################################################### +# PREPARE BUILD +########################################################################### - if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NuGet tools." - } - else - { - $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location +function ExecSafe([scriptblock] $cmd) { + & $cmd + if ($LastExitCode -ne 0) { throw "The following call failed with exit code $LastExitCode. '$cmd'" } } -# Restore addins from NuGet -if (Test-Path $ADDINS_PACKAGES_CONFIG) { - Push-Location - Set-Location $ADDINS_DIR - - Write-Verbose -Message "Restoring addins from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" +if (!$NoInit) { + md -force $TempDirectory > $null - if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NuGet addins." - } + if (!(Test-Path $NuGetFile)) { (New-Object System.Net.WebClient).DownloadFile($NuGetUrl, $NuGetFile) } + elseif ($NuGetVersion -eq "latest") { & $NuGetFile update -Self } - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location + ExecSafe { & $NuGetFile restore $BuildProjectFile -SolutionDirectory $SolutionDirectory } + ExecSafe { & $NuGetFile install Nuke.MSBuildLocator -ExcludeVersion -OutputDirectory $TempDirectory -SolutionDirectory $SolutionDirectory } } -# Restore modules from NuGet -if (Test-Path $MODULES_PACKAGES_CONFIG) { - Push-Location - Set-Location $MODULES_DIR - - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NuGet modules." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} - - +$MSBuildFile = & "$TempDirectory\Nuke.MSBuildLocator\tools\Nuke.MSBuildLocator.exe" +ExecSafe { & $MSBuildFile $BuildProjectFile } -# Build Cake arguments -$cakeArguments = @("$Script"); -if ($Target) { $cakeArguments += "-target=$Target" } -if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } -if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } -if ($ShowDescription) { $cakeArguments += "-showdescription" } -if ($DryRun) { $cakeArguments += "-dryrun" } -if ($Experimental) { $cakeArguments += "-experimental" } -if ($Mono) { $cakeArguments += "-mono" } -$cakeArguments += $ScriptArgs +########################################################################### +# EXECUTE BUILD +########################################################################### -# Start Cake -Write-Host "Running build script..." -&$CAKE_EXE $cakeArguments -exit $LASTEXITCODE +ExecSafe { & $BuildExeFile $BuildArguments } diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..659e9b09 --- /dev/null +++ b/build.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +NOINIT=0 +BUILD_ARGUMENTS=() +for i in "$@"; do + case $(echo $1 | awk '{print tolower($0)}') in + -noinit) NOINIT=1;; + *) BUILD_ARGUMENTS+=("$1") ;; + esac + shift +done + +set -eo pipefail +SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) + +########################################################################### +# CONFIGURATION +########################################################################### + +NUGET_VERSION="latest" +SOLUTION_DIRECTORY="$SCRIPT_DIR/../UCR" +BUILD_PROJECT_FILE="$SCRIPT_DIR/./build/.build.csproj" +BUILD_EXE_FILE="$SCRIPT_DIR/./build/bin/Debug/.build.exe" + +TEMP_DIRECTORY="$SCRIPT_DIR/.tmp" + +NUGET_URL="https://dist.nuget.org/win-x86-commandline/$NUGET_VERSION/nuget.exe" +NUGET_FILE="$TEMP_DIRECTORY/nuget.exe" +export NUGET_EXE="$NUGET_FILE" + +########################################################################### +# PREPARE BUILD +########################################################################### + +if ! ((NOINIT)); then + mkdir -p "$TEMP_DIRECTORY" + + if [ ! -f "$NUGET_FILE" ]; then curl -Lsfo "$NUGET_FILE" $NUGET_URL; + elif [ $NUGET_VERSION == "latest" ]; then mono "$NUGET_FILE" update -Self; fi + + mono "$NUGET_FILE" restore "$BUILD_PROJECT_FILE" -SolutionDirectory $SOLUTION_DIRECTORY +fi + +msbuild "$BUILD_PROJECT_FILE" + +########################################################################### +# EXECUTE BUILD +########################################################################### + +mono "$BUILD_EXE_FILE" ${BUILD_ARGUMENTS[@]} diff --git a/build_cake.ps1 b/build_cake.ps1 new file mode 100644 index 00000000..265bd123 --- /dev/null +++ b/build_cake.ps1 @@ -0,0 +1,234 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER ShowDescription +Shows description about tasks. +.PARAMETER DryRun +Performs a dry run. +.PARAMETER Experimental +Uses the nightly builds of the Roslyn script engine. +.PARAMETER Mono +Uses the Mono Compiler rather than the Roslyn script engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +https://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target, + [string]$Configuration, + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity, + [switch]$ShowDescription, + [Alias("WhatIf", "Noop")] + [switch]$DryRun, + [switch]$Experimental, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null +function MD5HashFile([string] $filePath) +{ + if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) + { + return $null + } + + [System.IO.Stream] $file = $null; + [System.Security.Cryptography.MD5] $md5 = $null; + try + { + $md5 = [System.Security.Cryptography.MD5]::Create() + $file = [System.IO.File]::OpenRead($filePath) + return [System.BitConverter]::ToString($md5.ComputeHash($file)) + } + finally + { + if ($file -ne $null) + { + $file.Dispose() + } + } +} + +function GetProxyEnabledWebClient +{ + $wc = New-Object System.Net.WebClient + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials + $wc.Proxy = $proxy + return $wc +} + +Write-Host "Preparing to run build script..." + +if(!$PSScriptRoot){ + $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" +$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" +$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" +$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" +$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { + $wc = GetProxyEnabledWebClient + $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + $wc = GetProxyEnabledWebClient + $wc.DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + + # Check for changes in packages.config and remove installed tools if true. + [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) + if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or + ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { + Write-Verbose -Message "Missing or changed package.config hash..." + Remove-Item * -Recurse -Exclude packages.config,nuget.exe + } + + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + else + { + $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" + } + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Restore addins from NuGet +if (Test-Path $ADDINS_PACKAGES_CONFIG) { + Push-Location + Set-Location $ADDINS_DIR + + Write-Verbose -Message "Restoring addins from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet addins." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Restore modules from NuGet +if (Test-Path $MODULES_PACKAGES_CONFIG) { + Push-Location + Set-Location $MODULES_DIR + + Write-Verbose -Message "Restoring modules from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" + + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet modules." + } + + Write-Verbose -Message ($NuGetOutput | out-string) + + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + + + +# Build Cake arguments +$cakeArguments = @("$Script"); +if ($Target) { $cakeArguments += "-target=$Target" } +if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } +if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } +if ($ShowDescription) { $cakeArguments += "-showdescription" } +if ($DryRun) { $cakeArguments += "-dryrun" } +if ($Experimental) { $cakeArguments += "-experimental" } +if ($Mono) { $cakeArguments += "-mono" } +$cakeArguments += $ScriptArgs + +# Start Cake +Write-Host "Running build script..." +&$CAKE_EXE $cakeArguments +exit $LASTEXITCODE From b27e34578aea142cf142ae2c472825095c4d8da9 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Wed, 28 Feb 2018 22:34:21 +0100 Subject: [PATCH 05/30] IOWrapper added as submodule --- .gitmodules | 3 +++ submodules/IOWrapper | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 submodules/IOWrapper diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..2c16fedb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/IOWrapper"] + path = submodules/IOWrapper + url = https://github.com/evilC/IOWrapper.git diff --git a/submodules/IOWrapper b/submodules/IOWrapper new file mode 160000 index 00000000..b7533f27 --- /dev/null +++ b/submodules/IOWrapper @@ -0,0 +1 @@ +Subproject commit b7533f275da5d55549594fd4009cdc2052734997 From 4553fe1b026d7637ca63b6e75cdcbb51c48264b7 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Wed, 28 Feb 2018 23:42:23 +0100 Subject: [PATCH 06/30] IOWrapper is now part of the UCR msbuild --- UCR.Core/UCR.Core.csproj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 36d39f40..d299b3d9 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -35,7 +35,7 @@ ..\dependencies\IOWrapper\IOWrapper.DTOs.dll - + ..\packages\Mono.Options.5.3.0.1\lib\net4-client\Mono.Options.dll True @@ -85,6 +85,13 @@ + + "$(MSBuildBinPath)\msbuild.exe" /t:restore $(SolutionDir)\submodules\IOWrapper\IOWrapper.sln +"$(MSBuildBinPath)\msbuild.exe" $(SolutionDir)\submodules\IOWrapper\IOWrapper.sln + + + xcopy /Y /S "$(SolutionDir)\submodules\IOWrapper\Artifacts" "$(SolutionDir)\dependencies" + + * + False + + + + + + + + + + + + + + + + + + diff --git a/build/.build.csproj.DotSettings b/build/.build.csproj.DotSettings new file mode 100644 index 00000000..5af2bdc9 --- /dev/null +++ b/build/.build.csproj.DotSettings @@ -0,0 +1,23 @@ + + False + Implicit + Implicit + ExpressionBody + 0 + NEXT_LINE + True + False + 120 + IF_OWNER_IS_SINGLE_LINE + WRAP_IF_LONG + False + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + True + True + True + True + True + True diff --git a/build/Build.cs b/build/Build.cs new file mode 100644 index 00000000..366b3e3a --- /dev/null +++ b/build/Build.cs @@ -0,0 +1,99 @@ +using System; +using System.Linq; +using Nuke.Common; +using Nuke.Common.Git; +using Nuke.Common.Gitter; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.GitVersion; +using Nuke.Common.Tools.MSBuild; +using Nuke.Common.Tools.NuGet; +using Nuke.Core; +using Nuke.Core.Tooling; +using static Nuke.Common.Tools.Git.GitTasks; +using static Nuke.Common.Tools.MSBuild.MSBuildTasks; +using static Nuke.Core.IO.FileSystemTasks; +using static Nuke.Core.IO.PathConstruction; +using static Nuke.Core.EnvironmentInfo; + +class Build : NukeBuild +{ + // Console application entry. Also defines the default target. + public static int Main() => Execute(x => x.Compile); + + // Auto-injection fields: + + // [GitVersion] readonly GitVersion GitVersion; + // Semantic versioning. Must have 'GitVersion.CommandLine' referenced. + + // [GitRepository] readonly GitRepository GitRepository; + // Parses origin, branch name and head from git config. + + // [Parameter] readonly string MyGetApiKey; + // Returns command-line arguments and environment variables. + + string IoWrapper => "IOWrapper"; + AbsolutePath IoWrapperDirectory => RootDirectory / "submodules" / IoWrapper; + AbsolutePath IoWrapperSolution => IoWrapperDirectory / (IoWrapper + ".sln"); + + MSBuildSettings DefaultIoWrapperMSBuild => DefaultMSBuild + .SetWorkingDirectory(IoWrapperDirectory) + .SetSolutionFile(IoWrapperSolution); + + + Target Clean => _ => _ + .OnlyWhen(() => false) // Disabled for safety. + .Executes(() => + { + DeleteDirectories(GlobDirectories(SourceDirectory, "**/bin", "**/obj")); + EnsureCleanDirectory(OutputDirectory); + }); + + Target RestoreSubmodules => _ => _ + .Executes(() => + { + Git("submodule init"); + Git("submodule update"); + MSBuild(s => DefaultIoWrapperMSBuild + .SetTargets("Restore") + ); + NuGetTasks.NuGetRestore(s => s.SetTargetPath(IoWrapperSolution)); + }); + + Target CompileSubmodules => _ => _ + .DependsOn(RestoreSubmodules) + .Executes(() => + { + MSBuild(s => DefaultIoWrapperMSBuild + .SetTargets("Rebuild") + ); + }); + + Target InitProject => _ => _ + .DependsOn(RestoreSubmodules) + .DependsOn(CompileSubmodules) + .Executes(() => + { + CopyRecursively(IoWrapperDirectory / "Artifacts", SolutionDirectory / "dependencies", FileExistsPolicy.Overwrite); + }); + + Target Restore => _ => _ + .DependsOn(Clean) + .Executes(() => + { + MSBuild(s => DefaultMSBuildRestore); + }); + + Target Compile => _ => _ + .DependsOn(Restore) + .Executes(() => + { + MSBuild(s => DefaultMSBuildCompile); + }); + + Target Test => _ => _ + .DependsOn(Compile) + .Executes(() => + { + MSBuild(s => DefaultMSBuildCompile); + }); +} From 181d679d4a80c1b2eaa32272a04d279a5d2aca53 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Thu, 15 Mar 2018 23:38:50 +0100 Subject: [PATCH 09/30] Refactored Core to new architecture --- UCR.Core/Managers/SubscriptionsManager.cs | 9 +- UCR.Core/Models/Binding/DeviceBinding.cs | 14 +-- UCR.Core/Models/Mapping/Mapping.cs | 54 ++++++++++ UCR.Core/Models/Plugin/Plugin.cs | 92 ++++------------- UCR.Core/Models/Plugin/PluginGroup.cs | 49 ---------- UCR.Core/Models/Profile/Profile.cs | 96 ++++++++++-------- .../Subscription/DeviceBindingSubscription.cs | 4 +- .../Models/Subscription/SubscriptionState.cs | 32 +++--- UCR.Core/UCR.Core.csproj | 2 +- UCR.Plugins/AxisToAxis/AxisToAxis.cs | 2 - UCR.Plugins/AxisToButton/AxisToButton.cs | 3 - UCR.Plugins/ButtonToAxis/ButtonToAxis.cs | 10 +- UCR.Plugins/ButtonToButton/ButtonToButton.cs | 15 +-- UCR.Plugins/JoystickGroup/JoystickGroup.cs | 98 ------------------- UCR.Plugins/JoystickGroup/Resources.cs | 14 --- UCR.Plugins/JoystickGroup/Resources.xaml | 19 ---- UCR.Plugins/UCR.Plugins.csproj | 6 -- UCR.Tests/ModelTests/PersistenceTests.cs | 53 +++++----- UCR.Tests/ModelTests/ProfileTests.cs | 18 ++-- UCR/UCR.csproj | 7 -- UCR/Utilities/DummyGroup.cs | 12 --- .../Controls/DeviceBindingControl.xaml.cs | 6 +- UCR/Views/Controls/PluginGroupView.cs | 54 ---------- UCR/Views/Controls/PluginGroupView.xaml | 44 --------- .../PluginGroupViewTemplateSelector.cs | 24 ----- .../Controls/PluginViewTemplateSelector.cs | 1 - UCR/Views/Profile/ProfileWindow.xaml.cs | 6 +- 27 files changed, 206 insertions(+), 538 deletions(-) create mode 100644 UCR.Core/Models/Mapping/Mapping.cs delete mode 100644 UCR.Core/Models/Plugin/PluginGroup.cs delete mode 100644 UCR.Plugins/JoystickGroup/JoystickGroup.cs delete mode 100644 UCR.Plugins/JoystickGroup/Resources.cs delete mode 100644 UCR.Plugins/JoystickGroup/Resources.xaml delete mode 100644 UCR/Utilities/DummyGroup.cs delete mode 100644 UCR/Views/Controls/PluginGroupView.cs delete mode 100644 UCR/Views/Controls/PluginGroupView.xaml delete mode 100644 UCR/Views/Controls/PluginGroupViewTemplateSelector.cs diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index ab45cf60..2dafb3e9 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -118,10 +118,11 @@ private bool PopulateSubscriptionStateForProfile(SubscriptionState state, Profil state.AddOutputDevice(device, profile); } - foreach (var profilePlugin in profile.Plugins) - { - state.AddDeviceBindingSubscriptions(profilePlugin); - } + // TODO + //foreach (var profilePlugin in profile.Plugins) + //{ + // state.AddDeviceBindingSubscriptions(profilePlugin); + //} state.BuildActivePluginsList(); diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index 35696fd7..6bf9b27b 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -28,7 +28,7 @@ public class DeviceBinding [XmlIgnore] public Guid Guid { get; } [XmlIgnore] - public Models.Plugin.Plugin Plugin { get; set; } + public Profile.Profile Profile { get; set; } [XmlIgnore] public DeviceIoType DeviceIoType { get; set; } [XmlIgnore] @@ -46,10 +46,10 @@ private DeviceBinding() Guid = Guid.NewGuid(); } - public DeviceBinding(ValueChanged callback, Plugin.Plugin plugin, DeviceIoType deviceIoType) + public DeviceBinding(ValueChanged callback, Profile.Profile profile, DeviceIoType deviceIoType) { Callback = callback; - Plugin = plugin; + Profile = profile; DeviceIoType = deviceIoType; Guid = Guid.NewGuid(); IsBound = false; @@ -60,7 +60,7 @@ public DeviceBinding(DeviceBinding deviceBinding) DeviceNumber = deviceBinding.DeviceNumber; KeyType = deviceBinding.KeyType; KeyValue = deviceBinding.KeyValue; - Plugin = deviceBinding.Plugin; + Profile = deviceBinding.Profile; Callback = deviceBinding.Callback; Guid = deviceBinding.Guid; IsBound = deviceBinding.IsBound; @@ -69,7 +69,7 @@ public DeviceBinding(DeviceBinding deviceBinding) public void SetDeviceNumber(int number) { DeviceNumber = number; - Plugin.ParentProfile.context.ContextChanged(); + Profile.Context.ContextChanged(); } public void SetKeyTypeValue(int type, int value, int subValue) @@ -78,12 +78,12 @@ public void SetKeyTypeValue(int type, int value, int subValue) KeyValue = value; KeySubValue = subValue; IsBound = true; - Plugin.ParentProfile.context.ContextChanged(); + Profile.Context.ContextChanged(); } public string BoundName() { - return Plugin.GetDevice(this)?.GetBindingName(this) ?? "Device unavailable"; + return Profile.GetDevice(this)?.GetBindingName(this) ?? "Device unavailable"; } public static DeviceBindingCategory MapCategory(BindingCategory bindingInfoCategory) diff --git a/UCR.Core/Models/Mapping/Mapping.cs b/UCR.Core/Models/Mapping/Mapping.cs new file mode 100644 index 00000000..8ef4909b --- /dev/null +++ b/UCR.Core/Models/Mapping/Mapping.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.Core.Models.Device; + +namespace HidWizards.UCR.Core.Models.Mapping +{ + public class Mapping + { + public String Title { get; set; } + public Guid Guid { get; set; } + public List DeviceBindings { get; set; } + public List Plugins { get; set; } + + internal Profile.Profile Profile { get; set; } + + public Mapping() + { + Guid = Guid.NewGuid(); + DeviceBindings = new List(); + Plugins = new List(); + } + + public Mapping(string title) : this() + { + Title = title; + } + + // TODO Add Guid to distinguish devicebindings + internal void Update(long value) + { + + } + + internal void PostLoad(Context context, Profile.Profile profile = null) + { + Profile = profile; + + foreach (var plugin in Plugins) + { + plugin.PostLoad(context, profile); + } + } + + internal void InitializeMappings(int amount) + { + DeviceBindings = new List(); + for (var i = 0; i < amount; i++) + { + DeviceBindings.Add(new DeviceBinding(Update, Profile, DeviceIoType.Input)); + } + } + } +} diff --git a/UCR.Core/Models/Plugin/Plugin.cs b/UCR.Core/Models/Plugin/Plugin.cs index b5d8f809..c1db30d7 100644 --- a/UCR.Core/Models/Plugin/Plugin.cs +++ b/UCR.Core/Models/Plugin/Plugin.cs @@ -10,26 +10,23 @@ public abstract class Plugin : IComparable { // Persistence public string Title { get; set; } - public List Inputs { get; } - public List Outputs { get; } + public string State { get; set; } + public DeviceBinding Output { get; } // Runtime - internal Profile.Profile ParentProfile { get; set; } - internal List ContainingList { get; set; } + internal Profile.Profile Profile { get; set; } // Abstract public abstract string PluginName(); protected Plugin() { - Inputs = new List(); - Outputs = new List(); + Output = new DeviceBinding(null, Profile, DeviceIoType.Output); } public bool Remove() { - ContainingList.Remove(this); - ParentProfile.context.ContextChanged(); + Profile.Context.ContextChanged(); return true; } @@ -43,99 +40,48 @@ public virtual void OnDeactivate() } - public Device.Device GetDevice(DeviceBinding deviceBinding) - { - return ParentProfile.GetDevice(deviceBinding); - } - - protected void WriteOutput(DeviceBinding output, long value) - { - output.WriteOutput(value); - } - - public virtual List GetInputs() - { - return Inputs; - // TODO Delete? - return Inputs.Select(input => new DeviceBinding(input)).ToList(); - } - - protected DeviceBinding InitializeInputMapping(DeviceBinding.ValueChanged callbackFunc) + public virtual long Update(List values) { - return InitializeMapping(DeviceIoType.Input, callbackFunc); + return 0L; } - protected DeviceBinding InitializeOutputMapping() + public Device.Device GetDevice(DeviceBinding deviceBinding) { - return InitializeMapping(DeviceIoType.Output, null); + return Profile.GetDevice(deviceBinding); } - private DeviceBinding InitializeMapping(DeviceIoType deviceIoType, DeviceBinding.ValueChanged callbackFunc) + public List GetDeviceList(DeviceBinding deviceBinding) { - var deviceBinding = new DeviceBinding(callbackFunc, this, deviceIoType); - switch(deviceIoType) - { - case DeviceIoType.Input: - Inputs.Add(deviceBinding); - break; - case DeviceIoType.Output: - Outputs.Add(deviceBinding); - break; - default: - throw new ArgumentOutOfRangeException(nameof(deviceIoType), deviceIoType, null); - } - return deviceBinding; + return Profile.GetDeviceList(deviceBinding); } - public List GetDeviceList(DeviceBinding deviceBinding) + // TODO + protected void WriteOutput(DeviceBinding output, long value) { - return ParentProfile.GetDeviceList(deviceBinding); + output.WriteOutput(value); } - + public void Rename(string title) { Title = title; - ParentProfile.context.ContextChanged(); + Profile.Context.ContextChanged(); } public void PostLoad(Context context, Profile.Profile parentProfile) { - ParentProfile = parentProfile; - ContainingList = parentProfile.Plugins; - - ZipDeviceBindingList(Inputs); - ZipDeviceBindingList(Outputs); + Profile = parentProfile; } public Plugin Duplicate() { var newPlugin = Context.DeepXmlClone(this); - newPlugin.PostLoad(ParentProfile.context, ParentProfile); + newPlugin.PostLoad(Profile.Context, Profile); return newPlugin; } protected void ContextChanged() { - ParentProfile?.context?.ContextChanged(); - } - - private static void ZipDeviceBindingList(IList deviceBindings) - { - if (deviceBindings.Count == 0) return; - var split = deviceBindings.Count / 2; - for (var i = 0; i < split; i++) - { - deviceBindings[i].IsBound = deviceBindings[i + split].IsBound; - deviceBindings[i].DeviceNumber = deviceBindings[i + split].DeviceNumber; - deviceBindings[i].KeyType = deviceBindings[i + split].KeyType; - deviceBindings[i].KeyValue = deviceBindings[i + split].KeyValue; - deviceBindings[i].KeySubValue = deviceBindings[i + split].KeySubValue; - } - - for (var i = deviceBindings.Count - 1; i >= split ; i--) - { - deviceBindings.Remove(deviceBindings[i]); - } + Profile?.Context?.ContextChanged(); } public int CompareTo(Plugin other) diff --git a/UCR.Core/Models/Plugin/PluginGroup.cs b/UCR.Core/Models/Plugin/PluginGroup.cs deleted file mode 100644 index 1aa7e680..00000000 --- a/UCR.Core/Models/Plugin/PluginGroup.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using HidWizards.UCR.Core.Models.Binding; - -namespace HidWizards.UCR.Core.Models.Plugin -{ - public abstract class PluginGroup : Plugin - { - public List Plugins { get; set; } - - public PluginGroup() - { - Plugins = new List(); - } - - public override List GetInputs() - { - List newBindings = Inputs.Select(input => new DeviceBinding(input)).ToList(); - - foreach (var plugin in Plugins) - { - newBindings.AddRange(plugin.GetInputs()); - } - - return newBindings; - } - - public void AddPlugin(Plugin plugin, string title) - { - var newPlugin = (Plugin) Activator.CreateInstance(plugin.GetType()); - newPlugin.ParentProfile = ParentProfile; - newPlugin.Title = title; - newPlugin.ContainingList = Plugins; - Plugins.Add(newPlugin); - ParentProfile.context.ContextChanged(); - } - - internal new void PostLoad(Context context, Profile.Profile parentProfile) - { - (this as Plugin).PostLoad(context, parentProfile); - foreach (var plugin in Plugins) - { - plugin.PostLoad(context, parentProfile); - plugin.ContainingList = Plugins; - } - } - } -} diff --git a/UCR.Core/Models/Profile/Profile.cs b/UCR.Core/Models/Profile/Profile.cs index 9818272e..37260041 100644 --- a/UCR.Core/Models/Profile/Profile.cs +++ b/UCR.Core/Models/Profile/Profile.cs @@ -3,7 +3,6 @@ using System.Xml.Serialization; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Plugin; using NLog; namespace HidWizards.UCR.Core.Models.Profile @@ -16,7 +15,8 @@ public class Profile public string Title { get; set; } public Guid Guid { get; set; } public List ChildProfiles { get; set; } - public List Plugins { get; set; } + public List States { get; set; } + public List Mappings { get; set; } // IO public Guid InputDeviceGroupGuid { get; set; } @@ -25,7 +25,7 @@ public class Profile /* Runtime */ [XmlIgnore] - public Context context; + public Context Context; [XmlIgnore] public Profile ParentProfile { get; set; } @@ -38,17 +38,16 @@ public Profile() public Profile(Context context) { - this.context = context; + this.Context = context; Init(); } private void Init() { - Plugins = Plugins ?? new List(); - ChildProfiles = ChildProfiles ?? new List(); - Plugins = Plugins ?? new List(); - - Guid = Guid == Guid.Empty ? Guid.NewGuid() : Guid; + Guid = Guid.NewGuid(); + ChildProfiles = new List(); + States = new List(); + Mappings = new List(); } public Profile(Context context, Profile parentProfile = null) : this(context) @@ -73,23 +72,23 @@ public static Profile CreateProfile(Context context, string title, Profile paren public void AddNewChildProfile(string title) { if (ChildProfiles == null) ChildProfiles = new List(); - ChildProfiles.Add(CreateProfile(context, title, this)); - context.ContextChanged(); + ChildProfiles.Add(CreateProfile(Context, title, this)); + Context.ContextChanged(); } public void AddChildProfile(Profile profile) { if (ChildProfiles == null) ChildProfiles = new List(); - profile.context = context; + profile.Context = Context; profile.ParentProfile = this; ChildProfiles.Add(profile); - context.ContextChanged(); + Context.ContextChanged(); } public bool Rename(string title) { Title = title; - context.ContextChanged(); + Context.ContextChanged(); return true; } @@ -97,13 +96,13 @@ public void Remove() { if (ParentProfile == null) { - context.Profiles.Remove(this); + Context.Profiles.Remove(this); } else { ParentProfile.ChildProfiles.Remove(this); } - context.ContextChanged(); + Context.ContextChanged(); } public void SetDeviceGroup(DeviceIoType ioType, Guid deviceGroupGuid) @@ -119,17 +118,33 @@ public void SetDeviceGroup(DeviceIoType ioType, Guid deviceGroupGuid) default: throw new ArgumentOutOfRangeException(nameof(ioType), ioType, null); } - context.ContextChanged(); + Context.ContextChanged(); } public bool ActivateProfile() { - return context.SubscriptionsManager.ActivateProfile(this); + return Context.SubscriptionsManager.ActivateProfile(this); } public bool Deactivate() { - return context.SubscriptionsManager.DeactivateProfile(); + return Context.SubscriptionsManager.DeactivateProfile(); + } + + #endregion + + #region Mapping + + public Mapping.Mapping AddMapping(string title) + { + var mapping = new Mapping.Mapping(title); + Mappings.Add(mapping); + return mapping; + } + + public bool RemoveMapping(Mapping.Mapping mapping) + { + return Mappings.Remove(mapping); } #endregion @@ -161,32 +176,35 @@ public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType) { return ParentProfile?.GetDeviceGroup(deviceIoType); } - return context.DeviceGroupsManager.GetDeviceGroup(deviceIoType, deviceGroupGuid); + return Context.DeviceGroupsManager.GetDeviceGroup(deviceIoType, deviceGroupGuid); } #endregion #region Plugin - public void AddNewPlugin(Plugin.Plugin plugin, string title = "Untitled") + public bool AddNewPlugin(Mapping.Mapping mapping, Plugin.Plugin plugin, string title = "Untitled", string state = null) { - AddPlugin((Plugin.Plugin)Activator.CreateInstance(plugin.GetType()), title); + return AddPlugin(mapping, (Plugin.Plugin)Activator.CreateInstance(plugin.GetType()), title, state); } - public void AddPlugin(Plugin.Plugin plugin, string title = "Untitled") + public bool AddPlugin(Mapping.Mapping mapping, Plugin.Plugin plugin, string title = "Untitled", string state = null) { - + if (!Mappings.Contains(mapping)) return false; if (plugin.Title == null) plugin.Title = title; - plugin.ParentProfile = this; - plugin.ContainingList = Plugins; - Plugins.Add(plugin); - context.ContextChanged(); + plugin.State = state; + plugin.Profile = this; + mapping.Plugins.Add(plugin); + Context.ContextChanged(); + return true; } - public void RemovePlugin(Models.Plugin.Plugin plugin) + public bool RemovePlugin(Mapping.Mapping mapping, Models.Plugin.Plugin plugin) { - Plugins.Remove(plugin); - context.ContextChanged(); + if (!Mappings.Contains(mapping)) return false; + mapping.Plugins.Remove(plugin); + Context.ContextChanged(); + return true; } #endregion @@ -204,7 +222,7 @@ public string ProfileBreadCrumbs() /// public bool IsActive() { - return context.SubscriptionsManager.GetActiveProfile() != null && context.SubscriptionsManager.GetActiveProfile().Guid == Guid; + return Context.SubscriptionsManager.GetActiveProfile() != null && Context.SubscriptionsManager.GetActiveProfile().Guid == Guid; } private Guid GetDeviceGroupGuid(DeviceIoType deviceIoType) @@ -232,7 +250,7 @@ public List GetAncestry() internal void PostLoad(Context context, Profile parentProfile = null) { - this.context = context; + Context = context; ParentProfile = parentProfile; foreach (var profile in ChildProfiles) @@ -240,17 +258,9 @@ internal void PostLoad(Context context, Profile parentProfile = null) profile.PostLoad(context, this); } - foreach (var plugin in Plugins) + foreach (var mapping in Mappings) { - var group = plugin as PluginGroup; - if (group != null) - { - group.PostLoad(context, this); - } - else - { - plugin.PostLoad(context, this); - } + mapping.PostLoad(context, this); } } } diff --git a/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs b/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs index d593e4de..17e24f70 100644 --- a/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs +++ b/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs @@ -30,7 +30,7 @@ public DeviceBindingSubscription(DeviceBinding deviceBinding, Profile.Profile pr public static List GetSubscriptionsFromList(List deviceBindings, Guid subscriptionStateGuid, List deviceSubscriptions) { - return deviceBindings.Select(deviceBinding => new DeviceBindingSubscription(deviceBinding, deviceBinding.Plugin.ParentProfile, subscriptionStateGuid, deviceSubscriptions)).ToList(); + return deviceBindings.Select(deviceBinding => new DeviceBindingSubscription(deviceBinding, deviceBinding.Profile, subscriptionStateGuid, deviceSubscriptions)).ToList(); } private Device.Device GetDevice() @@ -41,7 +41,7 @@ private Device.Device GetDevice() public void WriteOutput(long value) { // TODO get context properly - var success = Profile.context.IOController.SetOutputstate(SubscriptionsManager.GetOutputSubscriptionRequest(SubscriptionStateGuid, DeviceSubscription), SubscriptionsManager.GetBindingDescriptor(DeviceBinding), (int)value); + var success = Profile.Context.IOController.SetOutputstate(SubscriptionsManager.GetOutputSubscriptionRequest(SubscriptionStateGuid, DeviceSubscription), SubscriptionsManager.GetBindingDescriptor(DeviceBinding), (int)value); var a = 1; } } diff --git a/UCR.Core/Models/Subscription/SubscriptionState.cs b/UCR.Core/Models/Subscription/SubscriptionState.cs index 7d48ff29..f0a9b6cc 100644 --- a/UCR.Core/Models/Subscription/SubscriptionState.cs +++ b/UCR.Core/Models/Subscription/SubscriptionState.cs @@ -38,29 +38,31 @@ public void AddDeviceBindingSubscriptions(Plugin.Plugin plugin) AddDeviceBindingSubscriptions(plugin, DeviceIoType.Output); } + // TODO private void AddDeviceBindingSubscriptions(Plugin.Plugin plugin, DeviceIoType deviceIoType) { - var deviceBindings = deviceIoType == DeviceIoType.Input ? plugin.GetInputs() : plugin.Outputs; - var deviceBindingsList = deviceIoType == DeviceIoType.Input ? DeviceBindingSubscriptions : OutputDeviceBindingSubscriptions; - if (deviceBindingsList.ContainsKey(plugin.Title)) - { - foreach (var deviceBindingSubscription in deviceBindingsList[plugin.Title]) - { - deviceBindingSubscription.IsOverwritten = true; - } - deviceBindingsList[plugin.Title].AddRange(DeviceBindingSubscription.GetSubscriptionsFromList(deviceBindings, StateGuid, DeviceSubscriptions)); - } - else - { - deviceBindingsList[plugin.Title] = DeviceBindingSubscription.GetSubscriptionsFromList(deviceBindings, StateGuid, DeviceSubscriptions); - } + //var deviceBindings = deviceIoType == DeviceIoType.Input ? plugin.GetInputs() : plugin.Outputs; + //var deviceBindingsList = deviceIoType == DeviceIoType.Input ? DeviceBindingSubscriptions : OutputDeviceBindingSubscriptions; + //if (deviceBindingsList.ContainsKey(plugin.Title)) + //{ + // foreach (var deviceBindingSubscription in deviceBindingsList[plugin.Title]) + // { + // deviceBindingSubscription.IsOverwritten = true; + // } + // deviceBindingsList[plugin.Title].AddRange(DeviceBindingSubscription.GetSubscriptionsFromList(deviceBindings, StateGuid, DeviceSubscriptions)); + //} + //else + //{ + // deviceBindingsList[plugin.Title] = DeviceBindingSubscription.GetSubscriptionsFromList(deviceBindings, StateGuid, DeviceSubscriptions); + //} } public void BuildActivePluginsList() { foreach (var subscription in DeviceBindingSubscriptions) { - ActivePlugins.Add(subscription.Value.First(d => d.IsOverwritten == false).DeviceBinding.Plugin); + // TODO + //ActivePlugins.Add(subscription.Value.First(d => d.IsOverwritten == false).DeviceBinding.Plugin); } } } diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index eee27a7f..04ff3f9d 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -66,8 +66,8 @@ + - diff --git a/UCR.Plugins/AxisToAxis/AxisToAxis.cs b/UCR.Plugins/AxisToAxis/AxisToAxis.cs index 059c9c38..a875e8ce 100644 --- a/UCR.Plugins/AxisToAxis/AxisToAxis.cs +++ b/UCR.Plugins/AxisToAxis/AxisToAxis.cs @@ -46,8 +46,6 @@ public string Sensitivity public AxisToAxis() { - InputAxis = InitializeInputMapping(InputChanged); - OutputAxis = InitializeOutputMapping(); DeadZone = "0"; Sensitivity = "100"; } diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index 202733b3..aeba7193 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -41,9 +41,6 @@ public override string PluginName() public AxisToButton() { - Input = InitializeInputMapping(InputChanged); - OutputLow = InitializeOutputMapping(); - OutputHigh = InitializeOutputMapping(); DeadZone = "30"; } diff --git a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs index 57f24362..e8167dd4 100644 --- a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs +++ b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs @@ -10,12 +10,6 @@ namespace HidWizards.UCR.Plugins.ButtonToAxis [Export(typeof(Plugin))] public class ButtonToAxis : Plugin { - [XmlIgnore] - public DeviceBinding InputHigh { get; set; } - [XmlIgnore] - public DeviceBinding InputLow { get; set; } - [XmlIgnore] - public DeviceBinding Output { get; set; } private long _direction = 0; @@ -26,9 +20,7 @@ public override string PluginName() public ButtonToAxis() { - InputLow = InitializeInputMapping(InputLowChanged); - InputHigh = InitializeInputMapping(InputHighChanged); - Output = InitializeOutputMapping(); + } private void InputLowChanged(long value) diff --git a/UCR.Plugins/ButtonToButton/ButtonToButton.cs b/UCR.Plugins/ButtonToButton/ButtonToButton.cs index 9a5f6a77..5ae65835 100644 --- a/UCR.Plugins/ButtonToButton/ButtonToButton.cs +++ b/UCR.Plugins/ButtonToButton/ButtonToButton.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.Composition; using System.Xml.Serialization; using HidWizards.UCR.Core.Models.Binding; @@ -9,25 +10,15 @@ namespace HidWizards.UCR.Plugins.ButtonToButton [Export(typeof(Plugin))] public class ButtonToButton : Plugin { - [XmlIgnore] - public DeviceBinding Input { get; set; } - [XmlIgnore] - public DeviceBinding Output { get; set; } public override string PluginName() { return "Button to Button"; } - public ButtonToButton() + public override long Update(List values) { - Input = InitializeInputMapping(InputChanged); - Output = InitializeOutputMapping(); - } - - private void InputChanged(long value) - { - WriteOutput(Output, Math.Max(Math.Min(value, 1),0)); + return values[0]; } } } diff --git a/UCR.Plugins/JoystickGroup/JoystickGroup.cs b/UCR.Plugins/JoystickGroup/JoystickGroup.cs deleted file mode 100644 index ab20506e..00000000 --- a/UCR.Plugins/JoystickGroup/JoystickGroup.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Plugin; - -namespace HidWizards.UCR.Plugins.JoystickGroup -{ - [Export(typeof(Plugin))] - public class JoystickGroup : PluginGroup - { - private List _inputSequenceValues; - private string _inputSequence = "1,2,3,4"; - public string InputSequence - { - get { return _inputSequence; } - set - { - SetIntListValues(_inputSequenceValues, value); - _inputSequence = value; - } - } - - private List _outputSequenceValues; - private string _outputSequence = "1,2,3,4"; - public string OutputSequence - { - get { return _outputSequence; } - set - { - SetIntListValues(_outputSequenceValues, value); - _outputSequence = value; - } - } - - private List TempPlugins; - - public override string PluginName() - { - return "Joystick Group"; - } - - public JoystickGroup() - { - TempPlugins = new List(); - _inputSequenceValues = new List(); - _outputSequenceValues = new List(); - } - - public override void OnActivate() - { - TempPlugins.Clear(); - for (var index = 0; index < Math.Min(_inputSequenceValues.Count, _outputSequenceValues.Count); index++) - { - foreach (var plugin in Plugins) - { - var newPlugin = plugin.Duplicate(); - TempPlugins.Add(newPlugin); - foreach (var input in newPlugin.Inputs) - { - input.Plugin = this; - input.DeviceNumber = _inputSequenceValues[index]; - } - foreach (var input in newPlugin.Outputs) - { - input.Plugin = this; - input.DeviceNumber = _outputSequenceValues[index]; - } - } - - } - } - - public override List GetInputs() - { - var inputs = new List(); - - foreach (var plugin in TempPlugins) - { - inputs.AddRange(plugin.GetInputs()); - } - return inputs; - } - - private void SetIntListValues(List list, string value) - { - list.Clear(); - if (string.IsNullOrEmpty(value)) return; - foreach (var i in value.Split(',')) - { - int val; - if(int.TryParse(i, out val)) list.Add(val - 1); - } - ContextChanged(); - } - - } -} diff --git a/UCR.Plugins/JoystickGroup/Resources.cs b/UCR.Plugins/JoystickGroup/Resources.cs deleted file mode 100644 index b77ad5d3..00000000 --- a/UCR.Plugins/JoystickGroup/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.JoystickGroup -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/JoystickGroup/Resources.xaml b/UCR.Plugins/JoystickGroup/Resources.xaml deleted file mode 100644 index a374d1e1..00000000 --- a/UCR.Plugins/JoystickGroup/Resources.xaml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 3d31eacb..cba1f33f 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -54,8 +54,6 @@ - - @@ -77,10 +75,6 @@ MSBuild:Compile Designer - - MSBuild:Compile - Designer - diff --git a/UCR.Tests/ModelTests/PersistenceTests.cs b/UCR.Tests/ModelTests/PersistenceTests.cs index 1d9cee89..9f726af2 100644 --- a/UCR.Tests/ModelTests/PersistenceTests.cs +++ b/UCR.Tests/ModelTests/PersistenceTests.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Net.Http.Headers; using HidWizards.UCR.Core; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models.Mapping; using HidWizards.UCR.Plugins.ButtonToButton; using HidWizards.UCR.Tests.Factory; using NUnit.Framework; @@ -52,60 +54,57 @@ public void ProfileContext() Assert.That(newcontext.Profiles[0].Title, Is.EqualTo(context.Profiles[0].Title)); Assert.That(newcontext.Profiles[0].Guid, Is.EqualTo(context.Profiles[0].Guid)); - Assert.That(newcontext.Profiles[0].Plugins.Count, Is.EqualTo(context.Profiles[0].Plugins.Count)); + Assert.That(newcontext.Profiles[0].Mappings.Count, Is.EqualTo(context.Profiles[0].Mappings.Count)); Assert.That(newcontext.Profiles[0].ChildProfiles[0].Title, Is.EqualTo(context.Profiles[0].ChildProfiles[0].Title)); Assert.That(newcontext.Profiles[0].ChildProfiles[0].Guid, Is.EqualTo(context.Profiles[0].ChildProfiles[0].Guid)); - Assert.That(newcontext.Profiles[0].ChildProfiles[0].Plugins.Count, Is.EqualTo(context.Profiles[0].ChildProfiles[0].Plugins.Count)); + Assert.That(newcontext.Profiles[0].ChildProfiles[0].Mappings.Count, Is.EqualTo(context.Profiles[0].ChildProfiles[0].Mappings.Count)); newcontext.SaveContext(); } } [Test] - public void PluginContext() + public void MappingContext() { var context = new Context(); var pluginTypes = new List(); pluginTypes.Add(typeof(ButtonToButton)); context.ProfilesManager.AddProfile("Root profile"); - var profile = context.Profiles[0]; - profile.AddPlugin(new ButtonToButton(), "Button to button 1"); - profile.AddPlugin(new ButtonToButton(), "Button to button 2"); + var mapping = profile.AddMapping("Jump"); + profile.AddPlugin(mapping, new ButtonToButton(), "Button to button 1"); + profile.AddPlugin(mapping, new ButtonToButton(), "Button to button 2"); - for (var i = 0; i < profile.Plugins.Count; i++) + var bindingCount = 10; + mapping.InitializeMappings(bindingCount); + for (var i = 0; i < bindingCount; i++) { - SetDeviceBindingValues(profile.Plugins[i].Inputs[0], i + 1); - SetDeviceBindingValues(profile.Plugins[i].Outputs[0], i + 2); + SetDeviceBindingValues(profile.Mappings[0].DeviceBindings[i], i + 1); } - var plugins = profile.Plugins; + var deviceBindings = mapping.DeviceBindings; context.SaveContext(pluginTypes); for (var i = 0; i < _saveReloadTimes; i++) { var newcontext = Context.Load(pluginTypes); - var newProfile = newcontext.Profiles[0]; - Assert.That(newProfile.Plugins.Count, Is.EqualTo(profile.Plugins.Count)); + var newMapping = newcontext.Profiles[0].Mappings[0]; + var newDeviceBindings = newcontext.Profiles[0].Mappings[0].DeviceBindings; + Assert.That(newMapping.Title, Is.EqualTo(mapping.Title)); + Assert.That(newMapping.Plugins.Count, Is.EqualTo(mapping.Plugins.Count)); + Assert.That(newMapping.Guid, Is.EqualTo(mapping.Guid)); - for (var j = 0; j < plugins.Count; j++) + for (var j = 0; j < mapping.DeviceBindings.Count; j++) { - Assert.That(newProfile.Plugins[j].Title, Is.EqualTo(plugins[j].Title)); - Assert.That(newProfile.Plugins[j].Inputs.Count, Is.EqualTo(plugins[j].Inputs.Count)); - Assert.That(newProfile.Plugins[j].Outputs.Count, Is.EqualTo(plugins[j].Outputs.Count)); - Assert.That(newProfile.Plugins[j].Outputs[0].DeviceIoType, Is.EqualTo(DeviceIoType.Output)); - Assert.That(newProfile.Plugins[j].Inputs[0].Guid, Is.Not.EqualTo(plugins[j].Inputs[0].Guid)); - Assert.That(newProfile.Plugins[j].Inputs[0].IsBound, Is.EqualTo(plugins[j].Inputs[0].IsBound)); - Assert.That(newProfile.Plugins[j].Inputs[0].DeviceIoType, Is.EqualTo(DeviceIoType.Input)); - Assert.That(newProfile.Plugins[j].Inputs[0].DeviceNumber, Is.EqualTo(plugins[j].Inputs[0].DeviceNumber)); - Assert.That(newProfile.Plugins[j].Inputs[0].KeyType, Is.EqualTo(plugins[j].Inputs[0].KeyType)); - Assert.That(newProfile.Plugins[j].Inputs[0].KeyValue, Is.EqualTo(plugins[j].Inputs[0].KeyValue)); - Assert.That(newProfile.Plugins[j].Inputs[0].KeySubValue, Is.EqualTo(plugins[j].Inputs[0].KeySubValue)); + Assert.That(newDeviceBindings[j].DeviceIoType, Is.EqualTo(DeviceIoType.Input)); + Assert.That(newDeviceBindings[j].Guid, Is.Not.EqualTo(deviceBindings[j].Guid)); + Assert.That(newDeviceBindings[j].IsBound, Is.EqualTo(deviceBindings[j].IsBound)); + Assert.That(newDeviceBindings[j].DeviceNumber, Is.EqualTo(deviceBindings[j].DeviceNumber)); + Assert.That(newDeviceBindings[j].KeyType, Is.EqualTo(deviceBindings[j].KeyType)); + Assert.That(newDeviceBindings[j].KeyValue, Is.EqualTo(deviceBindings[j].KeyValue)); + Assert.That(newDeviceBindings[j].KeySubValue, Is.EqualTo(deviceBindings[j].KeySubValue)); } - Assert.That(((ButtonToButton)newProfile.Plugins[0]).Input.Guid, Is.EqualTo(newProfile.Plugins[0].Inputs[0].Guid)); - Assert.That(((ButtonToButton)newProfile.Plugins[0]).Output.Guid, Is.EqualTo(newProfile.Plugins[0].Outputs[0].Guid)); - newcontext.SaveContext(pluginTypes); } } diff --git a/UCR.Tests/ModelTests/ProfileTests.cs b/UCR.Tests/ModelTests/ProfileTests.cs index aca70051..95780531 100644 --- a/UCR.Tests/ModelTests/ProfileTests.cs +++ b/UCR.Tests/ModelTests/ProfileTests.cs @@ -3,6 +3,7 @@ using HidWizards.UCR.Core.Managers; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models.Mapping; using HidWizards.UCR.Core.Models.Profile; using HidWizards.UCR.Plugins.ButtonToButton; using HidWizards.UCR.Tests.Factory; @@ -15,6 +16,7 @@ internal class ProfileTests { private Context _context; private Profile _profile; + private Mapping _mapping; private string _profileName; [SetUp] @@ -23,6 +25,7 @@ public void Setup() _context = new Context(); _context.ProfilesManager.AddProfile("Base profile"); _profile = _context.Profiles[0]; + _mapping = _profile.AddMapping("Test mapping"); _profileName = "Test"; } @@ -64,13 +67,14 @@ public void RenameProfile() public void AddPlugin() { var pluginName = "Test plugin"; - _profile.AddPlugin(new ButtonToButton(), pluginName); - var plugin = _profile.Plugins[0]; + var pluginState = "State"; + _profile.AddPlugin(_mapping, new ButtonToButton(), pluginName, pluginState); + var plugin = _mapping.Plugins[0]; Assert.That(plugin, Is.Not.Null); Assert.That(plugin.Title, Is.EqualTo(pluginName)); - Assert.That(plugin.Inputs, Is.Not.Null); - Assert.That(plugin.Outputs, Is.Not.Null); - Assert.That(plugin.ParentProfile, Is.EqualTo(_profile)); + Assert.That(plugin.State, Is.EqualTo(pluginState)); + Assert.That(plugin.Output, Is.Not.Null); + Assert.That(plugin.Profile, Is.EqualTo(_profile)); Assert.That(_context.IsNotSaved, Is.True); } @@ -147,7 +151,7 @@ public void CopyProfile() Assert.That(newProfile.Guid, Is.Not.EqualTo(profile.Guid)); Assert.That(newProfile.Title, Is.EqualTo("Copy")); Assert.That(newProfile.ParentProfile, Is.Null); - Assert.That(newProfile.context, Is.Not.Null); + Assert.That(newProfile.Context, Is.Not.Null); } [Test] @@ -162,7 +166,7 @@ public void CopyChildProfile() Assert.That(newProfile.Guid, Is.Not.EqualTo(profile.Guid)); Assert.That(newProfile.Title, Is.EqualTo("Copy")); Assert.That(newProfile.ParentProfile.Guid, Is.EqualTo(parentProfile.Guid)); - Assert.That(newProfile.context, Is.Not.Null); + Assert.That(newProfile.Context, Is.Not.Null); } [Test] diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index d70d44c0..e432b50c 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -80,7 +80,6 @@ - @@ -102,10 +101,8 @@ PluginView.xaml - - DeviceListWindow.xaml @@ -150,10 +147,6 @@ Designer MSBuild:Compile - - MSBuild:Compile - Designer - Designer MSBuild:Compile diff --git a/UCR/Utilities/DummyGroup.cs b/UCR/Utilities/DummyGroup.cs deleted file mode 100644 index f86d41f5..00000000 --- a/UCR/Utilities/DummyGroup.cs +++ /dev/null @@ -1,12 +0,0 @@ -using HidWizards.UCR.Core.Models.Plugin; - -namespace HidWizards.UCR.Utilities -{ - public class DummyGroup : PluginGroup - { - public override string PluginName() - { - return "Dummy plugin group"; - } - } -} diff --git a/UCR/Views/Controls/DeviceBindingControl.xaml.cs b/UCR/Views/Controls/DeviceBindingControl.xaml.cs index c3ed5416..43ffabf1 100644 --- a/UCR/Views/Controls/DeviceBindingControl.xaml.cs +++ b/UCR/Views/Controls/DeviceBindingControl.xaml.cs @@ -64,7 +64,7 @@ private void LoadBindingName() private void LoadDeviceInputs() { - var devicelist = DeviceBinding.Plugin.GetDeviceList(DeviceBinding); + var devicelist = DeviceBinding.Profile.GetDeviceList(DeviceBinding); Devices = new ObservableCollection(); for(var i = 0; i < Math.Max(devicelist?.Count ?? 0, Constants.MaxDevices); i++) { @@ -108,9 +108,9 @@ private void LoadContextMenu() private void BuildContextMenu() { BindMenu = new ObservableCollection(); - var device = DeviceBinding.Plugin.GetDevice(DeviceBinding); + var device = DeviceBinding.Profile.GetDevice(DeviceBinding); if (device == null) return; - BindMenu = BuildMenu(device.GetDeviceBindingMenu(DeviceBinding.Plugin.ParentProfile.context, DeviceBinding.DeviceIoType)); + BindMenu = BuildMenu(device.GetDeviceBindingMenu(DeviceBinding.Profile.Context, DeviceBinding.DeviceIoType)); } private ObservableCollection BuildMenu(List deviceBindingNodes) diff --git a/UCR/Views/Controls/PluginGroupView.cs b/UCR/Views/Controls/PluginGroupView.cs deleted file mode 100644 index c770d887..00000000 --- a/UCR/Views/Controls/PluginGroupView.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Collections.Generic; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; -using HidWizards.UCR.Core.Models.Plugin; -using HidWizards.UCR.Views.Profile; - -namespace HidWizards.UCR.Views.Controls -{ - public partial class PluginGroupView : ResourceDictionary - { - public PluginGroupView() - { - InitializeComponent(); - - } - - private void AddPluginButton_OnClick(object sender, RoutedEventArgs e) - { - var button = ((Button) sender); - var pluginGroup = button.DataContext as PluginGroup; - if (pluginGroup == null) return; - var win = new PluginDialog(pluginGroup.ParentProfile.context, "Add plugin", "Untitled"); - win.ShowDialog(); - if (!win.DialogResult.HasValue || !win.DialogResult.Value) return; - pluginGroup.AddPlugin(win.Plugin, win.TextResult); - - // TODO: Do a proper refresh of ListBox - foreach (var listbox in FindVisualChildren(((Grid)button.Parent).Parent)) - { - if (listbox.Name != "PluginsListBox") continue; - listbox.Items.Refresh(); - break; - } - } - - private IEnumerable FindVisualChildren(DependencyObject depObj) where T : DependencyObject - { - if (depObj != null) - { - for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) - { - DependencyObject child = VisualTreeHelper.GetChild(depObj, i); - - if (child != null && child is T) - yield return (T)child; - - foreach (T childOfChild in FindVisualChildren(child)) - yield return childOfChild; - } - } - } - } -} \ No newline at end of file diff --git a/UCR/Views/Controls/PluginGroupView.xaml b/UCR/Views/Controls/PluginGroupView.xaml deleted file mode 100644 index 86226aae..00000000 --- a/UCR/Views/Controls/PluginGroupView.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/UCR/Views/Controls/PluginGroupViewTemplateSelector.cs b/UCR/Views/Controls/PluginGroupViewTemplateSelector.cs deleted file mode 100644 index 935960af..00000000 --- a/UCR/Views/Controls/PluginGroupViewTemplateSelector.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Windows; -using System.Windows.Controls; - -namespace HidWizards.UCR.Views.Controls -{ - class PluginGroupViewTemplateSelector : DataTemplateSelector - { - public DataTemplate PluginTemplate { get; set; } - public Window Window { get; set; } - - public PluginGroupViewTemplateSelector() - { - Window = Application.Current.MainWindow; - } - - //You override this function to select your data template based in the given item - public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) - { - if (item == null) return PluginTemplate; - PluginTemplate = (DataTemplate)Window.FindResource(item.GetType().Name); - return PluginTemplate; - } - } -} diff --git a/UCR/Views/Controls/PluginViewTemplateSelector.cs b/UCR/Views/Controls/PluginViewTemplateSelector.cs index d783c028..4923d048 100644 --- a/UCR/Views/Controls/PluginViewTemplateSelector.cs +++ b/UCR/Views/Controls/PluginViewTemplateSelector.cs @@ -18,7 +18,6 @@ public PluginViewTemplateSelector() public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) { if (item == null) return PluginTemplate; - if (item is PluginGroup) return (DataTemplate)Window.FindResource("PluginGroup"); PluginTemplate = (DataTemplate)Window.FindResource(item.GetType().Name); return PluginTemplate; } diff --git a/UCR/Views/Profile/ProfileWindow.xaml.cs b/UCR/Views/Profile/ProfileWindow.xaml.cs index 92a03eab..66a38b53 100644 --- a/UCR/Views/Profile/ProfileWindow.xaml.cs +++ b/UCR/Views/Profile/ProfileWindow.xaml.cs @@ -47,13 +47,14 @@ private void DeactivateProfile(object sender, RoutedEventArgs e) Profile.Deactivate(); } + // TODO Add plugin private void AddPlugin_OnClick(object sender, RoutedEventArgs e) { var win = new PluginDialog(Context, "Add plugin", "Untitled"); win.ShowDialog(); if (!win.DialogResult.HasValue || !win.DialogResult.Value) return; // TODO Check if plugin with same name exists - Profile.AddNewPlugin(win.Plugin, win.TextResult); + //Profile.AddNewPlugin(win.Plugin, win.TextResult); PluginsListBox.Items.Refresh(); PluginsListBox.SelectedIndex = PluginsListBox.Items.Count - 1; PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); @@ -73,11 +74,12 @@ private void RenamePlugin_OnClick(object sender, RoutedEventArgs e) PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); } + // TODO Remove plugin private void RemovePlugin_OnClick(object sender, RoutedEventArgs e) { Plugin plugin; if (!GetSelectedItem(out plugin)) return; - Profile.RemovePlugin(plugin); + //Profile.RemovePlugin(plugin); PluginsListBox.Items.Refresh(); PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); } From 8dc8e82b57f4eabb4f0c6d983cf32e3f17a200d0 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Fri, 16 Mar 2018 19:45:06 +0100 Subject: [PATCH 10/30] Fixed namespace for UCR.Core.Models --- UCR.Core/Context.cs | 12 +- UCR.Core/Managers/DeviceGroupsManager.cs | 2 +- UCR.Core/Managers/DevicesManager.cs | 2 +- .../PluginManager.cs} | 7 +- UCR.Core/Managers/ProfilesManager.cs | 2 +- UCR.Core/Managers/SubscriptionsManager.cs | 3 +- UCR.Core/Models/Binding/DeviceBinding.cs | 5 +- UCR.Core/Models/{Device => }/Device.cs | 6 +- UCR.Core/Models/{Device => }/DeviceGroup.cs | 2 +- UCR.Core/Models/{Mapping => }/Mapping.cs | 11 +- UCR.Core/Models/{Plugin => }/Plugin.cs | 12 +- UCR.Core/Models/{Profile => }/Profile.cs | 29 ++-- .../Subscription/DeviceBindingSubscription.cs | 6 +- .../Models/Subscription/DeviceSubscription.cs | 6 +- .../Models/Subscription/SubscriptionState.cs | 15 +- UCR.Core/UCR.Core.csproj | 12 +- UCR.Plugins/AxisToAxis/AxisToAxis.cs | 2 +- UCR.Plugins/AxisToButton/AxisToButton.cs | 2 +- UCR.Plugins/ButtonToAxis/ButtonToAxis.cs | 4 +- UCR.Plugins/ButtonToButton/ButtonToButton.cs | 7 +- UCR.Tests/Factory/DeviceFactory.cs | 2 +- UCR.Tests/ModelTests/PersistenceTests.cs | 4 +- UCR.Tests/ModelTests/ProfileTests.cs | 4 +- .../DeviceListControlSampleData.xaml | 136 +++++++++++++++--- UCR/UCR.csproj | 6 +- .../DeviceGroupViewModel.cs | 10 +- .../DeviceListControlViewModel.cs | 8 +- .../DeviceListWindowViewModel.cs | 4 +- UCR/ViewModels/ProfileItem.cs | 2 +- UCR/Views/Controls/DeviceListControl.xaml | 8 +- UCR/Views/Controls/DeviceListControl.xaml.cs | 13 +- UCR/Views/Controls/PluginView.xaml.cs | 2 +- .../Controls/PluginViewTemplateSelector.cs | 1 - UCR/Views/Device/DeviceListWindow.xaml.cs | 2 +- UCR/Views/Profile/DeviceGroupComboBoxItem.cs | 2 +- UCR/Views/Profile/PluginDialog.xaml.cs | 2 +- UCR/Views/Profile/ProfileWindow.xaml.cs | 7 +- 37 files changed, 219 insertions(+), 141 deletions(-) rename UCR.Core/{Models/Plugin/PluginLoader.cs => Managers/PluginManager.cs} (85%) rename UCR.Core/Models/{Device => }/Device.cs (97%) rename UCR.Core/Models/{Device => }/DeviceGroup.cs (95%) rename UCR.Core/Models/{Mapping => }/Mapping.cs (77%) rename UCR.Core/Models/{Plugin => }/Plugin.cs (83%) rename UCR.Core/Models/{Profile => }/Profile.cs (86%) rename UCR/ViewModels/{Device => DeviceViewModels}/DeviceGroupViewModel.cs (86%) rename UCR/ViewModels/{Device => DeviceViewModels}/DeviceListControlViewModel.cs (94%) rename UCR/ViewModels/{Device => DeviceViewModels}/DeviceListWindowViewModel.cs (86%) diff --git a/UCR.Core/Context.cs b/UCR.Core/Context.cs index 9a6401ea..67a7a526 100644 --- a/UCR.Core/Context.cs +++ b/UCR.Core/Context.cs @@ -6,9 +6,7 @@ using System.Xml.Serialization; using HidWizards.IOWrapper.Core; using HidWizards.UCR.Core.Managers; -using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Plugin; -using HidWizards.UCR.Core.Models.Profile; +using HidWizards.UCR.Core.Models; using Mono.Options; using NLog; @@ -40,7 +38,7 @@ public class Context : IDisposable internal bool IsNotSaved { get; private set; } internal IOController IOController { get; set; } internal readonly List ActiveProfileCallbacks = new List(); - private PluginLoader _pluginLoader; + private PluginManager _pluginManager; private OptionSet options; public Context() @@ -61,7 +59,7 @@ private void Init() DevicesManager = new DevicesManager(this); DeviceGroupsManager = new DeviceGroupsManager(this, InputGroups, OutputGroups); SubscriptionsManager = new SubscriptionsManager(this); - _pluginLoader = new PluginLoader(PluginPath); + _pluginManager = new PluginManager(PluginPath); } private void SetCommandLineOptions() @@ -91,7 +89,7 @@ public void SetActiveProfileCallback(Action profileActivated) public List GetPlugins() { - return _pluginLoader.Plugins; + return _pluginManager.Plugins; } public void ContextChanged() @@ -148,7 +146,7 @@ private static XmlSerializer GetXmlSerializer(List additionalPluginTypes) private static XmlSerializer GetXmlSerializer(List additionalPluginTypes, Type type) { - var plugins = new PluginLoader(PluginPath); + var plugins = new PluginManager(PluginPath); var pluginTypes = plugins.Plugins.Select(p => p.GetType()).ToList(); if (additionalPluginTypes != null) pluginTypes.AddRange(additionalPluginTypes); return new XmlSerializer(type, pluginTypes.ToArray()); diff --git a/UCR.Core/Managers/DeviceGroupsManager.cs b/UCR.Core/Managers/DeviceGroupsManager.cs index e7baeabc..2f955abc 100644 --- a/UCR.Core/Managers/DeviceGroupsManager.cs +++ b/UCR.Core/Managers/DeviceGroupsManager.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Core.Managers { diff --git a/UCR.Core/Managers/DevicesManager.cs b/UCR.Core/Managers/DevicesManager.cs index 5b2e7703..7ebc57f0 100644 --- a/UCR.Core/Managers/DevicesManager.cs +++ b/UCR.Core/Managers/DevicesManager.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Core.Managers { diff --git a/UCR.Core/Models/Plugin/PluginLoader.cs b/UCR.Core/Managers/PluginManager.cs similarity index 85% rename from UCR.Core/Models/Plugin/PluginLoader.cs rename to UCR.Core/Managers/PluginManager.cs index 0196f7c3..e5ddc8dc 100644 --- a/UCR.Core/Models/Plugin/PluginLoader.cs +++ b/UCR.Core/Managers/PluginManager.cs @@ -2,17 +2,18 @@ using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.IO; +using HidWizards.UCR.Core.Models; -namespace HidWizards.UCR.Core.Models.Plugin +namespace HidWizards.UCR.Core.Managers { - internal class PluginLoader + internal class PluginManager { private CompositionContainer _Container; [ImportMany(typeof(Plugin))] public List Plugins { get; set; } - public PluginLoader(string basePath) + public PluginManager(string basePath) { var catalog = new AggregateCatalog(); diff --git a/UCR.Core/Managers/ProfilesManager.cs b/UCR.Core/Managers/ProfilesManager.cs index fd3feb43..69ab8c83 100644 --- a/UCR.Core/Managers/ProfilesManager.cs +++ b/UCR.Core/Managers/ProfilesManager.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using HidWizards.UCR.Core.Models.Profile; +using HidWizards.UCR.Core.Models; using NLog; namespace HidWizards.UCR.Core.Managers diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index 2dafb3e9..bf0b6bbd 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -1,8 +1,7 @@ using System; using HidWizards.IOWrapper.DataTransferObjects; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Profile; using HidWizards.UCR.Core.Models.Subscription; using NLog; using Logger = NLog.Logger; diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index 6bf9b27b..0069f74d 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -1,7 +1,6 @@ using System; using System.Xml.Serialization; using HidWizards.IOWrapper.DataTransferObjects; -using HidWizards.UCR.Core.Models.Device; namespace HidWizards.UCR.Core.Models.Binding { @@ -28,7 +27,7 @@ public class DeviceBinding [XmlIgnore] public Guid Guid { get; } [XmlIgnore] - public Profile.Profile Profile { get; set; } + public Profile Profile { get; set; } [XmlIgnore] public DeviceIoType DeviceIoType { get; set; } [XmlIgnore] @@ -46,7 +45,7 @@ private DeviceBinding() Guid = Guid.NewGuid(); } - public DeviceBinding(ValueChanged callback, Profile.Profile profile, DeviceIoType deviceIoType) + public DeviceBinding(ValueChanged callback, Profile profile, DeviceIoType deviceIoType) { Callback = callback; Profile = profile; diff --git a/UCR.Core/Models/Device/Device.cs b/UCR.Core/Models/Device.cs similarity index 97% rename from UCR.Core/Models/Device/Device.cs rename to UCR.Core/Models/Device.cs index 0c93f4fe..5543f22f 100644 --- a/UCR.Core/Models/Device/Device.cs +++ b/UCR.Core/Models/Device.cs @@ -5,7 +5,7 @@ using HidWizards.UCR.Core.Models.Binding; using NLog; -namespace HidWizards.UCR.Core.Models.Device +namespace HidWizards.UCR.Core.Models { public enum DeviceIoType { @@ -27,7 +27,7 @@ public class Device [XmlIgnore] public Guid Guid { get; set; } [XmlIgnore] - public Profile.Profile ParentProfile { get; private set; } + public Profile ParentProfile { get; private set; } [XmlIgnore] private List DeviceBindingMenu { get; set; } @@ -43,7 +43,7 @@ public Device() Guid = (guid == Guid.Empty) ? Guid.NewGuid() : guid; } - public Device(Device device) : this(device.Guid) + public Device(Device device) : this((Guid) device.Guid) { Title = device.Title; DeviceHandle = device.DeviceHandle; diff --git a/UCR.Core/Models/Device/DeviceGroup.cs b/UCR.Core/Models/DeviceGroup.cs similarity index 95% rename from UCR.Core/Models/Device/DeviceGroup.cs rename to UCR.Core/Models/DeviceGroup.cs index a2939dfa..a6c3b7a8 100644 --- a/UCR.Core/Models/Device/DeviceGroup.cs +++ b/UCR.Core/Models/DeviceGroup.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -namespace HidWizards.UCR.Core.Models.Device +namespace HidWizards.UCR.Core.Models { public class DeviceGroup { diff --git a/UCR.Core/Models/Mapping/Mapping.cs b/UCR.Core/Models/Mapping.cs similarity index 77% rename from UCR.Core/Models/Mapping/Mapping.cs rename to UCR.Core/Models/Mapping.cs index 8ef4909b..f2499e8b 100644 --- a/UCR.Core/Models/Mapping/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -1,24 +1,23 @@ using System; using System.Collections.Generic; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; -namespace HidWizards.UCR.Core.Models.Mapping +namespace HidWizards.UCR.Core.Models { public class Mapping { public String Title { get; set; } public Guid Guid { get; set; } public List DeviceBindings { get; set; } - public List Plugins { get; set; } + public List Plugins { get; set; } - internal Profile.Profile Profile { get; set; } + internal Profile Profile { get; set; } public Mapping() { Guid = Guid.NewGuid(); DeviceBindings = new List(); - Plugins = new List(); + Plugins = new List(); } public Mapping(string title) : this() @@ -32,7 +31,7 @@ internal void Update(long value) } - internal void PostLoad(Context context, Profile.Profile profile = null) + internal void PostLoad(Context context, Profile profile = null) { Profile = profile; diff --git a/UCR.Core/Models/Plugin/Plugin.cs b/UCR.Core/Models/Plugin.cs similarity index 83% rename from UCR.Core/Models/Plugin/Plugin.cs rename to UCR.Core/Models/Plugin.cs index c1db30d7..d8c54033 100644 --- a/UCR.Core/Models/Plugin/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; -namespace HidWizards.UCR.Core.Models.Plugin +namespace HidWizards.UCR.Core.Models { public abstract class Plugin : IComparable { @@ -14,7 +12,7 @@ public abstract class Plugin : IComparable public DeviceBinding Output { get; } // Runtime - internal Profile.Profile Profile { get; set; } + internal Profile Profile { get; set; } // Abstract public abstract string PluginName(); @@ -45,12 +43,12 @@ public virtual long Update(List values) return 0L; } - public Device.Device GetDevice(DeviceBinding deviceBinding) + public Device GetDevice(DeviceBinding deviceBinding) { return Profile.GetDevice(deviceBinding); } - public List GetDeviceList(DeviceBinding deviceBinding) + public List GetDeviceList(DeviceBinding deviceBinding) { return Profile.GetDeviceList(deviceBinding); } @@ -67,7 +65,7 @@ public void Rename(string title) Profile.Context.ContextChanged(); } - public void PostLoad(Context context, Profile.Profile parentProfile) + public void PostLoad(Context context, Profile parentProfile) { Profile = parentProfile; } diff --git a/UCR.Core/Models/Profile/Profile.cs b/UCR.Core/Models/Profile.cs similarity index 86% rename from UCR.Core/Models/Profile/Profile.cs rename to UCR.Core/Models/Profile.cs index 37260041..212bec81 100644 --- a/UCR.Core/Models/Profile/Profile.cs +++ b/UCR.Core/Models/Profile.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Xml.Serialization; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; using NLog; -namespace HidWizards.UCR.Core.Models.Profile +namespace HidWizards.UCR.Core.Models { public class Profile { @@ -16,7 +15,7 @@ public class Profile public Guid Guid { get; set; } public List ChildProfiles { get; set; } public List States { get; set; } - public List Mappings { get; set; } + public List Mappings { get; set; } // IO public Guid InputDeviceGroupGuid { get; set; } @@ -47,7 +46,7 @@ private void Init() Guid = Guid.NewGuid(); ChildProfiles = new List(); States = new List(); - Mappings = new List(); + Mappings = new List(); } public Profile(Context context, Profile parentProfile = null) : this(context) @@ -135,14 +134,14 @@ public bool Deactivate() #region Mapping - public Mapping.Mapping AddMapping(string title) + public Mapping AddMapping(string title) { - var mapping = new Mapping.Mapping(title); + var mapping = new Mapping(title); Mappings.Add(mapping); return mapping; } - public bool RemoveMapping(Mapping.Mapping mapping) + public bool RemoveMapping(Mapping mapping) { return Mappings.Remove(mapping); } @@ -151,7 +150,7 @@ public bool RemoveMapping(Mapping.Mapping mapping) #region Device - public Device.Device GetDevice(DeviceBinding deviceBinding) + public Device GetDevice(DeviceBinding deviceBinding) { var deviceList = GetDeviceList(deviceBinding); return deviceBinding.DeviceNumber < deviceList.Count @@ -159,14 +158,14 @@ public Device.Device GetDevice(DeviceBinding deviceBinding) : null; } - public List GetDeviceList(DeviceBinding deviceBinding) + public List GetDeviceList(DeviceBinding deviceBinding) { return GetDeviceList(deviceBinding.DeviceIoType); } - private List GetDeviceList(DeviceIoType deviceIoType) + private List GetDeviceList(DeviceIoType deviceIoType) { - return GetDeviceGroup(deviceIoType)?.Devices ?? new List(); + return GetDeviceGroup(deviceIoType)?.Devices ?? new List(); } public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType) @@ -183,12 +182,12 @@ public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType) #region Plugin - public bool AddNewPlugin(Mapping.Mapping mapping, Plugin.Plugin plugin, string title = "Untitled", string state = null) + public bool AddNewPlugin(Mapping mapping, Plugin plugin, string title = "Untitled", string state = null) { - return AddPlugin(mapping, (Plugin.Plugin)Activator.CreateInstance(plugin.GetType()), title, state); + return AddPlugin(mapping, (Plugin)Activator.CreateInstance(plugin.GetType()), title, state); } - public bool AddPlugin(Mapping.Mapping mapping, Plugin.Plugin plugin, string title = "Untitled", string state = null) + public bool AddPlugin(Mapping mapping, Plugin plugin, string title = "Untitled", string state = null) { if (!Mappings.Contains(mapping)) return false; if (plugin.Title == null) plugin.Title = title; @@ -199,7 +198,7 @@ public bool AddPlugin(Mapping.Mapping mapping, Plugin.Plugin plugin, string titl return true; } - public bool RemovePlugin(Mapping.Mapping mapping, Models.Plugin.Plugin plugin) + public bool RemovePlugin(Mapping mapping, Plugin plugin) { if (!Mappings.Contains(mapping)) return false; mapping.Plugins.Remove(plugin); diff --git a/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs b/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs index 17e24f70..bb563b5c 100644 --- a/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs +++ b/UCR.Core/Models/Subscription/DeviceBindingSubscription.cs @@ -9,13 +9,13 @@ namespace HidWizards.UCR.Core.Models.Subscription public class DeviceBindingSubscription { public DeviceBinding DeviceBinding { get; } - public Profile.Profile Profile { get; } + public Profile Profile { get; } public Guid SubscriptionStateGuid { get; set; } public Guid DeviceBindingSubscriptionGuid { get; set; } public bool IsOverwritten { get; set; } public DeviceSubscription DeviceSubscription { get; } - public DeviceBindingSubscription(DeviceBinding deviceBinding, Profile.Profile profile, Guid subscriptionStateGuid, List deviceSubscriptions) + public DeviceBindingSubscription(DeviceBinding deviceBinding, Profile profile, Guid subscriptionStateGuid, List deviceSubscriptions) { DeviceBinding = deviceBinding; deviceBinding.OutputSink = WriteOutput; @@ -33,7 +33,7 @@ public static List GetSubscriptionsFromList(List new DeviceBindingSubscription(deviceBinding, deviceBinding.Profile, subscriptionStateGuid, deviceSubscriptions)).ToList(); } - private Device.Device GetDevice() + private Device GetDevice() { return Profile.GetDevice(DeviceBinding); } diff --git a/UCR.Core/Models/Subscription/DeviceSubscription.cs b/UCR.Core/Models/Subscription/DeviceSubscription.cs index d8b1e04d..d35c0484 100644 --- a/UCR.Core/Models/Subscription/DeviceSubscription.cs +++ b/UCR.Core/Models/Subscription/DeviceSubscription.cs @@ -5,10 +5,10 @@ namespace HidWizards.UCR.Core.Models.Subscription public class DeviceSubscription { public Guid DeviceSubscriptionGuid { get; } - public Device.Device Device { get; } - public Profile.Profile Profile { get; } + public Device Device { get; } + public Profile Profile { get; } - public DeviceSubscription(Device.Device device, Profile.Profile profile) + public DeviceSubscription(Device device, Profile profile) { DeviceSubscriptionGuid = Guid.NewGuid(); Device = device; diff --git a/UCR.Core/Models/Subscription/SubscriptionState.cs b/UCR.Core/Models/Subscription/SubscriptionState.cs index f0a9b6cc..3d0c91aa 100644 --- a/UCR.Core/Models/Subscription/SubscriptionState.cs +++ b/UCR.Core/Models/Subscription/SubscriptionState.cs @@ -1,45 +1,44 @@ using System; using System.Collections.Generic; using System.Linq; -using HidWizards.UCR.Core.Models.Device; namespace HidWizards.UCR.Core.Models.Subscription { public class SubscriptionState { public Guid StateGuid { get; } - public Profile.Profile ActiveProfile { get; } + public Profile ActiveProfile { get; } public bool IsActive { get; set; } public List DeviceSubscriptions { get; } public Dictionary> DeviceBindingSubscriptions { get; } public Dictionary> OutputDeviceBindingSubscriptions { get; } - public List ActivePlugins { get; } + public List ActivePlugins { get; } - public SubscriptionState(Profile.Profile profile) + public SubscriptionState(Profile profile) { StateGuid = Guid.NewGuid(); ActiveProfile = profile; DeviceSubscriptions = new List(); DeviceBindingSubscriptions = new Dictionary>(); OutputDeviceBindingSubscriptions = new Dictionary>(); - ActivePlugins = new List(); + ActivePlugins = new List(); IsActive = false; } - public void AddOutputDevice(Device.Device device, Profile.Profile profile) + public void AddOutputDevice(Device device, Profile profile) { DeviceSubscriptions.Add(new DeviceSubscription(device, profile)); } - public void AddDeviceBindingSubscriptions(Plugin.Plugin plugin) + public void AddDeviceBindingSubscriptions(Plugin plugin) { AddDeviceBindingSubscriptions(plugin, DeviceIoType.Input); AddDeviceBindingSubscriptions(plugin, DeviceIoType.Output); } // TODO - private void AddDeviceBindingSubscriptions(Plugin.Plugin plugin, DeviceIoType deviceIoType) + private void AddDeviceBindingSubscriptions(Plugin plugin, DeviceIoType deviceIoType) { //var deviceBindings = deviceIoType == DeviceIoType.Input ? plugin.GetInputs() : plugin.Outputs; //var deviceBindingsList = deviceIoType == DeviceIoType.Input ? DeviceBindingSubscriptions : OutputDeviceBindingSubscriptions; diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index 04ff3f9d..1f96b632 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -63,13 +63,13 @@ - - + + - - - - + + + + diff --git a/UCR.Plugins/AxisToAxis/AxisToAxis.cs b/UCR.Plugins/AxisToAxis/AxisToAxis.cs index a875e8ce..9b554b4e 100644 --- a/UCR.Plugins/AxisToAxis/AxisToAxis.cs +++ b/UCR.Plugins/AxisToAxis/AxisToAxis.cs @@ -1,8 +1,8 @@ using System; using System.ComponentModel.Composition; using System.Xml.Serialization; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Plugin; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.AxisToAxis diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index aeba7193..71bb56b6 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -1,8 +1,8 @@ using System; using System.ComponentModel.Composition; using System.Xml.Serialization; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Plugin; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.AxisToButton diff --git a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs index e8167dd4..74475c5d 100644 --- a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs +++ b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs @@ -1,8 +1,6 @@ using System; using System.ComponentModel.Composition; -using System.Xml.Serialization; -using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Plugin; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.ButtonToAxis diff --git a/UCR.Plugins/ButtonToButton/ButtonToButton.cs b/UCR.Plugins/ButtonToButton/ButtonToButton.cs index 5ae65835..927590f3 100644 --- a/UCR.Plugins/ButtonToButton/ButtonToButton.cs +++ b/UCR.Plugins/ButtonToButton/ButtonToButton.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Xml.Serialization; -using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Plugin; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Plugins.ButtonToButton { diff --git a/UCR.Tests/Factory/DeviceFactory.cs b/UCR.Tests/Factory/DeviceFactory.cs index e221d3e2..d2ba7322 100644 --- a/UCR.Tests/Factory/DeviceFactory.cs +++ b/UCR.Tests/Factory/DeviceFactory.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Tests.Factory { diff --git a/UCR.Tests/ModelTests/PersistenceTests.cs b/UCR.Tests/ModelTests/PersistenceTests.cs index 9f726af2..4a2bbb00 100644 --- a/UCR.Tests/ModelTests/PersistenceTests.cs +++ b/UCR.Tests/ModelTests/PersistenceTests.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Net.Http.Headers; using HidWizards.UCR.Core; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Mapping; using HidWizards.UCR.Plugins.ButtonToButton; using HidWizards.UCR.Tests.Factory; using NUnit.Framework; diff --git a/UCR.Tests/ModelTests/ProfileTests.cs b/UCR.Tests/ModelTests/ProfileTests.cs index 95780531..810f14be 100644 --- a/UCR.Tests/ModelTests/ProfileTests.cs +++ b/UCR.Tests/ModelTests/ProfileTests.cs @@ -1,10 +1,8 @@ using System; using HidWizards.UCR.Core; using HidWizards.UCR.Core.Managers; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; -using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Mapping; -using HidWizards.UCR.Core.Models.Profile; using HidWizards.UCR.Plugins.ButtonToButton; using HidWizards.UCR.Tests.Factory; using NUnit.Framework; diff --git a/UCR/SampleData/DeviceListControlSampleData.xaml b/UCR/SampleData/DeviceListControlSampleData.xaml index 7a620ace..8ff4e732 100644 --- a/UCR/SampleData/DeviceListControlSampleData.xaml +++ b/UCR/SampleData/DeviceListControlSampleData.xaml @@ -1,23 +1,119 @@ - - - - SharpDX - - - USB Gamepad - - - vJoy 1 - - - vJoy 2 - - - - - + + + + SharpDX + + + USB Gamepad + + + vJoy 1 + + + vJoy 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index e432b50c..27fbc6c7 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -86,7 +86,7 @@ - + @@ -102,11 +102,11 @@ PluginView.xaml - + DeviceListWindow.xaml - + HelpWindow.xaml diff --git a/UCR/ViewModels/Device/DeviceGroupViewModel.cs b/UCR/ViewModels/DeviceViewModels/DeviceGroupViewModel.cs similarity index 86% rename from UCR/ViewModels/Device/DeviceGroupViewModel.cs rename to UCR/ViewModels/DeviceViewModels/DeviceGroupViewModel.cs index cc1a7fd8..c7f26880 100644 --- a/UCR/ViewModels/Device/DeviceGroupViewModel.cs +++ b/UCR/ViewModels/DeviceViewModels/DeviceGroupViewModel.cs @@ -4,10 +4,10 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Data; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.Properties; -namespace HidWizards.UCR.ViewModels.Device +namespace HidWizards.UCR.ViewModels.DeviceViewModels { public class DeviceGroupViewModel : INotifyPropertyChanged { @@ -26,13 +26,13 @@ public string Title public Guid Guid { get; set; } public ObservableCollection Groups { get; set; } - public ObservableCollection Devices { get; set; } + public ObservableCollection Devices { get; set; } public DeviceGroupViewModel(string title = null, Guid guid = new Guid()) { Title = title; Groups = new ObservableCollection(); - Devices = new ObservableCollection(); + Devices = new ObservableCollection(); Guid = guid.Equals(Guid.Empty) ? Guid.NewGuid() : guid; } @@ -54,7 +54,7 @@ public IList Items } } - public static DeviceGroupViewModel FindDeviceGroupViewModelWithDevice(Collection deviceGroupViewModels, global::HidWizards.UCR.Core.Models.Device.Device device) + public static DeviceGroupViewModel FindDeviceGroupViewModelWithDevice(Collection deviceGroupViewModels, Device device) { DeviceGroupViewModel result = null; foreach (var deviceGroupViewModel in deviceGroupViewModels) diff --git a/UCR/ViewModels/Device/DeviceListControlViewModel.cs b/UCR/ViewModels/DeviceViewModels/DeviceListControlViewModel.cs similarity index 94% rename from UCR/ViewModels/Device/DeviceListControlViewModel.cs rename to UCR/ViewModels/DeviceViewModels/DeviceListControlViewModel.cs index 29eb032b..082b8bf6 100644 --- a/UCR/ViewModels/Device/DeviceListControlViewModel.cs +++ b/UCR/ViewModels/DeviceViewModels/DeviceListControlViewModel.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Windows; using HidWizards.UCR.Core; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; -namespace HidWizards.UCR.ViewModels.Device +namespace HidWizards.UCR.ViewModels.DeviceViewModels { public class DeviceListControlViewModel { @@ -50,13 +50,13 @@ public void RenameDeviceGroup(DeviceGroupViewModel deviceGroup, string title) context.DeviceGroupsManager.RenameDeviceGroup(deviceGroup.Guid, _deviceIoType, title); } - public void AddDeviceToDeviceGroup(global::HidWizards.UCR.Core.Models.Device.Device device, Guid deviceGroupGuid) + public void AddDeviceToDeviceGroup(Device device, Guid deviceGroupGuid) { context.DeviceGroupsManager.AddDeviceToDeviceGroup(device, _deviceIoType, deviceGroupGuid); OutputDeviceGroups.First(d => d.Guid == deviceGroupGuid).Devices.Add(device); } - public void RemoveDeviceFromDeviceGroup(global::HidWizards.UCR.Core.Models.Device.Device device) + public void RemoveDeviceFromDeviceGroup(Device device) { var deviceGroupViewModel = DeviceGroupViewModel.FindDeviceGroupViewModelWithDevice(OutputDeviceGroups, device); context.DeviceGroupsManager.RemoveDeviceFromDeviceGroup(device, _deviceIoType, deviceGroupViewModel.Guid); diff --git a/UCR/ViewModels/Device/DeviceListWindowViewModel.cs b/UCR/ViewModels/DeviceViewModels/DeviceListWindowViewModel.cs similarity index 86% rename from UCR/ViewModels/Device/DeviceListWindowViewModel.cs rename to UCR/ViewModels/DeviceViewModels/DeviceListWindowViewModel.cs index 35350e60..137053b8 100644 --- a/UCR/ViewModels/Device/DeviceListWindowViewModel.cs +++ b/UCR/ViewModels/DeviceViewModels/DeviceListWindowViewModel.cs @@ -1,7 +1,7 @@ using HidWizards.UCR.Core; -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; -namespace HidWizards.UCR.ViewModels.Device +namespace HidWizards.UCR.ViewModels.DeviceViewModels { public class DeviceListWindowViewModel { diff --git a/UCR/ViewModels/ProfileItem.cs b/UCR/ViewModels/ProfileItem.cs index e58c5a7a..0395784c 100644 --- a/UCR/ViewModels/ProfileItem.cs +++ b/UCR/ViewModels/ProfileItem.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using HidWizards.UCR.Core.Models.Profile; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.ViewModels { diff --git a/UCR/Views/Controls/DeviceListControl.xaml b/UCR/Views/Controls/DeviceListControl.xaml index 159c9e77..422ca561 100644 --- a/UCR/Views/Controls/DeviceListControl.xaml +++ b/UCR/Views/Controls/DeviceListControl.xaml @@ -4,8 +4,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HidWizards.UCR.Views.Controls" - xmlns:device="clr-namespace:HidWizards.UCR.ViewModels.Device" - xmlns:devices1="clr-namespace:HidWizards.UCR.Core.Models.Device;assembly=UCR.Core" + xmlns:models="clr-namespace:HidWizards.UCR.Core.Models;assembly=UCR.Core" + xmlns:device="clr-namespace:HidWizards.UCR.ViewModels.DeviceViewModels" mc:Ignorable="d" d:DataContext="{d:DesignData Source=/SampleData/DeviceListControlSampleData.xaml}" d:DesignHeight="600" d:DesignWidth="400"> @@ -27,7 +27,7 @@ - + @@ -78,7 +78,7 @@ - + diff --git a/UCR/Views/Controls/DeviceListControl.xaml.cs b/UCR/Views/Controls/DeviceListControl.xaml.cs index 09b22005..13dbab0e 100644 --- a/UCR/Views/Controls/DeviceListControl.xaml.cs +++ b/UCR/Views/Controls/DeviceListControl.xaml.cs @@ -1,7 +1,8 @@ using System; using System.Windows; using System.Windows.Controls; -using HidWizards.UCR.ViewModels.Device; +using HidWizards.UCR.ViewModels.DeviceViewModels; +using HidWizards.UCR.Core.Models; using MessageBox = System.Windows.MessageBox; using UserControl = System.Windows.Controls.UserControl; @@ -27,8 +28,8 @@ private void AddDeviceGroup_OnClick(object sender, RoutedEventArgs e) private void AddDevice_OnClick(object sender, RoutedEventArgs e) { - var device = (sender as MenuItem)?.DataContext as global::HidWizards.UCR.Core.Models.Device.Device - ?? DeviceTreeView.SelectedItem as global::HidWizards.UCR.Core.Models.Device.Device; + var device = (sender as MenuItem)?.DataContext as Core.Models.Device + ?? DeviceTreeView.SelectedItem as Core.Models.Device; if (device == null) { MessageBox.Show("Please select a device", "No device selected!", MessageBoxButton.OK, MessageBoxImage.Exclamation); @@ -38,7 +39,7 @@ private void AddDevice_OnClick(object sender, RoutedEventArgs e) var deviceGroup = DeviceGroupTreeView.SelectedItem as DeviceGroupViewModel; if (deviceGroup == null) { - var outputDevice = DeviceGroupTreeView.SelectedItem as global::HidWizards.UCR.Core.Models.Device.Device; + var outputDevice = DeviceGroupTreeView.SelectedItem as Core.Models.Device; if (outputDevice != null) { deviceGroup = DeviceGroupViewModel.FindDeviceGroupViewModelWithDevice(GetViewModel().OutputDeviceGroups, outputDevice); @@ -55,8 +56,8 @@ private void AddDevice_OnClick(object sender, RoutedEventArgs e) private void RemoveDevice_OnClick(object sender, RoutedEventArgs e) { // Select device from context menu first, then default to selected item - var device = (sender as MenuItem)?.DataContext as global::HidWizards.UCR.Core.Models.Device.Device - ?? DeviceGroupTreeView.SelectedItem as global::HidWizards.UCR.Core.Models.Device.Device; + var device = (sender as MenuItem)?.DataContext as Core.Models.Device + ?? DeviceGroupTreeView.SelectedItem as Core.Models.Device; if (device == null) { MessageBox.Show("Please select a device to remove", "No device selected!", MessageBoxButton.OK, MessageBoxImage.Exclamation); diff --git a/UCR/Views/Controls/PluginView.xaml.cs b/UCR/Views/Controls/PluginView.xaml.cs index c380c0b9..6eb2d419 100644 --- a/UCR/Views/Controls/PluginView.xaml.cs +++ b/UCR/Views/Controls/PluginView.xaml.cs @@ -1,7 +1,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; -using HidWizards.UCR.Core.Models.Plugin; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Views.Controls { diff --git a/UCR/Views/Controls/PluginViewTemplateSelector.cs b/UCR/Views/Controls/PluginViewTemplateSelector.cs index 4923d048..9b436b21 100644 --- a/UCR/Views/Controls/PluginViewTemplateSelector.cs +++ b/UCR/Views/Controls/PluginViewTemplateSelector.cs @@ -1,6 +1,5 @@ using System.Windows; using System.Windows.Controls; -using HidWizards.UCR.Core.Models.Plugin; namespace HidWizards.UCR.Views.Controls { diff --git a/UCR/Views/Device/DeviceListWindow.xaml.cs b/UCR/Views/Device/DeviceListWindow.xaml.cs index 458c4730..076128bd 100644 --- a/UCR/Views/Device/DeviceListWindow.xaml.cs +++ b/UCR/Views/Device/DeviceListWindow.xaml.cs @@ -1,6 +1,6 @@ using System.Windows; using HidWizards.UCR.Core; -using HidWizards.UCR.ViewModels.Device; +using HidWizards.UCR.ViewModels.DeviceViewModels; namespace HidWizards.UCR.Views.Device { diff --git a/UCR/Views/Profile/DeviceGroupComboBoxItem.cs b/UCR/Views/Profile/DeviceGroupComboBoxItem.cs index 25f0b24c..7f1e3e5b 100644 --- a/UCR/Views/Profile/DeviceGroupComboBoxItem.cs +++ b/UCR/Views/Profile/DeviceGroupComboBoxItem.cs @@ -1,4 +1,4 @@ -using HidWizards.UCR.Core.Models.Device; +using HidWizards.UCR.Core.Models; namespace HidWizards.UCR.Views.Profile { diff --git a/UCR/Views/Profile/PluginDialog.xaml.cs b/UCR/Views/Profile/PluginDialog.xaml.cs index 78283a9d..fe5195c4 100644 --- a/UCR/Views/Profile/PluginDialog.xaml.cs +++ b/UCR/Views/Profile/PluginDialog.xaml.cs @@ -3,7 +3,7 @@ using System.Collections.ObjectModel; using System.Windows; using HidWizards.UCR.Core; -using HidWizards.UCR.Core.Models.Plugin; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.ViewModels; namespace HidWizards.UCR.Views.Profile diff --git a/UCR/Views/Profile/ProfileWindow.xaml.cs b/UCR/Views/Profile/ProfileWindow.xaml.cs index 66a38b53..36cd25ff 100644 --- a/UCR/Views/Profile/ProfileWindow.xaml.cs +++ b/UCR/Views/Profile/ProfileWindow.xaml.cs @@ -3,8 +3,7 @@ using System.Windows; using System.Windows.Controls; using HidWizards.UCR.Core; -using HidWizards.UCR.Core.Models.Device; -using HidWizards.UCR.Core.Models.Plugin; +using HidWizards.UCR.Core.Models; using HidWizards.UCR.ViewModels; namespace HidWizards.UCR.Views.Profile @@ -15,13 +14,13 @@ namespace HidWizards.UCR.Views.Profile public partial class ProfileWindow : Window { private Context Context { get; set; } - private global::HidWizards.UCR.Core.Models.Profile.Profile Profile { get; set; } + private Core.Models.Profile Profile { get; set; } private bool HasLoaded = false; public List InputGroups { get; set; } public List OutputGroups { get; set; } - public ProfileWindow(Context context, global::HidWizards.UCR.Core.Models.Profile.Profile profile) + public ProfileWindow(Context context, Core.Models.Profile profile) { Context = context; Profile = profile; From 9f164fc48b4058c04e848a1553bb8ede8ea35851 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sat, 17 Mar 2018 00:12:00 +0100 Subject: [PATCH 11/30] Profile window redesigned --- UCR.Plugins/AxisToAxis/AxisToAxis.cs | 13 +- UCR.Plugins/AxisToAxis/Resources.xaml | 4 - UCR.Plugins/AxisToButton/AxisToButton.cs | 8 +- UCR.Plugins/AxisToButton/Resources.xaml | 12 +- UCR.Plugins/ButtonToAxis/ButtonToAxis.cs | 19 +-- UCR.Plugins/ButtonToAxis/Resources.xaml | 8 +- UCR.Plugins/ButtonToButton/Resources.xaml | 10 +- UCR/App.xaml | 2 +- UCR/UCR.csproj | 28 ++-- UCR/ViewModels/ProfileViewModel.cs | 12 ++ UCR/Views/Controls/MappingControl.xaml | 41 +++++ ...ginView.xaml.cs => MappingControl.xaml.cs} | 4 +- .../{PluginView.xaml => PluginControl.xaml} | 2 +- UCR/Views/Controls/PluginControl.xaml.cs | 24 +++ .../DeviceListWindow.xaml | 2 +- .../DeviceListWindow.xaml.cs | 2 +- UCR/Views/MainWindow.xaml.cs | 4 +- UCR/Views/Profile/ProfileWindow.xaml | 74 -------- .../DeviceGroupComboBoxItem.cs | 2 +- .../PluginDialog.xaml | 2 +- .../PluginDialog.xaml.cs | 2 +- UCR/Views/ProfileViews/ProfileWindow.xaml | 158 ++++++++++++++++++ .../ProfileWindow.xaml.cs | 4 +- 23 files changed, 284 insertions(+), 153 deletions(-) create mode 100644 UCR/ViewModels/ProfileViewModel.cs create mode 100644 UCR/Views/Controls/MappingControl.xaml rename UCR/Views/Controls/{PluginView.xaml.cs => MappingControl.xaml.cs} (91%) rename UCR/Views/Controls/{PluginView.xaml => PluginControl.xaml} (97%) create mode 100644 UCR/Views/Controls/PluginControl.xaml.cs rename UCR/Views/{Device => DeviceViews}/DeviceListWindow.xaml (93%) rename UCR/Views/{Device => DeviceViews}/DeviceListWindow.xaml.cs (92%) delete mode 100644 UCR/Views/Profile/ProfileWindow.xaml rename UCR/Views/{Profile => ProfileViews}/DeviceGroupComboBoxItem.cs (81%) rename UCR/Views/{Profile => ProfileViews}/PluginDialog.xaml (95%) rename UCR/Views/{Profile => ProfileViews}/PluginDialog.xaml.cs (97%) create mode 100644 UCR/Views/ProfileViews/ProfileWindow.xaml rename UCR/Views/{Profile => ProfileViews}/ProfileWindow.xaml.cs (98%) diff --git a/UCR.Plugins/AxisToAxis/AxisToAxis.cs b/UCR.Plugins/AxisToAxis/AxisToAxis.cs index 9b554b4e..c14e5b84 100644 --- a/UCR.Plugins/AxisToAxis/AxisToAxis.cs +++ b/UCR.Plugins/AxisToAxis/AxisToAxis.cs @@ -1,8 +1,7 @@ using System; +using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Xml.Serialization; using HidWizards.UCR.Core.Models; -using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.AxisToAxis @@ -10,11 +9,6 @@ namespace HidWizards.UCR.Plugins.AxisToAxis [Export(typeof(Plugin))] public class AxisToAxis : Plugin { - [XmlIgnore] - public DeviceBinding InputAxis { get; set; } - [XmlIgnore] - public DeviceBinding OutputAxis { get; set; } - public bool Invert { get; set; } public bool Linear { get; set; } @@ -55,12 +49,13 @@ public override string PluginName() return "Axis to axis"; } - private void InputChanged(long value) + public override long Update(List values) { + var value = values[0]; if (Invert) value *= -1; if (_deadZoneValue != 0) value = ApplyDeadZone(value); if (_sensitivityValue != 100) value = ApplySensitivity(value); - WriteOutput(OutputAxis, Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue)); + return Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); } private long ApplySensitivity(long value) diff --git a/UCR.Plugins/AxisToAxis/Resources.xaml b/UCR.Plugins/AxisToAxis/Resources.xaml index 14a04b7a..5d59fc79 100644 --- a/UCR.Plugins/AxisToAxis/Resources.xaml +++ b/UCR.Plugins/AxisToAxis/Resources.xaml @@ -1,7 +1,5 @@  @@ -30,8 +28,6 @@ - - diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index 71bb56b6..032556d4 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.Composition; using System.Xml.Serialization; using HidWizards.UCR.Core.Models; @@ -44,11 +45,13 @@ public AxisToButton() DeadZone = "30"; } - private void InputChanged(long value) + + // TODO implement high/low select + public override long Update(List values) { + var value = values[0]; if (Invert) value *= -1; value = Math.Sign(ApplyDeadZone(value)); - if (value == _direction && value != 0) return; switch (value) { case 0: @@ -65,6 +68,7 @@ private void InputChanged(long value) break; } _direction = value; + return value; } private long ApplyDeadZone(long value) diff --git a/UCR.Plugins/AxisToButton/Resources.xaml b/UCR.Plugins/AxisToButton/Resources.xaml index 5ba01439..9593ccc7 100644 --- a/UCR.Plugins/AxisToButton/Resources.xaml +++ b/UCR.Plugins/AxisToButton/Resources.xaml @@ -1,7 +1,5 @@  @@ -18,15 +16,7 @@ - - - - - - - - - + diff --git a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs index 74475c5d..de2f594b 100644 --- a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs +++ b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.Composition; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Utilities; @@ -21,22 +22,10 @@ public ButtonToAxis() } - private void InputLowChanged(long value) + // TODO Implement value to set + public override long Update(List values) { - _direction += value == 0 ? 1 : -1; - WriteOutput(); - } - - private void InputHighChanged(long value) - { - _direction += value == 0 ? -1 : 1; - WriteOutput(); - } - - private void WriteOutput() - { - _direction = Math.Sign(_direction); - WriteOutput(Output, _direction*Constants.AxisMaxValue); + return values[0] * Constants.AxisMaxValue; } } } diff --git a/UCR.Plugins/ButtonToAxis/Resources.xaml b/UCR.Plugins/ButtonToAxis/Resources.xaml index be2bb40b..8246e42c 100644 --- a/UCR.Plugins/ButtonToAxis/Resources.xaml +++ b/UCR.Plugins/ButtonToAxis/Resources.xaml @@ -1,7 +1,5 @@  @@ -9,11 +7,7 @@ - - - - - + \ No newline at end of file diff --git a/UCR.Plugins/ButtonToButton/Resources.xaml b/UCR.Plugins/ButtonToButton/Resources.xaml index 1d8abdc6..81d928bc 100644 --- a/UCR.Plugins/ButtonToButton/Resources.xaml +++ b/UCR.Plugins/ButtonToButton/Resources.xaml @@ -1,15 +1,9 @@  + x:Class="HidWizards.UCR.Plugins.ButtonToButton.Resources"> - - - - - - + \ No newline at end of file diff --git a/UCR/App.xaml b/UCR/App.xaml index 5c48b18b..bb6cce9e 100644 --- a/UCR/App.xaml +++ b/UCR/App.xaml @@ -4,6 +4,6 @@ ShutdownMode="OnMainWindowClose" Exit="App_OnExit"> - + diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index 27fbc6c7..8f7bb9d7 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -89,6 +89,7 @@ + AboutWindow.xaml @@ -98,20 +99,23 @@ DeviceListControl.xaml - - PluginView.xaml + + MappingControl.xaml + + + PluginControl.xaml - + DeviceListWindow.xaml HelpWindow.xaml - - + + PluginDialog.xaml @@ -125,7 +129,7 @@ Code - + ProfileWindow.xaml @@ -143,11 +147,15 @@ Designer MSBuild:Compile - + + MSBuild:Compile + Designer + + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -155,7 +163,7 @@ Designer MSBuild:Compile - + MSBuild:Compile Designer @@ -167,7 +175,7 @@ MSBuild:Compile Designer - + Designer MSBuild:Compile diff --git a/UCR/ViewModels/ProfileViewModel.cs b/UCR/ViewModels/ProfileViewModel.cs new file mode 100644 index 00000000..ff6ebe14 --- /dev/null +++ b/UCR/ViewModels/ProfileViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HidWizards.UCR.ViewModels +{ + class ProfileViewModel + { + } +} diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml new file mode 100644 index 00000000..2d201c3f --- /dev/null +++ b/UCR/Views/Controls/MappingControl.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + diff --git a/UCR/Views/Controls/PluginView.xaml.cs b/UCR/Views/Controls/MappingControl.xaml.cs similarity index 91% rename from UCR/Views/Controls/PluginView.xaml.cs rename to UCR/Views/Controls/MappingControl.xaml.cs index 6eb2d419..923b2ae5 100644 --- a/UCR/Views/Controls/PluginView.xaml.cs +++ b/UCR/Views/Controls/MappingControl.xaml.cs @@ -5,10 +5,10 @@ namespace HidWizards.UCR.Views.Controls { - public partial class PluginView : UserControl + public partial class PluginControl : UserControl { - public PluginView() + public PluginControl() { InitializeComponent(); } diff --git a/UCR/Views/Controls/PluginView.xaml b/UCR/Views/Controls/PluginControl.xaml similarity index 97% rename from UCR/Views/Controls/PluginView.xaml rename to UCR/Views/Controls/PluginControl.xaml index 8d9ed764..b5b7f6e5 100644 --- a/UCR/Views/Controls/PluginView.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -1,4 +1,4 @@ - /// Interaction logic for DeviceListWindow.xaml diff --git a/UCR/Views/MainWindow.xaml.cs b/UCR/Views/MainWindow.xaml.cs index d626d5a0..4d3e36f0 100644 --- a/UCR/Views/MainWindow.xaml.cs +++ b/UCR/Views/MainWindow.xaml.cs @@ -10,8 +10,8 @@ using HidWizards.UCR.Properties; using HidWizards.UCR.Utilities; using HidWizards.UCR.ViewModels; -using HidWizards.UCR.Views.Device; -using HidWizards.UCR.Views.Profile; +using DeviceListWindow = HidWizards.UCR.Views.DeviceViews.DeviceListWindow; +using ProfileWindow = HidWizards.UCR.Views.ProfileViews.ProfileWindow; namespace HidWizards.UCR.Views { diff --git a/UCR/Views/Profile/ProfileWindow.xaml b/UCR/Views/Profile/ProfileWindow.xaml deleted file mode 100644 index 254584b8..00000000 --- a/UCR/Views/Profile/ProfileWindow.xaml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/UCR/Views/Profile/DeviceGroupComboBoxItem.cs b/UCR/Views/ProfileViews/DeviceGroupComboBoxItem.cs similarity index 81% rename from UCR/Views/Profile/DeviceGroupComboBoxItem.cs rename to UCR/Views/ProfileViews/DeviceGroupComboBoxItem.cs index 7f1e3e5b..c0d923eb 100644 --- a/UCR/Views/Profile/DeviceGroupComboBoxItem.cs +++ b/UCR/Views/ProfileViews/DeviceGroupComboBoxItem.cs @@ -1,6 +1,6 @@ using HidWizards.UCR.Core.Models; -namespace HidWizards.UCR.Views.Profile +namespace HidWizards.UCR.Views.ProfileViews { class DeviceGroupComboBoxItem { diff --git a/UCR/Views/Profile/PluginDialog.xaml b/UCR/Views/ProfileViews/PluginDialog.xaml similarity index 95% rename from UCR/Views/Profile/PluginDialog.xaml rename to UCR/Views/ProfileViews/PluginDialog.xaml index e1214bd6..8859eafd 100644 --- a/UCR/Views/Profile/PluginDialog.xaml +++ b/UCR/Views/ProfileViews/PluginDialog.xaml @@ -1,4 +1,4 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UCR/Views/Profile/ProfileWindow.xaml.cs b/UCR/Views/ProfileViews/ProfileWindow.xaml.cs similarity index 98% rename from UCR/Views/Profile/ProfileWindow.xaml.cs rename to UCR/Views/ProfileViews/ProfileWindow.xaml.cs index 36cd25ff..307d9eff 100644 --- a/UCR/Views/Profile/ProfileWindow.xaml.cs +++ b/UCR/Views/ProfileViews/ProfileWindow.xaml.cs @@ -6,7 +6,7 @@ using HidWizards.UCR.Core.Models; using HidWizards.UCR.ViewModels; -namespace HidWizards.UCR.Views.Profile +namespace HidWizards.UCR.Views.ProfileViews { /// /// Interaction logic for ProfileWindow.xaml @@ -14,7 +14,7 @@ namespace HidWizards.UCR.Views.Profile public partial class ProfileWindow : Window { private Context Context { get; set; } - private Core.Models.Profile Profile { get; set; } + private Profile Profile { get; set; } private bool HasLoaded = false; public List InputGroups { get; set; } From 2f9784d49181de380447be85657f1441830888e1 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sat, 17 Mar 2018 12:30:36 +0100 Subject: [PATCH 12/30] Mapping management implemented for profile window --- UCR.Core/Models/Binding/DeviceBinding.cs | 2 +- UCR.Core/Models/Profile.cs | 5 +- UCR/SampleData/MappingControlSampleData.xaml | 14 +++++ .../ProfileViewModelSampleData.xaml | 21 +++++++ UCR/UCR.csproj | 9 ++- UCR/ViewModels/ProfileViewModel.cs | 12 ---- .../ProfileViewModels/MappingViewModel.cs | 21 +++++++ .../ProfileViewModels/ProfileViewModel.cs | 60 +++++++++++++++++++ UCR/Views/Controls/DeviceListControl.xaml | 1 - UCR/Views/Controls/MappingControl.xaml | 45 ++++++++++++-- UCR/Views/Controls/MappingControl.xaml.cs | 23 ++----- UCR/Views/Controls/PluginControl.xaml.cs | 23 +++++-- UCR/Views/DeviceViews/DeviceListWindow.xaml | 5 +- UCR/Views/ProfileViews/ProfileWindow.xaml | 25 +++++--- UCR/Views/ProfileViews/ProfileWindow.xaml.cs | 48 ++++++++++++--- 15 files changed, 250 insertions(+), 64 deletions(-) create mode 100644 UCR/SampleData/MappingControlSampleData.xaml create mode 100644 UCR/SampleData/ProfileViewModelSampleData.xaml delete mode 100644 UCR/ViewModels/ProfileViewModel.cs create mode 100644 UCR/ViewModels/ProfileViewModels/MappingViewModel.cs create mode 100644 UCR/ViewModels/ProfileViewModels/ProfileViewModel.cs diff --git a/UCR.Core/Models/Binding/DeviceBinding.cs b/UCR.Core/Models/Binding/DeviceBinding.cs index 0069f74d..5641913f 100644 --- a/UCR.Core/Models/Binding/DeviceBinding.cs +++ b/UCR.Core/Models/Binding/DeviceBinding.cs @@ -40,7 +40,7 @@ public class DeviceBinding [XmlIgnore] public ValueChanged OutputSink { get; set; } - private DeviceBinding() + public DeviceBinding() { Guid = Guid.NewGuid(); } diff --git a/UCR.Core/Models/Profile.cs b/UCR.Core/Models/Profile.cs index 212bec81..b6a3dca6 100644 --- a/UCR.Core/Models/Profile.cs +++ b/UCR.Core/Models/Profile.cs @@ -138,12 +138,15 @@ public Mapping AddMapping(string title) { var mapping = new Mapping(title); Mappings.Add(mapping); + Context.ContextChanged(); return mapping; } public bool RemoveMapping(Mapping mapping) { - return Mappings.Remove(mapping); + if (!Mappings.Remove(mapping)) return false; + Context.ContextChanged(); + return true; } #endregion diff --git a/UCR/SampleData/MappingControlSampleData.xaml b/UCR/SampleData/MappingControlSampleData.xaml new file mode 100644 index 00000000..da914eaa --- /dev/null +++ b/UCR/SampleData/MappingControlSampleData.xaml @@ -0,0 +1,14 @@ + + + + Test title + + + + + + + + \ No newline at end of file diff --git a/UCR/SampleData/ProfileViewModelSampleData.xaml b/UCR/SampleData/ProfileViewModelSampleData.xaml new file mode 100644 index 00000000..bb5ede84 --- /dev/null +++ b/UCR/SampleData/ProfileViewModelSampleData.xaml @@ -0,0 +1,21 @@ + + + + + Mappine one + + + + + Mappine two + + + + + Mappine three + + + + \ No newline at end of file diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index 8f7bb9d7..ec14d7b1 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -89,7 +89,8 @@ - + + AboutWindow.xaml @@ -135,6 +136,12 @@ Designer + + Designer + + + Designer + Designer MSBuild:Compile diff --git a/UCR/ViewModels/ProfileViewModel.cs b/UCR/ViewModels/ProfileViewModel.cs deleted file mode 100644 index ff6ebe14..00000000 --- a/UCR/ViewModels/ProfileViewModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HidWizards.UCR.ViewModels -{ - class ProfileViewModel - { - } -} diff --git a/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs b/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs new file mode 100644 index 00000000..dab85204 --- /dev/null +++ b/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs @@ -0,0 +1,21 @@ +using HidWizards.UCR.Core.Models; + +namespace HidWizards.UCR.ViewModels.ProfileViewModels +{ + public class MappingViewModel + { + public ProfileViewModel ProfileViewModel { get; } + public Mapping Mapping { get; set; } + + public MappingViewModel(ProfileViewModel profileViewModel, Mapping mapping) + { + ProfileViewModel = profileViewModel; + Mapping = mapping; + } + + public void Remove() + { + ProfileViewModel.RemoveMapping(this); + } + } +} diff --git a/UCR/ViewModels/ProfileViewModels/ProfileViewModel.cs b/UCR/ViewModels/ProfileViewModels/ProfileViewModel.cs new file mode 100644 index 00000000..511688f0 --- /dev/null +++ b/UCR/ViewModels/ProfileViewModels/ProfileViewModel.cs @@ -0,0 +1,60 @@ +using System.Collections.ObjectModel; +using System.Windows; +using HidWizards.UCR.Core.Models; + +namespace HidWizards.UCR.ViewModels.ProfileViewModels +{ + public class ProfileViewModel + { + public Profile Profile { get; } + public ObservableCollection MappingsList { get; set; } + public MappingViewModel SelectedMapping { get; set; } + + public ProfileViewModel() + { + + } + + public ProfileViewModel(Profile profile) + { + Profile = profile; + PopulateMappingsList(profile); + } + + private void PopulateMappingsList(Profile profile) + { + MappingsList = new ObservableCollection(); + foreach (var profileMapping in profile.Mappings) + { + AddMapping(profileMapping); + } + + if (MappingsList.Count > 0) SelectedMapping = MappingsList[0]; + } + + public MappingViewModel AddMapping(string title) + { + return AddMapping(Profile.AddMapping(title)); + } + + public MappingViewModel AddMapping(Mapping mapping) + { + var mappingViewModel = new MappingViewModel(this, mapping); + MappingsList.Add(mappingViewModel); + return mappingViewModel; + } + + public void RemoveMapping(MappingViewModel mappingViewModel) + { + if (mappingViewModel.Mapping.DeviceBindings.Count > 0) + { + var result = + MessageBox.Show("Are you sure you want to remove '" + mappingViewModel.Mapping.Title + "'?", + "Remove mapping?", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (result != MessageBoxResult.Yes) return; + } + + if (Profile.RemoveMapping(mappingViewModel.Mapping)) MappingsList.Remove(mappingViewModel); + } + } +} diff --git a/UCR/Views/Controls/DeviceListControl.xaml b/UCR/Views/Controls/DeviceListControl.xaml index 422ca561..2b3eb7ee 100644 --- a/UCR/Views/Controls/DeviceListControl.xaml +++ b/UCR/Views/Controls/DeviceListControl.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:HidWizards.UCR.Views.Controls" xmlns:models="clr-namespace:HidWizards.UCR.Core.Models;assembly=UCR.Core" xmlns:device="clr-namespace:HidWizards.UCR.ViewModels.DeviceViewModels" mc:Ignorable="d" diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index 2d201c3f..2bd3a616 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -2,16 +2,18 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:controls="clr-namespace:HidWizards.UCR.Views.Controls" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="300" - x:Name="PluginViewName" Margin="0,0,0,5"> + d:DataContext="{d:DesignData Source=/SampleData/MappingControlSampleData.xaml}" + x:Name="MappingViewName" Margin="0,0,0,5"> + Width="{Binding ActualWidth, ElementName=MappingViewName}"> - public partial class ProfileWindow : Window { - private Context Context { get; set; } - private Profile Profile { get; set; } - private bool HasLoaded = false; + private Context Context { get; } + private Profile Profile { get; } + private ProfileViewModel ProfileViewModel { get; } + private bool _hasLoaded; public List InputGroups { get; set; } public List OutputGroups { get; set; } - public ProfileWindow(Context context, Core.Models.Profile profile) + public ProfileWindow(Context context, Profile profile) { Context = context; Profile = profile; + ProfileViewModel = new ProfileViewModel(profile); InitializeComponent(); Title = "Edit " + profile.Title; - DataContext = Profile; + DataContext = ProfileViewModel; PopulateComboBox(InputGroups, DeviceIoType.Input, profile.InputDeviceGroupGuid, InputComboBox); PopulateComboBox(OutputGroups, DeviceIoType.Output, profile.OutputDeviceGroupGuid, OutputComboBox); Loaded += Window_Loaded; } + #region Profile + private void ActivateProfile(object sender, RoutedEventArgs e) { if (!Profile.ActivateProfile()) @@ -46,6 +51,25 @@ private void DeactivateProfile(object sender, RoutedEventArgs e) Profile.Deactivate(); } + #endregion + + #region Mappings + + private void AddMapping_OnClick(object sender, RoutedEventArgs e) + { + var title = MappingNameField.Text; + if (string.IsNullOrEmpty(title)) + { + MessageBox.Show("Please write a title to add a new mapping", "No title!", MessageBoxButton.OK, MessageBoxImage.Exclamation); + return; + } + + ProfileViewModel.AddMapping(title); + MappingNameField.Text = ""; + } + + #endregion + // TODO Add plugin private void AddPlugin_OnClick(object sender, RoutedEventArgs e) { @@ -103,7 +127,11 @@ private void Close_OnClick(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e) { - HasLoaded = true; + _hasLoaded = true; + if (ProfileViewModel.MappingsList.Count > 0) + { + MappingsListBox.SelectedItem = ProfileViewModel.MappingsList[0]; + } } private void PopulateComboBox(List groups, DeviceIoType deviceIoType, Guid currentGroup, ComboBox comboBox) @@ -138,7 +166,7 @@ private void PopulateComboBox(List groups, DeviceIoType d private void DeviceGroup_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { - if (!HasLoaded) return; + if (!_hasLoaded) return; var comboBox = sender as ComboBox; var selectedItem = comboBox?.SelectedItem as ComboBoxItemViewModel; if (selectedItem == null) return; @@ -155,5 +183,11 @@ private string GetInheritedDeviceGroupName(DeviceIoType deviceIoType) if (Profile.ParentProfile != null) parentDeviceGroupName += " (Inherited)"; return parentDeviceGroupName; } + + private void MappingsListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + var mappingViewModel = sender as MappingViewModel; + ProfileViewModel.SelectedMapping = mappingViewModel; + } } } From a04f85bc81046ed4d6a5f19d59c9b513d8fae8ef Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sat, 17 Mar 2018 16:41:21 +0100 Subject: [PATCH 13/30] Plugin management implemented for profile window --- UCR.Core/Models/Mapping.cs | 62 ++++++++++++++++++- UCR.Core/Models/Plugin.cs | 40 +++++++++--- UCR.Core/Models/Profile.cs | 2 +- UCR.Plugins/AxisToAxis/AxisToAxis.cs | 17 +++-- UCR.Plugins/AxisToButton/AxisToButton.cs | 54 ++++++++-------- UCR.Plugins/ButtonToAxis/ButtonToAxis.cs | 16 +++-- UCR.Plugins/ButtonToButton/ButtonToButton.cs | 14 +++-- .../ProfileViewModelSampleData.xaml | 11 ++++ UCR/UCR.csproj | 2 + .../DeviceBindingViewModel.cs | 11 ++++ .../ProfileViewModels/MappingViewModel.cs | 54 +++++++++++++++- .../ProfileViewModels/PluginViewModel.cs | 21 +++++++ UCR/Views/Controls/MappingControl.xaml | 4 +- UCR/Views/Controls/PluginControl.xaml | 9 ++- UCR/Views/Controls/PluginControl.xaml.cs | 6 +- UCR/Views/ProfileViews/PluginDialog.xaml.cs | 2 +- UCR/Views/ProfileViews/ProfileWindow.xaml | 18 ++---- UCR/Views/ProfileViews/ProfileWindow.xaml.cs | 51 ++++++++++----- 18 files changed, 302 insertions(+), 92 deletions(-) create mode 100644 UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs create mode 100644 UCR/ViewModels/ProfileViewModels/PluginViewModel.cs diff --git a/UCR.Core/Models/Mapping.cs b/UCR.Core/Models/Mapping.cs index f2499e8b..1254a837 100644 --- a/UCR.Core/Models/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -6,12 +6,15 @@ namespace HidWizards.UCR.Core.Models { public class Mapping { + // Persistence public String Title { get; set; } public Guid Guid { get; set; } public List DeviceBindings { get; set; } public List Plugins { get; set; } + // Runtime internal Profile Profile { get; set; } + private List InputCache { get; set; } public Mapping() { @@ -20,20 +23,77 @@ public Mapping() Plugins = new List(); } - public Mapping(string title) : this() + public Mapping(Profile profile, string title) : this() { + Profile = profile; Title = title; } + internal void PrepareMapping() + { + InputCache = new List(); + foreach (var _ in DeviceBindings) + { + InputCache.Add(0L); + } + } + // TODO Add Guid to distinguish devicebindings internal void Update(long value) { + InputCache[0] = value; + foreach (var plugin in Plugins) + { + plugin.WriteOutput(plugin.Update(InputCache)); + } + } + + #region Plugin + + internal List GetPluginList() + { + var plugins = Profile.Context.GetPlugins(); + plugins.Sort(); + return plugins; + } + + public bool AddPlugin(Plugin plugin) + { + if (Plugins.Count == 0) + { + foreach (var _ in plugin.GetInputCategories()) + { + DeviceBindings.Add(new DeviceBinding(Update, Profile, DeviceIoType.Input)); + } + } + Plugins.Add(plugin); + Profile.Context.ContextChanged(); + return true; + } + + public bool RemovePlugin(Plugin plugin) + { + if (!Plugins.Remove(plugin)) return false; + if (Plugins.Count == 0) + { + DeviceBindings = new List(); + } + Profile.Context.ContextChanged(); + + return true; } + #endregion + + internal void PostLoad(Context context, Profile profile = null) { Profile = profile; + foreach (var deviceBinding in DeviceBindings) + { + deviceBinding.Profile = profile; + } foreach (var plugin in Plugins) { diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index d8c54033..bfc094b2 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Xml.Serialization; using HidWizards.UCR.Core.Models.Binding; namespace HidWizards.UCR.Core.Models @@ -9,19 +10,34 @@ public abstract class Plugin : IComparable // Persistence public string Title { get; set; } public string State { get; set; } - public DeviceBinding Output { get; } - + public DeviceBinding Output { get; set; } + // Runtime internal Profile Profile { get; set; } // Abstract - public abstract string PluginName(); - + [XmlIgnore] + public abstract string PluginName { get; } + [XmlIgnore] + public abstract DeviceBindingCategory OutputCategory { get; } + protected abstract List InputCategories { get; } + + public struct PluginInput + { + public string Name; + public DeviceBindingCategory Category; + } + protected Plugin() { Output = new DeviceBinding(null, Profile, DeviceIoType.Output); } - + + public List GetInputCategories() + { + return InputCategories; + } + public bool Remove() { Profile.Context.ContextChanged(); @@ -54,9 +70,9 @@ public List GetDeviceList(DeviceBinding deviceBinding) } // TODO - protected void WriteOutput(DeviceBinding output, long value) + internal void WriteOutput(long value) { - output.WriteOutput(value); + Output.WriteOutput(value); } public void Rename(string title) @@ -67,7 +83,13 @@ public void Rename(string title) public void PostLoad(Context context, Profile parentProfile) { - Profile = parentProfile; + SetProfile(parentProfile); + } + + public void SetProfile(Profile profile) + { + Profile = profile; + Output.Profile = profile; } public Plugin Duplicate() @@ -84,7 +106,7 @@ protected void ContextChanged() public int CompareTo(Plugin other) { - return string.Compare(PluginName(), other.PluginName(), StringComparison.Ordinal); + return string.Compare(PluginName, other.PluginName, StringComparison.Ordinal); } } } diff --git a/UCR.Core/Models/Profile.cs b/UCR.Core/Models/Profile.cs index b6a3dca6..68f5f600 100644 --- a/UCR.Core/Models/Profile.cs +++ b/UCR.Core/Models/Profile.cs @@ -136,7 +136,7 @@ public bool Deactivate() public Mapping AddMapping(string title) { - var mapping = new Mapping(title); + var mapping = new Mapping(this, title); Mappings.Add(mapping); Context.ContextChanged(); return mapping; diff --git a/UCR.Plugins/AxisToAxis/AxisToAxis.cs b/UCR.Plugins/AxisToAxis/AxisToAxis.cs index c14e5b84..002ab739 100644 --- a/UCR.Plugins/AxisToAxis/AxisToAxis.cs +++ b/UCR.Plugins/AxisToAxis/AxisToAxis.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.AxisToAxis @@ -9,6 +10,17 @@ namespace HidWizards.UCR.Plugins.AxisToAxis [Export(typeof(Plugin))] public class AxisToAxis : Plugin { + public override string PluginName => "Axis to axis"; + public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Range; + protected override List InputCategories => new List() + { + new PluginInput() + { + Name = "Axis", + Category = DeviceBindingCategory.Range + } + }; + public bool Invert { get; set; } public bool Linear { get; set; } @@ -44,11 +56,6 @@ public AxisToAxis() Sensitivity = "100"; } - public override string PluginName() - { - return "Axis to axis"; - } - public override long Update(List values) { var value = values[0]; diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index 032556d4..4faec342 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -11,13 +11,17 @@ namespace HidWizards.UCR.Plugins.AxisToButton [Export(typeof(Plugin))] public class AxisToButton : Plugin { - [XmlIgnore] - public DeviceBinding Input { get; set; } - [XmlIgnore] - public DeviceBinding OutputLow { get; set; } - [XmlIgnore] - public DeviceBinding OutputHigh { get; set; } - + public override string PluginName => "Axis to buttons"; + public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Momentary; + protected override List InputCategories => new List() + { + new PluginInput() + { + Name = "Axis", + Category = DeviceBindingCategory.Range + } + }; + public bool Invert { get; set; } private int _deadZoneValue; @@ -34,11 +38,7 @@ public string DeadZone } private long _direction = 0; - - public override string PluginName() - { - return "Axis to buttons"; - } + public AxisToButton() { @@ -52,21 +52,21 @@ public override long Update(List values) var value = values[0]; if (Invert) value *= -1; value = Math.Sign(ApplyDeadZone(value)); - switch (value) - { - case 0: - WriteOutput(OutputLow, 0); - WriteOutput(OutputHigh, 0); - break; - case -1: - WriteOutput(OutputLow, 1); - WriteOutput(OutputHigh, 0); - break; - case 1: - WriteOutput(OutputLow, 0); - WriteOutput(OutputHigh, 1); - break; - } + //switch (value) + //{ + // case 0: + // WriteOutput(OutputLow, 0); + // WriteOutput(OutputHigh, 0); + // break; + // case -1: + // WriteOutput(OutputLow, 1); + // WriteOutput(OutputHigh, 0); + // break; + // case 1: + // WriteOutput(OutputLow, 0); + // WriteOutput(OutputHigh, 1); + // break; + //} _direction = value; return value; } diff --git a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs index de2f594b..9f06b2f4 100644 --- a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs +++ b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; namespace HidWizards.UCR.Plugins.ButtonToAxis @@ -9,14 +10,19 @@ namespace HidWizards.UCR.Plugins.ButtonToAxis [Export(typeof(Plugin))] public class ButtonToAxis : Plugin { + public override string PluginName => "Button to axis"; + public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Range; + protected override List InputCategories => new List() + { + new PluginInput() + { + Name = "Button", + Category = DeviceBindingCategory.Momentary + } + }; private long _direction = 0; - public override string PluginName() - { - return "Button to Axis"; - } - public ButtonToAxis() { diff --git a/UCR.Plugins/ButtonToButton/ButtonToButton.cs b/UCR.Plugins/ButtonToButton/ButtonToButton.cs index 927590f3..91b2cf70 100644 --- a/UCR.Plugins/ButtonToButton/ButtonToButton.cs +++ b/UCR.Plugins/ButtonToButton/ButtonToButton.cs @@ -1,17 +1,23 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; namespace HidWizards.UCR.Plugins.ButtonToButton { [Export(typeof(Plugin))] public class ButtonToButton : Plugin { - - public override string PluginName() + public override string PluginName => "Button to Button"; + public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Momentary; + protected override List InputCategories => new List() { - return "Button to Button"; - } + new PluginInput() + { + Name = "Button", + Category = DeviceBindingCategory.Momentary + } + }; public override long Update(List values) { diff --git a/UCR/SampleData/ProfileViewModelSampleData.xaml b/UCR/SampleData/ProfileViewModelSampleData.xaml index bb5ede84..b29de2e7 100644 --- a/UCR/SampleData/ProfileViewModelSampleData.xaml +++ b/UCR/SampleData/ProfileViewModelSampleData.xaml @@ -18,4 +18,15 @@ + + + + + Mappine three + + + + + + \ No newline at end of file diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index ec14d7b1..f819e064 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -89,6 +89,8 @@ + + diff --git a/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs new file mode 100644 index 00000000..5c9d11ef --- /dev/null +++ b/UCR/ViewModels/ProfileViewModels/DeviceBindingViewModel.cs @@ -0,0 +1,11 @@ +using HidWizards.UCR.Core.Models.Binding; + +namespace HidWizards.UCR.ViewModels.ProfileViewModels +{ + public class DeviceBindingViewModel + { + public string DeviceBindingName { get; set; } + public DeviceBindingCategory DeviceBindingCategory { get; set; } + public DeviceBinding DeviceBinding { get; set; } + } +} diff --git a/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs b/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs index dab85204..71b74723 100644 --- a/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs +++ b/UCR/ViewModels/ProfileViewModels/MappingViewModel.cs @@ -1,4 +1,8 @@ -using HidWizards.UCR.Core.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; namespace HidWizards.UCR.ViewModels.ProfileViewModels { @@ -6,16 +10,64 @@ public class MappingViewModel { public ProfileViewModel ProfileViewModel { get; } public Mapping Mapping { get; set; } + public ObservableCollection Plugins { get; set; } + public ObservableCollection DeviceBindings { get; set; } public MappingViewModel(ProfileViewModel profileViewModel, Mapping mapping) { ProfileViewModel = profileViewModel; Mapping = mapping; + DeviceBindings = new ObservableCollection(); + PopulateDeviceBindingsViewModels(); + PopulatePlugins(mapping); } public void Remove() { ProfileViewModel.RemoveMapping(this); } + + public void AddPlugin(Plugin plugin) + { + if (!Mapping.AddPlugin(plugin)) return; + + Plugins.Add(new PluginViewModel(this, plugin)); + if (Plugins.Count != 1) return; + + PopulateDeviceBindingsViewModels(); + } + + private void PopulateDeviceBindingsViewModels() + { + if (Mapping.Plugins.Count == 0) return; + + var plugin = Mapping.Plugins[0]; + for (var i = 0; i < plugin.GetInputCategories().Count; i++) + { + DeviceBindings.Add(new DeviceBindingViewModel() + { + DeviceBinding = Mapping.DeviceBindings[i], + DeviceBindingName = plugin.GetInputCategories()[i].Name, + DeviceBindingCategory = plugin.GetInputCategories()[i].Category + }); + } + } + + public void RemovePlugin(PluginViewModel pluginViewModel) + { + if (!Mapping.RemovePlugin(pluginViewModel.Plugin)) return; + + Plugins.Remove(pluginViewModel); + if (Plugins.Count == 0) DeviceBindings.Clear(); + } + + private void PopulatePlugins(Mapping mapping) + { + Plugins = new ObservableCollection(); + foreach (var mappingPlugin in mapping.Plugins) + { + Plugins.Add(new PluginViewModel(this, mappingPlugin)); + } + } } } diff --git a/UCR/ViewModels/ProfileViewModels/PluginViewModel.cs b/UCR/ViewModels/ProfileViewModels/PluginViewModel.cs new file mode 100644 index 00000000..4a4125d2 --- /dev/null +++ b/UCR/ViewModels/ProfileViewModels/PluginViewModel.cs @@ -0,0 +1,21 @@ +using HidWizards.UCR.Core.Models; + +namespace HidWizards.UCR.ViewModels.ProfileViewModels +{ + public class PluginViewModel + { + public MappingViewModel MappingViewModel { get; } + public Plugin Plugin { get; set; } + + public PluginViewModel(MappingViewModel mappingViewModel, Plugin plugin) + { + MappingViewModel = mappingViewModel; + Plugin = plugin; + } + + public void Remove() + { + MappingViewModel.RemovePlugin(this); + } + } +} diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index 2bd3a616..aa1986ef 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -37,7 +37,7 @@ - @@ -65,7 +65,7 @@ - + diff --git a/UCR/Views/Controls/PluginControl.xaml b/UCR/Views/Controls/PluginControl.xaml index b5b7f6e5..f38ef436 100644 --- a/UCR/Views/Controls/PluginControl.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -15,7 +15,7 @@ - @@ -114,7 +108,7 @@ - + @@ -124,9 +118,7 @@ - - - diff --git a/UCR/Views/ProfileViews/ProfileWindow.xaml.cs b/UCR/Views/ProfileViews/ProfileWindow.xaml.cs index a1bdc010..51bd382b 100644 --- a/UCR/Views/ProfileViews/ProfileWindow.xaml.cs +++ b/UCR/Views/ProfileViews/ProfileWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using HidWizards.UCR.Core; @@ -66,23 +67,41 @@ private void AddMapping_OnClick(object sender, RoutedEventArgs e) ProfileViewModel.AddMapping(title); MappingNameField.Text = ""; + MappingsListBox.SelectedIndex = MappingsListBox.Items.Count - 1; + MappingsListBox.ScrollIntoView(MappingsListBox.SelectedItem); + MappingNameField.Focus(); } #endregion - // TODO Add plugin + #region Plugin + + private void PopulatePluginsComboBox() + { + var pluginlist = ProfileViewModel.SelectedMapping.Mapping.GetPluginList(); + var plugins = new ObservableCollection(); + foreach (var plugin in pluginlist) + { + plugins.Add(new ComboBoxItemViewModel(plugin.PluginName, plugin)); + } + PluginsComboBox.ItemsSource = plugins; + PluginsComboBox.SelectedIndex = 0; + } + private void AddPlugin_OnClick(object sender, RoutedEventArgs e) { - var win = new PluginDialog(Context, "Add plugin", "Untitled"); - win.ShowDialog(); - if (!win.DialogResult.HasValue || !win.DialogResult.Value) return; - // TODO Check if plugin with same name exists - //Profile.AddNewPlugin(win.Plugin, win.TextResult); + var plugin = ((ComboBoxItemViewModel)PluginsComboBox.SelectedItem)?.Value; + if (plugin == null) return; + plugin.SetProfile(Profile); + + ProfileViewModel.SelectedMapping.AddPlugin(plugin); + PluginsListBox.Items.Refresh(); PluginsListBox.SelectedIndex = PluginsListBox.Items.Count - 1; PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); } + // TODO Rename private void RenamePlugin_OnClick(object sender, RoutedEventArgs e) { Plugin plugin; @@ -96,16 +115,8 @@ private void RenamePlugin_OnClick(object sender, RoutedEventArgs e) PluginsListBox.Items.Refresh(); PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); } - - // TODO Remove plugin - private void RemovePlugin_OnClick(object sender, RoutedEventArgs e) - { - Plugin plugin; - if (!GetSelectedItem(out plugin)) return; - //Profile.RemovePlugin(plugin); - PluginsListBox.Items.Refresh(); - PluginsListBox.ScrollIntoView(PluginsListBox.SelectedItem); - } + + #endregion private bool GetSelectedItem(out Plugin selection) { @@ -186,8 +197,14 @@ private string GetInheritedDeviceGroupName(DeviceIoType deviceIoType) private void MappingsListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { - var mappingViewModel = sender as MappingViewModel; + var listBox = sender as ListBox; + var mappingViewModel = listBox.SelectedItem as MappingViewModel; ProfileViewModel.SelectedMapping = mappingViewModel; + if (mappingViewModel == null) return; + + PopulatePluginsComboBox(); + PluginsListBox.ItemsSource = ProfileViewModel.SelectedMapping.Plugins; + PluginsListBox.Items.Refresh(); } } } From 291614e383c7ffc109b7473263f3457cd392a12e Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sat, 17 Mar 2018 17:34:17 +0100 Subject: [PATCH 14/30] Refactoring and cleanup --- UCR.Core/Models/Mapping.cs | 4 +++ UCR.Core/Models/Plugin.cs | 18 ++++++++----- UCR.Core/Models/Profile.cs | 7 +++-- UCR.Plugins/AxisToButton/AxisToButton.cs | 2 +- UCR.Plugins/ButtonToButton/ButtonToButton.cs | 2 +- UCR.Tests/ModelTests/ProfileTests.cs | 4 +-- UCR/Views/Controls/MappingControl.xaml | 2 +- UCR/Views/Controls/PluginControl.xaml.cs | 10 ------- UCR/Views/ProfileViews/ProfileWindow.xaml | 6 ++--- UCR/Views/ProfileViews/ProfileWindow.xaml.cs | 28 +++++++++----------- 10 files changed, 38 insertions(+), 45 deletions(-) diff --git a/UCR.Core/Models/Mapping.cs b/UCR.Core/Models/Mapping.cs index 1254a837..9f9297c3 100644 --- a/UCR.Core/Models/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -54,6 +54,10 @@ internal List GetPluginList() { var plugins = Profile.Context.GetPlugins(); plugins.Sort(); + if (Plugins.Count > 0) + { + plugins = plugins.FindAll(p => p.HasSameInputCategories(Plugins[0])); + } return plugins; } diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index bfc094b2..5fb1b386 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -8,7 +8,6 @@ namespace HidWizards.UCR.Core.Models public abstract class Plugin : IComparable { // Persistence - public string Title { get; set; } public string State { get; set; } public DeviceBinding Output { get; set; } @@ -74,12 +73,6 @@ internal void WriteOutput(long value) { Output.WriteOutput(value); } - - public void Rename(string title) - { - Title = title; - Profile.Context.ContextChanged(); - } public void PostLoad(Context context, Profile parentProfile) { @@ -108,5 +101,16 @@ public int CompareTo(Plugin other) { return string.Compare(PluginName, other.PluginName, StringComparison.Ordinal); } + + public bool HasSameInputCategories(Plugin other) + { + if (InputCategories.Count != other.GetInputCategories().Count) return false; + for (var i = 0; i < InputCategories.Count; i++) + { + if (InputCategories[i].Category != other.GetInputCategories()[i].Category) return false; + } + + return true; + } } } diff --git a/UCR.Core/Models/Profile.cs b/UCR.Core/Models/Profile.cs index 68f5f600..73347b12 100644 --- a/UCR.Core/Models/Profile.cs +++ b/UCR.Core/Models/Profile.cs @@ -185,15 +185,14 @@ public DeviceGroup GetDeviceGroup(DeviceIoType deviceIoType) #region Plugin - public bool AddNewPlugin(Mapping mapping, Plugin plugin, string title = "Untitled", string state = null) + public bool AddNewPlugin(Mapping mapping, Plugin plugin, string state = null) { - return AddPlugin(mapping, (Plugin)Activator.CreateInstance(plugin.GetType()), title, state); + return AddPlugin(mapping, (Plugin)Activator.CreateInstance(plugin.GetType()), state); } - public bool AddPlugin(Mapping mapping, Plugin plugin, string title = "Untitled", string state = null) + public bool AddPlugin(Mapping mapping, Plugin plugin, string state = null) { if (!Mappings.Contains(mapping)) return false; - if (plugin.Title == null) plugin.Title = title; plugin.State = state; plugin.Profile = this; mapping.Plugins.Add(plugin); diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index 4faec342..fcab802a 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -11,7 +11,7 @@ namespace HidWizards.UCR.Plugins.AxisToButton [Export(typeof(Plugin))] public class AxisToButton : Plugin { - public override string PluginName => "Axis to buttons"; + public override string PluginName => "Axis to button"; public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Momentary; protected override List InputCategories => new List() { diff --git a/UCR.Plugins/ButtonToButton/ButtonToButton.cs b/UCR.Plugins/ButtonToButton/ButtonToButton.cs index 91b2cf70..99b37162 100644 --- a/UCR.Plugins/ButtonToButton/ButtonToButton.cs +++ b/UCR.Plugins/ButtonToButton/ButtonToButton.cs @@ -8,7 +8,7 @@ namespace HidWizards.UCR.Plugins.ButtonToButton [Export(typeof(Plugin))] public class ButtonToButton : Plugin { - public override string PluginName => "Button to Button"; + public override string PluginName => "Button to button"; public override DeviceBindingCategory OutputCategory => DeviceBindingCategory.Momentary; protected override List InputCategories => new List() { diff --git a/UCR.Tests/ModelTests/ProfileTests.cs b/UCR.Tests/ModelTests/ProfileTests.cs index 810f14be..d26fb79a 100644 --- a/UCR.Tests/ModelTests/ProfileTests.cs +++ b/UCR.Tests/ModelTests/ProfileTests.cs @@ -64,12 +64,10 @@ public void RenameProfile() [Test] public void AddPlugin() { - var pluginName = "Test plugin"; var pluginState = "State"; - _profile.AddPlugin(_mapping, new ButtonToButton(), pluginName, pluginState); + _profile.AddPlugin(_mapping, new ButtonToButton(), pluginState); var plugin = _mapping.Plugins[0]; Assert.That(plugin, Is.Not.Null); - Assert.That(plugin.Title, Is.EqualTo(pluginName)); Assert.That(plugin.State, Is.EqualTo(pluginState)); Assert.That(plugin.Output, Is.Not.Null); Assert.That(plugin.Profile, Is.EqualTo(_profile)); diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index aa1986ef..0db67ba1 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -37,7 +37,7 @@ - diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index d35a4c96..354c7e8d 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -19,15 +19,5 @@ private void RemovePlugin_OnClick(object sender, RoutedEventArgs e) var plugin = button.DataContext as PluginViewModel; plugin?.Remove(); } - - public static T FindAncestor(DependencyObject dependencyObject) where T : DependencyObject - { - var parent = VisualTreeHelper.GetParent(dependencyObject); - - if (parent == null) return null; - - var parentT = parent as T; - return parentT ?? FindAncestor(parent); - } } } diff --git a/UCR/Views/ProfileViews/ProfileWindow.xaml b/UCR/Views/ProfileViews/ProfileWindow.xaml index b7777b09..baf018a1 100644 --- a/UCR/Views/ProfileViews/ProfileWindow.xaml +++ b/UCR/Views/ProfileViews/ProfileWindow.xaml @@ -40,8 +40,8 @@ - - + + @@ -121,7 +121,7 @@ + ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="PluginsListBox_OnSelectionChanged"> + + + + + + + From 581241de56b4f98a660466e11a4f83bf9fec0b78 Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 1 Apr 2018 22:50:22 +0200 Subject: [PATCH 21/30] Plugin GUI is now generated by plugin attributes --- UCR.Core/Attributes/PluginGuiAttribute.cs | 33 ++++++ UCR.Core/Models/Mapping.cs | 2 +- UCR.Core/Models/Plugin.cs | 107 ++++++++++++++---- UCR.Core/Models/PluginProperty.cs | 41 +++++++ UCR.Core/UCR.Core.csproj | 3 + UCR.Core/Utilities/Functions.cs | 23 ++++ UCR.Plugins/AxisToAxis/AxisToAxis.cs | 68 ++--------- UCR.Plugins/AxisToAxis/Resources.cs | 14 --- UCR.Plugins/AxisToAxis/Resources.xaml | 34 ------ UCR.Plugins/AxisToButton/AxisToButton.cs | 57 ++++------ UCR.Plugins/AxisToButton/Resources.cs | 14 --- UCR.Plugins/AxisToButton/Resources.xaml | 23 ---- UCR.Plugins/ButtonToAxis/ButtonToAxis.cs | 18 +-- UCR.Plugins/ButtonToAxis/Resources.cs | 14 --- UCR.Plugins/ButtonToAxis/Resources.xaml | 13 --- UCR.Plugins/ButtonToButton/ButtonToButton.cs | 18 ++- UCR.Plugins/ButtonToButton/Resources.cs | 14 --- UCR.Plugins/ButtonToButton/Resources.xaml | 9 -- UCR.Plugins/MouseToAxis/MouseToAxis.cs | 4 +- UCR.Plugins/MouseToAxis/Resources.cs | 14 --- UCR.Plugins/MouseToAxis/Resources.xaml | 9 -- UCR.Plugins/UCR.Plugins.csproj | 33 ------ UCR.Tests/ModelTests/AttributeTests.cs | 11 ++ UCR.Tests/ModelTests/PersistenceTests.cs | 1 + UCR.sln | 12 +- UCR/UCR.csproj | 1 + UCR/Views/Controls/MappingControl.xaml | 21 ++-- UCR/Views/Controls/PluginControl.xaml | 51 +++++++-- UCR/Views/Controls/PluginControl.xaml.cs | 10 +- .../Controls/PluginGuiTemplateSelector.cs | 39 +++++++ .../Controls/PluginViewTemplateSelector.cs | 13 ++- 31 files changed, 379 insertions(+), 345 deletions(-) create mode 100644 UCR.Core/Attributes/PluginGuiAttribute.cs create mode 100644 UCR.Core/Models/PluginProperty.cs create mode 100644 UCR.Core/Utilities/Functions.cs delete mode 100644 UCR.Plugins/AxisToAxis/Resources.cs delete mode 100644 UCR.Plugins/AxisToAxis/Resources.xaml delete mode 100644 UCR.Plugins/AxisToButton/Resources.cs delete mode 100644 UCR.Plugins/AxisToButton/Resources.xaml delete mode 100644 UCR.Plugins/ButtonToAxis/Resources.cs delete mode 100644 UCR.Plugins/ButtonToAxis/Resources.xaml delete mode 100644 UCR.Plugins/ButtonToButton/Resources.cs delete mode 100644 UCR.Plugins/ButtonToButton/Resources.xaml delete mode 100644 UCR.Plugins/MouseToAxis/Resources.cs delete mode 100644 UCR.Plugins/MouseToAxis/Resources.xaml create mode 100644 UCR/Views/Controls/PluginGuiTemplateSelector.cs diff --git a/UCR.Core/Attributes/PluginGuiAttribute.cs b/UCR.Core/Attributes/PluginGuiAttribute.cs new file mode 100644 index 00000000..4425652d --- /dev/null +++ b/UCR.Core/Attributes/PluginGuiAttribute.cs @@ -0,0 +1,33 @@ +using System; + +namespace HidWizards.UCR.Core.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class PluginGuiAttribute : Attribute + { + private string name; + private int rowOrder; + private int columnOrder; + + public PluginGuiAttribute(string name) + { + this.name = name; + rowOrder = 0; + columnOrder = 0; + } + + public virtual string Name => name; + + public virtual int RowOrder + { + get => rowOrder; + set => rowOrder = value; + } + + public virtual int ColumnOrder + { + get => columnOrder; + set => columnOrder = value; + } + } +} diff --git a/UCR.Core/Models/Mapping.cs b/UCR.Core/Models/Mapping.cs index 21c29208..6b8c08b8 100644 --- a/UCR.Core/Models/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -57,7 +57,7 @@ public void Update(long value) InputCache[0] = value; foreach (var plugin in Plugins) { - plugin.Update(InputCache); + plugin.Update(InputCache.ToArray()); } } diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index 57dca24c..f3d455f4 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -13,21 +13,22 @@ public abstract class Plugin : IComparable { // Persistence public string State { get; set; } - public List Outputs { get; set; } + public List Outputs { get; } // Runtime internal Profile Profile { get; set; } - private List inputCategories; - private List outputCategories; + private List _inputCategories; + private List _outputCategories; + private List> _guiMatrix; [XmlIgnore] public List InputCategories { get { - if (inputCategories != null) return inputCategories; - inputCategories = GetIODefinitions(DeviceIoType.Input); - return inputCategories; + if (_inputCategories != null) return _inputCategories; + _inputCategories = GetIODefinitions(DeviceIoType.Input); + return _inputCategories; } } @@ -36,13 +37,25 @@ public List OutputCategories { get { - if (outputCategories != null) return outputCategories; - outputCategories = GetIODefinitions(DeviceIoType.Output); - return outputCategories; + if (_outputCategories != null) return _outputCategories; + _outputCategories = GetIODefinitions(DeviceIoType.Output); + return _outputCategories; } } - internal string PluginName => GetPluginAttribute().Name; + [XmlIgnore] + public List> GuiMatrix + { + get + { + if (_guiMatrix != null) return _guiMatrix; + _guiMatrix = GetGuiMatrix(); + return _guiMatrix; + } + } + + [XmlIgnore] + public string PluginName => GetPluginAttribute().Name; public struct IODefinition { @@ -66,7 +79,7 @@ public virtual void OnActivate() } - public virtual void Update(List values) + public virtual void Update(params long[] values) { } @@ -84,17 +97,6 @@ protected void WriteOutput(int number, long value) #endregion - public Device GetDevice(DeviceBinding deviceBinding) - { - return Profile.GetDevice(deviceBinding); - } - - public List GetDeviceList(DeviceBinding deviceBinding) - { - return Profile.GetDeviceList(deviceBinding); - } - - public void SetProfile(Profile profile) { Profile = profile; @@ -108,17 +110,42 @@ public Plugin Duplicate() return newPlugin; } - protected void ContextChanged() + public void ContextChanged() { Profile?.Context?.ContextChanged(); } + #region Loading + public void PostLoad(Context context, Profile parentProfile) { SetProfile(parentProfile); + ZipDeviceBindingList(Outputs); Outputs.ForEach(o => o.DeviceIoType = DeviceIoType.Output); + } + private static void ZipDeviceBindingList(IList deviceBindings) + { + if (deviceBindings.Count == 0) return; + var split = deviceBindings.Count / 2; + for (var i = 0; i < split; i++) + { + deviceBindings[i].IsBound = deviceBindings[i + split].IsBound; + deviceBindings[i].DeviceGuid = deviceBindings[i + split].DeviceGuid; + deviceBindings[i].KeyType = deviceBindings[i + split].KeyType; + deviceBindings[i].KeyValue = deviceBindings[i + split].KeyValue; + deviceBindings[i].KeySubValue = deviceBindings[i + split].KeySubValue; + } + + for (var i = deviceBindings.Count - 1; i >= split; i--) + { + deviceBindings.Remove(deviceBindings[i]); + } + } + + #endregion + #region Comparison public int CompareTo(Plugin other) @@ -159,6 +186,40 @@ private List GetIODefinitions(DeviceIoType deviceIoType) }).ToList(); } + private List GetGuiProperties() + { + var properties = from p in GetType().GetProperties() + let attr = p.GetCustomAttributes(typeof(PluginGuiAttribute), true) + where attr.Length == 1 + select new { Property = p, Attribute = attr.First() as PluginGuiAttribute }; + + + return properties.Select(prop => new PluginProperty(this, prop.Property, prop.Attribute.Name, prop.Attribute.RowOrder, prop.Attribute.ColumnOrder)).ToList(); + } + + public List> GetGuiMatrix() + { + var result = new List>(); + var currentRow = new List(); + result.Add(currentRow); + + var guiProperties = GetGuiProperties(); + guiProperties.Sort(); + + foreach (var pluginProperty in guiProperties) + { + if (currentRow.Count != 0 && currentRow[0].RowOrder != pluginProperty.RowOrder) + { + currentRow = new List(); + result.Add(currentRow); + } + + currentRow.Add(pluginProperty); + } + + return result; + } + #endregion } } diff --git a/UCR.Core/Models/PluginProperty.cs b/UCR.Core/Models/PluginProperty.cs new file mode 100644 index 00000000..6d4e4798 --- /dev/null +++ b/UCR.Core/Models/PluginProperty.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace HidWizards.UCR.Core.Models +{ + public class PluginProperty : IComparable + { + public string Name { get; } + public Plugin Plugin { get; } + public int RowOrder { get; } + public int ColumnOrder { get; } + + public PropertyInfo PropertyInfo { get; } + public dynamic Property + { + get => PropertyInfo.GetValue(Plugin); + set + { + if (value.Equals(PropertyInfo.GetValue(Plugin))) return; + PropertyInfo.SetValue(Plugin, Convert.ChangeType(value, PropertyInfo.PropertyType)); + Plugin.ContextChanged(); + } + } + + public PluginProperty(Plugin plugin, PropertyInfo propertyInfo, string name, int rowOrder = 0, int columnOrder = 0) + { + Plugin = plugin; + PropertyInfo = propertyInfo; + Name = name; + RowOrder = rowOrder; + ColumnOrder = columnOrder; + } + + public int CompareTo(PluginProperty other) + { + return RowOrder.CompareTo(other.RowOrder); + } + } +} diff --git a/UCR.Core/UCR.Core.csproj b/UCR.Core/UCR.Core.csproj index f77bcfb7..3b2d9ec0 100644 --- a/UCR.Core/UCR.Core.csproj +++ b/UCR.Core/UCR.Core.csproj @@ -59,6 +59,7 @@ + @@ -73,6 +74,7 @@ + @@ -83,6 +85,7 @@ + diff --git a/UCR.Core/Utilities/Functions.cs b/UCR.Core/Utilities/Functions.cs new file mode 100644 index 00000000..c1f1929e --- /dev/null +++ b/UCR.Core/Utilities/Functions.cs @@ -0,0 +1,23 @@ +using System; + +namespace HidWizards.UCR.Core.Utilities +{ + public static class Functions + { + public static long ApplyRangeDeadZone(long value, int deadZonePercentage) + { + var gap = (deadZonePercentage / 100.0) * Constants.AxisMaxValue; + var remainder = Constants.AxisMaxValue - gap; + var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; + return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); + } + + public static long ApplyRangeSensitivity(long value, int sensitivity, bool linear) + { + var sensitivityPercent = (sensitivity / 100.0); + if (linear) return (long)(value * sensitivityPercent); + // TODO https://github.com/evilC/UCR/blob/master/Libraries/StickOps/StickOps.ahk#L60 + return value; + } + } +} diff --git a/UCR.Plugins/AxisToAxis/AxisToAxis.cs b/UCR.Plugins/AxisToAxis/AxisToAxis.cs index dcc6887e..5fe205e7 100644 --- a/UCR.Plugins/AxisToAxis/AxisToAxis.cs +++ b/UCR.Plugins/AxisToAxis/AxisToAxis.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; @@ -13,74 +11,32 @@ namespace HidWizards.UCR.Plugins.AxisToAxis [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class AxisToAxis : Plugin { + [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } + + [PluginGui("Linear", ColumnOrder = 3)] public bool Linear { get; set; } - private int _deadZoneValue; - private string _deadZone; - public string DeadZone - { - get { return _deadZone; } - set - { - SetIntValue(ref _deadZoneValue, value); - ContextChanged(); - _deadZone = value; - } - } + [PluginGui("Dead zone", ColumnOrder = 1)] + public int DeadZone { get; set; } - private int _sensitivityValue; - private string _sensitivity; - public string Sensitivity - { - get { return _sensitivity; } - set - { - SetIntValue(ref _sensitivityValue, value); - ContextChanged(); - _sensitivity = value; - } - } + [PluginGui("Sensitivity", ColumnOrder = 2)] + public int Sensitivity { get; set; } public AxisToAxis() { - DeadZone = "0"; - Sensitivity = "100"; + DeadZone = 0; + Sensitivity = 100; } - public override void Update(List values) + public override void Update(params long[] values) { var value = values[0]; if (Invert) value *= -1; - if (_deadZoneValue != 0) value = ApplyDeadZone(value); - if (_sensitivityValue != 100) value = ApplySensitivity(value); + if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, Linear); value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); WriteOutput(0, value); } - - private long ApplySensitivity(long value) - { - var sensitivityPercent = (_sensitivityValue / 100.0); - if (Linear) return (long) (value * sensitivityPercent); - // TODO https://github.com/evilC/UCR/blob/master/Libraries/StickOps/StickOps.ahk#L60 - return value; - } - - private long ApplyDeadZone(long value) - { - var gap = (_deadZoneValue / 100.0) * Constants.AxisMaxValue; - var remainder = Constants.AxisMaxValue - gap; - var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; - return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); - } - - private static void SetIntValue(ref int field, string value) - { - int result; - if (int.TryParse(value, out result)) - { - field = result; - } - } } } diff --git a/UCR.Plugins/AxisToAxis/Resources.cs b/UCR.Plugins/AxisToAxis/Resources.cs deleted file mode 100644 index 123fe91f..00000000 --- a/UCR.Plugins/AxisToAxis/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.AxisToAxis -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/AxisToAxis/Resources.xaml b/UCR.Plugins/AxisToAxis/Resources.xaml deleted file mode 100644 index 5d59fc79..00000000 --- a/UCR.Plugins/AxisToAxis/Resources.xaml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/AxisToButton/AxisToButton.cs b/UCR.Plugins/AxisToButton/AxisToButton.cs index afdbbf48..085975bf 100644 --- a/UCR.Plugins/AxisToButton/AxisToButton.cs +++ b/UCR.Plugins/AxisToButton/AxisToButton.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; @@ -10,54 +9,40 @@ namespace HidWizards.UCR.Plugins.AxisToButton { [Plugin("Axis to button")] [PluginInput(DeviceBindingCategory.Range, "Axis")] - [PluginOutput(DeviceBindingCategory.Momentary, "Button")] + [PluginOutput(DeviceBindingCategory.Momentary, "Button high")] + [PluginOutput(DeviceBindingCategory.Momentary, "Button low")] public class AxisToButton : Plugin { + [PluginGui("Invert", ColumnOrder = 0)] public bool Invert { get; set; } - private int _deadZoneValue; - private string _deadZone; - public string DeadZone - { - get { return _deadZone; } - set - { - SetIntValue(ref _deadZoneValue, value); - ContextChanged(); - _deadZone = value; - } - } + [PluginGui("Dead zone", ColumnOrder = 1)] + public int DeadZone { get; set; } - private long _direction = 0; - public AxisToButton() { - DeadZone = "30"; + DeadZone = 30; } - public override void Update(List values) + public override void Update(params long[] values) { var value = values[0]; if (Invert) value *= -1; - if (value < 0) value = 0; - value = Math.Sign(ApplyDeadZone(value)); - WriteOutput(0, value); - } - - private long ApplyDeadZone(long value) - { - var gap = (_deadZoneValue / 100.0) * Constants.AxisMaxValue; - var remainder = Constants.AxisMaxValue - gap; - var gapPercent = Math.Max(0, Math.Abs(value) - gap) / remainder; - return (long)(gapPercent * Constants.AxisMaxValue * Math.Sign(value)); - } - - private static void SetIntValue(ref int field, string value) - { - int result; - if (int.TryParse(value, out result)) + value = Math.Sign(Functions.ApplyRangeDeadZone(value,DeadZone)); + switch (value) { - field = result; + case 0: + WriteOutput(0, 0); + WriteOutput(1, 0); + break; + case 1: + WriteOutput(0, 1); + WriteOutput(1, 0); + break; + case -1: + WriteOutput(0, 0); + WriteOutput(1, 1); + break; } } } diff --git a/UCR.Plugins/AxisToButton/Resources.cs b/UCR.Plugins/AxisToButton/Resources.cs deleted file mode 100644 index 4ac556fe..00000000 --- a/UCR.Plugins/AxisToButton/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.AxisToButton -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/AxisToButton/Resources.xaml b/UCR.Plugins/AxisToButton/Resources.xaml deleted file mode 100644 index 9593ccc7..00000000 --- a/UCR.Plugins/AxisToButton/Resources.xaml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs index 9909ef81..e280345d 100644 --- a/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs +++ b/UCR.Plugins/ButtonToAxis/ButtonToAxis.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.Composition; -using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; using HidWizards.UCR.Core.Utilities; @@ -12,17 +10,21 @@ namespace HidWizards.UCR.Plugins.ButtonToAxis [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class ButtonToAxis : Plugin { - private long _direction = 0; + [PluginGui("Invert", ColumnOrder = 0)] + public bool Invert { get; set; } + + [PluginGui("Range target", ColumnOrder = 1)] + public int Range { get; set; } public ButtonToAxis() { - + Range = 100; } - // TODO Implement value to set - public override void Update(List values) + public override void Update(params long[] values) { - WriteOutput(0, values[0] * Constants.AxisMaxValue); + if (Invert) values[0] = values[0] * - 1; + WriteOutput(0, values[0] * (long)(Constants.AxisMaxValue * ( Range / 100.0 ))); } } } diff --git a/UCR.Plugins/ButtonToAxis/Resources.cs b/UCR.Plugins/ButtonToAxis/Resources.cs deleted file mode 100644 index bd3d1cff..00000000 --- a/UCR.Plugins/ButtonToAxis/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.ButtonToAxis -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/ButtonToAxis/Resources.xaml b/UCR.Plugins/ButtonToAxis/Resources.xaml deleted file mode 100644 index 8246e42c..00000000 --- a/UCR.Plugins/ButtonToAxis/Resources.xaml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/ButtonToButton/ButtonToButton.cs b/UCR.Plugins/ButtonToButton/ButtonToButton.cs index eb1aa98c..28937c93 100644 --- a/UCR.Plugins/ButtonToButton/ButtonToButton.cs +++ b/UCR.Plugins/ButtonToButton/ButtonToButton.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Attributes; using HidWizards.UCR.Core.Models; using HidWizards.UCR.Core.Models.Binding; @@ -10,9 +9,20 @@ namespace HidWizards.UCR.Plugins.ButtonToButton [PluginOutput(DeviceBindingCategory.Momentary, "Button")] public class ButtonToButton : Plugin { - public override void Update(List values) + + [PluginGui("Invert", ColumnOrder = 0, RowOrder = 0)] + public bool Invert { get; set; } + + public override void Update(params long[] values) { - WriteOutput(0, values[0]); + if (Invert) + { + WriteOutput(0, values[0] == 0 ? 1 : 0); + } + else + { + WriteOutput(0, values[0]); + } } } } diff --git a/UCR.Plugins/ButtonToButton/Resources.cs b/UCR.Plugins/ButtonToButton/Resources.cs deleted file mode 100644 index 3f27a335..00000000 --- a/UCR.Plugins/ButtonToButton/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.ButtonToButton -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/ButtonToButton/Resources.xaml b/UCR.Plugins/ButtonToButton/Resources.xaml deleted file mode 100644 index 81d928bc..00000000 --- a/UCR.Plugins/ButtonToButton/Resources.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/MouseToAxis/MouseToAxis.cs b/UCR.Plugins/MouseToAxis/MouseToAxis.cs index ba4cacbe..94cc7136 100644 --- a/UCR.Plugins/MouseToAxis/MouseToAxis.cs +++ b/UCR.Plugins/MouseToAxis/MouseToAxis.cs @@ -11,8 +11,10 @@ namespace HidWizards.UCR.Plugins.MouseToAxis [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class MouseToAxis: Plugin { + [PluginGui("Invert", RowOrder = 0, ColumnOrder = 0)] + public bool Invert { get; set; } - public override void Update(List values) + public override void Update(params long[] values) { WriteOutput(0, values[0]*(Constants.AxisMaxValue/1000)); } diff --git a/UCR.Plugins/MouseToAxis/Resources.cs b/UCR.Plugins/MouseToAxis/Resources.cs deleted file mode 100644 index e53cefca..00000000 --- a/UCR.Plugins/MouseToAxis/Resources.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel.Composition; -using System.Windows; - -namespace HidWizards.UCR.Plugins.MouseToAxis -{ - [Export(typeof(ResourceDictionary))] - public partial class Resources : ResourceDictionary - { - public Resources() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/UCR.Plugins/MouseToAxis/Resources.xaml b/UCR.Plugins/MouseToAxis/Resources.xaml deleted file mode 100644 index 40a9b758..00000000 --- a/UCR.Plugins/MouseToAxis/Resources.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 2162811e..39c7cab5 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -47,15 +47,10 @@ - - - - - @@ -63,34 +58,6 @@ {676d3228-c3f0-4be7-8951-b83f7a16cea7} UCR.Core - - {2F2E9A0C-C97C-4AC7-A598-03D334B2D827} - UCR - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - diff --git a/UCR.Tests/ModelTests/AttributeTests.cs b/UCR.Tests/ModelTests/AttributeTests.cs index 85900403..2883e04e 100644 --- a/UCR.Tests/ModelTests/AttributeTests.cs +++ b/UCR.Tests/ModelTests/AttributeTests.cs @@ -21,5 +21,16 @@ public void ButtonToButtonIoTest() Assert.AreEqual(outputs[0].Category, DeviceBindingCategory.Momentary); Assert.AreEqual(outputs[0].Name, "Button"); } + + [Test] + public void ButtonToButtonGuiMatrixTest() + { + var plugin = new ButtonToButton(); + + var guiMatrix = plugin.GetGuiMatrix(); + var invertProperty = guiMatrix[0][0]; + + Assert.AreEqual(invertProperty.Name, "Invert"); + } } } diff --git a/UCR.Tests/ModelTests/PersistenceTests.cs b/UCR.Tests/ModelTests/PersistenceTests.cs index a0ac544f..04f9f870 100644 --- a/UCR.Tests/ModelTests/PersistenceTests.cs +++ b/UCR.Tests/ModelTests/PersistenceTests.cs @@ -96,6 +96,7 @@ public void MappingContext() Assert.That(newMapping.Title, Is.EqualTo(mapping.Title)); Assert.That(newMapping.Plugins.Count, Is.EqualTo(mapping.Plugins.Count)); Assert.That(newMapping.Guid, Is.EqualTo(mapping.Guid)); + Assert.That(newMapping.Plugins[0].Outputs.Count, Is.EqualTo(1)); for (var j = 0; j < mapping.DeviceBindings.Count; j++) { diff --git a/UCR.sln b/UCR.sln index 1f1fe218..8e30ab32 100644 --- a/UCR.sln +++ b/UCR.sln @@ -1,11 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ".build", ".\build\.build.csproj", "{199C7B20-7300-4F41-877E-15C100097EAC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ".build", "build\.build.csproj", "{199C7B20-7300-4F41-877E-15C100097EAC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UCR", "UCR\UCR.csproj", "{2F2E9A0C-C97C-4AC7-A598-03D334B2D827}" + ProjectSection(ProjectDependencies) = postProject + {35B5A93F-03EA-445F-BDF6-2B37C256578F} = {35B5A93F-03EA-445F-BDF6-2B37C256578F} + EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UCR.Tests", "UCR.Tests\UCR.Tests.csproj", "{F401B642-1E27-44C2-BFFA-5F3CFBFD14BD}" EndProject @@ -41,4 +44,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {141F569E-6EF9-4F6A-9868-4828B35B51E5} + EndGlobalSection EndGlobal diff --git a/UCR/UCR.csproj b/UCR/UCR.csproj index c77fd8cd..8a86bc7f 100644 --- a/UCR/UCR.csproj +++ b/UCR/UCR.csproj @@ -108,6 +108,7 @@ PluginControl.xaml + diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index 0db67ba1..7cc85e4a 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -37,17 +37,14 @@ - - + + - - - - - + + - - + + diff --git a/UCR/Views/Controls/PluginControl.xaml b/UCR/Views/Controls/PluginControl.xaml index 2d2c555f..8b1bb91d 100644 --- a/UCR/Views/Controls/PluginControl.xaml +++ b/UCR/Views/Controls/PluginControl.xaml @@ -10,6 +10,7 @@ x:Name="PluginViewName" Margin="0,0,0,5"> + - - - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UCR/Views/Controls/PluginControl.xaml.cs b/UCR/Views/Controls/PluginControl.xaml.cs index 354c7e8d..f138f5b9 100644 --- a/UCR/Views/Controls/PluginControl.xaml.cs +++ b/UCR/Views/Controls/PluginControl.xaml.cs @@ -1,5 +1,7 @@ -using System.Windows; +using System.Text.RegularExpressions; +using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media; using HidWizards.UCR.ViewModels.ProfileViewModels; @@ -19,5 +21,11 @@ private void RemovePlugin_OnClick(object sender, RoutedEventArgs e) var plugin = button.DataContext as PluginViewModel; plugin?.Remove(); } + + private void NumberValidationTextBox(object sender, TextCompositionEventArgs e) + { + Regex regex = new Regex("[^0-9]+"); + e.Handled = regex.IsMatch(e.Text); + } } } diff --git a/UCR/Views/Controls/PluginGuiTemplateSelector.cs b/UCR/Views/Controls/PluginGuiTemplateSelector.cs new file mode 100644 index 00000000..09e96088 --- /dev/null +++ b/UCR/Views/Controls/PluginGuiTemplateSelector.cs @@ -0,0 +1,39 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using HidWizards.UCR.Core.Models; + +namespace HidWizards.UCR.Views.Controls +{ + public class PluginGuiTemplateSelector : DataTemplateSelector + { + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + var element = container as FrameworkElement; + + if (element == null || !(item is PluginProperty)) return null; + var pluginProperty = (PluginProperty) item; + + switch (Type.GetTypeCode(pluginProperty.PropertyInfo.PropertyType)) + { + case TypeCode.Boolean: + return element.FindResource("BooleanTemplate") as DataTemplate; + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + return element.FindResource("NumberTemplate") as DataTemplate; + case TypeCode.String: + return element.FindResource("StringTemplate") as DataTemplate; + default: + return null; + } + + + } + } +} \ No newline at end of file diff --git a/UCR/Views/Controls/PluginViewTemplateSelector.cs b/UCR/Views/Controls/PluginViewTemplateSelector.cs index 9b436b21..f8671af9 100644 --- a/UCR/Views/Controls/PluginViewTemplateSelector.cs +++ b/UCR/Views/Controls/PluginViewTemplateSelector.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System; +using System.Windows; using System.Windows.Controls; namespace HidWizards.UCR.Views.Controls @@ -17,7 +18,15 @@ public PluginViewTemplateSelector() public override DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) { if (item == null) return PluginTemplate; - PluginTemplate = (DataTemplate)Window.FindResource(item.GetType().Name); + try + { + PluginTemplate = (DataTemplate)Window.FindResource(item.GetType().Name); + } + catch (ResourceReferenceKeyNotFoundException) + { + return null; + } + return PluginTemplate; } } From 3209cc28997645e009bb8cfd8a8464d807c4d83b Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Sun, 1 Apr 2018 23:46:51 +0200 Subject: [PATCH 22/30] Unfinished plugins can be disabled --- UCR.Core/Attributes/PluginAttribute.cs | 8 ++++++ UCR.Core/Context.cs | 2 +- UCR.Core/Models/Plugin.cs | 2 ++ UCR.Core/Models/Profile.cs | 8 ------ UCR.Plugins/AxisToMouse/AxisToMouse.cs | 39 ++++++++++++++++++++++++++ UCR.Plugins/MouseToAxis/MouseToAxis.cs | 2 +- UCR.Plugins/UCR.Plugins.csproj | 1 + 7 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 UCR.Plugins/AxisToMouse/AxisToMouse.cs diff --git a/UCR.Core/Attributes/PluginAttribute.cs b/UCR.Core/Attributes/PluginAttribute.cs index 39416acd..d203b178 100644 --- a/UCR.Core/Attributes/PluginAttribute.cs +++ b/UCR.Core/Attributes/PluginAttribute.cs @@ -5,12 +5,20 @@ namespace HidWizards.UCR.Core.Attributes public class PluginAttribute : Attribute { private string name; + private bool disabled; public PluginAttribute(string name) { this.name = name; + disabled = false; } public virtual string Name => name; + + public virtual bool Disabled + { + get => disabled; + set => disabled = value; + } } } diff --git a/UCR.Core/Context.cs b/UCR.Core/Context.cs index cd3dacbf..6bf5ff3b 100644 --- a/UCR.Core/Context.cs +++ b/UCR.Core/Context.cs @@ -90,7 +90,7 @@ public void SetActiveProfileCallback(Action profileActivated) public List GetPlugins() { - return PluginManager.Plugins; + return PluginManager.Plugins.Where(p => !p.IsDisabled).ToList(); } public void ContextChanged() diff --git a/UCR.Core/Models/Plugin.cs b/UCR.Core/Models/Plugin.cs index f3d455f4..bbd81b6b 100644 --- a/UCR.Core/Models/Plugin.cs +++ b/UCR.Core/Models/Plugin.cs @@ -56,6 +56,8 @@ public List> GuiMatrix [XmlIgnore] public string PluginName => GetPluginAttribute().Name; + [XmlIgnore] + public bool IsDisabled => GetPluginAttribute().Disabled; public struct IODefinition { diff --git a/UCR.Core/Models/Profile.cs b/UCR.Core/Models/Profile.cs index cdc1040a..c456bebb 100644 --- a/UCR.Core/Models/Profile.cs +++ b/UCR.Core/Models/Profile.cs @@ -247,14 +247,6 @@ private Guid GetDeviceGroupGuid(DeviceIoType deviceIoType) } } - public List GetAncestry() - { - var result = new List(); - if (ParentProfile != null) result.AddRange(ParentProfile.GetAncestry()); - result.Add(this); - return result; - } - #endregion internal void PostLoad(Context context, Profile parentProfile = null) diff --git a/UCR.Plugins/AxisToMouse/AxisToMouse.cs b/UCR.Plugins/AxisToMouse/AxisToMouse.cs new file mode 100644 index 00000000..efd69360 --- /dev/null +++ b/UCR.Plugins/AxisToMouse/AxisToMouse.cs @@ -0,0 +1,39 @@ +using System; +using HidWizards.UCR.Core.Attributes; +using HidWizards.UCR.Core.Models; +using HidWizards.UCR.Core.Models.Binding; +using HidWizards.UCR.Core.Utilities; + +namespace HidWizards.UCR.Plugins.AxisToMouse +{ + [Plugin("Axis to mouse", Disabled = true)] + [PluginInput(DeviceBindingCategory.Range, "Axis")] + [PluginOutput(DeviceBindingCategory.Delta, "Mouse")] + public class AxisToMouse : Plugin + { + [PluginGui("Invert", ColumnOrder = 0)] + public bool Invert { get; set; } + + [PluginGui("Dead zone", ColumnOrder = 1)] + public int DeadZone { get; set; } + + [PluginGui("Sensitivity", ColumnOrder = 2)] + public int Sensitivity { get; set; } + + public AxisToMouse() + { + DeadZone = 0; + Sensitivity = 1; + } + + public override void Update(params long[] values) + { + var value = values[0]; + if (Invert) value *= -1; + if (DeadZone != 0) value = Functions.ApplyRangeDeadZone(value, DeadZone); + if (Sensitivity != 100) value = Functions.ApplyRangeSensitivity(value, Sensitivity, false); + value = Math.Min(Math.Max(value, Constants.AxisMinValue), Constants.AxisMaxValue); + WriteOutput(0, value); + } + } +} diff --git a/UCR.Plugins/MouseToAxis/MouseToAxis.cs b/UCR.Plugins/MouseToAxis/MouseToAxis.cs index 94cc7136..89456ead 100644 --- a/UCR.Plugins/MouseToAxis/MouseToAxis.cs +++ b/UCR.Plugins/MouseToAxis/MouseToAxis.cs @@ -6,7 +6,7 @@ namespace HidWizards.UCR.Plugins.MouseToAxis { - [Plugin("Mouse to Axis")] + [Plugin("Mouse to Axis", Disabled = true)] [PluginInput(DeviceBindingCategory.Delta, "Mouse axis")] [PluginOutput(DeviceBindingCategory.Range, "Axis")] public class MouseToAxis: Plugin diff --git a/UCR.Plugins/UCR.Plugins.csproj b/UCR.Plugins/UCR.Plugins.csproj index 39c7cab5..a57d9f9c 100644 --- a/UCR.Plugins/UCR.Plugins.csproj +++ b/UCR.Plugins/UCR.Plugins.csproj @@ -48,6 +48,7 @@ + From 5074dd35149bf7314d543df3174ccfedc5479bec Mon Sep 17 00:00:00 2001 From: Kai Ejler Rasmussen Date: Mon, 2 Apr 2018 21:01:51 +0200 Subject: [PATCH 23/30] Overriding parent mappings implemented --- UCR.Core/Managers/SubscriptionsManager.cs | 24 +++++++------- UCR.Core/Models/Mapping.cs | 32 +++++++++++++++++++ .../Subscription/MappingSubscription.cs | 8 +++-- .../Models/Subscription/SubscriptionState.cs | 27 ++++++++++++++-- UCR/Views/Controls/MappingControl.xaml | 2 +- 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/UCR.Core/Managers/SubscriptionsManager.cs b/UCR.Core/Managers/SubscriptionsManager.cs index 92933d85..c836b979 100644 --- a/UCR.Core/Managers/SubscriptionsManager.cs +++ b/UCR.Core/Managers/SubscriptionsManager.cs @@ -73,25 +73,24 @@ public bool DeactivateProfile() foreach (var mappingSubscription in state.MappingSubscriptions) { + if (mappingSubscription.Overriden) continue; + foreach (var deviceBindingSubscription in mappingSubscription.DeviceBindingSubscriptions) { success &= UnsubscribeDeviceBindingInput(state, deviceBindingSubscription); } - } - - foreach (var deviceSubscription in state.OutputDeviceSubscriptions) - { - success &= UnsubscribeOutput(state, deviceSubscription); - } - foreach (var mappingSubscription in state.MappingSubscriptions) - { foreach (var pluginSubscription in mappingSubscription.PluginSubscriptions) { pluginSubscription.Plugin.OnDeactivate(); } } + foreach (var deviceSubscription in state.OutputDeviceSubscriptions) + { + success &= UnsubscribeOutput(state, deviceSubscription); + } + _context.IOController.SetProfileState(state.StateGuid, false); SubscriptionState = null; @@ -134,11 +133,8 @@ private bool PopulateSubscriptionStateForProfile(SubscriptionState state, Profil } } } - - foreach (var profileMapping in profile.Mappings) - { - state.AddMapping(profileMapping, profile, profileOutputDevices); - } + + state.AddMappings(profile, profileOutputDevices); return success; } @@ -158,6 +154,8 @@ private bool ActivateSubscriptionState(SubscriptionState state) foreach (var mappingSubscription in state.MappingSubscriptions) { + if (mappingSubscription.Overriden) continue; + mappingSubscription.Mapping.PrepareMapping(); foreach (var deviceBindingSubscription in mappingSubscription.DeviceBindingSubscriptions) diff --git a/UCR.Core/Models/Mapping.cs b/UCR.Core/Models/Mapping.cs index 6b8c08b8..124231f6 100644 --- a/UCR.Core/Models/Mapping.cs +++ b/UCR.Core/Models/Mapping.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Xml.Serialization; using System.Xml.XPath; using HidWizards.UCR.Core.Models.Binding; @@ -17,6 +18,16 @@ public class Mapping internal Profile Profile { get; set; } private List InputCache { get; set; } + [XmlIgnore] + public string FullTitle + { + get + { + var mapping = GetOverridenMapping(); + return mapping != null ? $"{Title} (Overrides {GetOverridenMapping().Profile.Title})" : Title; + } + } + public Mapping() { Guid = Guid.NewGuid(); @@ -51,6 +62,27 @@ internal void PrepareMapping() } } + internal Mapping GetOverridenMapping() + { + var list = new List(); + var parentProfile = Profile.ParentProfile; + if (parentProfile != null) list.AddRange(parentProfile.Mappings); + + while (list.Count > 0) + { + var mapping = list[0]; + list.RemoveAt(0); + if (string.Compare(Title, mapping.Title, StringComparison.CurrentCultureIgnoreCase) == 0) + { + return mapping; + } + parentProfile = parentProfile?.ParentProfile; + if (parentProfile != null) list.AddRange(parentProfile.Mappings); + } + + return null; + } + // TODO Add Guid to distinguish devicebindings public void Update(long value) { diff --git a/UCR.Core/Models/Subscription/MappingSubscription.cs b/UCR.Core/Models/Subscription/MappingSubscription.cs index 8c4f34c5..417a0659 100644 --- a/UCR.Core/Models/Subscription/MappingSubscription.cs +++ b/UCR.Core/Models/Subscription/MappingSubscription.cs @@ -5,13 +5,15 @@ namespace HidWizards.UCR.Core.Models.Subscription { public class MappingSubscription { - public Mapping Mapping { get; set; } - public List DeviceBindingSubscriptions { get; set; } - public List PluginSubscriptions { get; set; } + public Mapping Mapping { get; } + public List DeviceBindingSubscriptions { get; } + public List PluginSubscriptions { get; } + public bool Overriden { get; set; } public MappingSubscription(Profile profile, Mapping mapping, Guid subscriptionStateGuid, List profileOutputDevices) { Mapping = mapping; + Overriden = false; DeviceBindingSubscriptions = new List(); foreach (var mappingDeviceBinding in Mapping.DeviceBindings) { diff --git a/UCR.Core/Models/Subscription/SubscriptionState.cs b/UCR.Core/Models/Subscription/SubscriptionState.cs index cab963f6..12f26cb6 100644 --- a/UCR.Core/Models/Subscription/SubscriptionState.cs +++ b/UCR.Core/Models/Subscription/SubscriptionState.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace HidWizards.UCR.Core.Models.Subscription { @@ -29,10 +28,32 @@ public DeviceSubscription AddOutputDevice(Device device, Profile profile) OutputDeviceSubscriptions.Add(deviceSubscription); return deviceSubscription; } + + public void AddMappings(Profile profile, List profileOutputDevices) + { + var profileMappings = new List(); + + foreach (var profileMapping in profile.Mappings) + { + profileMappings.Add(new MappingSubscription(profile, profileMapping, StateGuid, profileOutputDevices)); + } + + OverrideParentMappings(profileMappings); + MappingSubscriptions.AddRange(profileMappings); + } - public void AddMapping(Mapping mapping, Profile profile, List profileOutputDevices) + private void OverrideParentMappings(List profileMappingSubscriptions) { - MappingSubscriptions.Add(new MappingSubscription(profile, mapping, StateGuid, profileOutputDevices)); + foreach (var profileMappingSubscription in profileMappingSubscriptions) + { + foreach (var subscription in MappingSubscriptions) + { + if (profileMappingSubscription.Mapping.Title.Equals(subscription.Mapping.Title)) + { + subscription.Overriden = true; + } + } + } } } } diff --git a/UCR/Views/Controls/MappingControl.xaml b/UCR/Views/Controls/MappingControl.xaml index 7cc85e4a..14a1f2e7 100644 --- a/UCR/Views/Controls/MappingControl.xaml +++ b/UCR/Views/Controls/MappingControl.xaml @@ -13,7 +13,7 @@ -