Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back to old static way of determining supported runtime #696

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void CheckAppManifestRuntime(CompilationAnalysisContext ctx)
if (manifest.Application == null && manifest.Platform == null) return;

GetTargetProperty(manifest, out string propertyName, out Version propertyVersion);
ReleaseVersion.LatestSupportedRuntimeVersions.TryGetValue(propertyVersion, out Version supportedRuntime);
Version supportedRuntime = FindValueOfFirstValueLessThan(GetSupportedRuntimeVersions(), propertyVersion);
if (supportedRuntime == null) return;

if (manifest.Runtime < supportedRuntime)
Expand All @@ -51,5 +51,47 @@ private static void GetTargetProperty(NavAppManifest manifest, out string proper
propertyVersion = new Version(manifest.Platform.Major, manifest.Platform.Minor);
}
}

private static SortedList<Version, Version> GetSupportedRuntimeVersions()
{
// Populate a SortedList with platform version and runtime version combined
SortedList<Version, Version> AvailableRuntimeVersion = new SortedList<Version, Version>();

// https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-choosing-runtime#currently-available-runtime-versions
// When in the future the offset between the platform and runtime versions isn't exactly is eleven, we're in trouble
// By populating a list here, in stead of just adding up eleven somewhere else, we probably can resolve this here
int offset = 11;

foreach (var v in RuntimeVersion.SupportedVersions)
{
AvailableRuntimeVersion.Add(new Version(v.Major + offset, v.Minor), new Version(v.Major, v.Minor));
}
return AvailableRuntimeVersion;
}

private static Version FindValueOfFirstValueLessThan(SortedList<Version, Version> sortedList, Version version)
{
int index = FindIndexOfFirstValueLessThan(sortedList.Keys.ToList(), version);
return sortedList.ElementAtOrDefault(index).Value;
}

private static int FindIndexOfFirstValueLessThan<T>(List<T> sortedList, T value, IComparer<T> comparer = null)
{
var index = sortedList.BinarySearch(value, comparer);

// The value was found in the list. Just return its index.
if (index >= 0)
return index;

// The value was not found and "~index" is the index of the next value greater than the search value.
index = ~index;

// There are values in the list less than the search value. Return the index of the closest one.
if (index > 0)
return index - 1;

// All values in the list are greater than the search value.
return -1;
}
}
}