Skip to content

Commit

Permalink
Some refactorings on #140 and #173 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HEskandari committed Dec 23, 2013
1 parent cb5ccbb commit 8be9d80
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 31 deletions.
23 changes: 8 additions & 15 deletions src/ServiceInsight.Desktop/MessageFlow/MessageFlowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
using Caliburn.PresentationFramework.Screens;
using ExceptionHandler;
using Mindscape.WpfDiagramming;
using NServiceBus.Profiler.Desktop.Core.MessageDecoders;
using NServiceBus.Profiler.Desktop.Events;
using NServiceBus.Profiler.Desktop.MessageProperties;
using NServiceBus.Profiler.Desktop.Models;
using NServiceBus.Profiler.Desktop.ServiceControl;
using NServiceBus.Profiler.Desktop.ScreenManager;
Expand All @@ -23,42 +21,37 @@ public interface IMessageFlowViewModel : IScreen,
MessageFlowDiagram Diagram { get; }
void CopyMessageUri(StoredMessage message);
void CopyConversationId(StoredMessage message);
void CopyMessageId(StoredMessage Message);
void CopyMessageId(StoredMessage message);
Task RetryMessage(StoredMessage message);
void ShowMessageBody(StoredMessage message);
void ShowSagaWindow(StoredMessage message);
void ToggleEndpointData();
void ShowException(IExceptionDetails exception);
void ZoomIn();
void ZoomOut();
bool IsFocused(MessageInfo Message);
bool IsFocused(MessageInfo message);
}

public class MessageFlowViewModel : Screen, IMessageFlowViewModel
{
private readonly IScreenFactory _screenFactory;
private readonly IServiceControl _serviceControl;
private readonly IEventAggregator _eventAggregator;
private readonly IContentDecoder<IList<HeaderInfo>> _decoder;
private readonly IHeaderInfoSerializer _headerInfoSerializer;
private readonly IClipboard _clipboard;
private readonly IWindowManagerEx _windowManager;
private readonly ConcurrentDictionary<string, MessageNode> _nodeMap;
private IMessageFlowView _view;
private string _originalSelectionId = string.Empty;

public MessageFlowViewModel(
IServiceControl serviceControl,
IEventAggregator eventAggregator,
IContentDecoder<IList<HeaderInfo>> decoder,
IHeaderInfoSerializer headerInfoSerializer,
IClipboard clipboard,
IWindowManagerEx windowManager,
IScreenFactory screenFactory)
{
_serviceControl = serviceControl;
_eventAggregator = eventAggregator;
_decoder = decoder;
_headerInfoSerializer = headerInfoSerializer;
_clipboard = clipboard;
_windowManager = windowManager;
_screenFactory = screenFactory;
Expand Down Expand Up @@ -151,7 +144,7 @@ private MessageNode CreateMessageNode(StoredMessage x)

public bool IsFocused(MessageInfo message)
{
return message.Id == originalSelectionId;
return message.Id == _originalSelectionId;
}

private void LinkConversationNodes(IEnumerable<MessageNode> relatedMessagesTask)
Expand Down Expand Up @@ -197,14 +190,13 @@ private void AddConnection(MessageNode parentNode, MessageNode childNode)
Diagram.Connections.Add(connection);
}

private string originalSelectionId = string.Empty;
private void CreateConversationNodes(string selectedId, IEnumerable<MessageNode> relatedNodes)
{
foreach (var node in relatedNodes)
{
if (string.Equals(node.Message.Id, selectedId, StringComparison.InvariantCultureIgnoreCase))
{
originalSelectionId = selectedId;
_originalSelectionId = selectedId;
SelectedMessage = node;
}

Expand Down Expand Up @@ -246,9 +238,10 @@ public MessageNode SelectedMessage

public void Handle(SelectedMessageChanged message)
{
originalSelectionId = string.Empty;
SelectedMessage = null;
_originalSelectionId = string.Empty;
_nodeMap.Clear();

SelectedMessage = null;
Diagram = new MessageFlowDiagram();
}

Expand Down
11 changes: 5 additions & 6 deletions src/ServiceInsight.Desktop/MessageFlow/MessageNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ namespace NServiceBus.Profiler.Desktop.MessageFlow
[DebuggerDisplay("Type={Message.FriendlyMessageType}, Id={Message.Id}")]
public class MessageNode : DiagramNode
{
private const int heightNoEndpoints = 56;
private const int endpointsHeight = 25;
private const int HeightNoEndpoints = 56;
private const int EndpointsHeight = 25;

public MessageNode(IMessageFlowViewModel owner, StoredMessage message)
{
IsResizable = false;
Owner = owner;
Bounds = new Rect(0, 0, 233, heightNoEndpoints);
//ZOrder = 1;
Bounds = new Rect(0, 0, 233, HeightNoEndpoints);
Data = message;
ExceptionMessage = message.GetHeaderByKey(MessageHeaderKeys.ExceptionType);
}
Expand Down Expand Up @@ -82,7 +81,7 @@ public bool ShowEndpoints

public void OnShowEndpointsChanged()
{
Bounds = new Rect(Bounds.Location, new Size(Bounds.Width, heightNoEndpoints + (ShowEndpoints ? endpointsHeight : 0)));
Bounds = new Rect(Bounds.Location, new Size(Bounds.Width, HeightNoEndpoints + (ShowEndpoints ? EndpointsHeight : 0)));
}

public bool ShowExceptionInfo
Expand Down Expand Up @@ -137,7 +136,7 @@ public bool IsFocused
{
get
{
return Owner.IsFocused(this.Message);
return Owner.IsFocused(Message);
}
}
}
Expand Down
49 changes: 43 additions & 6 deletions src/ServiceInsight.Desktop/MessageList/MessageListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MessageListViewModel : Conductor<IScreen>.Collection.AllActive, IMe
private readonly IMenuItem _retryMessageMenu;
private readonly IMenuItem _copyMessageIdMenu;
private readonly IMenuItem _copyHeadersMenu;
private bool _lockUpdate;
private string _lastSortColumn;
private bool _lastSortOrderAscending;
private int _workCount;
Expand Down Expand Up @@ -142,6 +143,8 @@ public bool CanCopyMessageId()

public void OnFocusedRowChanged()
{
if (_lockUpdate) return;

_eventAggregator.Publish(new SelectedMessageChanged(FocusedRow));

if (FocusedRow != null)
Expand Down Expand Up @@ -208,12 +211,7 @@ public async Task RefreshMessages(Endpoint endpoint, int pageIndex = 1, string s
ascending: _lastSortOrderAscending);
}

using (new GridSelectionPreserver<StoredMessage>(this))
using (new GridFocusedRowPreserver<StoredMessage>(this))
{
Rows.Clear();
Rows.AddRange(pagedResult.Result);
}
TryRebindMessageList(pagedResult);

SearchBar.IsVisible = true;
SearchBar.SetupPaging(new PagedResult<StoredMessage>
Expand All @@ -226,6 +224,45 @@ public async Task RefreshMessages(Endpoint endpoint, int pageIndex = 1, string s
_eventAggregator.Publish(new WorkFinished());
}

private void TryRebindMessageList(PagedResult<StoredMessage> pagedResult)
{
try
{
_lockUpdate = !ShouldUpdateMessages(pagedResult);

using (new GridSelectionPreserver<StoredMessage>(this))
using (new GridFocusedRowPreserver<StoredMessage>(this))
{
Rows.Clear();
Rows.AddRange(pagedResult.Result);
}
}
finally
{
_lockUpdate = false;
}
}

private bool ShouldUpdateMessages(PagedResult<StoredMessage> pagedResult)
{
if (FocusedRow == null)
return true;

var hasNewMessageInConversation = Rows.Count(m => m.ConversationId == FocusedRow.ConversationId) != pagedResult.Result.Count(p => p.ConversationId == FocusedRow.ConversationId);
if (hasNewMessageInConversation)
return true;

var messagesInConversation = Rows.Where(m => m.ConversationId == FocusedRow.ConversationId);
var anyConversationMessageChanged = messagesInConversation.Any(message => ShouldUpdateMessage(message, pagedResult.Result.FirstOrDefault(m => m.Id == message.Id)));

return anyConversationMessageChanged;
}

private static bool ShouldUpdateMessage(StoredMessage focusedMessage, StoredMessage newMessage)
{
return newMessage == null || newMessage.DisplayPropertiesChanged(focusedMessage);
}

public string GetCriticalTime(StoredMessage msg)
{
if (msg != null && msg.Statistics != null)
Expand Down
3 changes: 0 additions & 3 deletions src/ServiceInsight.Desktop/Models/MessageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public MessageInfo(string id, string label, DateTime timeSent)
Id = id;
Label = label;
TimeSent = timeSent;
IsDeleted = false;
}

public string Id { get; set; }
Expand All @@ -27,8 +26,6 @@ public MessageInfo(string id, string label, DateTime timeSent)

public DateTime TimeSent { get; set; }

public bool IsDeleted { get; set; }

public string FriendlyMessageType { get; private set; }

public void OnMessageTypeChanged()
Expand Down
11 changes: 11 additions & 0 deletions src/ServiceInsight.Desktop/Models/StoredMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ public string GetHeaderByKey(string key)
x.Key.Equals(keyWithPrefix, StringComparison.InvariantCultureIgnoreCase));
return pair == null ? string.Empty : pair.Value;
}

public bool DisplayPropertiesChanged(StoredMessage focusedMessage)
{
if (focusedMessage == null) return true;

return (Status != focusedMessage.Status) ||
(TimeSent != focusedMessage.TimeSent) ||
(ProcessingTime != focusedMessage.ProcessingTime) ||
(ReceivingEndpoint.ToString() != focusedMessage.ReceivingEndpoint.ToString()) ||
(SendingEndpoint.ToString() != focusedMessage.SendingEndpoint.ToString());
}
}

[DebuggerDisplay("Key={Key},Value={Value}")]
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceInsight.Desktop/ServiceInsight.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
<Compile Include="MessageProperties\PerformanceHeaderViewModel.cs" />
<Compile Include="MessageProperties\SagaHeaderViewModel.cs" />
<Compile Include="MessageList\GridSelectionPreserver.cs" />
<Compile Include="MessageList\IViewWithGrid.cs" />
<Compile Include="MessageList\ITableViewModel.cs" />
<Compile Include="MessageList\MessageErrorInfo.cs" />
<Compile Include="MessageViewers\HexViewer\HexContentView.xaml.cs">
<DependentUpon>HexContentView.xaml</DependentUpon>
Expand Down

0 comments on commit 8be9d80

Please sign in to comment.