Skip to content

Commit

Permalink
Added support for Esent on netstandard builds. xBimTeam#346
Browse files Browse the repository at this point in the history
This means Xbim.IO.Esent can be referenced by netcore projects. This will enable IfcStore to use the HeuristicModelProvider in netcore apps.

Note: Microsoft have republished ManagedEsent under a different nuget Package for 2.0.1+ no longer seem to strong name sign. Equally the new ManagedEsent component only supports net47+

As such I took the decision to use the 'legacy' 1.9.4 Esent for net4[567] and the new 2.0.1 for netstandard (and where the output is unsigned)
  • Loading branch information
andyward committed Jul 31, 2020
1 parent 07fc65a commit 6c3e94b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 21 deletions.
20 changes: 20 additions & 0 deletions Xbim.Essentials.NetCore.Tests/EsentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using Xbim.Ifc4;

namespace Xbim.Essentials.NetCore.Tests
{
[TestClass]
public class EsentTests
{
[TestMethod]
public void CanCreateEsentModel()
{
var esentModel = new Xbim.IO.Esent.EsentModel(new EntityFactoryIfc4());

Assert.IsNotNull(esentModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Xbim.IO.Esent\Xbim.IO.Esent.csproj" />
<ProjectReference Include="..\Xbim.IO.MemoryModel\Xbim.IO.MemoryModel.csproj" />
</ItemGroup>

Expand Down
48 changes: 35 additions & 13 deletions Xbim.IO.Esent/Esent/EsentCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public abstract class EsentCursor : IDisposable


private static string ifcHeaderColumnName = "IfcHeader";


private bool disposedValue;

public bool ReadOnly { get; set; }

Expand Down Expand Up @@ -209,20 +208,43 @@ internal void MoveBeforeFirst()
Api.MoveBeforeFirst(Sesid, Table);
}


virtual public void Dispose()
protected virtual void Dispose(bool disposing)
{
try
if (!disposedValue)
{
Api.JetCloseTable(Sesid, Table);
Api.JetCloseTable(Sesid, GlobalsTable);
Api.JetCloseDatabase(Sesid, DbId, CloseDatabaseGrbit.None);
Api.JetEndSession(Sesid, EndSessionGrbit.None);
}
catch (Exception)
{
// ignored
if (disposing)
{
// TODO: dispose managed state (managed objects)
try
{
Api.JetCloseTable(Sesid, Table);
Api.JetCloseTable(Sesid, GlobalsTable);
Api.JetCloseDatabase(Sesid, DbId, CloseDatabaseGrbit.None);
Api.JetEndSession(Sesid, EndSessionGrbit.None);
}
catch (Exception)
{
// ignored
}
}

// TODO: free unmanaged resources (unmanaged objects) and override finalizer
disposedValue = true;
}
}

// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~EsentCursor()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }

public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
4 changes: 2 additions & 2 deletions Xbim.IO.Esent/Esent/EsentEntityCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static implicit operator JET_TABLEID(EsentEntityCursor table)
return table;
}

public override void Dispose()
protected override void Dispose(bool disposing)
{
try
{
Expand All @@ -72,7 +72,7 @@ public override void Dispose()
catch (Exception)
{
}
base.Dispose();
base.Dispose(disposing);
}

internal static void CreateTable(JET_SESID sesid, JET_DBID dbid)
Expand Down
17 changes: 12 additions & 5 deletions Xbim.IO.Esent/Xbim.IO.Esent.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;net46;net47</TargetFrameworks>
<TargetFrameworks>net45;net47;netstandard2.0</TargetFrameworks>
<Company>Xbim Ltd.</Company>
<Title>Xbim IO for ESENT</Title>
<Description>Manages Ifc or STEP Model backed by the ESENT database. Windows only.</Description>
<Description>Manages Ifc or STEP Models backed by the ESENT database. Windows only.</Description>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net47|AnyCPU'">
<NoWarn>CS1572;CS1573;CS1591</NoWarn>
Expand All @@ -15,11 +15,18 @@
<ProjectReference Include="..\Xbim.Common\Xbim.Common.csproj" />
<ProjectReference Include="..\Xbim.IO.MemoryModel\Xbim.IO.MemoryModel.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net46' OR '$(TargetFramework)' == 'net47' ">

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<!-- New Microsoft.Database.ManagedEsent is not signed -->
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net47' ">
<PackageReference Include="ManagedEsent" Version="1.9.4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Database.ManagedEsent" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Xbim.Ifc/IfcStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

protected void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
Expand Down

0 comments on commit 6c3e94b

Please sign in to comment.