Ejemplo n.º 1
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("CHECKUSERMODULEPERMISSIONS");
                            snippet.SetCodelet("METHODNAME", m.Name);
                            snippet.SetCodelet("CONNECTORWITHNAMESPACE", AConnectorClassWithNamespace);
                            snippet.SetCodelet("LEDGERNUMBER", "");

                            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")
                                {
                                    ParameterType = ParameterType.Replace("Dictionary", "Dictionary[" +
                                        p.TypeReference.GenericTypes[0].ToString() + "," +
                                        p.TypeReference.GenericTypes[1].ToString() + "]");
                                    ParameterType = ParameterType.Replace("System.", String.Empty);
                                }

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