Skip to content

Commit 3d4a977

Browse files
authored
Fix GetOrCreateObject Update Copyright date range (#88)
* Fix GetOrCreateObject Update Copyright date range GetOrCreateObject did not add any data to the database Copyright updated form 2019 to 2021 to 2019 to 2022 Update formatting Use auto Null parameter check where possible i.e. key!! * Clean up code Use more expression bodies where possible
1 parent e2aa403 commit 3d4a977

File tree

27 files changed

+120
-270
lines changed

27 files changed

+120
-270
lines changed

src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
65
using System.Text.Json;
7-
using System.Text.Json.Serialization;
8-
96
using ReactiveMarbles.CacheDatabase.Core;
107

118
namespace ReactiveMarbles.CacheDatabase.SystemTextJson

src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.IO;
8-
using System.Linq;
97
using System.Reactive.Disposables;
10-
using System.Text;
118
using System.Threading;
12-
using System.Threading.Tasks;
139

1410
namespace ReactiveMarbles.CacheDatabase.Benchmarks
1511
{

src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
6-
using System.Collections.Generic;
75
using System.Reactive.Concurrency;
8-
using System.Text;
96

107
namespace ReactiveMarbles.CacheDatabase.Core
118
{

src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

@@ -48,15 +48,8 @@ public HttpService()
4848
/// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
4949
/// <param name="absoluteExpiration">An optional expiration date.</param>
5050
/// <returns>The data downloaded from the URL.</returns>
51-
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
52-
{
53-
if (blobCache is null)
54-
{
55-
throw new ArgumentNullException(nameof(blobCache));
56-
}
57-
58-
return blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration);
59-
}
51+
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache!!, string url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) =>
52+
blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration);
6053

6154
/// <summary>
6255
/// Download data from an HTTP URL and insert the result into the
@@ -71,20 +64,9 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string url, HttpMet
7164
/// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
7265
/// <param name="absoluteExpiration">An optional expiration date.</param>
7366
/// <returns>The data downloaded from the URL.</returns>
74-
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, Uri url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
75-
{
76-
if (blobCache is null)
77-
{
78-
throw new ArgumentNullException(nameof(blobCache));
79-
}
80-
81-
if (url is null)
82-
{
83-
throw new ArgumentNullException(nameof(url));
84-
}
85-
86-
return blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration);
87-
}
67+
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache!!, Uri url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) => url is null
68+
? throw new ArgumentNullException(nameof(url))
69+
: blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration);
8870

8971
/// <summary>
9072
/// Download data from an HTTP URL and insert the result into the
@@ -186,9 +168,7 @@ protected virtual IObservable<HttpResponseMessage> MakeWebRequest(
186168
int retries = 3,
187169
TimeSpan? timeout = null)
188170
{
189-
IObservable<HttpResponseMessage> request;
190-
191-
request = Observable.Defer(() =>
171+
var request = Observable.Defer(() =>
192172
{
193173
var httpRequest = CreateWebRequest(uri, method, headers);
194174

src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

55
using System;
66
using System.Collections.Generic;
77
using System.Net.Http;
8-
using System.Text;
98

109
namespace ReactiveMarbles.CacheDatabase.Core
1110
{

src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
6-
using System.Collections.Generic;
7-
using System.Text;
8-
95
namespace ReactiveMarbles.CacheDatabase.Core
106
{
117
/// <summary>

src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
6-
using System.Collections.Generic;
7-
using System.Text;
8-
95
namespace ReactiveMarbles.CacheDatabase.Core
106
{
117
/// <summary>
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.Reactive;
87
using System.Reactive.Linq;
9-
using System.Text;
108

119
namespace ReactiveMarbles.CacheDatabase.Core
1210
{
@@ -26,10 +24,8 @@ public static class LoginExtensions
2624
/// <param name="host">The host to associate with the data.</param>
2725
/// <param name="absoluteExpiration">An optional expiration date.</param>
2826
/// <returns>A observable which signals when the insert is completed.</returns>
29-
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host = "default", DateTimeOffset? absoluteExpiration = null)
30-
{
31-
return blobCache.InsertObject("login:" + host, new Tuple<string, string>(user, password), absoluteExpiration);
32-
}
27+
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host = "default", DateTimeOffset? absoluteExpiration = null) =>
28+
blobCache.InsertObject("login:" + host, new Tuple<string, string>(user, password), absoluteExpiration);
3329

3430
/// <summary>
3531
/// Returns the currently cached user/password. If the cache does not
@@ -39,20 +35,16 @@ public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, strin
3935
/// <param name="blobCache">The blob cache where to get the data.</param>
4036
/// <param name="host">The host associated with the data.</param>
4137
/// <returns>A Future result representing the user/password Tuple.</returns>
42-
public static IObservable<LoginInfo> GetLoginAsync(this ISecureBlobCache blobCache, string host = "default")
43-
{
44-
return blobCache.GetObject<(string, string)>("login:" + host).Select(x => new LoginInfo(x));
45-
}
38+
public static IObservable<LoginInfo> GetLoginAsync(this ISecureBlobCache blobCache, string host = "default") =>
39+
blobCache.GetObject<(string, string)>("login:" + host).Select(x => new LoginInfo(x));
4640

4741
/// <summary>
4842
/// Erases the login associated with the specified host.
4943
/// </summary>
5044
/// <param name="blobCache">The blob cache where to erase the data.</param>
5145
/// <param name="host">The host associated with the data.</param>
5246
/// <returns>A observable which signals when the erase is completed.</returns>
53-
public static IObservable<Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default")
54-
{
55-
return blobCache.InvalidateObject<(string, string)>("login:" + host);
56-
}
47+
public static IObservable<Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default") =>
48+
blobCache.InvalidateObject<(string, string)>("login:" + host);
5749
}
5850
}

src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

5-
using System;
6-
using System.Collections.Generic;
7-
using System.Text;
8-
95
namespace ReactiveMarbles.CacheDatabase.Core
106
{
117
/// <summary>

src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

55
using System;
6-
using System.Collections.Generic;
7-
using System.Text;
86

97
namespace ReactiveMarbles.CacheDatabase.Core
108
{

src/ReactiveMarbles.CacheDatabase.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
1+
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
22
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for full license information.
44

55
using System;
66
using System.Collections.Generic;
77
using System.Net.Http;
88
using System.Reactive;
9-
using System.Text;
109

1110
namespace ReactiveMarbles.CacheDatabase.Core
1211
{
@@ -24,15 +23,10 @@ public static class RelativeTimeExtensions
2423
/// <param name="data">The data for the entry.</param>
2524
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
2625
/// <returns>A observable which will signal when the item is added.</returns>
27-
public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration)
28-
{
29-
if (blobCache is null)
30-
{
31-
throw new ArgumentNullException(nameof(blobCache));
32-
}
33-
34-
return blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration);
35-
}
26+
public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration) =>
27+
blobCache is null
28+
? throw new ArgumentNullException(nameof(blobCache))
29+
: blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration);
3630

3731
/// <summary>
3832
/// Inserts a item into the cache.
@@ -43,15 +37,10 @@ public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, by
4337
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
4438
/// <typeparam name="T">The type of item to insert.</typeparam>
4539
/// <returns>A observable which will signal when the item is added.</returns>
46-
public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, string key, T value, TimeSpan expiration)
47-
{
48-
if (blobCache is null)
49-
{
50-
throw new ArgumentNullException(nameof(blobCache));
51-
}
52-
53-
return blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration);
54-
}
40+
public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, string key, T value, TimeSpan expiration) =>
41+
blobCache is null
42+
? throw new ArgumentNullException(nameof(blobCache))
43+
: blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration);
5544

5645
/// <summary>
5746
/// Downloads the specified url if there is not already a entry in the cache.
@@ -63,15 +52,10 @@ public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, strin
6352
/// <param name="headers">The headers to specify when getting the entry.</param>
6453
/// <param name="fetchAlways">If we should fetch always and not return the cache entry if available.</param>
6554
/// <returns>A observable which will signal when the data is available.</returns>
66-
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false)
67-
{
68-
if (blobCache is null)
69-
{
70-
throw new ArgumentNullException(nameof(blobCache));
71-
}
72-
73-
return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
74-
}
55+
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false) =>
56+
blobCache is null
57+
? throw new ArgumentNullException(nameof(blobCache))
58+
: blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
7559

7660
/// <summary>
7761
/// Downloads the specified url if there is not already a entry in the cache.
@@ -83,15 +67,10 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string
8367
/// <param name="headers">The headers to specify when getting the entry.</param>
8468
/// <param name="fetchAlways">If we should fetch always and not return the cache entry if available.</param>
8569
/// <returns>A observable which will signal when the data is available.</returns>
86-
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false)
87-
{
88-
if (blobCache is null)
89-
{
90-
throw new ArgumentNullException(nameof(blobCache));
91-
}
92-
93-
return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
94-
}
70+
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false) =>
71+
blobCache is null
72+
? throw new ArgumentNullException(nameof(blobCache))
73+
: blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
9574

9675
/// <summary>
9776
/// Saves a username and password.
@@ -102,14 +81,9 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url
10281
/// <param name="host">The host to store against.</param>
10382
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
10483
/// <returns>A observable which will signal when the item is added.</returns>
105-
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration)
106-
{
107-
if (blobCache is null)
108-
{
109-
throw new ArgumentNullException(nameof(blobCache));
110-
}
111-
112-
return blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration);
113-
}
84+
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration) =>
85+
blobCache is null
86+
? throw new ArgumentNullException(nameof(blobCache))
87+
: blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration);
11488
}
11589
}

0 commit comments

Comments
 (0)