private static TemplatedExpressionParser InitializePointTagExpressionParser() { TemplatedExpressionParser pointTagExpressionParser; // Get point tag name expression from configuration try { // Note that both manager and service application may need this expression and each will have their own setting, users // will need to synchronize these expressions in both config files for consistent custom point tag naming ConfigurationFile configFile = ConfigurationFile.Current; CategorizedSettingsElementCollection settings = configFile.Settings["systemSettings"]; settings.Add("PointTagNameExpression", DefaultPointTagNameExpression, "Defines the expression used to create point tag names. NOTE: if updating this setting, synchronize value in both the manager and service config files."); pointTagExpressionParser = new TemplatedExpressionParser() { TemplatedExpression = configFile.Settings["systemSettings"]["PointTagNameExpression"].Value }; } catch { pointTagExpressionParser = new TemplatedExpressionParser() { TemplatedExpression = DefaultPointTagNameExpression }; } return pointTagExpressionParser; }
public static string CreatePointTag(string companyAcronym, string deviceAcronym, string vendorAcronym, string signalTypeAcronym, int signalIndex = -1, char phase = '_') { // Initialize point tag expression parser if ((object)s_pointTagExpressionParser == null) s_pointTagExpressionParser = InitializePointTagExpressionParser(); // Initialize signal type dictionary if ((object)s_signalTypes == null) s_signalTypes = InitializeSignalTypes(); Dictionary<string, string> substitutions; DataRow signalTypeValues; if (!s_signalTypes.TryGetValue(signalTypeAcronym, out signalTypeValues)) throw new ArgumentOutOfRangeException("signalTypeAcronym", "No database definition was found for signal type \"" + signalTypeAcronym + "\""); // Validate key acronyms if ((object)companyAcronym == null) companyAcronym = ""; if ((object)deviceAcronym == null) deviceAcronym = ""; if ((object)vendorAcronym == null) vendorAcronym = ""; companyAcronym = companyAcronym.Trim(); deviceAcronym = deviceAcronym.Trim(); vendorAcronym = vendorAcronym.Trim(); // Define fixed parameter replacements substitutions = new Dictionary<string, string> { { "{CompanyAcronym}", companyAcronym }, { "{DeviceAcronym}", deviceAcronym }, { "{VendorAcronym}", vendorAcronym }, { "{SignalIndex}", signalIndex.ToString() }, { "{Phase}", phase.ToString() } }; // Define signal type field value replacements DataColumnCollection columns = signalTypeValues.Table.Columns; for (int i = 0; i < columns.Count; i++) { substitutions.Add(string.Format("{{SignalType.{0}}}", columns[i].ColumnName), signalTypeValues[i].ToNonNullString()); } return s_pointTagExpressionParser.Execute(substitutions); }