-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/UniversalFiles.Swarm/Extensions/UFileProviderExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2023-present Etherna SA | ||
// This file is part of UniversalFiles. | ||
// | ||
// UniversalFiles is free software: you can redistribute it and/or modify it under the terms of the | ||
// GNU Lesser General Public License as published by the Free Software Foundation, | ||
// either version 3 of the License, or (at your option) any later version. | ||
// | ||
// UniversalFiles is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along with UniversalFiles. | ||
// If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using Etherna.BeeNet; | ||
using System; | ||
|
||
namespace Etherna.UniversalFiles.Extensions | ||
{ | ||
public static class UFileProviderExtension | ||
{ | ||
public static UFileProvider UseSwarmUFiles( | ||
this UFileProvider fileProvider, | ||
IBeeClient beeClient) | ||
{ | ||
ArgumentNullException.ThrowIfNull(fileProvider, nameof(fileProvider)); | ||
|
||
fileProvider.RegisterUUriType<SwarmUUri>(uuri => new SwarmUFile(beeClient, uuri)); | ||
return fileProvider; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023-present Etherna SA | ||
// This file is part of UniversalFiles. | ||
// | ||
// UniversalFiles is free software: you can redistribute it and/or modify it under the terms of the | ||
// GNU Lesser General Public License as published by the Free Software Foundation, | ||
// either version 3 of the License, or (at your option) any later version. | ||
// | ||
// UniversalFiles is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along with UniversalFiles. | ||
// If not, see <https://www.gnu.org/licenses/>. | ||
|
||
namespace Etherna.UniversalFiles | ||
{ | ||
public interface IUFileProvider | ||
{ | ||
UFile BuildNewUFile(UUri uuri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023-present Etherna SA | ||
// This file is part of UniversalFiles. | ||
// | ||
// UniversalFiles is free software: you can redistribute it and/or modify it under the terms of the | ||
// GNU Lesser General Public License as published by the Free Software Foundation, | ||
// either version 3 of the License, or (at your option) any later version. | ||
// | ||
// UniversalFiles is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along with UniversalFiles. | ||
// If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
|
||
namespace Etherna.UniversalFiles | ||
{ | ||
public class UFileProvider : IUFileProvider | ||
{ | ||
// Fields. | ||
private readonly Dictionary<Type, Func<UUri, UFile>> uFileBuilders = new(); //<typeof(UUri), UFile builder> | ||
|
||
public UFileProvider(IHttpClientFactory httpClientFactory) | ||
{ | ||
uFileBuilders[typeof(BasicUUri)] = uuri => new BasicUFile((BasicUUri)uuri, httpClientFactory); | ||
} | ||
|
||
// Methods. | ||
public UFile BuildNewUFile(UUri uuri) | ||
{ | ||
ArgumentNullException.ThrowIfNull(uuri, nameof(uuri)); | ||
|
||
var builder = uFileBuilders[uuri.GetType()]; | ||
return builder(uuri); | ||
} | ||
|
||
public void RegisterUUriType<TUUri>(Func<TUUri, UFile> builder) where TUUri : UUri => | ||
uFileBuilders[typeof(TUUri)] = uuri => builder((TUUri)uuri); | ||
} | ||
} |