Skip to content

Commit 2d758d2

Browse files
committed
More work on logic
1 parent e11e7b3 commit 2d758d2

File tree

11 files changed

+668
-117
lines changed

11 files changed

+668
-117
lines changed

SmartImage.Lib 3/Engines/Impl/Search/TraceMoeEngine.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections;
22
using System.Diagnostics;
3+
using System.Json;
34
using Flurl;
45
using Flurl.Http;
56
using JetBrains.Annotations;
@@ -46,8 +47,10 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
4647
.AllowAnyHttpStatus()
4748
.SetQueryParam("url", query.Upload, true);
4849

49-
var json = await request.GetStringAsync(cancellationToken: token);
50+
var response = await request.GetAsync(cancellationToken: token);
5051

52+
var json = await response.GetStringAsync();
53+
5154
var settings = new JsonSerializerSettings
5255
{
5356
Error = (sender, args) =>

SmartImage.Lib 3/SearchClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query, bool reload
136136
}
137137

138138
OnComplete?.Invoke(this, results);
139-
139+
IsRunning = false;
140140
IsComplete = true;
141141

142142
if (Config.PriorityEngines == SearchEngineOptions.Auto) {

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class SearchQuery : IDisposable, IEquatable<SearchQuery>
2323
public UniSource Uni { get; }
2424

2525
[MN]
26-
public Url Upload { get; private set; }
26+
public Url Upload { get; internal set; }
2727

2828
public long Size { get; private set; }
2929

SmartImage.UI/App.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ private static void SendMessage(StartupEventArgs e)
7575

7676
public event PipeMessageCallback OnPipeMessage;
7777

78+
[DebuggerHidden]
7879
private void StartServer()
7980
{
8081
PipeServer = new NamedPipeServerStream(IPC_PIPE_NAME, PipeDirection.In);
8182

82-
PipeThread = new Thread(() =>
83+
PipeThread = new Thread([DebuggerHidden]() =>
8384
{
8485
while (true) {
8586
PipeServer.WaitForConnection();

SmartImage.UI/MainWindow.Handlers.cs

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
using System.Collections.ObjectModel;
77
using System.ComponentModel;
88
using System.Diagnostics;
9+
using System.Globalization;
910
using System.IO;
1011
using System.Linq;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314
using System.Windows;
1415
using System.Windows.Controls;
1516
using System.Windows.Controls.Primitives;
17+
using System.Windows.Data;
1618
using System.Windows.Input;
1719
using System.Windows.Media;
1820
using System.Windows.Threading;
21+
using Flurl;
1922
using Kantan.Text;
2023
using Kantan.Utilities;
2124
using Microsoft.VisualBasic.FileIO;
@@ -79,7 +82,7 @@ private void Tb_Input_Drop(object sender, DragEventArgs e)
7982
var f1 = files1.FirstOrDefault();
8083

8184
if (!string.IsNullOrWhiteSpace(f1)) {
82-
CurrentQueueItem = f1;
85+
SetQueue(f1);
8386

8487
}
8588

@@ -181,7 +184,9 @@ private void Btn_Restart_Click(object sender, RoutedEventArgs e)
181184
{
182185
var ctrl = Keyboard.Modifiers.HasFlag(ModifierKeys.Control);
183186
Restart(ctrl);
184-
Queue.Clear();
187+
// ClearQueue();
188+
// ClearResults(true);
189+
185190
e.Handled = true;
186191
}
187192

@@ -200,6 +205,8 @@ private void Btn_Cancel_Click(object sender, RoutedEventArgs e)
200205
Cancel();
201206
ReloadToken();
202207
Lb_Queue.IsEnabled = true;
208+
Btn_Run.IsEnabled = true;
209+
Btn_Remove.IsEnabled = true;
203210
e.Handled = true;
204211
}
205212

@@ -215,16 +222,16 @@ private void Btn_Remove_Click(object sender, RoutedEventArgs e)
215222

216223
var old = CurrentQueueItem;
217224

218-
if (old == null) {
225+
if (old == null || old.IsPrimitive) {
219226
goto ret;
220227
}
221228
var i = Queue.IndexOf(old);
222229
Queue.Remove(old);
223-
230+
old?.Dispose();
224231
// TrySeekQueue(q);
225232
// AdvanceQueue(-1);
226233

227-
if (m_queries.TryRemove(old, out var sq)) {
234+
/*if (m_queries.TryRemove(old, out var sq)) {
228235
m_resultMap.TryRemove(sq, out var result);
229236
230237
foreach (var r in result) {
@@ -233,28 +240,31 @@ private void Btn_Remove_Click(object sender, RoutedEventArgs e)
233240
result.Clear();
234241
/*foreach (var r in m_resultMap[sq]) {
235242
r.Dispose();
236-
}*/
243+
}#1#
237244
238245
m_images.TryRemove(sq, out var img);
239246
img = null;
240-
}
247+
}*/
248+
241249
// ClearQueryControls();
242250

243-
var i2 = i - 1;
251+
/*var i2 = i - 1;
244252
245253
i2 = Math.Clamp(i2, 0, Queue.Count);
246-
string n;
254+
ResultModel n;
247255
248256
if (Queue.Count == 0)
249-
n = String.Empty;
257+
n = null;
250258
else
251259
n = Queue[i2];
252-
CurrentQueueItem = n;
253-
260+
// SetQueue(n);
261+
262+
CurrentQueueItem = n;*/
254263
// Lb_Queue.ItemsSource. = n;
255264
// AdvanceQueue(i-1);
256265

257-
sq?.Dispose();
266+
// n?.Dispose();
267+
258268
GC.Collect();
259269
GC.WaitForPendingFinalizers();
260270
GC.Collect();
@@ -269,18 +279,19 @@ private void Btn_Delete_Click(object sender, RoutedEventArgs e)
269279
ClearResults();
270280
m_cbDispatch.Stop();
271281
var old = CurrentQueueItem;
272-
m_clipboardHistory.Remove(old);
273-
CurrentQueueItem = String.Empty;
274-
m_queries.TryRemove(old, out var q);
275-
m_resultMap.TryRemove(Query, out var x);
276-
Query.Dispose();
282+
m_clipboardHistory.Remove(old.Value);
283+
old.Dispose();
284+
// CurrentQueueItem = null;
285+
// m_queries.TryRemove(old, out var q);
286+
// m_resultMap.TryRemove(Query, out var x);
287+
// Query.Dispose();
277288
Queue.Remove(old);
278289
Img_Preview.Source = m_image = null;
279-
Query = SearchQuery.Null;
290+
// Query = SearchQuery.Null;
280291
bool ok;
281292

282293
try {
283-
VBFS.DeleteFile(old, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
294+
VBFS.DeleteFile(old.Value, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
284295
// FileSystem.SendFileToRecycleBin(old);
285296
ok = true;
286297
}
@@ -290,8 +301,8 @@ private void Btn_Delete_Click(object sender, RoutedEventArgs e)
290301
}
291302

292303
m_cbDispatch.Start();
293-
Btn_Delete.IsEnabled = !ok;
294-
Btn_Remove.IsEnabled = !ok;
304+
Btn_Delete.IsEnabled = ok;
305+
Btn_Remove.IsEnabled = ok;
295306
AdvanceQueue();
296307
// FileSystem.SendFileToRecycleBin(InputText);
297308
e.Handled = true;
@@ -390,8 +401,9 @@ private void Lv_Results_KeyDown(object sender, KeyEventArgs e)
390401

391402
CurrentResultItem.Dispose();
392403

393-
Results.Remove(CurrentResultItem);
404+
// Results.Remove(CurrentResultItem);
394405

406+
CurrentQueueItem.Results.Remove(CurrentResultItem);
395407
Img_Preview.Source = m_image;
396408
break;
397409
case Key.C when ctrl:
@@ -538,7 +550,7 @@ private void Wnd_Main_Loaded(object sender, RoutedEventArgs e)
538550
}
539551

540552
// todo: not used for now
541-
// m_trDispatch.Start();
553+
m_trDispatch.Start();
542554
e.Handled = true;
543555
Debug.WriteLine("Main loaded");
544556

@@ -703,8 +715,8 @@ private void Btn_Filter_Click(object sender, RoutedEventArgs e)
703715

704716
private void Tb_Search_TextChanged(object sender, TextChangedEventArgs e)
705717
{
706-
if (string.IsNullOrWhiteSpace(Tb_Search.Text) && m_resultMap.TryGetValue(Query, out var value)) {
707-
Lv_Results.ItemsSource = value;
718+
if (string.IsNullOrWhiteSpace(Tb_Search.Text)) /*&& m_resultMap.TryGetValue(Query, out var value))*/ {
719+
Lv_Results.ItemsSource = CurrentQueueItem.Results; //todo
708720
}
709721
else {
710722
var selected = (string) Cb_SearchFields.SelectionBoxItem;
@@ -726,4 +738,27 @@ private void Tb_Search_TextChanged(object sender, TextChangedEventArgs e)
726738

727739
e.Handled = true;
728740
}
741+
}
742+
[ValueConversion(typeof(Url), typeof(String))]
743+
public class UrlConverter : IValueConverter
744+
{
745+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
746+
{
747+
if (value == null) {
748+
return null;
749+
}
750+
var date = (Url)value;
751+
return date.ToString();
752+
}
753+
754+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
755+
{
756+
if (value == null) {
757+
return null;
758+
}
759+
string strValue = value as string;
760+
Url resultDateTime;
761+
762+
return (Url) strValue;
763+
}
729764
}

SmartImage.UI/MainWindow.State.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,49 @@ public bool IsChecked
9191
OnPropertyChanged();
9292
}
9393
}
94+
95+
public ResultModel? Find(string s)
96+
{
97+
var x = Queue.FirstOrDefault(x => x.Value == s);
98+
99+
return x;
100+
}
101+
102+
public void ClearQueue()
103+
{
104+
lock (Queue) {
105+
foreach (var kv in Queue) {
106+
kv.Dispose();
107+
}
108+
Lb_Queue.Dispatcher.Invoke(() =>
109+
{
110+
Lb_Queue.SelectedIndex = -1;
111+
Queue.Clear();
112+
Queue.Insert(0, new ResultModel());
113+
Lb_Queue.SelectedIndex = 0;
114+
});
115+
116+
// CurrentQueueItem = new ResultModel();
117+
118+
/*var item = new ResultModel();
119+
Queue.Add(item);
120+
CurrentQueueItem = item;*/
121+
}
122+
}
123+
124+
public bool SetQueue(string s)
125+
{
126+
var x = Find(s);
127+
128+
var b = x == null;
129+
130+
if (b) {
131+
x = new ResultModel(s);
132+
Queue.Add(x);
133+
}
134+
135+
CurrentQueueItem = x;
136+
137+
return b;
138+
}
94139
}

0 commit comments

Comments
 (0)