Skip to content

Commit

Permalink
feat: Add BuilderVersion class and replace NdapiContext.ProductVersio…
Browse files Browse the repository at this point in the history
…n by NdapiContext.BuilderVersion
  • Loading branch information
felipebz committed Jan 3, 2024
1 parent 5fae0df commit 036010d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
12 changes: 8 additions & 4 deletions Ndapi/Core/ConstantConverter.cs
Expand Up @@ -7,24 +7,28 @@ internal static partial class ConstantConverter
public static int GetValue(Enum propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants[property] : Forms12Constants[property];
return (NdapiContext.BuilderVersion.MajorVersion == 6) ? Forms6Constants[property] : Forms12Constants[property];
}

public static int GetValue(int propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants[property] : Forms12Constants[property];
return (NdapiContext.BuilderVersion.MajorVersion == 6) ? Forms6Constants[property] : Forms12Constants[property];
}

public static bool HasConstant(Enum propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants.ContainsKey(property) : Forms12Constants.ContainsKey(property);
return (NdapiContext.BuilderVersion.MajorVersion == 6)
? Forms6Constants.ContainsKey(property)
: Forms12Constants.ContainsKey(property);
}

public static bool HasConstant(int propertyId)
{
var property = (NdapiConstant)propertyId;
return (NdapiContext.ProductVersion == 60082201) ? Forms6Constants.ContainsKey(property) : Forms12Constants.ContainsKey(property);
return (NdapiContext.BuilderVersion.MajorVersion == 6)
? Forms6Constants.ContainsKey(property)
: Forms12Constants.ContainsKey(property);
}
}
15 changes: 15 additions & 0 deletions Ndapi/Enums/BuilderVersion.cs
@@ -0,0 +1,15 @@
using System;

namespace Ndapi.Enums;

public record BuilderVersion(int FullVersion)
{
public Version Version { get; } =
new(FullVersion / 10_000_000, (FullVersion / 1_000_000) % 10, (FullVersion / 10_000) % 100,
(FullVersion / 100) % 100);

public int MajorVersion => Version.Major;

public static BuilderVersion Forms6 { get; } = new(60000000);
public static BuilderVersion Forms12213 { get; } = new(122010300);
}
23 changes: 16 additions & 7 deletions Ndapi/NdapiContext.cs
Expand Up @@ -23,7 +23,8 @@ public sealed class NdapiContext : IDisposable

private static readonly List<NdapiModule> _modules = [];
private static ContextSafeHandle _context;
private static string formsLib;
private static string _formsLib;
private static BuilderVersion _builderVersion;

/// <summary>
/// If true, the module loading will not fail when a required library module is not in the
Expand All @@ -44,7 +45,7 @@ public sealed class NdapiContext : IDisposable

static NdapiContext()
{
formsLib = NativeMethods.formsLib;
_formsLib = NativeMethods.formsLib;
if (!Environment.Is64BitProcess)
{
NativeLibrary.SetDllImportResolver(typeof(NdapiContext).Assembly, ((name, assembly, path) =>
Expand All @@ -54,8 +55,8 @@ static NdapiContext()
return IntPtr.Zero;
}
formsLib = NativeMethods.forms6Lib;
return NativeLibrary.Load(formsLib, assembly, path);
_formsLib = NativeMethods.forms6Lib;
return NativeLibrary.Load(_formsLib, assembly, path);
}));
}
}
Expand All @@ -82,9 +83,10 @@ internal static ContextSafeHandle GetContext()
}
catch (DllNotFoundException)
{
throw new NdapiException($"Could not found the {formsLib} from Oracle Forms installation. " +
throw new NdapiException($"Could not found the {_formsLib} from Oracle Forms installation. " +
"Please check if this version of Oracle Forms is installed.");
}

Ensure.Success(status);
return _context;
}
Expand All @@ -108,14 +110,20 @@ private static void FreeMemory(ref IntPtr context, IntPtr ptr)
/// Gets the version of the Forms API currently running. The format of the version number is a number
/// of the form 12334455, that corresponds to version 1.2.33.44.55.
/// </summary>
public static int ProductVersion
public static BuilderVersion BuilderVersion
{
get
{
if (_builderVersion != null)
{
return _builderVersion;
}

var status = NativeMethods.d2fctxbv_BuilderVersion(GetContext(), out var version);
Ensure.Success(status);

return version;
_builderVersion = new BuilderVersion(version);
return _builderVersion;
}
}

Expand Down Expand Up @@ -167,6 +175,7 @@ public static void Destroy()

_context.Dispose();
_context = null;
_builderVersion = null;
}

/// <summary>
Expand Down

0 comments on commit 036010d

Please sign in to comment.