-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Widget: Add Configuration code for Widgets
This adds necessary bits for Widgets to be configurable. Configuration can be changed via CLI "widget update" command. - Widgets can have their own configuration class which must inherit and implement abstract WidgetConfiguration class. WidgetConfiguration inherits from LukeBot.Communication.Common.EventArgsBase in order to make sending configuration to HTML/JS side of Widgets hassle-free. - Each Widget has its configuration available as protected mConfiguration field, kept in base IWidget class. - For Widgets which don't have a configuration, EmptyWidgetConfig object is created automatically. This config is treated specially by code saving the configuration to Property Store and skipped (it's empty anyway so no reason to clutter the Property Store). - Widget's Configuration is automatically loaded and created. To modify it, "widget update <widget_name> <changes>" is available. Changes are parsed with the same method as "event test" call.
- Loading branch information
Showing
19 changed files
with
427 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using LukeBot.Communication.Common; | ||
using Newtonsoft.Json; | ||
|
||
|
||
namespace LukeBot.Widget.Common | ||
{ | ||
public abstract class WidgetConfiguration: EventArgsBase | ||
{ | ||
public WidgetConfiguration(string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
public string SerializeConfiguration() | ||
{ | ||
return JsonConvert.SerializeObject(this); | ||
} | ||
|
||
public abstract void DeserializeConfiguration(string configString); | ||
public abstract void ValidateUpdate(string field, string value); | ||
public abstract void Update(string field, string value); | ||
public abstract string ToFormattedString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using LukeBot.Logging; | ||
using LukeBot.Widget.Common; | ||
|
||
|
||
namespace LukeBot.Widget | ||
{ | ||
internal class EmptyWidgetConfiguration: WidgetConfiguration | ||
{ | ||
public EmptyWidgetConfiguration() | ||
: base(Constants.EMPTY_WIDGET_CONFIGURATION_NAME) | ||
{ | ||
} | ||
|
||
public override void DeserializeConfiguration(string configString) | ||
{ | ||
} | ||
|
||
public override void ValidateUpdate(string field, string value) | ||
{ | ||
} | ||
|
||
public override void Update(string field, string value) | ||
{ | ||
} | ||
|
||
public override string ToFormattedString() | ||
{ | ||
return ""; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
LukeBot.Widget/Exception/WidgetConfigurationUpdateException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using LukeBot.Common; | ||
|
||
namespace LukeBot.Widget | ||
{ | ||
public class WidgetConfigurationUpdateException: Exception | ||
{ | ||
public WidgetConfigurationUpdateException(string fmt, params object[] args) | ||
: base(string.Format(fmt, args)) {} | ||
} | ||
} |
Oops, something went wrong.