示例#1
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);
    }
示例#2
0
 /// <summary>
 /// Create a DiagramNode.
 /// </summary>
 /// <param name="messageInfo">The message info.</param>
 /// <returns>The newly created DiagramNode.</returns>
 private static DiagramNode CreateNode(MessageInfo messageInfo)
 {
   DiagramNode node = new DiagramSequenceNode();
   node.MessageInfo = messageInfo;
   node.NodeType = NodeType.MessageInfo;
   return node;
 }
示例#3
0
    /// <summary>
    /// Creates the message row.
    /// </summary>
    /// <param name="messageInfo">The message info.</param>
    /// <returns>A new message row.</returns>
    internal DiagramRow CreateSequenceMessageRow(MessageInfo messageInfo)
    {
      DiagramGroup group = new DiagramGroup();

      // Set up the row.
      DiagramRow row = new DiagramRow();
      DiagramConnectorNode sourceConnector = null;
      DiagramConnectorNode targetConnector = null;

      foreach (DiagramConnectorNode connectorNode in this.ObjectInfoLookup.Values)
      {
        DiagramNode node = CreateNode(messageInfo);
        if (messageInfo != null &&
          (connectorNode.Node.ObjectInfo == messageInfo.Source || connectorNode.Node.ObjectInfo == messageInfo.Target))
        {
          node.ObjectInfo = connectorNode.Node.ObjectInfo;
          if (connectorNode.Node.ObjectInfo == messageInfo.Source && sourceConnector == null)
          {
            sourceConnector = new DiagramConnectorNode(node, group, row);
          }
          else
          {
            targetConnector = new DiagramConnectorNode(node, group, row);
          }
        }

        group.Add(node);
      }

      if (targetConnector == null)
      {
        targetConnector = sourceConnector;
      }

      if (sourceConnector != null)
      {
        // add the message connection between the two nodes
        this.connections.Add(new DiagramCallConnector(sourceConnector, targetConnector));
      }

      row.Add(group);

      return row;
    }
示例#4
0
    /// <summary>
    /// Finds all nested calls.
    /// </summary>
    /// <param name="infoList">The info list.</param>
    /// <param name="item">The message info item.</param>
    /// <param name="level">The current level.</param>
    /// <returns>A list of MessageInfo objects found to be nested calls for the specified item.</returns>
    private static List<MessageInfo> FindAllNestedCalls(List<MessageInfo> infoList, MessageInfo item, int level)
    {
      if (processedCalls.Contains(item))
      {
        return new List<MessageInfo>();
      }

      List<MessageInfo> result = new List<MessageInfo>();

      var query = from m in infoList
                  where m.Parent == item
                  select m;

      result.AddRange(query);
      processedCalls.Add(item);

      foreach (MessageInfo resultItem in result.ToArray())
      {
        result.AddRange(FindAllNestedCalls(infoList, resultItem, level + 1));
      }

      return result;
    }
示例#5
0
    /// <summary>
    /// Determines the total count of nested calls.
    /// </summary>
    /// <param name="item">The message info item.</param>
    /// <returns>The number of nested calls.</returns>
    internal static int NestedCallCount(MessageInfo item)
    {
      processedCalls.Clear();
      ProcessParents(item);
      List<MessageInfo> messages = new List<MessageInfo>(Messages);
      List<MessageInfo> nestedMessages = FindAllNestedCalls(messages, item, 0);

      return nestedMessages.Count;
    }
示例#6
0
    /// <summary>
    /// Determines the nested offset.
    /// </summary>
    /// <param name="item">The message info item.</param>
    /// <returns>The nesting level of the specified item.</returns>
    internal static int DetermineNestedOffset(MessageInfo item)
    {
      ProcessParents(item);

      return item.NestingLevel;
    }
示例#7
0
    /// <summary>
    /// Processes the parents.
    /// </summary>
    /// <param name="info">The message info.</param>
    internal static void ProcessParents(MessageInfo info)
    {
      MessageInfo mi = Messages[0];
      mi.Parent = null;
      if (info.ParentIsSet)
      {
        return;
      }

      mi.NestingLevel = 0;
      for (int i = 1; i < Messages.Count; i++)
      {
        MessageInfo item = Messages[i];

        if (string.Compare(mi.MethodCallInfo.MethodName, item.MethodCallInfo.MethodName, StringComparison.OrdinalIgnoreCase) == 0)
        {
          item.Parent = null;
        }
        else if (string.Compare(mi.MethodCallInfo.MethodCallName, item.MethodCallInfo.MethodName, StringComparison.OrdinalIgnoreCase) == 0)
        {
          item.Parent = mi;
        }
        else
        {
          var query = from m in Messages
                      where m.ParentIsSet &&
                            string.Compare(m.MethodCallInfo.MethodCallName, item.MethodCallInfo.MethodName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(m.MethodCallInfo.MethodCallName, m.MethodCallInfo.MethodName, StringComparison.OrdinalIgnoreCase) != 0
                      select m;

          List<MessageInfo> queryList = query.ToList();
          if (queryList.Count > 0)
          {
            item.Parent = queryList[queryList.Count - 1];
          }
        }

        if (item.Parent != null && string.Compare(item.Parent.MethodCallInfo.MethodCallType, item.Parent.MethodCallInfo.TypeName, StringComparison.Ordinal) == 0)
        {
          item.NestingLevel = item.Parent.NestingLevel + 1;
        }
        else
        {
          item.NestingLevel = 0;
        }

        Logger.Current.Debug(string.Format("item: {0} - {2}; parent: {1} - {3};", item, item.Parent, item.NestingLevel, (item.Parent != null ? item.Parent.NestingLevel : 0)));
      }
    }