Skip to content

Commit

Permalink
Merge pull request #6201 from bdukes/fix-server-info-version
Browse files Browse the repository at this point in the history
Fix server info error on .NET 4.8
  • Loading branch information
valadas authored Nov 7, 2024
2 parents 020547c + 395ee6b commit 7a31fdc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 19 deletions.
4 changes: 4 additions & 0 deletions DNN Platform/Library/Common/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ public static TimeSpan ElapsedSinceAppStart
/// </value>
public static Version NETFrameworkVersion { get; set; }

/// <summary>Gets the .Net framework version text.</summary>
/// <value>The .Net framework version text.</value>
public static string FormattedNetFrameworkVersion => FormatVersion(NETFrameworkVersion, "0", 3, ".");

/// <summary>Gets or sets the database engine version.</summary>
/// <value>
/// The database engine version.
Expand Down
57 changes: 57 additions & 0 deletions DNN Platform/Tests/DotNetNuke.Tests.Core/Common/GlobalsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Tests.Core.Common;

using System;

using DotNetNuke.Common;

using NUnit.Framework;

[TestFixture]
public class GlobalsTests
{
[Test]
public void FormatVersion_WhenTwoDigitVersionFormattedWithThreeParts_UsesZeroForThirdPart()
{
Assert.That(Globals.FormatVersion(new Version("4.8"), "0", 3, "."), Is.EqualTo("4.8.0"));
}

[Test]
public void FormatVersion_WhenThreeDigitVersionFormattedWithThreeParts_DisplaysThirdPart()
{
Assert.That(Globals.FormatVersion(new Version("4.8.1"), "0", 3, "."), Is.EqualTo("4.8.1"));
}

[Test]
public void FormatVersion_WhenFourDigitVersionFormattedWithThreeParts_DoesNotDisplayFourthPart()
{
Assert.That(Globals.FormatVersion(new Version("4.8.1.7"), "0", 3, "."), Is.EqualTo("4.8.1"));
}

[Test]
public void FormatVersion_WhenTwoDigitVersion_DisplaysThreePartsWithLeadingZeroes_InABrokenWay()
{
Assert.That(Globals.FormatVersion(new Version("4.8")), Is.EqualTo("04.08.-01"));
}

[Test]
public void FormatVersion_WhenThreeDigitVersion_DisplaysThirdPartWithLeadingZeroes()
{
Assert.That(Globals.FormatVersion(new Version("4.8.1")), Is.EqualTo("04.08.01"));
}

[Test]
public void FormatVersion_WhenFourDigitVersion_DisplaysThreePartsWithLeadingZeroes()
{
Assert.That(Globals.FormatVersion(new Version("4.8.1.7")), Is.EqualTo("04.08.01"));
}

[Test]
public void FormatVersion_WhenFourDigitVersionWithRevision_DisplaysThreePartsWithLeadingZeroes()
{
Assert.That(Globals.FormatVersion(new Version("4.8.1.7"), true), Is.EqualTo("04.08.01 (7)"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<Compile Include="Collections\ReaderWriterSlimLockTests.cs" />
<Compile Include="Collections\SharedDictionaryTests.cs" />
<Compile Include="Collections\SharedListTests.cs" />
<Compile Include="Common\GlobalsTests.cs" />
<Compile Include="Common\NavigationManagerTests.cs" />
<Compile Include="Common\UrlUtilsTests.cs" />
<Compile Include="ComponentModel\ComponentFactoryTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace Dnn.PersonaBar.Prompt.Components.Models
{
using System.Web;


using DotNetNuke.Common;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Users;


public class HostModel
{
// DNN Platform for example
public string Product { get; set; }


public string Version { get; set; }

public bool UpgradeAvailable { get; set; }
Expand All @@ -30,23 +30,23 @@ public class HostModel

// prompt.com
public string Site { get; set; }


public string Title { get; set; }


public string Url { get; set; }


public string Email { get; set; }


public string Theme { get; set; }


public string Container { get; set; }


public string EditTheme { get; set; }


public string EditContainer { get; set; }


public int PortalCount { get; set; }


public static HostModel Current()
{
var application = DotNetNuke.Application.DotNetNukeContext.Current.Application;
Expand All @@ -63,7 +63,7 @@ public static HostModel Current()
Version = "v." + Globals.FormatVersion(application.Version, true),
Product = application.Description,
UpgradeAvailable = upgradeIndicator != null,
Framework = isHost ? Globals.NETFrameworkVersion.ToString(3) : string.Empty,
Framework = isHost ? Globals.FormattedNetFrameworkVersion : string.Empty,
IpAddress = System.Net.Dns.GetHostEntry(hostName).AddressList[0].ToString(),
Permissions = DotNetNuke.Framework.SecurityPolicy.Permissions,
Site = hostPortal.PortalName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ServerInfo
{
public string Framework => Environment.Version.ToString();

public string NetFrameworkVersion => Globals.NETFrameworkVersion.ToString(3);
public string NetFrameworkVersion => Globals.FormattedNetFrameworkVersion;

public string HostName => Dns.GetHostName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public HttpResponseMessage GetServerInfo()
{
ProductName = DotNetNukeContext.Current.Application.Description,
ProductVersion = "v. " + Globals.FormatVersion(DotNetNukeContext.Current.Application.Version, true),
FrameworkVersion = isHost ? Globals.NETFrameworkVersion.ToString(3) : string.Empty,
FrameworkVersion = isHost ? Globals.FormattedNetFrameworkVersion : string.Empty,
ServerName = isHost ? Globals.ServerName : string.Empty,
LicenseVisible = isHost && this.GetVisibleSetting("LicenseVisible"),
DocCenterVisible = this.GetVisibleSetting("DocCenterVisible"),
Expand Down

0 comments on commit 7a31fdc

Please sign in to comment.