public void RunRequestProperty() { var methodStructure = new MethodStructure { URL = "/API/Person", Name = "Put", Result = new TypeStructure { IsSytemType = false, IsArray = true, TypeName = "AddPersonResult", }, Parameters = new List <TypeStructure> { new TypeStructure { Name = "Id", IsSytemType = true, Type = typeof(int), Attributes = new Dictionary <string, Attribute> { } }, new TypeStructure { Name = "Details", IsSytemType = false, TypeName = "PersonDetails", Attributes = new Dictionary <string, Attribute> { { "FromBodyAttribute", new IgnoreAttribute() } } } }, Attributes = new Dictionary <string, Attribute> { { "HttpPutAttribute", new IgnoreAttribute() } } }; var jsCode = ((JSRenderble)DI.Get <IRunRequestProperty>(methodStructure)).GetText(); Assert.AreEqual(jsCode, "this._PutById = new request(this.baseUrl,\"/API/Person\",\"PUT\",{Id:\"QUERY\",Details:\"BODY\"}, AddPersonResult);\r\n"); }
public void RunRequestMethodComment() { var methodStructure = new MethodStructure { URL = "/Person/Add", Result = new TypeStructure { IsSytemType = false, IsArray = true, TypeName = "AddPersonResult", }, Parameters = new List <TypeStructure> { new TypeStructure { Name = "Id", IsSytemType = true, Type = typeof(int) }, new TypeStructure { Name = "Name", IsSytemType = true, Type = typeof(string) }, new TypeStructure { Name = "DateOfBirth", IsSytemType = true, Type = typeof(DateTime) }, new TypeStructure { Name = "Details", IsSytemType = false, TypeName = "PersonDetails" } }, Attributes = new Dictionary <string, Attribute> { { "HttpPostAttribute", new IgnoreAttribute() } } }; var jsCode = ((JSRenderble)DI.Get <IRunRequestMethodComment>(methodStructure)).GetText(); Assert.AreEqual(jsCode, " /**\r\n * Method used to invoke request of type: POST to URL: /Person/Add.\r\n * @param { Number } Id\r\n * @param { String } Name\r\n * @param { Date } DateOfBirth\r\n * @param { PersonDetails } Details\r\n * @return {PromiseLike<AddPersonResult[]>}\r\n*/"); }
public void RunMethodRequest() { var methodStructure = new MethodStructure { URL = "/API/Person", Name = "Put", Result = new TypeStructure { IsSytemType = false, IsArray = true, TypeName = "AddPersonResult", }, Parameters = new List <TypeStructure> { new TypeStructure { Name = "Id", IsSytemType = true, Type = typeof(int), Attributes = new Dictionary <string, Attribute> { } }, new TypeStructure { Name = "Details", IsSytemType = false, TypeName = "PersonDetails", Attributes = new Dictionary <string, Attribute> { { "FromBodyAttribute", new IgnoreAttribute() } } } }, Attributes = new Dictionary <string, Attribute> { { "HttpPutAttribute", new IgnoreAttribute() } } }; var jsCode = ((JSRenderble)DI.Get <IRunRequestMethod>(methodStructure, "")).GetText(); Assert.AreEqual(jsCode, " /**\r\n * Method used to invoke request of type: PUT to URL: /API/Person.\r\n * @param { Number } Id\r\n * @param { PersonDetails } Details\r\n * @return {PromiseLike<AddPersonResult[]>}\r\n*/\r\n PutById (Id,Details)\r\n {\r\n return this._PutById.ExecuteRequest({Id:Id,Details:Details});\r\n }\r\n"); }
public static string GetHTTPMethod(MethodStructure methodStructure) { return(methodStructure.Attributes.ContainsKey("HttpPostAttribute") ? "POST" : methodStructure.Attributes.ContainsKey("HttpPutAttribute") ? "PUT" : methodStructure.Attributes.ContainsKey("HttpDeleteAttribute") ? "DELETE" : methodStructure.Attributes.ContainsKey("HttpPatchAttribute") ? "PATCH" : "GET"); }
private void handleMethod(List <IJSProperty> properties, bool isRPCMode, MethodStructure method) { method.IsRPC = isRPCMode; properties.Add(JSBuilderIOCContainer.Instance.CreatePropertyFromMethod(method)); ((List <IRenderble>)Methods).Add((IRenderble)JSBuilderIOCContainer.Instance.CreateRunMethodRequestFromMethod(method)); buildResultTypeImports(method); buildParameterTypeImports(method); }
private void buildResultTypeImports(MethodStructure method) { if (!method.Result.IsSytemType && !Imports.Any(x => x.Modules.Any(m => m == method.Result.TypeName)) && method.Result.TypeName != null) { var import = JSBuilderIOCContainer.Instance.CreateImport(); ((List <String>)import.Modules).Add(method.Result.TypeName); import.URL = $"./{Configuration.Instance.ModelsFolder}/{method.Result.TypeName}.js"; ((List <IImport>)Imports).Add(import); } }
public RunRequestProperty(MethodStructure methodStructure) : base("RunRequestProperty") { tagValues = new Dictionary <string, string> { { nameTag, methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure) }, { urlTag, methodStructure.URL }, { methodTag, HttpHelpers.GetHTTPMethod(methodStructure) }, { parameterSourceBindingTag, HttpHelpers.GetRequestParametersSourceObject(methodStructure) }, { resultTypeTag, !methodStructure.Result.IsSytemType && methodStructure.Result.TypeName != null?Configuration.Instance.ModelsNameFactory(methodStructure.Result.TypeName) : "null" } }; }
public RunMethodRequest(MethodStructure methodStructure, string name) : base("RunMethodRequest") { tagValues = new Dictionary <string, string> { { controllerNameTag, name }, { nameTag, methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure) }, { parameterTag, methodStructure.Parameters.GetCSV(x => x.Name) }, { requestObjectTag, methodStructure.Parameters.GetCSV(x => $"{x.Name}:{x.Name}") } }; childRenderbles.Add((JSRenderble)DI.Get <IRunRequestMethodComment>(methodStructure)); }
private void createPropertyAssignable(MethodStructure methodStructure) { Assignable = JSBuilderIOCContainer.Instance.CreateAssignable(); Assignable.NewInstanceParamters = new List <string> { "this._baseUrl", $"\"{methodStructure.URL}\"", $"\"{HttpHelpers.GetHTTPMethod(methodStructure)}\"", getRequestParametersSourceObject(methodStructure), !methodStructure.Result.IsSytemType && methodStructure.Result.TypeName != null ? methodStructure.Result.TypeName : "null" }; Assignable.NewInstanceType = "request"; }
public RunMethodRequest(MethodStructure methodStructure) : base(Resources.runRequestMethod) { Name = methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure); Comment = JSBuilderIOCContainer.Instance.CreateComment(); Comment.Description = $"Method to invoke request to {methodStructure.URL}. Method: {HttpHelpers.GetHTTPMethod(methodStructure)}."; Comment.Params = methodStructure.Parameters.ToDictionary(k => k.Name, v => JSTypeMapping.GetJSType(v)); Comment.ReturnType = JSTypeMapping.GetJSType(methodStructure.Result); Comment.ReturnType.IsPromise = true; Parameters = methodStructure.Parameters.Select(x => x.Name).ToList(); }
public static string GetRestfullMethodName(MethodStructure methodStructure) { var parameters = methodStructure.Parameters.Where(x => !x.Attributes.ContainsKey("FromBodyAttribute")); if (parameters.Count() > 0) { return($"{methodStructure.Name}{"By" + parameters.Select(x => x.Name.Substring(0, 1).ToUpper() + x.Name.Substring(1)).Aggregate((a, b) => a + "And" + b)}"); } else { return(methodStructure.Name); } }
private void buildParameterTypeImports(MethodStructure method) { foreach (var parameter in method.Parameters) { if (!parameter.IsSytemType && !Imports.Any(x => x.Modules.Any(m => m == parameter.TypeName))) { var import = JSBuilderIOCContainer.Instance.CreateImport(); ((List <String>)import.Modules).Add(parameter.TypeName); import.URL = $"./{Configuration.Instance.ModelsFolder}/{parameter.TypeName}.js"; ((List <IImport>)Imports).Add(import); } } }
public RunRequestMethodComment(MethodStructure methodStructure) : base("RunRequestMethodComment") { tagValues = new Dictionary <string, string> { { descriptionTag, Configuration.Instance.Comments.RequestMethod(HttpHelpers.GetHTTPMethod(methodStructure), methodStructure.URL) }, { resultTypeTag, JSTypeMapping.GetJSType(methodStructure.Result, true).JSTypeDef } }; multiplyTags(methodStructure.Parameters.Count, ((JSRenderble)DI.Get <IParameterTypeComment>()).Name); methodStructure.Parameters.ForEach(parameter => childRenderbles.Add((JSRenderble)DI.Get <IParameterTypeComment>(JSTypeMapping.GetJSType(parameter), parameter.Name)) ); }
private MethodStructure getMethodStructureInstance <T>(MethodInfo action, ClassStructure classStructure, ClassContainter <T> classContainter) { var actionURL = action.GetCustomAttribute <HttpMethodAttribute>()?.Template ?? null; var newMethod = new MethodStructure { Attributes = filterAndMapAttributesToDictionary(action.GetCustomAttributes(), classContainter), Name = action.Name, URL = classStructure.URL.Replace("[controller]", classStructure.Name).Replace("[action]", action.Name) + ((actionURL != null) ? $"/{actionURL}" : "") }; classStructure.Methods.Add(newMethod); return(newMethod); }
public void travelAction <T>(MethodInfo action, ClassStructure classStructure, ClassContainter <T> classContainter) { if (shouldMethodBeExcluded(action, classContainter) || shouldMethodBeIncluded(action, classContainter)) { return; } MethodStructure newMethod = getMethodStructureInstance(action, classStructure, classContainter); populateParameters(action, classContainter, newMethod); var resultTypeStructure = new TypeStructure(); travelResult <T>(action.ReturnType, resultTypeStructure, classContainter); newMethod.Result = new TypeStructure(resultTypeStructure); }
public void travelParamters <T>(ParameterInfo parameter, MethodStructure method, ClassContainter <T> classContainter) { if (shouldExcludeParameter(parameter, classContainter) || shouldIncludeParamter(parameter, classContainter)) { return; } var objectType = GetItemType(parameter.ParameterType); TypeStructure parameterStructure = getNewTypeStructuree <T>(classContainter, parameter, method, objectType); if (shouldProcessParameter(objectType, parameterStructure)) { var properties = parameter.ParameterType.GetProperties(propertyBindingFlags).ToList(); properties.ForEach(property => travelObject(property, parameterStructure, classContainter)); } }
public MethodNode(MethodStructure codeStructure, BasicNodeStructure structure, RectangleRenderElementStyle border_style) : base(new PropertyStructure(codeStructure.Position, codeStructure.Name, codeStructure.Type, codeStructure.AccessModifier, codeStructure.Modifier), structure, border_style) { CodeStructure = codeStructure; LeftBracket = new LabelNode(new BasicTextNodeStructure(Position + new Vector(AccessModifierButton.Width + NameTextBox.Width, 0), Renderer.SingleTextWidth, Height, "("), TextRenderElementStyle.Default, RectangleRenderElementStyle.Textbox); string argum = codeStructure.Arguments; ArgumentsTextBox = new TextBoxNode(new BasicTextNodeStructure(Position + new Vector(AccessModifierButton.Width + NameTextBox.Width + LeftBracket.Width, 0), Renderer.GetTextWidth(argum.Length), Height, argum), TextRenderElementStyle.Default, RectangleRenderElementStyle.Textbox); RightBracket = new LabelNode(new BasicTextNodeStructure(Position + new Vector(NameTextBox.Width + AccessModifierButton.Width + ArgumentsTextBox.Width + LeftBracket.Width, 0), Renderer.SingleTextWidth, Height, ")"), TextRenderElementStyle.Default, RectangleRenderElementStyle.Textbox); Children.Add(LeftBracket); Children.Add(RightBracket); Children.Add(ArgumentsTextBox); GenerateMenu(); GenerateOptions(); }
public DrawerTestFixture(string sourceCode, string className, string methodName) { var syntaxTree = CSharpSyntaxTree.ParseText(sourceCode); var syntaxRoot = syntaxTree.GetCompilationUnitRoot(); var ns = syntaxRoot.Members.OfType <NamespaceDeclarationSyntax>().FirstOrDefault(); var classes = ns.Members.OfType <ClassDeclarationSyntax>().FirstOrDefault(); var usings = syntaxRoot.Members.OfType <UsingDirectiveSyntax>().ToArray(); var references = Mock.Of <List <MetadataReference> >(); var classStructure = new ClassStructure(classes, ns, references, usings, "test", "memory"); classStructure.ParseClass(); MethodDeclaration = classes.Members.OfType <MethodDeclarationSyntax>() .Where(m => m.Identifier.ToString().Contains(methodName)).FirstOrDefault(); var methodStructure = new MethodStructure(classStructure, MethodDeclaration); var analyzedClasses = Mock.Of <IDictionary <string, IClassStructure> >(); Mock.Get(analyzedClasses).Setup(d => d[It.IsAny <string>()]).Returns(classStructure); var interfaceResolver = Mock.Of <IInterfaceResolver>(); DiagramGenerator = new SequenceDiagramGenerator(analyzedClasses, interfaceResolver, null); }
private void setPropertyName(MethodStructure methodStructure) { Name = $"_{(methodStructure.IsRPC ? methodStructure.Name : NamingHelpers.GetRestfullMethodName(methodStructure))}"; }
private static string getSourceParameters(MethodStructure methodStructure, TypeStructure typeStructure) { return($"{typeStructure.Name}:{(typeStructure.Attributes.ContainsKey("FromBodyAttribute") ? "\"BODY\"" : methodStructure.URL.Contains($"{{{typeStructure.Name}}}") ? "\"URL\"" : "\"QUERY\"")}");
private void travelObject(PropertyInfo objectType, TypeStructure typeStructure, ClassContainter classContainter, MethodStructure method, int depth) { depth++; if (depth > classContainter.recursionConfiguration.MaxRecursiveDepth) { throw new Exception($"WillCore.Requests reflection has encountered a method parameter that exceeds the max recursive depth of {classContainter.recursionConfiguration.MaxRecursiveDepth}. This happened on method {method.Name} and type {typeStructure.TypeName}. " + $"Please check the class depth or increase the default maximum recursive depth of WillCore.Requests."); } var type = GetItemType(objectType.PropertyType); TypeStructure newTypeStructure = getNewTypeStructure(objectType, type, classContainter); if (!type.IsSystem && !classContainter.Models.ContainsKey(newTypeStructure.TypeName)) { classContainter.Models[newTypeStructure.TypeName] = newTypeStructure; foreach (var property in type.Type.GetProperties(propertyBindingFlags)) { travelObject(property, newTypeStructure, classContainter, method, depth); } } typeStructure.Properties.Add(new TypeStructure(newTypeStructure)); }
private void populateParameters <T>(MethodInfo action, ClassContainter <T> classContainter, MethodStructure newMethod) { foreach (var parameter in action.GetParameters()) { travelParamters <T>(parameter, newMethod, classContainter); } }
public static string GetRequestParametersSourceObject(MethodStructure methodStructure) { return(methodStructure.Parameters.Any() ? "{" + methodStructure.Parameters.Select(x => getSourceParameters(methodStructure, x)).Aggregate((a, b) => a + "," + b) + "}" : "{}"); }
public MethodGenerator(MethodStructure structure) { Structure = structure; GenerateLines(); }
private TypeStructure getNewTypeStructuree <T>(ClassContainter <T> classContainter, ParameterInfo parameter, MethodStructure method, Models.ItemType objectType) { var paramterStructure = new TypeStructure { Attributes = filterAndMapAttributesToDictionary(parameter.GetCustomAttributes(), classContainter), IsSytemType = objectType.IsSystem, Name = parameter.Name, Type = objectType.Type, TypeName = objectType.Type.Name, IsArray = objectType.Type.IsArray }; method.Parameters.Add(new TypeStructure(paramterStructure)); if (!paramterStructure.IsSytemType && !classContainter.Models.ContainsKey(paramterStructure.TypeName)) { classContainter.Models[paramterStructure.TypeName] = paramterStructure; } return(paramterStructure); }
public JSProperty(MethodStructure methodStructure) : base(Resources.property) { createPropertyComment(methodStructure); setPropertyName(methodStructure); createPropertyAssignable(methodStructure); }
public void travelResult(Type type, TypeStructure typeStructure, ClassContainter container, MethodStructure method, int depth) { var objectType = GetItemType(type); typeStructure.IsArray = objectType.IsArray; typeStructure.IsSytemType = objectType.IsSystem; typeStructure.Type = objectType.Type; typeStructure.TypeName = objectType.Type.Name; depth++; if (depth > container.recursionConfiguration.MaxRecursiveDepth) { throw new Exception($"WillCore.Requests reflection has encountered a method result that exceeds the max recursive depth of {container.recursionConfiguration.MaxRecursiveDepth}. This happened on method {method.Name} and type {typeStructure.TypeName}. " + $"Please check the class depth or increase the default maximum recursive depth of WillCore.Requests."); } if (type == typeof(void)) { return; } ; if (!objectType.IsSystem && AppDomain.CurrentDomain.GetAssemblies().Contains(objectType.Type.Assembly)) { foreach (var property in typeStructure.Type.GetProperties(propertyBindingFlags)) { var propertyName = ResultCamelCase ? $"{property.Name.Substring(0, 1).ToLower()}{(property.Name.Length > 1 ? property.Name.Substring(1) : "")}" : property.Name; var newTypeStructure = new TypeStructure { Name = propertyName, Attributes = property.GetCustomAttributes().ToDictionary(a => a.GetType().Name, b => b) }; travelResult(property.PropertyType, newTypeStructure, container, method, depth); typeStructure.Properties.Add(new TypeStructure(newTypeStructure)); } if (!container.Models.ContainsKey(typeStructure.TypeName)) { container.Models[typeStructure.TypeName] = typeStructure; } } }
private void createPropertyComment(MethodStructure methodStructure) { Comment = JSBuilderIOCContainer.Instance.CreateComment(); Comment.Description = $"Reqeust {methodStructure.URL}"; }