Skip to content

Commit

Permalink
Merge pull request #11 from UpendoVentures/tasks/debug-mode
Browse files Browse the repository at this point in the history
Version 01.01.00
  • Loading branch information
WillStrohl committed Feb 13, 2022
2 parents d01dd13 + fe112a7 commit 34549da
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 26 deletions.
1 change: 1 addition & 0 deletions Build/ModulePackage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<InstallInclude Include="**\*.jpg" Exclude="packages\**;node_modules\**;clientApp\**;client-app\**" />
<InstallInclude Include="**\*.bmp" Exclude="packages\**;node_modules\**;clientApp\**;client-app\**" />
<InstallInclude Include="**\*.xml" Exclude="packages\**;node_modules\**;clientApp\**;client-app\**;bin\**" />
<InstallInclude Include="**\*.resources" Exclude="packages\**;node_modules\**;clientApp\**;client-app\**;bin\**" />
<InstallInclude Include="**\web.config" Exclude="packages\**;node_modules\**;clientApp\**;client-app\**" />
</ItemGroup>

Expand Down
21 changes: 15 additions & 6 deletions Modules/UpendoPrompt/App_LocalResources/Global.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,40 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<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="ErrorOccurred.Text" xml:space="preserve">
<value>An error occurred. Please check the log files to find and resolve the issue.</value>
</data>
<data name="ModuleHelp.Text" xml:space="preserve">
<value>&lt;p&gt;No information at this time.&lt;/p&gt;</value>
</data>
<data name="PopupsDisabled.Text" xml:space="preserve">
<data name="PopupDisabled.Text" xml:space="preserve">
<value>Popups have been disabled for {0}.</value>
</data>
<data name="PopupsEnabled.Text" xml:space="preserve">
<data name="PopupEnabled.Text" xml:space="preserve">
<value>Popups have been enabled for {0}.</value>
</data>
<data name="PromptPopupsMode.Text" xml:space="preserve">
<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>
<data name="PromptPopupMode.Text" xml:space="preserve">
<value>Allows you to enable/disable the popup editing feature on the current website or all sites in this installation. </value>
</data>
<data name="Prompt_ModeInvalid.Text" xml:space="preserve">
<value>The mode can only be 'enable' or 'disable'. The default is 'disable'.</value>
</data>
<data name="Prompt_PopupsMode_FlagMode.Text" xml:space="preserve">
<data name="Prompt_PopupMode_FlagMode.Text" xml:space="preserve">
<value>Specify whether you want to enable or disable the popups on the specified site(s). Acceptable values include 'enable' and 'disable'. </value>
</data>
<data name="Prompt_PopupsMode_FlagScope.Text" xml:space="preserve">
<data name="Prompt_PopupMode_FlagScope.Text" xml:space="preserve">
<value>Specify whether you want to apply this to only the current site, or all sites. The accepted values include 'current' and 'all'.</value>
</data>
<data name="Prompt_PopupsMode_ResultHtml.Text" xml:space="preserve">
<data name="Prompt_PopupMode_ResultHtml.Text" xml:space="preserve">
<value>&lt;div&gt;
&lt;h4&gt;Enable or disable popups on the current or all sites&lt;/h4&gt;

Expand Down
173 changes: 173 additions & 0 deletions Modules/UpendoPrompt/Commands/DebugMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#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.IO;
using System.Xml;
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 Constants = Upendo.Modules.UpendoPrompt.Components.Constants;

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

#region Constants

private const string WEBCONFIG_DEBUG_ON = "~/DesktopModules/UpendoPrompt/Config/webConfig-DebugOn.xml.resources";
private const string WEBCONFIG_DEBUG_OFF = "~/DesktopModules/UpendoPrompt/Config/webConfig-DebugOff.xml.resources";

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

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

public override ConsoleResultModel Run()
{
try
{
var currentState = Host.DebugMode;
var newState = !currentState;

// site debug mode
HostController.Instance.Update(Constants.SettingKeys.HostSetting_DebugMode, newState.ToString());

// web.config debug mode
MergeWebConfig(newState);

// log4net debug mode
MergeLog4net(newState);

var output = string.Empty;

if (newState)
{
output = this.LocalizeString(Constants.LocalizationKeys.DebugOn);
}
else
{
output = this.LocalizeString(Constants.LocalizationKeys.DebugOff);
}

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

#endregion

#region Helpers

private void MergeWebConfig(bool newState)
{
var filePath = System.Web.HttpContext.Current.Server.MapPath(newState ? WEBCONFIG_DEBUG_ON : WEBCONFIG_DEBUG_OFF);

ExecuteMerge(filePath);
}

private void MergeLog4net(bool newState)
{
var filePath = System.Web.HttpContext.Current.Server.MapPath(newState ? LOG4NET_DEBUG_ON : LOG4NET_DEBUG_OFF);

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;
var merge = new DotNetNuke.Services.Installer.XmlMerge(xmlDoc, Globals.FormatVersion(app.Version), app.Description);
merge.UpdateConfigs();

merge.UpdateConfigs();
}

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
}
}
6 changes: 3 additions & 3 deletions Modules/UpendoPrompt/Commands/PopupMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override ConsoleResultModel Run()
{
PortalController.Instance.UpdatePortalSetting(
PortalSettings.PortalId,
Constants.PortalSettingKeys.PortalSetting_Popups,
Constants.SettingKeys.PortalSetting_Popup,
newMode.ToString(),
true,
PortalSettings.CultureCode,
Expand All @@ -112,7 +112,7 @@ public override ConsoleResultModel Run()
{
PortalController.Instance.UpdatePortalSetting(
portal.PortalID, // deprecated - REPLACE!!!
Constants.PortalSettingKeys.PortalSetting_Popups,
Constants.SettingKeys.PortalSetting_Popup,
newMode.ToString(),
true,
portal.CultureCode,
Expand All @@ -133,7 +133,7 @@ public override ConsoleResultModel Run()
}
else
{
output = string.Format(this.LocalizeString(Constants.LocalizationKeys.PopupsDisabled), outputScope);
output = string.Format(this.LocalizeString(Constants.LocalizationKeys.PopupDisabled), outputScope);
}

return new ConsoleResultModel
Expand Down
15 changes: 11 additions & 4 deletions Modules/UpendoPrompt/Components/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ public static class Constants
public const string PromptCategory = "Upendo Ventures";
public const string OutputPrefix = "Upendo Prompt";

public static class PortalSettingKeys
public const string STATE_TRUE = "true";
public const string STATE_FALSE = "false";

public static class SettingKeys
{
public const string PortalSetting_Popups = "EnablePopUps";
public const string HostSetting_DebugMode = "DebugMode";
public const string PortalSetting_Popup = "EnablePopUps";
}

public static class LocalizationKeys
{
public const string PopupsEnabled = "PopupsEnabled";
public const string PopupsDisabled = "PopupsDisabled";
public const string PopupsEnabled = "PopupEnabled";
public const string PopupDisabled = "PopupDisabled";
public const string ErrorOccurred = "ErrorOccurred";

public const string FlagMode = "Prompt_PopupMode_FlagMode";
Expand All @@ -50,6 +54,9 @@ public static class LocalizationKeys
public const string PromptScopeInvalid = "Prompt_ScopeInvalid";
public const string ScopeCurrent = "ScopeCurrent";
public const string ScopeAll = "ScopeAll";

public const string DebugOn = "DebugOn";
public const string DebugOff = "DebugOff";
}
}
}
6 changes: 6 additions & 0 deletions Modules/UpendoPrompt/Config/log4net-DebugOff.xml.resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nodes configfile="DotNetNuke.log4net.config">
<node path="/log4net/root/level" action="updateattribute" name="value" value="Error" />
</nodes>
</configuration>
6 changes: 6 additions & 0 deletions Modules/UpendoPrompt/Config/log4net-DebugOn.xml.resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nodes configfile="DotNetNuke.log4net.config">
<node path="/log4net/root/level" action="updateattribute" name="value" value="All" />
</nodes>
</configuration>
6 changes: 6 additions & 0 deletions Modules/UpendoPrompt/Config/webConfig-DebugOff.xml.resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nodes configfile="web.config">
<node path="/configuration/system.web/compilation" action="updateattribute" name="debug" value="false" />
</nodes>
</configuration>
6 changes: 6 additions & 0 deletions Modules/UpendoPrompt/Config/webConfig-DebugOn.xml.resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nodes configfile="web.config">
<node path="/configuration/system.web/compilation" action="updateattribute" name="debug" value="true" />
</nodes>
</configuration>
4 changes: 3 additions & 1 deletion Modules/UpendoPrompt/Module.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<Images Include="Images/**/*.*" />
<JsFiles Include="js/**/*.*" />
<Styles Include="Styles/**/*.*" />
<Configs Include="Config/**/*.resources" />
<DataProvider Include="Providers/DataProviders/SqlDataProvider/*.SqlDataProvider" />
<Resources Include="@(Manifest);@(TextFiles);@(SourceFiles);@(Views);@(ResourceFiles);@(Images);@(JsFiles);@(Styles);@(DataProvider)" />
<Resources Include="@(Manifest);@(TextFiles);@(SourceFiles);@(Views);@(ResourceFiles);@(Images);@(JsFiles);@(Styles);@(Configs);@(DataProvider)" />
</ItemGroup>
</Target>
<ItemGroup>
Expand All @@ -47,6 +48,7 @@
<Copy SourceFiles="@(Images)" DestinationFolder="$(FullModulePath)\Images\%(RecursiveDir)" />
<Copy SourceFiles="@(JsFiles)" DestinationFolder="$(FullModulePath)\Scripts\%(RecursiveDir)" />
<Copy SourceFiles="@(Styles)" DestinationFolder="$(FullModulePath)\Styles\%(RecursiveDir)" />
<Copy SourceFiles="@(Configs)" DestinationFolder="$(FullModulePath)\Configs\%(RecursiveDir)" />
<Copy SourceFiles="@(DataProvider)" DestinationFolder="$(FullModulePath)\Providers\DataProviders\SqlDataProvider" />
</Target>
</Project>
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.00.00")]
[assembly: AssemblyFileVersion("01.00.00")]
[assembly: AssemblyVersion("01.01.00")]
[assembly: AssemblyFileVersion("01.01.00")]
11 changes: 8 additions & 3 deletions Modules/UpendoPrompt/Upendo.Modules.UpendoPrompt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
</PropertyGroup>
<Import Project="..\..\Build\SolutionReferences.targets" />
<ItemGroup>
<PackageReference Include="Dnn.PersonaBar.Library">
<Version>9.10.0</Version>
</PackageReference>
<PackageReference Include="Dnn.PersonaBar.Library" Version="9.10.0" />
<PackageReference Include="DotNetNuke.Core" Version="9.10.0" />
<PackageReference Include="DotNetNuke.Instrumentation" Version="9.10.0" />
<PackageReference Include="DotNetNuke.Web" Version="9.10.0" />
Expand Down Expand Up @@ -79,6 +77,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\DebugMode.cs" />
<Compile Include="Commands\PopupMode.cs" />
<Compile Include="Components\Constants.cs" />
<Compile Include="Components\FeatureController.cs" />
Expand Down Expand Up @@ -145,6 +144,12 @@
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Config\log4net-DebugOff.xml.resources" />
<EmbeddedResource Include="Config\webConfig-DebugOff.xml.resources" />
<EmbeddedResource Include="Config\log4net-DebugOn.xml.resources" />
<EmbeddedResource Include="Config\webConfig-DebugOn.xml.resources" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
Loading

0 comments on commit 34549da

Please sign in to comment.