Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit 78c9522

Browse files
authored
Merge pull request #109 from JacopoWolf/dev/3.1
Preparing 3.1 release branch
2 parents bd3a1ed + be1ddae commit 78c9522

17 files changed

Lines changed: 166 additions & 105 deletions

.github/dependabot.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
version: 2
77
updates:
88

9+
910
# prod
1011
- package-ecosystem: "nuget"
1112
directory: "/StackInjector"
@@ -26,10 +27,10 @@ updates:
2627
- "dependencies"
2728
- "testing"
2829

30+
2931
#todo: add TEST.WhiteBox
3032

3133

32-
3334
# ci
3435
- package-ecosystem: "github-actions"
3536
# Workflow files stored in the

StackInjector/Attributes/ServedAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class ServedAttribute : Attribute
1313
/// <summary>
1414
/// The target version.
1515
/// </summary>
16-
public double TargetVersion { get; set; } = 0.0;
16+
public double TargetVersion { get; set; }
1717

1818
/// <summary>
1919
/// <para>How the specified TargetVersion should be found.</para>
@@ -31,7 +31,7 @@ public ServedVersionTargetingMethod TargetingMethod
3131

3232

3333
private ServedVersionTargetingMethod _targeting;
34-
internal bool _targetingDefined = false;
34+
internal bool _targetingDefined;
3535

3636
}
3737

StackInjector/Attributes/ServiceAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ServingMethods Serving
3434
}
3535

3636
private ServingMethods _serving;
37-
internal bool _servingDefined = false;
37+
internal bool _servingDefined;
3838
}
3939

4040
}

StackInjector/Core/AsyncStackWrapperCore.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace StackInjector.Core
88
internal abstract partial class AsyncStackWrapperCore<T> : StackWrapperCore, IAsyncStackWrapperCore<T>
99
{
1010

11+
public event Action<T> OnElaborated;
12+
13+
1114
// used to cancel everything
1215
protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource();
1316

@@ -16,10 +19,13 @@ public CancellationToken PendingTasksCancellationToken
1619
=> this.cancelPendingTasksSource.Token;
1720

1821
// used to lock access to tasks
19-
protected internal readonly object listAccessLock = new object();
22+
private readonly object listAccessLock = new object();
23+
24+
// used to endure Elaborated() and Elaborate() are called together
25+
private bool exclusiveExecution;
2026

2127
// asyncronously waited for new events if TaskList is empty
22-
protected internal readonly SemaphoreSlim emptyListAwaiter = new SemaphoreSlim(0);
28+
private readonly SemaphoreSlim emptyListAwaiter = new SemaphoreSlim(0);
2329

2430
// pending tasks
2531
protected internal LinkedList<Task<T>> tasks = new LinkedList<Task<T>>();
@@ -35,7 +41,7 @@ internal AsyncStackWrapperCore ( InjectionCore core, Type toRegister ) : base(co
3541

3642
#region IDisposable Support
3743

38-
private bool disposedValue = false;
44+
private bool disposedValue;
3945

4046
public override void Dispose ()
4147
{
@@ -61,7 +67,6 @@ public override void Dispose ()
6167
this.disposedValue = true;
6268
}
6369
}
64-
6570
#endregion
6671
}
6772

StackInjector/Core/AsyncStackWrapperCore.logic.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Threading.Tasks;
45
using StackInjector.Settings;
@@ -30,8 +31,17 @@ public bool AnyTaskLeft ()
3031
return this.tasks.Any();
3132
}
3233

34+
public bool AnyTaskCompleted ()
35+
{
36+
return this.tasks.Any(t => t.IsCompleted);
37+
}
38+
39+
// todo add a method to safely exit the await loop to be able to re-join later or maybe an Unloack() of some sort
40+
//! should check if exiting an await foreach loop and re-entering will not hack the control or lose data
3341
public async IAsyncEnumerable<T> Elaborated ()
3442
{
43+
this.EnsureExclusiveExecution(true);
44+
3545
while( !this.cancelPendingTasksSource.IsCancellationRequested )
3646
{
3747
// avoid deadlocks
@@ -51,8 +61,28 @@ public async IAsyncEnumerable<T> Elaborated ()
5161
break;
5262
}
5363
}
64+
65+
lock( this.listAccessLock )
66+
this.exclusiveExecution = false;
67+
68+
}
69+
70+
public Task Elaborate ()
71+
{
72+
// must run syncronously
73+
this.EnsureExclusiveExecution();
74+
75+
return
76+
Task.Run(async () =>
77+
{
78+
79+
await foreach( var res in this.Elaborated() )
80+
this.OnElaborated?.Invoke(res);
81+
});
82+
5483
}
5584

85+
5686
// true if outher loop is to break
5787
private async Task<bool> OnNoTasksLeft ()
5888
{
@@ -86,10 +116,18 @@ Task listAwaiter ()
86116
}
87117
}
88118

119+
private void EnsureExclusiveExecution ( bool set = false )
120+
{
121+
lock( this.listAccessLock ) // reused lock
122+
{
123+
if( this.exclusiveExecution )
124+
throw new InvalidOperationException();
125+
126+
if( set )
127+
this.exclusiveExecution = set;
128+
}
129+
}
89130

90-
public bool AnyTaskCompleted ()
91-
=>
92-
this.tasks.Any(t => t.IsCompleted);
93131

94132

95133
}

StackInjector/Core/IAsyncStackWrapperCore.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ namespace StackInjector.Core
1111
/// <typeparam name="T">the type tasks will return</typeparam>
1212
public interface IAsyncStackWrapperCore<T> : IStackWrapperCore
1313
{
14+
/// <summary>
15+
/// called when a new element has been elaborated
16+
/// </summary>
17+
event Action<T> OnElaborated;
1418

1519
/// <summary>
1620
/// Used to signal cancellation of every pending task
1721
/// </summary>
1822
CancellationToken PendingTasksCancellationToken { get; }
1923

20-
2124
/// <summary>
2225
/// submit new work to this wrapper
2326
/// </summary>
@@ -30,8 +33,17 @@ public interface IAsyncStackWrapperCore<T> : IStackWrapperCore
3033
/// this will wait indefinitively.
3134
/// </summary>
3235
/// <returns>An asyncronous enumerable of completed tasks</returns>
36+
/// <exception cref="InvalidOperationException"></exception>
3337
IAsyncEnumerable<T> Elaborated ();
3438

39+
/// <summary>
40+
/// Calling this method will begin the elaboration loop.<br/>
41+
/// If a concurrent call to the <see cref="Elaborated"/> is made, this will return an exception
42+
/// </summary>
43+
/// <returns>a task rappresenting the elaboration loop</returns>
44+
/// <exception cref="InvalidOperationException"></exception>
45+
Task Elaborate ();
46+
3547
/// <summary>
3648
/// check if there are tasks left to elaborate
3749
/// </summary>

StackInjector/Core/InjectionCore.logic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal void ServeAll ()
2626
var next = toInject.Dequeue();
2727
var usedServices = this.InjectServicesInto(next);
2828

29-
// this object has been ionjected
29+
// this object has been injected
3030
this.instances.SetInjectionStatus(next);
3131

3232
// foreach injected object check if it has already been injected.

StackInjector/Core/StackWrapperCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public StackWrapperCore ( InjectionCore core, Type toRegister )
2323
this.Core = core;
2424

2525
// setting for referencing the calling wrapper as a service
26-
if( this.Core.settings._registerSelf )
26+
if( this.Core.settings._registerWrapAsService )
2727
this.Core.instances.AddInstance(toRegister, this);
2828
}
2929

StackInjector/Exceptions/StackInjectorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class StackInjectorException : Exception
1010
/// <summary>
1111
/// The source type of the exception
1212
/// </summary>
13-
public Type SourceType { get; private protected set; } = null;
13+
public Type SourceType { get; private protected set; }
1414

1515
internal StackInjectorException ( Type type, string message ) : this(message)
1616
{

StackInjector/Injector.defaults.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public static class Defaults
2424
/// </summary>
2525
public const ServingMethods ServeAll =
2626
( ServingMethods.Fields | ServingMethods.Properties );
27+
28+
29+
/// <summary>
30+
/// Default regex to filter system assemblies
31+
/// </summary>
32+
public const string AssemblyRegexFilter = "^(System)|(Microsoft)";
2733
}
2834
}
2935
}

0 commit comments

Comments
 (0)