Adds call logger

This commit is contained in:
Cyberboss
2017-12-10 10:58:17 -05:00
parent 6e820b89ee
commit 67309dc27f
4 changed files with 70 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace TGS.Server
{
sealed class AddCallLoggerBehavior : IOperationBehavior
{
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
clientOperation.ClientParameterInspectors.Add(new CallLogger());
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
dispatchOperation.ParameterInspectors.Add(new CallLogger());
}
public void Validate(OperationDescription operationDescription)
{
}
}
sealed class CallLogger : IParameterInspector
{
static readonly IDictionary<string, int> ActiveCalls = new Dictionary<string, int>();
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
lock (ActiveCalls)
--ActiveCalls[operationName];
}
public object BeforeCall(string operationName, object[] inputs)
{
lock (ActiveCalls)
{
string res = String.Empty;
foreach (var I in ActiveCalls)
{
if (I.Value > 0)
res += Environment.NewLine + I.Key + ": " + I.Value;
}
if (res != String.Empty)
{
res = String.Format("Starting call {0}. Warning: other calls in progress!{1}", operationName, res);
Server.Logger.WriteInfo(res, EventID.CallTracking, 0);
}
if (!ActiveCalls.ContainsKey(operationName))
ActiveCalls.Add(operationName, 0);
++ActiveCalls[operationName];
return null;
}
}
}
}
+4
View File
@@ -331,5 +331,9 @@ namespace TGS.Server
/// Warning: When a testmerge commit failed to be published
/// </summary>
ReferencePush = 7700,
/// <summary>
/// Info: When a call starts and another call hasn't completed
/// </summary>
CallTracking = 7800,
}
}
+4 -1
View File
@@ -4,6 +4,7 @@ using System.IO;
using System.Reflection;
using System.Security.Principal;
using System.ServiceModel;
using System.ServiceModel.Description;
using TGS.Interface;
using TGS.Interface.Components;
using TGS.Server.Security;
@@ -342,7 +343,9 @@ namespace TGS.Server
void AddEndpoint(ServiceHost host, Type typetype)
{
var bindingName = typetype.Name;
host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Definitions.TransferLimitLocal }, bindingName);
var endpint = host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Definitions.TransferLimitLocal }, bindingName);
foreach (OperationDescription od in endpint.Contract.Operations)
od.OperationBehaviors.Add(new AddCallLoggerBehavior());
var httpsBinding = new BasicHttpsBinding()
{
SendTimeout = new TimeSpan(0, 0, 40),
+1
View File
@@ -81,6 +81,7 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="CallLogger.cs" />
<Compile Include="Security\AuthenticationHeaderDecoder.cs" />
<Compile Include="ChatCommands\ByondCommand.cs" />
<Compile Include="ChatCommands\CommandInfo.cs" />