Exemple #1
0
        public void GenerateProjectTemplatesAndCommandsHandler(ToolCommandInfo commandInfo)
        {
            if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
            {
                throw new Exception("Error executing command. Too few arguments.");
            }

            string sourceDirectory      = commandInfo.Arguments[0];
            string destinationDirectory = commandInfo.Arguments[1];

            List <string> cultures;

            cultures = commandInfo.Arguments[2].ToUpperInvariant() == "ALL"
                     ? new List <string> {
                "cs-CZ", "de-DE", "es-ES", "fr-FR", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "tr-TR", "zh-CN", "zh-TW"
            }
                     : new List <string>(commandInfo.Arguments[2].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries));

            var csProjectTemplateGenerator = new CSharpProjectTemplateGenerator(sourceDirectory, destinationDirectory);

            csProjectTemplateGenerator.GenerateProjectTemplates(cultures);

            var vbProjectTemplateGenerator = new VisualBasicProjectTemplateGenerator(sourceDirectory, destinationDirectory);

            vbProjectTemplateGenerator.GenerateProjectTemplates(cultures);

            var rightClickCommandGenerator = new RightClickCommandGenerator(sourceDirectory, destinationDirectory);

            rightClickCommandGenerator.GenerateRightClickCommands(cultures);
        }
Exemple #2
0
        internal void Listen()
        {
            ToolCommandInfo commandInfo;
            string          commandLine;

            string[] commandParts;

            while (true)
            {
                Console.Write(">> ");
                commandLine = Console.ReadLine().Trim();
                MatchCollection matches = Regex.Matches(commandLine, SplitPattern);
                commandParts = new string[matches.Count];
                int i = 0;

                foreach (Match match in matches)
                {
                    commandParts[i++] = match.Value.Trim("\"".ToCharArray());
                }

                if (commandParts.Length > 0)
                {
                    string[] arguments = commandParts.Length > 1 ? new string[commandParts.Length - 1] : new string[] { };

                    if (commandParts.Length > 1)
                    {
                        Array.ConstrainedCopy(commandParts, 1, arguments, 0, arguments.Length);
                    }

                    commandInfo = new ToolCommandInfo(commandParts[0].Trim().ToLower(), arguments);

                    if (commandInfo.Command == "exit")
                    {
                        break;
                    }

                    if (_handlers != null && _handlers.ContainsKey(commandInfo.Command) && _handlers[commandInfo.Command].Count > 0)
                    {
                        foreach (OnCommand handler in _handlers[commandInfo.Command])
                        {
                            try
                            {
                                handler.Invoke(commandInfo);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine($"Error executing command {commandInfo.Command.ToUpper()}:");
                                Console.Error.WriteLine(ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Command unknown. Type HELP for help.");
                    }
                }
            }
        }
        public void GenerateProjectTemplatesAndCommandsHandler(ToolCommandInfo commandInfo)
        {
            if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
            {
                throw new Exception("Error executing command. Too few arguments.");
            }
            string                   sourceDirectory          = commandInfo.Arguments[0];
            string                   destinationDirectory     = commandInfo.Arguments[1];
            List <string>            cultures                 = new List <string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
            ProjectTemplateGenerator projectTemplateGenerator = new ProjectTemplateGenerator(sourceDirectory, destinationDirectory);

            projectTemplateGenerator.GenerateProjectTemplates(cultures);
            RightClickCommandGenerator rightClickCommandGenerator = new RightClickCommandGenerator(sourceDirectory, destinationDirectory);

            rightClickCommandGenerator.GenerateRightClickCommands(cultures);
        }
        public void ExtractLocalizableItems(ToolCommandInfo commandInfo)
        {
            if (commandInfo.Arguments == null || commandInfo.Arguments.Length < 3)
            {
                throw new Exception("Error executing command. Too few arguments.");
            }
            string                    sourceDirectory      = commandInfo.Arguments[0];
            string                    destinationDirectory = commandInfo.Arguments[1];
            List <string>             cultures             = new List <string>(commandInfo.Arguments[2].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
            LocalizableItemsExtractor extractor            = new LocalizableItemsExtractor(sourceDirectory, destinationDirectory);

            extractor.ExtractVsix(cultures);
            extractor.ExtractProjectTemplates(cultures);
            extractor.ExtractCommandTemplates(cultures);
            extractor.ExtractTemplateEngineTemplates(cultures);
            extractor.ExtractWtsTemplates(cultures);
            extractor.ExtractResourceFiles(cultures);
        }
        private static void PrintHelp(ToolCommandInfo commandInfo)
        {
            if (commandInfo.Arguments == null || commandInfo.Arguments.Length == 0)
            {
                Console.WriteLine("For more information on a specific command, type HELP command-name");
                Console.WriteLine("EXIT\tQuits Windows Template Studio Localization Tool.");
                Console.WriteLine("EXT\tExtract localizable items for different cultures.");
                Console.WriteLine("GEN\tGenerates Project Templates for different cultures.");
                Console.WriteLine("HELP\tProvides Help information for Windows Template Studio Localization Tool.");
                Console.WriteLine();
            }
            else
            {
                switch (commandInfo.Arguments[0].ToUpper())
                {
                case "EXIT":
                    Console.WriteLine("Quits Windows Template Studio Localization Tool.");
                    Console.WriteLine();
                    Console.WriteLine("EXIT");
                    Console.WriteLine();
                    break;

                case "EXT":
                    Console.WriteLine("Extract localizable items for different cultures.");
                    Console.WriteLine();
                    Console.WriteLine("EXT \"sourceDirectoryPath\" \"destinationDirectoryPath\" \"cultures\"");
                    Console.WriteLine();
                    Console.WriteLine($"\tsourceDirectoryPath\t - path to the folder that contains{argumentNewLine}source files for data extraction{argumentNewLine}(it's root project folder).");
                    Console.WriteLine();
                    Console.WriteLine($"\tdestinationDirectoryPath - path to the folder in which will be{argumentNewLine}saved all extracted items.");
                    Console.WriteLine();
                    Console.WriteLine($"\tcultures\t\t - list of cultures, to extract{argumentNewLine}localizable items for. It's case{argumentNewLine}sensitive (es-us != en-US).");
                    Console.WriteLine();
                    Console.WriteLine("Example:");
                    Console.WriteLine();
                    Console.WriteLine("\tEXT \"C:\\Projects\\wts\" \"C:\\MyFolder\\Extracted\" \"de-DE;es-ES;fr-FR\"");
                    Console.WriteLine();
                    break;

                case "GEN":
                    Console.WriteLine("Generates Project Templates for different cultures.");
                    Console.WriteLine();
                    Console.WriteLine("GEN \"sourceDirectoryPath\" \"destinationDirectoryPath\" \"cultures\"");
                    Console.WriteLine();
                    Console.WriteLine($"\tsourceDirectoryPath\t - path to the folder that contains{argumentNewLine}source files for Project Templates{argumentNewLine}(it's name is CSharp.UWP.2017.{argumentNewLine}Solution).");
                    Console.WriteLine();
                    Console.WriteLine($"\tdestinationDirectoryPath - path to the folder in which will be{argumentNewLine}saved all localized Project{argumentNewLine}Templates (parent for CSharp.UWP.{argumentNewLine}2017.Solution directory).");
                    Console.WriteLine();
                    Console.WriteLine($"\tcultures\t\t - list of cultures, to generate{argumentNewLine}Project Templates for. It's case{argumentNewLine}sensitive (es-us != en-US).");
                    Console.WriteLine();
                    Console.WriteLine("Example:");
                    Console.WriteLine();
                    Console.WriteLine("\tGEN \"C:\\MyFolder\\ProjectTemplates\\CSharp.UWP.2017.Solution\" \"C:\\MyFolder\\Generated\\ProjectTemplates\" \"de-DE;es-ES;fr-FR\"");
                    Console.WriteLine();
                    break;

                case "HELP":
                    Console.WriteLine("Provides Help information for Windows Template Studio Localization Tool.");
                    Console.WriteLine();
                    Console.WriteLine("HELP [command]");
                    Console.WriteLine();
                    Console.WriteLine("\tcommand - displays help information on that command.");
                    Console.WriteLine();
                    break;

                default:
                    Console.WriteLine("Command unknown.");
                    break;
                }
            }
        }