Skip to content

Commit

Permalink
Merge pull request #24 from niik/explicit-capture
Browse files Browse the repository at this point in the history
Explicit capture
  • Loading branch information
niik committed Sep 15, 2014
2 parents 9f5e2bd + a03e3af commit b4e1840
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
4 changes: 1 addition & 3 deletions RxSpy/Proxy/QueryServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public override IMessage Invoke(IMessage msg)
if (call == null)
throw new ArgumentException("QueryLanguageProxy only supports call messages");

if (RxSpyGroup.IsActive)
{
if (!RxSpySession.Current.IsCapturing)
return ForwardCall(call);
}

var method = (System.Reflection.MethodInfo)call.MethodBase;

Expand Down
1 change: 0 additions & 1 deletion RxSpy/RxSpy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<Compile Include="Utils\MethodInvoker.cs" />
<Compile Include="Utils\Monotonic.cs" />
<Compile Include="Utils\OperatorFactory.cs" />
<Compile Include="Utils\RxSpyGroup.cs" />
<Compile Include="Utils\TypeUtils.cs" />
<Compile Include="Utils\ValueFormatter.cs" />
</ItemGroup>
Expand Down
44 changes: 37 additions & 7 deletions RxSpy/RxSpySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reflection;
using System.Threading;
Expand All @@ -18,20 +19,33 @@ public class RxSpySession: IRxSpyEventHandler, IDisposable
{
static int _launched = 0;
readonly IRxSpyEventHandler _eventHandler;
readonly bool _explicitCapture;

[ThreadStatic]
bool _isInCaptureScope;

public bool IsCapturing
{
get
{
return _explicitCapture == false || _isInCaptureScope == true;
}
}

internal static RxSpySession Current { get; private set; }

RxSpySession(IRxSpyEventHandler eventHandler)
RxSpySession(IRxSpyEventHandler eventHandler, bool explicitCapture)
{
_eventHandler = eventHandler;
_explicitCapture = explicitCapture;
}

public static RxSpySession Launch(string pathToRxSpy = null)
public static RxSpySession Launch(string pathToRxSpy = null, bool explicitCapture = false)
{
return Launch(TimeSpan.FromSeconds(10), pathToRxSpy);
return Launch(TimeSpan.FromSeconds(10), pathToRxSpy, explicitCapture);
}

public static RxSpySession Launch(TimeSpan timeout, string pathToRxSpy = null)
public static RxSpySession Launch(TimeSpan timeout, string pathToRxSpy = null, bool explicitCapture = false)
{
if (_launched == 1)
throw new InvalidOperationException("Session already created");
Expand All @@ -51,12 +65,12 @@ public static RxSpySession Launch(TimeSpan timeout, string pathToRxSpy = null)
Process.Start(psi);
server.WaitForConnection(timeout);

return Launch(server);
return Launch(server, explicitCapture);
}

public static RxSpySession Launch(IRxSpyEventHandler eventHandler)
public static RxSpySession Launch(IRxSpyEventHandler eventHandler, bool explicitCapture = false)
{
var session = new RxSpySession(eventHandler);
var session = new RxSpySession(eventHandler, explicitCapture);
Current = session;

if (Interlocked.CompareExchange(ref _launched, 1, 0) != 0)
Expand Down Expand Up @@ -129,6 +143,22 @@ static void InstallInterceptingQueryLanguage(RxSpySession session)
defaultImplementationField.SetValue(null, proxy);
}

public static IDisposable Capture()
{
Current.StartCapture();
return Disposable.Create(() => Current.StopCapture());
}

public void StartCapture()
{
_isInCaptureScope = true;
}

public void StopCapture()
{
_isInCaptureScope = false;
}

public void OnCreated(IOperatorCreatedEvent onCreatedEvent)
{
_eventHandler.OnCreated(onCreatedEvent);
Expand Down
31 changes: 0 additions & 31 deletions RxSpy/Utils/RxSpyGroup.cs

This file was deleted.

0 comments on commit b4e1840

Please sign in to comment.