diff --git a/TGS.Server/CallLogger.cs b/TGS.Server/CallLogger.cs new file mode 100644 index 0000000000..7ddb7e409d --- /dev/null +++ b/TGS.Server/CallLogger.cs @@ -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 ActiveCalls = new Dictionary(); + + 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; + } + } + } +} diff --git a/TGS.Server/EventID.cs b/TGS.Server/EventID.cs index 9981fd199f..05043646ef 100644 --- a/TGS.Server/EventID.cs +++ b/TGS.Server/EventID.cs @@ -331,5 +331,9 @@ namespace TGS.Server /// Warning: When a testmerge commit failed to be published /// ReferencePush = 7700, + /// + /// Info: When a call starts and another call hasn't completed + /// + CallTracking = 7800, } } diff --git a/TGS.Server/Server.cs b/TGS.Server/Server.cs index eff1d58fa9..59f0abd5d4 100644 --- a/TGS.Server/Server.cs +++ b/TGS.Server/Server.cs @@ -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), diff --git a/TGS.Server/TGS.Server.csproj b/TGS.Server/TGS.Server.csproj index 83f970c8c1..14e9e076e2 100644 --- a/TGS.Server/TGS.Server.csproj +++ b/TGS.Server/TGS.Server.csproj @@ -81,6 +81,7 @@ +