| 1 |
using System; |
| 2 |
using System.Drawing; |
| 3 |
using System.Reactive.Concurrency; |
| 4 |
using System.Reactive.Disposables; |
| 5 |
using System.Reactive.Linq; |
| 6 |
using System.Reactive.Subjects; |
| 7 |
using RxMouseService; |
| 8 |
|
| 9 |
namespace RxMouseServer |
| 10 |
{ |
| 11 |
public class MouseService : MarshalByRefObject, IMouseService, IObserver<Point> |
| 12 |
{ |
| 13 |
private ReplaySubject<Point> _points; |
| 14 |
|
| 15 |
public MouseService() |
| 16 |
{ |
| 17 |
_points = new ReplaySubject<Point>(); |
| 18 |
} |
| 19 |
|
| 20 |
public IObservable<Point> GetPoints() |
| 21 |
{ |
| 22 |
var src = _points.ObserveOn(NewThreadScheduler.Default); |
| 23 |
return Log(src).Remotable(); |
| 24 |
} |
| 25 |
|
| 26 |
public IObservable<T> Log<T>(IObservable<T> source) |
| 27 |
{ |
| 28 |
return Observable.Create<T>(observer => |
| 29 |
{ |
| 30 |
Console.WriteLine("Client connected!"); |
| 31 |
|
| 32 |
var d = source.Subscribe(observer); |
| 33 |
|
| 34 |
return Disposable.Create(() => |
| 35 |
{ |
| 36 |
Console.WriteLine("Client disconnected!"); |
| 37 |
d.Dispose(); |
| 38 |
}); |
| 39 |
}); |
| 40 |
} |
| 41 |
|
| 42 |
public void OnNext(Point value) |
| 43 |
{ |
| 44 |
_points.OnNext(value); |
| 45 |
} |
| 46 |
|
| 47 |
public void OnError(Exception error) |
| 48 |
{ |
| 49 |
throw new NotImplementedException(); |
| 50 |
} |
| 51 |
|
| 52 |
public void OnCompleted() |
| 53 |
{ |
| 54 |
throw new NotImplementedException(); |
| 55 |
} |
| 56 |
|
| 57 |
public override object InitializeLifetimeService() |
| 58 |
{ |
| 59 |
return null; |
| 60 |
} |
| 61 |
} |
| 62 |
} |