2019-06-11 13:32:43 +00:00
|
|
|
|
using System;
|
2019-08-15 09:14:10 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
2019-06-11 13:32:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
2019-08-15 09:14:10 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-06-11 13:32:43 +00:00
|
|
|
|
using ASC.Common.DependencyInjection;
|
|
|
|
|
using ASC.Common.Utils;
|
|
|
|
|
using CommandLine;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Resource.Manager
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
Parser.Default.ParseArguments<Options>(args).WithParsed(Export);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Export(Options options)
|
|
|
|
|
{
|
|
|
|
|
var services = new ServiceCollection();
|
|
|
|
|
var startup = new Startup();
|
|
|
|
|
startup.ConfigureServices(services);
|
|
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
CommonServiceProvider.Init(serviceProvider);
|
|
|
|
|
ConfigurationManager.Init(serviceProvider);
|
|
|
|
|
|
|
|
|
|
var cultures = new List<string>();
|
|
|
|
|
var projects = new List<ResFile>();
|
|
|
|
|
var enabledSettings = new EnabledSettings();
|
2019-08-13 15:17:14 +00:00
|
|
|
|
Action<string, string, string, string, string, string> export = null;
|
2019-06-11 13:32:43 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
var (project, module, filePath, exportPath, culture, format, key) = options;
|
2019-08-13 11:17:18 +00:00
|
|
|
|
|
2019-08-13 15:17:14 +00:00
|
|
|
|
if (format == "json")
|
2019-08-13 11:17:18 +00:00
|
|
|
|
{
|
|
|
|
|
export = JsonManager.Export;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
export = ResxManager.Export;
|
|
|
|
|
}
|
2019-06-11 13:32:43 +00:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(exportPath))
|
|
|
|
|
{
|
|
|
|
|
exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 11:17:18 +00:00
|
|
|
|
if (!Path.IsPathRooted(exportPath))
|
|
|
|
|
{
|
|
|
|
|
exportPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), exportPath));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 13:32:43 +00:00
|
|
|
|
if (!Directory.Exists(exportPath))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Error!!! Export path doesn't exist! Please enter a valid directory path.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enabledSettings = ConfigurationManager.GetSetting<EnabledSettings>("enabled");
|
|
|
|
|
cultures = ResourceData.GetCultures().Where(r => r.Available).Select(r => r.Title).Intersect(enabledSettings.Langs).ToList();
|
|
|
|
|
projects = ResourceData.GetAllFiles();
|
|
|
|
|
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ExportWithProject(project, module, filePath, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("The data has been successfully exported!");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(err);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 15:17:14 +00:00
|
|
|
|
void ExportWithProject(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
|
2019-06-11 13:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(projectName))
|
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ExportWithModule(projectName, moduleName, fileName, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-15 11:52:47 +00:00
|
|
|
|
var projectToExport = projects
|
|
|
|
|
.Where(r => string.IsNullOrEmpty(r.ModuleName) || r.ModuleName == moduleName)
|
|
|
|
|
.Where(r => string.IsNullOrEmpty(r.FileName) || r.FileName == fileName)
|
|
|
|
|
.Select(r => r.ProjectName)
|
|
|
|
|
.Intersect(enabledSettings.Projects);
|
|
|
|
|
|
|
|
|
|
foreach (var p in projectToExport)
|
2019-06-11 13:32:43 +00:00
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ExportWithModule(p, moduleName, fileName, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 15:17:14 +00:00
|
|
|
|
void ExportWithModule(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
|
2019-06-11 13:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(moduleName))
|
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ExportWithFile(projectName, moduleName, fileName, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-15 11:52:47 +00:00
|
|
|
|
var moduleToExport = projects
|
|
|
|
|
.Where(r => r.ProjectName == projectName)
|
|
|
|
|
.Where(r => string.IsNullOrEmpty(r.FileName) || r.FileName == fileName)
|
|
|
|
|
.Select(r => r.ModuleName);
|
|
|
|
|
|
|
|
|
|
foreach (var m in moduleToExport)
|
2019-06-11 13:32:43 +00:00
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ExportWithFile(projectName, m, fileName, culture, exportPath, key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void ExportWithFile(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(fileName))
|
|
|
|
|
{
|
|
|
|
|
ExportWithCulture(projectName, moduleName, fileName, culture, exportPath, key);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var f in projects.Where(r => r.ProjectName == projectName && r.ModuleName == moduleName).Select(r => r.FileName))
|
|
|
|
|
{
|
|
|
|
|
ExportWithCulture(projectName, moduleName, f, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-13 15:17:14 +00:00
|
|
|
|
void ExportWithCulture(string projectName, string moduleName, string fileName, string culture, string exportPath, string key)
|
2019-06-11 13:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(culture))
|
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
export(projectName, moduleName, fileName, culture, exportPath, key);
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-08-13 15:17:14 +00:00
|
|
|
|
ParallelEnumerable.ForAll(cultures.AsParallel(), c => export(projectName, moduleName, fileName, c, exportPath, key));
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-15 09:14:10 +00:00
|
|
|
|
|
|
|
|
|
public static string CheckExist(string resName, string fullClassName)
|
|
|
|
|
{
|
|
|
|
|
var bag = new ConcurrentBag<string>();
|
|
|
|
|
var path = "..\\..\\..\\..\\..\\";
|
|
|
|
|
|
|
|
|
|
var csFiles = Directory.GetFiles(Path.GetFullPath(path), "*.cs", SearchOption.AllDirectories);
|
|
|
|
|
var xmlFiles = Directory.GetFiles(Path.GetFullPath(path), "*.xml", SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
string localInit() => "";
|
|
|
|
|
|
|
|
|
|
Func<string, ParallelLoopState, long, string, string> func(string regexp) => (f, state, index, a) =>
|
|
|
|
|
{
|
|
|
|
|
var data = File.ReadAllText(f);
|
|
|
|
|
var regex = new Regex(regexp);
|
|
|
|
|
var matches = regex.Matches(data);
|
|
|
|
|
if (matches.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return a + "," + string.Join(",", matches.Select(r => r.Groups[1].Value));
|
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void localFinally(string r)
|
|
|
|
|
{
|
|
|
|
|
if (!bag.Contains(r) && !string.IsNullOrEmpty(r))
|
|
|
|
|
{
|
|
|
|
|
bag.Add(r.Trim(','));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 11:27:18 +00:00
|
|
|
|
_ = Parallel.ForEach(csFiles, localInit, func(@$"\W+{resName}\.(\w*)"), localFinally);
|
|
|
|
|
_ = Parallel.ForEach(csFiles, localInit, func(@$"CustomNamingPeople\.Substitute\<{resName}\>\(""(\w*)""\)"), localFinally);
|
2019-08-15 09:14:10 +00:00
|
|
|
|
_ = Parallel.ForEach(xmlFiles, localInit, func(@$"\|(\w*)\|{fullClassName.Replace(".", "\\.")}"), localFinally);
|
|
|
|
|
|
|
|
|
|
return string.Join(',', bag.ToArray());
|
|
|
|
|
}
|
2019-06-11 13:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|