private static void GenerateGlueForOpenPetraCore(TCmdOpts ACmd, string AOutputDir) { TNamespace namespaceRoot; try { Console.WriteLine("parsing all cs files for namespaces..."); namespaceRoot = TNamespace.ParseFromDirectory(AOutputDir + "/Server/lib/"); if (namespaceRoot.Children.Count < 1) { Console.WriteLine("problems with parsing namespaces from " + AOutputDir + "/Server/lib/"); Environment.Exit(-1); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); return; } try { /* * CreateInstantiators instantiators = new CreateInstantiators(); * instantiators.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir")); * TCreateConnectors connectors = new TCreateConnectors(); * connectors.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir")); */ CreateInterfaces interfaces = new CreateInterfaces(); interfaces.CreateFiles(namespaceRoot, AOutputDir + "/Shared/lib/Interfaces", ACmd.GetOptValue("TemplateDir")); GenerateClientGlue.GenerateCode(namespaceRoot, AOutputDir + "/Client/app/Core/Remoteobjects", ACmd.GetOptValue("TemplateDir")); GenerateClientGlue.GenerateConnectorCode(AOutputDir + "/../Common/Remoting/Client", ACmd.GetOptValue("TemplateDir")); GenerateServerGlue.GenerateCode(namespaceRoot, AOutputDir + "/Server/app/WebService", ACmd.GetOptValue("TemplateDir")); namespaceRoot = new TNamespace(); TNamespace ServerAdminNamespace = new TNamespace("ServerAdmin"); namespaceRoot.Children.Add("ServerAdmin", ServerAdminNamespace); TNamespace ServerAdminWebConnectorNamespace = new TNamespace("WebConnectors"); ServerAdminNamespace.Children.Add("WebConnectors", ServerAdminWebConnectorNamespace); GenerateServerGlue.GenerateCode(namespaceRoot, AOutputDir + "/Server/app/WebService", ACmd.GetOptValue("TemplateDir")); GenerateClientGlue.GenerateCode(namespaceRoot, AOutputDir + "/ServerAdmin/app/Core", ACmd.GetOptValue("TemplateDir")); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); } }
private static void GenerateGlueForPlugin(TCmdOpts ACmd, string AOutputDir) { TNamespace namespaceRoot; AOutputDir = AOutputDir.Replace("\\", "/"); try { Console.WriteLine("parsing plugin cs files for namespaces..."); namespaceRoot = TNamespace.ParseFromDirectory(AOutputDir + "/Server/"); if (namespaceRoot.Children.Count < 1) { Console.WriteLine("There are no connectors in " + AOutputDir + "/Server/"); return; } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); return; } try { CreateInterfaces interfaces = new CreateInterfaces(); #if disabled // at the moment, we do not support UIConnectors for plugins. Better to focus on Webconnectors! if (!Directory.Exists(AOutputDir + "/Shared")) { Directory.CreateDirectory(AOutputDir + "/Shared"); } interfaces.CreateFiles(namespaceRoot, AOutputDir + "/Shared", ACmd.GetOptValue("TemplateDir")); #endif GenerateClientGlue.GenerateCode(namespaceRoot, AOutputDir + "/Client", ACmd.GetOptValue("TemplateDir")); GenerateServerGlue.GenerateCode(namespaceRoot, AOutputDir + "/Server", ACmd.GetOptValue("TemplateDir")); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); } }
static private void CreateServerGlue(TNamespace tn, SortedList <string, TypeDeclaration> connectors, string AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "ServerGlue.M" + tn.Name + "-generated.cs"; Console.WriteLine("working on " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "ServerGlue.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.SetCodelet("TOPLEVELMODULE", tn.Name); Template.SetCodelet("WEBCONNECTORS", string.Empty); Template.SetCodelet("UICONNECTORS", string.Empty); string InterfacePath = Path.GetFullPath(AOutputPath).Replace(Path.DirectorySeparatorChar, '/'); InterfacePath = InterfacePath.Substring(0, InterfacePath.IndexOf("csharp/ICT/Petra")) + "csharp/ICT/Petra/Shared/lib/Interfaces"; Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, tn.Name)); if (AOutputPath.Contains("ICT/Petra/Plugins/")) { Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Server.App.WebService;" + Environment.NewLine); // add namespaces that are required by the plugin InterfacePath = Path.GetFullPath(AOutputPath + "/../").Replace(Path.DirectorySeparatorChar, '/'); Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, "Plugin")); } FUsingNamespaces = new SortedList <string, string>(); FContainsAsynchronousExecutionProgress = false; foreach (string connector in connectors.Keys) { if (connector.EndsWith("UIConnector")) { WriteUIConnector(connector, connectors[connector], Template); } else { WriteWebConnector(connector, connectors[connector], Template); } } if (FContainsAsynchronousExecutionProgress) { Template.InsertSnippet("UICONNECTORS", Template.GetSnippet("ASYNCEXECPROCESSCONNECTOR")); if (!FUsingNamespaces.ContainsKey("Ict.Petra.Server.MCommon")) { FUsingNamespaces.Add("Ict.Petra.Server.MCommon", "Ict.Petra.Server.MCommon"); } } foreach (string usingNamespace in FUsingNamespaces.Keys) { Template.AddToCodelet("USINGNAMESPACES", "using " + usingNamespace + ";" + Environment.NewLine); } if (OutputFile.Replace("\\", "/").Contains("ICT/Petra/Plugins")) { string pluginWithNamespace = TAppSettingsManager.GetValue("plugin"); Template.SetCodelet("WEBSERVICENAMESPACE", pluginWithNamespace + ".WebService"); } else { Template.SetCodelet("WEBSERVICENAMESPACE", "Ict.Petra.Server.App.WebService"); } Template.FinishWriting(OutputFile, ".cs", true); }
static private void CreateClientGlue(TNamespace tn, SortedList <string, TypeDeclaration> connectors, string AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "ClientGlue.M" + tn.Name + "-generated.cs"; Console.WriteLine("working on " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "ClientGlue.cs"); FUsingNamespaces = new SortedList <string, string>(); FModuleHasUIConnector = false; FUIConnectorsAdded = new List <string>(); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.SetCodelet("TOPLEVELMODULE", tn.Name); string InterfacePath = Path.GetFullPath(AOutputPath).Replace(Path.DirectorySeparatorChar, '/'); InterfacePath = InterfacePath.Substring(0, InterfacePath.IndexOf("csharp/ICT/Petra")) + "csharp/ICT/Petra/Shared/lib/Interfaces"; Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, tn.Name)); if (AOutputPath.Contains("ICT/Petra/Plugins/")) { // add namespaces that are required by the plugin InterfacePath = Path.GetFullPath(AOutputPath + "/../").Replace(Path.DirectorySeparatorChar, '/'); Template.AddToCodelet("USINGNAMESPACES", CreateInterfaces.AddNamespacesFromYmlFile(InterfacePath, "Plugin")); } string SharedPathName = "Ict.Petra.Shared.M" + tn.Name; if (SharedPathName.Contains("ServerAdmin")) { SharedPathName = "Ict.Petra.Server.App.Core." + tn.Name; } else if (OutputFile.Contains("ICT/Petra/Plugins")) { SharedPathName = "Ict.Petra.Plugins." + tn.Name; } InsertSubNamespaces(Template, connectors, tn.Name, SharedPathName, tn); if (FModuleHasUIConnector) { Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared.Interfaces.M" + tn.Name + ";" + Environment.NewLine); } foreach (string usingNamespace in FUsingNamespaces.Keys) { Template.AddToCodelet("USINGNAMESPACES", "using " + usingNamespace + ";" + Environment.NewLine); } if (OutputFile.Contains("ClientGlue.MServerAdmin")) { Template.SetCodelet("REMOTEOBJECTSNAMESPACE", "Ict.Petra.ServerAdmin.App.Core.RemoteObjects"); } else if (OutputFile.Contains("ICT/Petra/Plugins")) { string pluginWithNamespace = TAppSettingsManager.GetValue("plugin"); Template.SetCodelet("REMOTEOBJECTSNAMESPACE", pluginWithNamespace + ".RemoteObjects"); } else { Template.SetCodelet("REMOTEOBJECTSNAMESPACE", "Ict.Petra.Client.App.Core.RemoteObjects"); } Template.FinishWriting(OutputFile, ".cs", true); }
public static void Main(string[] args) { TCmdOpts cmd = new TCmdOpts(); new TAppSettingsManager(false); TLogging.DebugLevel = TAppSettingsManager.GetInt32("debuglevel", 0); String OutputDir; if (!cmd.IsFlagSet("TemplateDir")) { Console.WriteLine("call: " + sampleCall); return; } if (cmd.IsFlagSet("outputdir")) { OutputDir = cmd.GetOptValue("outputdir"); // calculate ICTPath from outputdir string fullOutputPath = Path.GetFullPath(OutputDir).Replace("\\", "/"); if (!fullOutputPath.Contains("csharp/ICT")) { Console.WriteLine("Output path must be below the csharp/ICT directory"); } CSParser.ICTPath = fullOutputPath.Substring(0, fullOutputPath.IndexOf("csharp/ICT") + "csharp/ICT".Length); } else { Console.WriteLine("call: " + sampleCall); return; } TNamespace namespaceRoot; try { Console.WriteLine("parsing all cs files for namespaces..."); namespaceRoot = TNamespace.ParseFromDirectory(OutputDir + "/Server/lib/"); if (namespaceRoot.Children.Count < 1) { Console.WriteLine("problems with parsing namespaces from " + OutputDir + "/Server/lib/"); Environment.Exit(-1); } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); return; } try { CreateInterfaces interfaces = new CreateInterfaces(); interfaces.CreateFiles(namespaceRoot, OutputDir + "/Shared/lib/Interfaces", cmd.GetOptValue("TemplateDir")); CreateInstantiators instantiators = new CreateInstantiators(); instantiators.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir")); TCreateConnectors connectors = new TCreateConnectors(); connectors.CreateFiles(namespaceRoot, OutputDir + "/Server/lib", cmd.GetOptValue("TemplateDir")); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); } }