Example #1
0
        List <PackageListItem> Widgets()
        {
            var widgets = new List <PackageListItem>();

            foreach (var assembly in Configuration.GetAssemblies())
            {
                var name = assembly.GetName().Name;

                if (name != "Blogifier.Core")
                {
                    var path = $"~/Views/Shared/Components/{name}/Settings.cshtml";
                    var view = _engine.GetView("", path, false);

                    var item = new PackageListItem
                    {
                        Title       = name,
                        Description = name,
                        Version     = assembly.GetName().Version.ToString(),
                        LastUpdated = System.IO.File.GetLastWriteTime(assembly.Location)
                    };

                    try
                    {
                        Type t = assembly.GetType("PackageInfo");
                        if (t != null)
                        {
                            var info       = (IPackageInfo)Activator.CreateInstance(t);
                            var attributes = info.GetAttributes();
                            if (attributes != null)
                            {
                                item.Author         = string.IsNullOrEmpty(attributes.Author) ? "Unknown" : attributes.Author;
                                item.Cover          = string.IsNullOrEmpty(attributes.Cover) ? BlogSettings.Cover : attributes.Cover;
                                item.Description    = attributes.Description;
                                item.Icon           = string.IsNullOrEmpty(attributes.Icon) ? BlogSettings.Logo : attributes.Icon;
                                item.ProjectUrl     = attributes.ProjectUrl;
                                item.Tags           = attributes.Tags;
                                item.Title          = attributes.Title;
                                item.ControllerName = attributes.ControllerName;
                            }
                        }
                    }
                    catch { }

                    var disabled = Disabled();
                    //var maxLen = 70;

                    //item.Description = item.Description.Length > maxLen ? item.Description.Substring(0, maxLen) + "..." : item.Description;
                    item.HasSettings = view.Success;
                    item.Enabled     = disabled == null || !disabled.Contains(name);
                    widgets.Add(item);
                }
            }
            return(widgets);
        }
Example #2
0
        public IActionResult Packages(string packageType = "Widgets")
        {
            var type  = packageType.ToLower();
            var model = new AdminPackagesModel {
                Profile = GetProfile()
            };

            model.Packages = new List <PackageListItem>();

            if (type == "widgets")
            {
                foreach (var assembly in Configuration.GetAssemblies())
                {
                    var name = assembly.GetName().Name;

                    if (name != "Blogifier.Core")
                    {
                        var path = $"~/Views/Shared/Components/{name}/Settings.cshtml";
                        var view = _engine.GetView("", path, false);

                        var item = new PackageListItem
                        {
                            Title       = name,
                            Description = name,
                            Version     = assembly.GetName().Version.ToString()
                        };

                        try
                        {
                            Type t = assembly.GetType("PackageInfo");
                            if (t != null)
                            {
                                var info = (IPackageInfo)Activator.CreateInstance(t);
                                item = info.GetAttributes();
                            }
                        }
                        catch { }

                        var disabled = Disabled();

                        item.Description = item.Description.Length > 50 ? item.Description.Substring(0, 50) + "..." : item.Description;
                        item.HasSettings = view.Success;
                        item.Enabled     = disabled == null || !disabled.Contains(name);
                        model.Packages.Add(item);
                    }
                }
            }

            return(View($"{_theme}Packages/Widgets.cshtml", model));
        }