Skip to content

Commit

Permalink
v3.1
Browse files Browse the repository at this point in the history
- Updated Logger class to include process name and thread id
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio
  • Loading branch information
BarRaider committed Nov 29, 2020
1 parent 181b4ba commit 0e8634f
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 15 deletions.
4 changes: 4 additions & 0 deletions NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
**Author's website and contact information:** [https://barraider.com](https://barraider.com)
** Samples of plugins using this framework: [Samples][1]

### Version 3.1 is out!
- Updated Logger class to include process name and thread id
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio

### Version 3.0 is out!
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
- Removed obsolete MD5 functions, use SHA512 functions instead
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio - Automatically creates a project with all the files needed to compile a plugin
* [Profiles](https://barraider.com/profiles) Downloadable empty profiles for the XL (32-key), Classic (15-key), Mini (6-key) and Mobile devices at https://barraider.com/profiles

### Version 3.1 is out!
- Updated Logger class to include process name and thread id
- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio

### Version 3.0 is out!
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
- Removed obsolete MD5 functions, use SHA512 functions instead
Expand Down Expand Up @@ -310,6 +314,18 @@ private void SetGlobalSettings()
```

# Change Log
### Version 3.1 is out!
- Updated Logger class to include process name and thread id

### Version 3.0 is out!
- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
- Removed obsolete MD5 functions, use SHA512 functions instead
- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
- New `Tools.FormatBytes` function converts bytes to human-readable value
- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
- Updated dependency packages to latest versions
- Bug fix where FileNameProperty attribute

### Version 2.7 is out!
- Fully wrapped all Stream Deck events (All part of the SDConneciton class). See ***"Subscribing to events"*** section below
- Added extension methods for multiple classes related to brushes/colors
Expand Down
30 changes: 29 additions & 1 deletion barraider-sdtools/Backend/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public void Run(StreamDeckOptions options)
connection.OnKeyUp += Connection_OnKeyUp;
connection.OnWillAppear += Connection_OnWillAppear;
connection.OnWillDisappear += Connection_OnWillDisappear;

// Settings changed
connection.OnDidReceiveSettings += Connection_OnDidReceiveSettings;
connection.OnDidReceiveGlobalSettings += Connection_OnDidReceiveGlobalSettings;

// Start the connection
connection.Run();
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Loaded: UUID: {pluginUUID} Device Info: {deviceInfo}");
#endif
Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin version: {deviceInfo.Plugin.Version}");
Logger.Instance.LogMessage(TracingLevel.INFO, "Connecting to Stream Deck");

Expand All @@ -76,6 +79,10 @@ private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEv
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Keydown: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (instances.ContainsKey(e.Event.Context))
{
KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
Expand All @@ -95,6 +102,10 @@ private async void Connection_OnKeyUp(object sender, StreamDeckEventReceivedEven
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Keyup: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (instances.ContainsKey(e.Event.Context))
{
KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
Expand Down Expand Up @@ -133,6 +144,10 @@ private async void Connection_OnWillAppear(object sender, StreamDeckEventReceive
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillAppear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (supportedActions.ContainsKey(e.Event.Action))
{
try
Expand Down Expand Up @@ -167,6 +182,10 @@ private async void Connection_OnWillDisappear(object sender, StreamDeckEventRece
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillDisappear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (instances.ContainsKey(e.Event.Context))
{
instances[e.Event.Context].Destroy();
Expand All @@ -185,6 +204,10 @@ private async void Connection_OnDidReceiveSettings(object sender, StreamDeckEven
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveSettings: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (instances.ContainsKey(e.Event.Context))
{
instances[e.Event.Context].ReceivedSettings(JObject.FromObject(e.Event.Payload).ToObject<ReceivedSettingsPayload>());
Expand All @@ -202,6 +225,10 @@ private async void Connection_OnDidReceiveGlobalSettings(object sender, StreamDe
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveGlobalSettings: Settings: {e.Event.Payload?.ToStringEx()}");
#endif

var globalSettings = JObject.FromObject(e.Event.Payload).ToObject<ReceivedGlobalSettingsPayload>();
foreach (string key in instances.Keys)
{
Expand Down Expand Up @@ -235,5 +262,6 @@ private KeyCoordinates GenerateKeyCoordinates(Coordinates coordinates)

return new KeyCoordinates() { Column = coordinates.Columns, Row = coordinates.Rows };
}

}
}
15 changes: 14 additions & 1 deletion barraider-sdtools/Backend/SDWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class SDWrapper
/// <param name="supportedActionIds"></param>
public static void Run(string[] args, PluginActionId[] supportedActionIds)
{
Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin Loading - {supportedActionIds.Length} Actions Found");
Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin [{GetExeName()}] Loading - {supportedActionIds.Length} Actions Found");
System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

#if DEBUG
Expand Down Expand Up @@ -83,5 +83,18 @@ private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionE
{
Logger.Instance.LogMessage(TracingLevel.FATAL, $"Unhandled Exception: {e.ExceptionObject}");
}

private static string GetExeName()
{
try
{
return System.IO.Path.GetFileNameWithoutExtension(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.WARN, $"GetExeName failed {ex}");
}
return String.Empty;
}
}
}
9 changes: 9 additions & 0 deletions barraider-sdtools/StreamDeckInfo/StreamDeckApplicationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@ public class StreamDeckApplicationInfo
/// </summary>
[JsonProperty(PropertyName = "version")]
public string Version { get; private set; }

/// <summary>
/// Shows class information as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Language: {Language} Platform: {Platform} Version: {Version}";
}
}
}
16 changes: 15 additions & 1 deletion barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public enum StreamDeckDeviceType
/// <summary>
/// StreamDeck Mobile version
/// </summary>
StreamDeckMobile = 3
StreamDeckMobile = 3,

/// <summary>
/// Corsair G-Keys version
/// </summary>
CorsairGKeys = 4
}

/// <summary>
Expand Down Expand Up @@ -68,5 +73,14 @@ public StreamDeckDeviceInfo(StreamDeckDeviceSize size, StreamDeckDeviceType type
Type = type;
Id = deviceId;
}

/// <summary>
/// Shows class information as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Id: {Id} Type: {Type} Size: {Size?.ToString()}";
}
}
}
9 changes: 9 additions & 0 deletions barraider-sdtools/StreamDeckInfo/StreamDeckDeviceSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ public StreamDeckDeviceSize(int rows, int cols)
Rows = rows;
Cols = cols;
}

/// <summary>
/// Shows class information as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Rows: {Rows} Columns: {Cols}";
}
}
}
31 changes: 31 additions & 0 deletions barraider-sdtools/StreamDeckInfo/StreamDeckInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,36 @@ public class StreamDeckInfo
/// </summary>
[JsonProperty(PropertyName = "devicePixelRatio")]
public int DevicePixelRatio { get; private set; }

/// <summary>
/// Shows class information as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
if (Devices != null)
{
sb.Append("Devices:\n");
for (int device = 0; device < Devices.Length; device++)
{
if (Devices[device] != null)
{
sb.Append($"[{Devices[device]}]\n");
}
}
}

if (Application != null)
{
sb.Append($"ApplicationInfo: {Application}\n");
}

if (Plugin != null)
{
sb.Append($"PluginInfo: {Plugin}\n");
}
return sb.ToString();
}
}
}
9 changes: 9 additions & 0 deletions barraider-sdtools/StreamDeckInfo/StreamDeckPluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ public class StreamDeckPluginInfo
/// </summary>
[JsonProperty(PropertyName = "version")]
public string Version { get; private set; }

/// <summary>
/// Shows class information as string
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Version: {Version}";
}
}
}
2 changes: 1 addition & 1 deletion barraider-sdtools/Tools/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Logger Instance
private Logger()
{
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "pluginlog.log", ArchiveEvery=NLog.Targets.FileArchivePeriod.Day, MaxArchiveFiles=10, ArchiveFileName="logs/log.{###}.log", ArchiveNumbering=NLog.Targets.ArchiveNumberingMode.Rolling };
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "pluginlog.log", ArchiveEvery=NLog.Targets.FileArchivePeriod.Day, MaxArchiveFiles=3, ArchiveFileName="archive/log.{###}.log", ArchiveNumbering=NLog.Targets.ArchiveNumberingMode.Rolling, Layout = "${longdate}|${level:uppercase=true}|${processname}|${threadid}|${message}" };
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
NLog.LogManager.Configuration = config;
log = LogManager.GetCurrentClassLogger();
Expand Down
46 changes: 46 additions & 0 deletions barraider-sdtools/Tools/PayloadExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using streamdeck_client_csharp.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools
{
internal static class PayloadExtensionMethods
{
internal static string ToStringEx(this ReceiveSettingsPayload rsp)
{
if (rsp == null)
{
return "ReceiveSettingsPayload is null!";
}
return $"IsInMultiAction: {rsp.IsInMultiAction} Coordinates: ({rsp.Coordinates?.Rows},{rsp.Coordinates?.Columns}) Settings: {rsp.Settings}";
}

internal static string ToStringEx(this AppearancePayload ap)
{
if (ap == null)
{
return "AppearancePayload is null!";
}
return $"State: {ap.State} IsInMultiAction: {ap.IsInMultiAction} Coordinates: ({ap.Coordinates?.Rows},{ap.Coordinates?.Columns}) Settings: {ap.Settings}";
}

internal static string ToStringEx(this streamdeck_client_csharp.Events.KeyPayload kp)
{
if (kp == null)
{
return "KeyPayload is null!";
}
return $"State: {kp.State} IsInMultiAction: {kp.IsInMultiAction} DesiredState: {kp.UserDesiredState} Coordinates: ({kp.Coordinates?.Rows},{kp.Coordinates?.Columns}) Settings: {kp.Settings}";
}

internal static string ToStringEx(this ReceiveGlobalSettingsPayload gsp)
{
if (gsp == null)
{
return "ReceiveGlobalSettingsPayload is null!";
}
return $"Settings: {gsp.Settings}";
}
}
}
2 changes: 2 additions & 0 deletions barraider-sdtools/Tools/PluginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public void Destroy()
/// </summary>
/// <param name="connection">Communication module with Stream Deck</param>
/// <param name="payload">Plugin settings - NOTE: Not used in base class, should be consumed by deriving class</param>
#pragma warning disable IDE0060 // Remove unused parameter
public PluginBase(SDConnection connection, InitialPayload payload)
#pragma warning restore IDE0060 // Remove unused parameter
{
Connection = connection;
}
Expand Down
25 changes: 14 additions & 11 deletions barraider-sdtools/barraider-sdtools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ Feel free to contact me for more information: https://barraider.com</Description
<PackageLicenseUrl>https://github.com/BarRaider/streamdeck-tools/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/BarRaider/streamdeck-tools</PackageProjectUrl>
<RepositoryUrl>https://github.com/BarRaider/streamdeck-tools</RepositoryUrl>
<PackageTags>StreamDeck Elgato Library Plugin Stream Deck</PackageTags>
<PackageTags>StreamDeck Elgato Library Plugin Stream Deck Toolkit</PackageTags>
<PackageId>StreamDeck-Tools</PackageId>
<PackageIconUrl>https://raw.githubusercontent.com/BarRaider/barraider.github.io/master/images/BRLogo.png</PackageIconUrl>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
<Version>3.0</Version>
<PackageReleaseNotes>3.0 - 1. Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods
2. Removed obsolete MD5 functions, use SHA512 functions instead
3. `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width
4. New `Tools.FormatBytes` function converts bytes to human-readable value
5. New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line
6. Updated dependencies</PackageReleaseNotes>
<PackageIconUrl></PackageIconUrl>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<FileVersion>3.1.0.0</FileVersion>
<Version>3.1</Version>
<PackageReleaseNotes>3.1 - 1. Updated Logger class to include process name and thread id
2. Updated StreamDeck-Tools template for Visual Studio</PackageReleaseNotes>
<RootNamespace>BarRaider.SdTools</RootNamespace>
<AssemblyName>StreamDeckTools</AssemblyName>
<PackageIcon>BRLogo_460.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<DocumentationFile></DocumentationFile>
Expand All @@ -43,4 +40,10 @@ Feel free to contact me for more information: https://barraider.com</Description
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="D:\Documents\My Pictures\PSD\BRLogo_460.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>
Loading

0 comments on commit 0e8634f

Please sign in to comment.