예제 #1
0
        public void TryAddNewAlarmCode(int alarmCodeID, string alarmText, EnumAlarmLevel level, string description)
        {
            Alarm newAlarm = new Alarm();

            newAlarm.Id          = alarmCodeID;
            newAlarm.AlarmText   = alarmText;
            newAlarm.Level       = level;
            newAlarm.Description = description;

            if (!AllAlarms.ContainsKey(newAlarm.Id))
            {
                AllAlarms.Add(newAlarm.Id, newAlarm);
            }
        }
예제 #2
0
        private void LoadAlarmFile()
        {
            try
            {
                string alarmFullPath = Path.Combine(LocalData.Instance.MapConfig.FileDirectory, alarmFileName);

                if (!File.Exists(alarmFullPath))
                {
                    WriteLog(3, "", String.Concat("找不到AlarmCode.csv, path : ", alarmFullPath));
                    return;
                }

                Dictionary <string, int> dicAlarmIndexes = new Dictionary <string, int>();
                AllAlarms.Clear();

                string[] allRows = File.ReadAllLines(alarmFullPath, Encoding.UTF8);

                if (allRows == null || allRows.Length < 2)
                {
                    WriteLog(3, "", "There are no alarms in file");
                    return;
                }

                string[] titleRow = allRows[0].Split(',');
                allRows = allRows.Skip(1).ToArray();

                int nRows    = allRows.Length;
                int nColumns = titleRow.Length;

                //Id, AlarmText, PlcAddress, PlcBitNumber, Level, Description
                for (int i = 0; i < nColumns; i++)
                {
                    var keyword = titleRow[i].Trim();

                    if (!string.IsNullOrWhiteSpace(keyword))
                    {
                        dicAlarmIndexes.Add(keyword, i);
                    }
                }

                for (int i = 0; i < nRows; i++)
                {
                    string[] getThisRow = LoadAlarmFile_SplitCsvLine(allRows[i]);
                    Alarm    oneRow     = new Alarm();
                    oneRow.Id          = int.Parse(getThisRow[dicAlarmIndexes["Id"]]);
                    oneRow.AlarmText   = getThisRow[dicAlarmIndexes["AlarmText"]];
                    oneRow.Level       = EnumAlarmLevelParse(getThisRow[dicAlarmIndexes["Level"]]);
                    oneRow.Description = getThisRow[dicAlarmIndexes["Description"]];

                    if (AllAlarms.ContainsKey(oneRow.Id))
                    {
                        WriteLog(3, "", String.Concat("Alarm code : ", oneRow.Id.ToString(), "repeat"));
                    }
                    else
                    {
                        AllAlarms.Add(oneRow.Id, oneRow);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog(3, "", String.Concat("Exception : ", ex.ToString()));
                WriteLog(3, "", String.Concat("Exception : ", ex.StackTrace));
            }
        }