33using Blogifier . Core . Data . Interfaces ;
44using Blogifier . Core . Data . Models ;
55using Blogifier . Core . Middleware ;
6+ using Blogifier . Core . Services . Packages ;
67using Microsoft . AspNetCore . Authorization ;
78using Microsoft . AspNetCore . Mvc ;
8- using Microsoft . AspNetCore . Mvc . ViewEngines ;
9- using Microsoft . Extensions . Logging ;
10- using System ;
119using System . Collections . Generic ;
12- using System . Linq ;
10+ using System . Threading . Tasks ;
1311
1412namespace Blogifier . Core . Controllers
1513{
@@ -18,63 +16,24 @@ namespace Blogifier.Core.Controllers
1816 public class PackagesController : Controller
1917 {
2018 private readonly string _theme ;
21- private readonly ILogger _logger ;
22- private readonly ICompositeViewEngine _engine ;
2319 IUnitOfWork _db ;
20+ IPackageService _pkgs ;
2421
25- public PackagesController ( IUnitOfWork db , ILogger < AdminController > logger , ICompositeViewEngine engine )
22+ public PackagesController ( IUnitOfWork db , IPackageService pkgs )
2623 {
2724 _db = db ;
28- _logger = logger ;
29- _engine = engine ;
25+ _pkgs = pkgs ;
3026 _theme = $ "~/{ ApplicationSettings . BlogAdminFolder } /";
3127 }
3228
3329 [ VerifyProfile ]
3430 [ HttpGet ( "widgets" ) ]
35- public IActionResult Widgets ( )
31+ public async Task < IActionResult > Widgets ( )
3632 {
37- var model = new AdminPackagesModel { Profile = GetProfile ( ) } ;
38-
39- model . Packages = new List < PackageListItem > ( ) ;
40-
41- foreach ( var assembly in Configuration . GetAssemblies ( ) )
42- {
43- var name = assembly . GetName ( ) . Name ;
44-
45- if ( name != "Blogifier.Core" )
46- {
47- var path = $ "~/Views/Shared/Components/{ name } /Settings.cshtml";
48- var view = _engine . GetView ( "" , path , false ) ;
49-
50- var item = new PackageListItem
51- {
52- Title = name ,
53- Description = name ,
54- Version = assembly . GetName ( ) . Version . ToString ( )
55- } ;
56-
57- try
58- {
59- Type t = assembly . GetType ( "PackageInfo" ) ;
60- if ( t != null )
61- {
62- var info = ( IPackageInfo ) Activator . CreateInstance ( t ) ;
63- item = info . GetAttributes ( ) ;
64- }
65- }
66- catch { }
67-
68- var disabled = Disabled ( ) ;
69- var maxLen = 70 ;
70-
71- item . Description = item . Description . Length > maxLen ? item . Description . Substring ( 0 , maxLen ) + "..." : item . Description ;
72- item . HasSettings = view . Success ;
73- item . Enabled = disabled == null || ! disabled . Contains ( name ) ;
74- model . Packages . Add ( item ) ;
75- }
76- }
77-
33+ var model = new AdminPackagesModel {
34+ Profile = GetProfile ( ) ,
35+ Packages = await _pkgs . Find ( PackageType . Widgets )
36+ } ;
7837 return View ( $ "{ _theme } Packages/Widgets.cshtml", model ) ;
7938 }
8039
@@ -92,11 +51,5 @@ private Profile GetProfile()
9251 {
9352 return _db . Profiles . Single ( b => b . IdentityName == User . Identity . Name ) ;
9453 }
95-
96- List < string > Disabled ( )
97- {
98- var field = _db . CustomFields . GetValue ( CustomType . Application , 0 , Constants . DisabledPackages ) ;
99- return string . IsNullOrEmpty ( field ) ? null : field . Split ( ',' ) . ToList ( ) ;
100- }
10154 }
10255}
0 commit comments