Skip to content

Commit

Permalink
diagnostics for the client messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Jul 6, 2015
1 parent edcf6af commit 52081e1
Show file tree
Hide file tree
Showing 10 changed files with 1,168 additions and 899 deletions.
74 changes: 74 additions & 0 deletions javascript/client-messages.jsx
@@ -0,0 +1,74 @@
var React = require('react');


var MessageRow = React.createClass({
render: function(){
var url = '#fubumvc/chain-details/' + this.props.message.chain;


return (
<tr>
<td><a href={url} title="View the chain visualization for this message type">{this.props.message.type}</a></td>
<td>{this.props.message.query}</td>
<td>{this.props.message.resource}</td>
</tr>
);
}
});

var MessageTable = React.createClass({
getInitialState: function(){
return {
loading: true
}
},

componentDidMount: function(){
FubuDiagnostics.get('ClientMessages:clientmessages', {}, data => {
_.assign(data, {loading: false});

this.setState(data);
});
},

render: function(){
if (this.state.loading){
return (<p>Loading...</p>);
}

if (this.state.messages.length == 0){
return (
<h1>No client messages in this application!</h1>
);
}

var rows = this.state.messages.map(function(r, i){
return (
<MessageRow message={r} />
);
});

return (
<table className="table table-striped">
<thead>
<tr>
<th>Client Side Name</th>
<th>Query Model</th>
<th>Resource Model</th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
);
}
});


FubuDiagnostics.section('fubumvc').add({
title: 'Client Message Types',
description: 'A list of all the message types available for aggregated querying',
key: 'client-messages',
component: MessageTable
});
3 changes: 2 additions & 1 deletion javascript/root.jsx
Expand Up @@ -20,7 +20,7 @@ _.assign(FubuDiagnostics, {
get: function (key, params, callback) {
var url = this.toUrl(key, params);
$.get(url, function(data){
var parsed = JSON.parse(data.toString());
var parsed = JSON.parse(JSON.stringify(data));
callback(parsed);
});
},
Expand Down Expand Up @@ -76,6 +76,7 @@ require('./chain-details');
require('./request-table.jsx');
require('./request-details.jsx');
require('./packaging');
require('./client-messages');



Expand Down
58 changes: 58 additions & 0 deletions src/FubuMVC.Core/Diagnostics/ClientMessagesFubuDiagnostics.cs
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using FubuMVC.Core.Runtime.Aggregation;

namespace FubuMVC.Core.Diagnostics
{
public class ClientMessagesFubuDiagnostics
{
private readonly IClientMessageCache _messages;

public ClientMessagesFubuDiagnostics(IClientMessageCache messages)
{
_messages = messages;
}

public ClientMessageReport get_clientmessages()
{
return new ClientMessageReport
{
messages = _messages.AllClientMessages().OrderBy(x => x.Message).Select(x =>
{
var description1 = new ClientMessageDescription(x);
return description1;
}).ToArray()
};
}
}

public class ClientMessageReport
{
public ClientMessageDescription[] messages;
}

public class ClientMessageDescription
{
public ClientMessageDescription()
{
}

public ClientMessageDescription(ClientMessagePath path)
{
type = path.Message;
query = path.InputType == null ? "N/A" : path.InputType.FullName;
resource = path.ResourceType.FullName;
chain = path.Chain.GetHashCode();
}

public int chain { get; set; }

public string resource { get; set; }

public string query { get; set; }

public string type { get; set; }
}
}
1 change: 1 addition & 0 deletions src/FubuMVC.Core/FubuMVC.Core.csproj
Expand Up @@ -124,6 +124,7 @@
<Compile Include="Diagnostics\BehaviorChainExtensions.cs" />
<Compile Include="Diagnostics\ChainFubuDiagnostics.cs" />
<Compile Include="Diagnostics\ChildDescriptionTag.cs" />
<Compile Include="Diagnostics\ClientMessagesFubuDiagnostics.cs" />
<Compile Include="Diagnostics\DescriptionPropertyTag.cs" />
<Compile Include="Diagnostics\DescriptionBodyTag.cs" />
<Compile Include="Diagnostics\DiagnosticChain.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/FubuMVC.Core/Runtime/Aggregation/ClientMessageCache.cs
Expand Up @@ -46,7 +46,8 @@ public IEnumerable<ClientMessagePath> AllClientMessages()
{
Message = name,
InputType = chain.InputType(),
ResourceType = chain.ResourceType()
ResourceType = chain.ResourceType(),
Chain = chain
});
});

Expand Down
2 changes: 2 additions & 0 deletions src/FubuMVC.Core/Runtime/Aggregation/ClientMessagePath.cs
@@ -1,4 +1,5 @@
using System;
using FubuMVC.Core.Registration.Nodes;

namespace FubuMVC.Core.Runtime.Aggregation
{
Expand All @@ -7,6 +8,7 @@ public class ClientMessagePath
public string Message { get; set; }
public Type InputType { get; set; }
public Type ResourceType { get; set; }
public BehaviorChain Chain { get; set; }

protected bool Equals(ClientMessagePath other)
{
Expand Down
121 changes: 121 additions & 0 deletions src/TestHarnessApp/AggregationEndpoint.cs
@@ -0,0 +1,121 @@
using System.Linq;
using FubuMVC.Core;
using FubuMVC.Core.Runtime.Aggregation;

namespace TestHarnessApp
{
public class AggregationEndpoint
{
private readonly IAggregator _aggregator;

public AggregationEndpoint(IAggregator aggregator)
{
_aggregator = aggregator;
}

public Resource1 get_query1_Name(Query1 query)
{
return new Resource1 { Name = query.Name };
}

public Resource2 get_second_resource()
{
return new Resource2();
}

public Resource3 get_third_resource(Input2 input)
{
return new Resource3();
}

public Resource4 get_fourth_resource()
{
return new Resource4();
}

public AggregationResponse post_aggregated_query(AggregatedQuery query)
{
return _aggregator.QueryAggregate(query);
}

public string[] get_aggregation()
{
// The call to IAggregator.Fetch() will return an array
// of objects. My assumption now is that you'd do this in
// the main endpoint method, tack the data store data on
// to the view model sent to the main spark view, and
// render it to the view with a page helper there.
// This is so common now that I think we put a json variable
// helper into FubuMVC.Core.
return _aggregator.Fetch(_ =>
{
// By an input query
_.Query(new Query1 { Name = "Jeremy Maclin" });
// By the resource type
_.Resource<Resource2>();
// By the input type as a marker
_.Input<Input2>();
// By action method
_.Action<AggregationEndpoint>(x => x.get_fourth_resource());
})
.Select(x => x.ToString())
.ToArray();
}

[ClientMessage]
public class Input1
{

}

[ClientMessage]
public class Resource2
{
public override string ToString()
{
return "I am Resource2";
}
}

[ClientMessage]
public class Input2 { }

[ClientMessage]
public class Resource3
{
public override string ToString()
{
return "Resource3 from input type 2";
}
}

[ClientMessage]
public class Resource4
{
public override string ToString()
{
return "Resource4 from an action identified by expression";
}
}

[ClientMessage]
public class Query1
{
public string Name { get; set; }
}

[ClientMessage]
public class Resource1
{
public string Name { get; set; }

public override string ToString()
{
return "Resource1: " + Name;
}
}
}
}
1 change: 1 addition & 0 deletions src/TestHarnessApp/TestHarnessApp.csproj
Expand Up @@ -69,6 +69,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="AggregationEndpoint.cs" />
<Compile Include="BlowsUpEndpoint.cs" />
<Compile Include="Instrumentation\HelloTextBehavior.cs" />
<Compile Include="Instrumentation\ErrorEndpoint.cs" />
Expand Down

0 comments on commit 52081e1

Please sign in to comment.