Exemplo n.º 1
0
        internal MethodDefinition AddNewCall(string typeName, MethodDefinition mDef, object callDef, string startMethod)
        {
            Logger.Current.Debug("AssemblyData :: AddNewCall");

            // check whether the call and the current type is valid
            if (Rules.IsValidCall(callDef, typeName, new CallRules()))
            {
                if (mDef != null)
                {
                    var mInfo = new MethodCallInfo
                                    {
                                        StartMethod = startMethod,
                                        TypeName = typeName,
                                        MethodName = CecilAssemblyHelper.CreateNormalizeMethodDefinition(mDef).ToString()
                                    };

                    mDef = callDef as MethodDefinition;

                    NormalizeMethodDefinition norm;

                    if (mDef == null)
                    {
                        var callRef = callDef as MethodReference;
                        // method reference, just add the callee, we'll search for the referenced assembly later
                        norm = CecilAssemblyHelper.CreateNormalizeMethodDefinition(callRef);
                    }
                    else
                    {
                      norm = CecilAssemblyHelper.CreateNormalizeMethodDefinition(mDef);
                    }

                    mInfo.MethodCallType = norm.DeclaringTypeFullName;
                    mInfo.MethodCallNamespace = norm.DeclaringTypeNamespace;
                    mInfo.MethodCallName = norm.ToString();
                    mInfo.TargetMethodAssembly = norm.AssemblyName;

                    // check whether the calling type is in the ignored list
                    if (Rules.IsValidType(mInfo.MethodCallType))
                    {
                        MethodCallList.Add(mInfo);

                        Logger.Current.Debug(">> Adding Method:" + mInfo);
                    }
                    else
                    {
                        Logger.Current.Debug(">> MethodCallType: " + mInfo.MethodCallType + " in ignored list");
                    }
                }
            }
            else
            {
                mDef = null;
            }

            return mDef;
        }
Exemplo n.º 2
0
    public void AddMessage(string sourceKey, string targetKey, string methodCallName, MethodCallInfo methodCallInfo)
    {
      if (string.IsNullOrEmpty(sourceKey) || string.IsNullOrEmpty(targetKey) || string.IsNullOrEmpty(methodCallName))
      {
        throw new ArgumentNullException(string.IsNullOrEmpty(sourceKey) ? "sourceKey" : string.IsNullOrEmpty(targetKey) ? "targetKey" : "typeName");
      }

      ObjectInfo sourceInfo = DiagramContext.DiagramObjects.Find(sourceKey);
      ObjectInfo targetInfo = DiagramContext.DiagramObjects.Find(targetKey);

      if (sourceInfo == null || targetInfo == null)
      {
        throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.SourceOrTargetObjectInfoNotFound, sourceInfo == null ? sourceKey : targetKey), sourceInfo == null ? "sourceKey" : "targetKey");
      }

      MessageInfo message = new MessageInfo(sourceInfo, targetInfo, methodCallName, methodCallInfo);
      DiagramContext.Messages.Add(message);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Adds the new call.
    /// </summary>
    /// <param name="typeName">Name of the type.</param>
    /// <param name="methodDefinition">The method definition.</param>
    /// <param name="callDefinition">The call definition.</param>
    /// <param name="startMethod">The start method.</param>
    /// <returns>The IMethodDeclaration based on the given call definition. This provides a means of working through the method's call stack.</returns>
    internal IMethodDeclaration AddNewCall(string typeName, IMethodDeclaration methodDefinition, object callDefinition, string startMethod)
    {
      Logger.Current.Info(typeName);
      Logger.Current.Info(methodDefinition.Name);
      Logger.Current.Info(startMethod);

      if (!Rules.IsValidCall(callDefinition, new CallRules()))
      {
        return null;
      }

      MethodCallInfo methodInfo = new MethodCallInfo();
      methodInfo.StartMethod = startMethod;
      methodInfo.TypeName = typeName;
      methodInfo.MethodName = ReflectorHelper.CreateNormalizeMethodDefinition(methodDefinition).ToString();

      methodDefinition = callDefinition as IMethodDeclaration;
      IMethodReference methodReference = callDefinition as IMethodReference;

      if (methodDefinition != null || methodReference != null)
      {
        NormalizeMethodDefinition norm = null;
        if (methodDefinition == null)
        {
          norm = ReflectorHelper.CreateNormalizeMethodDefinition(methodReference);
        }
        else
        {
          norm = ReflectorHelper.CreateNormalizeMethodDefinition(methodDefinition);
        }

        methodInfo.MethodCallType = norm.DeclaringTypeFullName;
        methodInfo.MethodCallNamespace = norm.DeclaringTypeNamespace;
        methodInfo.MethodCallName = norm.ToString();

        this.MethodCallList.Add(methodInfo);
      }

      return methodDefinition;
    }
Exemplo n.º 4
0
 public void AddMessage(MethodCallInfo methodCall)
 {
     methodList.Add(methodCall);
 }
Exemplo n.º 5
0
        private void WriteMessage(StreamWriter sw, MethodCallInfo mInfo)
        {
            // get the key
            string sourceKey = objectList.Find(
                oInfo => oInfo.TypeName.Equals(mInfo.TypeName)
                ).Key;

            string targetKey = objectList.Find(
                oInfo => oInfo.TypeName.Equals(mInfo.MethodCallType)
                ).Key;

            Write(sw, string.Format("message({0},{1}, \"{2}\");",sourceKey, targetKey, mInfo.MethodCallName));
        }