Skip to content

Commit 9f230de

Browse files
committed
v4.0.1
1 parent faf5625 commit 9f230de

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

SmartImage.Lib 3/Engines/Impl/Upload/BaseUploadEngine.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ protected virtual async Task<UploadResult> ProcessResultAsync(
6767

6868
if (Paranoid) {
6969
var r2 = await url.ConfigureRequest(r =>
70-
r.OnError = rx =>
71-
{
72-
rx.ExceptionHandled = true;
73-
}).GetAsync(cancellationToken: ct);
70+
{
71+
r.OnError = rx =>
72+
{
73+
rx.ExceptionHandled = true;
74+
};
75+
}).GetAsync(cancellationToken: ct);
7476

7577
if (r2 == null || r2.GetContentLength() == 0) {
7678
ok = false;
@@ -82,9 +84,9 @@ protected virtual async Task<UploadResult> ProcessResultAsync(
8284

8385
return new()
8486
{
85-
Url = url,
86-
Size = response.GetContentLength(),
87-
IsValid = ok
87+
Url = url,
88+
Size = response.GetContentLength(),
89+
IsValid = ok
8890
};
8991
}
9092

@@ -135,12 +137,12 @@ public override async Task<UploadResult> UploadFileAsync(string file, Cancellati
135137
User_Agent = HttpUtilities.UserAgent
136138
})
137139
.PostMultipartAsync(mp =>
138-
mp.AddFile("fileToUpload", file)
139-
.AddString("reqtype", "fileupload")
140-
.AddString("time", "1h")
141-
.AddString("userhash", string.Empty)
142-
, cancellationToken: ct,
143-
completionOption: HttpCompletionOption.ResponseHeadersRead);
140+
{
141+
mp.AddFile("fileToUpload", file)
142+
.AddString("reqtype", "fileupload")
143+
.AddString("time", "1h")
144+
.AddString("userhash", string.Empty);
145+
}, cancellationToken: ct, completionOption: HttpCompletionOption.ResponseHeadersRead);
144146

145147
return await ProcessResultAsync(response, ct).ConfigureAwait(false);
146148
}

SmartImage.Lib 3/Engines/Impl/Upload/PomfEngine.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public override async Task<UploadResult> UploadFileAsync(string file, Cancellati
3434
};
3535
})
3636
.PostMultipartAsync(mp =>
37-
mp.AddFile("files[]", file)
38-
, cancellationToken: ct);
37+
{
38+
mp.AddFile("files[]", file);
39+
}, cancellationToken: ct);
3940

4041
var pr = await response.GetJsonAsync<PomfResult>();
4142

SmartImage.UI/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
</Button>
279279
<Button x:Name="Btn_Delete" Content="Delete"
280280
HorizontalAlignment="Left" Margin="634,8,0,0" VerticalAlignment="Top"
281-
Click="Btn_Delete_Click" Height="20" Width="39">
281+
Click="Btn_Delete_Click" Height="20" Width="39" IsEnabled="{Binding Path=CurrentQueueItem.CanDelete, UpdateSourceTrigger=PropertyChanged, ElementName=Wnd_Main}">
282282

283283
<Button.Style>
284284
<Style TargetType="{x:Type Button}">
@@ -493,7 +493,7 @@
493493
IsSelected="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}"
494494
IsSynchronizedWithCurrentItem="True"
495495
Background="{DynamicResource Black2}"
496-
ItemsSource="{Binding CurrentQueueItem.Results, UpdateSourceTrigger=PropertyChanged, IsAsync=True}"
496+
ItemsSource="{Binding CurrentQueueItem.Results, UpdateSourceTrigger=PropertyChanged, IsAsync=False, Mode=TwoWay}"
497497
SelectedItem="{Binding CurrentResultItem, Mode=TwoWay}"
498498
ItemContainerStyle="{DynamicResource CustomListViewItemStyle}"
499499
MouseRightButtonDown="Lv_Results_MouseRightButtonDown"

SmartImage.UI/MainWindow.xaml.cs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public MainWindow()
136136
Rb_UploadEngine_Catbox.IsChecked = BaseUploadEngine.Default is CatboxEngine;
137137
Rb_UploadEngine_Litterbox.IsChecked = BaseUploadEngine.Default is LitterboxEngine;
138138

139-
BindingOperations.EnableCollectionSynchronization(Queue, m_lock);
140-
BindingOperations.EnableCollectionSynchronization(CurrentQueueItem.Results, m_lock);
139+
// BindingOperations.EnableCollectionSynchronization(Queue, m_lock);
140+
// BindingOperations.EnableCollectionSynchronization(CurrentQueueItem.Results, m_lock);
141141
RenderOptions.SetBitmapScalingMode(Img_Preview, BitmapScalingMode.HighQuality);
142142

143143
Application.Current.Dispatcher.InvokeAsync(CheckForUpdate);
@@ -152,8 +152,8 @@ public MainWindow()
152152

153153
Cb_SearchFields.ItemsSource = SearchFields.Keys;
154154
Cb_SearchFields.SelectedIndex = 0;
155+
155156
// m_images = new();
156-
Queue.CollectionChanged += OnCollectionChangedEventHandler;
157157
AddQueueListener();
158158
// CurrentQueueItem.PropertyChanged += OnCurrentQueueItemChanged;
159159
// PropertyChangedEventManager.AddListener(this, this, nameof(CurrentQueueItem) );
@@ -162,27 +162,6 @@ public MainWindow()
162162
ParseArgs(Args);
163163
}
164164

165-
private void OnCollectionChangedEventHandler(object? sender, NotifyCollectionChangedEventArgs args)
166-
{
167-
var val = (ObservableCollection<ResultModel>) sender;
168-
169-
switch (args.Action) {
170-
171-
case NotifyCollectionChangedAction.Add:
172-
break;
173-
case NotifyCollectionChangedAction.Remove:
174-
break;
175-
case NotifyCollectionChangedAction.Replace:
176-
break;
177-
case NotifyCollectionChangedAction.Move:
178-
break;
179-
case NotifyCollectionChangedAction.Reset:
180-
break;
181-
default:
182-
throw new ArgumentOutOfRangeException();
183-
}
184-
}
185-
186165
private void AddQueueListener()
187166
{
188167
PropertyChangedEventManager.AddHandler(this, OnCurrentQueueItemChanged, nameof(CurrentQueueItem));
@@ -217,7 +196,7 @@ private void RemoveQueueListener()
217196

218197
public SearchConfig Config => Client.Config;
219198

220-
public SearchQuery Query
199+
public SearchQuery? Query
221200
{
222201
get { return CurrentQueueItem.Query; }
223202
set { CurrentQueueItem.Query = value; }
@@ -339,12 +318,12 @@ private void OnCurrentQueueItemChanged(object? sender, PropertyChangedEventArgs
339318

340319
if (!ok) {
341320
ClearQueryControls();
342-
343-
Dispatcher.InvokeAsync(() =>
321+
/*Dispatcher.BeginInvoke(() =>
344322
{
345323
CurrentQueueItem.UpdateProperties();
346-
});
324+
})*/;
347325
}
326+
348327
});
349328
// m_us.Release();
350329
}
@@ -1326,7 +1305,9 @@ private async void CheckForUpdate()
13261305

13271306
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
13281307
{
1329-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
1308+
var eventArgs = new PropertyChangedEventArgs(propertyName);
1309+
PropertyChanged?.Invoke(this, eventArgs);
1310+
// Debug.WriteLine($"{this} :: {eventArgs.PropertyName}");
13301311
}
13311312

13321313
/*public delegate bool PreviewChangedCallback(ResultItem? ri);

SmartImage.UI/Model/ResultModel.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,29 @@ public void UpdateProperties()
6060
OnPropertyChanged(nameof(CanSearch));
6161
OnPropertyChanged(nameof(IsPrimitive));
6262
OnPropertyChanged(nameof(Results));
63+
OnPropertyChanged(nameof(CanDelete));
6364

6465
}
6566

6667
public BitmapImage? Image { get; set; }
6768

68-
public ObservableCollection<ResultItem> Results { get; set; }
69+
private ObservableCollection<ResultItem> m_results;
6970

71+
public ObservableCollection<ResultItem> Results
72+
{
73+
get => m_results;
74+
set
75+
{
76+
if (Equals(value, m_results)) return;
77+
m_results = value;
78+
OnPropertyChanged();
79+
OnPropertyChanged(nameof(IsPrimitive));
80+
OnPropertyChanged(nameof(IsComplete));
81+
OnPropertyChanged(nameof(CanSearch));
82+
}
83+
}
84+
85+
[MemberNotNullWhen(true, nameof(Query))]
7086
public bool HasQuery => (Query != SearchQuery.Null) && Query != null;
7187

7288
public bool CanLoadImage => !HasImage && HasQuery;
@@ -78,7 +94,10 @@ public void UpdateProperties()
7894
public bool IsPrimitive => !Results.Any() && !HasQuery;
7995

8096
public bool IsComplete => Results.Any() && HasQuery && Query.IsUploaded;
81-
public bool CanSearch => !Results.Any() && HasQuery && Query.IsUploaded;
97+
98+
public bool CanDelete => HasQuery && Query.Uni.IsFile;
99+
100+
public bool CanSearch => !Results.Any() && HasQuery && Query.IsUploaded;
82101

83102
public ResultModel() : this(string.Empty) { }
84103

@@ -271,7 +290,9 @@ public bool LoadImage()
271290

272291
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
273292
{
274-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
293+
var eventArgs = new PropertyChangedEventArgs(propertyName);
294+
PropertyChanged?.Invoke(this, eventArgs);
295+
// Debug.WriteLine($"{this} :: {eventArgs.PropertyName}");
275296
}
276297

277298
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
@@ -299,7 +320,6 @@ public void ClearResults()
299320

300321
public void Dispose()
301322
{
302-
PropertyChanged = null;
303323

304324
ClearResults();
305325

@@ -315,5 +335,6 @@ public void Dispose()
315335
Status2 = null;
316336
Info = null;
317337

338+
PropertyChanged = null;
318339
}
319340
}

0 commit comments

Comments
 (0)