Skip to content

Commit b3f8094

Browse files
committed
* Improve search performance & implementation
* Binding improvements * Fixes * Other
1 parent 63edf39 commit b3f8094

File tree

12 files changed

+220
-95
lines changed

12 files changed

+220
-95
lines changed

SmartImage.Benchmark/SmartImage.Benchmark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
1212
<PackageReference Include="BenchmarkDotNet.Annotations" Version="0.13.12" />
1313
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
14-
<PackageReference Include="Flurl.Http" Version="4.0.0" />
14+
<PackageReference Include="Flurl.Http" Version="4.0.2" />
1515
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
16-
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.1" />
16+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

SmartImage.Lib 3/Model/IBaseImageSource.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public string DimensionString
2424

2525
public bool LoadImage();
2626

27+
}
28+
29+
public interface IItemSize
30+
{
31+
public long Size { get; }
32+
2733
}

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using SixLabors.ImageSharp;
1616
using SmartImage.Lib.Engines;
1717
using SmartImage.Lib.Engines.Impl.Upload;
18+
using SmartImage.Lib.Model;
1819
using SmartImage.Lib.Results;
1920
using SmartImage.Lib.Utilities;
2021

@@ -24,7 +25,7 @@
2425

2526
namespace SmartImage.Lib;
2627

27-
public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
28+
public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>, IItemSize
2829
{
2930

3031
[MN]
@@ -33,7 +34,17 @@ public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
3334
[MN]
3435
public Url Upload { get; internal set; }
3536

36-
public long Size { get; private set; }
37+
public long Size
38+
{
39+
get
40+
{
41+
if (HasUni) {
42+
return Uni.Stream.Length;
43+
}
44+
45+
return -1;
46+
}
47+
}
3748

3849
[CBN]
3950
public string ValueString => HasUni ? Uni.Value.ToString() : null;
@@ -49,7 +60,7 @@ public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
4960
internal SearchQuery([CBN] UniSource f)
5061
{
5162
Uni = f;
52-
Size = Uni == null ? default : Uni.Stream.Length;
63+
// Size = Uni == null ? default : Uni.Stream.Length;
5364
}
5465

5566
private SearchQuery() : this(null) { }
@@ -145,7 +156,7 @@ public async Task<Url> UploadAsync(BaseUploadEngine engine = null, CancellationT
145156
/*if (u.Response is { }) {
146157
Size = NetHelper.GetContentLength(u.Response) ?? Size;
147158
}*/
148-
Size = u.Size ?? Size;
159+
// Size = u.Size ?? Size;
149160
u.Dispose();
150161
}
151162

SmartImage.Lib 3/SmartImage.Lib.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232
</PropertyGroup>
3333
<ItemGroup>
34-
<PackageReference Include="AngleSharp" Version="1.0.7" />
34+
<PackageReference Include="AngleSharp" Version="1.1.0" />
3535
<PackageReference Include="AngleSharp.Css" Version="1.0.0-alpha-99" />
3636
<PackageReference Include="AngleSharp.Io" Version="1.0.0" />
3737
<PackageReference Include="AngleSharp.Js" Version="0.15.0" />
3838
<PackageReference Include="AngleSharp.XPath" Version="2.0.3" />
39-
<PackageReference Include="Flurl.Http" Version="4.0.0" />
39+
<PackageReference Include="Flurl.Http" Version="4.0.2" />
4040
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
4141
<PackageReference Include="Microsoft.ClearScript.V8" Version="7.4.4" />
4242
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
4343
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
44-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
44+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
4545
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
4646
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
4747
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
@@ -51,11 +51,11 @@
5151
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
5252
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
5353
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
54-
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
54+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
5555
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
56-
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.1" />
56+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
5757
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
58-
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
58+
<PackageReference Include="System.Drawing.Common" Version="8.0.1" />
5959
<PackageReference Include="System.Json" Version="4.7.1" />
6060
<PackageReference Include="System.Reactive" Version="6.0.1-preview.1" />
6161
<PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Kantan.Utilities;
2+
using Novus.Win32;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Globalization;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using SmartImage.Lib.Model;
12+
using SmartImage.UI.Model;
13+
14+
namespace SmartImage.UI.Controls;
15+
16+
[ValueConversion(typeof(IBaseImageSource), typeof(string))]
17+
public class ImageDimensionConverter : IValueConverter
18+
{
19+
20+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
21+
{
22+
var val = (IBaseImageSource) value;
23+
24+
if (val == null) {
25+
return null;
26+
}
27+
28+
string dim;
29+
30+
int? w = null, h = null;
31+
32+
if (val is ResultItem ri) {
33+
if (ri is { IsThumbnail: true } and { HasImage: true }) {
34+
w = ri.Image.PixelWidth;
35+
h = ri.Image.PixelHeight;
36+
}
37+
38+
}
39+
else {
40+
w = (val.Width);
41+
h = val.Height;
42+
43+
}
44+
45+
dim = ControlsHelper.FormatDimensions(w, h);
46+
47+
return dim;
48+
}
49+
50+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
51+
{
52+
return null;
53+
}
54+
55+
}

SmartImage.UI/Controls/UnitStringConverter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using System.Windows.Data;
88
using Kantan.Utilities;
9+
using Novus.Win32;
910

1011
namespace SmartImage.UI.Controls;
1112

@@ -16,7 +17,13 @@ internal class UnitStringConverter : IValueConverter
1617
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1718
{
1819
var val = (long) value;
19-
var bytes = FormatHelper.FormatBytes(val);
20+
21+
string bytes;
22+
23+
if (val == Native.INVALID) {
24+
bytes = "N/A";
25+
}
26+
else bytes = FormatHelper.FormatBytes(val);
2027

2128
return bytes;
2229
}

SmartImage.UI/MainWindow.xaml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<!-- <ui:SharedImageControl x:Key="SharedImage" /> -->
2121
<controls:UrlConverter x:Key="urlConverter" />
2222
<controls:UnitStringConverter x:Key="unitConverter" />
23+
<controls:ImageDimensionConverter x:Key="imgConverter" />
2324

2425
<converters:BooleanToBrushConverter x:Key="BooleanToBrushConverter">
2526
<converters:BooleanToBrushConverter.TrueBrush>
@@ -549,17 +550,19 @@
549550
<TextBox x:Name="Tb_Info_Size" HorizontalAlignment="Left" Margin="217,65,0,0" TextWrapping="Wrap"
550551
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
551552
Foreground="White" TextAlignment="Center"
552-
Text="{Binding CurrentQuery.Query.Uni.Stream.Length, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay,
553+
Text="{Binding CurrentQuery.Query.Size, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay,
553554
UpdateSourceTrigger=PropertyChanged, FallbackValue={x:Null}, Converter={StaticResource unitConverter}}" />
554555

555556
<TextBox x:Name="Tb_Info_Dim" HorizontalAlignment="Left" Margin="369,65,0,0" TextWrapping="Wrap"
556557
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
557558
Foreground="White" TextAlignment="Center"
558559
Text="{Binding CurrentQuery.DimensionString, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay,
559560
UpdateSourceTrigger=PropertyChanged}" />
561+
560562
<Image x:Name="Img_Status" HorizontalAlignment="Left" Height="20px" Width="20px"
561563
Margin="10,5,0,0"
562564
VerticalAlignment="Top" Stretch="None" Grid.Row="1" />
565+
563566
<ListView x:Name="Lv_Results" Margin="0,120,0,0"
564567
MouseDoubleClick="Lv_Results_MouseDoubleClick"
565568
Foreground="White"
@@ -664,7 +667,8 @@
664667

665668
<TextBlock x:Name="Tb_Status" HorizontalAlignment="Left" Margin="30,96,0,0"
666669
VerticalAlignment="Top" Foreground="White" FontStyle="Italic"
667-
Text="{Binding CurrentQuery.Status, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}" Grid.Column="1" Grid.Row="1" />
670+
Text="{Binding CurrentQuery.Status, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}"
671+
Grid.Column="1" Grid.Row="1" />
668672

669673
<!--
670674
<TextBlock x:Name="Tb_Status2" HorizontalAlignment="Left" Margin="95,28,0,0"
@@ -706,47 +710,62 @@
706710

707711
<Label x:Name="Lb_SelMainUrl" Content="Item" HorizontalAlignment="Left" Margin="4,59,0,0"
708712
VerticalAlignment="Top" Height="26" Foreground="White"
709-
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Width="55" HorizontalContentAlignment="Center"
713+
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Width="55"
714+
HorizontalContentAlignment="Center"
710715
Grid.Row="1" FontWeight="Bold" />
711716

712717
<TextBox x:Name="Tb_SelMainUrl" HorizontalAlignment="Left" Margin="64,61,0,0"
713-
VerticalAlignment="Top" Width="435" IsReadOnly="True" Height="20" Foreground="White" Background="Black"
714-
Text="{Binding CurrentResult.Result.Url, Converter={StaticResource urlConverter}, ElementName=Wnd_Main, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
718+
VerticalAlignment="Top" Width="435" IsReadOnly="True" Height="20" Foreground="White"
719+
Background="Black"
720+
Text="{Binding CurrentResult.Result.Url, Converter={StaticResource urlConverter}, ElementName=Wnd_Main, Mode=OneWay,
721+
UpdateSourceTrigger=PropertyChanged}"
722+
ToolTip="Preview result URL"
715723
Grid.Row="1" MouseDoubleClick="Tb_SelUrl_MouseDoubleClick" />
716724

717725
<Label x:Name="Lb_SelInfo" Content="Info" HorizontalAlignment="Left" Margin="4,87,0,0"
718726
VerticalAlignment="Top" Height="26" FontWeight="Bold" Foreground="White"
719-
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" HorizontalContentAlignment="Center" Width="55"
727+
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
728+
HorizontalContentAlignment="Center" Width="55"
720729
Grid.Row="1" />
721730

722-
<TextBox x:Name="Tb_SelInfo_Type" HorizontalAlignment="Left" Margin="64,89,0,0" TextWrapping="Wrap"
731+
<TextBox x:Name="Tb_SelInfo_Info" HorizontalAlignment="Left" Margin="64,89,0,0" TextWrapping="Wrap"
723732
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
724733
Foreground="White" TextAlignment="Center"
725-
Text="{Binding CurrentResult.Status, ElementName=Wnd_Main, FallbackValue={x:Null}, IsAsync=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
734+
Text="{Binding CurrentResult.Status, ElementName=Wnd_Main, FallbackValue={x:Null}, IsAsync=True, Mode=OneWay,
735+
UpdateSourceTrigger=PropertyChanged}"
736+
ToolTip="Preview image info"
726737
Grid.Row="1" />
727738

728739
<TextBox x:Name="Tb_SelInfo_Size" HorizontalAlignment="Left" Margin="217,89,0,0"
729740
TextWrapping="Wrap"
730741
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
731742
Foreground="White" TextAlignment="Center"
732-
Text="..."
743+
Text="{Binding CurrentResult.Size, Converter={StaticResource unitConverter}, FallbackValue={x:Null}, Mode=OneWay, IsAsync=True,
744+
UpdateSourceTrigger=PropertyChanged}"
745+
ToolTip="Preview image size"
733746
Grid.Row="1" />
734747

735748
<TextBox x:Name="Tb_SelInfo_Dim" HorizontalAlignment="Left" Margin="369,89,0,0" TextWrapping="Wrap"
736749
VerticalAlignment="Top" Width="130" IsReadOnly="True" Height="20" Background="Black"
737750
Foreground="White" TextAlignment="Center"
738-
Text="{Binding CurrentResult.DimensionString, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
751+
Text="{Binding CurrentResult.DimensionString, ElementName=Wnd_Main, IsAsync=True, Mode=OneWay, FallbackValue={x:Null},
752+
UpdateSourceTrigger=PropertyChanged}"
753+
ToolTip="Preview image dimensions"
739754
Grid.Row="1" />
740755

741756
<Label x:Name="Lb_SelPrevUrl" Content="Preview" HorizontalAlignment="Left" Margin="4,31,0,0"
742-
VerticalAlignment="Top" Height="26" Foreground="White"
743-
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Width="55" HorizontalContentAlignment="Center"
744-
Grid.Row="1" FontWeight="Bold" />
757+
VerticalAlignment="Top" Height="26" Foreground="White"
758+
Background="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Width="55"
759+
HorizontalContentAlignment="Center"
760+
Grid.Row="1" FontWeight="Bold" />
745761

746762
<TextBox x:Name="Tb_SelPrevUrl" HorizontalAlignment="Left" Margin="64,34,0,0"
747-
VerticalAlignment="Top" Width="434" IsReadOnly="True" Height="20" Foreground="White" Background="Black"
748-
Text="{Binding CurrentResult.Result.Thumbnail, Converter={StaticResource urlConverter}, ElementName=Wnd_Main, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
749-
Grid.Row="1" MouseDoubleClick="Tb_SelPrevUrl_MouseDoubleClick" />
763+
VerticalAlignment="Top" Width="434" IsReadOnly="True" Height="20" Foreground="White"
764+
Background="Black"
765+
Text="{Binding CurrentResult.Result.Thumbnail, Converter={StaticResource urlConverter}, ElementName=Wnd_Main, Mode=OneWay,
766+
UpdateSourceTrigger=PropertyChanged}"
767+
ToolTip="Preview image URL"
768+
Grid.Row="1" MouseDoubleClick="Tb_SelPrevUrl_MouseDoubleClick" />
750769

751770
</Grid>
752771
</TabItem>

0 commit comments

Comments
 (0)