Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove MachineNameProvider

KrzysztofPajak812774fbf319
diff --git a/src/Business/Grand.Business.System/Services/MachineNameProvider/AzureWebAppsMachineNameProvider.cs b/src/Business/Grand.Business.System/Services/MachineNameProvider/AzureWebAppsMachineNameProvider.cs
deleted file mode 100644
index 126f6789d..000000000
--- a/src/Business/Grand.Business.System/Services/MachineNameProvider/AzureWebAppsMachineNameProvider.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-//Contribution: Orchard project (http://www.orchardproject.net/)
-
-using Grand.Business.Core.Interfaces.System.MachineNameProvider;
-
-namespace Grand.Business.System.Services.MachineNameProvider;
-
-/// <summary>
-/// Azure websites machine name provider
-/// </summary>
-public class AzureWebAppsMachineNameProvider : IMachineNameProvider
-{
- /// <summary>
- /// Returns the name of the machine (instance) running the application.
- /// </summary>
- public string GetMachineName()
- {
- //use the code below if run on Windows Azure cloud services (web roles)
- //return Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id;
- var name = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
- if (string.IsNullOrEmpty(name))
- name = Environment.MachineName;
-
- //you can also use ARR affinity cookie in order to detect instance name
-
- return name;
- }
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.System/Services/MachineNameProvider/DefaultMachineNameProvider.cs b/src/Business/Grand.Business.System/Services/MachineNameProvider/DefaultMachineNameProvider.cs
deleted file mode 100644
index 8b11d2ed8..000000000
--- a/src/Business/Grand.Business.System/Services/MachineNameProvider/DefaultMachineNameProvider.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-//Contribution: Orchard project (http://www.orchardproject.net/)
-
-using Grand.Business.Core.Interfaces.System.MachineNameProvider;
-
-namespace Grand.Business.System.Services.MachineNameProvider;
-
-/// <summary>
-/// Default machine name provider
-/// </summary>
-public class DefaultMachineNameProvider : IMachineNameProvider
-{
- /// <summary>
- /// Returns the name of the machine (instance) running the application.
- /// </summary>
- public string GetMachineName()
- {
- return Environment.MachineName;
- }
-}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.System/Startup/StartupApplication.cs b/src/Business/Grand.Business.System/Startup/StartupApplication.cs
index ee4fa5f5e..15d36533d 100644
--- a/src/Business/Grand.Business.System/Startup/StartupApplication.cs
+++ b/src/Business/Grand.Business.System/Startup/StartupApplication.cs
@@ -1,13 +1,10 @@
using Grand.Business.Core.Interfaces.System.Admin;
-using Grand.Business.Core.Interfaces.System.MachineNameProvider;
using Grand.Business.Core.Interfaces.System.Reports;
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Grand.Business.System.Services.Admin;
using Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
-using Grand.Business.System.Services.MachineNameProvider;
using Grand.Business.System.Services.Reports;
using Grand.Infrastructure;
-using Grand.Infrastructure.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@@ -20,7 +17,6 @@ public class StartupApplication : IStartupApplication
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
RegisterReports(services);
- RegisterMachineNameProvider(services, configuration);
RegisterTask(services);
RegisterAdmin(services);
}
@@ -44,24 +40,12 @@ public class StartupApplication : IStartupApplication
serviceCollection.AddScoped<IScheduleTask, EndAuctionsTask>();
serviceCollection.AddScoped<IScheduleTask, CancelOrderScheduledTask>();
}
-
private void RegisterReports(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<ICustomerReportService, CustomerReportService>();
serviceCollection.AddScoped<IOrderReportService, OrderReportService>();
serviceCollection.AddScoped<IProductsReportService, ProductsReportService>();
}
-
- private void RegisterMachineNameProvider(IServiceCollection serviceCollection, IConfiguration configuration)
- {
- var config = new AzureConfig();
- configuration.GetSection("Azure").Bind(config);
- if (config.RunOnAzureWebApps)
- serviceCollection.AddSingleton<IMachineNameProvider, AzureWebAppsMachineNameProvider>();
- else
- serviceCollection.AddSingleton<IMachineNameProvider, DefaultMachineNameProvider>();
- }
-
private void RegisterAdmin(IServiceCollection serviceCollection)
{
serviceCollection.AddScoped<IAdminSiteMapService, AdminSiteMapService>();
diff --git a/src/Core/Grand.Infrastructure/Configuration/AzureConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AzureConfig.cs
index 6f0e298de..fa8780e69 100644
--- a/src/Core/Grand.Infrastructure/Configuration/AzureConfig.cs
+++ b/src/Core/Grand.Infrastructure/Configuration/AzureConfig.cs
@@ -2,11 +2,6 @@
public class AzureConfig
{
- /// <summary>
- /// A value indicating whether the site is run on Windows Azure Web Apps
- /// </summary>
- public bool RunOnAzureWebApps { get; set; }
-
/// <summary>
/// Connection string for Azure BLOB storage
/// </summary>
diff --git a/src/Web/Grand.Web.Admin/App_Data/appsettings.json b/src/Web/Grand.Web.Admin/App_Data/appsettings.json
index f42a89685..27e944dd3 100644
--- a/src/Web/Grand.Web.Admin/App_Data/appsettings.json
+++ b/src/Web/Grand.Web.Admin/App_Data/appsettings.json
@@ -144,10 +144,6 @@
"RabbitCacheReceiveEndpoint": "grandnode"
},
"Azure": {
-
- //Enable "RunOnAzureWebApps" if you run on Windows Azure Web Apps
- "RunOnAzureWebApps": false,
-
//Azure BLOB storage.
//Specify your connection string, container name, end point for BLOB storage here
"AzureBlobStorageConnectionString": "",
diff --git a/src/Web/Grand.Web.Admin/Controllers/SystemController.cs b/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
index 4f71a7ad0..087c40ae1 100644
--- a/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/SystemController.cs
@@ -4,7 +4,6 @@ using Grand.Business.Core.Interfaces.Checkout.Payments;
using Grand.Business.Core.Interfaces.Checkout.Shipping;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
-using Grand.Business.Core.Interfaces.System.MachineNameProvider;
using Grand.Domain.Permissions;
using Grand.Domain.Directory;
using Grand.Infrastructure;
@@ -35,7 +34,6 @@ public class SystemController : BaseAdminController
IDateTimeService dateTimeService,
IWorkContext workContext,
ITranslationService translationService,
- IMachineNameProvider machineNameProvider,
IHostApplicationLifetime applicationLifetime,
IWebHostEnvironment webHostEnvironment,
ILogger<SystemController> logger,
@@ -57,7 +55,6 @@ public class SystemController : BaseAdminController
_logger = logger;
_extConfig = extConfig;
_accessControlConfig = accessControlConfig;
- _machineNameProvider = machineNameProvider;
}
#endregion
@@ -71,7 +68,6 @@ public class SystemController : BaseAdminController
private readonly IDateTimeService _dateTimeService;
private readonly IWorkContext _workContext;
private readonly ITranslationService _translationService;
- private readonly IMachineNameProvider _machineNameProvider;
private readonly IHostApplicationLifetime _applicationLifetime;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly ILogger<SystemController> _logger;
@@ -104,7 +100,7 @@ public class SystemController : BaseAdminController
}
catch (Exception) { }
- model.MachineName = _machineNameProvider.GetMachineName();
+ model.MachineName = Environment.MachineName;
model.WebRootPath = _webHostEnvironment.WebRootPath;
model.ContentRootPath = _webHostEnvironment.ContentRootPath;
model.EnvironmentName = _webHostEnvironment.EnvironmentName;
diff --git a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json b/src/Web/Grand.Web.Vendor/App_Data/appsettings.json
index f42a89685..27e944dd3 100644
--- a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json
+++ b/src/Web/Grand.Web.Vendor/App_Data/appsettings.json
@@ -144,10 +144,6 @@
"RabbitCacheReceiveEndpoint": "grandnode"
},
"Azure": {
-
- //Enable "RunOnAzureWebApps" if you run on Windows Azure Web Apps
- "RunOnAzureWebApps": false,
-
//Azure BLOB storage.
//Specify your connection string, container name, end point for BLOB storage here
"AzureBlobStorageConnectionString": "",
diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json
index f781787b5..d860345e4 100644
--- a/src/Web/Grand.Web/App_Data/appsettings.json
+++ b/src/Web/Grand.Web/App_Data/appsettings.json
@@ -179,10 +179,6 @@
"UrlRedirectToHttpsPermanent": false
},
"Azure": {
-
- //Enable "RunOnAzureWebApps" if you run on Windows Azure Web Apps
- "RunOnAzureWebApps": false,
-
//Azure BLOB storage.
//Specify your connection string, container name, end point for BLOB storage here
"AzureBlobStorageConnectionString": "",