diff --git a/App.config b/App.config index 816b022..a2c5664 100644 --- a/App.config +++ b/App.config @@ -1,8 +1,12 @@  - - - + + +
+ + + + @@ -19,4 +23,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Database.cs b/Database.cs index 7acedb0..b811f9b 100644 --- a/Database.cs +++ b/Database.cs @@ -1,6 +1,7 @@ -using Microsoft.Data.Sqlite; -using System; +using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Data.SQLite; using System.Diagnostics; using System.Linq; using System.Text; @@ -26,7 +27,7 @@ namespace FAtoPA private bool CreateFSMTable() { //Debug.WriteLine("About to execute CreateFSMTable"); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { try { @@ -47,7 +48,7 @@ namespace FAtoPA } public bool ClearFSMTable() { - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); var deleteCmd = connection.CreateCommand(); @@ -57,7 +58,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting FSMData: " + e.Message); } @@ -68,7 +69,7 @@ namespace FAtoPA public List GetFSMDatas() { List fsmDatas = new List(); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); @@ -88,7 +89,7 @@ namespace FAtoPA public bool AddFSMData(params FSMData[] data) { - using(var connection = new SqliteConnection(connectionString)) + using(var connection = new SQLiteConnection(connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) @@ -109,7 +110,7 @@ namespace FAtoPA return false; } } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error inserting FSMData: " + e.Message); transaction.Rollback(); @@ -124,7 +125,7 @@ namespace FAtoPA public bool RemoveFSMDatabySIID(String SIID) { - using (var conn = new SqliteConnection(connectionString)) + using (var conn = new SQLiteConnection(connectionString)) { conn.Open(); var deleteCmd = conn.CreateCommand(); @@ -135,7 +136,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting FSMData: " + e.Message); return false; @@ -146,7 +147,7 @@ namespace FAtoPA private bool CreateModbusTable() { //Debug.WriteLine("About to execute CreateModbusTable"); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { try { @@ -167,7 +168,7 @@ namespace FAtoPA public bool ClearModbusTable() { - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); var deleteCmd = connection.CreateCommand(); @@ -177,7 +178,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting ModbusData: " + e.Message); } @@ -187,7 +188,7 @@ namespace FAtoPA public Boolean AddModbusData(params ModbusData[] data) { - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) @@ -208,7 +209,7 @@ namespace FAtoPA return false; } } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error inserting ModbusData: " + e.Message); transaction.Rollback(); @@ -224,7 +225,7 @@ namespace FAtoPA public List GetModbusDatas() { List modbusDatas = new List(); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); @@ -244,7 +245,7 @@ namespace FAtoPA public bool RemoveModbusDatabySIID(String SIID) { - using (var conn = new SqliteConnection(connectionString)) + using (var conn = new SQLiteConnection(connectionString)) { conn.Open(); var deleteCmd = conn.CreateCommand(); @@ -255,7 +256,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting ModbusData: " + e.Message); return false; @@ -266,7 +267,7 @@ namespace FAtoPA private bool CreateVXTable() { //Debug.WriteLine("About to execute CreateVXTable"); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { try { @@ -287,7 +288,7 @@ namespace FAtoPA public bool ClearVXTable() { - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); var deleteCmd = connection.CreateCommand(); @@ -297,7 +298,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting VXData: " + e.Message); } @@ -308,7 +309,7 @@ namespace FAtoPA public List GetVXDatas() { List vxDatas = new List(); - using (var connection = new SqliteConnection(connectionString)) + using (var connection = new SQLiteConnection(connectionString)) { connection.Open(); @@ -328,7 +329,7 @@ namespace FAtoPA public bool RemoveVXDatabySIID(String SIID) { - using (var conn = new SqliteConnection(connectionString)) + using (var conn = new SQLiteConnection(connectionString)) { conn.Open(); var deleteCmd = conn.CreateCommand(); @@ -339,7 +340,7 @@ namespace FAtoPA int result = deleteCmd.ExecuteNonQuery(); return (result > 0); } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error deleting VXData: " + e.Message); return false; @@ -348,7 +349,7 @@ namespace FAtoPA } public bool AddVXData(params VXData[] data) { - using(var connection = new SqliteConnection(connectionString)) + using(var connection = new SQLiteConnection(connectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) @@ -370,7 +371,7 @@ namespace FAtoPA return false; } } - catch (SqliteException e) + catch (SQLiteException e) { Debug.WriteLine("Error inserting VXData: " + e.Message); transaction.Rollback(); @@ -385,7 +386,7 @@ namespace FAtoPA } - class FSMData + class FSMData : INotifyPropertyChanged { public String SIID { get; set; } public Boolean Enable { get; set; } @@ -417,6 +418,13 @@ namespace FAtoPA this.Value = ""; } + + protected void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public event PropertyChangedEventHandler PropertyChanged; } class ModbusData diff --git a/FAtoPA.Net.csproj b/FAtoPA.Net.csproj index cb23295..c4dda1c 100644 --- a/FAtoPA.Net.csproj +++ b/FAtoPA.Net.csproj @@ -1,5 +1,6 @@ + Debug @@ -14,6 +15,8 @@ 4 true true + + AnyCPU @@ -64,6 +67,12 @@ ..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\DataExchangeInterfaces.dll + + packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + ..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\FSIConfig.dll @@ -82,9 +91,6 @@ packages\Microsoft.Bcl.AsyncInterfaces.9.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - packages\Microsoft.Data.Sqlite.Core.9.0.0\lib\netstandard2.0\Microsoft.Data.Sqlite.dll - ..\..\..\Bosch FA\FSM5000FSI-2.0.21\Release_x64\MPNetCIL.dll @@ -110,7 +116,17 @@ packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\lib\net46\System.Data.SQLite.dll + + + packages\System.Data.SQLite.EF6.1.0.119.0\lib\net46\System.Data.SQLite.EF6.dll + + + packages\System.Data.SQLite.Linq.1.0.119.0\lib\net46\System.Data.SQLite.Linq.dll + packages\System.IO.Pipelines.9.0.0\lib\net462\System.IO.Pipelines.dll @@ -204,4 +220,14 @@ + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/FSM.cs b/FSM.cs index fa18635..ec6de69 100644 --- a/FSM.cs +++ b/FSM.cs @@ -4,6 +4,7 @@ using FSM5000FSIAPI.Version3; using System; using System.CodeDom; using System.Collections.Generic; +using System.Data.Entity.Infrastructure.Interception; using System.Diagnostics; using System.Linq; using System.Text; @@ -47,7 +48,6 @@ namespace FAtoPA config.PNA = pna; config.LocalIPAddress = localip; config.RepositoryLocation = ".\\repository"; - config.AdvancedFSIConfig = new AdvancedFSIConfig(); } /// @@ -82,7 +82,7 @@ namespace FAtoPA TraceConsoleWritter outputter = new TraceConsoleWritter(); controller.SetTraceLevel(SourceLevels.Warning); //for support issues please set the level to SourceLevels.Verbose Result result = controller.Startup(config); - //Debug.WriteLine("[FSM] Start result = "+result.ToString()); + Debug.WriteLine("[FSM] Start result = "+result.ToString()); if (result==Result.SUCCESS) { Started = true; @@ -110,7 +110,7 @@ namespace FAtoPA try { Result result = controller.Shutdown(); - //Console.WriteLine("[FSM] Shutdown result = " + result.ToString()); + Debug.WriteLine("[FSM] Shutdown result = " + result.ToString()); if (_event!=null) _event.ConnectStatus(false, "FSM Stopped"); } catch (Exception e) { @@ -149,12 +149,16 @@ namespace FAtoPA /// public void SetItemType(ItemType devItemType) { - Debug.WriteLine($"Item type {devItemType.FunctionalType} ({devItemType.Description})"); + //Debug.WriteLine($"Item type {devItemType.FunctionalType} ({devItemType.Description})"); if (type_dictionary != null) { int type = int.Parse(devItemType.FunctionalType.ToString()); - if (!type_dictionary.ContainsKey(type)) type_dictionary.Add(type, devItemType.Description); - + if (!type_dictionary.ContainsKey(type)) + { + Debug.WriteLine($"Adding key={type}, value={devItemType.Description} to type_dictionary"); + type_dictionary.Add(type, devItemType.Description); + } + else Debug.WriteLine($"type_dictionary already have key={type}"); } } @@ -178,12 +182,14 @@ namespace FAtoPA nodeData.Label = devItem.Label; nodeData.Description = type_dictionary.ContainsKey(type) ? type_dictionary[type] : "Unknown"; node_data.Add(SIID, nodeData); + Debug.WriteLine($"Adding SIID={nodeData.SIID} Label={nodeData.Label} Description={nodeData.Description} to node_data"); // notify all listeners - if (listeners != null) - foreach (var item in listeners) + if (listeners != null) + foreach (var item in listeners) item.DiscoveredSIID(SIID, nodeData); - - } + + } + else Debug.WriteLine($"node_data already have SIID={SIID}"); } } @@ -235,22 +241,23 @@ namespace FAtoPA { NodeState prev = nd.State; nd.State = new NodeState(devItemState); + //if (prev != null) + //{ + // Debug.WriteLine($"SIID={SIID} Change LogicalState from {prev.LogicalState} to {nd.State.LogicalState}"); + //} + //else + //{ + // Debug.WriteLine($"SIID={SIID} New LogicalState {nd.State.LogicalState}"); + //} // notify all listeners if (listeners != null) foreach (var item in listeners) item.NewState(SIID, prev, nd.State); - if (prev != null) - { - Debug.WriteLine("SIID=" + SIID + " Change LogicalState from " + prev.LogicalState + " to " + nd.State.LogicalState); - } - else - { - Debug.WriteLine("New State for SIID=" + SIID + " LogicalState=" + nd.State.LogicalState); - } - } else Debug.WriteLine("NodeData with SIID " + SIID + " is null"); - } else Debug.WriteLine("node_data doesn't contain SIID " + SIID); + + } else Debug.WriteLine($"NodeData with SIID {SIID} is null"); + } else Debug.WriteLine($"node_data doesn't contain SIID {SIID}"); } else Debug.WriteLine("node_data is null"); @@ -263,7 +270,7 @@ namespace FAtoPA /// public void SetMPNetTime(DateTime mpNetTime) { - Debug.WriteLine("Time is " + mpNetTime + "."); + Debug.WriteLine($"Time is {mpNetTime}"); } } @@ -276,7 +283,7 @@ namespace FAtoPA { public override void Write(string message) { - if (message!=null && message.Length>0) Debug.Write(message); + if (message!=null && message.Length>0) Debug.WriteLine(message); } public override void WriteLine(string message) diff --git a/MainWindow.xaml b/MainWindow.xaml index 35b78c3..0f71c28 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -7,7 +7,10 @@ mc:Ignorable="d" Loaded="Window_Loaded" Closing="Window_Closing" - Title="MainWindow" Height="450" Width="800"> + Title="MainWindow" + MinWidth="800" + MinHeight="480" + WindowState="Maximized" > @@ -102,14 +105,22 @@ -