private void ConnectGenericMethodParameters(NetMethod method)
 {
     foreach (var param in method.GenericParameters)
     {
         _tx.CreateRelationship(method, param, Relationship.DEFINES_GENERIC_METHOD_ARG);
     }
 }
Exemplo n.º 2
0
 private void ConnectGenericMethodParameters(NetMethod method, IGraphDatabaseTransaction tx)
 {
     foreach (var param in method.GenericParameters)
     {
         tx.CreateRelationship(method, param, Relationship.DEFINES_GENERIC_METHOD_ARG);
     }
 }
 private IReadOnlyList <NetMethodParameter> CreateParameters(
     MethodDefinition method,
     NetMethod methodModel)
 {
     return(method.Parameters
            .Select(param => CreateParameter(method, param, methodModel))
            .ToList());
 }
        private void ConnectMethod(NetType type, NetMethod method)
        {
            _tx.CreateRelationship(type, method, Relationship.DEFINES_METHOD);
            _tx.CreateRelationship(method, method.ReturnType, Relationship.RETURNS);

            ConnectMethodParameters(method);
            ConnectGenericMethodParameters(method);
        }
Exemplo n.º 5
0
 public ClientMethod(ClientComponent parent, NetMethod method)
 {
     this.parent        = parent;
     this.name          = method.name;
     this.returnTypeRaw = method.returnTypeRaw;
     this.returnType    = method.returnType;
     this.argumentTypes = method.argumentTypes;
     this.argumentNames = method.argumentNames;
 }
Exemplo n.º 6
0
        private void PrepareMethodForCallCount(NetMethod method)
        {
            MethodDefinition CecilType = (MethodDefinition)method.Tag;
            BodyWorker       worker    = new BodyWorker(CecilType.Body);

            Instruction beforeIns    = CecilType.Body.Instructions[0];
            Instruction afterIns     = worker.InsertBefore(beforeIns, worker.Create(OpCodes.Ldc_I4, method.Handle));
            Instruction instruction4 = worker.AppendAfter(afterIns, worker.Create(OpCodes.Ldc_I4, Project.Settings.BuildKey));

            worker.AppendAfter(instruction4, worker.Create(OpCodes.Call, _Context.StartEndMethodRef));
            worker.Done();
        }
Exemplo n.º 7
0
        private void ConnectMethod(NetType type, NetMethod method, IGraphDatabaseTransaction tx)
        {
            tx.CreateRelationship(type, method, Relationship.DEFINES_METHOD);
            tx.CreateRelationship(method, method.ReturnType, Relationship.RETURNS);

            ConnectMethodParameters(method, tx);
            ConnectGenericMethodParameters(method, tx);

            ConnectAnalyzerExtensionValues(method, method.Exports, Relationship.EXPORTS, tx);
            ConnectAnalyzerExtensionValues(method, method.Imports, Relationship.IMPORTS, tx);
            ConnectAnalyzerExtensionValues(method, method.TypesUsedInBody, Relationship.HAS_TYPE, tx);
        }
Exemplo n.º 8
0
 public virtual TsFunction GetTsFunction(NetMethod netMethod)
 {
     return(new TsFunction
     {
         IsConstructor = netMethod.IsConstructor,
         IsPublic = netMethod.IsPublic,
         IsStatic = netMethod.IsStatic,
         Name = GetTsName(netMethod.Name),
         Parameters = netMethod.Parameters.Select(GetTsParameter).ToList(),
         ReturnType = GetTsType(netMethod.ReturnType)
     });
 }
        private NetMethodParameter CreateParameter(
            MethodDefinition method,
            ParameterDefinition param,
            NetMethod methodModel)
        {
            var model = Factory.CreateMethodParameter(method, param);

            model.Order           = param.Sequence;
            model.Type            = GetTypeFromTypeReference(param.ParameterType);
            model.DeclaringMethod = methodModel;

            return(model);
        }
Exemplo n.º 10
0
        private NetMethodParameter CreateParameter(
            MethodDefinition method,
            ParameterDefinition param,
            NetMethod methodModel)
        {
            var model = Factory.CreateMethodParameter(method, param);

            model.Order           = param.Sequence;
            model.Type            = GetTypeFromTypeReference(param.ParameterType);
            model.DeclaringMethod = methodModel;
            model.Imports         = GetMefUsedInterfacesFromMethodParameter(param, nameof(AttributeType.Import));
            model.Exports         = GetMefUsedInterfacesFromMethodParameter(param, nameof(AttributeType.Export));

            return(model);
        }
        private void ConnectMethodParameters(NetMethod method)
        {
            foreach (var param in method.Parameters)
            {
                _tx.CreateRelationship(
                    method,
                    param,
                    Relationship.DEFINES_PARAMETER);

                _tx.CreateRelationship(
                    param,
                    param.Type,
                    Relationship.HAS_TYPE);
            }
        }
Exemplo n.º 12
0
        private void ConnectMethod(NetType type, NetMethod method)
        {
            _db.CreateRelationship(type, method, Relationship.DEFINES_METHOD);
            _db.CreateRelationship(method, method.ReturnType, Relationship.RETURNS);

            var order = 0;

            foreach (var param in method.ParameterTypes)
            {
                var rel = new HasParameterRelationship {
                    Order = order++
                };
                _db.CreateRelationship(method, param, Relationship.HAS_PARAMETER, rel);
            }
        }
Exemplo n.º 13
0
        public static NetMethod GetNetMethod(MethodDeclarationSyntax methodDeclaration)
        {
            var item = new NetMethod
            {
                Name          = methodDeclaration.Identifier.ToString(),
                Attributes    = GetAttributeList(methodDeclaration.AttributeLists),
                IsConstructor = false, //constructor declarations are separate type of syntax
                IsStatic      = IsStatic(methodDeclaration.Modifiers),
                IsPublic      = IsPublic(methodDeclaration.Modifiers),
                Parameters    = methodDeclaration.ParameterList.Parameters.Select(GetParameter).ToList(),
                ReturnType    = GetType(methodDeclaration.ReturnType)
            };

            return(item);
        }
Exemplo n.º 14
0
        private void ConnectMethodParameters(NetMethod method, IGraphDatabaseTransaction tx)
        {
            foreach (var param in method.Parameters)
            {
                tx.CreateRelationship(
                    method,
                    param,
                    Relationship.DEFINES_PARAMETER);

                tx.CreateRelationship(
                    param,
                    param.Type,
                    Relationship.HAS_TYPE);
            }
        }
Exemplo n.º 15
0
        private NetFieldDeclaration GetUrlNavigateConstFieldDeclaration(NetMethod netMethod, NetClass controllerNetClass)
        {
            var route = GetRouteInfo(controllerNetClass, netMethod);

            var a = new NetFieldDeclaration
            {
                DefaultValue         = "\"" + route.Url + "\"",
                FieldDeclarationType = NetFieldDeclarationType.Const,
                FieldType            = new NetType {
                    Name = "string"
                },
                IsPublic = true,
                Name     = netMethod.Name + "Url"
            };

            return(a);
        }
Exemplo n.º 16
0
        public virtual string WriteMethod(NetMethod netMethod)
        {
            var funParams     = string.Join(", ", netMethod.Parameters.Select(p => WriteField(p)));
            var returnTypeStr = WriteTypeName(netMethod.ReturnType);
            var returnType    = string.IsNullOrWhiteSpace(returnTypeStr) ? "void" : returnTypeStr;

            var    exportStr      = !netMethod.IsPublic ? "private " : "public ";
            var    staticStr      = netMethod.IsStatic ? "static " : "";
            string accessModifier = $"{exportStr}{staticStr}";

            var body = netMethod.MethodBody;

            return($"{accessModifier}{returnType} {netMethod.Name}({funParams})" + _config.NewLine +
                   @"{" + _config.NewLine +
                   $@"{body.Indent(_indent)}" + _config.NewLine +
                   @"}");
            //TODO: if body is null then we should only render a method signature?
        }
Exemplo n.º 17
0
        //TODO: no route info classes for now
        //        public NetFieldDeclaration GetRouteDataFieldDeclaration(NetMethod netMethod, NetClass controllerNetClass)
        //        {
        //            var route = GetRouteInfo(controllerNetClass, netMethod);

        //            var a = new NetFieldDeclaration
        //            {
        //                DefaultValue =
        //$@"{{
        //    baseUrl: '/',
        //    controller: '{route.Controller}',
        //    action: '{route.Action}'
        //}}",
        //                FieldDeclarationType = NetFieldDeclarationType.Const,
        //                FieldType = new NetType { Name = "IRouteData" },
        //                IsStatic = true,
        //                Name = netMethod.Name + "Route"
        //            };
        //            return a;
        //        }

        private RouteInfo GetRouteInfo(NetClass controllerNetClass, NetMethod netMethod)
        {
            var controllerName = GetControllerName(controllerNetClass.Name);
            var actionName     = netMethod.Name;
            var routeInfo      = controllerNetClass.Attributes.FirstOrDefault(attr => attr.StartsWith("Route"));

            if (string.IsNullOrWhiteSpace(routeInfo))
            {
                routeInfo = "[controller]/[action]";
            }
            else
            {
                var m = Regex.Match(routeInfo, "\"(.*?)\"");

                if (m.Success && m.Groups.Count > 1 && m.Groups[1].Success)
                {
                    routeInfo = m.Groups[1].Value;
                }
            }

            var route = routeInfo
                        .Replace("[controller]", controllerName)
                        .Replace("[action]", actionName);

            if (!route.StartsWith("/"))
            {
                route = "/" + route;
            }

            return(new RouteInfo
            {
                Url = route,
                Controller = controllerName,
                Action = actionName
            });
        }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="method"></param>
        /// <param name="rtmodule"></param>
        private void PrepareMethod(AssemblyDefinition assembly, NetMethod method)
        {
            Tracer.Verbose("InjectionProfiler.PrepareMethod START ", method.Name);

            // no profiling on this method
            if (MustSkipMethod((MethodDefinition)method.Tag))
            {
                return;
            }

            //trace the number of call in methods
            if (Project.Settings.Action == ProfilMode.CallCount)
            {
                PrepareMethodForCallCount(method);
            }

            //trace for performance
            if (Project.Settings.Action == ProfilMode.TimeSpent)
            {
                PrepareMethodForTiming(assembly, method);
            }

            Tracer.Verbose("InjectionProfiler.PrepareMethod END ", method.Name);
        }
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (value.ToString() == "FolderGroup")
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/references.png")));
            }

            if (value.GetType() == typeof(NetAssembly))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/assembly.png")));
            }

            if (value.GetType() == typeof(NetReference))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/assembly.png")));
            }
            if (value.GetType() == typeof(NetNamespace))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/namespace.png")));
            }

            if (value.GetType() == typeof(NetClass))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/class.png")));
            }
            if (value.GetType() == typeof(NetInterface))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/interfaces.png")));
            }
            if (value.GetType() == typeof(NetEnum))
            {
                return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/enum.png")));
            }


            if (value.GetType() == typeof(NetMethod))
            {
                NetMethod method = value as NetMethod;

                if (method.Tag.GetType().ToString() == "System.Reflection.RuntimeConstructorInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/constructor.png")));
                }

                if (method.Tag.GetType().ToString() == "System.Reflection.RuntimeMethodInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/method.png")));
                }

                if (method.Tag.GetType().ToString() == "System.Reflection.RuntimePropertyInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/properties.png")));
                }

                if (method.Tag.GetType().ToString() == "System.Reflection.RtFieldInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/member.png")));
                }

                if (method.Tag.GetType().ToString() == "System.Reflection.MdFieldInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/member.png")));
                }

                if (method.Tag.GetType().ToString() == "System.Reflection.RuntimeEventInfo")
                {
                    return(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/16x16/assembly/event.png")));
                }
            }
            return(null);
        }
Exemplo n.º 20
0
        private void PrepareMethodForTiming(AssemblyDefinition assembly, NetMethod method)
        {
            MethodDefinition CecilType = (MethodDefinition)method.Tag;
            MethodBody       body      = CecilType.Body;

            BodyWorker bw = new BodyWorker(body);

            VariableDefinition definition = null;

            if (CecilType.ReturnType.ReturnType != assembly.MainModule.TypeReferences["System.Void"])
            {
                definition = new VariableDefinition(CecilType.ReturnType.ReturnType);
                body.Variables.Add(definition);
            }

            Instruction instruction6 = null;
            Instruction instruction7 = body.Instructions[0];
            Instruction instruction8 = bw.InsertBefore(instruction7, bw.Create(OpCodes.Ldc_I4, method.Handle));
            Instruction instruction9 = bw.AppendAfter(instruction8, bw.Create(OpCodes.Ldc_I4, Project.Settings.BuildKey));

            bw.AppendAfter(instruction9, bw.Create(OpCodes.Call, _Context.StartMethodRef));

            Instruction instruction10 = bw.OriginalInstructions[bw.OriginalInstructions.Count - 1];
            Instruction instruction11 = bw.AppendAfter(instruction10, bw.Create(OpCodes.Call, _Context.EndMethodRef));
            Instruction instruction12 = bw.AppendAfter(instruction11, bw.Create(OpCodes.Endfinally));
            Instruction outside       = body.Instructions.Outside;

            //gestion des methodes de debut/fin ?
            // TODO

            foreach (Instruction original in bw.OriginalInstructions)
            {
                Instruction instruction15;

                if (!(original.OpCode == OpCodes.Ret) || (original == instruction6))
                {
                    continue;
                }

                //return type exist
                if (definition != null)
                {
                    //return the value
                    instruction15 = bw.AppendAfter(instruction12, bw.Create(OpCodes.Ldloc, definition));
                    bw.AppendAfter(instruction15, bw.Create(OpCodes.Ret));
                }
                else
                {
                    //else quit
                    instruction15 = bw.AppendAfter(instruction12, bw.Create(OpCodes.Ret));
                }

                foreach (Instruction instruction16 in bw.OriginalInstructions)
                {
                    if ((instruction16.OpCode == OpCodes.Ret) && (instruction16 != instruction6))
                    {
                        if (definition != null)
                        {
                            Instruction instruction17 = bw.Replace(instruction16, bw.Create(OpCodes.Stloc, definition));
                            bw.AppendAfter(instruction17, bw.Create(OpCodes.Leave, instruction15));
                        }
                        else
                        {
                            bw.Replace(instruction16, bw.Create(OpCodes.Leave, instruction15));
                        }
                    }
                }
                outside = instruction15;
                break;
            }
            bw.RemapBodyOutside(instruction11);

            bw.Done();

            //define the exception handling arround the existing code
            ExceptionHandler handler = new ExceptionHandler(ExceptionHandlerType.Finally)
            {
                TryStart     = instruction7,
                TryEnd       = instruction11,
                HandlerStart = instruction11,
                HandlerEnd   = outside
            };

            body.ExceptionHandlers.Add(handler);

            //if return type, be sure that variables are initialized
            if (definition != null)
            {
                body.InitLocals = true;
            }
        }
Exemplo n.º 21
0
        private NetMethod GetCsProxy(NetMethod controllerMethod, string controllerName)
        {
            var csProxy = new NetMethod
            {
                ReturnType = new NetType
                {
                    Name = "RestRequestAsyncHandle"
                },
                Name     = controllerMethod.Name,
                IsPublic = true
            };

            //get HTTP verb from controller attributes if present. Default to Post
            var actionType = controllerMethod.Attributes.Any(attr => attr.Contains("HttpGet")) ? "GET" : "POST";

            actionType = controllerMethod.Attributes.Any(attr => attr.Contains("HttpPost")) ? "POST" : actionType;

            //gets the param names from controller
            var dataParametersString = string.Join(",\r\n", controllerMethod.Parameters.Select(p => $"{p.Name}"));

            //these are value params
            csProxy.Parameters = controllerMethod.Parameters.Select(p => new NetParameter
            {
                Name      = p.Name,
                FieldType = new NetType
                {
                    Name = p.FieldType.Name
                }
            }).ToList();

            csProxy.Parameters.Add(new NetParameter
            {
                //Action<IRestResponse<{functionReturnType}>>
                FieldType = new NetType
                {
                    Name = "Action",
                    GenericParameters = new[] {
                        new NetGenericParameter
                        {
                            Name = "IRestResponse",
                            NetGenericParameters = controllerMethod.ReturnType.Name == "void" ? null : new[]
                            {
                                new NetGenericParameter(controllerMethod.ReturnType)
                            }
                        }
                    }

                    //Name = $"Action<IRestResponse<{functionReturnType}>>"
                },
                Name = "callback"
            });

            csProxy.MethodBody =
                @"return ServiceFramework.FrameworkExec(
    baseUrl: _baseUrl,
	url: "     + $"{csProxy.Name}Url" + @",
	data: new {
" + dataParametersString.Indent("\t\t") + @"
	},
	method: Method."     + actionType + @",
	callback: callback
);";

            return(csProxy);
        }