Exemplo n.º 1
0
        private EngineMethod CreateMethodClone(EngineMethod currentMethod)
        {
            var json = JsonConvert.SerializeObject(currentMethod);

            return(JsonConvert.DeserializeObject <EngineMethod>(json));
        }
Exemplo n.º 2
0
        private string GetFormatedMethod(EngineMethod method)
        {
            var response    = method.Responses.FirstOrDefault() ?? null;
            var descBuilder = new DescritpionBuilder(Config.UseDescription)
            {
                Summary = method.Description,
                SeeAlso = method.SeeAlso,
                Param   = method.Parameters,
            };

            if (response != null)
            {
                descBuilder.Return = response.Description;
            }
            var description = descBuilder.Generate(2);
            var returnType  = "Task";

            if (response != null)
            {
                returnType = $"Task<{QlikApiUtils.GetDotNetType(response.GetRealType())}>";
                var serviceType = response.GetServiceType();
                if (serviceType != null)
                {
                    returnType = $"Task<{serviceType}>";
                }

                if (method?.Responses?.Count > 1 || !Config.UseQlikResponseLogic)
                {
                    logger.Debug($"The method {method?.Name} has {method?.Responses?.Count} responses.");
                    var resultClass = method.GetMultipleClass();
                    EngineObjects.Add(resultClass);
                    returnType = $"Task<{resultClass.Name}>";
                }
            }
            if (method.UseGeneric)
            {
                returnType = "Task<T>";
            }
            var methodBuilder = new StringBuilder();

            if (!String.IsNullOrEmpty(description))
            {
                methodBuilder.AppendLine(description);
            }
            var asyncValue = String.Empty;

            switch (Config.AsyncMode)
            {
            case AsyncMode.NONE:
                asyncValue = String.Empty;
                break;

            case AsyncMode.SHOW:
                asyncValue = "Async";
                break;

            default:
                asyncValue = String.Empty;
                break;
            }
            var cancellationToken = String.Empty;
            var parameter         = new StringBuilder();

            if (method.Parameters.Count > 0)
            {
                //Sort parameters by required
                var parameters = method.Parameters.OrderBy(p => p.Required == false);
                foreach (var para in parameters)
                {
                    var defaultValue = String.Empty;
                    if (!para.Required)
                    {
                        defaultValue = $" = {QlikApiUtils.GetDefaultValue(para.Type, para.Default)}";
                    }
                    parameter.Append($"{QlikApiUtils.GetDotNetType(para.Type)} {para.Name}{defaultValue}, ");
                }
            }
            var parameterValue = parameter.ToString().TrimEnd().TrimEnd(',');

            if (Config.GenerateCancelationToken)
            {
                if (String.IsNullOrEmpty(parameterValue.Trim()))
                {
                    cancellationToken = "CancellationToken? token = null";
                }
                else
                {
                    cancellationToken = ", CancellationToken? token = null";
                }
            }
            if (method.Deprecated)
            {
                methodBuilder.AppendLine(QlikApiUtils.Indented("[ObsoleteAttribute]", 2));
            }
            var tvalue = String.Empty;

            if (method.UseGeneric)
            {
                tvalue = "<T>";
            }
            methodBuilder.AppendLine(QlikApiUtils.Indented($"{returnType} {method.Name}{asyncValue}{tvalue}({parameterValue}{cancellationToken});", 2));
            return(methodBuilder.ToString());
        }