Beispiel #1
0
        private DeviceCollection GetTable(string name, string pattern)
        {
            var devices = new DeviceCollection();

            tables.Add(name, devices);

            var signals = Symbols.Where(x => Regex.IsMatch(x.Symbol, pattern));

            //var x1 = signals.First().Symbol.Substring(0, signals.First().Symbol.IndexOf('_'));
            ///var x2 = GetDevice(signals.First().Symbol, name);

            var devicesOrdered = signals.GroupBy(x => new { location = x.Symbol.Substring(0, x.Symbol.IndexOf('_')), device = GetDevice(x.Symbol, name) }).Select(g => new { key = g.Key, value = g.First() }).OrderBy(o => o.key.device);

            devices.AddRange(devicesOrdered.Select(x => new Device()
            {
                DeviceSymbol     = (x.value.Symbol.EndsWith("_OUT_Of") || x.value.Symbol.EndsWith("_OUT_On")) ? x.value.Symbol.Substring(0, x.value.Symbol.LastIndexOf("_OUT_")) : x.value.Symbol.Substring(0, x.value.Symbol.LastIndexOf('_')),
                Point            = ((x.value.Symbol.EndsWith("_OUT_Of") || x.value.Symbol.EndsWith("_OUT_On")) ? x.value.Symbol.Substring(0, x.value.Symbol.LastIndexOf("_OUT_")) : x.value.Symbol.Substring(0, x.value.Symbol.LastIndexOf('_'))).Replace("_", "."),
                Comment          = x.value.Comment,
                Description      = GetDescription(x.key.device, x.value.Comment),
                Tooltip          = GetToolTip(x.key.device, x.value.Comment),
                AlarmDescription = GetAlarmDescription(x.key.device, x.value.Comment),
                Location         = x.value.Symbol.Substring(0, x.value.Symbol.IndexOf("_"))
            }));


            return(devices);
        }
Beispiel #2
0
        private void GetCustomTables()
        {
            if (!Directory.Exists(Location))
            {
                return;
            }

            try
            {
                var files = Directory.GetFiles(Location, "*.jsond");

                foreach (var f in files)
                {
                    var d = DeviceCollection.Deserialize(File.ReadAllText(f));
                    if (d.Name == null)
                    {
                        d.Name = Path.GetFileNameWithoutExtension(f);
                    }

                    if (!tables.ContainsKey(d.Name))
                    {
                        tables.Add(d.Name, d);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"GetCustomTables error: {ex.Message}");
            }
        }
Beispiel #3
0
        public async Task <DeviceCollection> GetTable(string table, string name)
        {
            DeviceCollection list = new DeviceCollection();

            list.Name = name;

            using (OleDbConnection db = new OleDbConnection(Connection))
            {
                using (var cmd = db.CreateCommand())
                {
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = $"SELECT [point], [Comment], [description], [tooltip], [DeviceSymbol], [Comment], [Location] FROM [{table}]";

                    try
                    {
                        db.Open();
                        var reader = await cmd.ExecuteReaderAsync();

                        while (reader.Read())
                        {
                            if (!reader.IsDBNull(0))
                            {
                                list.Add(new Device()
                                {
                                    Point            = reader.GetString(0),
                                    Comment          = reader.IsDBNull(1) ? null : reader.GetString(1),
                                    Description      = reader.IsDBNull(2) ? null : reader.GetString(2),
                                    AlarmDescription = reader.IsDBNull(5) ? null : reader.GetString(5),
                                    DeviceSymbol     = reader.IsDBNull(4) ? null : reader.GetString(4),
                                    Location         = reader.IsDBNull(5) ? null : reader.GetString(5),
                                    Tooltip          = reader.IsDBNull(3) ? null : reader.GetString(3)
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (db.State == System.Data.ConnectionState.Open)
                        {
                            db.Close();
                        }
                    }
                }
            }

            return(list);
        }
Beispiel #4
0
        static string FindObjectAndFill(string fileContent, string objectName, DeviceCollection table)
        {
            int pos = 0, os;

            while ((pos = fileContent.IndexOf($"\"$object\" \"{objectName}\"", pos + 1, StringComparison.InvariantCultureIgnoreCase)) > 0)
            {
                if ((os = fileContent.LastIndexOf("(GmmiOptionTable", pos, StringComparison.InvariantCultureIgnoreCase)) > 0)
                {
                    int brcnt = 1;
                    int cpos  = os;
                    while (brcnt > 0)
                    {
                        cpos = cpos + 1;
                        char c = fileContent[cpos];
                        if (c == '(')
                        {
                            brcnt = brcnt + 1;
                        }
                        else if (c == ')')
                        {
                            brcnt = brcnt - 1;
                        }
                    }
                    int oe = cpos;

                    var newObject = ReplaceVariableValues(fileContent.Substring(os, oe - os + 1), table);
                    if (newObject != null)
                    {
                        fileContent = fileContent.Substring(0, os - 1) +
                                      newObject +
                                      fileContent.Substring(oe + 1);
                    }
                }
            }

            return(fileContent);
        }
Beispiel #5
0
        static string ReplaceVariableValues(string objectString, DeviceCollection table)
        {
            int pos = objectString.IndexOf("\"point\"", StringComparison.InvariantCultureIgnoreCase);

            if (pos < 0)
            {
                return(null);
            }

            int pns = objectString.IndexOf("\"", pos + 7);

            if (pns < 0)
            {
                return(null);
            }

            int pne = objectString.IndexOf("\"", pns + 1);

            if (pne < 0)
            {
                return(null);
            }


            var pointname = objectString.Substring(pns + 1, pne - pns - 1);

            var rec = table.FirstOrDefault(x => x.Point.Trim() == pointname);

            if (rec == null)
            {
                return(null);
            }

            string newObjectString;

            if ((newObjectString = ReplaceVariableValue(objectString, "description", ((rec.Description == null || rec.Description.Length == 0) ? "" : "{&h22}" + rec.Description + "{&h22}"))) != null)
            {
                objectString = newObjectString;
            }

            if ((newObjectString = ReplaceVariableValue(objectString, "tooltiptext", ((rec.Tooltip == null || rec.Tooltip.Length == 0) ? "" : "{&h22}" + rec.Tooltip + "{&h22}"))) != null)
            {
                objectString = newObjectString;
            }


            string unit = null, chartTable = null, chartValueDescription = null, chartYTitle = null;

            if (Regex.IsMatch(pointname, @"(\.I)[^\.]*$")) /// pointname.EndsWith(".I"))
            {
                chartTable            = "ENERGIA";
                chartValueDescription = rec.Comment;
                unit        = "A";
                chartYTitle = $"I [{unit}]";
            }
            else if (Regex.IsMatch(pointname, @"(\.U)[^\.]*$")) ///(pointname.EndsWith(".U") || pointname.EndsWith(".U1"))
            {
                chartTable            = "ENERGIA";
                chartValueDescription = rec.Comment;
                unit        = pointname.Contains("VN") ? "kV" : "V";
                chartYTitle = $"U [{unit}]";
            }
            if (chartYTitle != null)
            {
                if ((newObjectString = ReplaceVariableValue(objectString, "chartTable", chartTable)) != null)
                {
                    objectString = newObjectString;
                }

                if ((newObjectString = ReplaceVariableValue(objectString, "chartValueDescription", chartValueDescription)) != null)
                {
                    objectString = newObjectString;
                }

                if ((newObjectString = ReplaceVariableValue(objectString, "chartYTitle", chartYTitle)) != null)
                {
                    objectString = newObjectString;
                }

                if ((newObjectString = ReplaceVariableValue(objectString, "unit", unit)) != null)
                {
                    objectString = newObjectString;
                }
            }

            return(objectString);
        }