From 35cb0bc7b66e37a943c28266cd5ba4456bd83f2f Mon Sep 17 00:00:00 2001 From: Timerix Date: Sun, 3 Oct 2021 00:17:31 +0300 Subject: [PATCH] reatcivity --- DTLib.csproj | 12 ++++++++++++ EventHandlerAsync.cs | 10 ++++++++++ Reactive/ReactiveListener.cs | 13 +++++++++++++ Reactive/ReactiveProvider.cs | 13 +++++++++++++ Reactive/ReactiveStream.cs | 28 ++++++++++++++++++++++++++++ Reactive/ReactiveWorker.cs | 18 ++++++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 EventHandlerAsync.cs create mode 100644 Reactive/ReactiveListener.cs create mode 100644 Reactive/ReactiveProvider.cs create mode 100644 Reactive/ReactiveStream.cs create mode 100644 Reactive/ReactiveWorker.cs diff --git a/DTLib.csproj b/DTLib.csproj index 1b46f80..833f694 100644 --- a/DTLib.csproj +++ b/DTLib.csproj @@ -43,6 +43,7 @@ + @@ -53,12 +54,23 @@ + + + + + + + + + + + diff --git a/EventHandlerAsync.cs b/EventHandlerAsync.cs new file mode 100644 index 0000000..6efbbf5 --- /dev/null +++ b/EventHandlerAsync.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib +{ + public delegate Func EventHandlerAsync(object sender, TEventArgs e); +} diff --git a/Reactive/ReactiveListener.cs b/Reactive/ReactiveListener.cs new file mode 100644 index 0000000..4db4f15 --- /dev/null +++ b/Reactive/ReactiveListener.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib.Reactive +{ + public class ReactiveListener : ReactiveWorker + { + + } +} diff --git a/Reactive/ReactiveProvider.cs b/Reactive/ReactiveProvider.cs new file mode 100644 index 0000000..6e29089 --- /dev/null +++ b/Reactive/ReactiveProvider.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib.Reactive +{ + public class ReactiveProvider : ReactiveWorker + { + + } +} diff --git a/Reactive/ReactiveStream.cs b/Reactive/ReactiveStream.cs new file mode 100644 index 0000000..10b97fc --- /dev/null +++ b/Reactive/ReactiveStream.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.ObjectModel; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib.Reactive +{ + public class ReactiveStream + { + List Storage = new(); + public event EventHandlerAsync ElementAdded; + bool StoreData = false; + + SafeMutex StorageAccess = new(); + + public ReactiveStream() { } + public ReactiveStream(bool storeData) => StoreData = storeData; + + public void Add(T elem) + { + if (StoreData) StorageAccess.Execute(()=> Storage.Add(elem)); + ElementAdded?.Invoke(this, elem); + } + + } +} diff --git a/Reactive/ReactiveWorker.cs b/Reactive/ReactiveWorker.cs new file mode 100644 index 0000000..f7ebf07 --- /dev/null +++ b/Reactive/ReactiveWorker.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib.Reactive +{ + public abstract class ReactiveWorker + { + List> Streams = new(); + + SafeMutex StreamCollectionAccess = new(); + + public void Join(ReactiveStream stream) => StreamCollectionAccess.Execute(()=>Streams.Add(stream)); + public void Leave(ReactiveStream stream) => StreamCollectionAccess.Execute(() => Streams.Remove(stream)); + } +}