Skip to content

Commit

Permalink
Merge from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev committed Oct 24, 2024
2 parents e284f18 + 1b2d85f commit 942fdcd
Show file tree
Hide file tree
Showing 39 changed files with 12,319 additions and 1,125 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>3.858.0</VersionPrefix>
<VersionPrefix>3.860.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
<NoWarn>$(NoWarn);S3875;S4457</NoWarn>
Expand Down
80 changes: 58 additions & 22 deletions src/VirtoCommerce.Platform.Web/Controllers/Api/ModulesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,30 @@ namespace VirtoCommerce.Platform.Web.Controllers.Api
[Authorize]
public class ModulesController : Controller
{
private const string _managementIsDisabledMessage = "Module management is disabled.";

private readonly IExternalModuleCatalog _externalModuleCatalog;
private readonly IModuleInstaller _moduleInstaller;
private readonly IPushNotificationManager _pushNotifier;
private readonly IUserNameResolver _userNameResolver;
private readonly ISettingsManager _settingsManager;
private readonly PlatformOptions _platformOptions;
private readonly ExternalModuleCatalogOptions _externalModuleCatalogOptions;
private readonly LocalStorageModuleCatalogOptions _localStorageModuleCatalogOptions;
private readonly IPlatformRestarter _platformRestarter;
private static readonly object _lockObject = new object();
private static readonly FormOptions _defaultFormOptions = new FormOptions();

public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleInstaller moduleInstaller, IPushNotificationManager pushNotifier, IUserNameResolver userNameResolver, ISettingsManager settingsManager, IOptions<PlatformOptions> platformOptions, IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions, IPlatformRestarter platformRestarter)
public ModulesController(
IExternalModuleCatalog externalModuleCatalog,
IModuleInstaller moduleInstaller,
IPushNotificationManager pushNotifier,
IUserNameResolver userNameResolver,
ISettingsManager settingsManager,
IOptions<PlatformOptions> platformOptions,
IOptions<ExternalModuleCatalogOptions> externalModuleCatalogOptions,
IOptions<LocalStorageModuleCatalogOptions> localStorageModuleCatalogOptions,
IPlatformRestarter platformRestarter)
{
_externalModuleCatalog = externalModuleCatalog;
_moduleInstaller = moduleInstaller;
Expand All @@ -49,6 +61,7 @@ public ModulesController(IExternalModuleCatalog externalModuleCatalog, IModuleIn
_settingsManager = settingsManager;
_platformOptions = platformOptions.Value;
_externalModuleCatalogOptions = externalModuleCatalogOptions.Value;
_localStorageModuleCatalogOptions = localStorageModuleCatalogOptions.Value;
_platformRestarter = platformRestarter;
}

Expand Down Expand Up @@ -143,22 +156,29 @@ public ActionResult<ModuleDescriptor[]> GetMissingDependencies([FromBody] Module
public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
{
EnsureModulesCatalogInitialized();
ModuleDescriptor result = null;

if (!_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
{
return BadRequest(_managementIsDisabledMessage);
}

if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
return BadRequest($"Expected a multipart request, but got {Request.ContentType}");
}

var uploadPath = Path.GetFullPath(_platformOptions.LocalUploadFolderPath);
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string targetFilePath = null;

ModuleDescriptor result = null;
string targetFilePath = null;
var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
var reader = new MultipartReader(boundary, HttpContext.Request.Body);

var section = await reader.ReadNextSectionAsync();

if (section != null)
{
var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition);
Expand Down Expand Up @@ -205,6 +225,7 @@ public async Task<ActionResult<ModuleDescriptor>> UploadModuleArchive()
}
}
}

return Ok(result);
}

Expand Down Expand Up @@ -394,27 +415,42 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
try
{
notification.Started = DateTime.UtcNow;
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
.ToArray();
var reportProgress = new Progress<ProgressMessage>(m =>

if (_localStorageModuleCatalogOptions.RefreshProbingFolderOnStart)
{
lock (_lockObject)
var moduleInfos = _externalModuleCatalog.Modules.OfType<ManifestModuleInfo>()
.Where(x => options.Modules.Any(y => y.Identity.Equals(x.Identity)))
.ToArray();
var reportProgress = new Progress<ProgressMessage>(m =>
{
notification.Description = m.Message;
notification.ProgressLog.Add(m);
_pushNotifier.Send(notification);
}
});
lock (_lockObject)
{
notification.Description = m.Message;
notification.ProgressLog.Add(m);
_pushNotifier.Send(notification);
}
});

switch (options.Action)
switch (options.Action)
{
case ModuleAction.Install:
_moduleInstaller.Install(moduleInfos, reportProgress);
break;
case ModuleAction.Uninstall:
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
break;
}
}
else
{
case ModuleAction.Install:
_moduleInstaller.Install(moduleInfos, reportProgress);
break;
case ModuleAction.Uninstall:
_moduleInstaller.Uninstall(moduleInfos, reportProgress);
break;
notification.Finished = DateTime.UtcNow;
notification.Description = _managementIsDisabledMessage;
notification.ProgressLog.Add(new ProgressMessage
{
Level = ProgressMessageLevel.Error,
Message = notification.Description,
});
_pushNotifier.Send(notification);
}
}
catch (Exception ex)
Expand All @@ -430,7 +466,7 @@ public void ModuleBackgroundJob(ModuleBackgroundJobOptions options, ModulePushNo
_settingsManager.SetValue(PlatformConstants.Settings.Setup.ModulesAutoInstallState.Name, AutoInstallState.Completed);

notification.Finished = DateTime.UtcNow;
notification.Description = "Installation finished.";
notification.Description = options.Action == ModuleAction.Install ? "Installation finished." : "Uninstalling finished.";
notification.ProgressLog.Add(new ProgressMessage
{
Level = ProgressMessageLevel.Info,
Expand Down
Loading

0 comments on commit 942fdcd

Please sign in to comment.