Skip to content

Commit

Permalink
[ConnectorIdParser] Connector data key names are truncated if TouchPo…
Browse files Browse the repository at this point in the history
…rtalOptions.ActionDataIdSeparator is set, just like action/connector data; Fix that the "pc_plugin-name_" part wasn't properly stripped from the "actual" connector ID.
  • Loading branch information
mpaperno committed Jul 18, 2022
1 parent 85e5622 commit bd3962a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ for how to update (but now you can also `message.Data.TryGetValue("myDataId", ou

Since `oddbear's` TouchPortalSDK v 0.30.0 release version, the paths have diverged further, most notably in the handling of TP Connectors.

### New Features
### New Features & Change Log

#### v 1.45.0
Both changes affect the feature which parses the "Long" connector ID from the short ID notification events into individual key/value fields (see notes for v0.43.0-mp below).
* Connector data key names are now truncated if `TouchPortalOptions.ActionDataIdSeparator` is set, just like action/connector data keys.
* Fix that the "pc_plugin-name_" part wasn't properly stripped from the "actual" connector ID.

#### v 1.44.0
* Add TP API v6 `parentGroup` parameter for dynamic state creation.
Expand Down
17 changes: 10 additions & 7 deletions TouchPortalSDK/Configuration/ConnectorIdParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TouchPortalSDK.Messages.Models;

namespace TouchPortalSDK.Configuration
Expand Down Expand Up @@ -31,22 +29,27 @@ public ConnectorIdParser(string connectorId, string pluginId = null)
{
var values = connectorId?.Split('|', StringSplitOptions.RemoveEmptyEntries);
// get our actual connector id
ConnectorIdPart = values.FirstOrDefault();
ConnectorIdPart = values.Length > 0 ? values[0] : null;
if (string.IsNullOrWhiteSpace(ConnectorIdPart))
return;

if (!string.IsNullOrWhiteSpace(pluginId))
ConnectorIdPart.Replace("pc_" + pluginId + "_", "");
ConnectorIdPart = ConnectorIdPart.Replace("pc_" + pluginId + "_", "");

for (int i = 1, e = values.Length; i < e; ++i) {
var keyVal = values[i].Split('=', StringSplitOptions.RemoveEmptyEntries);
var len = keyVal.Length;
if (len == 0)
continue;
var key = keyVal[0];
if (TouchPortalOptions.ActionDataIdSeparator != '\0')
key = key.Split(TouchPortalOptions.ActionDataIdSeparator, StringSplitOptions.RemoveEmptyEntries)[^1];
if (len == 2)
_kvPairs.Add(keyVal[0], keyVal[1]);
_kvPairs.Add(key, keyVal[1]);
else if (len == 1)
_kvPairs.Add(keyVal[0], "");
_kvPairs.Add(key, "");
else if (len > 2)
_kvPairs.Add(keyVal[0], string.Join('=', keyVal[1..^0]));
_kvPairs.Add(key, string.Join('=', keyVal[1..^0]));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions TouchPortalSDK/TouchPortalSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.44.2</Version>
<Version>1.45.0</Version>
<FileVersion>1.45.0.0</FileVersion>
<Authors>Maxim Paperno, Oddbjørn U. Bakke</Authors>
<PackageProjectUrl>https://github.com/mpaperno/TouchPortal-CS-API</PackageProjectUrl>
<RepositoryUrl>https://github.com/mpaperno/TouchPortal-CS-API.git</RepositoryUrl>
Expand All @@ -26,7 +27,6 @@
<SignAssembly>True</SignAssembly>
<ErrorReport>none</ErrorReport>
<AssemblyOriginatorKeyFile>signing_key.snk</AssemblyOriginatorKeyFile>
<FileVersion>1.44.2.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down

0 comments on commit bd3962a

Please sign in to comment.