private void CreateConnectors(TNamespace tn, String AOutputPath, String ATemplateDir) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "Instantiator.Connectors-generated.cs"; if (Directory.Exists(AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "connect")) { OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "connect" + Path.DirectorySeparatorChar + "Instantiator.Connectors-generated.cs"; } Console.WriteLine("working on " + OutputFile); SortedList <string, TypeDeclaration> connectors = TCollectConnectorInterfaces.GetConnectors(tn.Name); ProcessTemplate Template = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "Connector.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir)); Template.SetCodelet("TOPLEVELMODULE", tn.Name); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared.Interfaces.M" + tn.Name + ";" + Environment.NewLine); UsingConnectorNamespaces = new List <string>(); 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))); Template.SetCodelet("CONNECTORCLASSES", string.Empty); foreach (TNamespace sn in tn.Children.Values) { WriteConnectorClass( Template, "Ict.Petra.Shared.M" + tn.Name + "." + sn.Name, sn.Name, sn.Name, sn.Children, connectors); } foreach (string n in UsingConnectorNamespaces) { Template.AddToCodelet("USINGNAMESPACES", "using " + n + ";" + Environment.NewLine); } Template.FinishWriting(OutputFile, ".cs", true); }
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); } }
//other interfaces, e.g. IPartnerUIConnectorsPartnerEdit // we don't know the interfaces that are implemented, so need to look for the base classes // we need to know all the source files that are part of the UIConnector dll private void WriteNamespaces(ProcessTemplate AMainTemplate, TNamespace tn, SortedList AInterfaceNames, List <CSParser> ACSFiles) { AMainTemplate.SetCodelet("MODULE", tn.Name); // parse Instantiator source code foreach (TNamespace sn in tn.Children.Values) { WriteNamespace(AMainTemplate, "Ict.Petra.Shared.Interfaces.M" + tn.Name + "." + sn.Name, sn.Name, tn, sn, sn.Children, AInterfaceNames, ACSFiles); } }
/// <summary> /// main function to create the interface files /// </summary> public void CreateFiles(TNamespace ANamespaces, String AOutputPath, String ATemplateDir) { FTemplateDir = ATemplateDir; foreach (TNamespace tn in ANamespaces.Children.Values) { string module = TAppSettingsManager.GetValue("module", "all"); if ((module == "all") || (tn.Name == module)) { WriteInterfaces(tn, AOutputPath); } } }
/// <summary> /// use CSParser to parse the Server files /// </summary> /// <param name="tn"></param> /// <param name="AOutputPath"></param> private void WriteInterfaces(TNamespace tn, String AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + tn.Name + ".Interfaces-generated.cs"; // open file Console.WriteLine("working on file " + OutputFile); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "Interface.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.AddToCodelet("USINGNAMESPACES", AddNamespacesFromYmlFile(AOutputPath, tn.Name)); // get all csharp files that might hold implementations of remotable classes List <CSParser> CSFiles = null; if (AOutputPath.Contains("ICT/Petra/Plugins")) { // search for webconnectors in the directory of the plugin CSFiles = CSParser.GetCSFilesForDirectory(Path.GetFullPath(AOutputPath + "/../Server"), SearchOption.AllDirectories); } else if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name)) { // any class in the module can contain a webconnector CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name, SearchOption.AllDirectories); } else { CSFiles = new List <CSParser>(); } SortedList InterfaceNames = GetInterfaceNamesFromImplementation(CSFiles); Template.SetCodelet("INTERFACES", string.Empty); WriteNamespaces(Template, tn, InterfaceNames, CSFiles); if (Template.FCodelets["INTERFACES"].Length == 0) { Template.InsertSnippet("INTERFACES", Template.GetSnippet("DUMMYINTERFACE")); } Template.FinishWriting(OutputFile, ".cs", true); }
/// <summary> /// write the client code /// </summary> static public void GenerateCode(TNamespace ANamespaces, String AOutputPath, String ATemplateDir) { FTemplateDir = ATemplateDir; FCompileForStandalone = TAppSettingsManager.GetValue("compileForStandalone", "false", false) == "true"; foreach (TNamespace tn in ANamespaces.Children.Values) { string module = TAppSettingsManager.GetValue("module", "all"); if ((module == "all") || (tn.Name == module)) { SortedList <string, TypeDeclaration> connectors = TCollectConnectorInterfaces.GetConnectors(AOutputPath, tn.Name); CreateClientGlue(tn, connectors, AOutputPath); } } }
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); } }
/// <summary> /// write the namespace for an interface /// this includes all the interfaces in this namespace /// it calls itself recursively for sub namespaces /// </summary> private void WriteNamespace( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { WriteInterface( AMainTemplate, ParentNamespace, ParentInterfaceName, "I" + ParentInterfaceName + "Namespace", tn, sn, children, InterfaceNames, ACSFiles); StringCollection InterfacesInNamespace = GetInterfacesInNamespace(ParentNamespace, InterfaceNames); // has been written already; we want to keep the order of the interfaces this way InterfacesInNamespace.Remove("I" + ParentInterfaceName + "Namespace"); foreach (String InterfaceName in InterfacesInNamespace) { WriteInterface( AMainTemplate, ParentNamespace, ParentInterfaceName, InterfaceName, tn, sn, children, InterfaceNames, ACSFiles); } foreach (TNamespace child in children.Values) { WriteNamespace( AMainTemplate, ParentNamespace + "." + child.Name, ParentInterfaceName + child.Name, tn, child, child.Children, InterfaceNames, ACSFiles); } }
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 { 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")); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); } }
//other interfaces, e.g. IPartnerUIConnectorsPartnerEdit // we don't know the interfaces that are implemented, so need to look for the base classes // we need to know all the source files that are part of the UIConnector dll private void WriteNamespaces(ProcessTemplate AMainTemplate, TNamespace tn, SortedList AInterfaceNames, List <CSParser> ACSFiles) { AMainTemplate.SetCodelet("MODULE", tn.Name); foreach (TNamespace sn in tn.Children.Values) { ProcessTemplate snippet = AMainTemplate.GetSnippet("SUBNAMESPACE"); snippet.SetCodelet("SUBNAMESPACENAME", sn.Name); snippet.SetCodelet("SUBNAMESPACEOBJECT", sn.Name); AMainTemplate.InsertSnippet("SUBNAMESPACES", snippet); } // parse Instantiator source code foreach (TNamespace sn in tn.Children.Values) { WriteNamespace(AMainTemplate, "Ict.Petra.Shared.Interfaces.M" + tn.Name + "." + sn.Name, sn.Name, tn, sn, sn.Children, AInterfaceNames, ACSFiles); } }
static private void InsertSubNamespaces(ProcessTemplate ATemplate, SortedList <string, TypeDeclaration> connectors, string AParentNamespaceName, string AFullNamespace, TNamespace AParentNamespace) { ATemplate.SetCodelet("SUBNAMESPACECLASSES", string.Empty); ATemplate.SetCodelet("SUBNAMESPACEPROPERTIES", string.Empty); ATemplate.SetCodelet("CONNECTORMETHODS", string.Empty); foreach (TNamespace sn in AParentNamespace.Children.Values) { ProcessTemplate templateProperty = ATemplate.GetSnippet("SUBNAMESPACEPROPERTY"); templateProperty.SetCodelet("NAMESPACENAME", AParentNamespaceName + sn.Name); templateProperty.SetCodelet("SUBNAMESPACENAME", sn.Name); templateProperty.SetCodelet("OBJECTNAME", sn.Name); ProcessTemplate templateClass = ATemplate.GetSnippet("NAMESPACECLASS"); templateClass.SetCodelet("NAMESPACENAME", AParentNamespaceName + sn.Name); InsertSubNamespaces(templateClass, connectors, AParentNamespaceName + sn.Name, AFullNamespace + "." + sn.Name, sn); ATemplate.InsertSnippet("SUBNAMESPACECLASSES", templateClass); ATemplate.InsertSnippet("SUBNAMESPACEPROPERTIES", templateProperty); } if (AParentNamespaceName.EndsWith("WebConnectors")) { ImplementWebConnector(connectors, ATemplate, AFullNamespace); } else { ImplementUIConnector(connectors, ATemplate, AFullNamespace); } }
void WriteInterface( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, string AInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { ProcessTemplate snippet = AMainTemplate.GetSnippet("INTERFACE"); snippet.SetCodelet("INTERFACENAME", AInterfaceName); snippet.SetCodelet("CONTENT", string.Empty); //this should return the Connector classes; the instantiator classes are in a different namespace string ServerConnectorNamespace = ParentNamespace.Replace("Ict.Petra.Shared.Interfaces", "Ict.Petra.Server"); // don't write methods twice, once from Connector, and then again from Instantiator StringCollection MethodsAlreadyWritten = new StringCollection(); List <TypeDeclaration> ConnectorClasses2 = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerConnectorNamespace); WriteConnectorMethods( snippet, ref MethodsAlreadyWritten, ConnectorClasses2, AInterfaceName, ParentNamespace, ServerConnectorNamespace); AMainTemplate.InsertSnippet("INTERFACES", snippet); }
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 { GenerateServerGlue.GenerateCode(namespaceRoot, AOutputDir + "/Server", ACmd.GetOptValue("TemplateDir")); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Environment.Exit(-1); } }
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); } }
void WriteInterface( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, string AInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { ProcessTemplate snippet = AMainTemplate.GetSnippet("INTERFACE"); snippet.SetCodelet("INTERFACENAME", AInterfaceName); snippet.SetCodelet("CONTENT", string.Empty); snippet.SetCodelet("SUBNAMESPACES", string.Empty); foreach (TNamespace child in children.Values) { ProcessTemplate snippetSubNamespace = AMainTemplate.GetSnippet("SUBNAMESPACE"); snippetSubNamespace.SetCodelet("SUBNAMESPACENAME", ParentInterfaceName + child.Name); snippetSubNamespace.SetCodelet("SUBNAMESPACEOBJECT", child.Name); snippet.InsertSnippet("SUBNAMESPACES", snippetSubNamespace); } //this should return the Connector classes; the instantiator classes are in a different namespace string ServerConnectorNamespace = ParentNamespace.Replace("Ict.Petra.Shared.Interfaces", "Ict.Petra.Server"); // don't write methods twice, once from Connector, and then again from Instantiator StringCollection MethodsAlreadyWritten = new StringCollection(); StringCollection InterfacesInNamespace = GetInterfacesInNamespace(ParentNamespace, InterfaceNames); foreach (string ChildInterface in InterfacesInNamespace) { List <TypeDeclaration> ConnectorClasses = GetClassesThatImplementInterface( ACSFiles, ChildInterface, ServerConnectorNamespace); if (AInterfaceName.EndsWith("Namespace")) { WriteConnectorConstructors( snippet, ref MethodsAlreadyWritten, ConnectorClasses, ChildInterface, ParentNamespace, ServerConnectorNamespace); } } List <TypeDeclaration> ConnectorClasses2 = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerConnectorNamespace); WriteConnectorMethods( snippet, ref MethodsAlreadyWritten, ConnectorClasses2, AInterfaceName, ParentNamespace, ServerConnectorNamespace); if (!ParentNamespace.Contains("WebConnector")) { // this is for the instantiator classes StringCollection NamespaceSplit = StringHelper.StrSplit(ParentNamespace, "."); // eg convert Ict.Petra.Shared.Interfaces.MPartner.Extracts.UIConnectors to Ict.Petra.Server.MPartner.Instantiator.Extracts.UIConnectors NamespaceSplit[2] = "Server"; NamespaceSplit[3] = NamespaceSplit[4]; NamespaceSplit[4] = "Instantiator"; string ServerInstantiatorNamespace = StringHelper.StrMerge(NamespaceSplit, '.'); List <TypeDeclaration> InstantiatorClasses = GetClassesThatImplementInterface( ACSFiles, AInterfaceName, ServerInstantiatorNamespace); WriteInstantiatorMethods( snippet, MethodsAlreadyWritten, InstantiatorClasses, AInterfaceName, ParentNamespace, ServerInstantiatorNamespace); } AMainTemplate.InsertSnippet("INTERFACES", snippet); }
private void CreateAutoHierarchy(TNamespace tn, String AOutputPath) { String OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "Instantiator.AutoHierarchy-generated.cs"; if (Directory.Exists(AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "connect")) { OutputFile = AOutputPath + Path.DirectorySeparatorChar + "M" + tn.Name + Path.DirectorySeparatorChar + "connect" + Path.DirectorySeparatorChar + "Instantiator.AutoHierarchy-generated.cs"; } Console.WriteLine("working on " + OutputFile); SortedList <string, TypeDeclaration> connectors = TCollectConnectorInterfaces.GetConnectors(tn.Name); ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar + "ClientServerGlue" + Path.DirectorySeparatorChar + "Instantiator.cs"); // load default header with license and copyright Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir)); Template.SetCodelet("TOPLEVELMODULE", tn.Name); Template.AddToCodelet("USINGNAMESPACES", "using Ict.Petra.Shared.Interfaces.M" + tn.Name + ";" + Environment.NewLine); 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)); ProcessTemplate topLevelNamespaceSnippet = Template.GetSnippet("TOPLEVELNAMESPACE"); topLevelNamespaceSnippet.SetCodelet("SUBNAMESPACEREMOTABLECLASSES", ""); topLevelNamespaceSnippet.SetCodelet("TOPLEVELMODULE", tn.Name); topLevelNamespaceSnippet.InsertSnippet("LOADERCLASS", WriteLoaderClass(Template, tn.Name)); topLevelNamespaceSnippet.InsertSnippet("MAINREMOTABLECLASS", WriteRemotableClass( topLevelNamespaceSnippet, "Ict.Petra.Shared.M" + tn.Name, "TM" + tn.Name, "M" + tn.Name, true, tn.Children, connectors)); foreach (TNamespace sn in tn.Children.Values) { topLevelNamespaceSnippet.InsertSnippet("SUBNAMESPACEREMOTABLECLASSES", WriteRemotableClass( topLevelNamespaceSnippet, "Ict.Petra.Shared.M" + tn.Name + "." + sn.Name, sn.Name, sn.Name, false, sn.Children, connectors)); } Template.InsertSnippet("CONTENT", topLevelNamespaceSnippet); Template.FinishWriting(OutputFile, ".cs", true); }
public void convertFile(string inFile, string outFile) { nsList = new TNamespaceList(this); this.outFile = outFile; this.inFile = inFile; var localIdlFile = Program.idlOutTempDirectory + @"\" + Path.GetFileName(inFile); var localIdlFile2 = Program.idlOutTempDirectory + @"\" + Path.GetFileNameWithoutExtension(inFile) + ".i"; var path = Path.GetDirectoryName(inFile).Replace(Program.idlInDirectory, "").Replace("\\", "."); if (File.Exists(localIdlFile)) File.Delete(localIdlFile); File.Copy(inFile, localIdlFile); Environment.CurrentDirectory = Path.GetDirectoryName(localIdlFile); if (Program.runPreprocessor) { Process.Start(new ProcessStartInfo(Program.preprocessorExe, localIdlFile + " /P /DLANGUAGE_JAVASCRIPT=1") { WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit(); } var lines = File.ReadAllLines(localIdlFile2); for (var i = 0; i < lines.Length; i++) if (lines[i].StartsWith("#")) lines[i] = ""; TScriptTokenizer tokenizer = new TScriptTokenizer(string.Join("\r\n", lines)); TCodeTokenFile tf = tokenizer.GetTokenFile(); setTokens(tf.tokens); TNamespace ns = new TNamespace(this); nsList.Add(ns); path = path.Replace("Modules.", ""); if (TransformationConfig.moveToRootNamespace.Contains(path.ToLower())) { ns.name = "SharpKit.Html"; } else { ns.name = "SharpKit.Html." + path.ToLower(); if (!Generator.namespaceNames.Contains(ns.name)) Generator.namespaceNames.Add(ns.name); } getNextToken(); TAttributeList attributes = new TAttributeList(); while (true) { //if (currentToken.token == ECodeToken.kwModule) //{ // getNextToken(); // var module = readDottedString(); // ns.name = "SharpKit.Html"; // //var seperateModules = new HashSet<string>(new string[]{ // // "svg", // // "storage", // // "threads", // // "audio", // // "webaudio", // //}); // if (TransformationConfig.createSubNamespaceForModule.Contains(module)) // { // ns.name += "." + module; // if (!Generator.namespaceNames.Contains(ns.name)) Generator.namespaceNames.Add(ns.name); // } //} //if (CurrentToken.Token == ECodeToken.kwImport) { // GetNextToken(); // string imp = readDottedString(); // if (!(imp.Contains("org.w3c.dom.html.Function"))) { // ns.ImportList.Add(imp); // } //} ns.importList.Clear(); if (currentToken.token == ECodeToken.brSmallBraceBegin) { attributes = readAttributes(); } if (currentToken.token == ECodeToken.kwInterface) //new type { TFileType t = readInterfaceType(); t.attributes = attributes; foreach (var attr in t.attributes) if (attr is TConstructorAttribute) ((TConstructorAttribute)attr).constructor.parentType = t; attributes = new TAttributeList(); //reset t.ns = ns; ns.types.Add(t); t.checkProp(); } getNextToken(); if (_IsEndOfDocument) { break; } } }
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); }