mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Adds call logger
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,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),
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user