Skip to content

Commit

Permalink
MetaDataImportAdapter, CommonPhasorServices
Browse files Browse the repository at this point in the history
  • Loading branch information
collins-self committed Dec 26, 2024
1 parent b50baa4 commit 586c742
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1119,12 +1119,14 @@ private static void OptimizeLocalHistorianSettings(AdoDataConnection database, s
string archiveLocation = FilePath.GetDirectoryName(settings["FileName"].Value);
string adapterName = $"{instanceName}READER";
string connectionString = string.Format("archiveLocation={0}; instanceName={1}; sourceIDs={1}; publicationInterval=333333; connectOnDemand=true", archiveLocation, instanceName);
string query = "INSERT INTO CustomInputAdapter(NodeID, AdapterName, AssemblyName, TypeName, ConnectionString, LoadOrder, Enabled) " + $"VALUES({nodeIDQueryString}, @adapterName, 'HistorianAdapters.dll', 'HistorianAdapters.LocalInputAdapter', @connectionString, 0, 1)";

string query = database.ParameterizedQueryString("INSERT INTO " +
"CustomInputAdapter(NodeID, AdapterName, AssemblyName, TypeName, ConnectionString, LoadOrder, Enabled) " +
"VALUES({0}, @{1}, 'HistorianAdapters.dll', 'HistorianAdapters.LocalInputAdapter', @{2}, 0, 1)",
"nodeIDQueryString", "adapterName", "connectionString");
if (database.IsOracle)
query = query.Replace('@', ':');

database.Connection.ExecuteNonQuery(query, adapterName, connectionString);
database.Connection.ExecuteNonQuery(query, nodeIDQueryString, adapterName, connectionString);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -1252,7 +1254,10 @@ private static void AddPIHistorianReaders(AdoDataConnection database, string nod

string connectionString = string.IsNullOrEmpty(userName) ? $"ServerName={serverName}; ConnectTimeout={connectTimeout}; sourceIDs={instanceName}; connectOnDemand=true" : $"ServerName={serverName}; UserName={userName}; Password={password.ToNonNullString()}; ConnectTimeout={connectTimeout}; sourceIDs={instanceName}; connectOnDemand=true";

string query = "INSERT INTO CustomInputAdapter(NodeID, AdapterName, AssemblyName, TypeName, ConnectionString, LoadOrder, Enabled) " + $"VALUES({nodeIDQueryString}, @adapterName, 'PIAdapters.dll', 'PIAdapters.PIPBInputAdapter', @connectionString, 0, 1)";
string query = database.ParameterizedQueryString("INSERT INTO " +
"CustomInputAdapter(NodeID, AdapterName, AssemblyName, TypeName, ConnectionString, LoadOrder, Enabled) " +
"VALUES({0}, @{1}, 'PIAdapters.dll', 'PIAdapters.PIPBInputAdapter', @{2}, 0, 1)",
"nodeIDQueryString", "adapterName", "connectionString");

if (database.IsOracle)
query = query.Replace('@', ':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ private Action<DataSet> GetSynchronizeMetadataAction()
List<int> sourceIndicies;

if (definedSourceIndicies.TryGetValue(id, out sourceIndicies))
command.ExecuteNonQuery(deletePhasorSql + $" AND SourceIndex NOT IN ({string.Join(",", sourceIndicies)})", MetadataSynchronizationTimeout, id);
command.ExecuteNonQuery(deletePhasorSql + " AND SourceIndex NOT IN ({0})", string.Join(",", sourceIndicies), MetadataSynchronizationTimeout, id);
else
command.ExecuteNonQuery(deletePhasorSql, MetadataSynchronizationTimeout, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ private static void MeasurementDeviceAssociation(AdoDataConnection connection, s
int virtualProtocolID = connection.ExecuteScalar<int>("SELECT ID FROM Protocol WHERE Acronym='VirtualInput'");

// Create new virtual device record
connection.ExecuteNonQuery($"INSERT INTO Device(NodeID, Acronym, Name, ProtocolID, Enabled) VALUES({nodeIDQueryString}, {{0}}, {{1}}, {{2}}, 1)", deviceAcronym, deviceAcronym, virtualProtocolID);
connection.ExecuteNonQuery("INSERT INTO Device(NodeID, Acronym, Name, ProtocolID, Enabled) VALUES({0}, {1}, {2}, {3}, 1)", nodeIDQueryString, deviceAcronym, deviceAcronym, virtualProtocolID);
}

statusMessage($"Validating \"{deviceAcronym}\" virtual device measurement associations...");
Expand Down Expand Up @@ -1297,7 +1297,7 @@ private static void PhasorDataSourceValidation(AdoDataConnection database, strin

// Validate that the statistics historian exists
if (Convert.ToInt32(database.Connection.ExecuteScalar("SELECT COUNT(*) FROM Historian WHERE Acronym='STAT' AND NodeID={0}", nodeIDQueryString)) == 0)
database.Connection.ExecuteNonQuery($"INSERT INTO Historian(NodeID, Acronym, Name, AssemblyName, TypeName, ConnectionString, IsLocal, Description, LoadOrder, Enabled) VALUES({nodeIDQueryString}, 'STAT', 'Statistics Archive', 'HistorianAdapters.dll', 'HistorianAdapters.LocalOutputAdapter', '', 1, 'Local historian used to archive system statistics', 9999, 1)");
database.Connection.ExecuteNonQuery("INSERT INTO Historian(NodeID, Acronym, Name, AssemblyName, TypeName, ConnectionString, IsLocal, Description, LoadOrder, Enabled) VALUES({0}, 'STAT', 'Statistics Archive', 'HistorianAdapters.dll', 'HistorianAdapters.LocalOutputAdapter', '', 1, 'Local historian used to archive system statistics', 9999, 1)", nodeIDQueryString);

// Make sure statistics path exists to hold historian files
string statisticsPath = FilePath.GetAbsolutePath(FilePath.AddPathSuffix("Statistics"));
Expand Down Expand Up @@ -1533,7 +1533,8 @@ private static void PhasorDataSourceValidation(AdoDataConnection database, strin
signalReference = SignalReference.ToString(acronym, SignalKind.Statistic, signalIndex);
// If the original format for device statistics is found in the database, update to new format
if (Convert.ToInt32(database.Connection.ExecuteScalar("SELECT COUNT(*) FROM Measurement WHERE SignalReference='{0}' AND HistorianID={1}", oldSignalReference, statHistorianID)) > 0)
database.Connection.ExecuteNonQuery($"UPDATE Measurement SET SignalReference='{signalReference}' WHERE SignalReference='{oldSignalReference}' AND HistorianID={statHistorianID}");
database.Connection.ExecuteNonQuery("UPDATE Measurement SET SignalReference='{0}' " +
"WHERE SignalReference='{1}' AND HistorianID={2}", signalReference, oldSignalReference, statHistorianID);
else if (!skipOptimization)
break;
}
Expand Down Expand Up @@ -1564,7 +1565,7 @@ private static void PhasorDataSourceValidation(AdoDataConnection database, strin
}

// Remove extraneous input statistics
database.Connection.ExecuteNonQuery($"DELETE FROM Measurement WHERE SignalReference = '{signalReference}'");
database.Connection.ExecuteNonQuery("DELETE FROM Measurement WHERE SignalReference = '{0}'", signalReference);
}
}
}
Expand Down Expand Up @@ -1635,7 +1636,7 @@ private static void PhasorDataSourceValidation(AdoDataConnection database, strin

foreach (int measurementID in measurementIDsToDelete)
{
database.Connection.ExecuteNonQuery($"DELETE FROM OutputStreamMeasurement WHERE ID = {measurementID} AND NodeID = {nodeIDQueryString}");
database.Connection.ExecuteNonQuery("DELETE FROM OutputStreamMeasurement WHERE ID = {0} AND NodeID = {1}", measurementID, nodeIDQueryString);
}
}

Expand Down Expand Up @@ -1679,7 +1680,8 @@ private static void PhasorDataSourceValidation(AdoDataConnection database, strin
if (string.IsNullOrWhiteSpace(label))
label = measurement.ConvertField<string>("AlternateTag");

database.Connection.ExecuteNonQuery($"UPDATE Measurement SET PointTag = '{CreatePointTag(company, device, vendor, signalAcronym, label, signalIndex, phase ?? '_', baseKV)}' WHERE SignalID = '{database.Guid(measurement, "SignalID")}'");
database.Connection.ExecuteNonQuery("UPDATE Measurement SET PointTag = '{0}' WHERE SignalID = '{1}'",
CreatePointTag(company, device, vendor, signalAcronym, label, signalIndex, phase ?? '_', baseKV), database.Guid(measurement, "SignalID"));
}
}

Expand Down Expand Up @@ -1709,7 +1711,7 @@ private static void CreateDefaultNode(AdoDataConnection database, string nodeIDQ
{
statusMessage("Creating default record for Node...");
database.Connection.ExecuteNonQuery("INSERT INTO Node(Name, CompanyID, Description, Settings, MenuType, MenuData, Master, LoadOrder, Enabled) VALUES('Default', NULL, 'Default node', 'RemoteStatusServerConnectionString={server=localhost:8500;integratedSecurity=true};datapublisherport=6165;AlarmServiceUrl=http://localhost:5018/alarmservices', 'File', 'Menu.xml', 1, 0, 1)");
database.Connection.ExecuteNonQuery("UPDATE Node SET ID=" + nodeIDQueryString);
database.Connection.ExecuteNonQuery("UPDATE Node SET ID={0}", nodeIDQueryString);
}
}

Expand Down

0 comments on commit 586c742

Please sign in to comment.