Fix warnings
This commit is contained in:
parent
1e4c1bbd85
commit
3c15b99d61
2 changed files with 33 additions and 19 deletions
|
|
@ -28,19 +28,25 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace MatterHackers.MatterControl.DataStorage
|
||||
{
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Private getters used to enforce presence of directories")]
|
||||
public class ApplicationDataStorage
|
||||
{
|
||||
public bool FirstRun = false;
|
||||
// Required by Android
|
||||
public bool FirstRun { get; set; } = false;
|
||||
|
||||
//Describes the location for storing all local application data
|
||||
// Describes the location for storing all local application data
|
||||
private static ApplicationDataStorage globalInstance;
|
||||
|
||||
private const string applicationDataFolderName = "MatterControl";
|
||||
private const string datastoreName = "MatterControl.db";
|
||||
private const string ApplicationDataFolderName = "MatterControl";
|
||||
|
||||
private const string DatastoreName = "MatterControl.db";
|
||||
|
||||
private string _applicationPath;
|
||||
|
||||
public static ApplicationDataStorage Instance
|
||||
{
|
||||
|
|
@ -50,11 +56,11 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
{
|
||||
globalInstance = new ApplicationDataStorage();
|
||||
}
|
||||
|
||||
return globalInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private string _applicationPath;
|
||||
public string ApplicationPath
|
||||
{
|
||||
get
|
||||
|
|
@ -68,12 +74,18 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
}
|
||||
}
|
||||
|
||||
private static string _applicationUserDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), applicationDataFolderName);
|
||||
private static string _applicationUserDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ApplicationDataFolderName);
|
||||
|
||||
private static string _applicationLibraryDataPath => Path.Combine(_applicationUserDataPath, "Library");
|
||||
|
||||
private static string _libraryAssetPath => Path.Combine(_applicationLibraryDataPath, "Assets");
|
||||
|
||||
private static string _platingDirectory => Path.Combine(_applicationLibraryDataPath, "Plating");
|
||||
|
||||
private static string _applicationTempDataPath => Path.Combine(_applicationUserDataPath, "data", "temp");
|
||||
|
||||
private static string _gcodeOutputPath => Path.Combine(_applicationTempDataPath, "gcode");
|
||||
|
||||
private static string _cacheDirectory => Path.Combine(_applicationTempDataPath, "cache");
|
||||
|
||||
private static string _webCacheDirectory => Path.Combine(_applicationTempDataPath, "WebCache");
|
||||
|
|
@ -99,20 +111,20 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
public string CustomLibraryFoldersPath => Path.Combine(_applicationUserDataPath, "LibraryFolders.conf");
|
||||
|
||||
/// <summary>
|
||||
/// Returns the path to the sqlite database
|
||||
/// Gets the path to the Sqlite database
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string DatastorePath => Path.Combine(EnsurePath(_applicationUserDataPath), datastoreName);
|
||||
/// <returns>The path toe Sqlite database</returns>
|
||||
public string DatastorePath => Path.Combine(EnsurePath(_applicationUserDataPath), DatastoreName);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the public storage folder (ex. download folder on Android)
|
||||
/// Gets or sets the public storage folder (ex. download folder on Android)
|
||||
/// </summary>
|
||||
public string PublicDataStoragePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invokes CreateDirectory on all paths, creating if missing, before returning
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>Returns the path to the given directory</returns>
|
||||
private static string EnsurePath(string fullPath)
|
||||
{
|
||||
Directory.CreateDirectory(fullPath);
|
||||
|
|
@ -123,6 +135,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>
|
||||
/// <param name="sqliteBuilder">The Sqlite generator with platform specific bindings</param>
|
||||
internal void OverrideAppDataLocation(string path, Func<ISQLite> sqliteBuilder)
|
||||
{
|
||||
Console.WriteLine(" Overriding ApplicationUserDataPath: " + path);
|
||||
|
|
|
|||
|
|
@ -31,21 +31,20 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
||||
namespace MatterHackers.MatterControl.DataStorage
|
||||
{
|
||||
public class Datastore
|
||||
{
|
||||
bool wasExited = false;
|
||||
public bool ConnectionError = false;
|
||||
private bool wasExited = false;
|
||||
public ISQLite dbSQLite;
|
||||
private string datastoreLocation = ApplicationDataStorage.Instance.DatastorePath;
|
||||
private static Datastore globalInstance;
|
||||
private ApplicationSession activeSession;
|
||||
|
||||
private List<Type> dataStoreTables = new List<Type>
|
||||
private readonly List<Type> dataStoreTables = new List<Type>
|
||||
{
|
||||
typeof(PrintItemCollection),
|
||||
typeof(PrinterSetting),
|
||||
|
|
@ -76,6 +75,7 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
{
|
||||
globalInstance = new Datastore();
|
||||
}
|
||||
|
||||
return globalInstance;
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +85,7 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
globalInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
if (wasExited)
|
||||
|
|
@ -94,10 +95,10 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
|
||||
wasExited = true;
|
||||
|
||||
if (this.activeSession != null)
|
||||
if (activeSession != null)
|
||||
{
|
||||
this.activeSession.SessionEnd = DateTime.Now;
|
||||
this.activeSession.Commit();
|
||||
activeSession.SessionEnd = DateTime.Now;
|
||||
activeSession.Commit();
|
||||
}
|
||||
|
||||
// lets wait a bit to make sure the commit has resolved.
|
||||
|
|
@ -122,7 +123,7 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
}
|
||||
}
|
||||
|
||||
//Run initial checks and operations on sqlite datastore
|
||||
// Run initial checks and operations on sqlite datastore
|
||||
public void Initialize(ISQLite dbSQLite)
|
||||
{
|
||||
this.dbSQLite = dbSQLite;
|
||||
|
|
@ -148,7 +149,7 @@ namespace MatterHackers.MatterControl.DataStorage
|
|||
return Convert.ToInt32(result);
|
||||
}
|
||||
|
||||
//Begins new application session record
|
||||
// Begins new application session record
|
||||
private void StartSession()
|
||||
{
|
||||
activeSession = new ApplicationSession();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue