Skip to content

Commit

Permalink
Merge pull request #14 from UpendoVentures/tasks/new-prompt-debuginfo
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
WillStrohl authored Feb 14, 2022
2 parents d1503bf + 22a0f90 commit d2f71bb
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 34 deletions.
24 changes: 24 additions & 0 deletions Modules/UpendoPrompt/App_LocalResources/Global.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,33 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DebugDisabled.Text" xml:space="preserve">
<value>Debugging is disabled throughout the site. </value>
</data>
<data name="DebugEnabled.Text" xml:space="preserve">
<value>Debugging is enabled in one or more of the debugging areas. You should consider turning it off if this is not expected. </value>
</data>
<data name="DebugOff.Text" xml:space="preserve">
<value>Debugging has been turned off in all areas of the site.</value>
</data>
<data name="DebugOn.Text" xml:space="preserve">
<value>Debugging has been enabled throughout the site. All visitors will experience slow page loads for the next few moments. </value>
</data>
<data name="DebugStatusHost.Text" xml:space="preserve">
<value>Debugging in the Host Settings is {0}.</value>
</data>
<data name="DebugStatusLog4net.Text" xml:space="preserve">
<value>Debugging in the Log4Net logging is {0}.</value>
</data>
<data name="DebugStatusWebConfig.Text" xml:space="preserve">
<value>Debugging in the web.config is {0}.</value>
</data>
<data name="Disabled.Text" xml:space="preserve">
<value>disabled</value>
</data>
<data name="Enabled.Text" xml:space="preserve">
<value>enabled</value>
</data>
<data name="ErrorOccurred.Text" xml:space="preserve">
<value>An error occurred. Please check the log files to find and resolve the issue.</value>
</data>
Expand All @@ -135,6 +156,9 @@
<data name="PopupEnabled.Text" xml:space="preserve">
<value>Popups have been enabled for {0}.</value>
</data>
<data name="PromptDebugInfo.Text" xml:space="preserve">
<value>Displays the debug details for the primary 3 debugging locations. </value>
</data>
<data name="PromptDebugMode.Text" xml:space="preserve">
<value>Allows you to turn on debugging in your site. This method enables debugging in the web.config, site settings, and the Log4Net configuration file.</value>
</data>
Expand Down
139 changes: 139 additions & 0 deletions Modules/UpendoPrompt/Commands/DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#region License

// Distributed under the MIT License
// ============================================================
// Copyright (c) Upendo Ventures, LLC
//
// 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

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using Dnn.PersonaBar.Library.Helper;
using Dnn.PersonaBar.Library.Prompt;
using Dnn.PersonaBar.Library.Prompt.Attributes;
using Dnn.PersonaBar.Library.Prompt.Models;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Users;
using DotNetNuke.Instrumentation;
using Upendo.Modules.UpendoPrompt.Components;
using Upendo.Modules.UpendoPrompt.Entities;
using Constants = Upendo.Modules.UpendoPrompt.Components.Constants;

namespace Upendo.Modules.UpendoPrompt.Commands
{
[ConsoleCommand("debug-info", Constants.PromptCategory, "PromptDebugInfo")]
public class DebugInfo : PromptBase, IConsoleCommand
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(DebugInfo));

#region Implementation

public override void Init(string[] args, PortalSettings portalSettings, UserInfo userInfo, int activeTabId)
{
// do nothing
}

public override ConsoleResultModel Run()
{
try
{
var debugHost = Host.DebugMode;
var debugWebConfig = HttpContext.Current.IsDebuggingEnabled;
var debugLog4net = GetLog4netStatus();

var enabled = LocalizeString(Constants.LocalizationKeys.ENABLED).ToUpper();
// DNN is stripping out comments with HTML added
//var enabled = string.Format(Constants.FORMAT_IMPORTANT, LocalizeString(Constants.LocalizationKeys.ENABLED));
var disabled = LocalizeString(Constants.LocalizationKeys.DISABLED).ToUpper();

var messages = new List<PromptMessage>();

messages.Add(new PromptMessage
{
Message = string.Format(LocalizeString(Constants.LocalizationKeys.DebugStatus_Host), debugHost ? enabled : disabled)
});

messages.Add(new PromptMessage
{
Message = string.Format(LocalizeString(Constants.LocalizationKeys.DebugStatus_WebConfig), debugWebConfig ? enabled : disabled)
});

messages.Add(new PromptMessage
{
Message = string.Format(LocalizeString(Constants.LocalizationKeys.DebugStatus_Log4net), debugLog4net ? enabled : disabled)
});

var output = string.Empty;
if (debugWebConfig || debugLog4net || debugHost)
{
output = LocalizeString(Constants.LocalizationKeys.DebugEnabled);
// DNN is stripping out comments with HTML added
//output = string.Format(Constants.FORMAT_IMPORTANT, LocalizeString(Constants.LocalizationKeys.DebugEnabled));
}
else
{
output = LocalizeString(Constants.LocalizationKeys.DebugDisabled);
}

return new ConsoleResultModel
{
Records = messages.Count,
Data = messages,
IsError = false,
Output = output
};
}
catch (Exception e)
{
LogError(e);
return new ConsoleErrorResultModel(string.Concat(Constants.OutputPrefix, this.LocalizeString(Constants.LocalizationKeys.ErrorOccurred)));
}
}

#endregion

#region Helpers

protected override void LogError(Exception ex)
{
if (ex != null)
{
Logger.Error(ex.Message, ex);
if (ex.InnerException != null)
{
Logger.Error(ex.InnerException.Message, ex.InnerException);
}
}
}
#endregion
}
}
28 changes: 2 additions & 26 deletions Modules/UpendoPrompt/Commands/DebugMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class DebugMode : PromptBase, IConsoleCommand
private const string LOG4NET_DEBUG_ON = "~/DesktopModules/UpendoPrompt/Config/log4net-DebugOn.xml.resources";
private const string LOG4NET_DEBUG_OFF = "~/DesktopModules/UpendoPrompt/Config/log4net-DebugOff.xml.resources";

private const string CONFIG_EXT = ".config";

#endregion

#region Implementation
Expand Down Expand Up @@ -97,7 +95,8 @@ public override ConsoleResultModel Run()

return new ConsoleResultModel
{
Output = output
Output = output,
IsError = false
};
}
catch (Exception e)
Expand Down Expand Up @@ -125,29 +124,6 @@ private void MergeLog4net(bool newState)
ExecuteMerge(filePath);
}

public string GetConfigFile(string configFile)
{
if (configFile.EndsWith(CONFIG_EXT, StringComparison.InvariantCultureIgnoreCase))
{
var configDoc = Config.Load(configFile);
using (var txtWriter = new StringWriter())
{
using (var writer = new XmlTextWriter(txtWriter))
{
writer.Formatting = Formatting.Indented;
configDoc.WriteTo(writer);
}

return txtWriter.ToString();
}
}
else
{
var doc = File.ReadAllText(Path.Combine(Globals.ApplicationMapPath, configFile));
return doc;
}
}

private void ExecuteMerge(string xmlDoc)
{
var app = DotNetNukeContext.Current.Application;
Expand Down
3 changes: 2 additions & 1 deletion Modules/UpendoPrompt/Commands/PopupMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public override ConsoleResultModel Run()

return new ConsoleResultModel
{
Output = output
Output = output,
IsError = false
};
}
catch (Exception e)
Expand Down
16 changes: 16 additions & 0 deletions Modules/UpendoPrompt/Components/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ public static class Constants
public const string Namespace = "uvm";
public const string PromptCategory = "Upendo Ventures";
public const string OutputPrefix = "Upendo Prompt";

public const string CONFIG_EXT = ".config";
public const string LOG4NET_CONFIG = "DotNetNuke.log4net.config";

public const string STATE_TRUE = "true";
public const string STATE_FALSE = "false";

public const string FORMAT_IMPORTANT = "<span style=\"color:red;font-weight:bold;>{0}</span>";
public const string FORMAT_WARNING = "<span style=\"color:yellow;font-weight:bold;>{0}</span>";
public const string FORMAT_SUCCESS = "<span style=\"color:green;font-weight:bold;>{0}</span>";

public static class SettingKeys
{
public const string HostSetting_DebugMode = "DebugMode";
Expand All @@ -57,6 +64,15 @@ public static class LocalizationKeys

public const string DebugOn = "DebugOn";
public const string DebugOff = "DebugOff";

public const string DebugStatus_Host = "DebugStatusHost";
public const string DebugStatus_Log4net = "DebugStatusLog4net";
public const string DebugStatus_WebConfig = "DebugStatusWebConfig";
public const string DebugEnabled = "DebugEnabled";
public const string DebugDisabled = "DebugDisabled";

public const string ENABLED = "Enabled";
public const string DISABLED = "Disabled";
}
}
}
38 changes: 38 additions & 0 deletions Modules/UpendoPrompt/Components/PromptBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
#endregion

using System;
using System.IO;
using System.Xml;
using Dnn.PersonaBar.Library.Prompt;
using Dnn.PersonaBar.Library.Prompt.Models;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;

namespace Upendo.Modules.UpendoPrompt.Components
{
Expand All @@ -42,5 +46,39 @@ public override string LocalResourceFile
return Constants.PromptLocalResourceFile;
}
}

protected string GetConfigFile(string configFile)
{
if (configFile.EndsWith(Constants.CONFIG_EXT, StringComparison.InvariantCultureIgnoreCase))
{
var configDoc = Config.Load(configFile);
using (var txtWriter = new StringWriter())
{
using (var writer = new XmlTextWriter(txtWriter))
{
writer.Formatting = Formatting.Indented;
configDoc.WriteTo(writer);
}

return txtWriter.ToString();
}
}
else
{
var doc = File.ReadAllText(Path.Combine(Globals.ApplicationMapPath, configFile));
return doc;
}
}

protected bool GetLog4netStatus()
{
var doc = new XmlDocument();
doc.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Constants.LOG4NET_CONFIG));

var node = doc.DocumentElement.SelectSingleNode("/log4net/root/level");
var log4netStatus = node.Attributes["value"].Value.ToString();

return (log4netStatus == "All");
}
}
}
4 changes: 2 additions & 2 deletions Modules/UpendoPrompt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("01.01.01")]
[assembly: AssemblyFileVersion("01.01.01")]
[assembly: AssemblyVersion("01.02.00")]
[assembly: AssemblyFileVersion("01.02.00")]
1 change: 1 addition & 0 deletions Modules/UpendoPrompt/Upendo.Modules.UpendoPrompt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\DebugInfo.cs" />
<Compile Include="Commands\DebugMode.cs" />
<Compile Include="Commands\PopupMode.cs" />
<Compile Include="Components\Constants.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Modules/UpendoPrompt/UpendoPrompt.dnn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<dotnetnuke type="Package" version="6.0">
<packages>
<package name="Upendo.Modules.UpendoPrompt" type="Module" version="01.01.01">
<package name="Upendo.Modules.UpendoPrompt" type="Module" version="01.02.00">
<friendlyName>UpendoPrompt</friendlyName>
<description>
<![CDATA[<p>This extension adds some prompt commands that might help your management of DNN be easier from time to time. </p>]]>
Expand Down Expand Up @@ -52,7 +52,7 @@
<attributes>
<businessControllerClass>Upendo.Modules.UpendoPrompt.Components.FeatureController, Upendo.Modules.UpendoPrompt</businessControllerClass>
<desktopModuleID>[DESKTOPMODULEID]</desktopModuleID>
<upgradeVersionsList>01.00.00,01.01.00,01.01.01</upgradeVersionsList>
<upgradeVersionsList>01.00.00,01.01.00,01.01.01,01.02.00</upgradeVersionsList>
</attributes>
</eventMessage>
</component>
Expand All @@ -62,7 +62,7 @@
<assembly>
<name>Upendo.Modules.UpendoPrompt.dll</name>
<path>bin</path>
<version>01.01.01</version>
<version>01.02.00</version>
</assembly>
</assemblies>
</component>
Expand Down
4 changes: 2 additions & 2 deletions Modules/UpendoPrompt/UpendoPrompt_Symbols.dnn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<dotnetnuke type="Package" version="6.0">
<packages>
<package name="Upendo.Modules.UpendoPrompt_Symbols" type="Library" version="01.01.01">
<package name="Upendo.Modules.UpendoPrompt_Symbols" type="Library" version="01.02.00">
<friendlyName>UpendoPrompt Module Symbols</friendlyName>
<description><![CDATA[This extension adds some prompt commands that might help your management of DNN be easier from time to time. ]]></description>
<owner>
Expand All @@ -14,7 +14,7 @@
<releaseNotes src="ReleaseNotes.txt" />
<azureCompatible>True</azureCompatible>
<dependencies>
<dependency type="managedPackage" version="1.1.1">Upendo.Modules.UpendoPrompt</dependency>
<dependency type="managedPackage" version="1.2.0">Upendo.Modules.UpendoPrompt</dependency>
</dependencies>

<components>
Expand Down
Loading

0 comments on commit d2f71bb

Please sign in to comment.