HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/CMS/App_Code/CMSModules/Licenses/LicenseListControlExtender.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CMS;
using CMS.Base;
using CMS.ExtendedControls;
using CMS.ExtendedControls.ActionsConfig;
using CMS.Helpers;
using CMS.LicenseProvider;
using CMS.PortalEngine;
using CMS.UIControls;


/// <summary>
/// Custom class registration.
/// </summary>
[assembly: RegisterCustomClass("LicenseListControlExtender", typeof(LicenseListControlExtender))]

/// <summary>
/// License list control extender.
/// </summary>
public class LicenseListControlExtender : ControlExtender<UniGrid>
{
    #region "Constants"

    /// <summary>
    /// Client portal URL
    /// </summary>
    private const string CLIENT_PORTAL = "http://client.kentico.com/";


    /// <summary>
    /// Support e-mail address
    /// </summary>
    private const string SUPPORT_MAIL = "support@kentico.com";

    #endregion


    private bool mRefreshUI = false;


    #region "Events"

    /// <summary>
    /// Extender initialization.
    /// </summary>
    public override void OnInit()
    {
        mRefreshUI = QueryHelper.GetBoolean("reload", false);

        Control.GridView.PageSize = 20;
        Control.OnAction += Control_OnAction;
        Control.OnExternalDataBound += Control_OnExternalDataBound;
        Control.PreRender += Control_PreRender;
        Control.ZeroRowsText = ResHelper.GetString("general.nodatafound");

        // Add extra header actions
        ICMSPage page = Control.Page as ICMSPage;
        if (page != null)
        {
            var newAction = new HeaderAction
            {
                Text = ResHelper.GetString("license.list.export"),
                RedirectUrl = "~/CMSModules/Licenses/Pages/License_Export_Domains.aspx",
            };

            page.HeaderActions.InsertAction(1, newAction);
        }

        // Check if valid license for current domain exists
        var validationResult = LicenseHelper.ValidateLicenseForDomain(RequestContext.CurrentDomain);
        if (validationResult != LicenseValidationEnum.Valid)
        {
            // Build invalid license string
            var sb = new StringBuilder();
            sb.AppendFormat("{0} {1} <strong>{2}</strong><br /><br />", GetString("invalidlicense.currentdomain"), GetString("InvalidLicense.Result"), LicenseHelper.GetValidationResultString(validationResult))
              .AppendFormat("<strong>{0}</strong><br /><ul>", GetString("invalidlicense.howto"))
              .AppendFormat("<li>{0} ", GetString("invalidlicense.howto.option1.firstpart"))
              .AppendFormat("<a target=\"_blank\" href=\"{0}\" title=\"{1}\">{2}</a>", CLIENT_PORTAL, CLIENT_PORTAL, GetString("invalidlicense.clientportal"))
              .AppendFormat("{0}</li>", GetString("invalidlicense.howto.option1.secondpart"))
              .AppendFormat("<li>{0} <a href=\"mailto:{1}\">{2}</a>.</li>", GetString("invalidlicense.howto.option2"), SUPPORT_MAIL, SUPPORT_MAIL)
              .AppendFormat("<li>{0} ", GetString("invalidlicense.howto.option3.firstpart"))
              .AppendFormat("<a target=\"_blank\" href=\"{0}\" title=\"{1}\">{2}</a>", CLIENT_PORTAL, CLIENT_PORTAL, GetString("invalidlicense.clientportal"))
              .AppendFormat("{0}</li>", GetString("invalidlicense.howto.option3.secondpart"));

            if (validationResult == LicenseValidationEnum.Expired)
            {
                sb.Append("<li>" + GetString("invalidlicense.trialexpired") + "</li>");
            }

            sb.Append("</ul>");

            Control.ShowInformation(sb.ToString());
        }
    }


    /// <summary>
    /// Handles the pre-render event of the control
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event arguments</param>
    private void Control_PreRender(object sender, EventArgs e)
    {
        if (mRefreshUI)
        {
            // Register javascript to reload application
            ScriptHelper.RegisterModule(Control, "CMS/Licenses", true);
        }
    }


    /// <summary>
    /// External data binding handler.
    /// </summary>
    private object Control_OnExternalDataBound(object sender, string sourcename, object parameter)
    {
        switch (sourcename.ToLowerCSafe())
        {
            case "editionname":
                string edition = ValidationHelper.GetString(parameter, "").ToUpperCSafe();
                try
                {
                    return LicenseHelper.GetEditionName(edition.ToEnum<ProductEditionEnum>());
                }
                catch
                {
                    return "#UNKNOWN#";
                }

            case "expiration":
                return ResHelper.GetString(Convert.ToString(parameter));

            case "licenseservers":
                int count = ValidationHelper.GetInteger(parameter, -1);
                if (count == LicenseKeyInfo.SERVERS_UNLIMITED)
                {
                    return ResHelper.GetString("general.unlimited");
                }
                if (count > 0)
                {
                    return count.ToString();
                }
                return String.Empty;
        }
        return parameter;
    }


    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionname">Name of item (button) that throws event</param>
    /// <param name="actionargument">ID (value of Primary key) of corresponding data row</param>
    private void Control_OnAction(string actionname, object actionargument)
    {
        if (actionname == "delete")
        {
            LicenseKeyInfoProvider.DeleteLicenseKeyInfo(Convert.ToInt32(actionargument));

            mRefreshUI = true;
        }
    }

    #endregion


    #region "Methods"

    /// <summary>
    /// Gets resource string.
    /// </summary>
    /// <param name="stringKey">Resource string key.</param>
    private string GetString(string stringKey)
    {
        return ResHelper.GetString(stringKey);
    }

    #endregion
}