Пример #1
0
        private static TNamespace FindOrCreateNamespace(TNamespace ARootNamespace, string ANamespaceName)
        {
            if (ANamespaceName.Contains("."))
            {
                TNamespace parent = FindOrCreateNamespace(ARootNamespace, ANamespaceName.Substring(0, ANamespaceName.LastIndexOf(".")));

                string childName = ANamespaceName.Substring(ANamespaceName.LastIndexOf(".") + 1);

                if (parent.Children.ContainsKey(childName))
                {
                    return(parent.Children[childName]);
                }
                else
                {
                    TNamespace Result = new TNamespace(childName);
                    parent.Children.Add(childName, Result);
                    return(Result);
                }
            }
            else if (!ARootNamespace.Children.ContainsKey(ANamespaceName))
            {
                TNamespace Result = new TNamespace(ANamespaceName);
                ARootNamespace.Children.Add(ANamespaceName, Result);
                return(Result);
            }
            else
            {
                return(ARootNamespace.Children[ANamespaceName]);
            }
        }
Пример #2
0
    private static TNamespace FindOrCreateNamespace(TNamespace ARootNamespace, string ANamespaceName)
    {
        if (ANamespaceName.Contains("."))
        {
            TNamespace parent = FindOrCreateNamespace(ARootNamespace, ANamespaceName.Substring(0, ANamespaceName.LastIndexOf(".")));

            string childName = ANamespaceName.Substring(ANamespaceName.LastIndexOf(".") + 1);

            if (parent.Children.ContainsKey(childName))
            {
                return parent.Children[childName];
            }
            else
            {
                TNamespace Result = new TNamespace(childName);
                parent.Children.Add(childName, Result);
                return Result;
            }
        }
        else if (!ARootNamespace.Children.ContainsKey(ANamespaceName))
        {
            TNamespace Result = new TNamespace(ANamespaceName);
            ARootNamespace.Children.Add(ANamespaceName, Result);
            return Result;
        }
        else
        {
            return ARootNamespace.Children[ANamespaceName];
        }
    }
Пример #3
0
 /// <summary>
 /// check if this is the current module
 /// </summary>
 /// <param name="AModule"></param>
 /// <returns></returns>
 public static bool FindModule(TNamespace AModule)
 {
     if (AModule.Name == FindModuleName)  //FindModuleName
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
        /// <summary>
        /// parse the namespaces from an XmlDocument
        /// </summary>
        public static TNamespace ParseFromDirectory(string AServerLibPath)
        {
            TNamespace NamespaceRoot = new TNamespace();

            List <CSParser> CSFiles = CSParser.GetCSFilesForDirectory(AServerLibPath, SearchOption.AllDirectories);

            foreach (CSParser file in CSFiles)
            {
                foreach (NamespaceDeclaration namespaceDecl in file.GetNamespaces())
                {
                    if (namespaceDecl.Name.EndsWith("Connectors"))
                    {
                        string name = namespaceDecl.Name.Substring("Ict.Petra.Server.".Length + 1);
                        FindOrCreateNamespace(NamespaceRoot, name);
                    }
                }
            }

            return(NamespaceRoot);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
    /// <summary>
    /// parse the namespaces from an XmlDocument
    /// </summary>
    public static TNamespace ParseFromDirectory(string AServerLibPath)
    {
        TNamespace NamespaceRoot = new TNamespace();

        List <CSParser>CSFiles = CSParser.GetCSFilesForDirectory(AServerLibPath, SearchOption.AllDirectories);

        foreach (CSParser file in CSFiles)
        {
            foreach (NamespaceDeclaration namespaceDecl in file.GetNamespaces())
            {
                if (namespaceDecl.Name.EndsWith("Connectors"))
                {
                    string name = namespaceDecl.Name.Substring("Ict.Petra.Server.".Length + 1);
                    FindOrCreateNamespace(NamespaceRoot, name);
                }
            }
        }

        return NamespaceRoot;
    }
Пример #7
0
 /// <summary>
 /// check if this is the current module
 /// </summary>
 /// <param name="AModule"></param>
 /// <returns></returns>
 public static bool FindModule(TNamespace AModule)
 {
     if (AModule.Name == FindModuleName)      //FindModuleName
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #8
0
    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);
    }
Пример #9
0
    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))
            {
                CreateAutoHierarchy(tn, AOutputPath);
            }
        }
    }
Пример #10
0
    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);
    }
Пример #11
0
        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);
            }
        }
Пример #12
0
        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.Contains(":"))
                {
                    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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        //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);
            }
        }
Пример #15
0
        /// <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)
        {
            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);
            }
        }
Пример #16
0
        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);
        }
Пример #17
0
    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);
    }
Пример #18
0
    //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);
        }
    }
Пример #19
0
        /// <summary>
        /// write the server code
        /// </summary>
        static public void GenerateCode(TNamespace ANamespaces, String AOutputPath, String ATemplateDir)
        {
            if (TAppSettingsManager.GetValue("compileForStandalone", "false", false) == "yes")
            {
                // this code is not needed for standalone
                return;
            }

            FTemplateDir = ATemplateDir;

            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);
                    CreateServerGlue(tn, connectors, AOutputPath);
                }
            }
        }
Пример #20
0
        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);
            }
        }