Ejemplo n.º 1
0
        private static (List<CSharpObject>, List<CSharpObject>, List<CSharpObject>) GetQueriesCommandsModels(string directory)
        {
            var solution = CSharpParser.ParseAllFiles(directory);

            foreach (var item in solution.Interfaces)
            {
                foreach (var m in item.Methods)
                {
                    var t = m.ReturnType.Resolved;
                }
            }

            var queryInterfaces = new List<CSharpObject>();
            foreach (var csInterface in solution.Interfaces)
            {
                var apiExposed = false;
                foreach (var attribute in csInterface.Attributes)
                {
                    if (attribute.Name == "ServiceBlocked" && (attribute.Arguments.Count == 0 || attribute.Arguments.Any(x => x.EndsWith("NetworkType.Api"))))
                    {
                        apiExposed = false;
                        break;
                    }
                    if (attribute.Name == "ServiceExposed" && (attribute.Arguments.Count == 0 || attribute.Arguments.Any(x => x.EndsWith("NetworkType.Api"))))
                    {
                        apiExposed = true;
                    }
                }
                if (apiExposed)
                    queryInterfaces.Add(csInterface);
            }

            var commands = new List<CSharpObject>();
            foreach (var csClass in solution.Classes)
            {
                if (csClass.Implements.Any(x => x.Name == "ICommand"))
                {
                    var apiExposed = false;
                    foreach (var attribute in csClass.Attributes)
                    {
                        if (attribute.Name == "ServiceBlocked" && (attribute.Arguments.Count == 0 || attribute.Arguments.Any(x => x.EndsWith("NetworkType.Api"))))
                        {
                            apiExposed = false;
                            break;
                        }
                        if (attribute.Name == "ServiceExposed" && (attribute.Arguments.Count == 0 || attribute.Arguments.Any(x => x.EndsWith("NetworkType.Api"))))
                        {
                            apiExposed = true;
                        }
                    }
                    if (apiExposed)
                        commands.Add(csClass);
                }
            }

            var models = new List<CSharpObject>();
            foreach (var queryInterface in queryInterfaces)
            {
                foreach (var method in queryInterface.Methods)
                {
                    var returnType = method.ReturnType.Resolved;
                    while (returnType.GenericArguments.Count == 1)
                    {
                        returnType = returnType.GenericArguments[0];
                    }
                    if (returnType.SolutionType != null)
                    {
                        if (!models.Contains(returnType.SolutionType))
                        {
                            models.Add(returnType.SolutionType);
                            AddModels(returnType.SolutionType, models);
                        }
                    }

                    foreach (var parameter in method.Parameters)
                    {
                        var parameterType = parameter.Type.Resolved;
                        if (parameterType.SolutionType != null)
                        {
                            if (!models.Contains(parameterType.SolutionType))
                            {
                                models.Add(parameterType.SolutionType);
                                AddModels(parameterType.SolutionType, models);
                            }
                        }
                    }
                }
            }
            foreach (var command in commands)
            {
                AddModels(command, models);
            }

            return (queryInterfaces, commands, models);
        }