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);
        }
Esempio n. 2
0
        private TemplatedExpressionParser InitializePointTagExpressionParser()
        {
            TemplatedExpressionParser pointTagExpressionParser;

            // Get point tag name expression from configuration
            try
            {
                XDocument serviceConfig = XDocument.Load(HostConfig);

                string pointTagNameExpression = serviceConfig
                                                .Descendants("systemSettings")
                                                .SelectMany(systemSettings => systemSettings.Elements("add"))
                                                .Where(element => "PointTagNameExpression".Equals((string)element.Attribute("name"), StringComparison.OrdinalIgnoreCase))
                                                .Select(element => (string)element.Attribute("value"))
                                                .FirstOrDefault() ?? DefaultPointTagNameExpression;

                pointTagExpressionParser = new TemplatedExpressionParser()
                {
                    TemplatedExpression = pointTagNameExpression
                };
            }
            catch
            {
                pointTagExpressionParser = new TemplatedExpressionParser()
                {
                    TemplatedExpression = DefaultPointTagNameExpression
                };
            }

            return(pointTagExpressionParser);
        }
Esempio n. 3
0
        private static string GetSubFolder(Device device, string profileName, string directoryNamingExpression, DateTime eventStartTime)
        {
            TemplatedExpressionParser   directoryNameExpressionParser = new TemplatedExpressionParser('<', '>', '[', ']');
            Dictionary <string, string> substitutions = new Dictionary <string, string>
            {
                { "<YYYY>", $"{eventStartTime.Year}" },
                { "<YY>", $"{eventStartTime.Year.ToString().Substring(2)}" },
                { "<MM>", $"{eventStartTime.Month.ToString().PadLeft(2, '0')}" },
                { "<DD>", $"{eventStartTime.Day.ToString().PadLeft(2, '0')}" },
                { "<DeviceName>", device.Name ?? "undefined" },
                { "<DeviceAcronym>", device.Acronym },
                { "<DeviceFolderName>", string.IsNullOrWhiteSpace(device.OriginalSource) ? device.Acronym : device.OriginalSource },
                { "<ProfileName>", profileName }
            };

            directoryNameExpressionParser.TemplatedExpression = directoryNamingExpression.Replace("\\", "\\\\");

            return($"{directoryNameExpressionParser.Execute(substitutions)}{Path.DirectorySeparatorChar}");
        }
Esempio n. 4
0
        private string GetLocalFileName(string fileName)
        {
            TemplatedExpressionParser   directoryNameExpressionParser = new TemplatedExpressionParser('<', '>', '[', ']');
            Dictionary <string, string> substitutions = new Dictionary <string, string>
            {
                { "<YYYY>", $"{DateTime.Now.Year}" },
                { "<YY>", $"{DateTime.Now.Year.ToString().Substring(2)}" },
                { "<MM>", $"{DateTime.Now.Month.ToString().PadLeft(2, '0')}" },
                { "<DD>", $"{DateTime.Now.Day.ToString().PadLeft(2, '0')}" },
                { "<DeviceName>", (m_deviceRecord["Name"].ToString() == ""? "undefined": m_deviceRecord["Name"].ToString()) },
                { "<DeviceAcronym>", m_deviceRecord["Acronym"].ToString() },
                { "<DeviceFolderName>", (m_deviceRecord["OriginalSource"].ToString() == "" ? m_deviceRecord["Acronym"].ToString() : m_deviceRecord["OriginalSource"].ToString()) },
                { "<ProfileName>", (m_connectionProfile["Name"].ToString() == "" ? "undefined" :m_connectionProfile["Name"].ToString()) }
            };

            directoryNameExpressionParser.TemplatedExpression = m_connectionProfileTaskSettings["directoryNamingExpression"].Replace("\\", "\\\\");

            //         Possible UNC Path                            Sub Directory - duplicate path slashes are removed
            fileName = m_localPath + $"{Path.DirectorySeparatorChar}{directoryNameExpressionParser.Execute(substitutions)}{Path.DirectorySeparatorChar}{fileName}".RemoveDuplicates(Path.DirectorySeparatorChar.ToString());
            //Console.WriteLine(fileName);

            string directoryName = FilePath.GetDirectoryName(fileName);

            if (!Directory.Exists(directoryName))
            {
                try
                {
                    Directory.CreateDirectory(directoryName);
                }
                catch (Exception ex)
                {
                    Program.Log($"Failed to create directory \"{directoryName}\": {ex.Message}", m_tempDirectoryName);
                    throw new InvalidOperationException($"Failed to create directory \"{directoryName}\": {ex.Message}", ex);
                }
            }

            return(fileName);
        }
Esempio n. 5
0
        public string CreatePointTag(string companyAcronym, string deviceAcronym, string vendorAcronym, string signalTypeAcronym, string phasorLabel = null, int signalIndex = -1, char phase = '_', int baseKV = 0)
        {
            // Initialize point tag expression parser
            if (s_pointTagExpressionParser is null)
            {
                s_pointTagExpressionParser = InitializePointTagExpressionParser();
            }

            // Initialize signal type dictionary
            if (s_signalTypes is null)
            {
                s_signalTypes = InitializeSignalTypes();
            }

            Dictionary <string, string> substitutions;

            if (!s_signalTypes.TryGetValue(signalTypeAcronym, out DataRow signalTypeValues))
            {
                throw new ArgumentOutOfRangeException(nameof(signalTypeAcronym), $"No database definition was found for signal type \"{signalTypeAcronym}\"");
            }

            // Validate key acronyms
            if (companyAcronym is null)
            {
                companyAcronym = "";
            }

            if (deviceAcronym is null)
            {
                deviceAcronym = "";
            }

            if (vendorAcronym is null)
            {
                vendorAcronym = "";
            }

            if (phasorLabel is null)
            {
                phasorLabel = "";
            }

            companyAcronym = companyAcronym.Trim();
            deviceAcronym  = deviceAcronym.Trim();
            vendorAcronym  = vendorAcronym.Trim();

            // Define fixed parameter replacements
            substitutions = new Dictionary <string, string>
            {
                { "{CompanyAcronym}", companyAcronym },
                { "{DeviceAcronym}", deviceAcronym },
                { "{VendorAcronym}", vendorAcronym },
                { "{PhasorLabel}", phasorLabel },
                { "{SignalIndex}", signalIndex.ToString() },
                { "{Phase}", phase.ToString() },
                { "{BaseKV}", baseKV.ToString() }
            };

            // Define signal type field value replacements
            DataColumnCollection columns = signalTypeValues.Table.Columns;

            for (int i = 0; i < columns.Count; i++)
            {
                substitutions.Add($"{{SignalType.{columns[i].ColumnName}}}", signalTypeValues[i].ToNonNullString());
            }

            return(s_pointTagExpressionParser.Execute(substitutions));
        }