Skip to content

Commit 0192150

Browse files
authored
Merge pull request #11 from dgw-dev/dw_main_dev
Dw main dev
2 parents fd810b6 + 55e314d commit 0192150

25 files changed

Lines changed: 272 additions & 114 deletions

DbLocalizer.Tests/appsettings.Test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"ScheduledImportPurgeCron": "0 0 6 ? * FRI *",
1616
"ImportMaxTablesPerFile": "20",
1717
"ExportMaxTablesPerFile": "20",
18-
"MaxRowsPerTable": "1000",
18+
"MaxRowsPerTable": "500",
1919
"ExportLookbackInDays": "5000",
2020
"MaximumRequestSize": "10485760", // 10MB in bytes
21-
"DataToPurgeInDays": "60",
21+
"TMSPlugin": "Smartling",
2222
"Cors": {
2323
"CorsOrigins": [ "https://localhost:44310" ]
2424
}

DbLocalizer/Controllers/BaseController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Entities;
22
using Entities.Interfaces;
33
using Entities.Utilities;
4+
using Microsoft.AspNetCore.DataProtection;
45
using Microsoft.AspNetCore.Mvc;
56
using Microsoft.Extensions.Caching.Memory;
67
using Microsoft.Extensions.Configuration;
@@ -17,11 +18,11 @@ public abstract class BaseController : Controller
1718
protected readonly IConfiguration _config;
1819
protected readonly ISqlSchemaBuilder _schemaBuilder;
1920

20-
protected BaseController(IMemoryCache memoryCache, IConfiguration config, ISqlSchemaBuilder sqlSchemaBuilder, ILogger logger)
21+
protected BaseController(IMemoryCache memoryCache, IConfiguration config, ISqlSchemaBuilder sqlSchemaBuilder, ILogger logger, IEncryptionService encryptionService)
2122
{
2223
_memoryCache = memoryCache;
2324
TokenSore = TokenStore.Instance;
24-
CacheManager = new CacheManager(_memoryCache, config, sqlSchemaBuilder);
25+
CacheManager = new CacheManager(_memoryCache, config, sqlSchemaBuilder, encryptionService);
2526
_config = config;
2627
_schemaBuilder = sqlSchemaBuilder;
2728
_logger = logger;

DbLocalizer/Controllers/CommonServiceController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Entities.Utilities;
55
using Microsoft.AspNetCore.Authorization;
66
using Microsoft.AspNetCore.Cors;
7+
using Microsoft.AspNetCore.DataProtection;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc;
910
using Microsoft.Extensions.Caching.Memory;
@@ -23,7 +24,8 @@ public class CommonServiceController : BaseController
2324
public CommonServiceController(IMemoryCache memoryCache,
2425
IConfiguration config,
2526
ISqlSchemaBuilder sqlSchemaBuilder,
26-
ILogger<CommonServiceController> logger) : base(memoryCache, config, sqlSchemaBuilder, logger)
27+
ILogger<CommonServiceController> logger,
28+
IEncryptionService encryptionService) : base(memoryCache, config, sqlSchemaBuilder, logger, encryptionService)
2729
{
2830
}
2931

DbLocalizer/Controllers/SmartlingExportController.cs renamed to DbLocalizer/Controllers/ExportController.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Entities.Utilities;
77
using Microsoft.AspNetCore.Authorization;
88
using Microsoft.AspNetCore.Cors;
9+
using Microsoft.AspNetCore.DataProtection;
910
using Microsoft.AspNetCore.Http;
1011
using Microsoft.AspNetCore.Mvc;
1112
using Microsoft.Extensions.Caching.Memory;
@@ -21,25 +22,26 @@ namespace DbLocalizer.Controllers
2122
[EnableCors("DbLocalizerCorsPolicy")]
2223
[Route("api/[controller]")]
2324
[ApiController]
24-
public class SmartlingExportController : BaseController
25+
public class ExportController : BaseController
2526
{
2627
private readonly IBackgroundWorkerQueue _backgroundWorkerQueue;
2728
private readonly AppSettings _appSettings;
2829
private readonly ILongRunningService _longRunningService;
2930
private readonly IExportDal _exportDal;
3031
private readonly IFileDataService _fileDataService;
3132

32-
public SmartlingExportController(
33+
public ExportController(
3334
IBackgroundWorkerQueue backgroundWorkerQueue,
3435
ILongRunningService longRunningService,
3536
AppSettings appSettings,
36-
ILogger<SmartlingExportController> logger,
37+
ILogger<ExportController> logger,
3738
IExportDal exportDal,
3839
IFileDataService fileDataService,
3940
IMemoryCache memoryCache,
4041
IConfiguration config,
41-
ISqlSchemaBuilder sqlSchemaBuilder)
42-
: base(memoryCache, config, sqlSchemaBuilder, logger)
42+
ISqlSchemaBuilder sqlSchemaBuilder,
43+
IEncryptionService encryptionService)
44+
: base(memoryCache, config, sqlSchemaBuilder, logger, encryptionService)
4345
{
4446
_backgroundWorkerQueue = backgroundWorkerQueue;
4547
_appSettings = appSettings;
@@ -76,6 +78,10 @@ public IActionResult Export()
7678
{
7779
return BadRequest("The required database and/or culture data is null");
7880
}
81+
if (string.IsNullOrEmpty(_appSettings.TMSPlugin))
82+
{
83+
return BadRequest("Please set your choice of TMSPlugin in the appSettings.json config file");
84+
}
7985

8086
Guid processId = Guid.NewGuid();
8187
CancellationTokenSource tokenSource = new CancellationTokenSource();
@@ -100,19 +106,27 @@ await Task.Factory.StartNew(async () =>
100106
{
101107
try
102108
{
103-
ISmartlingConfiguration smartlingConfig = new SmartlingConfiguration(_config);
104-
ISmartlingExportFileProcessor _fileProcessor = new SmartlingExportFileProcessor(_logger, _exportDal, "Default", CacheManager, _schemaBuilder, smartlingConfig);
105-
IExportUtility util = new SmartlingExportUtility(
106-
_fileProcessor,
107-
_fileDataService,
108-
_exportDal,
109-
_appSettings,
110-
_config,
111-
smartlingConfig,
112-
_logger,
113-
processId);
114-
115-
result = await util.Export(ct);
109+
switch (_appSettings.TMSPlugin)
110+
{
111+
case "Smartling":
112+
ISmartlingConfiguration smartlingConfig = new SmartlingConfiguration(_config);
113+
IExportFileProcessor _fileProcessor = new SmartlingExportFileProcessor(_logger, _exportDal, "Default", CacheManager, _schemaBuilder, smartlingConfig);
114+
IExportUtility util = new SmartlingExportUtility(
115+
_fileProcessor,
116+
_fileDataService,
117+
_exportDal,
118+
_appSettings,
119+
_config,
120+
smartlingConfig,
121+
_logger,
122+
processId);
123+
124+
result = await util.Export(ct);
125+
break;
126+
default:
127+
throw new NotImplementedException("The TMSPlugin is not implemented");
128+
}
129+
116130
}
117131
catch (Exception ex)
118132
{

DbLocalizer/Controllers/SmartlingImportController.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Entities.Utilities;
66
using Microsoft.AspNetCore.Authorization;
77
using Microsoft.AspNetCore.Cors;
8+
using Microsoft.AspNetCore.DataProtection;
89
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.Extensions.Caching.Memory;
@@ -33,8 +34,9 @@ public SmartlingImportController(
3334
ISmartlingImportUtility importUtility,
3435
IMemoryCache memoryCache,
3536
IConfiguration config,
36-
ISqlSchemaBuilder sqlSchemaBuilder
37-
) : base(memoryCache, config, sqlSchemaBuilder, logger)
37+
ISqlSchemaBuilder sqlSchemaBuilder,
38+
IEncryptionService encryptionService
39+
) : base(memoryCache, config, sqlSchemaBuilder, logger, encryptionService)
3840
{
3941
_backgroundWorkerQueue = backgroundWorkerQueue;
4042
_importUtility = importUtility;
@@ -101,14 +103,23 @@ public async Task<IActionResult> Get([FromQuery] string fileUri, [FromQuery] str
101103
}
102104

103105
// Download import json from smartling
104-
var importJson = await _smartlingFileDataService.GetTranslatedFileForLocaleAsync(locale, fileUri, processId);
106+
var importJsonFileCollection = await _smartlingFileDataService.GetTranslatedFileForLocaleAsync(locale, fileUri, processId);
105107

106108
// Run the import
107109
//do something with the importPackage
108-
SmartlingImportSqlFilePackageCollection importPackage = await _importUtility.Import(importJson);
110+
SmartlingImportSqlFilePackageCollection importPackage = await _importUtility.Import(importJsonFileCollection);
111+
112+
//check errors
113+
if (_importUtility.ErrorList.Count > 0)
114+
{
115+
foreach (var error in _importUtility.ErrorList)
116+
{
117+
returnData.ImportErrors.Add(new ImportErrorEntry(error.Message, processId, importJsonFileCollection.PackageId, Guid.Empty));
118+
}
119+
}
109120

110121
returnData.IsJobRunning = _backgroundWorkerQueue.IsRunning;
111-
returnData.OperationComplete = true;
122+
returnData.OperationComplete = _importUtility.OperationComplete;
112123

113124
return Ok(JsonUtility.SerializeData<ReturnData>(returnData));
114125
}
@@ -199,8 +210,17 @@ public async Task<IActionResult> UploadImportFiles(RawImportFile package)
199210
//do something with the importPackage
200211
SmartlingImportSqlFilePackageCollection importPackage = await _importUtility.Import(importJsonFileCollection);
201212

213+
//check errors
214+
if (_importUtility.ErrorList.Count > 0)
215+
{
216+
foreach (var error in _importUtility.ErrorList)
217+
{
218+
returnData.ImportErrors.Add(new ImportErrorEntry(error.Message, processId, importJsonFileCollection.PackageId, Guid.Empty));
219+
}
220+
}
221+
202222
returnData.IsJobRunning = _backgroundWorkerQueue.IsRunning;
203-
returnData.OperationComplete = true;
223+
returnData.OperationComplete = _importUtility.OperationComplete;
204224

205225
return Ok(JsonUtility.SerializeData<ReturnData>(returnData));
206226
}

DbLocalizer/Startup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public Startup(IConfiguration configuration)
3939
// This method gets called by the runtime. Use this method to add services to the container.
4040
public void ConfigureServices(IServiceCollection services)
4141
{
42+
services.AddDataProtection();
43+
services.AddSingleton<IEncryptionService, EncryptionService>();
44+
4245
services.AddScoped<IGenericPluginInData, GenericPluginInData>();
4346
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
4447
services.AddSingleton<IMemoryCache, MemoryCache>();
@@ -58,6 +61,7 @@ public void ConfigureServices(IServiceCollection services)
5861
services.AddScoped<IGenericRepository, GenericRepository>();
5962
services.AddScoped<IFileDataService, FileDataService>();
6063
services.AddScoped<IExportDal, ExportDal>();
64+
services.AddScoped<IImportDal, ImportDal>();
6165
services.AddScoped<ICacheManager, CacheManager>();
6266

6367
services.AddScoped<ISmartlingConfiguration>(provider =>
@@ -70,6 +74,8 @@ public void ConfigureServices(IServiceCollection services)
7074
services.AddScoped<ISmartlingImportFileProcessor, SmartlingImportFileProcessor>();
7175
services.AddScoped<ISmartlingSqlProcessor, SmartlingSqlProcessor>();
7276

77+
78+
7379

7480
services.AddSwaggerGen(options =>
7581
{

DbLocalizer/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"MaxRowsPerTable": "500",
1919
"ExportLookbackInDays": "5000",
2020
"MaximumRequestSize": "10485760", // 10MB in bytes
21-
"DataToPurgeInDays": "60",
21+
"TMSPlugin": "Smartling",
2222
"Cors": {
2323
"CorsOrigins": [ "https://localhost:44310" ]
2424
}

DbLocalizer/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"ScheduledImportPurgeCron": "0 0 6 ? * FRI *",
1616
"ImportMaxTablesPerFile": "20",
1717
"ExportMaxTablesPerFile": "20",
18-
"MaxRowsPerTable": "1000",
18+
"MaxRowsPerTable": "500",
1919
"ExportLookbackInDays": "5000",
2020
"MaximumRequestSize": "10485760", // 10MB in bytes
21-
"DataToPurgeInDays": "60",
21+
"TMSPlugin": "Smartling",
2222
"Cors": {
2323
"CorsOrigins": [ "https://localhost:44310" ]
2424
}

Entities/AppSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class AppSettings
1010
public string MaxRowsPerTable { get; set; }
1111
public string ExportLookbackInDays { get; set; }
1212
public string MaximumRequestSize { get; set; }
13-
public string DataToPurgeInDays { get; set; }
13+
public string TMSPlugin { get; set; }
1414
public Cors Cors { get; set; }
1515
}
1616

Entities/BL/FileProcessorBase.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,6 @@ public static DataTable GetBaseTableSubset(DataTable allBaseTables, List<string>
203203
return result;
204204
}
205205

206-
public void AddFileContent(MultipartFormDataContent content, string fileName, string sqlFileContent, List<SmartlingLocaleId> localeIds, string callBackUrl)
207-
{
208-
//add to outputcontent
209-
StreamContent streamContent = CreateFileContent(sqlFileContent, fileName, "application/json", new UTF8Encoding(false));
210-
content.Add(streamContent, "file");
211-
content.Add(new StringContent(fileName ?? string.Empty), "fileUri");
212-
content.Add(new StringContent("json" ?? string.Empty), "fileType");
213-
foreach (SmartlingLocaleId locale in localeIds)
214-
{
215-
content.Add(new StringContent(locale.targetLocaleId ?? string.Empty), "localeIdsToAuthorize[]");
216-
}
217-
content.Add(new StringContent(callBackUrl ?? string.Empty), "callbackUrl");
218-
}
219-
220206
public bool IsCancelled(CancellationToken ct)
221207
{
222208
if (ct.IsCancellationRequested || !TokenStore.Store.TryGetValue(ProcessId, out CancellationTokenSource _))

0 commit comments

Comments
 (0)