Пример #1
0
        static private void WriteWebConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template)
        {
            List <string> MethodNames = new List <string>();

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

                string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name;

                if (!FUsingNamespaces.ContainsKey(connectorNamespaceName))
                {
                    FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName);
                }

                ProcessTemplate snippet = Template.GetSnippet("WEBCONNECTOR");

                InsertWebConnectorMethodCall(snippet, connectorClass, m, ref MethodNames);

                Template.InsertSnippet("WEBCONNECTORS", snippet);
            }
        }
Пример #2
0
        private static ProcessTemplate GenerateUIConnector(ProcessTemplate ATemplate, TypeDeclaration connectorClass, string interfacename)
        {
            ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORCLASS");

            snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
            snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
            snippet.SetCodelet("CONSTRUCTORS", string.Empty);

            int constructorCounter = 0;

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

                constructorCounter++;

                ProcessTemplate snippetConstructor = ATemplate.GetSnippet("UICONNECTORCONSTRUCTOR");

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

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

                snippetConstructor.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                snippetConstructor.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
                snippetConstructor.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                snippetConstructor.SetCodelet("ADDACTUALPARAMETERS", string.Empty);

                foreach (ParameterDeclarationExpression p in m.Parameters)
                {
                    if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                    {
                        throw new Exception("we do not support ref or out parameters in UIConnector constructor calls! " + connectorClass.Name);
                    }

                    snippetConstructor.AddToCodelet("ADDACTUALPARAMETERS",
                                                    "ActualParameters.Add(\"" + p.ParameterName + "\", " +
                                                    p.ParameterName + ");" + Environment.NewLine);
                }

                string methodname = m.Name;

                if (constructorCounter > 1)
                {
                    methodname += constructorCounter.ToString();
                }

                snippetConstructor.SetCodelet("METHODNAME", methodname);

                snippet.InsertSnippet("CONSTRUCTORS", snippetConstructor);
            }

            InsertMethodsAndProperties(snippet, connectorClass);

            return(snippet);
        }
Пример #3
0
        /// <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);
                }
            }
        }
Пример #4
0
        private static 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(".Shared.", ".Server.");

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                List <string> MethodNames = new List <string>();

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

                    ProcessTemplate snippet;

                    if (FCompileForStandalone)
                    {
                        if (!FUsingNamespaces.ContainsKey(ConnectorNamespace))
                        {
                            FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace);
                        }

                        snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODSTANDALONE");
                    }
                    else
                    {
                        snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODREMOTE");
                    }

                    InsertMethodCall(snippet, connectorClass, m, ref MethodNames);

                    ATemplate.InsertSnippet("CONNECTORMETHODS", snippet);
                }
            }
        }
Пример #5
0
        static private void WriteUIConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template)
        {
            List <string> MethodNames = new List <string>();

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

                string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name;

                if (!FUsingNamespaces.ContainsKey(connectorNamespaceName))
                {
                    FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName);
                }

                ProcessTemplate snippet = Template.GetSnippet("UICONNECTORCONSTRUCTOR");

                snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS");

                PrepareParametersForMethod(snippet, null, m.Parameters, m.Name, ref MethodNames);

                Template.InsertSnippet("UICONNECTORS", snippet);
            }

            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

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

                snippet.SetCodelet("METHODNAME", m.Name);
                snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS");

                PrepareParametersForMethod(snippet, m.TypeReference, m.Parameters, m.Name, ref MethodNames);

                if (snippet.FCodelets["PARAMETERDEFINITION"].Length > 0)
                {
                    snippet.AddToCodeletPrepend("PARAMETERDEFINITION", ", ");
                }

                Template.InsertSnippet("UICONNECTORS", snippet);
            }

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

                string propertytype = p.TypeReference.ToString();

                // check if the parametertype is not a generic type, eg. dictionary or list
                if (!propertytype.Contains("<"))
                {
                    propertytype = propertytype == "string" || propertytype == "String" ? "System.String" : propertytype;
                    propertytype = propertytype == "bool" || propertytype == "Boolean" ? "System.Boolean" : propertytype;

                    if (propertytype.Contains("UINT") || propertytype.Contains("unsigned"))
                    {
                        propertytype = propertytype.Contains("UInt32") || propertytype == "unsigned int" ? "System.UInt32" : propertytype;
                        propertytype = propertytype.Contains("UInt16") || propertytype == "unsigned short" ? "System.UInt16" : propertytype;
                        propertytype = propertytype.Contains("UInt64") || propertytype == "unsigned long" ? "System.UInt64" : propertytype;
                    }
                    else
                    {
                        propertytype = propertytype.Contains("Int32") || propertytype == "int" ? "System.Int32" : propertytype;
                        propertytype = propertytype.Contains("Int16") || propertytype == "short" ? "System.Int16" : propertytype;
                        propertytype = propertytype.Contains("Int64") || propertytype == "long" ? "System.Int64" : propertytype;
                    }

                    propertytype = propertytype.Contains("Decimal") || propertytype == "decimal" ? "System.Decimal" : propertytype;
                }

                bool BinaryReturn = !((propertytype == "System.Int64") || (propertytype == "System.Int32") || (propertytype == "System.Int16") ||
                                      (propertytype == "System.String") || (propertytype == "System.Boolean"));

                string EncodedType      = propertytype;
                string EncodeReturnType = string.Empty;
                string ActualValue      = "AValue";

                if (BinaryReturn)
                {
                    EncodedType      = "System.String";
                    EncodeReturnType = "THttpBinarySerializer.SerializeObject";
                    ActualValue      = "(" + propertytype + ")THttpBinarySerializer.DeserializeObject(AValue)";
                }

                ProcessTemplate propertySnippet = Template.GetSnippet("UICONNECTORPROPERTY");
                propertySnippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                propertySnippet.SetCodelet("ENCODEDTYPE", EncodedType);
                propertySnippet.SetCodelet("PROPERTYNAME", p.Name);

                if (p.HasGetRegion)
                {
                    if (p.TypeReference.ToString().StartsWith("I"))
                    {
                        if (p.TypeReference.ToString() == "IAsynchronousExecutionProgress")
                        {
                            FContainsAsynchronousExecutionProgress = true;
                        }

                        // return the ObjectID of the Sub-UIConnector
                        propertySnippet.InsertSnippet("GETTER", Template.GetSnippet("GETSUBUICONNECTOR"));
                        propertySnippet.SetCodelet("ENCODEDTYPE", "System.String");
                    }
                    else
                    {
                        propertySnippet.SetCodelet("GETTER",
                                                   "return {#ENCODERETURNTYPE}((({#UICONNECTORCLASS})FUIConnectors[ObjectID]).{#PROPERTYNAME});");
                        propertySnippet.SetCodelet("ENCODERETURNTYPE", EncodeReturnType);
                    }
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "true");
                    propertySnippet.SetCodelet("ACTUALPARAMETERS", ActualValue);
                }

                Template.InsertSnippet("UICONNECTORS", propertySnippet);
            }
        }
Пример #6
0
        private static 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(".Shared.", ".Server.");

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

                    ProcessTemplate snippet;

                    FModuleHasUIConnector = true;

                    if (FCompileForStandalone)
                    {
                        if (!FUsingNamespaces.ContainsKey(ConnectorNamespace))
                        {
                            FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace);
                        }

                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODSTANDALONE");
                    }
                    else
                    {
                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODREMOTE");
                    }

                    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"));
                    }

                    string interfacename = CSParser.GetImplementedInterface(connectorClass);
                    snippet.SetCodelet("METHODNAME", methodname);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
                    snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);

                    snippet.SetCodelet("UICONNECTORCLASS", string.Empty);

                    if (!FCompileForStandalone)
                    {
                        if (!FUIConnectorsAdded.Contains(connectorClass.Name))
                        {
                            FUIConnectorsAdded.Add(connectorClass.Name);

                            snippet.InsertSnippet("UICONNECTORCLASS",
                                                  GenerateUIConnector(ATemplate, connectorClass, interfacename));
                        }
                    }

                    ATemplate.InsertSnippet("CONNECTORMETHODS", snippet);
                }
            }
        }
Пример #7
0
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            List <string> MethodNames = new List <string>();

            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = template.GetSnippet("UICONNECTORMETHOD");

                InsertMethodCall(methodSnippet, t, m, ref MethodNames);

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

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

                ProcessTemplate propertySnippet = template.GetSnippet("UICONNECTORPROPERTY");

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

                string expectedreturntype = GetExpectedReturnType(0, AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                propertySnippet.SetCodelet("EXPECTEDRETURNTYPE", expectedreturntype);

                if (p.HasGetRegion)
                {
                    if (type.StartsWith("I"))
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return new T" + type.Substring(
                                1) +
                            "(\"M{#TOPLEVELMODULE}\", THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"System.String\").ToString());");
                    }
                    else
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return ({#TYPE}) THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"{#EXPECTEDRETURNTYPE}\");");
                    }
                }

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

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