Example #1
0
        void btnPreviewClick(object sender, EventArgs e)
        {
            TParseYAMLFormsDefinition.ClearCachedYamlFiles();
            bool bRequiresUCFilterFindDeclaration = false;

            // generate the code
            TFrmYamlPreview.ProcessFile(FFilename, FSelectedLocalisation);

            // load the designer code
            StreamReader  sr           = new StreamReader(FFilename.Replace(".yaml", "-generated.Designer.cs"));
            StringBuilder DesignerCode = new StringBuilder();

            string Namespace = string.Empty;
            string ClassName = "T" + Path.GetFileNameWithoutExtension(FFilename);

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();

                if (line.StartsWith("namespace "))
                {
                    Namespace = line.Substring("namespace ".Length);
                }

                if (line.Contains("+= new "))
                {
                    // ignore event handlers
                }
                else if (line.Contains(".ListTable = "))
                {
                    // ignore TtxtAutoPopulatedButtonLabel.set_ListTable
                }
                else if (line.Contains("partial class"))
                {
                    ClassName = line.Substring("    partial class ".Length);

                    if (Path.GetFileNameWithoutExtension(FFilename).StartsWith("UC"))
                    {
                        line = line.Replace("partial", string.Empty) + ": UserControl {";
                    }
                    else
                    {
                        line = line.Replace("partial", string.Empty) + ": Form {";
                    }

                    DesignerCode.Append(line).Append(Environment.NewLine);
                    line = "public " + ClassName + "() : base()     { InitializeComponent(); }";
                    DesignerCode.Append(line).Append(Environment.NewLine);
                    // read opening curly bracket
                    line = sr.ReadLine();
                }
                else if (line.Contains("FucoFilterAndFind.Dispose()"))
                {
                    // FucoFilterAndFind is not decalred through the standard YAML file and so is not part of the Designer file
                    // This means we have to add it to our copy that will be compiled
                    bRequiresUCFilterFindDeclaration = true;
                }
                else if ((line.Contains("CheckBox chkToggleFilter;")) && bRequiresUCFilterFindDeclaration)
                {
                    // This is a good point to add our FucoFilterAndFind declaration
                    DesignerCode.Append(line).Append(Environment.NewLine);
                    DesignerCode.Append("        private Ict.Common.Controls.TUcoFilterAndFind FucoFilterAndFind;").Append(Environment.NewLine);
                }
                else
                {
                    DesignerCode.Append(line).Append(Environment.NewLine);
                }
            }

            sr.Close();

            if (TLogging.DebugLevel > 0)
            {
                StreamWriter sw = new StreamWriter("../../log/tempPreviewWinforms.cs");
                sw.WriteLine(DesignerCode.ToString());
                sw.Close();
            }

            // compile the designer code
            CompilerResults results = CompileForm(DesignerCode.ToString(), Namespace + "." + ClassName);

            if (results.Errors.HasErrors)
            {
                TLogging.Log(results.Errors.ToString());
                return;
            }

            // open the form
            ShowScreen(results.CompiledAssembly, Namespace + "." + ClassName);
        }
Example #2
0
        public static void Main(string[] args)
        {
            try
            {
                new TAppSettingsManager(false);

                if (Directory.Exists("log"))
                {
                    new TLogging("log/generatewinforms.log");
                }
                else
                {
                    new TLogging("generatewinforms.log");
                }

                TLogging.DebugLevel = TAppSettingsManager.GetInt16("Server.DebugLevel", 0);

                if (!TAppSettingsManager.HasValue("op"))
                {
                    Console.WriteLine("call: GenerateWinForms -op:generate -ymlfile:c:\\test.yaml -petraxml:petra.xml -localisation:en");
                    Console.WriteLine("  or: GenerateWinForms -op:generate -ymldir:c:\\myclient -petraxml:petra.xml -localisation:en");
                    Console.WriteLine("  or: GenerateWinForms -op:clean -ymldir:c:\\myclient");
                    Console.WriteLine("  or: GenerateWinForms -op:preview");
                    Console.Write("Press any key to continue . . . ");
                    Console.ReadLine();
                    Environment.Exit(-1);
                    return;
                }

                // calculate ICTPath from ymlfile path
                string fullYmlfilePath =
                    Path.GetFullPath(TAppSettingsManager.GetValue("ymlfile", TAppSettingsManager.GetValue("ymldir", false))).Replace(
                        "\\",
                        "/");

                if (!fullYmlfilePath.Contains("csharp/ICT"))
                {
                    Console.WriteLine("ymlfile must be below the csharp/ICT directory");
                }

                CSParser.ICTPath = fullYmlfilePath.Substring(0, fullYmlfilePath.IndexOf("csharp/ICT") + "csharp/ICT".Length);

                if (TAppSettingsManager.GetValue("op") == "clean")
                {
                    if (!Directory.Exists(fullYmlfilePath))
                    {
                        throw new Exception("invalid directory " + fullYmlfilePath);
                    }

                    // delete all generated files in the directory
                    foreach (string file in System.IO.Directory.GetFiles(fullYmlfilePath, "*.yaml", SearchOption.AllDirectories))
                    {
                        DeleteGeneratedFile(file, "-generated.cs");
                        DeleteGeneratedFile(file, "-generated.Designer.cs");
                        DeleteGeneratedFile(file, "-generated.resx");
                    }
                }
                else if (TAppSettingsManager.GetValue("op") == "preview")
                {
                    string SelectedLocalisation = null;         // none selected by default; winforms autosize works quite well

                    if (TAppSettingsManager.HasValue("localisation"))
                    {
                        SelectedLocalisation = TAppSettingsManager.GetValue("localisation");
                    }

                    TDataBinding.FPetraXMLStore = new TDataDefinitionStore();
                    Console.WriteLine("parsing " + TAppSettingsManager.GetValue("petraxml", true));
                    TDataDefinitionParser parser = new TDataDefinitionParser(TAppSettingsManager.GetValue("petraxml", true));
                    parser.ParseDocument(ref TDataBinding.FPetraXMLStore, true, true);

                    TFrmYamlPreview PreviewWindow = new TFrmYamlPreview(
                        TAppSettingsManager.GetValue("ymlfile"),
                        SelectedLocalisation);

                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
                    Application.ThreadException += new ThreadExceptionEventHandler(UnhandledThreadExceptionHandler);

                    PreviewWindow.ShowDialog();

                    return;
                }
                else if (TAppSettingsManager.GetValue("op") == "generate")
                {
                    string SelectedLocalisation = null;         // none selected by default; winforms autosize works quite well

                    if (TAppSettingsManager.HasValue("localisation"))
                    {
                        SelectedLocalisation = TAppSettingsManager.GetValue("localisation");
                    }

                    TDataBinding.FPetraXMLStore = new TDataDefinitionStore();
                    Console.WriteLine("parsing " + TAppSettingsManager.GetValue("petraxml", true));
                    TDataDefinitionParser parser = new TDataDefinitionParser(TAppSettingsManager.GetValue("petraxml", true));
                    parser.ParseDocument(ref TDataBinding.FPetraXMLStore, true, true);

                    string ymlfileParam = TAppSettingsManager.GetValue("ymlfile", TAppSettingsManager.GetValue("ymldir", false));

                    if (ymlfileParam.Contains(","))
                    {
                        StringCollection collection = StringHelper.StrSplit(ymlfileParam, ",");

                        foreach (string file in collection)
                        {
                            ProcessFile(file, SelectedLocalisation);
                        }
                    }
                    else if (System.IO.Directory.Exists(ymlfileParam))
                    {
                        string[] yamlfiles = System.IO.Directory.GetFiles(ymlfileParam, "*.yaml", SearchOption.AllDirectories);
                        // sort the files so that the deepest files are first processed,
                        // since the files higher up are depending on them
                        // eg. FinanceMain.yaml needs to check for GLBatch-generated.cs

                        List <string> yamlFilesSorted = new List <string>(yamlfiles.Length);

                        foreach (string file in yamlfiles)
                        {
                            yamlFilesSorted.Add(file);
                        }

                        yamlFilesSorted.Sort(new YamlFileOrderComparer());

                        foreach (string file in yamlFilesSorted)
                        {
                            // only look for main files, not language specific files (*.xy-XY.yaml or *.xy.yaml)
                            if (TProcessYAMLForms.IgnoreLanguageSpecificYamlFile(file))
                            {
                                continue;
                            }

                            Console.WriteLine("working on " + file);
                            ProcessFile(file, SelectedLocalisation);
                        }
                    }
                    else
                    {
                        ProcessFile(ymlfileParam, SelectedLocalisation);
                    }
                }
            }
            catch (Exception e)
            {
                string commandline = "";

                foreach (string s in args)
                {
                    commandline += s + " ";
                }

                Console.WriteLine("Problem while processing " + commandline);
                Console.WriteLine(e.GetType().ToString() + ": " + e.Message);

                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.GetType().ToString() + ": " + e.InnerException.Message);
                }

                // do not print a stacktrace for custom generated exception, eg. by the YML parser
                if ((e.GetType() != typeof(System.Exception)) || (TLogging.DebugLevel > 0))
                {
                    Console.WriteLine(e.StackTrace);
                }

                Environment.Exit(-1);
            }
        }