Exemple #1
0
        public void GetReferencedFilesFromFileIdLog_Test(string fileContent, string expected)
        {
            File.WriteAllText(Path.Combine(TestFolder, "test.fileidlog"), fileContent, Encoding.Default);
            var l = UoeUtilities.GetReferencedFilesFromFileIdLog(Path.Combine(TestFolder, "test.fileidlog"), Encoding.Default, "");

            Assert.AreEqual(expected, string.Join(",", l));
        }
Exemple #2
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            var outputDirectory = OutputDirectory ?? Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileNameWithoutExtension(WsdlFilePath));

            Utils.CreateDirectoryIfNeeded(outputDirectory);

            var output = UoeUtilities.GenerateWsdlDoc(GetDlcPath(), WsdlFilePath.ToAbsolutePath(), outputDirectory, Bindings);

            Log.Debug(output);

            var reportFilePath = Path.Combine(outputDirectory, "index.html");

            if (!File.Exists(reportFilePath))
            {
                throw new CommandException($"The documentation was not successfully generated, the following file has not been found: {reportFilePath.PrettyQuote()}.");
            }

            if (!Unattended && !string.IsNullOrEmpty(reportFilePath))
            {
                try {
                    Process.Start(reportFilePath);
                } catch (Exception) {
                    //ignored
                }
            }

            return(0);
        }
Exemple #3
0
        public void GetProcessIoCodePageFromArgs()
        {
            var versionFilePath = Path.Combine(TestFolder, "startup.pf");

            File.WriteAllText(versionFilePath, "#\n\n-cpinternal UTF-8\n-cpstream ISO8859-15\n-cpcoll Basic\n-cpcase French");
            Assert.AreEqual("ISO8859-15", UoeUtilities.GetProcessIoCodePageFromArgs(new UoeProcessArgs().AppendFromPfFilePath(versionFilePath)));
        }
Exemple #4
0
        public void GetDatabaseReferencesFromXrefFile_Test(string fileContent, string expected)
        {
            File.WriteAllText(Path.Combine(TestFolder, "test.xrf"), fileContent, Encoding.Default);
            var l = UoeUtilities.GetDatabaseReferencesFromXrefFile(Path.Combine(TestFolder, "test.xrf"), Encoding.Default);

            Assert.AreEqual(expected, string.Join(",", l));
        }
Exemple #5
0
        public void GetDatabaseVersionFromInternalVersion(int internalCode, int expectedVersion, int blockSize)
        {
            var ver = UoeUtilities.GetDatabaseVersionFromInternalVersion(internalCode, 0, out DatabaseBlockSize bs);

            Assert.AreEqual(expectedVersion, ver.Major);
            Assert.AreEqual(blockSize, (byte)bs);
        }
Exemple #6
0
        public void GetProVersionFromDlc_Test(string version, int major, int minor, int patch)
        {
            var versionFilePath = Path.Combine(TestFolder, "version");

            File.WriteAllText(versionFilePath, version);
            Assert.AreEqual(new Version(major, minor, patch), UoeUtilities.GetProVersionFromDlc(TestFolder));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public UoeProcessIo(string dlcPath, bool useCharacterModeOfProgress, bool?canUseNoSplash = null, Encoding redirectedOutputEncoding = null) : base(null)
 {
     DlcPath                  = dlcPath;
     UseCharacterMode         = useCharacterModeOfProgress;
     CanUseNoSplash           = canUseNoSplash ?? UoeUtilities.CanProVersionUseNoSplashParameter(UoeUtilities.GetProVersionFromDlc(DlcPath));
     ExecutablePath           = UoeUtilities.GetProExecutableFromDlc(DlcPath, UseCharacterMode);
     RedirectedOutputEncoding = redirectedOutputEncoding ?? UoeUtilities.GetProcessIoCodePageFromDlc(dlcPath);
 }
Exemple #8
0
        public void ProlibraryTestEdgeCases()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath) || UoeUtilities.GetProVersionFromDlc(dlcPath).Major != 11)
            {
                return;
            }

            // test the edge cases were the file entries fill 511/512/513 of the file entries block size
            var filePath = Path.Combine(TestFolder, "test_edge_cases");

            File.WriteAllText($"{filePath}1", "");
            File.WriteAllText($"{filePath}2", "");
            File.WriteAllText($"{filePath}3", "");
            File.WriteAllText($"{filePath}4", "");
            File.WriteAllText($"{filePath}5", "");

            for (int i = 65; i >= 63; i--)
            {
                // progress prolib
                OeProlibArchiver oeArchiver;
                try {
                    oeArchiver = new OeProlibArchiver(dlcPath, Encoding.Default);
                } catch (ArchiverException e) {
                    Console.WriteLine($"Cancelling test, prolib not found! : {e.Message}");
                    return;
                }
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = $"{filePath}1", PathInArchive = new string('a', 83), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}2", PathInArchive = new string('b', 84), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}3", PathInArchive = new string('f', 84), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}4", PathInArchive = new string('c', i), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}5", PathInArchive = new string('d', 1), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    }
                });

                // our prolib
                File.Copy(Path.Combine(TestFolder, "test_edge_cases_official.pl"), Path.Combine(TestFolder, "test_edge_cases.pl"));
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, "test_edge_cases.pl"), null)) {
                    prolib.Save();
                }

                Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "test_edge_cases_official.pl")).SequenceEqual(File.ReadAllBytes(Path.Combine(TestFolder, "test_edge_cases.pl"))), "file not recreated the same way : test_edge_cases.");

                File.Delete(Path.Combine(TestFolder, "test_edge_cases.pl"));
                File.Delete(Path.Combine(TestFolder, "test_edge_cases_official.pl"));
            }
        }
Exemple #9
0
        public void GetEncodingFromOpenedgeCodePage_Test(string codePage, string expectedEncoding, bool isOk)
        {
            var output = UoeUtilities.GetEncodingFromOpenedgeCodePage(codePage, out var encoding);

            Assert.AreEqual(isOk, output);
            if (isOk)
            {
                Assert.AreEqual(Encoding.GetEncoding(expectedEncoding), encoding);
            }
        }
Exemple #10
0
 public void GetProExecutableFromDlc_Test()
 {
     if (!TestHelper.GetDlcPath(out string dlcPath))
     {
         return;
     }
     Assert.IsTrue(UoeUtilities.GetProExecutableFromDlc(UoeUtilities.GetDlcPathFromEnv()).StartsWith(Path.Combine(dlcPath, "bin", "prowin")));
     Assert.AreEqual(Path.Combine(UoeUtilities.GetDlcPathFromEnv(), "bin", "_progres.exe"), UoeUtilities.GetProExecutableFromDlc(dlcPath, true));
     Assert.ThrowsException <UoeExecutionParametersException>(() => UoeUtilities.GetProExecutableFromDlc(TestFolder, true));
     Assert.ThrowsException <UoeExecutionParametersException>(() => UoeUtilities.GetProExecutableFromDlc(TestFolder));
 }
Exemple #11
0
        public void GetProPathFromIniFile_TestEnvVarReplacement()
        {
            var iniPath = Path.Combine(TestFolder, "test.ini");

            File.WriteAllText(iniPath, "[Startup]\nPROPATH=t:\\error:exception\";C:\\Windows,%TEMP%;z:\\nooooop");

            var list = UoeUtilities.GetProPathFromIniFile(iniPath, TestFolder);

            Assert.AreEqual(2, list.Count);
            Assert.IsTrue(list.ToList().Exists(s => s.Equals("C:\\Windows")));
            Assert.IsTrue(list.ToList().Exists(s => s.Equals(Environment.GetEnvironmentVariable("TEMP"))));
        }
        /// <summary>
        /// Read the table referenced in the source file using either the xref file or the RCODE-INFO:TABLE-LIST,
        /// make sure to also get the CRC value for each table
        /// </summary>
        /// <param name="ienv"></param>
        /// <param name="analysisModeSimplifiedDatabaseReferences"></param>
        public void ComputeRequiredDatabaseReferences(AUoeExecutionEnv ienv, bool analysisModeSimplifiedDatabaseReferences)
        {
            if (!IsAnalysisMode || string.IsNullOrEmpty(CompilationXrefFilePath) && string.IsNullOrEmpty(CompilationRcodeTableListFilePath))
            {
                return;
            }
            AddWarningIfFileDefinedButDoesNotExist(CompilationRcodeTableListFilePath);

            RequiredDatabaseReferences = new List <UoeDatabaseReference>();

            // read from xref (we need the table CRC from the environment)
            if (ienv is UoeExecutionEnv env && !analysisModeSimplifiedDatabaseReferences)
            {
                if (File.Exists(CompilationXrefFilePath))
                {
                    foreach (var dbRef in UoeUtilities.GetDatabaseReferencesFromXrefFile(CompilationXrefFilePath, ienv.IoEncoding))
                    {
                        if (env.TablesCrc.ContainsKey(dbRef))
                        {
                            RequiredDatabaseReferences.Add(new UoeDatabaseReferenceTable {
                                QualifiedName = dbRef,
                                Crc           = env.TablesCrc[dbRef]
                            });
                        }
                        else if (env.Sequences.Contains(dbRef))
                        {
                            RequiredDatabaseReferences.Add(new UoeDatabaseReferenceSequence {
                                QualifiedName = dbRef
                            });
                        }
                    }
                }
            }

            // read from rcode-info:table-list
            if (File.Exists(CompilationRcodeTableListFilePath))
            {
                Utils.ForEachLine(CompilationRcodeTableListFilePath, null, (i, line) => {
                    var split = line.Split('\t');
                    if (split.Length >= 1)
                    {
                        var qualifiedName = split[0].Trim();
                        if (!RequiredDatabaseReferences.Exists(r => r.QualifiedName.EqualsCi(qualifiedName)))
                        {
                            RequiredDatabaseReferences.Add(new UoeDatabaseReferenceTable {
                                QualifiedName = qualifiedName,
                                Crc           = split[1].Trim()
                            });
                        }
                    }
                }, ienv.IoEncoding);
            }
        }
Exemple #13
0
        public void ReturnProgressSessionDefaultPropath_Test()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            var output = UoeUtilities.GetProgressSessionDefaultPropath(dlcPath, true);

            Assert.IsTrue(output.Exists(p => p.Contains("tty")));

            output = UoeUtilities.GetProgressSessionDefaultPropath(dlcPath, false);
            Assert.IsTrue(output.Exists(p => p.Contains("gui")));
        }
Exemple #14
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            if (string.IsNullOrEmpty(BaseDirectory))
            {
                BaseDirectory = Directory.GetCurrentDirectory();
                Log.Info($"Using current directory as base directory : {BaseDirectory.PrettyQuote()}.");
            }

            foreach (var path in UoeUtilities.GetProPathFromIniFile(File, BaseDirectory))
            {
                Out.WriteResultOnNewLine(path);
            }

            return(0);
        }
Exemple #15
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            var outputFile = OutputFile ?? Path.Combine(Directory.GetCurrentDirectory(), $"{Path.GetFileNameWithoutExtension(InputFilePath)}.i");

            Utils.CreateDirectoryForFileIfNeeded(outputFile);

            string output;

            if (InputFilePath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
            {
                var temporaryXsd = Path.Combine(Path.GetDirectoryName(outputFile.ToAbsolutePath()), Path.GetTempFileName());
                try {
                    using (XmlReader reader = XmlReader.Create(InputFilePath)) {
                        XmlSchemaInference schema = new XmlSchemaInference();
                        var schemaSet             = schema.InferSchema(reader);
                        foreach (XmlSchema s in schemaSet.Schemas())
                        {
                            using (var stringWriter = new StringWriterWithEncoding(Encoding.UTF8)) {
                                using (var writer = XmlWriter.Create(stringWriter)) {
                                    s.Write(writer);
                                }

                                File.WriteAllText(temporaryXsd, stringWriter.ToString());
                            }
                        }
                    }

                    output = UoeUtilities.GenerateDatasetDefinition(GetDlcPath(), temporaryXsd, outputFile);
                } finally {
                    Utils.DeleteFileIfNeeded(temporaryXsd);
                }
            }
            else
            {
                output = UoeUtilities.GenerateDatasetDefinition(GetDlcPath(), InputFilePath.ToAbsolutePath(), outputFile);
            }

            Log.Debug(output);

            if (!File.Exists(outputFile))
            {
                throw new CommandException($"The dataset definition file (.i) was not successfully generated, the following file has not been found: {outputFile.PrettyQuote()}.");
            }

            return(0);
        }
        /// <summary>
        /// Gets the files that were necessary to compile this file
        /// </summary>
        private void ComputeReferencedFiles(Encoding enc, string currentDirectory)
        {
            if (string.IsNullOrEmpty(CompilationFileIdLogFilePath))
            {
                return;
            }

            if (File.Exists(CompilationFileIdLogFilePath))
            {
                RequiredFiles = UoeUtilities.GetReferencedFilesFromFileIdLog(CompilationFileIdLogFilePath, enc, currentDirectory);

                RequiredFiles.RemoveWhere(f =>
                                          f.PathEquals(CompiledFilePath) ||
                                          f.EndsWith(".r", StringComparison.OrdinalIgnoreCase) ||
                                          f.EndsWith(".pl", StringComparison.OrdinalIgnoreCase) ||
                                          !String.IsNullOrEmpty(CompilationXrefFilePath) && f.PathEquals(CompilationXrefFilePath));
            }
        }
Exemple #17
0
        public void ListProlibFilesInDirectory_Test()
        {
            var prolib = Path.Combine(TestFolder, "prolib");

            Directory.CreateDirectory(prolib);
            Directory.CreateDirectory(Path.Combine(prolib, "sub"));
            File.WriteAllText(Path.Combine(prolib, "1"), "");
            File.WriteAllText(Path.Combine(prolib, "2.pl"), "");
            File.WriteAllText(Path.Combine(prolib, "3"), "");
            File.WriteAllText(Path.Combine(prolib, "4.pl"), "");
            File.WriteAllText(Path.Combine(prolib, "sub", "5.pl"), "");

            var plList = UoeUtilities.ListProlibFilesInDirectory(prolib);

            Assert.AreEqual(2, plList.Count);
            Assert.IsTrue(plList.Exists(s => Path.GetFileName(s ?? "").Equals("2.pl")));
            Assert.IsTrue(plList.Exists(s => Path.GetFileName(s ?? "").Equals("4.pl")));
        }
Exemple #18
0
 /// <summary>
 /// Returns the DLC PATH
 /// </summary>
 /// <returns></returns>
 /// <exception cref="Exception"></exception>
 protected string GetDlcPath()
 {
     if (string.IsNullOrEmpty(_dlcDirectoryPath))
     {
         if (!string.IsNullOrEmpty(DlcDirectoryPath))
         {
             _dlcDirectoryPath = DlcDirectoryPath;
         }
         else
         {
             _dlcDirectoryPath = UoeUtilities.GetDlcPathFromEnv();
             if (string.IsNullOrEmpty(_dlcDirectoryPath) || !Directory.Exists(_dlcDirectoryPath))
             {
                 throw new Exception($"The path to the Openedge installation directory has not been found. Specify it with the --dlc option. Alternatively, set a {UoeConstants.OeDlcAlternativeEnvVar} (or {UoeConstants.OeDlcEnvVar}) environment variable containing the installation path.");
             }
             Log.Debug($"Using the DLC path found in the environment variable: {_dlcDirectoryPath.PrettyQuote()}.");
         }
     }
     return(_dlcDirectoryPath);
 }
Exemple #19
0
 public static bool GetDlcPath(out string dlcPath)
 {
     try {
         dlcPath = UoeUtilities.GetDlcPathFromEnv();
     } catch (UoeDlcNotFoundException) {
         Console.WriteLine("Cancelling test, DLC environment variable not found!");
         dlcPath = null;
         return(false);
     }
     if (string.IsNullOrEmpty(dlcPath))
     {
         Console.WriteLine("Cancelling test, DLC environment variable not found!");
         return(false);
     }
     if (!Directory.Exists(dlcPath))
     {
         Console.WriteLine("Cancelling test, DLC environment variable not found!");
         return(false);
     }
     return(true);
 }
Exemple #20
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            var dlcPath = GetDlcPath();

            var args = new UoeProcessArgs();

            args.Append(ToolArguments(), GetDatabaseConnections(true, false));
            if (UoeUtilities.CanProVersionUseNoSplashParameter(UoeUtilities.GetProVersionFromDlc(dlcPath)))
            {
                args.Append("-nosplash");
            }
            args.Append(RemainingArgs);

            var executable = UoeUtilities.GetProExecutableFromDlc(dlcPath);

            var argsString = args.ToCliArgs();

            Log?.Debug($"Executing command:\n{ProcessArgs.ToCliArg(executable)} {argsString}");

            var process = new Process {
                StartInfo = new ProcessStartInfo {
                    FileName         = executable,
                    Arguments        = argsString,
                    WorkingDirectory = ExecutionWorkingDirectory ?? Directory.GetCurrentDirectory()
                }
            };

            process.Start();

            if (!DetachedMode)
            {
                var detach = SpinUntilConditionOrDetachedOrExited(() => process.HasExited, "exit the program");
                if (!detach && !process.HasExited)
                {
                    process.Kill();
                }
            }

            return(0);
        }
Exemple #21
0
        public List <IUoeDatabase> ReadDatabasesFromDumpFile(string filePath)
        {
            var               output          = new List <IUoeDatabase>();
            IUoeDatabase      currentDatabase = null;
            IUoeDatabaseTable currentTable    = null;

            using (var reader = new UoeExportReader(filePath, Env.IoEncoding)) {
                reader.QuestionMarkReturnsNull = true;
                while (reader.ReadRecord(out List <string> fields, out int _, true))
                {
                    if (fields.Count < 2)
                    {
                        continue;
                    }

                    switch (fields[0])
                    {
                    case "D":
                        currentDatabase = GetNew <IUoeDatabase>();
                        currentDatabase.ExtractionTime = DateTime.ParseExact(fields[1], "yyyyMMdd-HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
                        currentDatabase.LogicalName    = fields[2];
                        currentDatabase.PhysicalName   = Path.GetFileName(fields[3]);
                        currentDatabase.Version        = UoeUtilities.GetDatabaseVersionFromInternalVersion(int.Parse(fields[4]), int.Parse(fields[5]), out DatabaseBlockSize bs);
                        currentDatabase.BlockSize      = bs;
                        currentDatabase.Charset        = fields[6];
                        currentDatabase.Collation      = fields[7];
                        output.Add(currentDatabase);
                        break;

                    case "S":
                        if (currentDatabase == null)
                        {
                            throw new UoeExecutionException($"Found sequence without a database ({fields[1]}).");
                        }
                        var sequence = GetNew <IUoeDatabaseSequence>();
                        sequence.Name         = fields[1];
                        sequence.CycleOnLimit = fields[2][0] == '1';
                        sequence.Increment    = int.Parse(fields[3]);
                        sequence.Initial      = int.Parse(fields[4]);
                        if (int.TryParse(fields[5], out int min))
                        {
                            sequence.Min = min;
                        }
                        if (int.TryParse(fields[6], out int max))
                        {
                            sequence.Max = max;
                        }
                        (currentDatabase.Sequences ?? (currentDatabase.Sequences = new List <IUoeDatabaseSequence>())).Add(sequence);
                        break;

                    case "T":
                        if (currentDatabase == null)
                        {
                            throw new UoeExecutionException($"Found table without a database ({fields[1]}).");
                        }
                        currentTable                = GetNew <IUoeDatabaseTable>();
                        currentTable.Name           = fields[1];
                        currentTable.DumpName       = fields[2];
                        currentTable.Crc            = ushort.Parse(fields[3]);
                        currentTable.Label          = fields[4];
                        currentTable.LabelAttribute = fields[5];
                        currentTable.Description    = fields[6];
                        currentTable.Hidden         = fields[7][0] == '1';
                        currentTable.Frozen         = fields[8][0] == '1';
                        currentTable.Area           = fields[9];
                        if (Enum.TryParse(fields[10], true, out UoeDatabaseTableType type))
                        {
                            currentTable.Type = type;
                        }
                        currentTable.ValidationExpression       = fields[11];
                        currentTable.ValidationMessage          = fields[12];
                        currentTable.ValidationMessageAttribute = fields[13];
                        currentTable.Replication = fields[14];
                        currentTable.Foreign     = fields[15];
                        (currentDatabase.Tables ?? (currentDatabase.Tables = new List <IUoeDatabaseTable>())).Add(currentTable);
                        break;

                    case "F":
                        if (currentTable == null)
                        {
                            throw new UoeExecutionException($"Found field without a table ({fields[1]}).");
                        }
                        var field = GetNew <IUoeDatabaseField>();
                        field.Name = fields[1];
                        if (Enum.TryParse(fields[2].Replace("-", ""), true, out UoeDatabaseDataType dataType))
                        {
                            field.DataType = dataType;
                        }
                        field.Format                = fields[3];
                        field.FormatAttribute       = fields[4];
                        field.Order                 = int.Parse(fields[5]);
                        field.Position              = int.Parse(fields[6]);
                        field.Mandatory             = fields[7][0] == '1';
                        field.CaseSensitive         = fields[8][0] == '1';
                        field.Extent                = int.Parse(fields[9]);
                        field.InitialValue          = fields[10];
                        field.InitialValueAttribute = fields[11];
                        field.Width                 = int.Parse(fields[12]);
                        field.Label                 = fields[13];
                        field.LabelAttribute        = fields[14];
                        field.ColumnLabel           = fields[15];
                        field.ColumnLabelAttribute  = fields[16];
                        field.Description           = fields[17];
                        field.Help          = fields[18];
                        field.HelpAttribute = fields[19];
                        if (int.TryParse(fields[20], out int decimals))
                        {
                            field.Decimals = decimals;
                        }
                        if (field.DataType == UoeDatabaseDataType.Clob)
                        {
                            field.ClobCharset   = fields[21];
                            field.ClobCollation = fields[22];
                            field.ClobType      = int.Parse(fields[23]);
                        }
                        if (field.DataType == UoeDatabaseDataType.Blob || field.DataType == UoeDatabaseDataType.Clob)
                        {
                            field.LobSize = fields[24];
                            if (int.TryParse(fields[25], out int lobBytes))
                            {
                                field.LobBytes = lobBytes;
                            }
                            field.LobArea = fields[26];
                        }
                        (currentTable.Fields ?? (currentTable.Fields = new List <IUoeDatabaseField>())).Add(field);
                        break;

                    case "X":
                        if (currentTable == null)
                        {
                            throw new UoeExecutionException($"Found trigger without a table ({fields[1]}).");
                        }
                        var trigger = GetNew <IUoeDatabaseTrigger>();
                        if (Enum.TryParse(fields[1].Replace("-", ""), true, out UoeDatabaseTriggerEvent triggerEvent))
                        {
                            trigger.Event = triggerEvent;
                        }
                        trigger.Procedure   = fields[3];
                        trigger.Overridable = fields[4][0] == '1';
                        if (ushort.TryParse(fields[5], out ushort crc))
                        {
                            trigger.Crc = crc;
                        }
                        if (!string.IsNullOrEmpty(fields[2]))
                        {
                            var triggerField = currentTable.Fields?.FirstOrDefault(f => f.Name.Equals(fields[2], StringComparison.CurrentCultureIgnoreCase));
                            if (triggerField == null)
                            {
                                throw new UoeExecutionException($"Found field trigger without a corresponding field ({fields[2]}).");
                            }
                            (triggerField.Triggers ?? (triggerField.Triggers = new List <IUoeDatabaseTrigger>())).Add(trigger);
                        }
                        else
                        {
                            (currentTable.Triggers ?? (currentTable.Triggers = new List <IUoeDatabaseTrigger>())).Add(trigger);
                        }
                        break;

                    case "I":
                        if (currentTable == null)
                        {
                            throw new UoeExecutionException($"Found index without a table ({fields[1]}).");
                        }
                        var index = GetNew <IUoeDatabaseIndex>();
                        index.Name    = fields[1];
                        index.Active  = fields[2][0] == '1';
                        index.Primary = fields[3][0] == '1';
                        index.Unique  = fields[4][0] == '1';
                        index.Word    = fields[5][0] == '1';
                        index.Crc     = ushort.Parse(fields[6]);
                        index.Area    = fields[7];
                        var indexFieldStrings = fields[8].Split(',');
                        index.Description = fields[9];
                        foreach (var indexFieldString in indexFieldStrings)
                        {
                            var indexFieldFound = currentTable.Fields?.FirstOrDefault(f => f.Name.Equals(indexFieldString.Substring(2), StringComparison.CurrentCultureIgnoreCase));
                            if (indexFieldFound == null)
                            {
                                throw new UoeExecutionException($"Found index without a corresponding field ({indexFieldString.Substring(2)}).");
                            }
                            var indexField = GetNew <IUoeDatabaseIndexField>();
                            indexField.Ascending  = indexFieldString[0] == '+';
                            indexField.Abbreviate = indexFieldString[1] == '1';
                            indexField.Field      = indexFieldFound;
                            (index.Fields ?? (index.Fields = new List <IUoeDatabaseIndexField>())).Add(indexField);
                        }
                        (currentTable.Indexes ?? (currentTable.Indexes = new List <IUoeDatabaseIndex>())).Add(index);
                        break;
                    }
                }
            }

            return(output);
        }
Exemple #22
0
 public void GetOpenedgeCodePageFromEncoding_Test(string encoding, string codePage)
 {
     Assert.AreEqual(UoeUtilities.GetOpenedgeCodePageFromEncoding(Encoding.GetEncoding(encoding)).ToLower(), codePage);
 }
Exemple #23
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            Out.WriteResultOnNewLine(UoeUtilities.GetProVersionFromDlc(GetDlcPath()).ToString());

            return(0);
        }
Exemple #24
0
        protected override int ExecuteCommand(CommandLineApplication app, IConsole console)
        {
            Out.WriteResultOnNewLine(UoeUtilities.GetProExecutableFromDlc(GetDlcPath(), CharMode));

            return(0);
        }
Exemple #25
0
        public void ReadAllKindsOfLib()
        {
            CreateProlibResources();
            var list = GetProlibResources();

            foreach (var prolibResource in list)
            {
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, prolibResource.FileName), null)) {
                    Assert.AreEqual(prolibResource.ContainedFiles, string.Join(",", prolib.Files.Select(f => f.RelativePath)), $"Wrong file listing for {prolibResource.FileName}.");
                    foreach (var libraryFileEntry in prolib.Files)
                    {
                        if (!File.Exists(Path.Combine(TestFolder, libraryFileEntry.RelativePath)))
                        {
                            prolib.ExtractToFile(libraryFileEntry.RelativePath, Path.Combine(TestFolder, libraryFileEntry.RelativePath));
                        }
                    }
                }
            }

            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file")).SequenceEqual(new byte[] { 0xAA }), "file incorrect.");
            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file2")).SequenceEqual(new byte[] { 0xAA, 0xAA }), "file2 incorrect.");
            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file.r")).SequenceEqual(GetBytesFromResource("file.r")), "file.r incorrect.");

            foreach (var prolibResource in list.Where(f => f.IsCompressed))
            {
                File.Copy(Path.Combine(TestFolder, prolibResource.FileName), Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl"));
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl"), null)) {
                    prolib.Save();
                    var data = new byte[new FileInfo(Path.Combine(TestFolder, prolibResource.FileName)).Length];
                    File.ReadAllBytes(Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl")).CopyTo(data, 0);

                    Assert.IsTrue(data.SequenceEqual(File.ReadAllBytes(Path.Combine(TestFolder, prolibResource.FileName))), $"file not recreated the same way : {prolibResource.FileName}.");
                }
            }

            if (!TestHelper.GetDlcPath(out string dlcPath) || UoeUtilities.GetProVersionFromDlc(dlcPath).Major != 11)
            {
                return;
            }
            OeProlibArchiver oeArchiver;

            try {
                oeArchiver = new OeProlibArchiver(dlcPath, Encoding.Default);
            } catch (ArchiverException e) {
                Console.WriteLine($"Cancelling test, prolib not found! : {e.Message}");
                return;
            }

            File.WriteAllBytes(Path.Combine(TestFolder, "file3"), new byte[] { 0xAA, 0xAA, 0xAA });
            File.WriteAllBytes(Path.Combine(TestFolder, "file4"), new byte[] { 0xAA, 0xAA, 0xAA, 0xAA });

            foreach (var prolibResource in list.Where(f => f.IsCompressed && f.Version == ProLibraryVersion.V11Standard))
            {
                var path = Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl");
                Assert.AreEqual(string.Join(",", prolibResource.ContainedFiles.Split(',').OrderBy(s => s)), string.Join(",", oeArchiver.ListFiles(path).Select(f => f.PathInArchive).OrderBy(s => s)), $"Wrong file listing 2 for {prolibResource.FileName}.");
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = Path.Combine(TestFolder, "file3"), PathInArchive = "sub/file3", ArchivePath = path
                    }
                });
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = Path.Combine(TestFolder, "file4"), PathInArchive = "sub/file4", ArchivePath = path
                    }
                });
                var fileCount = (string.IsNullOrEmpty(prolibResource.ContainedFiles) ? 0 : prolibResource.ContainedFiles.Split(',').Length) + 2;

                using (var prolib = new ProLibrary(path, null)) {
                    Assert.AreEqual(fileCount, prolib.Files.Count, $"Bad count for {prolibResource.FileName}.");
                    prolib.Save();
                }
                Assert.AreEqual(fileCount, oeArchiver.ListFiles(path).Count());
            }
        }