Skip to content

Commit 42fd78b

Browse files
author
Meyn
committed
Fix RequestContainer Array access
1 parent 8f0ff91 commit 42fd78b

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ This library includes the following classes:
4444
- **ProgressableContainer:** A container class to merge requests together that are using a `Progress` object to report the progress.
4545
- **RequestHandler:** A class to handle requests. Every handler is independent of any other handler.
4646

47-
> Expand and use as you like!<br />
47+
> Expand and use as you like!
48+
>
4849
> Because handling requests should be as delightful as a warm cup of cocoa on a winter day.
4950
5051
For additional information, refer to the Requests [Wiki](https://github.com/TypNull/Requests/wiki/).
@@ -95,7 +96,7 @@ Create your own requests with a sprinkle of magic! ✨
9596

9697
## 🌟 Contributing
9798

98-
Join our quest! If you'd like to contribute to this library, submit a pull request or open an issue. We appreciate your help in making **Requests** the best it can be!
99+
Join our quest! If you'd like to contribute to this library, submit a pull request or open an issue. We appreciate your help in making `Requests` the best it can be!
99100

100101
## 📜 License
101102

Requests/ProgressableContainer.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static ProgressableContainer<TRequest> MergeContainers(/*bool autoReset =
3636
}
3737

3838
/// <summary>
39-
/// Adds an <see cref="IRequest"/> to the <see cref="ProgressableContainer{TRequest}"/>.
39+
/// Adds an <see cref="IProgressableRequest"/> to the <see cref="ProgressableContainer{TRequest}"/>.
4040
/// </summary>
4141
/// <param name="request">The request to add.</param>
4242
public new void Add(TRequest request)
@@ -45,6 +45,21 @@ public static ProgressableContainer<TRequest> MergeContainers(/*bool autoReset =
4545
AttachProgress(request);
4646
}
4747

48+
/// <summary>
49+
/// Accesses all <see cref="IProgressableRequest"/> to the <see cref="ProgressableContainer{TRequest}"/>.
50+
/// </summary>
51+
/// <returns>Returns an array of <see cref="IProgressableRequest"/> instances.</returns>
52+
public override TRequest this[int key]
53+
{
54+
get => base[key];
55+
set
56+
{
57+
_progress.TryRemove(base[key].Progress);
58+
base[key] = value;
59+
_progress.Attach(base[key].Progress);
60+
}
61+
}
62+
4863
private void AttachProgress(TRequest request)
4964
{
5065
if (request.Progress == null)
@@ -67,7 +82,7 @@ private void AttachProgress(TRequest request)
6782
//}
6883

6984
/// <summary>
70-
/// Adds a range of <see cref="IRequest"/> instances to the container.
85+
/// Adds a range of <see cref="IProgressableRequest"/> instances to the container.
7186
/// </summary>
7287
/// <param name="requests">Requests to add.</param>
7388
public override void AddRange(params TRequest[] requests)
@@ -77,7 +92,7 @@ public override void AddRange(params TRequest[] requests)
7792
}
7893

7994
/// <summary>
80-
/// Removes one or more <see cref="IRequest"/> instances from this container.
95+
/// Removes one or more <see cref="IProgressableRequest"/> instances from this container.
8196
/// </summary>
8297
/// <param name="requests">Requests to remove.</param>
8398
public override void Remove(params TRequest[] requests)

Requests/RequestContainer.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,28 @@ protected set
7373
/// Accesses all <see cref="IRequest"/> instances in this container.
7474
/// </summary>
7575
/// <returns>Returns an array of <see cref="IRequest"/> instances.</returns>
76-
public TRequest this[int key]
76+
public virtual TRequest this[int key]
7777
{
7878
get => _requests[key];
79-
set => _requests[key] = value;
79+
set
80+
{
81+
if (!_requests[key].Equals(value))
82+
{
83+
_requests[key].StateChanged -= StateChanged;
84+
Remove(_requests[key]);
85+
_requests[key] = value;
86+
if (_isCanceled)
87+
_requests[key].Cancel();
88+
else if (_disposed)
89+
_requests[key].Dispose();
90+
else if (!_isrunning)
91+
_requests[key].Pause();
92+
93+
_requests[key].StateChanged += OnStateChanged;
94+
NewTaskCompletion();
95+
OnStateChanged(this, _requests[key].State);
96+
}
97+
}
8098
}
8199

82100
/// <summary>

Requests/Requests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
<PackageTags>async; channel; priority; request; parallel; </PackageTags>
1717
<RepositoryUrl>https://github.com/TypNull/Requests</RepositoryUrl>
1818
<PackageIcon>logo.png</PackageIcon>
19-
<Version>2.1.0</Version>
19+
<Version>2.1.1</Version>
2020
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
2121
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2222
<PackageId>Shard.Requests</PackageId>
23-
<PackageReleaseNotes>Fix descriptions
24-
Add RequestContainer IRequest.StartRequestAsync()</PackageReleaseNotes>
23+
<PackageReleaseNotes>Fix RequestContainer Array access</PackageReleaseNotes>
2524
</PropertyGroup>
2625

2726
<ItemGroup>

0 commit comments

Comments
 (0)