Skip to content

Commit

Permalink
Fixes in file explorer (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperJMN authored Oct 4, 2023
1 parent 49ef02c commit 7df631e
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 50 deletions.
58 changes: 29 additions & 29 deletions AvaloniaSyncer.Tests/AvaloniaSyncer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.2" />
<PackageReference Include="DynamicData" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Zafiro.FileSystem" Version="4.0.23" />
<PackageReference Include="Zafiro.FileSystem.Local" Version="4.0.23" />
<PackageReference Include="Zafiro.FileSystem.SeaweedFS" Version="4.0.23" />
<PackageReference Include="Zafiro.FileSystem.Sftp" Version="4.0.23" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.2" />
<PackageReference Include="DynamicData" Version="8.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Zafiro.FileSystem" Version="4.0.25" />
<PackageReference Include="Zafiro.FileSystem.Local" Version="4.0.25" />
<PackageReference Include="Zafiro.FileSystem.SeaweedFS" Version="4.0.25" />
<PackageReference Include="Zafiro.FileSystem.Sftp" Version="4.0.25" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\AvaloniaSyncer\AvaloniaSyncer.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\AvaloniaSyncer\AvaloniaSyncer.csproj" />
</ItemGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion AvaloniaSyncer.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AvaloniaSyncer.Sections.Explorer.FileSystemConnections.Serialization;
using AvaloniaSyncer.Sections.Explorer.FileSystemConnections.Serialization.Model;
using CSharpFunctionalExtensions;
using Serilog;
using File = System.IO.File;

namespace AvaloniaSyncer.Tests;
Expand All @@ -14,7 +15,7 @@ public async Task Test1()
{
var store = new ConfigurationStore(() => File.OpenRead("Connections.json"), () => File.OpenWrite("Connections.json"));
var repoResult = await store.Load()
.Map(list => new FileSystemConnectionRepository(list.Select(Mapper.ToSystem)))
.Map(list => new FileSystemConnectionRepository(list.Select(connection => Mapper.ToSystem(connection, Maybe<ILogger>.None))))
.Check(repo =>
{
var connections = repo.Connections.Select(Mapper.ToConfiguration);
Expand Down
3 changes: 2 additions & 1 deletion src/AvaloniaSyncer/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Markup.Xaml;
using AvaloniaSyncer.ViewModels;
using AvaloniaSyncer.Views;
using CSharpFunctionalExtensions;
using Serilog;
using Zafiro.Avalonia.Mixins;

Expand All @@ -24,7 +25,7 @@ public override void OnFrameworkInitializationCompleted()
{
this.Connect(() => new MainView(), view =>
{
var vm = new ViewModelFactory(ApplicationLifetime!, view);
var vm = new ViewModelFactory(ApplicationLifetime!, view, Maybe<ILogger>.From(Log.Logger));
var sections = new List<Section>
{
Expand Down
15 changes: 8 additions & 7 deletions src/AvaloniaSyncer/AvaloniaSyncer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.3" />
<PackageReference Include="HttpClient.Extensions.LoggingHttpMessageHandler" Version="1.0.3" />
<PackageReference Include="Nuke.Common" Version="7.0.2" />
<PackageReference Include="ReactiveUI.Fody" Version="19.4.1" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.1" />
<PackageReference Include="ReactiveUI.Validation" Version="3.1.7" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Zafiro.Avalonia" Version="3.0.38" />
<PackageReference Include="Zafiro.Avalonia.Dialogs" Version="3.0.38" />
<PackageReference Include="Zafiro.Avalonia.FileExplorer.Pickers" Version="1.0.7" />
<PackageReference Include="Zafiro.FileSystem.Local" Version="4.0.23" />
<PackageReference Include="Zafiro.FileSystem.SeaweedFS" Version="4.0.23" />
<PackageReference Include="Zafiro.FileSystem.Sftp" Version="4.0.23" />
<PackageReference Include="Zafiro.Avalonia" Version="3.0.39" />
<PackageReference Include="Zafiro.Avalonia.Dialogs" Version="3.0.39" />
<PackageReference Include="Zafiro.Avalonia.FileExplorer" Version="1.0.10" />
<PackageReference Include="Zafiro.Avalonia.FileExplorer.Pickers" Version="1.0.10" />
<PackageReference Include="Zafiro.FileSystem.Local" Version="4.0.25" />
<PackageReference Include="Zafiro.FileSystem.SeaweedFS" Version="4.0.25" />
<PackageReference Include="Zafiro.FileSystem.Sftp" Version="4.0.25" />
<PackageReference Include="Zafiro.UI" Version="4.0.10" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using AvaloniaSyncer.Sections.Explorer.FileSystemConnections.Serialization;
using CSharpFunctionalExtensions;
using ReactiveUI;
using Serilog;
using Zafiro.Avalonia.FileExplorer.Clipboard;
using Zafiro.Avalonia.FileExplorer.TransferManager;
using Zafiro.CSharpFunctionalExtensions;
Expand All @@ -20,10 +21,12 @@ namespace AvaloniaSyncer.Sections.Explorer;

public class ExplorerSectionViewModel : ReactiveObject
{
private readonly Maybe<ILogger> logger;
private readonly ObservableAsPropertyHelper<IList<FileSystemConnectionViewModel>> connections;

public ExplorerSectionViewModel(INotificationService notificationService, IClipboard clipboard, ITransferManager transferManager)
public ExplorerSectionViewModel(INotificationService notificationService, IClipboard clipboard, ITransferManager transferManager, Maybe<ILogger> logger)
{
this.logger = logger;
Load = ReactiveCommand.CreateFromObservable(() => Observable.FromAsync(() => GetConnections())
.Successes()
.SelectMany(x => x)
Expand All @@ -41,7 +44,7 @@ private async Task<Result<ReadOnlyObservableCollection<IFileSystemConnection>>>
{
var store = new ConfigurationStore(() => File.OpenRead("Connections.json"), () => File.OpenWrite("Connections.json"));
var configs = await Async.Await(() => store.Load())
.Map(enumerable => enumerable.Select(connection => Mapper.ToSystem(connection)))
.Map(enumerable => enumerable.Select(connection => Mapper.ToSystem(connection, logger)))
.Map(enumerable => new FileSystemConnectionRepository(enumerable))
.Map(r => r.Connections);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Panel>
<DockPanel>
<ContentControl Content="{Binding ToolBar}" DockPanel.Dock="Top" />
<ContentControl Content="{Binding Address}" DockPanel.Dock="Top" />
<ContentControl Content="{Binding AddressViewModel}" DockPanel.Dock="Top" />
<ContentControl Content="{Binding Details^}" />
</DockPanel>
<transferManager:LightTransferManagerView Width="400" VerticalAlignment="Bottom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FileSystemConnectionViewModel(IFileSystemConnection connection, INotifica
Load = ReactiveCommand.CreateFromObservable(() => Observable.FromAsync(connection.FileSystem));
explorer = Load
.Successes()
.Select(system => new FileSystemExplorer(system, DirectoryListing.GetAll, notificationService, clipboardViewModel, transferManager))
.Select(system => new FileSystemExplorer(system, notificationService, clipboardViewModel, transferManager))
.ToProperty(this, x => x.FileSystemExplorer);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using CSharpFunctionalExtensions;
using HttpClient.Extensions.LoggingHttpMessageHandler;
using Serilog;
using Zafiro.FileSystem;
using Zafiro.FileSystem.SeaweedFS;
Expand All @@ -11,19 +13,38 @@ namespace AvaloniaSyncer.Sections.Explorer.FileSystemConnections;
internal class SeaweedFileFileSystemConnection : Serialization.IFileSystemConnection
{
private readonly Uri uri;
private readonly Maybe<ILogger> logger;

public SeaweedFileFileSystemConnection(string name, Uri uri)
public SeaweedFileFileSystemConnection(string name, Uri uri, Maybe<ILogger> logger)
{
this.uri = uri;
this.logger = logger;
Name = name;
}

public Task<Result<IFileSystem>> FileSystem()
{
var seaweedFSClient = new SeaweedFSClient(new System.Net.Http.HttpClient() { BaseAddress = uri });
IFileSystem seaweedFileSystem = new SeaweedFileSystem(seaweedFSClient, Maybe<ILogger>.None);
var handler = GetHandler();

var httpClient = new System.Net.Http.HttpClient(handler)
{
BaseAddress = uri,
};

var seaweedFSClient = new SeaweedFSClient(httpClient);
IFileSystem seaweedFileSystem = new SeaweedFileSystem(seaweedFSClient, logger);
return Task.FromResult(Result.Success(seaweedFileSystem));
}

private HttpMessageHandler GetHandler()
{
return logger.Match<HttpMessageHandler, ILogger>(f =>
{
var loggingHttpMessageHandler = new LoggingHttpMessageHandler(new LoggerAdapter(f));
loggingHttpMessageHandler.InnerHandler = new HttpClientHandler();
return loggingHttpMessageHandler;
}, () => new HttpClientHandler());
}

public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using AvaloniaSyncer.Sections.Explorer.FileSystemConnections.Serialization.Model;
using CSharpFunctionalExtensions;
using Serilog;

namespace AvaloniaSyncer.Sections.Explorer.FileSystemConnections.Serialization;

Expand Down Expand Up @@ -35,14 +37,14 @@ public static Connection ToConfiguration(IFileSystemConnection fileSystemConnect
};
}

public static IFileSystemConnection ToSystem(Connection connection)
public static IFileSystemConnection ToSystem(Connection connection, Maybe<ILogger> logger)
{
switch (connection.Parameters)
{
case Local:
return new LocalFileSystemConnection(connection.Name);
case SeaweedFS fs:
return new SeaweedFileFileSystemConnection(connection.Name, fs.Uri);
return new SeaweedFileFileSystemConnection(connection.Name, fs.Uri, logger);
case Sftp sftp:
var info = new SftpConnectionParameters(sftp.Host, sftp.Port, sftp.Username, sftp.Password);
return new SftpFileFileSystemConnection(connection.Name, info);
Expand Down
9 changes: 6 additions & 3 deletions src/AvaloniaSyncer/ViewModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ namespace AvaloniaSyncer;

public class ViewModelFactory
{
public ViewModelFactory(IApplicationLifetime applicationLifetime, Visual control)
private readonly Maybe<ILogger> logger;

public ViewModelFactory(IApplicationLifetime applicationLifetime, Visual control, Maybe<ILogger> logger)
{
this.logger = logger;
NotificationService = new NotificationService(new WindowNotificationManager(TopLevel.GetTopLevel(control)));
DialogService = Zafiro.Avalonia.Dialogs.DialogService.Create(applicationLifetime, configureWindow: Maybe<Action<ConfigureWindowContext>>.From(ConfigureWindow));
Plugins = AvailablePlugins();
Expand All @@ -45,7 +48,7 @@ public ViewModelFactory(IApplicationLifetime applicationLifetime, Visual control

public SyncSectionViewModel GetSyncViewModel()
{
return new SyncSectionViewModel(DialogService, Plugins, NotificationService, Maybe.From(Log.Logger));
return new SyncSectionViewModel(DialogService, Plugins, NotificationService, logger);
}

public SettingsSectionViewModel GetSettingsViewModel()
Expand Down Expand Up @@ -74,6 +77,6 @@ private IPlugin[] AvailablePlugins()

public ExplorerSectionViewModel GetExploreSection()
{
return new ExplorerSectionViewModel(NotificationService, Clipboard, TransferManager);
return new ExplorerSectionViewModel(NotificationService, Clipboard, TransferManager, logger);
}
}

0 comments on commit 7df631e

Please sign in to comment.