private void writeScenario()
        {
            if (alreadyGenerated) initialize();

            TemplateGroup group = new TemplateGroupDirectory(this.templatePath, '$', '$');

                ErrorBuffer errors = new ErrorBuffer();
                group.Listener = errors;
                group.Load();

                Template st = group.GetInstanceOf("MainTemplate");

                this.TSFile = genTsStructFromTestContainer(this.outFile, sequence);

                st.Add("TestStandFile", this.TSFile);

                string result = st.Render();

                if (errors.Errors.Count > 0)
                {
                    foreach (TemplateMessage m in errors.Errors)
                    {
                        logger.Error(m);
                        throw new Exception(m.ToString());
                    }
                }

                StreamWriter output = new StreamWriter(this.outFile, false, Encoding.GetEncoding("windows-1251"));

                output.Write(result);
                output.Close();

                CTsGenericInstr.resetIdCounter();
            this.alreadyGenerated = true;
        }
        /// <summary>
        /// Converts a potentially complex tree structure to a standardized, linear TestStand sequence list
        /// </summary>
        /// <param name="sequence">Sequence to convert</param
        /// <returns>Sequence, in a format understandable to generate</returns>
        private TestStandFile genTsStructFromTestContainer(string filename, CTestContainer sequence)
        {
            TestStandFile ts = new TestStandFile(filename);

            foreach(CTest test in sequence)
            {
                logger.Info("Processing sequence");
                CTestStandSeq SubSeq = genInstrListFromTest(test);

                ts.addSequence("Call to subsequence " + SubSeq.identifier, SubSeq);
                logger.Debug("End of sequence Processing");
            }
            return ts;
        }
 private void initialize()
 {
     TSFile = new TestStandFile(outFile);
     alreadyGenerated = false;
 }