Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from j2ghz/feature/libUpdate
Browse files Browse the repository at this point in the history
update libraries, mainly reactivex to v4
  • Loading branch information
j2ghz authored Sep 13, 2018
2 parents fa90ece + 340f087 commit ad74702
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 108 deletions.
7 changes: 6 additions & 1 deletion src/ModSink.CLI/ModSink.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="2.3.2" />
<PackageReference Include="Flurl.Http" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Serilog.Enrichers.Demystify" Version="0.1.0-dev-00016" />
<PackageReference Include="Serilog.Enrichers.Memory" Version="1.0.4" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 20 additions & 11 deletions src/ModSink.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using ModSink.Common.Models.Group;
using ModSink.Common.Models.Repo;
using Serilog;
using Serilog.Formatting.Compact;
using Serilog.Sinks.SystemConsole.Themes;

namespace ModSink.CLI
{
Expand Down Expand Up @@ -83,22 +85,21 @@ private static void AddColCheck(this CommandLineApplication app)
var path = Path.Combine(Directory.GetCurrentDirectory(), pathStr);
IHashFunction xxhash = new XXHash64();
var hashing = new HashingService(xxhash);
hashing.GetFiles(new DirectoryInfo(path))
foreach (var g in hashing.GetFiles(new DirectoryInfo(path))
.Select(f =>
{
var hash = hashing.GetFileHash(f, CancellationToken.None).GetAwaiter().GetResult();
Console.WriteLine($"{hash} {Path.GetRelativePath(path, f.FullName)}");
return new {f, hash};
})
.GroupBy(a => a.hash.ToString())
.Where(g => g.Count() > 1)
.ForEach(g =>
{
Console.WriteLine(g.Key);
foreach (var i in g)
Console.WriteLine($" {i.f.FullName}");
Console.WriteLine();
});
.Where(g => g.Count() > 1))
{
Console.WriteLine(g.Key);
foreach (var i in g)
Console.WriteLine($" {i.f.FullName}");
Console.WriteLine();
}

Console.WriteLine("Done.");
return 0;
Expand Down Expand Up @@ -347,10 +348,18 @@ private static void DumpRepo(Repo repo)
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console(outputTemplate:
"{Timestamp:HH:mm:ss} {Level:u3} [{SourceContext}] {Properties} {Message:lj}{NewLine}{Exception}")
.WriteTo.Console(
theme: AnsiConsoleTheme.Code,
outputTemplate:
"{Timestamp:HH:mm:ss} {Level:u3} {SourceContext} {Message:lj} {Properties} {NewLine}{Exception}")
.WriteTo.File(new CompactJsonFormatter(), "log.txt", fileSizeLimitBytes: 10 * 1024 * 1024,
buffered: true, flushToDiskInterval: 10.Seconds(), rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.Enrich.WithDemystifiedStackTraces()
.Enrich.WithMemoryUsage()
.Enrich.WithThreadId()
.CreateLogger();

var app = new CommandLineApplication
Expand Down
12 changes: 7 additions & 5 deletions src/ModSink.Common.Tests/ModSink.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="22.3.2" />
<PackageReference Include="coverlet.msbuild" Version="2.1.1" />
<PackageReference Include="Bogus" Version="23.0.3" />
<PackageReference Include="coverlet.msbuild" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="JetBrains.DotMemoryUnit" Version="3.0.20171219.105559" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.9.0" />
<PackageReference Include="ReactiveUI.Testing" Version="8.3.1" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="ReactiveUI.Testing" Version="8.7.2" />
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions src/ModSink.Common/Client/ActiveDownload.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.IO;
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Runtime.CompilerServices;
using Anotar.Serilog;
using Humanizer.Bytes;
using ReactiveUI;

namespace ModSink.Common.Client
{
public class ActiveDownload : ReactiveObject, IDisposable
public class ActiveDownload : IDisposable
{
private readonly CompositeDisposable disposable = new CompositeDisposable();

Expand All @@ -21,11 +21,11 @@ public ActiveDownload(IConnectableObservable<DownloadProgress> downloadProgress,
{
Name = name;
LogTo.Verbose("[{download}] Created ActiveDownload", Name);
downloadProgress.Subscribe(progress).DisposeWith(disposable);
downloadProgress.Connect().DisposeWith(disposable);
progress.DistinctUntilChanged(dp => dp.State).Subscribe(dp =>
LogTo.Verbose("[{download}] State changed to {state}", Name, dp.State)).DisposeWith(disposable);
progress.Subscribe(_ => { }, completed).DisposeWith(disposable);
disposable.Add(downloadProgress.Subscribe(progress));
disposable.Add(downloadProgress.Connect());
disposable.Add(progress.DistinctUntilChanged(dp => dp.State).Subscribe(dp =>
LogTo.Verbose("[{download}] State changed to {state}", Name, dp.State)));
disposable.Add(progress.Subscribe(_ => { }, completed));
}

public string Name { get; }
Expand Down
28 changes: 12 additions & 16 deletions src/ModSink.Common/Client/ClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
using ModSink.Common.Models.Client;
using ModSink.Common.Models.Group;
using ModSink.Common.Models.Repo;
using ReactiveUI;

namespace ModSink.Common.Client
{
public class ClientService : IDisposable
{
private readonly CompositeDisposable disposable = new CompositeDisposable();
private readonly CompositeDisposable d = new CompositeDisposable();
private readonly IDownloader downloader;
private readonly IFileAccessService fileAccessService;

Expand All @@ -36,16 +35,13 @@ public ClientService(IDownloader downloader, IFormatter serializationFormatter,
this.serializationFormatter = serializationFormatter;
filesAvailable.Edit(l => { l.AddOrUpdate(fileAccessService.FilesAvailable()); });
LogTo.Warning("Creating pipeline");
Repos = DynamicDataChain.GetReposFromGroups(GroupUrls.Connect(), Load<Group>, Load<Repo>).AsObservableCache().DisposeWith(disposable);
OnlineFiles = DynamicDataChain.GetOnlineFileFromRepos(Repos.Connect())
.AsObservableCache()
.DisposeWith(disposable);
Modpacks = DynamicDataChain.GetModpacksFromRepos(Repos.Connect()).AsObservableCache()
.DisposeWith(disposable);
Repos = DynamicDataChain.GetReposFromGroups(GroupUrls.Connect(),Load<Group>,Load<Repo>).AsObservableCache();
d.Add(Repos);
OnlineFiles = DynamicDataChain.GetOnlineFileFromRepos(Repos.Connect()).AsObservableCache();
d.Add(OnlineFiles);
Modpacks = DynamicDataChain.GetModpacksFromRepos(Repos.Connect()).AsObservableCache();
d.Add(Modpacks);
QueuedDownloads = DynamicDataChain.GetDownloadsFromModpacks(Modpacks.Connect())
.AsObservableCache()
.DisposeWith(disposable)
.Connect()
.LeftJoin(filesAvailable.Connect(), f => f,
(required, available) => !available.HasValue
? Optional<FileSignature>.Create(required)
Expand All @@ -54,8 +50,8 @@ public ClientService(IDownloader downloader, IFormatter serializationFormatter,
.Transform(opt => opt.Value)
.InnerJoin(OnlineFiles.Connect(), of => of.FileSignature,
(fs, of) => new QueuedDownload(fs, of.Uri))
.AsObservableCache()
.DisposeWith(disposable);
.AsObservableCache();
d.Add(QueuedDownloads);
ActiveDownloads = QueuedDownloads.Connect()
.Sort(Comparer<QueuedDownload>.Create((_, __) => 0))
.Top(5)
Expand All @@ -74,8 +70,8 @@ public ClientService(IDownloader downloader, IFormatter serializationFormatter,
}, qd.FileSignature.ToString());
})
.LogVerbose("activeDownloads")
.AsObservableCache()
.DisposeWith(disposable);
.AsObservableCache();
d.Add(ActiveDownloads);
}

public IObservableCache<ActiveDownload, FileSignature> ActiveDownloads { get; }
Expand All @@ -87,7 +83,7 @@ public ClientService(IDownloader downloader, IFormatter serializationFormatter,

public void Dispose()
{
disposable.Dispose();
d.Dispose();
}

private void AddNewFile(FileSignature fileSignature)
Expand Down
3 changes: 1 addition & 2 deletions src/ModSink.Common/Client/DynamicDataChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using ModSink.Common.Models.Client;
using ModSink.Common.Models.Group;
using ModSink.Common.Models.Repo;
using ReactiveUI;

namespace ModSink.Common.Client
{
Expand All @@ -16,7 +15,7 @@ public static IObservable<IChangeSet<FileSignature, FileSignature>> GetDownloads
IObservable<IChangeSet<Modpack, Guid>> modpacks)
{
return modpacks
.AutoRefresh(m => m.Selected, scheduler: RxApp.TaskpoolScheduler)
.AutoRefresh(m => m.Selected)
.Filter(m => m.Selected)
.TransformMany(m => m.Mods, m => m.Mod.Id)
.TransformMany(m => m.Mod.Files.Values, fs => fs);
Expand Down
9 changes: 6 additions & 3 deletions src/ModSink.Common/Client/FileAccessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ IEnumerable<FileSignature> IFileAccessService.FilesAvailable()
)
fileInfo.Delete();

return localDir.EnumerateFiles()
foreach (var file in localDir.EnumerateFiles()
.Where(f => !f.Name.EndsWith(".tmp"))
.Select(f => new FileSignature(new HashValue(f.Name), f.Length))
.Do(file => LogTo.Verbose("File {file} has been discovered", file.Hash));
.Select(f => new FileSignature(new HashValue(f.Name), f.Length)))
{
LogTo.Verbose("File {file} has been discovered", file.Hash);
yield return file;
}
}

Stream IFileAccessService.Read(FileSignature fileSignature, bool temporary)
Expand Down
24 changes: 0 additions & 24 deletions src/ModSink.Common/DynamicDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,11 @@
using System.Reactive.Linq;
using Anotar.Serilog;
using DynamicData;
using ReactiveUI;

namespace ModSink.Common
{
public static class DynamicDataExtensions
{
public static IObservableCache<TObject, TKey> DisposeWithThrowExceptions<TObject, TKey>(
this IObservableCache<TObject, TKey> o,
CompositeDisposable disposable)
{
o.DisposeWith(disposable);
o.Connect().Subscribe().DisposeWith(disposable);
o.Connect().Subscribe(_ => { },
ex => RxApp.MainThreadScheduler.Schedule(() => RxApp.DefaultExceptionHandler.OnNext(ex)));
o.Connect().Subscribe(_ => { }, _ => Debugger.Break());
return o;
}

public static IObservableList<T> DisposeWithThrowExceptions<T>(this IObservableList<T> o,
CompositeDisposable disposable)
{
o.DisposeWith(disposable);
o.Connect().Subscribe().DisposeWith(disposable);
o.Connect().Subscribe(_ => { },
ex => RxApp.MainThreadScheduler.Schedule(() => RxApp.DefaultExceptionHandler.OnNext(ex)));
o.Connect().Subscribe(_ => { }, _ => Debugger.Break());
return o;
}

public static IObservable<IChangeSet<T>> LogVerbose<T>(this IObservable<IChangeSet<T>> source, string prefix)
{
return source.Do(changeSet =>
Expand Down
5 changes: 4 additions & 1 deletion src/ModSink.Common/HashingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public IEnumerable<FileInfo> GetFiles(DirectoryInfo directory)
while (directoryStack.Count > 0)
{
var dir = directoryStack.Pop();
dir.EnumerateDirectories().ForEach(directoryStack.Push);
foreach (var d in dir.EnumerateDirectories())
{
directoryStack.Push(d);
}
foreach (var file in dir.EnumerateFiles()) yield return file;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ModSink.Common/HttpClientDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using ModSink.Common.Client;
using Polly;
using Polly.Extensions.Http;
using ReactiveUI;
using static ModSink.Common.Client.DownloadProgress;

namespace ModSink.Common
Expand Down Expand Up @@ -85,7 +84,7 @@ public IConnectableObservable<DownloadProgress> Download(Uri source, Lazy<Stream
observer.OnCompleted();

return destination.Value;
}).SubscribeOn(RxApp.TaskpoolScheduler).Publish();
}).Publish();
}
}
}
14 changes: 8 additions & 6 deletions src/ModSink.Common/ModSink.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
<ItemGroup>
<PackageReference Include="Anotar.Serilog.Fody" Version="4.6.2" />
<PackageReference Include="Ben.Demystifier" Version="0.1.1" />
<PackageReference Include="DynamicData" Version="6.4.0.2419" />
<PackageReference Include="DynamicData" Version="6.5.1.2479" />
<PackageReference Include="Flurl" Version="2.8.0" />
<PackageReference Include="Fody" Version="3.1.3" />
<PackageReference Include="Fody" Version="3.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Humanizer" Version="2.4.2" />
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Polly.Extensions.Http" Version="2.0.1" />
<PackageReference Include="ReactiveUI" Version="8.3.1" />
<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="System.Reactive.Compatibility" Version="4.1.0" />
<PackageReference Include="System.Reactive" Version="4.1.0" />
<PackageReference Include="System.Data.HashFunction.xxHash" Version="2.0.0" />
<PackageReference Include="System.Interactive.Async.Providers" Version="3.2.0" />
<PackageReference Include="System.Interactive.Providers" Version="3.2.0" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/ModSink.WPF.Tests/ModSink.WPF.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.2.1" />
<PackageReference Include="coverlet.msbuild" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="ReactiveUI.Testing" Version="8.3.1" />
<PackageReference Include="ReactiveUI.Testing" Version="8.7.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
Loading

0 comments on commit ad74702

Please sign in to comment.