Implemented variable data instead of hardcoded

This commit is contained in:
Nikolaj Geisle
2021-09-30 13:09:04 +02:00
parent 61de77f6be
commit 4ea1f46f2b
8 changed files with 214 additions and 25 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Web;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Services
{
public class UserDataService : IUserDataService
{
private IUmbracoVersion _version;
public UserDataService(IUmbracoVersion version)
{
_version = version;
}
public IEnumerable<UserData> GetUserData()
{
var userDataList = new List<UserData>
{
new UserData("Server OS", Environment.OSVersion.VersionString),
new UserData("Umbraco Version", _version.SemanticVersion.ToSemanticStringWithoutBuild()),
new UserData("Current Culture", Thread.CurrentThread.CurrentCulture.ToString()),
new UserData("Current UI Culture", Thread.CurrentThread.CurrentUICulture.ToString()),
new UserData("Current Webserver", GetCurrentWebServer())
};
return userDataList;
}
public string GetCurrentWebServer()
{
if (IsRunningInProcessIIS())
{
return "IIS";
}
return "Kestrel";
}
public bool IsRunningInProcessIIS()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return false;
}
string processName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
return (processName.Contains("w3wp") || processName.Contains("iisexpress"));
}
}
}