<commit_before>#region Copyright
// 
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2014
// by DotNetNuke Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
#endregion
#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Installer.Packages;
using DotNetNuke.Services.Localization;

#endregion

namespace DotNetNuke.Modules.Admin.Extensions
{
	/// <summary>
	/// Add and Edit Servers for a Web Farm
	/// </summary>
	/// <remarks>
	/// </remarks>
    public partial class UsageDetails : PortalModuleBase
    {
        private bool _IsListBound;
        private PackageInfo _Package;
        private int _PackageID = Null.NullInteger;
        private IDictionary<int, PortalInfo> _Portals;

        protected int PackageID
        {
            get
            {
                if ((_PackageID == Null.NullInteger && Request.QueryString["PackageID"] != null))
                {
                    _PackageID = Int32.Parse(Request.QueryString["PackageID"]);
                }
                return _PackageID;
            }
        }

        protected PackageInfo Package
        {
            get
            {
                if (_Package == null)
                {
                    if (PackageID == Null.NullInteger)
                    {
                        _Package = new PackageInfo();
                    }
                    else
                    {
                        _Package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == PackageID);
                    }
                }
                return _Package;
            }
        }

        protected IDictionary<int, PortalInfo> Portals
        {
            get
            {
                if (_Portals == null)
                {
                    _Portals = new Dictionary<int, PortalInfo>();
                    var items = PortalController.Instance.GetPortals();
                    foreach (PortalInfo item in items)
                    {
                        _Portals.Add(item.PortalID, item);
                    }
                }
                return _Portals;
            }
        }

        protected bool IsSuperTab
        {
            get
            {
                return (ModuleContext.PortalSettings.ActiveTab.IsSuperTab);
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            try
            {
                lblTitle.Text = Localization.GetString("Usage", LocalResourceFile) + Package.FriendlyName;
                UsageList.PagerSettings.FirstPageText = Localization.GetString("grd.PagerSettings.FirstPageText", LocalResourceFile);
                UsageList.PagerSettings.LastPageText = Localization.GetString("grd.PagerSettings.LastPageText", LocalResourceFile);
                UsageList.PagerSettings.NextPageText = Localization.GetString("grd.PagerSettings.NextPageText", LocalResourceFile);
                UsageList.PagerSettings.PreviousPageText = Localization.GetString("grd.PagerSettings.PreviousPageText", LocalResourceFile);

                if (!Page.IsPostBack)
                {
                    BindFilterList();
                    BindUsageList();
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected void FilterUsageList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (FilterUsageList.SelectedValue != null)
                {
                    UsageList.PageIndex = 0;
                    BindUsageList(int.Parse(FilterUsageList.SelectedValue), FilterUsageList.SelectedItem.Text);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected void UsageList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                UsageList.PageIndex = e.NewPageIndex;
                BindUsageList();
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected string GetFormattedLink(object dataItem)
        {
            var returnValue = new StringBuilder();
            if ((dataItem is TabInfo))
            {
                var tab = (TabInfo) dataItem;
                if ((tab != null))
                {
                    int index = 0;
                    TabController.Instance.PopulateBreadCrumbs(ref tab);
                    foreach (TabInfo t in tab.BreadCrumbs)
                    {
                        if ((index > 0))
                        {
                            returnValue.Append(" > ");
                        }
                        if ((tab.BreadCrumbs.Count - 1 == index))
                        {
                            string url;
                            //use the current portal alias for host tabs
                            url = Globals.AddHTTP(t.PortalID == Null.NullInteger? PortalSettings.PortalAlias.HTTPAlias : PortalAliasController.Instance.GetPortalAliasesByPortalId(t.PortalID).ToList()[0].HTTPAlias) + "/Default.aspx?tabId=" + t.TabID;
                            returnValue.AppendFormat("<a href=\"{0}\">{1}</a>", url, t.LocalizedTabName);
                        }
                        else
                        {
                            returnValue.AppendFormat("{0}", t.LocalizedTabName);
                        }
                        index = index + 1;
                    }
                }
            }
            return returnValue.ToString();
        }

        private void BindFilterList()
        {
            if (PackageID != Null.NullInteger && Package != null && Package.PackageType.ToUpper() == "MODULE")
            {
                tblFilterUsage.Visible = IsSuperTab;

                if (FilterUsageList.Visible)
                {
                    FilterUsageList.DataSource = Portals.Values;
                    FilterUsageList.DataTextField = "PortalName";
                    FilterUsageList.DataValueField = "PortalID";
                    FilterUsageList.DataBind();

                    FilterUsageList.InsertItem(0, Localization.GetString("FilterOptionHost", LocalResourceFile), Null.NullInteger.ToString());<commit_msg>DNN-8560 Generate URL via NavigateURL<commit_after>#region Copyright
// 
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2014
// by DotNetNuke Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
#endregion
#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Installer.Packages;
using DotNetNuke.Services.Localization;

#endregion

namespace DotNetNuke.Modules.Admin.Extensions
{
	/// <summary>
	/// Add and Edit Servers for a Web Farm
	/// </summary>
	/// <remarks>
	/// </remarks>
    public partial class UsageDetails : PortalModuleBase
    {
        private bool _IsListBound;
        private PackageInfo _Package;
        private int _PackageID = Null.NullInteger;
        private IDictionary<int, PortalInfo> _Portals;

        protected int PackageID
        {
            get
            {
                if ((_PackageID == Null.NullInteger && Request.QueryString["PackageID"] != null))
                {
                    _PackageID = Int32.Parse(Request.QueryString["PackageID"]);
                }
                return _PackageID;
            }
        }

        protected PackageInfo Package
        {
            get
            {
                if (_Package == null)
                {
                    if (PackageID == Null.NullInteger)
                    {
                        _Package = new PackageInfo();
                    }
                    else
                    {
                        _Package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == PackageID);
                    }
                }
                return _Package;
            }
        }

        protected IDictionary<int, PortalInfo> Portals
        {
            get
            {
                if (_Portals == null)
                {
                    _Portals = new Dictionary<int, PortalInfo>();
                    var items = PortalController.Instance.GetPortals();
                    foreach (PortalInfo item in items)
                    {
                        _Portals.Add(item.PortalID, item);
                    }
                }
                return _Portals;
            }
        }

        protected bool IsSuperTab
        {
            get
            {
                return (ModuleContext.PortalSettings.ActiveTab.IsSuperTab);
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            try
            {
                lblTitle.Text = Localization.GetString("Usage", LocalResourceFile) + Package.FriendlyName;
                UsageList.PagerSettings.FirstPageText = Localization.GetString("grd.PagerSettings.FirstPageText", LocalResourceFile);
                UsageList.PagerSettings.LastPageText = Localization.GetString("grd.PagerSettings.LastPageText", LocalResourceFile);
                UsageList.PagerSettings.NextPageText = Localization.GetString("grd.PagerSettings.NextPageText", LocalResourceFile);
                UsageList.PagerSettings.PreviousPageText = Localization.GetString("grd.PagerSettings.PreviousPageText", LocalResourceFile);

                if (!Page.IsPostBack)
                {
                    BindFilterList();
                    BindUsageList();
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected void FilterUsageList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (FilterUsageList.SelectedValue != null)
                {
                    UsageList.PageIndex = 0;
                    BindUsageList(int.Parse(FilterUsageList.SelectedValue), FilterUsageList.SelectedItem.Text);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected void UsageList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                UsageList.PageIndex = e.NewPageIndex;
                BindUsageList();
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        protected string GetFormattedLink(object dataItem)
        {
            var returnValue = new StringBuilder();
            var tab = dataItem as TabInfo;
            if (tab != null)
            {
                int index = 0;
                TabController.Instance.PopulateBreadCrumbs(ref tab);
                foreach (TabInfo t in tab.BreadCrumbs)
                {
                    if (index > 0)
                    {
                        returnValue.Append(" &gt; ");
                    }
                    if (index < tab.BreadCrumbs.Count - 1)
                    {
                        returnValue.AppendFormat("{0}", t.LocalizedTabName);
                    }
                    else
                    {
                        //use the current portal alias for host tabs
                        var alias = t.PortalID == Null.NullInteger || t.PortalID == this.PortalId
                                        ? this.PortalSettings.PortalAlias
                                        : PortalAliasController.Instance.GetPortalAliasesByPortalId(t.PortalID)
                                                                .OrderBy(pa => pa.IsPrimary ? 0 : 1)
                                                                .First();
                        var url = Globals.NavigateURL(t.TabID, new PortalSettings(t.PortalID, alias), string.Empty);
                        returnValue.AppendFormat("<a href=\"{0}\">{1}</a>", url, t.LocalizedTabName);
                    }
                    index = index + 1;
                }
            }
            return returnValue.ToString();
        }

        private void BindFilterList()
        {
            if (PackageID != Null.NullInteger && Package != null && Package.PackageType.ToUpper() == "MODULE")
            {
                tblFilterUsage.Visible = IsSuperTab;

                if (FilterUsageList.Visible)
                {
                    FilterUsageList.DataSource = Portals.Values;
                    FilterUsageList.DataTextField = "PortalName";
                    FilterUsageList.DataValueField = "PortalID";
                    FilterUsageList.DataBind();

                    FilterUsageList.InsertItem(0, Localization.GetString("FilterOptionHost", LocalResourceFile), Null.NullInteger.ToString());
{'fraction_non_alphanumeric': 0.07991415225350335, 'fraction_numerical': 0.002840550435551067, 'mean_word_length': 1.5187599364069952, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107035', 'n_tokens_mistral': 3963, 'n_tokens_neox': 3691, 'n_words': 928}