Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MouseService.cs « RxMouseServer « RxRemoteMouseMoves « Samples « NET « Rx - github.com/mono/rx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52fe73389a73e3d884d4469174dc08e77870c3d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Drawing;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using RxMouseService;

namespace RxMouseServer
{
    public class MouseService : MarshalByRefObject, IMouseService, IObserver<Point>
    {
        private ReplaySubject<Point> _points;

        public MouseService()
        {
            _points = new ReplaySubject<Point>();
        }

        public IObservable<Point> GetPoints()
        {
            var src = _points.ObserveOn(NewThreadScheduler.Default);
            return Log(src).Remotable();
        }

        public IObservable<T> Log<T>(IObservable<T> source)
        {
            return Observable.Create<T>(observer =>
            {
                Console.WriteLine("Client connected!");

                var d = source.Subscribe(observer);

                return Disposable.Create(() =>
                {
                    Console.WriteLine("Client disconnected!");
                    d.Dispose();
                });
            });
        }

        public void OnNext(Point value)
        {
            _points.OnNext(value);
        }

        public void OnError(Exception error)
        {
            throw new NotImplementedException();
        }

        public void OnCompleted()
        {
            throw new NotImplementedException();
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }
    }
}