Example #1
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);
            }
        }
Example #2
0
        static private ProcessTemplate CreateModuleAccessPermissionCheck(ProcessTemplate ATemplate,
                                                                         string AConnectorClassWithNamespace,
                                                                         MethodDeclaration m)
        {
            if (m.Attributes != null)
            {
                foreach (AttributeSection attrSection in m.Attributes)
                {
                    foreach (ICSharpCode.NRefactory.Ast.Attribute attr in attrSection.Attributes)
                    {
                        if (attr.Name == "RequireModulePermission")
                        {
                            ProcessTemplate snippet = ATemplate.GetSnippet("CHECKUSERMODULEPERMISSIONSWITHEXCEPTION");;

                            foreach (ParameterDeclarationExpression p in m.Parameters)
                            {
                                if (p.ParameterName == "AVerificationResult")
                                {
                                    snippet = ATemplate.GetSnippet("CHECKUSERMODULEPERMISSIONSWITHRESULT");
                                }
                            }

                            snippet.SetCodelet("METHODNAME", m.Name);
                            snippet.SetCodelet("CONNECTORWITHNAMESPACE", AConnectorClassWithNamespace);
                            snippet.SetCodelet("LEDGERNUMBER", "-1");

                            string ParameterTypes = ";";

                            foreach (ParameterDeclarationExpression p in m.Parameters)
                            {
                                if (p.ParameterName == "ALedgerNumber")
                                {
                                    snippet.SetCodelet("LEDGERNUMBER", "ALedgerNumber");
                                }

                                string ParameterType = p.TypeReference.Type.Replace("&", "").Replace("System.", String.Empty);

                                if (ParameterType == "List")
                                {
                                    ParameterType = ParameterType.Replace("List", "List[" + p.TypeReference.GenericTypes[0].ToString() + "]");
                                    ParameterType = ParameterType.Replace("System.", String.Empty);
                                }

                                if (ParameterType == "Dictionary")
                                {
                                    // this does not seem to work with Mono 5.12 api browser
                                    // ParameterType = ParameterType.Replace("Dictionary", "Dictionary[" +
                                    //    p.TypeReference.GenericTypes[0].ToString() + "," +
                                    //    p.TypeReference.GenericTypes[1].ToString() + "]");
                                    // ParameterType = ParameterType.Replace("System.", String.Empty);
                                    ParameterType = "String";
                                }

                                if (ParameterType.Contains("."))
                                {
                                    ParameterType = ParameterType.Substring(ParameterType.LastIndexOf(".") + 1);
                                }

                                if (p.TypeReference.Type == "System.Nullable")
                                {
                                    ParameterType = ParameterType.Replace("Nullable", "Nullable[" + p.TypeReference.GenericTypes[0].ToString() + "]");
                                }

                                if (p.TypeReference.IsArrayType)
                                {
                                    ParameterType += ".ARRAY";
                                }

//                            if (ParameterType == "SortedList")
//                            {
//Console.WriteLine(p.ParameterName + "'s ParameterType = SortedList");
//                                ParameterType = ParameterType.Replace("List", "List[" +
//                                    p.TypeReference.GenericTypes[0].ToString() + "," +
//                                    p.TypeReference.GenericTypes[1].ToString() + "]");
//                                ParameterType = ParameterType.Replace("System.", String.Empty);
//                            }

                                ParameterType = ParameterType.Replace("Boolean", "bool");
                                ParameterType = ParameterType.Replace("Int32", "int");
                                ParameterType = ParameterType.Replace("Int64", "long");

                                ParameterTypes += ParameterType + ";";
                            }

                            ParameterTypes = ParameterTypes.ToUpper();
                            snippet.SetCodelet("PARAMETERTYPES", ParameterTypes);
                            return(snippet);
                        }
                        else if (attr.Name == "CheckServerAdminToken")
                        {
                            ProcessTemplate snippet         = ATemplate.GetSnippet("CHECKSERVERADMINPERMISSION");
                            string          paramdefinition = "string AServerAdminSecurityToken";

                            if (ATemplate.FCodelets["PARAMETERDEFINITION"].Length != 0)
                            {
                                paramdefinition += ", ";
                            }

                            ATemplate.AddToCodeletPrepend("PARAMETERDEFINITION", paramdefinition);
                            return(snippet);
                        }
                    }
                }
            }

            TLogging.Log("Warning !!! Missing module access permissions for " + AConnectorClassWithNamespace + "::" + m.Name);

            return(new ProcessTemplate());
        }