ASC.Resource.Manager: tool for export resources

This commit is contained in:
pavelbannov 2019-06-11 16:32:43 +03:00
parent 999f3fb63a
commit fcd562514b
22 changed files with 1461 additions and 20 deletions

View File

@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Core", "web\ASC.Web
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.VoipService", "common\ASC.VoipService\ASC.VoipService.csproj", "{988536C1-4B89-4649-8F77-5C16F55D95D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASC.Resource.Manager", "common\ASC.Resource.Manager\ASC.Resource.Manager.csproj", "{5A4A13CC-8EDD-4FDB-8C75-29E2B14A47F2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -72,6 +74,10 @@ Global
{988536C1-4B89-4649-8F77-5C16F55D95D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{988536C1-4B89-4649-8F77-5C16F55D95D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{988536C1-4B89-4649-8F77-5C16F55D95D1}.Release|Any CPU.Build.0 = Release|Any CPU
{5A4A13CC-8EDD-4FDB-8C75-29E2B14A47F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A4A13CC-8EDD-4FDB-8C75-29E2B14A47F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A4A13CC-8EDD-4FDB-8C75-29E2B14A47F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A4A13CC-8EDD-4FDB-8C75-29E2B14A47F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -10,12 +10,9 @@ namespace ASC.Common.DependencyInjection
private static IServiceProvider ServiceProvider { get; set; }
public static IApplicationBuilder InitCommonServiceProvider(this IApplicationBuilder app)
public static void Init(IServiceProvider serviceProvider)
{
ServiceProvider = app.ApplicationServices;
return app;
ServiceProvider = serviceProvider;
}
}
}

View File

@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using ASC.Common.Logging;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -16,13 +15,11 @@ namespace ASC.Common.Utils
public static ConnectionStringCollection ConnectionStrings { get; private set; }
public static LogManager LogManager { get; private set; }
public static IApplicationBuilder InitConfigurationManager(this IApplicationBuilder app)
public static void Init(IServiceProvider serviceProvider)
{
var serviceProvider = app.ApplicationServices;
AppSettings = serviceProvider.GetService<IConfiguration>();
LogManager = serviceProvider.GetService<LogManager>();
ConnectionStrings = new ConnectionStringCollection(GetSettings<ConnectionStringSettings>("ConnectionStrings"));
return app;
}
public static IEnumerable<T> GetSettings<T> (string section) where T : new ()
{

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.5.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0-preview5.19227.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0-preview5.19227.9" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0-preview5.19227.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ASC.Common\ASC.Common.csproj" />
<ProjectReference Include="..\ASC.Core.Common\ASC.Core.Common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace ASC.Resource.Manager
{
public class EnabledSettings
{
public List<string> Langs { get; set; }
public List<string> Projects { get; set; }
}
}

View File

@ -0,0 +1,209 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using ASC.Common.Logging;
using Newtonsoft.Json;
using Formatting = Newtonsoft.Json.Formatting;
namespace ASC.Resource.Manager
{
public static class JsonManager
{
public static void UploadJson(string fileName, Stream fileStream, string projectName, string moduleName)
{
var culture = GetCultureFromFileName(fileName);
string jsonString;
using (var reader = new StreamReader(fileStream))
{
jsonString = reader.ReadToEnd();
}
var jsonObj = new Dictionary<string, string>();
if (Path.GetExtension(fileName) == ".xml")
{
var doc = new XmlDocument();
doc.LoadXml(jsonString);
var list = doc.SelectNodes("//resources//string");
if (list != null)
{
try
{
var nodes = list.Cast<XmlNode>().ToList();
jsonObj = nodes.ToDictionary(r => r.Attributes["name"].Value, r => r.InnerText);
}
catch (Exception e)
{
LogManager.GetLogger("ASC").ErrorFormat("parse xml " + fileName, e);
}
}
}
else
{
jsonObj = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
}
var fileID = ResourceData.AddFile(fileName, projectName, moduleName);
const string resourceType = "text";
foreach (var key in jsonObj.Keys)
{
var word = new ResWord
{
Title = key,
ValueFrom = jsonObj[key],
ResFile = new ResFile {FileID = fileID}
};
if (culture != "Neutral")
{
var neutralKey = new ResWord
{
Title = key,
ValueFrom = jsonObj[key],
ResFile = new ResFile {FileID = fileID}
};
ResourceData.GetValueByKey(neutralKey, "Neutral");
if (string.IsNullOrEmpty(neutralKey.ValueTo)) continue;
}
ResourceData.AddResource(culture, resourceType, DateTime.UtcNow, word, true, "Console");
}
}
public static void ExportJson(string project, string module, string language, string exportPath, bool toJson = true, bool withDefaultValue = true)
{
var filter = new ResCurrent
{
Project = new ResProject { Name = project },
Module = new ResModule { Name = module },
Language = new ResCulture { Title = language }
};
var words = ResourceData.GetListResWords(filter, string.Empty).GroupBy(x => x.ResFile.FileID).ToList();
if (!words.Any())
{
Console.WriteLine("Error!!! Can't find appropriate project and module. Possibly wrong names!");
return;
}
foreach (var fileWords in words)
{
var wordsDictionary = new Dictionary<string, string>();
foreach (var word in fileWords.OrderBy(x => x.Title).Where(word => !wordsDictionary.ContainsKey(word.Title)))
{
if (string.IsNullOrEmpty(word.ValueTo) && !withDefaultValue) continue;
wordsDictionary[word.Title] = word.ValueTo ?? word.ValueFrom;
if (!string.IsNullOrEmpty(wordsDictionary[word.Title]))
{
wordsDictionary[word.Title] = wordsDictionary[word.Title].TrimEnd('\n').TrimEnd('\r');
}
}
var firstWord = fileWords.FirstOrDefault();
var fileName = firstWord == null
? module
: Path.GetFileNameWithoutExtension(firstWord.ResFile.FileName);
string zipFileName = null;
if (toJson)
{
zipFileName = Path.Combine(exportPath, language == "Neutral" ? "en" : language, $"{fileName}.json");
}
else
{
zipFileName = Path.Combine(exportPath, project, module, $"{fileName}{(language == "Neutral" ? string.Empty : "." + language)}.resx");
}
var dirName = Path.GetDirectoryName(zipFileName);
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
using TextWriter writer = new StreamWriter(zipFileName);
if (toJson)
{
var obj = JsonConvert.SerializeObject(wordsDictionary, Formatting.Indented);
writer.Write(obj);
}
else
{
var data = new XmlDocument();
var resources = data.CreateElement("resources");
foreach (var ind in wordsDictionary)
{
var stringAttr = data.CreateAttribute("name");
stringAttr.Value = ind.Key;
var child = data.CreateElement("string");
child.Attributes.Append(stringAttr);
child.InnerText = ind.Value;
resources.AppendChild(child);
}
data.AppendChild(resources);
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = " ",
NewLineChars = Environment.NewLine,
NewLineHandling = NewLineHandling.Replace,
OmitXmlDeclaration = false,
ConformanceLevel = ConformanceLevel.Fragment
};
using var xmlTextWriter = XmlWriter.Create(writer, settings);
data.WriteTo(xmlTextWriter);
xmlTextWriter.Flush();
}
}
}
private static string GetCultureFromFileName(string fileName)
{
var culture = "Neutral";
var nameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
if (nameWithoutExtension != null && nameWithoutExtension.Split('.').Length > 1)
{
culture = nameWithoutExtension.Split('.')[1];
}
return culture;
}
}
}

View File

@ -0,0 +1,50 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Collections.Generic;
namespace ASC.Resource.Manager
{
public class Author
{
public string Login { get; set; }
public string Password { get; set; }
public bool IsAdmin { get; set; }
public List<ResCulture> Langs { get; set; }
public List<ResProject> Projects { get; set; }
public Author()
{}
public Author(string login)
{
Login = login;
IsAdmin = false;
Langs = new List<ResCulture>();
Projects = new List<ResProject>();
}
}
}

View File

@ -0,0 +1,44 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
namespace ASC.Resource.Manager
{
public class ResCulture
{
public string Title { get; set; }
public string Value { get; set; }
public bool Available { get; set; }
public override bool Equals(object obj)
{
return Title.Equals(((ResCulture) obj).Title);
}
public override int GetHashCode()
{
return Title.GetHashCode();
}
}
}

View File

@ -0,0 +1,42 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ASC.Resource.Manager
{
public class ResCurrent
{
public ResProject Project { get; set; }
public ResModule Module { get; set; }
public ResWord Word { get; set; }
public ResCulture Language { get; set; }
public Author Author { get; set; }
}
}

View File

@ -0,0 +1,36 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
namespace ASC.Resource.Manager
{
public class ResFile
{
public int FileID { get; set; }
public string FileName { get; set; }
public string ProjectName { get; set; }
public string ModuleName { get; set; }
}
}

View File

@ -0,0 +1,50 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Collections.Generic;
namespace ASC.Resource.Manager
{
public class ResModule
{
public string Name { get; set; }
public bool IsLock { get; set; }
public List<ResWord> ListWords { get; set; }
public Dictionary<WordStatusEnum, int> Counts { get; set; }
public ResModule()
{
ListWords = new List<ResWord>();
Counts = new Dictionary<WordStatusEnum, int>
{
{WordStatusEnum.Translated, 0},
{WordStatusEnum.Changed, 0},
{WordStatusEnum.All, 0},
{WordStatusEnum.Untranslated, 0}
};
}
}
}

View File

@ -0,0 +1,36 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Collections.Generic;
namespace ASC.Resource.Manager
{
public class ResProject
{
public string Name { get; set; }
public List<ResModule> Modules { get; set; }
}
}

View File

@ -0,0 +1,45 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Collections.Generic;
namespace ASC.Resource.Manager
{
public class ResWord
{
public ResFile ResFile { get; set; }
public WordStatusEnum Status { get; set; }
public string Title { get; set; }
public string ValueFrom { get; set; }
public string ValueTo { get; set; }
public string TextComment { get; set; }
public string Link { get; set; }
public List<string> Alternative { get; set; }
public int Flag { get; set; }
}
}

View File

@ -0,0 +1,36 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
namespace ASC.Resource.Manager
{
public enum WordStatusEnum
{
Untranslated,
Changed,
Translated,
All
}
}

View File

@ -0,0 +1,19 @@
using CommandLine;
namespace ASC.Resource.Manager
{
public class Options
{
[Option('p', "project", Required = false, HelpText = "Project")]
public string Project { get; set; }
[Option('m', "module", Required = false, HelpText = "Module")]
public string Module { get; set; }
[Option('e', "exportpath", Required = false, HelpText = "Export Path")]
public string ExportPath { get; set; }
[Option('c', "culture", Required = false, HelpText = "Culture")]
public string Culture { get; set; }
}
}

View File

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
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();
try
{
var projectName = options.Project;
var moduleName = options.Module;
var exportPath = options.ExportPath;
var culture = options.Culture;
if (string.IsNullOrEmpty(exportPath))
{
exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
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();
ExportWithProject(projectName, moduleName, culture, exportPath);
Console.WriteLine("The data has been successfully exported!");
}
catch (Exception err)
{
Console.WriteLine(err);
}
void ExportWithProject(string projectName, string moduleName, string culture, string exportPath)
{
if (!string.IsNullOrEmpty(projectName))
{
ExportWithModule(projectName, moduleName, culture, exportPath);
}
else
{
foreach (var p in projects.Select(r => r.ProjectName).Intersect(enabledSettings.Projects))
{
ExportWithModule(p, moduleName, culture, exportPath);
}
}
}
void ExportWithModule(string projectName, string moduleName, string culture, string exportPath)
{
if (!string.IsNullOrEmpty(moduleName))
{
ExportWithCulture(projectName, moduleName, culture, exportPath);
}
else
{
foreach (var m in projects.Where(r => r.ProjectName == projectName).Select(r => r.ModuleName))
{
ExportWithCulture(projectName, m, culture, exportPath);
}
}
}
void ExportWithCulture(string projectName, string moduleName, string culture, string exportPath)
{
if (!string.IsNullOrEmpty(culture))
{
JsonManager.ExportJson(projectName, moduleName, culture, exportPath);
}
else
{
foreach (var c in cultures)
{
JsonManager.ExportJson(projectName, moduleName, c, exportPath);
}
}
}
}
}
}

View File

@ -0,0 +1,670 @@
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using ASC.Common.Data;
using ASC.Common.Data.Sql;
using ASC.Common.Data.Sql.Expressions;
namespace ASC.Resource.Manager
{
public static class ResourceData
{
private const string Dbid = "tmresource";
private const string ResDataTable = "res_data";
private const string ResCultureTable = "res_cultures";
private const string ResFilesTable = "res_files";
private const string ResReserveTable = "res_reserve";
private const string ResAuthorsTable = "res_authors";
private const string ResAuthorsLangTable = "res_authorslang";
private const string ResAuthorsFileTable = "res_authorsfile";
public static DateTime GetLastUpdate()
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResFilesTable).SelectMax("LastUpdate");
return dbManager.ExecuteScalar<DateTime>(sql);
}
}
public static List<ResCulture> GetListLanguages(int fileId, string title)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResCultureTable)
.Select("res_cultures.title", "res_cultures.value", "res_cultures.available")
.LeftOuterJoin("res_data", Exp.EqColumns("res_cultures.title", "res_data.cultureTitle"))
.Where("res_data.fileID", fileId)
.Where("res_data.title", title);
var language = dbManager.ExecuteList(sql).ConvertAll(GetCultureFromDB);
language.Remove(language.Find(p => p.Title == "Neutral"));
return language;
}
}
public static Dictionary<ResCulture, List<string>> GetCulturesWithAuthors()
{
using (var dbManager = new DbManager("tmresource"))
{
var sql = new SqlQuery("res_authorslang ral")
.Select(new[] { "ral.authorLogin", "rc.title", "rc.value" })
.InnerJoin("res_cultures rc", Exp.EqColumns("rc.title", "ral.cultureTitle"))
.InnerJoin("res_authors ra", Exp.EqColumns("ra.login", "ral.authorLogin"))
.Where("ra.isAdmin", false);
return dbManager.ExecuteList(sql)
.GroupBy(r => new ResCulture { Title = (string)r[1], Value = (string)r[2] }, r => (string)r[0])
.ToDictionary(r => r.Key, r => r.ToList());
}
}
public static void AddCulture(string cultureTitle, string name)
{
using (var dbManager = new DbManager(Dbid))
{
var sqlInsert = new SqlInsert(ResCultureTable);
sqlInsert.InColumnValue("title", cultureTitle).InColumnValue("value", name);
dbManager.ExecuteNonQuery(sqlInsert);
}
}
public static void AddResource(string cultureTitle, string resType, DateTime date, ResWord word, bool isConsole, string authorLogin, bool updateIfExist = true)
{
using (var db = new DbManager(Dbid))
{
var resData = db.ExecuteScalar<string>(GetQuery(ResDataTable, cultureTitle, word));
var resReserve = db.ExecuteScalar<string>(GetQuery(ResReserveTable, cultureTitle, word));
//нет ключа
if (string.IsNullOrEmpty(resData))
{
//добавляем в основную таблицу
db.ExecuteNonQuery(Insert(ResDataTable, cultureTitle, word)
.InColumnValue("resourceType", resType)
.InColumnValue("timechanges", date)
.InColumnValue("flag", 2)
.InColumnValue("authorLogin", authorLogin));
//добавляем в резервную таблицу
if (isConsole) db.ExecuteNonQuery(Insert(ResReserveTable, cultureTitle, word));
}
else
{
if (cultureTitle == "Neutral" && isConsole)
{
updateIfExist = db.ExecuteScalar<int>(new SqlQuery(ResDataTable)
.SelectCount()
.Where("fileID", word.ResFile.FileID)
.Where(!Exp.Eq("cultureTitle", cultureTitle))
.Where("title", word.Title)) == 0;
}
var isChangeResData = resData != word.ValueFrom;
var isChangeResReserve = resReserve != word.ValueFrom;
if (!updateIfExist) return;
//при работе с консолью изменилось по сравнению с res_data и res_reserve, либо при работе с сайтом изменилось по сравнению с res_reserve
if ((isConsole && isChangeResData && isChangeResReserve) || !isConsole)
{
// изменилась нейтральная культура - выставлен флаг у всех ключей из выбранного файла с выбранным title
if (cultureTitle == "Neutral")
{
var update = new SqlUpdate(ResDataTable)
.Set("flag", 3)
.Where("fileID", word.ResFile.FileID)
.Where("title", word.Title);
db.ExecuteNonQuery(update);
}
// изменилась не нейтральная культура
db.ExecuteNonQuery(Insert(ResDataTable, cultureTitle, word)
.InColumnValue("resourceType", resType)
.InColumnValue("timechanges", date)
.InColumnValue("flag", 2)
.InColumnValue("authorLogin", authorLogin));
if (isConsole) db.ExecuteNonQuery(Update(ResReserveTable, cultureTitle, word));
}
else if (isChangeResData)
{
db.ExecuteNonQuery(Update(ResReserveTable, cultureTitle, word));
}
}
}
}
public static void EditEnglish(ResWord word)
{
using (var dbManager = new DbManager(Dbid))
{
var update = new SqlUpdate(ResDataTable);
update.Set("textvalue", word.ValueFrom).Where("fileID", word.ResFile.FileID).Where("title", word.Title).Where("cultureTitle", "Neutral");
dbManager.ExecuteNonQuery(update);
}
}
public static void AddComment(ResWord word)
{
using (var dbManager = new DbManager(Dbid))
{
var sqlUpdate = new SqlUpdate(ResDataTable);
sqlUpdate.Set("description", word.TextComment).Where("title", word.Title).Where("fileID", word.ResFile.FileID).Where("cultureTitle", "Neutral");
dbManager.ExecuteNonQuery(sqlUpdate);
}
}
public static int AddFile(string fileName, string projectName, string moduleName)
{
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
if (fileNameWithoutExtension != null && fileNameWithoutExtension.Split('.').Length > 1)
{
fileName = fileNameWithoutExtension.Split('.')[0] + Path.GetExtension(fileName);
}
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResFilesTable)
.SelectCount()
.Where("resName", fileName)
.Where("projectName", projectName)
.Where("moduleName", moduleName);
if (dbManager.ExecuteScalar<int>(sql) == 0)
{
var insert = new SqlInsert(ResFilesTable)
.InColumns("resName", "projectName", "moduleName")
.Values(fileName, projectName, moduleName);
dbManager.ExecuteNonQuery(insert);
}
var update = new SqlUpdate(ResFilesTable)
.Set("lastUpdate", DateTime.UtcNow.AddHours(4));
dbManager.ExecuteNonQuery(update);
sql = new SqlQuery(ResFilesTable)
.Select("id")
.Where("resName", fileName)
.Where("projectName", projectName)
.Where("moduleName", moduleName);
return dbManager.ExecuteScalar<int>(sql);
}
}
public static IEnumerable<ResCulture> GetCultures()
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResCultureTable);
sql.Select("title", "value", "available")
.OrderBy("title", true);
return dbManager.ExecuteList(sql).ConvertAll(GetCultureFromDB);
}
}
public static void SetCultureAvailable(string title)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlUpdate(ResCultureTable);
sql.Set("available", true).Where("title", title);
dbManager.ExecuteNonQuery(sql);
}
}
private static ResCulture GetCultureFromDB(IList<object> r)
{
return new ResCulture { Title = (string)r[0], Value = (string)r[1], Available = (bool)r[2] };
}
public static List<ResFile> GetAllFiles()
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResFilesTable);
return dbManager.ExecuteList(sql.SelectAll()).Select(r => new ResFile
{
FileID = (int)r[0],
ProjectName = (string)r[1],
ModuleName = (string)r[2],
FileName = (string)r[3]
}).ToList();
}
}
public static IEnumerable<ResWord> GetListResWords(ResCurrent current, string search)
{
using (var dbManager = new DbManager(Dbid))
{
var exist = new SqlQuery(ResDataTable + " rd3")
.Select("rd3.title")
.Where("rd3.fileid = rd1.fileid")
.Where("rd3.title = concat('del_', rd1.title)")
.Where("rd3.cultureTitle = rd1.cultureTitle");
var sql = new SqlQuery(ResDataTable + " rd1")
.Select("rd1.title", "rd1.fileid", "rd1.textValue", "rd1.description", "rd1.flag", "rd1.link", "rf.resName", "rd2.id", "rd2.flag", "rd2.textValue")
.LeftOuterJoin(ResDataTable + " rd2", Exp.EqColumns("rd1.fileid", "rd2.fileid") & Exp.EqColumns("rd1.title", "rd2.title") & Exp.Eq("rd2.cultureTitle", current.Language.Title))
.InnerJoin(ResFilesTable + " rf", Exp.EqColumns("rf.ID", "rd1.fileID"))
.Where("rf.moduleName", current.Module.Name)
.Where("rf.projectName", current.Project.Name)
.Where("rd1.cultureTitle", "Neutral")
.Where("rd1.flag != 4")
.Where("rd1.resourceType", "text")
.Where(!Exp.Like("rd1.title", @"del\_", SqlLike.StartWith) & !Exp.Exists(exist))
.OrderBy("rd1.id", true);
if (!String.IsNullOrEmpty(search))
sql.Where(Exp.Like("rd1.textvalue", search));
return dbManager.ExecuteList(sql).ConvertAll(r =>
{
var word = GetWord(r);
word.ResFile.FileName = Convert.ToString(r[6]);
if (r[7] != null)
{
word.Status = (int)r[8] == 3 ? WordStatusEnum.Changed : WordStatusEnum.Translated;
word.ValueTo = Convert.ToString(r[9]);
}
else
{
word.Status = WordStatusEnum.Untranslated;
}
return word;
}).OrderBy(r => r.ValueFrom);
}
}
public static List<ResWord> GetListResWords(ResFile resFile, string to, string search)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResDataTable)
.Select("title", "fileid", "textValue", "description", "flag", "link")
.InnerJoin(ResFilesTable, Exp.EqColumns(ResFilesTable + ".ID", ResDataTable + ".fileID"))
.Where("moduleName", resFile.ModuleName)
.Where("projectName", resFile.ProjectName)
.Where("cultureTitle", to)
.Where("flag != 4")
.Where("resourceType", "text")
.OrderBy(ResDataTable + ".id", true);
if (!String.IsNullOrEmpty(resFile.FileName))
sql.Where("resName", resFile.FileName);
if (!String.IsNullOrEmpty(search))
sql.Where(Exp.Like("textvalue", search));
return dbManager.ExecuteList(sql).ConvertAll(GetWord);
}
}
public static void GetListModules(ResCurrent currentData)
{
using (var dbManager = new DbManager(Dbid))
{
var notExist = new SqlQuery(ResDataTable + " rd1")
.Select("1")
.Where("rd1.fileid = rd.fileid")
.Where("rd1.title = concat('del_', rd.title)")
.Where("rd1.cultureTitle = 'Neutral'");
var exist = new SqlQuery(ResDataTable + " rd2")
.Select("1")
.Where("rd2.fileid = rd.fileid")
.Where("rd2.title = rd.title")
.Where("rd2.cultureTitle = 'Neutral'");
var sql = new SqlQuery(ResFilesTable + " rf").Select("rf.moduleName",
string.Format("sum(case rd.cultureTitle when '{0}' then (case rd.flag when 3 then 0 else 1 end) else 0 end)", currentData.Language.Title),
string.Format("sum(case rd.cultureTitle when '{0}' then (case rd.flag when 3 then 1 else 0 end) else 0 end)", currentData.Language.Title),
string.Format("sum(case rd.cultureTitle when '{0}' then 1 else 0 end)", "Neutral"))
.InnerJoin(ResDataTable + " rd", Exp.EqColumns("rd.fileid", "rf.id"))
.Where("rf.projectName", currentData.Project.Name)
.Where("rd.resourceType", "text")
.Where(!Exp.Like("rd.title", @"del\_", SqlLike.StartWith) & Exp.Exists(exist) & !Exp.Exists(notExist))
.GroupBy("moduleName");
dbManager.ExecuteList(sql).ForEach(r =>
{
var module = currentData.Project.Modules.Find(mod => mod.Name == r[0].ToString());
if (module == null) return;
module.Counts[WordStatusEnum.Translated] = Convert.ToInt32(r[1]);
module.Counts[WordStatusEnum.Changed] = Convert.ToInt32(r[2]);
module.Counts[WordStatusEnum.All] = Convert.ToInt32(r[3]);
module.Counts[WordStatusEnum.Untranslated] = module.Counts[WordStatusEnum.All] - module.Counts[WordStatusEnum.Changed] - module.Counts[WordStatusEnum.Translated];
});
}
}
public static void LockModules(string projectName, string modules)
{
using (var dbManager = new DbManager(Dbid))
{
var sqlUpdate = new SqlUpdate(ResFilesTable);
sqlUpdate.Set("isLock", 1).Where("projectName", projectName).Where(Exp.In("moduleName", modules.Split(',')));
dbManager.ExecuteNonQuery(sqlUpdate);
}
}
public static void UnLockModules()
{
using (var dbManager = new DbManager(Dbid))
{
var sqlUpdate = new SqlUpdate(ResFilesTable);
sqlUpdate.Set("isLock", 0);
dbManager.ExecuteNonQuery(sqlUpdate);
}
}
public static void AddLink(string resource, string fileName, string page)
{
using (var dbManager = new DbManager(Dbid))
{
var query = new SqlQuery(ResDataTable);
query.Select(ResDataTable + ".id")
.InnerJoin(ResFilesTable, Exp.EqColumns(ResFilesTable + ".id", ResDataTable + ".fileid"))
.Where(ResDataTable + ".title", resource).Where(ResFilesTable + ".resName", fileName).Where(ResDataTable + ".cultureTitle", "Neutral");
var key = dbManager.ExecuteScalar<int>(query);
var update = new SqlUpdate(ResDataTable);
update.Set("link", page).Where("id", key);
dbManager.ExecuteNonQuery(update);
}
}
public static void GetResWordByKey(ResWord word, string to)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResDataTable)
.Select("textvalue", "description", "link")
.Where("fileID", word.ResFile.FileID)
.Where("cultureTitle", "Neutral")
.Where("title", word.Title);
dbManager.ExecuteList(sql).ForEach(r => GetValue(word, to, r));
GetValueByKey(word, to);
sql = new SqlQuery(ResDataTable + " as res1").Select("res1.textvalue").Distinct()
.InnerJoin(ResDataTable + " as res2", Exp.EqColumns("res1.title", "res2.title") & Exp.EqColumns("res1.fileid", "res2.fileid"))
.Where("res1.cultureTitle", to)
.Where("res2.cultureTitle", "Neutral")
.Where("res2.textvalue", word.ValueFrom);
word.Alternative = new List<string>();
dbManager.ExecuteList(sql).ForEach(r => word.Alternative.Add((string)r[0]));
word.Alternative.Remove(word.ValueTo);
sql = new SqlQuery(ResFilesTable)
.Select("resname")
.Where("id", word.ResFile.FileID);
word.ResFile.FileName = dbManager.ExecuteScalar<string>(sql);
}
}
public static void GetValueByKey(ResWord word, string to)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResDataTable);
sql.Select("textvalue")
.Where("fileID", word.ResFile.FileID)
.Where("cultureTitle", to)
.Where("title", word.Title);
word.ValueTo = dbManager.ExecuteScalar<string>(sql) ?? "";
}
}
private static void GetValue(ResWord word, string to, IList<object> r)
{
word.ValueFrom = (string)r[0] ?? "";
word.TextComment = (string)r[1] ?? "";
var langs = (ConfigurationManager.AppSettings["resources.com-lang"] ?? string.Empty).Split(';').ToList();
var dom = langs.Exists(lang => lang == to) ? ".info" : ".com";
word.Link = !String.IsNullOrEmpty((string)r[2]) ? String.Format("http://{0}-translator.teamlab{1}{2}", to, dom, r[2]) : "";
}
public static List<Author> GetListAuthors()
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResAuthorsTable)
.Select("login", "password", "isAdmin");
return dbManager.ExecuteList(sql).ConvertAll(r => new Author { Login = (string)r[0], Password = (string)r[1], IsAdmin = Convert.ToBoolean(r[2]) });
}
}
public static Author GetAuthor(string login)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResAuthorsTable)
.Select("login", "password", "isAdmin")
.Where("login", login);
var author = dbManager.ExecuteList(sql)
.ConvertAll(r => new Author
{
Login = (string)r[0],
Password = (string)r[1],
IsAdmin = Convert.ToBoolean(r[2])
}).FirstOrDefault();
if (author != null)
{
sql = new SqlQuery("res_cultures rc")
.Select("rc.title", "rc.value", "rc.available")
.InnerJoin(ResAuthorsLangTable + " ral", Exp.EqColumns("rc.title", "ral.cultureTitle"))
.Where("ral.authorLogin", author.Login);
author.Langs = dbManager.ExecuteList(sql).ConvertAll(GetCultureFromDB);
sql = new SqlQuery(ResFilesTable + " rf")
.Select("rf.projectName").Distinct()
.InnerJoin(ResAuthorsFileTable + " raf", Exp.EqColumns("raf.fileid", "rf.id"))
.Where("raf.authorlogin", login)
.Where("rf.isLock", 0);
var projects = dbManager.ExecuteList(sql).Select(r => new ResProject { Name = (string)r[0] }).ToList();
foreach (var resProject in projects)
{
sql = new SqlQuery(ResFilesTable + " rf")
.Select("rf.moduleName").Distinct()
.InnerJoin(ResAuthorsFileTable + " raf", Exp.EqColumns("raf.fileid", "rf.id"))
.Where("rf.projectName", resProject.Name)
.Where("raf.authorlogin", login)
.Where("rf.isLock", 0);
resProject.Modules = dbManager.ExecuteList(sql).Select(r => new ResModule { Name = (string)r[0] }).ToList();
}
author.Projects = projects;
}
return author;
}
}
public static void CreateAuthor(Author author, IEnumerable<string> languages, string modules)
{
using (var dbManager = new DbManager(Dbid))
{
var sqlInsert = new SqlInsert(ResAuthorsTable, true)
.InColumnValue("login", author.Login)
.InColumnValue("password", author.Password)
.InColumnValue("isAdmin", author.IsAdmin);
dbManager.ExecuteNonQuery(sqlInsert);
var delete = new SqlDelete(ResAuthorsLangTable).Where("authorLogin", author.Login);
dbManager.ExecuteNonQuery(delete);
delete = new SqlDelete(ResAuthorsFileTable).Where("authorLogin", author.Login);
dbManager.ExecuteNonQuery(delete);
foreach (var lang in languages)
{
sqlInsert = new SqlInsert(ResAuthorsLangTable, true)
.InColumnValue("authorLogin", author.Login)
.InColumnValue("cultureTitle", lang);
dbManager.ExecuteNonQuery(sqlInsert);
}
var resFiles = GetAllFiles();
//project1:module1-access1,module2-access2;project2:module3-access3,module4-access4
foreach (var projectData in modules.Split(';').Select(project => project.Split(':')))
{
foreach (var mod in projectData[1].Split(','))
{
//var modData = mod.Split('-');
var fileid = resFiles.Where(r => r.ModuleName == mod && r.ProjectName == projectData[0]).Select(r => r.FileID).FirstOrDefault();
sqlInsert = new SqlInsert(ResAuthorsFileTable, true)
.InColumnValue("authorLogin", author.Login)
.InColumnValue("fileId", fileid); //.InColumnValue("writeAccess", Convert.ToBoolean(modData[1]));
dbManager.ExecuteNonQuery(sqlInsert);
}
}
}
}
public static List<ResWord> SearchAll(string projectName, string moduleName, string languageTo, string searchText, string searchType)
{
using (var dbManager = new DbManager(Dbid))
{
var sql = new SqlQuery(ResDataTable)
.Select("title", "fileid", "textValue", "resName", "moduleName", "projectName")
.InnerJoin(ResFilesTable, Exp.EqColumns(ResFilesTable + ".ID", ResDataTable + ".fileID"))
.Where("cultureTitle", languageTo)
.Where("flag != 4")
.Where(Exp.Like(searchType, searchText))
.Where("resourceType", "text")
.OrderBy("textValue", true);
if (!string.IsNullOrEmpty(projectName) && projectName != "All")
{
sql.Where("projectName", projectName);
if (!string.IsNullOrEmpty(moduleName) && moduleName != "All")
sql.Where("moduleName", moduleName);
}
return dbManager.ExecuteList(sql).ConvertAll(GetSearchWord);
}
}
public static void UpdateHashTable(ref Hashtable table, DateTime date)
{
using (var dbManager = new DbManager("tmresourceTrans"))
{
var sql = new SqlQuery(ResDataTable)
.Select(ResDataTable + ".textValue", ResDataTable + ".title", ResFilesTable + ".ResName", ResDataTable + ".cultureTitle")
.InnerJoin(ResFilesTable, Exp.EqColumns(ResFilesTable + ".id", ResDataTable + ".fileID"))
.Where(Exp.Ge("timechanges", date));
var list = dbManager.ExecuteList(sql);
foreach (var t in list)
{
var key = t[1] + t[2].ToString() + t[3];
if (table.ContainsKey(key))
table[key] = t[0];
else
table.Add(key, t[0]);
}
}
}
private static ResWord GetWord(IList<object> r)
{
return new ResWord { Title = (string)r[0], ResFile = new ResFile { FileID = (int)r[1] }, ValueFrom = (string)r[2], TextComment = (string)r[3], Flag = (int)r[4], Link = (string)r[5] };
}
private static ResWord GetSearchWord(IList<object> r)
{
var resfile = new ResFile { FileID = (int)r[1], FileName = (string)r[3], ModuleName = (string)r[4], ProjectName = (string)r[5] };
return new ResWord { Title = (string)r[0], ResFile = resfile, ValueFrom = (string)r[2] };
}
private static SqlQuery GetQuery(string table, string cultureTitle, ResWord word)
{
return new SqlQuery(table)
.Select("textvalue")
.Where("fileID", word.ResFile.FileID)
.Where("cultureTitle", cultureTitle)
.Where("title", word.Title);
}
private static SqlUpdate Update(string table, string cultureTitle, ResWord word)
{
return new SqlUpdate(table)
.Set("flag", 2)
.Set("textvalue", word.ValueFrom)
.Where("fileID", word.ResFile.FileID)
.Where("title", word.Title)
.Where("cultureTitle", cultureTitle);
}
private static SqlInsert Insert(string table, string cultureTitle, ResWord word)
{
return new SqlInsert(table, true)
.InColumns("title", "textvalue", "cultureTitle", "fileID")
.Values(word.Title, word.ValueFrom, cultureTitle, word.ResFile.FileID);
}
}
}

View File

@ -0,0 +1,24 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ASC.Resource.Manager
{
public class Startup
{
IConfiguration Configuration { get; }
public Startup()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
services.AddSingleton(Configuration);
}
}
}

View File

@ -0,0 +1,37 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"enabled": {
"langs": [
"Neutral",
"ru",
"fr",
"de"
],
"projects": [
"People",
"WebStudio"
]
},
"ConnectionStrings": {
"default": {
"name": "default",
"connectionString": "Server=localhost;Database=onlyoffice;User ID=dev;Password=dev;Pooling=true;Character Set=utf8;AutoEnlist=false;SSL Mode=none",
"providerName": "MySql.Data.MySqlClient"
}
},
"DbProviderFactories": {
"mysql": {
"name": "MySQL Data Provider",
"invariant": "MySql.Data.MySqlClient",
"description": ".Net Framework Data Provider for MySQL",
"type": "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"
}
}
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ASC.Web.Api.Models
namespace ASC.Web.Api.Models
{
public class Module
{

View File

@ -96,9 +96,9 @@ namespace ASC.Web.Api
});
app.InitCommonServiceProvider()
.InitConfigurationManager()
.UseWebItemManager();
CommonServiceProvider.Init(app.ApplicationServices);
ConfigurationManager.Init(app.ApplicationServices);
app.UseWebItemManager();
}
}
}

View File

@ -77,8 +77,8 @@ namespace ASC.Web.Studio
template: "{controller}/{action=Index}/{id?}");
});*/
app.InitCommonServiceProvider()
.InitConfigurationManager();
CommonServiceProvider.Init(app.ApplicationServices);
ConfigurationManager.Init(app.ApplicationServices);
app.UseEndpoints(endpoints =>
{