using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.ExtensionMethods; 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 Persistent { get; set; } 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) { var color = Console.ForegroundColor; try { var options = new Options(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { ExitError(); return; } if (!File.Exists(options.ExcelFile)) { throw new FileNotFoundException($"Could not locate excel file '{Path.GetFullPath(options.ExcelFile)}'."); } Console.WriteLine(); Console.WriteLine("Generating alarm parameters file..."); Console.WriteLine(); Console.WriteLine($"Source: {Path.GetFullPath(options.ExcelFile)}"); Console.WriteLine($"Target: {Path.GetFullPath(options.OutputFile)}"); Console.WriteLine(); ExcelReader reader = new ExcelReader(options.ExcelFile); var results = reader.GetDataByIndex("ALARM EVENTS HANDLING", 2); AlarmParameters parameters = new AlarmParameters(); foreach (var item in results) { if (!String.IsNullOrWhiteSpace(item.Source)) { Console.WriteLine($"Parsing event {item.Code}, {item.Name},{item.Source}..."); AlarmHandlingItem alarm = new AlarmHandlingItem(); alarm.AlarmSource = item.Source.ToEnum(); //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(); //alarm.Predecessor = item.Predeccesor.ToUint(); alarm.DebounceValue = item.DebounceValue.ToUint(); alarm.EventType = (EventType)item.Code.ToUint(); alarm.IsPersistent = item.Persistent.ToBooleanYesNo(); parameters.AlarmItem.Add(alarm); } } Console.WriteLine("Writing file..."); File.WriteAllBytes(options.OutputFile, parameters.ToBytes()); Console.WriteLine("Validating file..."); AlarmParameters checkParameters = AlarmParameters.Parser.ParseFrom(File.ReadAllBytes(options.OutputFile)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("File generated successfully."); Console.ForegroundColor = color; } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ForegroundColor = color; } } private static void ExitError() { Environment.Exit(-1); } } public static class Extensions { public static UInt32 ToUint(this String str) { return String.IsNullOrWhiteSpace(str) ? 0 : UInt32.Parse(str); } public static T ToEnum(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); } public static bool ToBooleanYesNo(this String str) { return String.IsNullOrWhiteSpace(str) ? false : (str.Contains("Yes") ? true : false); } } }