aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/Controls/ObjectInTreeView.xaml
blob: d331935c8e8d766e5062e8a1f273abbced771b38 (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
<UserControl x:Class="Tango.FSE.Procedures.Controls.ObjectInTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Tango.FSE.Procedures.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" x:Name="ObjectInTreeViewControl">
    <TreeView ItemsSource="{Binding TreeNodes, ElementName=ObjectInTreeViewControl}" Style="{x:Null}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}" Background="Transparent" FontSize="{StaticResource FSE_SmallFontSize}" BorderThickness="0">
        <TreeView.Resources>
            <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                
            </Style>
            <HierarchicalDataTemplate DataType="{x:Type local:TreeNode}" ItemsSource="{Binding Path=Children}">
                <TreeViewItem Style="{x:Null}">
                    <TreeViewItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=Name}"/>
                            <TextBlock Text=" : "/>
                            <TextBlock Text="{Binding Path=Value}"/>
                        </StackPanel>
                    </TreeViewItem.Header>
                </TreeViewItem>
            </HierarchicalDataTemplate>
        </TreeView.Resources>
    </TreeView>
</UserControl>
dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
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 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<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}, {item.Name}...");

                        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);
                    }
                }

                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<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);
        }
    }
}