Skip to content

Commit f33a386

Browse files
committed
add id to global events/ actions, fix usage of global cancellaiton token breaking tasks, fix global event getting stuck [#43]
1 parent f9786fd commit f33a386

17 files changed

+1153
-990
lines changed

MyCBZ/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<applicationSettings>
169169
<Win_CBZ.Win_CBZSettings>
170170
<setting name="InstalledVersion" serializeAs="String">
171-
<value>0.21.164b</value>
171+
<value>0.21.165b</value>
172172
</setting>
173173
<setting name="RenamerPlaceholders" serializeAs="Xml">
174174
<value>

MyCBZ/Events/GeneralTaskProgressEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class GeneralTaskProgressEvent
4242

4343
public GeneralTaskProgressEvent() { }
4444

45-
public GeneralTaskProgressEvent(int type, int status, string message, int current, int total, bool popState, bool inBackground = false, string key = null)
45+
public GeneralTaskProgressEvent(int type, int status, string message, int current, int total, bool popState, bool inBackground = false, string id = null)
4646
{
4747
Current = current;
4848
Total = total;
@@ -51,7 +51,7 @@ public GeneralTaskProgressEvent(int type, int status, string message, int curren
5151
Message = message;
5252
PopGlobalState = popState;
5353
InBackground = inBackground;
54-
Key = key;
54+
Id = id;
5555
}
5656
}
5757
}

MyCBZ/Events/GlobalActionRequiredEvent.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ internal class GlobalActionRequiredEvent
2828

2929
public String ButtonText { get; set; }
3030

31+
public string Id { get; set; }
32+
33+
public GlobalActionRequiredEvent() { }
34+
3135

3236
public GlobalActionRequiredEvent(ProjectModel project, int type, String message, String buttonText)
3337
{
@@ -37,14 +41,15 @@ public GlobalActionRequiredEvent(ProjectModel project, int type, String message,
3741
ButtonText = buttonText;
3842
}
3943

40-
public GlobalActionRequiredEvent(ProjectModel project, int type, String message, String buttonText, String taskType, Task<TaskResult> task)
44+
public GlobalActionRequiredEvent(ProjectModel project, int type, String message, String buttonText, String taskType, Task<TaskResult> task, String id = null)
4145
{
4246
ArchiveInfo = project;
4347
Type = type;
4448
Message = message;
4549
ButtonText = buttonText;
4650
TaskType = taskType;
47-
Task = task;
51+
Task = task;
52+
Id = id;
4853
}
4954
}
5055
}

MyCBZ/Forms/MainForm.Designer.cs

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyCBZ/Forms/MainForm.cs

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ private void NewProject()
384384

385385
awaitClosingArchive.ContinueWith(t =>
386386
{
387+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_THUMBNAIL_SLICE);
388+
387389
RemoveMetaData();
388390
Program.ProjectModel.New();
389391
Invoke(new Action(() =>
@@ -2882,6 +2884,9 @@ private void MoveItemsToProc(object threadParams)
28822884
newIndex++;
28832885
}
28842886

2887+
String gid = Guid.NewGuid().ToString();
2888+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_MOVE_ITEMS);
2889+
28852890
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(
28862891
Program.ProjectModel,
28872892
0,
@@ -2891,9 +2896,13 @@ private void MoveItemsToProc(object threadParams)
28912896
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
28922897
AppEventHandler.OnGeneralTaskProgress,
28932898
AppEventHandler.OnPageChanged,
2894-
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_MOVE_ITEMS).Token
2895-
)
2896-
));
2899+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_MOVE_ITEMS).Token,
2900+
false,
2901+
true,
2902+
gid
2903+
),
2904+
gid
2905+
));
28972906

28982907

28992908
newIndex = tparams.NewIndex;
@@ -3069,8 +3078,23 @@ private void MovePageProc(object movePagesThreadParams)
30693078
AppEventHandler.OnPageChanged(this, new PageChangedEvent(originalPage, null, PageChangedEvent.IMAGE_STATUS_CHANGED));
30703079
}
30713080

3081+
String gid = Guid.NewGuid().ToString();
3082+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_MOVE_ITEMS);
3083+
30723084
AppEventHandler.OnArchiveStatusChanged(this, new ArchiveStatusEvent(Program.ProjectModel, ArchiveStatusEvent.ARCHIVE_FILE_UPDATED));
3073-
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(Program.ProjectModel, GlobalActionRequiredEvent.MESSAGE_TYPE_INFO, "Page order changed. Rebuild pageindex now?", "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token, false, true)));
3085+
AppEventHandler.OnGlobalActionRequired(this,
3086+
new GlobalActionRequiredEvent(Program.ProjectModel,
3087+
GlobalActionRequiredEvent.MESSAGE_TYPE_INFO,
3088+
"Page order changed. Rebuild pageindex now?",
3089+
"Rebuild",
3090+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
3091+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
3092+
AppEventHandler.OnGeneralTaskProgress,
3093+
AppEventHandler.OnPageChanged,
3094+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token,
3095+
false,
3096+
true, gid)
3097+
, gid));
30743098

30753099
Program.ProjectModel.IsChanged = true;
30763100
}));
@@ -4559,7 +4583,25 @@ private void ToolButtonRemoveFiles_Click(object sender, EventArgs e)
45594583
AppEventHandler.OnArchiveStatusChanged(this, new ArchiveStatusEvent(Program.ProjectModel, ArchiveStatusEvent.ARCHIVE_FILE_DELETED));
45604584
}
45614585

4562-
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page order changed. Rebuild pageindex now?", "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token, false, true)));
4586+
String gid = Guid.NewGuid().ToString();
4587+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX);
4588+
4589+
AppEventHandler.OnGlobalActionRequired(this,
4590+
new GlobalActionRequiredEvent(Program.ProjectModel,
4591+
0,
4592+
"Page order changed. Rebuild pageindex now?",
4593+
"Rebuild",
4594+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
4595+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
4596+
AppEventHandler.OnGeneralTaskProgress,
4597+
AppEventHandler.OnPageChanged,
4598+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token,
4599+
false,
4600+
true,
4601+
gid),
4602+
gid
4603+
)
4604+
);
45634605

45644606
//Program.ProjectModel.UpdatePageIndices();
45654607
}
@@ -4583,7 +4625,25 @@ private void TypeSelectionToolStripMenuItem_Click(object sender, EventArgs e)
45834625
{
45844626
if (PagesList.SelectedItems.Count > 1)
45854627
{
4586-
HandleGlobalActionRequired(null, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page type changed. Rebuild pageindex now?", "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token)));
4628+
String gid = Guid.NewGuid().ToString();
4629+
4630+
AppEventHandler.OnGlobalActionRequired(null,
4631+
new GlobalActionRequiredEvent(Program.ProjectModel,
4632+
0,
4633+
"Page type changed. Rebuild pageindex now?",
4634+
"Rebuild",
4635+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
4636+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
4637+
AppEventHandler.OnGeneralTaskProgress,
4638+
AppEventHandler.OnPageChanged,
4639+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token,
4640+
false,
4641+
true,
4642+
gid
4643+
),
4644+
gid
4645+
)
4646+
);
45874647
}
45884648
else
45894649
{
@@ -4927,7 +4987,25 @@ private void ToolButtonEditImageProps_Click(object sender, EventArgs e)
49274987

49284988
if (pageIndexUpdateNeeded)
49294989
{
4930-
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(Program.ProjectModel, 0, indexRebuildMessage, "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token)));
4990+
String gid = Guid.NewGuid().ToString();
4991+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX);
4992+
4993+
AppEventHandler.OnGlobalActionRequired(this,
4994+
new GlobalActionRequiredEvent(Program.ProjectModel,
4995+
0,
4996+
indexRebuildMessage,
4997+
"Rebuild",
4998+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
4999+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
5000+
AppEventHandler.OnGeneralTaskProgress,
5001+
AppEventHandler.OnPageChanged,
5002+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token,
5003+
false,
5004+
true,
5005+
gid
5006+
),
5007+
gid
5008+
));
49315009
}
49325010
}
49335011
}
@@ -5096,7 +5174,26 @@ private void ToolButtonSetPageType_ButtonClick(object sender, EventArgs e)
50965174
{
50975175
if (PagesList.SelectedItems.Count > 1)
50985176
{
5099-
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page type changed. Rebuild pageindex now?", "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token)));
5177+
String gid = Guid.NewGuid().ToString();
5178+
TokenStore.GetInstance().ResetCancellationToken(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX);
5179+
5180+
5181+
AppEventHandler.OnGlobalActionRequired(this,
5182+
new GlobalActionRequiredEvent(Program.ProjectModel,
5183+
0,
5184+
"Page type changed. Rebuild pageindex now?",
5185+
"Rebuild",
5186+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
5187+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
5188+
AppEventHandler.OnGeneralTaskProgress,
5189+
AppEventHandler.OnPageChanged,
5190+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_UPDATE_PAGE_INDEX).Token,
5191+
false,
5192+
true,
5193+
gid
5194+
),
5195+
gid
5196+
));
51005197
}
51015198
else
51025199
{
@@ -6776,7 +6873,24 @@ private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
67766873

67776874
if (pagesUpdated > 0)
67786875
{
6779-
AppEventHandler.OnGlobalActionRequired(this, new GlobalActionRequiredEvent(Program.ProjectModel, 0, "Page order changed. Rebuild pageindex now?", "Rebuild", GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD, UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages, AppEventHandler.OnGeneralTaskProgress, AppEventHandler.OnPageChanged, TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token)));
6876+
String gid = Guid.NewGuid().ToString();
6877+
6878+
AppEventHandler.OnGlobalActionRequired(this,
6879+
new GlobalActionRequiredEvent(Program.ProjectModel,
6880+
0,
6881+
"Page order changed. Rebuild pageindex now?",
6882+
"Rebuild",
6883+
GlobalActionRequiredEvent.TASK_TYPE_INDEX_REBUILD,
6884+
UpdatePageIndexTask.UpdatePageIndex(Program.ProjectModel.Pages,
6885+
AppEventHandler.OnGeneralTaskProgress,
6886+
AppEventHandler.OnPageChanged,
6887+
TokenStore.GetInstance().CancellationTokenSourceForName(TokenStore.TOKEN_SOURCE_GLOBAL).Token,
6888+
false,
6889+
true,
6890+
gid
6891+
),
6892+
gid
6893+
));
67806894

67816895
}
67826896
}

0 commit comments

Comments
 (0)