blob: 027f2fc73f252000377f374507319b69b347fd94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Helpers;
using Tango.Documents;
using Tango.PMR.Debugging;
using Tango.PMR.Diagnostics;
using Tango.PMR.EmbeddedParameters;
namespace Tango.AlarmParametersGenerator
{
class Program
{
private class ExcelEventType
{
public String Code { get; set; }
public String Name { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public String TechnicalDescription { get; set; }
public String Index { get; set; }
public String Category { get; set; }
public String Group { get; set; }
public String UserInterventionRequired { get; set; }
public String ActionsUI { get; set; }
public String ActionsEmbedded { get; set; }
public String NotificationTime { get; set; }
public String Guidance { get; set; }
//Embedded
public String SWIndex { get; set; }
public String Frequency { get; set; }
public String Source { get; set; }
public String DeviceId { get; set; }
public String ApplicationDeviceID { get; set; }
public String Criteria { get; set; }
public String Direction { get; set; }
public String Severity { get; set; }
public String Predeccesor { get; set; }
public String DebounceValue { get; set; }
public override string ToString()
{
return this.ToJsonString();
}
}
static void Main(string[] args)
{
try
{
if (args.Count() == 0)
{
throw new ArgumentException("Please specify an output file path");
}
String outputFile = args[0];
Console.WriteLine("Generating alarm parameters file...");
ExcelReader reader = new ExcelReader(PathHelper.GetStartupPath() + "\\Tango alarm events handling chart_Rev8.xlsx");
var results = reader.GetDataByIndex<ExcelEventType>("ALARM EVENTS HANDLING", 2);
AlarmParameters parameters = new AlarmParameters();
foreach (var item in results)
{
if (!String.IsNullOrWhiteSpace(item.Source))
{
Console.WriteLine($"Parsing event {item.Code}...");
AlarmHandlingItem alarm = new AlarmHandlingItem();
alarm.AlarmSource = item.Source.ToEnum<AlarmSourceType>();
alarm.Frequency = item.Frequency.ToUint();
alarm.DeviceId = item.DeviceId.ToUint();
alarm.ModuleDeviceId = item.ApplicationDeviceID.ToUint();
alarm.AlarmValue = item.Criteria.ToUint();
alarm.AlarmDirection = item.Direction.ToBoolean();
alarm.Severity = item.Severity.ToEnum<DebugLogCategory>();
alarm.Predecessor = item.Predeccesor.ToUint();
alarm.DebounceValue = item.DebounceValue.ToUint();
alarm.EventType = (EventType)item.Code.ToUint();
parameters.AlarmItem.Add(alarm);
}
}
File.WriteAllBytes(outputFile, parameters.ToBytes());
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("File generated successfully!");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
}
}
}
public static class Extensions
{
public static UInt32 ToUint(this String str)
{
return String.IsNullOrWhiteSpace(str) ? 0 : UInt32.Parse(str);
}
public static T ToEnum<T>(this String str) where T : struct
{
return String.IsNullOrWhiteSpace(str) ? default(T) : (T)Enum.Parse(typeof(T), str);
}
public static bool ToBoolean(this String str)
{
return String.IsNullOrWhiteSpace(str) ? false : (str.Contains("0") ? false : true);
}
}
}
|