home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 2
Plugin Development
Plugin: Shutdown Manager (or call it whatever you want ;) ) - A blog to develop a MP2 plugin
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="chefkoch" data-source="post: 942564" data-attributes="member: 10438"><p><span style="font-size: 15px"><strong>Use constants for references in code to</strong></span></p><ul> <li data-xf-list-type="ul"><span style="font-size: 12px"><strong>workflow states,</strong></span></li> <li data-xf-list-type="ul"><span style="font-size: 12px"><strong>localization resource identifier and</strong></span></li> <li data-xf-list-type="ul"><span style="font-size: 12px"><strong>GUI keys</strong></span></li> </ul><p>I added a new class "<a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs" target="_blank">General\Consts.cs</a>". There all kind of constant values, especially strings, are being defined. These constants can be reused directly within all code of the ShutdownManager project.</p><p> </p><p>The <strong><a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L31-L37" target="_blank">workflow states</a></strong> are defined in the <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/plugin.xml#L34-L51" target="_blank">plugin.xml file</a>. To reuse them in code directly they are added to the Consts class. The ID is defined as text and redefined as GUID to be reused in code immediately.</p><p>Workflow states in plugin\Consts.cs</p><p></p><p>Workflow states in plugin.xml</p><p></p><p> </p><p>You might remember that we also defined the <strong>Workflow model</strong> IDs within the <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/plugin.xml#L21-L31" target="_blank">plugin.xml</a>. A definition inside Consts.cs <span style="color: #ff0000"><strong>is not needed</strong></span>, because these Model IDs are defined in the models directly as a constant. Examples:</p><p>ShutdownDialogModel (<a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownDialogModel.cs#L48" target="_blank">string</a> <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownDialogModel.cs#L267-L270" target="_blank">GUID</a>), ShutdownTimerDialogModel (<a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownTimerDialogModel.cs#L46" target="_blank">string</a><a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownTimerDialogModel.cs#L363-L366" target="_blank"> GUID</a>), ShutdownConfigurationDialogModel (<a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L44" target="_blank">string</a> <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L203-L206" target="_blank">GUID</a>)</p><p> </p><p>The <strong><a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L39-L51" target="_blank">localization resource identifiers</a></strong> (LRI) can be reused in code to fill properties and list items etc with localized code.</p><p>In the example I use another <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L62" target="_blank">helper method</a> for setting the list <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L136" target="_blank">item text</a> depending on the ShutdownAction.</p><p>The LRI in Consts can refer to those which are in the <a href="https://github.com/MediaPortal/MediaPortal-2/blob/df52f22eca61061abdf8497b921d24b0eadfabb1/MediaPortal/Incubator/ShutdownManager/Language/strings_en.xml" target="_blank">plugin's own language file</a> or even to those which are provided by others.</p><p>Localization resource identifies in plugin\Consts.cs</p><p></p><p>Localization resource identifies in strings_en.xml</p><p></p><p> </p><p>The <strong><a href="https://github.com/MediaPortal/MediaPortal-2/blob/df52f22eca61061abdf8497b921d24b0eadfabb1/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L54-L60" target="_blank">accessor keys for GUI communication</a></strong> in</p><p> </p><p>Accessor keys in <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L54-L60" target="_blank">General\Consts.cs</a></p><p></p><p>Usage of accessor keys in <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L136-L141" target="_blank">plugin code</a></p><p></p><p>Usage of accessor keys in <a href="https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Skin/default/themes/default/styles/ShutdownStyles.xaml#L23-L53" target="_blank">skin files</a></p><p></p><p> </p><p>More infos about filling an itemlist from code and using it within skin as well as infos about settings handling will follow.</p></blockquote><p></p>
[QUOTE="chefkoch, post: 942564, member: 10438"] [SIZE=4][B]Use constants for references in code to[/B][/SIZE] [LIST] [*][SIZE=3][B]workflow states,[/B][/SIZE] [*][SIZE=3][B]localization resource identifier and[/B][/SIZE] [*][SIZE=3][B]GUI keys[/B][/SIZE] [/LIST] I added a new class "[URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs']General\Consts.cs[/URL]". There all kind of constant values, especially strings, are being defined. These constants can be reused directly within all code of the ShutdownManager project. The [B][URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L31-L37']workflow states[/URL][/B] are defined in the [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/plugin.xml#L34-L51']plugin.xml file[/URL]. To reuse them in code directly they are added to the Consts class. The ID is defined as text and redefined as GUID to be reused in code immediately. Workflow states in plugin\Consts.cs Workflow states in plugin.xml You might remember that we also defined the [B]Workflow model[/B] IDs within the [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/plugin.xml#L21-L31']plugin.xml[/URL]. A definition inside Consts.cs [COLOR=#ff0000][B]is not needed[/B][/COLOR], because these Model IDs are defined in the models directly as a constant. Examples: ShutdownDialogModel ([URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownDialogModel.cs#L48']string[/URL] [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownDialogModel.cs#L267-L270']GUID[/URL]), ShutdownTimerDialogModel ([URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownTimerDialogModel.cs#L46']string[/URL][URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownTimerDialogModel.cs#L363-L366'] GUID[/URL]), ShutdownConfigurationDialogModel ([URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L44']string[/URL] [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L203-L206']GUID[/URL]) The [B][URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L39-L51']localization resource identifiers[/URL][/B] (LRI) can be reused in code to fill properties and list items etc with localized code. In the example I use another [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L62']helper method[/URL] for setting the list [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L136']item text[/URL] depending on the ShutdownAction. The LRI in Consts can refer to those which are in the [URL='https://github.com/MediaPortal/MediaPortal-2/blob/df52f22eca61061abdf8497b921d24b0eadfabb1/MediaPortal/Incubator/ShutdownManager/Language/strings_en.xml']plugin's own language file[/URL] or even to those which are provided by others. Localization resource identifies in plugin\Consts.cs Localization resource identifies in strings_en.xml The [B][URL='https://github.com/MediaPortal/MediaPortal-2/blob/df52f22eca61061abdf8497b921d24b0eadfabb1/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L54-L60']accessor keys for GUI communication[/URL][/B] in Accessor keys in [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/General/Consts.cs#L54-L60']General\Consts.cs[/URL] Usage of accessor keys in [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Models/ShutdownConfigurationDialogModel.cs#L136-L141']plugin code[/URL] Usage of accessor keys in [URL='https://github.com/MediaPortal/MediaPortal-2/blob/9790cd19b4cc851e80e1df517fd8f49aaf40ee80/MediaPortal/Incubator/ShutdownManager/Skin/default/themes/default/styles/ShutdownStyles.xaml#L23-L53']skin files[/URL] More infos about filling an itemlist from code and using it within skin as well as infos about settings handling will follow. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
Plugin Development
Plugin: Shutdown Manager (or call it whatever you want ;) ) - A blog to develop a MP2 plugin
Contact us
RSS
Top
Bottom