Extract Windows only dependencies from shared .netstandard projects

This commit is contained in:
John Lewin 2018-10-19 15:53:16 -07:00
parent a9e0953e11
commit 6ea0de691c
10 changed files with 47 additions and 3291 deletions

View file

@ -44,9 +44,35 @@ using Sqlite3Statement = System.IntPtr;
using MatterHackers.MatterControl.DataStorage;
using System.Runtime.InteropServices;
using MatterHackers.Agg.Platform;
namespace SQLiteWin32
{
public static class DesktopSqlite
{
public static ISQLite CreateInstance()
{
ISQLite dbSQLite;
string datastoreLocation = ApplicationDataStorage.Instance.DatastorePath;
switch (AggContext.OperatingSystem)
{
case OSType.Mac:
return new SQLiteUnix.SQLiteConnection(datastoreLocation);
break;
case OSType.X11:
return new SQLiteUnix.SQLiteConnection(datastoreLocation);
break;
default:
return new SQLiteWin32.SQLiteConnection(datastoreLocation);
break;
}
}
}
public class SQLiteException : System.Exception
{
public SQLite3.Result Result { get; private set; }

View file

@ -18,7 +18,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;USE_OPENGL;IS_WINDOWS;IS_WINDOWS_FORMS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
@ -45,6 +45,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataStorage\SQLiteUnix.cs" />
<Compile Include="DataStorage\SQLiteWin32.cs" />
<Compile Include="InspectForm.cs">
<SubType>Form</SubType>
</Compile>
@ -56,6 +58,10 @@
<Compile Include="WinformsSingleWindowProvider.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Community.CsharpSqlite\Community.CsharpSqlite.csproj">
<Project>{f1653f20-d47d-4f29-8c55-3c835542af5f}</Project>
<Name>Community.CsharpSqlite</Name>
</ProjectReference>
<ProjectReference Include="..\MatterControlLib\MatterControlLib.csproj">
<Project>{D557B079-612F-467F-AE0D-3F77BCD627F7}</Project>
<Name>MatterControlLib</Name>

View file

@ -76,6 +76,10 @@
<Project>{97d5ade3-c1b4-4b46-8a3e-718a4f7f079f}</Project>
<Name>MatterControl.Printing</Name>
</ProjectReference>
<ProjectReference Include="MatterControl.Winforms\MatterControl.Winforms.csproj">
<Project>{D6DC2669-7B1F-40FE-89BF-45D4C94473E3}</Project>
<Name>MatterControl.Winforms</Name>
</ProjectReference>
<ProjectReference Include="MatterControlLib\MatterControlLib.csproj">
<Project>{93bebfdf-b81a-4344-ab82-0dbf58b234cd}</Project>
<Name>MatterControlLib</Name>

View file

@ -103,12 +103,10 @@ namespace MatterHackers.MatterControl.DataStorage
/// <returns></returns>
public string DatastorePath => Path.Combine(EnsurePath(_applicationUserDataPath), datastoreName);
#if __ANDROID__
/// <summary>
/// Returns the public storage folder (ex. download folder on Android)
/// </summary>
public string PublicDataStoragePath { get; } = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
#endif
public string PublicDataStoragePath { get; set; }
/// <summary>
/// Invokes CreateDirectory on all paths, creating if missing, before returning
@ -124,7 +122,7 @@ namespace MatterHackers.MatterControl.DataStorage
/// Overrides the AppData location. Used by tests to set a non-standard AppData location
/// </summary>
/// <param name="path">The new AppData path.</param>
internal void OverrideAppDataLocation(string path)
internal void OverrideAppDataLocation(string path, ISQLite sqlite)
{
Console.WriteLine(" Overriding ApplicationUserDataPath: " + path);
@ -135,7 +133,7 @@ namespace MatterHackers.MatterControl.DataStorage
// Initialize a fresh datastore instance after overriding the AppData path
Datastore.Instance = new Datastore();
Datastore.Instance.Initialize();
Datastore.Instance.Initialize(sqlite);
}
public string GetTempFileName(string fileExtension = null)

View file

@ -66,29 +66,6 @@ namespace MatterHackers.MatterControl.DataStorage
{
ApplicationDataStorage.Instance.FirstRun = true;
}
OSType osType = AggContext.OperatingSystem;
switch (osType)
{
case OSType.Windows:
dbSQLite = new SQLiteWin32.SQLiteConnection(datastoreLocation);
break;
case OSType.Mac:
dbSQLite = new SQLiteUnix.SQLiteConnection(datastoreLocation);
break;
case OSType.X11:
dbSQLite = new SQLiteUnix.SQLiteConnection(datastoreLocation);
break;
case OSType.Android:
dbSQLite = new SQLiteAndroid.SQLiteConnection(datastoreLocation);
break;
default:
throw new NotImplementedException();
}
}
public static Datastore Instance
@ -102,7 +79,7 @@ namespace MatterHackers.MatterControl.DataStorage
return globalInstance;
}
// Special case to allow tests to set custom application paths
// Special case to allow tests to set custom application paths
internal set
{
globalInstance = value;
@ -146,8 +123,9 @@ namespace MatterHackers.MatterControl.DataStorage
}
//Run initial checks and operations on sqlite datastore
public void Initialize()
public void Initialize(ISQLite dbSQLite)
{
this.dbSQLite = dbSQLite;
ValidateSchema();
// Construct the root library collection if missing

File diff suppressed because it is too large Load diff

View file

@ -71,7 +71,6 @@
<ProjectReference Include="..\Submodules\agg-sharp\RayTracer\RayTracer.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\VectorMath\VectorMath.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\Tesselate\Tesselate.csproj" />
<ProjectReference Include="..\Community.CsharpSqlite\Community.CsharpSqlite.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\RenderOpenGl\RenderOpenGl.csproj" />
<ProjectReference Include="..\Submodules\agg-sharp\PolygonMesh\PolygonMesh.csproj" />
<ProjectReference Include="..\PluginSystem\MatterControlPluginSystem.csproj" />

View file

@ -40,6 +40,7 @@ using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication.FrostedSerial;
using Microsoft.Extensions.Configuration;
using SQLiteWin32;
namespace MatterHackers.MatterControl
{
@ -122,7 +123,7 @@ namespace MatterHackers.MatterControl
// Make sure we have the right working directory as we assume everything relative to the executable.
Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
Datastore.Instance.Initialize();
Datastore.Instance.Initialize(DesktopSqlite.CreateInstance());
// Init platformFeaturesProvider before ShowAsSystemWindow
string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

View file

@ -52,6 +52,7 @@ using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.PrinterEmulator;
using Newtonsoft.Json;
using NUnit.Framework;
using SQLiteWin32;
namespace MatterHackers.MatterControl.Tests.Automation
{
@ -407,7 +408,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
public static void OverrideAppDataLocation(string matterControlDirectory)
{
string tempFolderPath = Path.Combine(matterControlDirectory, "Tests", "temp", runName, $"Test{testID++}");
ApplicationDataStorage.Instance.OverrideAppDataLocation(tempFolderPath);
ApplicationDataStorage.Instance.OverrideAppDataLocation(tempFolderPath, DesktopSqlite.CreateInstance());
}
public static void AddItemsToQueue(string queueItemFolderToLoad)