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..fa9b2b2 --- /dev/null +++ b/Reactive/ReactiveStream.cs @@ -0,0 +1,32 @@ +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); + } + + public void Clear() + { + if (StoreData) StorageAccess.Execute(() => Storage.Clear()); + } + } +} 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)); + } +}