Ejemplo n.º 1
0
        private static void Run(CommandLineOptions options)
        {
            try
            {
                //Load XLS FIl
                //Load Loo File
                //for each loo key, insert insert text into xls if key exists too

                var looParser = new LooParser();
                var workbook  = new XLWorkbook(options.SheetFile);

                var worksheet = workbook.Worksheets.Worksheet(1);
                var language  = (ParserLanguage)Enum.Parse(typeof(ParserLanguage), options.Language, true);

                var looLines = looParser.LoadLooFile(options.LooFile);
                foreach (var line in looLines)
                {
                    var cell = worksheet.Columns(1, 1).CellsUsed().Where((IXLCell c ) => c.GetString() == line.Item1).FirstOrDefault();
                    if (cell != null)
                    {
                        cell.WorksheetRow().Cell((int)language).SetValue(line.Item2);
                    }
                }
                workbook.Save();
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e);
            }
        }
Ejemplo n.º 2
0
        private static void Run(CommandLineOptions options)
        {
            try
            {
                var looParser  = new LooParser();
                var xlsxParser = new XlsxParser();
                switch (options.File)
                {
                case var xlsxFile when Path.GetExtension(options.File)
                    .Equals(XlsxExtension, StringComparison.CurrentCultureIgnoreCase)
                    :     //if xlsxl file -> convert to loo
                    foreach (var language in Enum.GetValues(typeof(ParserLanguage)).Cast <ParserLanguage>())
                    {
                        Console.WriteLine($"Preparing loo file for {language} language.");
                        var xlsxLines = xlsxParser.LoadXlsFile(xlsxFile, options.FormatFile, language);

                        Console.WriteLine($"{xlsxLines.Count} keys found for {language} language.");
                        var looFilename  = options.CreateLanguageFiles ? $"locdirect_{language.ToString().ToLower()}{LooExtension}" : $"{((ParserLanguageShort) language).ToString().ToLower()}\\locdirect_english{LooExtension}";
                        var looDirectory = Path.GetDirectoryName(looFilename);

                        if (!string.IsNullOrWhiteSpace(looDirectory) && !Directory.Exists(looDirectory))
                        {
                            Directory.CreateDirectory(looDirectory);
                        }
                        looParser.SaveLooFile(xlsxLines, looFilename);
                        Console.WriteLine($"Saved {looFilename} for {language} language.");
                    }

                    break;

                case var looFile when Path.GetExtension(options.File)
                    .Equals(LooExtension, StringComparison.CurrentCultureIgnoreCase)
                    :     //if loo file -> convert to xlsx
                    Console.WriteLine("Converting .loo file to .xslx");

                    var looLines     = looParser.LoadLooFile(looFile);
                    var xlsxFilename = Path.GetFileNameWithoutExtension(looFile) + XlsxExtension;
                    xlsxParser.SaveXlsFile(looLines, xlsxFilename);
                    Console.WriteLine($"Saved {xlsxFilename}.");
                    break;

                default:
                    Console.WriteLine("Invalid file type supplied. Only .loo and .xlsx are valid.");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e);
            }
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            try
            {
                if (args.Length <= 1) //If no file was supplied exit.
                {
                    PrintHelp();
                }
                else
                {
                    var file       = args[0];
                    var codePage   = int.Parse(args[1]);
                    var looParser  = new LooParser();
                    var xlsxParser = new XlsxParser();
                    switch (file)
                    {
                    case var xlsxFile when Path.GetExtension(file)
                        .Equals(XlsxExtension, StringComparison.CurrentCultureIgnoreCase)
                        : //if xlsxl file -> convert to loo
                        var xlsxLines = xlsxParser.LoadXlsFile(xlsxFile, args.Length > 1 ? args[2] : null);

                        looParser.SaveLooFile(xlsxLines, Path.GetFileNameWithoutExtension(xlsxFile) + LooExtension,
                                              codePage);
                        break;

                    case var looFile when Path.GetExtension(file)
                        .Equals(LooExtension, StringComparison.CurrentCultureIgnoreCase)
                        : //if loo file -> convert to xlsx
                        var looLines = looParser.LoadLooFile(looFile, codePage);

                        xlsxParser.SaveXlsFile(looLines, Path.GetFileNameWithoutExtension(looFile) + XlsxExtension);
                        break;

                    default:
                        PrintHelp();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                PrintHelp();
                throw e;
            }
        }