Beispiel #1
0
        private void button_GEN_XTSF_Click(object sender, EventArgs e)
        {
            var xtsf        = new Testsetfile();
            var ctTests     = 1;
            var ctFunctions = 1;

            foreach (var file in files)
            {
                var ConditionsDictionary = XtsfToCapl.GenerateOutputFile(file);
                xtsf.Tests.Entry.Add(new Entry()
                {
                    Id = $"{ctTests++}", Enabled = "1", Name = "nume Manevra - interface input"
                });
                foreach (var condition in ConditionsDictionary)
                {
                    xtsf.Functions.Entry.Add(new Entry()
                    {
                        Id = $"{ctFunctions++}", Enabled = "1", Name = "Function " + condition.Value.Name
                    });
                    var conditionsList = new List <Condition>()
                    {
                        new Condition()
                        {
                            Type = "Signal Write", Value = $"{condition.Value.Name} = {condition.Value.Value} [{condition.Value.Time}]"
                        }
                    };
                    xtsf.Dataset.Entry.Add(new Entry()
                    {
                        Test = $"{ctTests-1}", Function = $"{ctFunctions-1}", Condition = conditionsList
                    });
                }
            }
            XTSFHELPER.SerializeToXml <Testsetfile>(xtsf, @"D:\ZF\testFiles\WriteLines.xml");
        }
        public static void GenerateOutFile(Testsetfile xTSF, string testCase, string path, string text)
        {
            var pathVar = Path.Combine(path, Path.GetFileNameWithoutExtension(xTSF.Prename));

            if (!Directory.Exists(pathVar))
            {
                Directory.CreateDirectory(pathVar);
            }
            System.IO.File.WriteAllText(Path.Combine(pathVar, testCase + ".can"), text);
        }
 private static Boolean CheckDiagScript(Testsetfile xTSF, string testCase)
 {
     foreach (Entry entry in xTSF.Dataset.Entry.Where(e => e.Test.Equals(testCase)))
     {
         foreach (Condition condition in entry.Condition)
         {
             if (condition.Type.Equals("Diag Script"))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private static int CountValidCondition(Testsetfile xTSF, string testCase)
        {
            int ctor = 0;

            foreach (Entry entry in xTSF.Dataset.Entry.Where(e => e.Test.Equals(testCase)))
            {
                foreach (Condition condition in entry.Condition)
                {
                    if (condition.Type.Equals("Signal write") || condition.Type.Equals("Diag Script"))
                    {
                        ctor++;
                    }
                }
            }
            return(ctor);
        }
        public static void GenerateCapl(Testsetfile xTSF, string testCase, string path)
        {
            double        result;
            int           c         = 0;
            List <string> auxString = new List <string>();
            string        text      = startText;

            if (CheckDiagScript(xTSF, testCase))
            {
                text += "\tDiagRequest req;\n\tlong ret;\n";
            }
            for (int i = 0; i < CountValidCondition(xTSF, testCase); i++)
            {
                text += $"\tmsTimer t{i};\n";
            }
            text += $"}}\non start\n{{";
            foreach (Entry entry in xTSF.Dataset.Entry.Where(e => e.Test.Equals(testCase)))
            {
                foreach (Condition condition in entry.Condition)
                {
                    var ScriptType = CaplConditionFactory.GetScript(condition);
                    if (ScriptType != null)
                    {
                        if (Double.TryParse(ScriptType.Time, out result))
                        {
                            text += $"\n\tsetTimer(t{c++},{result * 1000});";
                        }
                        auxString.Add(ScriptType.ScriptText);
                    }
                }
            }
            text += "\n}";
            foreach (var item in auxString)
            {
                text += $"\non timer t{auxString.IndexOf(item)}\n{{" + item + "}";
            }
            GenerateOutFile(xTSF, testCase, path, text);
        }