Update: Plugin Framework

This commit is contained in:
Gary Sharp
2013-03-04 20:55:14 +11:00
parent 9b80fd743b
commit c205386bcf
18 changed files with 172 additions and 77 deletions
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1950")]
[assembly: AssemblyFileVersion("1.2.0225.1950")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1950")]
[assembly: AssemblyFileVersion("1.2.0225.1950")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1951")]
[assembly: AssemblyFileVersion("1.2.0225.1951")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1951")]
[assembly: AssemblyFileVersion("1.2.0225.1951")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
@@ -24,6 +24,10 @@ namespace Disco.Services.Plugins.Features.UIExtension
{
return new LiteralResult(this.Manifest, null);
}
protected LiteralResult ScriptInline(string JavaScriptContent)
{
return new LiteralResult(this.Manifest, string.Concat("<script type=\"text/javascript\">\n//<!--\n", JavaScriptContent, "\n//-->\n</script>"));
}
protected PluginResourceScriptResult ScriptResource(string Resource, bool PlaceInPageHead)
{
return new PluginResourceScriptResult(this.Manifest, Resource, PlaceInPageHead);
@@ -11,5 +11,6 @@ namespace Disco.Services.Plugins
{
public string Id { get; set; }
public string Name { get; set; }
public bool PrimaryFeature { get; set; }
}
}
@@ -14,7 +14,8 @@ namespace Disco.Services.Plugins
public string Id { get; set; }
public string Name { get; set; }
public string TypeName { get; set; }
public bool PrimaryFeature { get; set; }
[JsonProperty]
private string CategoryTypeName { get; set; }
@@ -77,6 +78,7 @@ namespace Disco.Services.Plugins
var featureId = featureAttribute.Id;
var featureName = featureAttribute.Name;
var featurePrimary = featureAttribute.PrimaryFeature;
// Determine Feature Category
var featureCategoryType = featureType.BaseType;
@@ -84,6 +86,10 @@ namespace Disco.Services.Plugins
if (featureCategoryType == null)
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but has no Base Type to determine its Category", featureType.Name), "featureType");
// Handle Generic-Type Features (Only use base-feature, not generic parameters)
if (featureCategoryType.IsGenericType)
featureCategoryType = featureCategoryType.GetGenericTypeDefinition();
if (featureCategoryType == typeof(PluginFeature) || !typeof(PluginFeature).IsAssignableFrom(featureCategoryType))
throw new ArgumentException(string.Format("Plugin Feature found [{0}], but its Base Type is not a valid Feature Category Type (Base Feature or not assignable)", featureType.Name), "featureType");
@@ -97,6 +103,7 @@ namespace Disco.Services.Plugins
PluginManifest = pluginManifest,
Id = featureId,
Name = featureName,
PrimaryFeature = featurePrimary,
Type = featureType,
TypeName = featureType.FullName,
CategoryType = featureCategoryType,
+26
View File
@@ -414,5 +414,31 @@ namespace Disco.Services.Plugins
return new Tuple<string, string>(resourcePath, resourceHash.Item1);
}
public void LogException(Exception PluginException)
{
PluginsLog.LogPluginException(this.ToString(), PluginException);
}
public void LogWarning(string Message)
{
LogWarning(Message, null);
}
public void LogWarning(string MessageFormat, params object[] Args)
{
PluginsLog.LogPluginWarning(this, string.Format(MessageFormat, Args), Args);
}
public void LogMessage(string Message)
{
LogMessage(Message, null);
}
public void LogMessage(string MessageFormat, params object[] Args)
{
PluginsLog.LogPluginMessage(this, string.Format(MessageFormat, Args), Args);
}
public override string ToString()
{
return string.Format("{0} [{1} v{2}]", this.Name, this.Id, this.VersionFormatted);
}
}
}
+57
View File
@@ -28,6 +28,8 @@ namespace Disco.Services.Plugins
InitializeExceptionWithInner,
PluginException = 20,
PluginExceptionWithInner,
PluginWarning = 30,
PluginMessage = 40,
PluginReferenceAssemblyLoaded = 50,
PluginConfigurationLoaded = 100,
PluginConfigurationSaved = 104,
@@ -142,6 +144,39 @@ namespace Disco.Services.Plugins
Log(EventTypeIds.PluginException, Component, ex.GetType().Name, ex.Message, ex.StackTrace);
}
}
public static void LogPluginWarning(PluginManifest Manifest, string Message, params object[] ExportData)
{
LogPluginWarningOrMessage(EventTypeIds.PluginWarning, Manifest, Message, ExportData);
}
public static void LogPluginMessage(PluginManifest Manifest, string Message, params object[] ExportData)
{
LogPluginWarningOrMessage(EventTypeIds.PluginMessage, Manifest, Message, ExportData);
}
private static void LogPluginWarningOrMessage(EventTypeIds WarningOrMessage, PluginManifest Manifest, string Message, object[] ExportData)
{
if (WarningOrMessage != EventTypeIds.PluginMessage && WarningOrMessage != EventTypeIds.PluginWarning)
throw new ArgumentException("Only PluginMessage/PluginWarning is allowed", "WarningOrMessage");
object[] LogData;
if (ExportData == null || ExportData.Length == 0)
{
LogData = new object[3];
}
else
{
LogData = new object[4 + ExportData.Length];
for (int i = 0; i < ExportData.Length; i++)
LogData[4 + i] = ExportData[i];
}
LogData[0] = Manifest.Name;
LogData[1] = Manifest.Id;
LogData[2] = Manifest.VersionFormatted;
LogData[3] = Message;
Log(WarningOrMessage, LogData);
}
protected override List<Logging.Models.LogEventType> LoadEventTypes()
{
@@ -257,6 +292,28 @@ namespace Disco.Services.Plugins
UsePersist = true,
UseDisplay = true
},
new LogEventType
{
Id = (int)EventTypeIds.PluginWarning,
ModuleId = _ModuleId,
Name = "Plugin Warning",
Format = "{0} [{1} v{2}]: {3}",
Severity = (int)LogEventType.Severities.Warning,
UseLive = true,
UsePersist = true,
UseDisplay = true
},
new LogEventType
{
Id = (int)EventTypeIds.PluginMessage,
ModuleId = _ModuleId,
Name = "Plugin Message",
Format = "{0} [{1} v{2}]: {3}",
Severity = (int)LogEventType.Severities.Information,
UseLive = true,
UsePersist = true,
UseDisplay = true
},
new LogEventType
{
Id = (int)EventTypeIds.PluginReferenceAssemblyLoaded,
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1951")]
[assembly: AssemblyFileVersion("1.2.0225.1951")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0225.1951")]
[assembly: AssemblyFileVersion("1.2.0225.1951")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]
@@ -34,41 +34,36 @@ namespace Disco.Web.Areas.Config.Models.Plugins
}
}
public List<Tuple<Type, List<PluginManifest>>> PluginManifestsByType
public List<Tuple<Type, List<PluginManifest>>> PluginManifestsByCategory
{
get
{
if (PluginManifests.Count == 0)
return new List<Tuple<Type, List<PluginManifest>>>();
return null;
var categorisedManifests = PluginManifests.SelectMany(pm => pm.Features)
.GroupBy(fm => fm.CategoryType)
.Select(g => new Tuple<Type, List<PluginManifest>>(g.Key, g.Select(fm => fm.PluginManifest).Distinct().OrderBy(fm => fm.Name).ToList())).ToList();
// Ensure all plugins are represented
var allCategorisedManifests = categorisedManifests.SelectMany(g => g.Item2).ToList();
var unrepresentedPlugins = PluginManifests.Where(m => !allCategorisedManifests.Contains(m)).ToList();
if (unrepresentedPlugins.Count > 0)
List<Tuple<Type, PluginManifest>> pluginsByCategory = new List<Tuple<Type, PluginManifest>>();
foreach (var pluginManifest in PluginManifests)
{
Tuple<Type, List<PluginManifest>> otherCategory = null;
foreach (var category in categorisedManifests)
{
if (category.Item1 == typeof(OtherFeature))
{
otherCategory = category;
}
}
if (otherCategory == null)
{
otherCategory = new Tuple<Type, List<PluginManifest>>(typeof(OtherFeature), new List<PluginManifest>());
categorisedManifests.Add(otherCategory);
}
foreach (var pluginManifest in unrepresentedPlugins)
otherCategory.Item2.Add(pluginManifest);
var orderedFeatures = pluginManifest.Features.OrderBy(pf => pf.Id);
var primaryFeature = orderedFeatures.Where(pf => pf.PrimaryFeature).FirstOrDefault();
Type categoryType;
if (primaryFeature == null)
primaryFeature = orderedFeatures.FirstOrDefault();
if (primaryFeature == null)
categoryType = typeof(OtherFeature);
else
categoryType = primaryFeature.CategoryType;
pluginsByCategory.Add(new Tuple<Type, PluginManifest>(categoryType, pluginManifest));
}
return categorisedManifests;
return pluginsByCategory.GroupBy(p => p.Item1)
.OrderBy(g => g.Key.Name)
.Select(g => new Tuple<Type, List<PluginManifest>>(g.Key, g.Select(pg => pg.Item2).OrderBy(p => p.Name).ToList())).ToList();
}
}
}
@@ -13,7 +13,7 @@
}
else
{
var pluginGroups = Model.PluginManifestsByType;
var pluginGroups = Model.PluginManifestsByCategory;
int itemsPerColumn = pluginGroups.Count / 3;
@@ -38,7 +38,7 @@
<h3>@pluginDefinition.Name</h3>
</a>
<div class="pageMenuBlurb">
<span class="pluginId">@pluginDefinition.Id</span> | <span class="pluginVersion">v@(pluginDefinition.VersionFormatted)</span> | @pluginDefinition.Author | <a href="@pluginDefinition.Url" target="_blank">More Information</a>
<span class="pluginVersion">v@(pluginDefinition.VersionFormatted)</span> | @pluginDefinition.Author | <a href="@pluginDefinition.Url" target="_blank">More Information</a>
</div>
}
</div>
@@ -37,9 +37,9 @@ namespace Disco.Web.Areas.Config.Views.Plugins
using Disco.Web;
using Disco.Web.Extensions;
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "1.5.4.0")]
[System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Config/Views/Plugins/Index.cshtml")]
public class Index : System.Web.Mvc.WebViewPage<Disco.Web.Areas.Config.Models.Plugins.IndexViewModel>
public partial class Index : System.Web.Mvc.WebViewPage<Disco.Web.Areas.Config.Models.Plugins.IndexViewModel>
{
public Index()
{
@@ -88,7 +88,7 @@ WriteLiteral(">\r\n <h2>No Plugins are Installed</h2>\r\n </di
}
else
{
var pluginGroups = Model.PluginManifestsByType;
var pluginGroups = Model.PluginManifestsByCategory;
int itemsPerColumn = pluginGroups.Count / 3;
@@ -169,14 +169,14 @@ WriteLiteral("</h2>\r\n");
#line hidden
WriteLiteral(" <a");
WriteAttribute("href", Tuple.Create(" href=\"", 1435), Tuple.Create("\"", 1504)
WriteAttribute("href", Tuple.Create(" href=\"", 1439), Tuple.Create("\"", 1508)
#line 37 "..\..\Areas\Config\Views\Plugins\Index.cshtml"
, Tuple.Create(Tuple.Create("", 1442), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.Config.Plugins.Configure(pluginDefinition.Id))
, Tuple.Create(Tuple.Create("", 1446), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.Config.Plugins.Configure(pluginDefinition.Id))
#line default
#line hidden
, 1442), false)
, 1446), false)
);
WriteLiteral(">\r\n <h3>");
@@ -196,26 +196,13 @@ WriteLiteral(" class=\"pageMenuBlurb\"");
WriteLiteral(">\r\n <span");
WriteLiteral(" class=\"pluginId\"");
WriteLiteral(">");
#line 41 "..\..\Areas\Config\Views\Plugins\Index.cshtml"
Write(pluginDefinition.Id);
#line default
#line hidden
WriteLiteral("</span> | <span");
WriteLiteral(" class=\"pluginVersion\"");
WriteLiteral(">v");
#line 41 "..\..\Areas\Config\Views\Plugins\Index.cshtml"
Write(pluginDefinition.VersionFormatted);
Write(pluginDefinition.VersionFormatted);
#line default
@@ -224,21 +211,21 @@ WriteLiteral("</span> | ");
#line 41 "..\..\Areas\Config\Views\Plugins\Index.cshtml"
Write(pluginDefinition.Author);
Write(pluginDefinition.Author);
#line default
#line hidden
WriteLiteral(" | <a");
WriteAttribute("href", Tuple.Create(" href=\"", 1885), Tuple.Create("\"", 1913)
WriteAttribute("href", Tuple.Create(" href=\"", 1836), Tuple.Create("\"", 1864)
#line 41 "..\..\Areas\Config\Views\Plugins\Index.cshtml"
, Tuple.Create(Tuple.Create("", 1892), Tuple.Create<System.Object, System.Int32>(pluginDefinition.Url
, Tuple.Create(Tuple.Create("", 1843), Tuple.Create<System.Object, System.Int32>(pluginDefinition.Url
#line default
#line hidden
, 1892), false)
, 1843), false)
);
WriteLiteral(" target=\"_blank\"");
+7
View File
@@ -731,6 +731,13 @@ div.logEventsViewport table.logEventsViewport > tbody > tr > td.eventType {
#plugins .pageMenuArea a > h3:hover {
color: #4f81bd;
}
#plugins .pageMenuArea .pageMenuBlurb {
padding-left: 18px;
}
#plugins #pageMenu td .pageMenuArea:not(:last-child) {
padding-bottom: 5px;
margin-bottom: 10px;
}
#plugins #pageMenu td .pageMenuArea > a {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90CDRcZMTlpMjsAAAKbSURBVDjLbZHBS2NHHMc/82ZeXpLaiNJHDylF6KEIGxFa0Jtdi4IFqfQq2P/As4f9D0rwplIwsDlZiofHStaTVQJCj+6a9SpKL3HhkTx5cZLMTA9uHov4Pf2Y33w/fL8z4vj4mHfv3vNUHz60ouXl5VmtNScnJ3eVmZkfn96ZqVRQj6P7HXj56VwAFAqFsenp6W+73S7NZjMRUH/iPwVqnwC8nJ2drU9NTb3I5XIDpVS6u7v7qlQqEQQBxWLxq83NzX+EEIUkSYJ8Pj+xs7Pz0+cAyuXyTqPR+F5KiTEGrTVCCHzfR2v99d7eXg3AGMPGxsZb4CPwWEEIAUC73ebm5gYhBKVSiTiOcc4RBAHn5+dYa9Fas76+nvXIEvi+jzEG5xyrq6vEcczV1RW+77O2tka73WZ/f58wDHHOZQBvNEgp6ff7hGHI4eEhSinOzs64uLjg+vqaWq3GYDBASom19vkEWmuMMYyPjxNFEUtLS1hrOTg4wBiD53k4554HeJ6H1pp+v59VaTQaWGuRUqKUYjAYADwPcM6Rpim9Xg9jDFJKgiBASokQAuccDw8P5PP5ZwHOOUe1WsU5hxACz/Oy3xlplCZJkmw3Apw2m81fx8bGEEJkFay12YuPDMPhkDiOvwP+/gwgXhtjTq21Yb/fTyuVysPt7e3PW1tbf/q+T7Va/U0p9b7VahW11vlOp3Pt53JtAOI4RimFUgohRG5+fv6Po6Ojf7e3twcLCwtucXHR1ev1NIqiN3Nzc6+klEUpJVJK7u/vEXEcE4YhgJBSfjE5OfnDysrKX4VC4ctSqdQCXKfTedHr9T5GUfRLmqb/DYfDBDB3d3ePgJGSJOHy8pJOt4vneQS5HABaa6xzfFMuUy6XmZiYyDz/AxHBRmZKLqH0AAAAAElFTkSuQmCC) /*Images/Actions/pluginDownloadIcon16.png*/;
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.2.0225.1951")]
[assembly: AssemblyFileVersion("1.2.0225.1951")]
[assembly: AssemblyVersion("1.2.0304.2046")]
[assembly: AssemblyFileVersion("1.2.0304.2046")]