// start monitoring for config changes public override void StartChangeMonitoring() { try { _demandMonitor?.StartListening(); _schedMonitor?.StartListening(); _requestGroupDefMonitor?.StartListening(); _connectionDefMonitor?.StartListening(); _dataPointDefMonitor?.StartListening(); if (_devicesTableExists) { _deviceDefMonitor?.StartListening(); } if (_tasksTableExists) { _taskDefMonitor?.StartListening(); } if (_datasubscriptionsTableExists) { _datasubscriptionMonitor?.StartListening(); } if (_scriptsTableExists) { _userScriptsMonitor?.StartListening(); } } catch (Exception ex) { Globals.SystemManager.LogApplicationError(Globals.FDANow(), ex, "Error when starting Table Change Monitoring objects"); } }
public void TaskInsert() { // create a FDATask FDATask original = new FDATask() { TASK_ID = rowID, task_type = "task type", task_details = "task details" }; // start listening for changes PostgreSQLListener <FDATask> listener = new PostgreSQLListener <FDATask>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA; Keepalive = 1;", "fdatasks"); listener.Notification += Listener_NotificationTasks; listener.StartListening(); currentTest = "INSERT"; expectedTask = new FDATask() { TASK_ID = rowID, task_type = "task type", task_details = "task details" }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA;Keepalive=1")) { conn.Open(); string query = "insert into fdatasks (task_id,task_type,task_details) values (cast('" + original.TASK_ID + "' as uuid),'" + original.task_type + "','" + original.task_details + "');"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("Notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } CompareTasks(expectedTask, resultingTask); } } }
public void REFDelete() { // start listening for changes PostgreSQLListener <FDATask> listener = new PostgreSQLListener <FDATask>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem; Keepalive = 1;", "roceventformats"); listener.Notification += Listener_NotificationTasks; listener.StartListening(); currentTest = "DELETE"; expectedTask = new FDATask() { TASK_ID = rowID, task_details = null, task_type = null }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem;Keepalive=1")) { conn.Open(); string query = "delete from roceventformats where pointtype=1 and format=2;"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("delete notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } if (expectedREF.POINTTYPE != resultingREF.POINTTYPE) { Assert.Fail("Unexpected POINTTYPE. expected " + expectedREF.POINTTYPE.ToString() + ", received " + resultingREF.POINTTYPE.ToString()); } if (expectedREF.FORMAT != resultingREF.FORMAT) { Assert.Fail("Unexpected FORMAT. expected " + expectedREF.FORMAT.ToString() + ", received " + resultingREF.FORMAT.ToString()); } } } }
public void RequestGroupDelete() { // start listening for changes PostgreSQLListener <FDADataBlockRequestGroup> listener = new PostgreSQLListener <FDADataBlockRequestGroup>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA; Keepalive = 1;", "fdadatablockrequestgroup"); listener.Notification += Listener_NotificationRequestGroup; listener.StartListening(); currentTest = "DELETE"; expectedRequestGroupResult = new FDADataBlockRequestGroup() { Description = "FDATestsGroup", DRGEnabled = true, DPSType = "ROC", DataPointBlockRequestListVals = "20:4:1|INT16:4BB8D0AF-0DC8-437E-A0F3-0B773A7B0083", CommsLogEnabled = false, DRGUID = rowID }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA;Keepalive=1")) { conn.Open(); string query = "delete from fdadatablockrequestgroup where drguid = cast('" + rowID.ToString() + "' as uuid);"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("Notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } if (expectedRequestGroupResult.DRGUID != requestGroupResult.DRGUID) { Assert.Fail("Unexpected DRGUID. expected " + expectedRequestGroupResult.DRGUID.ToString() + ", received " + requestGroupResult.DRGUID.ToString()); } } } }
public void TaskDelete() { // start listening for changes PostgreSQLListener <FDATask> listener = new PostgreSQLListener <FDATask>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA; Keepalive = 1;", "fdatasks"); listener.Notification += Listener_NotificationTasks; listener.StartListening(); currentTest = "DELETE"; expectedTask = new FDATask() { TASK_ID = rowID, task_details = null, task_type = null }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA;Keepalive=1")) { conn.Open(); string query = "delete from FDATasks where task_id = cast('" + rowID.ToString() + "' as uuid);"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("delete notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } if (expectedTask.TASK_ID != resultingTask.TASK_ID) { Assert.Fail("Unexpected DRGUID. expected " + expectedRequestGroupResult.DRGUID.ToString() + ", received " + requestGroupResult.DRGUID.ToString()); } } } }
public void REFUpdate() { // start listening for changes PostgreSQLListener <FDATask> listener = new PostgreSQLListener <FDATask>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem; Keepalive = 1;", "fdatasks"); listener.Notification += Listener_NotificationTasks; listener.StartListening(); currentTest = "UPDATE"; expectedREF = new RocEventFormats() { POINTTYPE = 1, FORMAT = 2, DescShort = "FAKE-updated", DescLong = "FAKE FORMAT-updated" }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem;Keepalive=1")) { conn.Open(); string query = "update roceventformats set descshort = 'FAKE-updated',desclong='FAKE FORMAT-updated' where pointtype = 1 and FORMAT = 2"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("Notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } CompareREFs(expectedREF, resultingREF); } } }
public void RequestGroupInsert() { // create a FDADataBlockrequestGroup FDADataBlockRequestGroup original = new FDADataBlockRequestGroup() { Description = "FDATestsGroup", DRGEnabled = false, DPSType = "MODBUS", DataPointBlockRequestListVals = "20:3:1|INT16:4BB8D0AF-0DC8-437E-A0F3-0B773A7B0083", CommsLogEnabled = true, DRGUID = rowID, }; // start listening for changes PostgreSQLListener <FDADataBlockRequestGroup> listener = new PostgreSQLListener <FDADataBlockRequestGroup>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA; Keepalive = 1;", "fdadatablockrequestgroup"); listener.Notification += Listener_NotificationRequestGroup; listener.StartListening(); currentTest = "INSERT"; expectedRequestGroupResult = new FDADataBlockRequestGroup() { Description = "FDATestsGroup", DRGEnabled = false, DPSType = "MODBUS", DataPointBlockRequestListVals = "20:3:1|INT16:4BB8D0AF-0DC8-437E-A0F3-0B773A7B0083", CommsLogEnabled = true, DRGUID = rowID, }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDA;Keepalive=1")) { conn.Open(); string query = "insert into fdadatablockrequestgroup (description,drgenabled,commslogenabled,dpstype,datapointblockrequestlistvals,drguid) values ('" + original.Description + "',cast(" + (original.DRGEnabled ? 1 : 0) + " as bit),cast(" + (original.CommsLogEnabled?1:0) + " as bit),'MODBUS','20:3:1|INT16:4BB8D0AF-0DC8-437E-A0F3-0B773A7B0083',cast('" + original.DRGUID.ToString() + "' as uuid));"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("Notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } CompareResult(expectedRequestGroupResult, requestGroupResult); } } }
public void REFInsert() { // create an REF RocEventFormats original = new RocEventFormats() { POINTTYPE = 1, FORMAT = 2, DescShort = "FAKE", DescLong = "FAKE FORMAT" }; // start listening for changes PostgreSQLListener <RocEventFormats> listener = new PostgreSQLListener <RocEventFormats>("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem; Keepalive = 1;", "roceventformats"); listener.Notification += Listener_NotificationREF; listener.StartListening(); currentTest = "INSERT"; expectedREF = new RocEventFormats() { POINTTYPE = 1, FORMAT = 2, DescShort = "FAKE", DescLong = "FAKE FORMAT" }; using (NpgsqlConnection conn = new NpgsqlConnection("Server = localhost; Port = 5432; User Id = Intricatesql; Password = Intricate2790!; Database = FDASystem;Keepalive=1")) { conn.Open(); string query = "insert into RocEventFormats (pointtype,format,descshort,desclong) values (1,2,'FAKE','FAKE FORMAT');"; using (NpgsqlCommand command = new NpgsqlCommand(query, conn)) { waiting = true; command.ExecuteNonQuery(); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (waiting && stopwatch.ElapsedMilliseconds < waitlimitms) { Thread.Sleep(100); } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= waitlimitms) { Assert.Fail("Notification not received"); } else { if (currentTest != resultOperation) { Assert.Fail("Unexpected operation '" + resultOperation + "', expected '" + currentTest + "'"); } CompareREFs(expectedREF, resultingREF); } } }