示例#1
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);
        }
示例#2
0
        void ImplementWebConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace("Ict.Petra.Shared.", "Ict.Petra.Server.");

            ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty);

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet = ATemplate.GetSnippet("WEBCONNECTORMETHOD");

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    snippet.InsertSnippet("CHECKUSERMODULEPERMISSIONS",
                                          CreateModuleAccessPermissionCheck(
                                              ATemplate,
                                              connectorClass.Name,
                                              m));

                    string returntype = AutoGenerationTools.TypeToString(m.TypeReference, "");

                    snippet.SetCodelet("RETURN", returntype != "void" ? "return " : string.Empty);

                    snippet.SetCodelet("METHODNAME", m.Name);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("RETURNTYPE", returntype);
                    snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name);

                    if (!UsingConnectorNamespaces.Contains(ConnectorNamespace))
                    {
                        UsingConnectorNamespaces.Add(ConnectorNamespace);
                    }

                    ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
                }
            }
        }
示例#3
0
        /// <summary>
        /// write the interfaces for the methods that need to be reflected
        /// check connector files
        /// </summary>
        /// <param name="ATemplate"></param>
        /// <param name="AMethodsAlreadyWritten">write methods only once</param>
        /// <param name="AConnectorClasses">the classes that are implementing the methods</param>
        /// <param name="AInterfaceName">the interface that is written at the moment</param>
        /// <param name="AInterfaceNamespace">only needed to shorten the type names to improve readability</param>
        /// <param name="AServerNamespace">for the comment in the autogenerated code</param>
        /// <returns></returns>
        private bool WriteConnectorMethods(
            ProcessTemplate ATemplate,
            ref StringCollection AMethodsAlreadyWritten,
            List <TypeDeclaration> AConnectorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace)
        {
            foreach (TypeDeclaration t in AConnectorClasses)
            {
                string ConnectorClassName = t.Name;

                foreach (PropertyDeclaration p in CSParser.GetProperties(t))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                    {
                        continue;
                    }

                    if (!p.GetRegion.Block.ToString().Contains("TCreateRemotableObject"))
                    {
                        TLogging.Log("Warning: properties in UIConnectors must use the class TCreateRemotableObject: " +
                                     AServerNamespace + "." + t.Name + "." + p.Name);
                    }

                    // don't write namespace hierarchy here
                    if (p.TypeReference.Type.IndexOf("Namespace") == -1)
                    {
                        String returnType = AutoGenerationTools.TypeToString(p.TypeReference, AInterfaceNamespace);

                        // this interface got implemented somewhere on the server
                        ProcessTemplate snippet = ATemplate.GetSnippet("CONNECTORPROPERTY");
                        snippet.SetCodelet("CONNECTORCLASSNAME", ConnectorClassName);
                        snippet.SetCodelet("SERVERNAMESPACE", AServerNamespace);
                        snippet.SetCodelet("TYPE", returnType);
                        snippet.SetCodelet("NAME", p.Name);

                        if (p.HasGetRegion)
                        {
                            snippet.SetCodelet("GETTER", "true");
                        }

                        if (p.HasSetRegion)
                        {
                            snippet.SetCodelet("SETTER", "true");
                        }

                        ATemplate.InsertSnippet("CONTENT", snippet);
                    }
                }

                foreach (MethodDeclaration m in CSParser.GetMethods(t))
                {
                    string MethodName = m.Name;

                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    String formattedMethod = "";
                    String returnType      = AutoGenerationTools.TypeToString(m.TypeReference, AInterfaceNamespace);

                    int align = (returnType + " " + m.Name).Length + 1;

                    // this interface got implemented somewhere on the server
                    formattedMethod = "/// <summary> auto generated from Connector method(" + AServerNamespace + "." + ConnectorClassName +
                                      ")</summary>" + Environment.NewLine;
                    formattedMethod += returnType + " " + m.Name + "(";

                    bool firstParameter = true;

                    foreach (ParameterDeclarationExpression p in m.Parameters)
                    {
                        if (!firstParameter)
                        {
                            ATemplate.AddToCodelet("CONTENT", formattedMethod + "," + Environment.NewLine);
                            formattedMethod = new String(' ', align);
                        }

                        firstParameter = false;
                        String parameterType = AutoGenerationTools.TypeToString(p.TypeReference, "");

                        if ((p.ParamModifier & ParameterModifiers.Ref) != 0)
                        {
                            formattedMethod += "ref ";
                        }
                        else if ((p.ParamModifier & ParameterModifiers.Out) != 0)
                        {
                            formattedMethod += "out ";
                        }

                        formattedMethod += parameterType + " " + p.ParameterName;
                    }

                    formattedMethod += ");";
                    AMethodsAlreadyWritten.Add(MethodName);
                    ATemplate.AddToCodelet("CONTENT", formattedMethod + Environment.NewLine);
                }
            }

            return(true);
        }
        private ProcessTemplate WriteRemotableClass(ProcessTemplate ATemplate,
                                                    String FullNamespace,
                                                    String Classname,
                                                    String Namespace,
                                                    Boolean HighestLevel,
                                                    SortedList <string, TNamespace> children,
                                                    SortedList <string, TypeDeclaration> connectors)
        {
            if ((children.Count == 0) && !HighestLevel)
            {
                return(new ProcessTemplate());
            }

            ProcessTemplate remotableClassSnippet = ATemplate.GetSnippet("REMOTABLECLASS");

            remotableClassSnippet.SetCodelet("SUBNAMESPACEREMOTABLECLASSES", string.Empty);

            remotableClassSnippet.SetCodelet("NAMESPACE", Namespace);

            remotableClassSnippet.SetCodelet("CLIENTOBJECTFOREACHPROPERTY", string.Empty);
            remotableClassSnippet.SetCodelet("SUBNAMESPACEPROPERTIES", string.Empty);

            foreach (TNamespace sn in children.Values)
            {
                ProcessTemplate subNamespaceSnippet = ATemplate.GetSnippet("SUBNAMESPACEPROPERTY");

                string NamespaceName = Namespace + sn.Name;

                if (HighestLevel)
                {
                    NamespaceName = sn.Name;
                }

                subNamespaceSnippet.SetCodelet("OBJECTNAME", sn.Name);
                subNamespaceSnippet.SetCodelet("NAMESPACENAME", NamespaceName);
                subNamespaceSnippet.SetCodelet("NAMESPACE", Namespace);

                remotableClassSnippet.InsertSnippet("SUBNAMESPACEPROPERTIES", subNamespaceSnippet);

                if (sn.Children.Count > 0)
                {
                    // properties for each sub namespace
                    foreach (TNamespace subnamespace in sn.Children.Values)
                    {
                        ATemplate.InsertSnippet("SUBNAMESPACEREMOTABLECLASSES",
                                                WriteRemotableClass(ATemplate,
                                                                    FullNamespace + "." + sn.Name + "." + subnamespace.Name,
                                                                    sn.Name + subnamespace.Name,
                                                                    NamespaceName + subnamespace.Name,
                                                                    false,
                                                                    subnamespace.Children,
                                                                    connectors));
                    }

                    remotableClassSnippet.InsertSnippet("CLIENTOBJECTFOREACHPROPERTY",
                                                        TCreateClientRemotingClass.AddClientRemotingClass(
                                                            FTemplateDir,
                                                            "T" + NamespaceName + "NamespaceRemote",
                                                            "I" + NamespaceName + "Namespace",
                                                            new List <TypeDeclaration>(),
                                                            FullNamespace + "." + sn.Name,
                                                            sn.Children
                                                            ));
                }
                else
                {
                    remotableClassSnippet.InsertSnippet("CLIENTOBJECTFOREACHPROPERTY",
                                                        TCreateClientRemotingClass.AddClientRemotingClass(
                                                            FTemplateDir,
                                                            "T" + NamespaceName + "NamespaceRemote",
                                                            "I" + NamespaceName + "Namespace",
                                                            TCollectConnectorInterfaces.FindTypesInNamespace(connectors, FullNamespace + "." + sn.Name)
                                                            ));
                }
            }

            return(remotableClassSnippet);
        }
        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);
        }
示例#6
0
        void ImplementUIConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace("Ict.Petra.Shared.", "Ict.Petra.Server.");

            ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty);

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORMETHOD");

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    string methodname = m.Name.Substring(1);

                    if (methodname.EndsWith("UIConnector"))
                    {
                        methodname = methodname.Substring(0, methodname.LastIndexOf("UIConnector"));
                    }

                    snippet.SetCodelet("METHODNAME", methodname);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("UICONNECTORINTERFACE", CSParser.GetImplementedInterface(connectorClass));
                    snippet.SetCodelet("UICONNECTORCLIENTREMOTINGCLASS", connectorClass.Name + "Remote");
                    snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);

                    if (!UsingConnectorNamespaces.Contains(ConnectorNamespace))
                    {
                        UsingConnectorNamespaces.Add(ConnectorNamespace);
                    }

                    ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
                }

                List <TypeDeclaration> tempList = new List <TypeDeclaration>();
                tempList.Add(connectorClass);

                ATemplate.InsertSnippet("CLIENTOBJECTFOREACHUICONNECTOR",
                                        TCreateClientRemotingClass.AddClientRemotingClass(
                                            FTemplateDir,
                                            connectorClass.Name + "Remote",
                                            CSParser.GetImplementedInterface(connectorClass),
                                            tempList
                                            ));
            }
        }
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD");

                string returntype = AutoGenerationTools.TypeToString(m.TypeReference, string.Empty);

                methodSnippet.SetCodelet("METHODNAME", m.Name);
                methodSnippet.SetCodelet("RETURNTYPE", returntype);

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);

                if (returntype != "void")
                {
                    methodSnippet.SetCodelet("RETURN", "return ");
                }
                else
                {
                    methodSnippet.SetCodelet("RETURN", string.Empty);
                }

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }

            // foreach public method create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                ProcessTemplate propertySnippet = ClientRemotingClassTemplate.GetSnippet("PROPERTY");

                propertySnippet.SetCodelet("NAME", p.Name);
                propertySnippet.SetCodelet("TYPE", AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                if (p.HasGetRegion)
                {
                    propertySnippet.SetCodelet("GETTER", "yes");
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "yes");
                }

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }