Skip to content

Commit

Permalink
Merge pull request #17 from hybridmachine/btabone-userdoc
Browse files Browse the repository at this point in the history
Btabone userdoc
  • Loading branch information
hybridmachine authored Feb 23, 2020
2 parents 7a481b9 + e9ffd51 commit 4678086
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 35 deletions.
Binary file not shown.
28 changes: 28 additions & 0 deletions Signals And Transforms/DAL/DatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void Initialize(SqliteConnection con)
try
{
InitializeWorkBookTable(con);
InitializeSettingsTable(con);
InitializeSignalsTable(con);
InitializeSignaTypesTable(con);
InitializeSignalValuesTable(con);
Expand All @@ -33,6 +34,7 @@ public static void Initialize(SqliteConnection con)
}
}


/// <summary>
/// Create the WorkBook table in the database
/// </summary>
Expand All @@ -58,6 +60,32 @@ private static bool InitializeWorkBookTable(SqliteConnection con)
return true;
}

/// <summary>
/// Initialize the workbook wide settings table
/// </summary>
/// <param name="con"></param>
/// <returns></returns>
private static bool InitializeSettingsTable(SqliteConnection con)
{
string sql = $@"
CREATE TABLE 'Settings' (
'Id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
'WorkBookId' INTEGER,
'Key' TEXT,
'Value' TEXT,
'Description' TEXT,
CONSTRAINT fk_settings_to_workbook
FOREIGN KEY (WorkBookId)
REFERENCES Workbook (Id)
ON DELETE CASCADE
)";

SqliteCommand cmd = con.CreateCommand();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
return true;
}

/// <summary>
/// Create the Signal table in the database
/// </summary>
Expand Down
56 changes: 56 additions & 0 deletions Signals And Transforms/DAL/SettingDAL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.Data.Sqlite;
using Serilog;
using SignalsAndTransforms.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SignalsAndTransforms.DAL
{
public static class SettingDAL
{

/// <summary>
/// Create a setting (deleting one if it is already there
/// </summary>
/// <param name="workBook"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="con">SQL Connection, it is assumed a transaction is already in process</param>
/// <returns></returns>
public static bool Create(WorkBook workBook, string key, string value, SqliteConnection con)
{
if (null == workBook) throw new ArgumentNullException(nameof(workBook));
if (null == key) throw new ArgumentNullException(nameof(key));
if (null == value) throw new ArgumentNullException(nameof(value));
if (null == con) throw new ArgumentException(nameof(con));

if (workBook.FilePath == null)
{
throw new Exception(Properties.Resources.ERROR_WORKBOOK_FILEPATHNOTSET);
}

string sql = $@"DELETE FROM Settings WHERE Key=@Key AND WorkBookId=@WorkBookId; INSERT INTO Settings ('WorkBookId', 'Key', 'Value') VALUES(@WorkBookId, @Key,@Value);";

try
{
SqliteCommand cmd = con.CreateCommand();
cmd.CommandText = sql;

cmd.Parameters.AddWithValue("@WorkBookId", workBook.Id);
cmd.Parameters.AddWithValue("@Key", key);
cmd.Parameters.AddWithValue("@Value", value);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Log.Error(ex, ex.Message);
throw;
}

return true;
}
}
}
22 changes: 20 additions & 2 deletions Signals And Transforms/DAL/WorkBookDAL.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dapper;
using Microsoft.Data.Sqlite;
using Serilog;
using SignalProcessor.Filters;
using SignalsAndTransforms.Models;
using System;
Expand All @@ -18,6 +19,12 @@ class MagPhase
public double Phase;
}

class Setting
{
public string Key;
public string Value;
}

public class SignalValue
{
public long Id { get; set; }
Expand All @@ -27,7 +34,7 @@ public class SignalValue

public static class WorkBookDAL
{
public const string SchemaVersion = "1.2";
public const string SchemaVersion = "1.3";

/// <summary>
/// Create the Workbook file, note this will delete any previously existing file if it exists
Expand Down Expand Up @@ -139,6 +146,11 @@ public static bool Update(WorkBook workBook)
FilterDAL.Create(workBook, filter, sqlLiteConnection);
}

foreach(string key in workBook.Settings.Keys)
{
SettingDAL.Create(workBook, key, workBook.Settings[key], sqlLiteConnection);
}

transaction.Commit();
} catch (Exception ex)
{
Expand Down Expand Up @@ -167,7 +179,8 @@ public static WorkBook Load(string fromPath)
var signals = connection.Query<Signal>($"SELECT * from Signals WHERE WorkBookId = '{newWorkBook.Id}'");
var windowedSyncFilters = connection.Query<Models.WindowedSyncFilter>($"SELECT * from Filters INNER JOIN WindowedSyncFilterParameters ON FilterId = Filters.Id WHERE WorkBookId = '{newWorkBook.Id}' AND FilterType in ('LOWPASS', 'HIGHPASS')");
var customFilters = connection.Query<Models.CustomFilter>($"SELECT * from Filters WHERE WorkBookId = '{newWorkBook.Id}' AND FilterType = 'CUSTOM'");

var settings = connection.Query<Setting>($"SELECT Key, Value from Settings WHERE WorkBookId = '{newWorkBook.Id}'");

foreach (Signal signal in signals)
{
var signalValues = connection.Query<SignalValue>($"SELECT * from SignalValues WHERE SignalId = {signal.Id} ORDER BY Id ASC");
Expand Down Expand Up @@ -204,6 +217,11 @@ public static WorkBook Load(string fromPath)
{
newWorkBook.CustomFilters.Add(filter.Name, filter);
}

foreach (Setting setting in settings)
{
newWorkBook.Settings.Add(setting.Key, setting.Value);
}
}

return newWorkBook;
Expand Down
15 changes: 15 additions & 0 deletions Signals And Transforms/Interfaces/IFilterIdentifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SignalsAndTransforms.Interfaces
{
// Common interface between filter types in the UI
public interface IFilterIdentifier
{
long Id { get; set; }
string Name { get; set; }
}
}
3 changes: 2 additions & 1 deletion Signals And Transforms/Models/CustomFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using System.Text;
using System.Threading.Tasks;
using SignalProcessor.Filters;
using SignalsAndTransforms.Interfaces;

namespace SignalsAndTransforms.Models
{
/// <summary>
/// UI model for filter, the SignalProcessor filter types are delegates that do the actual work
/// </summary>
public class CustomFilter : SignalProcessor.Filters.CustomFilter, INotifyPropertyChanged
public class CustomFilter : SignalProcessor.Filters.CustomFilter, INotifyPropertyChanged, IFilterIdentifier
{
public long Id { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion Signals And Transforms/Models/WindowedSyncFilter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SignalProcessor.Filters;
using SignalProcessor.Interfaces;
using SignalsAndTransforms.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -12,7 +13,7 @@ namespace SignalsAndTransforms.Models
/// <summary>
/// Simple subclass of WindowedSyncFilter, just adds the IsActive flag used by the UI in workbooks
/// </summary>
public class WindowedSyncFilter : SignalProcessor.Filters.WindowedSyncFilter, INotifyPropertyChanged
public class WindowedSyncFilter : SignalProcessor.Filters.WindowedSyncFilter, INotifyPropertyChanged, IFilterIdentifier
{
public long Id { get; set; }

Expand Down
Loading

0 comments on commit 4678086

Please sign in to comment.