Exemple #1
0
        public static void Export(Options options)
        {
            var services = new ServiceCollection();
            var startup  = new Startup(Args);

            startup.ConfigureServices(services);

            var serviceProvider = services.BuildServiceProvider();

            using var scope = serviceProvider.CreateScope();
            var scopeClass = scope.ServiceProvider.GetService <ProgramScope>();

            var cultures        = new List <string>();
            var projects        = new List <ResFile>();
            var enabledSettings = new EnabledSettings();
            Func <IServiceProvider, string, string, string, string, string, string, bool> export = null;

            try
            {
                var(project, module, filePath, exportPath, culture, format, key) = options;

                project  = "WebStudio";
                module   = "WebStudio";
                filePath = "Resource.resx";
                //culture = "ru";
                exportPath = @"C:\Git\portals_core\";
                //key = "*,HtmlMaster*";
                key = "*";

                if (format == "json")
                {
                    export = JsonManager.Export;
                }
                else
                {
                    export = ResxManager.Export;
                }

                if (string.IsNullOrEmpty(exportPath))
                {
                    exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                }

                if (!Path.IsPathRooted(exportPath))
                {
                    exportPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), exportPath));
                }

                if (!Directory.Exists(exportPath))
                {
                    Console.WriteLine("Error!!! Export path doesn't exist! Please enter a valid directory path.");
                    return;
                }

                enabledSettings = scopeClass.Configuration.GetSetting <EnabledSettings>("enabled");
                cultures        = scopeClass.ResourceData.GetCultures().Where(r => r.Available).Select(r => r.Title).ToList();//.Intersect(enabledSettings.Langs).ToList();
                projects        = scopeClass.ResourceData.GetAllFiles();

                ExportWithProject(project, module, filePath, culture, exportPath, key);

                Console.WriteLine("The data has been successfully exported!");
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            void ExportWithProject(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(projectName))
                {
                    ExportWithModule(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    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)
                    {
                        ExportWithModule(p, moduleName, fileName, culture, exportPath, key);
                    }
                }
            }

            void ExportWithModule(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(moduleName))
                {
                    ExportWithFile(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    var moduleToExport = projects
                                         .Where(r => r.ProjectName == projectName)
                                         .Where(r => string.IsNullOrEmpty(fileName) || r.FileName == fileName)
                                         .Select(r => r.ModuleName)
                                         .Distinct();

                    foreach (var m in moduleToExport)
                    {
                        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);
                    }
                }
            }

            void ExportWithCulture(string projectName, string moduleName, string fileName, string culture, string exportPath, string key)
            {
                var filePath = Directory.GetFiles(exportPath, $"{fileName}", SearchOption.AllDirectories).FirstOrDefault();

                if (!string.IsNullOrEmpty(culture))
                {
                    exportPath = Path.GetDirectoryName(filePath);
                    export(serviceProvider, projectName, moduleName, fileName, culture, exportPath, key);

                    Console.WriteLine(filePath);
                }
                else
                {
                    var resultFiles = new ConcurrentBag <Tuple <string, string> >();

                    var asmbl     = "";
                    var assmlPath = "";
                    var nsp       = "";

                    var keys = key.Split(",");
                    if (keys.Contains("*"))
                    {
                        if (string.IsNullOrEmpty(filePath))
                        {
                            return;
                        }

                        assmlPath = Path.GetDirectoryName(filePath);

                        var name         = Path.GetFileNameWithoutExtension(fileName);
                        var designerPath = Path.Combine(Path.GetDirectoryName(filePath), $"{name}.Designer.cs");
                        var data         = File.ReadAllText(designerPath);
                        var regex        = new Regex(@"namespace\s(\S*)\s", RegexOptions.IgnoreCase);
                        var matches      = regex.Matches(data);
                        if (!matches.Any() || matches[0].Groups.Count < 2)
                        {
                            return;
                        }

                        //File.Delete(designerPath);

                        nsp = matches[0].Groups[1].Value;

                        do
                        {
                            asmbl = Directory.GetFiles(assmlPath, "*.csproj").FirstOrDefault();
                            if (string.IsNullOrEmpty(asmbl))
                            {
                                assmlPath = Path.GetFullPath(Path.Combine(assmlPath, ".."));
                            }
                        }while (string.IsNullOrEmpty(asmbl));

                        regex   = new Regex(@"\<AssemblyName\>(\S*)\<\/AssemblyName\>", RegexOptions.IgnoreCase);
                        matches = regex.Matches(File.ReadAllText(asmbl));
                        string assName = "";
                        if (!matches.Any() || matches[0].Groups.Count < 2)
                        {
                            assName = Path.GetFileNameWithoutExtension(asmbl);
                        }
                        else
                        {
                            assName = matches[0].Groups[1].Value;
                        }

                        key = CheckExist(fileName, $"{nsp}.{name},{assName}", exportPath);
                        var additional = string.Join(",", keys.Where(r => r.Length > 1 && r.Contains("*")).ToArray());

                        if (!string.IsNullOrEmpty(additional))
                        {
                            key += "," + additional;
                        }

                        exportPath = Path.GetDirectoryName(filePath);
                    }
                    else
                    {
                        if (export != JsonManager.Export)
                        {
                            exportPath = Path.GetDirectoryName(filePath);
                        }
                    }

                    if (string.IsNullOrEmpty(exportPath))
                    {
                        return;
                    }

                    var exportPath1 = exportPath;

                    ParallelEnumerable.ForAll(cultures.AsParallel(), c =>
                    {
                        if (export == JsonManager.Export)
                        {
                            var files = Directory.GetFiles(exportPath1, $"{fileName}", SearchOption.AllDirectories);

                            exportPath = files.FirstOrDefault(r => Path.GetDirectoryName(r) == c);
                            if (exportPath == null)
                            {
                                exportPath = Path.GetDirectoryName(Path.GetDirectoryName(files.FirstOrDefault()));
                            }
                        }

                        var any = export(serviceProvider, projectName, moduleName, fileName, c, exportPath, key);
                        if (any)
                        {
                            resultFiles.Add(new Tuple <string, string>(c, $"{filePath.Replace(".resx", (c == "Neutral" ? $".resx" : $".{c}.resx"))}".Substring(assmlPath.Length + 1)));
                        }
                    });
Exemple #2
0
        public static void Export(Options options)
        {
            var services = new ServiceCollection();
            var startup  = new Startup();

            startup.ConfigureServices(services);

            var serviceProvider = services.BuildServiceProvider();

            using var scope = serviceProvider.CreateScope();
            var scopeClass = scope.ServiceProvider.GetService <ProgramScope>();

            var cultures        = new List <string>();
            var projects        = new List <ResFile>();
            var enabledSettings = new EnabledSettings();
            Action <IServiceProvider, string, string, string, string, string, string> export = null;

            try
            {
                var(project, module, filePath, exportPath, culture, format, key) = options;

                project    = "WebStudio";
                module     = "WebStudio";
                filePath   = "Resource.resx";
                exportPath = @"C:\Git\portals_core\web\ASC.Web.Core\PublicResources";
                key        = "LicenseUploadedOverdueSupport";

                if (format == "json")
                {
                    export = JsonManager.Export;
                }
                else
                {
                    export = ResxManager.Export;
                }

                if (string.IsNullOrEmpty(exportPath))
                {
                    exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                }

                if (!Path.IsPathRooted(exportPath))
                {
                    exportPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), exportPath));
                }

                if (!Directory.Exists(exportPath))
                {
                    Console.WriteLine("Error!!! Export path doesn't exist! Please enter a valid directory path.");
                    return;
                }

                enabledSettings = scopeClass.Configuration.GetSetting <EnabledSettings>("enabled");
                cultures        = scopeClass.ResourceData.GetCultures().Where(r => r.Available).Select(r => r.Title).Intersect(enabledSettings.Langs).ToList();
                projects        = scopeClass.ResourceData.GetAllFiles();
                //key = CheckExist("FilesJSResource", "ASC.Files.Resources.FilesJSResource,ASC.Files");

                ExportWithProject(project, module, filePath, culture, exportPath, key);

                Console.WriteLine("The data has been successfully exported!");
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            void ExportWithProject(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(projectName))
                {
                    ExportWithModule(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    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)
                    {
                        ExportWithModule(p, moduleName, fileName, culture, exportPath, key);
                    }
                }
            }

            void ExportWithModule(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(moduleName))
                {
                    ExportWithFile(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    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)
                    {
                        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);
                    }
                }
            }

            void ExportWithCulture(string projectName, string moduleName, string fileName, string culture, string exportPath, string key)
            {
                if (!string.IsNullOrEmpty(culture))
                {
                    export(serviceProvider, projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    ParallelEnumerable.ForAll(cultures.AsParallel(), c => export(serviceProvider, projectName, moduleName, fileName, c, exportPath, key));
                }
            }
        }
Exemple #3
0
        public static void Export(Options options)
        {
            var services = new ServiceCollection();
            var startup  = new Startup();

            startup.ConfigureServices(services);
            var serviceProvider = services.BuildServiceProvider();
            var ResourceData    = serviceProvider.GetService <ResourceData>();

            var cultures        = new List <string>();
            var projects        = new List <ResFile>();
            var enabledSettings = new EnabledSettings();
            Action <ResourceData, string, string, string, string, string, string> export = null;

            try
            {
                var(project, module, filePath, exportPath, culture, format, key) = options;

                if (format == "json")
                {
                    export = JsonManager.Export;
                }
                else
                {
                    export = ResxManager.Export;
                }

                if (string.IsNullOrEmpty(exportPath))
                {
                    exportPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                }

                if (!Path.IsPathRooted(exportPath))
                {
                    exportPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), exportPath));
                }

                if (!Directory.Exists(exportPath))
                {
                    Console.WriteLine("Error!!! Export path doesn't exist! Please enter a valid directory path.");
                    return;
                }

                enabledSettings = serviceProvider.GetService <IConfiguration>().GetSetting <EnabledSettings>("enabled");
                cultures        = ResourceData.GetCultures().Where(r => r.Available).Select(r => r.Title).Intersect(enabledSettings.Langs).ToList();
                projects        = ResourceData.GetAllFiles();

                ExportWithProject(project, module, filePath, culture, exportPath, key);

                Console.WriteLine("The data has been successfully exported!");
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            void ExportWithProject(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(projectName))
                {
                    ExportWithModule(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    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)
                    {
                        ExportWithModule(p, moduleName, fileName, culture, exportPath, key);
                    }
                }
            }

            void ExportWithModule(string projectName, string moduleName, string fileName, string culture, string exportPath, string key = null)
            {
                if (!string.IsNullOrEmpty(moduleName))
                {
                    ExportWithFile(projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    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)
                    {
                        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);
                    }
                }
            }

            void ExportWithCulture(string projectName, string moduleName, string fileName, string culture, string exportPath, string key)
            {
                if (!string.IsNullOrEmpty(culture))
                {
                    export(ResourceData, projectName, moduleName, fileName, culture, exportPath, key);
                }
                else
                {
                    ParallelEnumerable.ForAll(cultures.AsParallel(), c => export(ResourceData, projectName, moduleName, fileName, c, exportPath, key));
                }
            }
        }