Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

using ReactiveMarbles.CacheDatabase.Core;

namespace ReactiveMarbles.CacheDatabase.SystemTextJson
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
6 changes: 1 addition & 5 deletions src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ReactiveMarbles.CacheDatabase.Benchmarks
{
Expand Down
5 changes: 1 addition & 4 deletions src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Reactive.Concurrency;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
34 changes: 7 additions & 27 deletions src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down Expand Up @@ -48,15 +48,8 @@ public HttpService()
/// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
/// <param name="absoluteExpiration">An optional expiration date.</param>
/// <returns>The data downloaded from the URL.</returns>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration);
}
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache!!, string url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) =>
blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration);

/// <summary>
/// Download data from an HTTP URL and insert the result into the
Expand All @@ -71,20 +64,9 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string url, HttpMet
/// <param name="fetchAlways">Force a web request to always be issued, skipping the cache.</param>
/// <param name="absoluteExpiration">An optional expiration date.</param>
/// <returns>The data downloaded from the URL.</returns>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, Uri url, HttpMethod? method = default, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

if (url is null)
{
throw new ArgumentNullException(nameof(url));
}

return blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration);
}
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
? throw new ArgumentNullException(nameof(url))
: blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration);

/// <summary>
/// Download data from an HTTP URL and insert the result into the
Expand Down Expand Up @@ -186,9 +168,7 @@ protected virtual IObservable<HttpResponseMessage> MakeWebRequest(
int retries = 3,
TimeSpan? timeout = null)
{
IObservable<HttpResponseMessage> request;

request = Observable.Defer(() =>
var request = Observable.Defer(() =>
{
var httpRequest = CreateWebRequest(uri, method, headers);

Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
3 changes: 1 addition & 2 deletions src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
Expand Down
6 changes: 1 addition & 5 deletions src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
/// <summary>
Expand Down
6 changes: 1 addition & 5 deletions src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
/// <summary>
Expand Down
22 changes: 7 additions & 15 deletions src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;

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

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

/// <summary>
/// Erases the login associated with the specified host.
/// </summary>
/// <param name="blobCache">The blob cache where to erase the data.</param>
/// <param name="host">The host associated with the data.</param>
/// <returns>A observable which signals when the erase is completed.</returns>
public static IObservable<Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default")
{
return blobCache.InvalidateObject<(string, string)>("login:" + host);
}
public static IObservable<Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default") =>
blobCache.InvalidateObject<(string, string)>("login:" + host);
}
}
6 changes: 1 addition & 5 deletions src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand Down
68 changes: 21 additions & 47 deletions src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Reactive;
using System.Text;

namespace ReactiveMarbles.CacheDatabase.Core
{
Expand All @@ -24,15 +23,10 @@ public static class RelativeTimeExtensions
/// <param name="data">The data for the entry.</param>
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
/// <returns>A observable which will signal when the item is added.</returns>
public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration);
}
public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration) =>
blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration);

/// <summary>
/// Inserts a item into the cache.
Expand All @@ -43,15 +37,10 @@ public static IObservable<Unit> Insert(this IBlobCache blobCache, string key, by
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
/// <typeparam name="T">The type of item to insert.</typeparam>
/// <returns>A observable which will signal when the item is added.</returns>
public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, string key, T value, TimeSpan expiration)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration);
}
public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, string key, T value, TimeSpan expiration) =>
blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration);

/// <summary>
/// Downloads the specified url if there is not already a entry in the cache.
Expand All @@ -63,15 +52,10 @@ public static IObservable<Unit> InsertObject<T>(this IBlobCache blobCache, strin
/// <param name="headers">The headers to specify when getting the entry.</param>
/// <param name="fetchAlways">If we should fetch always and not return the cache entry if available.</param>
/// <returns>A observable which will signal when the data is available.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
}
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false) =>
blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);

/// <summary>
/// Downloads the specified url if there is not already a entry in the cache.
Expand All @@ -83,15 +67,10 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, string
/// <param name="headers">The headers to specify when getting the entry.</param>
/// <param name="fetchAlways">If we should fetch always and not return the cache entry if available.</param>
/// <returns>A observable which will signal when the data is available.</returns>
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);
}
public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable<KeyValuePair<string, string>>? headers = null, bool fetchAlways = false) =>
blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration);

/// <summary>
/// Saves a username and password.
Expand All @@ -102,14 +81,9 @@ public static IObservable<byte[]> DownloadUrl(this IBlobCache blobCache, Uri url
/// <param name="host">The host to store against.</param>
/// <param name="expiration">A timespan that will be added to the current DateTime.</param>
/// <returns>A observable which will signal when the item is added.</returns>
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration)
{
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}

return blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration);
}
public static IObservable<Unit> SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration) =>
blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration);
}
}
Loading