Table of Contents

Class ListWidgetBase

Namespace
Dynamicweb.Dashboard.Widgets
Assembly
Dynamicweb.Core.dll

The class DashboardWidget provides base list dashboard widget

[AddInIcon(KnownIcon.List)]
public abstract class ListWidgetBase : DashboardWidget, IParameterOptions
Inheritance
ListWidgetBase
Implements
Derived
Inherited Members

Examples

using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Dynamicweb.Core;
using Dynamicweb.Dashboard.Data;
using Dynamicweb.Dashboard.Widgets;
using Dynamicweb.Extensibility.AddIns;

namespace Dynamicweb.Dashboard.Examples;

[AddInName("Top files folders size")]
[AddInDescription("Show files folders sizes")]
[AddInIcon(Core.UI.Icons.KnownIcon.Healing)]
public class FilesFolderSizes : ListWidgetBase
{
    const string Folder = "/Files";

    public FilesFolderSizes()
    {
        Title = "Top space-hogging files folders";
    }

    public override IEnumerable<ListViewItem> GetItems(IDashboard dashboard, string path)
    {
        var filesPath = SystemInformation.MapPath(Folder);

        var directoryInfos = new List<DirectoryData>();
        foreach (string dirPath in Directory.GetDirectories(filesPath))
        {
            var dirInfo = new DirectoryInfo(dirPath);
            directoryInfos.Add(new()
            {
                Name = dirInfo.Name,
                Size = Helper.DirSize(dirInfo)
            });
        }

        double count;
        string subtitle;
        foreach (DirectoryData item in directoryInfos.OrderBy(directoryData => directoryData.Size).Take(4))
        {
            Helper.HumanizeByteSize(item.Size, out count, out subtitle);
            yield return new ListViewItem()
            {
                Icon = Core.UI.Icons.KnownIcon.Folder,
                Title = item.Name,
                Hint = string.Format(CultureInfo.InvariantCulture, "The folder size {0:0.##} {1}", count, subtitle)
            };
        }
    }
}

public class DirectoryData
{
    public string Name { get; set; } = "";

    public long Size { get; set; }
}

Constructors

ListWidgetBase()

The list widget default constructor

public ListWidgetBase()

Methods

GetItems(IDashboard, string)

Gets list items

public abstract IEnumerable<ListViewItem> GetItems(IDashboard dashboard, string path)

Parameters

dashboard IDashboard

The dashboard

path string

The request path

Returns

IEnumerable<ListViewItem>
To top