Skip to content

Commit

Permalink
Removing references to Base Harvest as it is discontinued
Browse files Browse the repository at this point in the history
  • Loading branch information
Klemet committed Jun 14, 2024
1 parent 485cd14 commit 4def8fc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LandisData Extension

Name "Magic Harvest"
Version "2.1"
Type disturbance:harvest
Assembly Landis.Extension.MagicHarvest
Class Landis.Extension.MagicHarvest.PlugIn
Description "Allows the update of the parameters of the harvest extension during the simulation"
CoreVersion 8.0
8 changes: 2 additions & 6 deletions Deploy/Installer Inno Setup script.iss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; LANDIS-II Extension infomation
#define CoreRelease "LANDIS-II-V8"
#define ExtensionName "Magic harvest"
#define AppVersion "2.0"
#define AppVersion "2.1"
#define AppPublisher "Clément Hardy"

; Build directory
Expand Down Expand Up @@ -55,12 +55,8 @@ Source: "..\Examples\Core-v8\Biomass Harvest\*"; DestDir: {#AppDir}\Examples\{#E

; LANDIS-II identifies the extension with the info in this .txt file
; NB. New releases must modify the name of this file and the info in it
#define InfoTxt "Magic harvest v2.0.txt"
#define InfoTxt "Magic harvest v2.1.txt"
Source: .\Installation Files\plug-ins-installer-files\{#InfoTxt}; DestDir: {#LandisPlugInDir}
; WARNING : At the time of making this update, Base Harvest hasn't been updated to Core v8 of LANDIS-II.
; Therefore, I'm obliged to pack the dll of the old Base Harvest (v7), or it will not work.
; However, if it's already in the LANDIS-II-v8 install folder, I won't overwrite it as it might be a new version.
Source: {#BuildDir}\Landis.Extension.BaseHarvest-v5.dll; DestDir: {#ExtDir}; Flags: uninsneveruninstall ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Expand Down
2 changes: 1 addition & 1 deletion Examples/Core-v8/README - Why no Base Harvest example.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
As the date of making the release of Magic Harvest 2.0 for LANDIS-II-v8 (14th of June 2024), Base Harvest seems to not have been updated to Core v8. As such, I wasn't able to provide examples files for it.
Base Harvest has been discontinued since the release of LANDIS-II-v8. Therefore, the code of Magic Harvest has been adapted to not consider Base Harvest anymore.
4 changes: 0 additions & 4 deletions Magic Harvest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
<Reference Include="Landis.Core.Implementation, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Landis.Core.Implementation.3.0.1\lib\netstandard2.0\Landis.Core.Implementation.dll</HintPath>
</Reference>
<Reference Include="Landis.Extension.BaseHarvest-v5, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\LANDIS-II-v7\extensions\Landis.Extension.BaseHarvest-v5.dll</HintPath>
</Reference>
<Reference Include="Landis.Extension.BiomassHarvest-v4">
<HintPath>C:\Program Files\LANDIS-II-v8\extensions\Landis.Extension.BiomassHarvest-v4.dll</HintPath>
</Reference>
Expand Down
52 changes: 5 additions & 47 deletions src/PlugIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,55 +182,9 @@ public override void Run()
// 5. RELOADING THE PARAMETERS OF THE EXTENSION

modelCore.UI.WriteLine("Magic Harvest : Re-loading the parameters of the harvest extension");
// Things are a bit different if we are talking about base harvest versus biomass harvest. We make a if for each of them.
if (harvestExtension.Name.Contains("Base"))
{
modelCore.UI.WriteLine("Magic Harvest : Acting for Base Harvest...");

// We re-do the initialization of the extension, without re-doing the logs.
// It would be simpler to call harvestExtension.Initialize();, but this would reset the harvest logs; we don't want that.
// See https://github.com/LANDIS-II-Foundation/Extension-Base-Harvest/blob/7e156827276960f00ca5db76e8bd97f0d379b49b/src/PlugIn.cs#L90 to see what is replicated here.

// Force Base Harvest to re-read its parameters
modelCore.UI.WriteLine("Magic Harvest : Parsing parameters...");
// We create a new parser
Landis.Extension.BaseHarvest.InputParametersParser parser = new Landis.Extension.BaseHarvest.InputParametersParser(modelCore.Species);
// We use the parser to fill a new object containing the parameters
// ⚠ If an type error comes here concerning InputParametersParser, it must be because the wrong version of Base Harvest is referenced : v4 is needed for now.
HarvestMgmtLib.IInputParameters reloadedHarvestParameters = Landis.Data.Load<HarvestMgmtLib.IInputParameters>(parameters.HarvestExtensionParameterFile, parser);

// Re-initialize the management areas
modelCore.UI.WriteLine("Magic Harvest : Reading management areas map...");
// We update both the "real" managementAreas private property of the harvest extension; and the "copy" we made earlier,
// because we will need this copy updated to give it to ManagementAreas.ReadMap() below.
harvestExtension.GetType().GetField("managementAreas", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(harvestExtension, reloadedHarvestParameters.ManagementAreas);
managementAreasList = reloadedHarvestParameters.ManagementAreas;
// We make Base Harvest re-read the management area map
ModelCore.UI.WriteLine(" Reading management-area map {0} ...", reloadedHarvestParameters.ManagementAreaMap);
HarvestMgmtLib.ManagementAreas.ReadMap(reloadedHarvestParameters.ManagementAreaMap, managementAreasList);

// We make Base Harvest re-read the stands map
modelCore.UI.WriteLine("Magic Harvest : Reading stands map...");
PlugIn.ModelCore.UI.WriteLine(" Reading stand map {0} ...", reloadedHarvestParameters.StandMap);
HarvestMgmtLib.Stands.ReadMap(reloadedHarvestParameters.StandMap);

modelCore.UI.WriteLine("Magic Harvest : Re-initializing site variables");
HarvestMgmtLib.SiteVars.GetExternalVars();

// We finish initialisation of the management areas.
foreach (HarvestMgmtLib.ManagementArea mgmtArea in managementAreasList)
{
mgmtArea.FinishInitialization();
}

// We re-load the prescription maps
harvestExtension.GetType().GetField("prescriptionMaps", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(harvestExtension, new HarvestMgmtLib.PrescriptionMaps(reloadedHarvestParameters.PrescriptionMapNames));


modelCore.UI.WriteLine("Magic Harvest : Re-loading is finished.");
}
// Now we take care of Biomass Harvest by reproducing https://github.com/LANDIS-II-Foundation/Extension-Biomass-Harvest/blob/e4fe90fb5a761ac00d01ee0ff39eae5f6d81b098/src/PlugIn.cs#L115
else
if (harvestExtension.Name.Contains("Biomass Harvest"))
{
modelCore.UI.WriteLine("Magic Harvest : Acting for Biomass Harvest...");

Expand Down Expand Up @@ -280,6 +234,10 @@ public override void Run()

modelCore.UI.WriteLine("Magic Harvest : Re-loading is finished.");
}
else
{
throw new Exception("Magic Harvest couldn't detect Biomass Harvest properly. Maybe another harvest extension has been used ?");
}
// ----------------------------------------------------------------------------------
}

Expand Down

0 comments on commit 4def8fc

Please sign in to comment.