Implemented variable data instead of hardcoded
This commit is contained in:
@@ -26,6 +26,8 @@ using Umbraco.Cms.Core.IO;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Mail;
|
||||
using Umbraco.Cms.Core.Manifest;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.PropertyEditors;
|
||||
@@ -179,6 +181,7 @@ namespace Umbraco.Cms.Core.DependencyInjection
|
||||
Services.AddUnique<UriUtility>();
|
||||
|
||||
Services.AddUnique<IDashboardService, DashboardService>();
|
||||
Services.AddUnique<IUserDataService, UserDataService>();
|
||||
|
||||
// will be injected in controllers when needed to invoke rest endpoints on Our
|
||||
Services.AddUnique<IInstallationService, InstallationService>();
|
||||
|
||||
19
src/Umbraco.Core/Models/UserData.cs
Normal file
19
src/Umbraco.Core/Models/UserData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Cms.Core.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class UserData
|
||||
{
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; }
|
||||
[DataMember(Name = "data")]
|
||||
public string Data { get; }
|
||||
|
||||
public UserData(string name, string data)
|
||||
{
|
||||
Name = name;
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Umbraco.Core/Services/IUserDataService.cs
Normal file
10
src/Umbraco.Core/Services/IUserDataService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services
|
||||
{
|
||||
public interface IUserDataService
|
||||
{
|
||||
IEnumerable<UserData> GetUserData();
|
||||
}
|
||||
}
|
||||
57
src/Umbraco.Core/Services/UserDataService.cs
Normal file
57
src/Umbraco.Core/Services/UserDataService.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user