1
- using AlbanianXrm . SolutionPackager . Models ;
1
+ using AlbanianXrm . BackgroundWorker ;
2
+ using AlbanianXrm . SolutionPackager . Models ;
2
3
using AlbanianXrm . SolutionPackager . Properties ;
3
- using AlbanianXrm . XrmToolBox . Shared ;
4
+ using AlbanianXrm . XrmToolBox . Shared . Extensions ;
4
5
using Microsoft . Crm . Sdk . Messages ;
5
6
using Microsoft . Xrm . Sdk ;
6
7
using Microsoft . Xrm . Sdk . Query ;
@@ -16,11 +17,11 @@ namespace AlbanianXrm.SolutionPackager
16
17
internal class CrmSolutionDownloader
17
18
{
18
19
private readonly SolutionPackagerControl solutionPackagerControl ;
19
- private readonly BackgroundWorkHandler asyncWorkQueue ;
20
+ private readonly AlBackgroundWorkHandler asyncWorkQueue ;
20
21
private readonly SolutionPackagerCaller solutionPackagerCaller ;
21
22
private readonly ComboBox cmbCrmSolutions ;
22
23
23
- public CrmSolutionDownloader ( SolutionPackagerControl solutionPackagerControl , BackgroundWorkHandler asyncWorkQueue , SolutionPackagerCaller solutionPackagerCaller , ComboBox cmbCrmSolutions )
24
+ public CrmSolutionDownloader ( SolutionPackagerControl solutionPackagerControl , AlBackgroundWorkHandler asyncWorkQueue , SolutionPackagerCaller solutionPackagerCaller , ComboBox cmbCrmSolutions )
24
25
{
25
26
this . solutionPackagerControl = solutionPackagerControl ?? throw new ArgumentNullException ( nameof ( solutionPackagerControl ) ) ;
26
27
this . asyncWorkQueue = asyncWorkQueue ?? throw new ArgumentNullException ( nameof ( asyncWorkQueue ) ) ;
@@ -30,12 +31,10 @@ public CrmSolutionDownloader(SolutionPackagerControl solutionPackagerControl, Ba
30
31
31
32
public void DownloadSolution ( Parameters @params )
32
33
{
33
- asyncWorkQueue . EnqueueWork (
34
- string . Format ( CultureInfo . InvariantCulture , Resources . DOWNLOADING_SOLUTION , @params . Solution . FriendlyName ) ,
35
- DownloadSolutionInner ,
36
- @params ,
37
- DownloadSolutionCompleted
38
- ) ;
34
+ asyncWorkQueue . EnqueueBackgroundWork (
35
+ AlBackgroundWorkerFactory . NewWorker ( DownloadSolutionInner , @params , DownloadSolutionCompleted )
36
+ . WithViewModel ( solutionPackagerControl . toolViewModel )
37
+ . WithMessage ( solutionPackagerControl , string . Format ( CultureInfo . InvariantCulture , Resources . DOWNLOADING_SOLUTION , @params . Solution . FriendlyName ) ) ) ;
39
38
}
40
39
41
40
private SolutionPackagerCaller . Parameters DownloadSolutionInner ( Parameters @params )
@@ -73,31 +72,30 @@ private SolutionPackagerCaller.Parameters DownloadSolutionInner(Parameters @para
73
72
return @params . SolutionPackagerParameters ;
74
73
}
75
74
76
- private void DownloadSolutionCompleted ( BackgroundWorkResult < Parameters , SolutionPackagerCaller . Parameters > args )
75
+ private void DownloadSolutionCompleted ( Parameters args , SolutionPackagerCaller . Parameters value , Exception exception )
77
76
{
78
- if ( args . Exception is FaultException < OrganizationServiceFault > crmError )
77
+ if ( exception is FaultException < OrganizationServiceFault > crmError )
79
78
{
80
79
solutionPackagerControl . WriteErrorLog ( "The following error occurred while downloading the solution:\r \n {0}" , crmError ) ;
81
80
MessageBox . Show ( crmError . Message , Resources . MBOX_ERROR , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
82
81
}
83
- else if ( args . Exception != null )
82
+ else if ( exception != null )
84
83
{
85
- solutionPackagerControl . WriteErrorLog ( "The following error occurred while downloading the solution:\r \n {0}" , args . Exception ) ;
86
- MessageBox . Show ( args . Exception . Message , Resources . MBOX_ERROR , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
84
+ solutionPackagerControl . WriteErrorLog ( "The following error occurred while downloading the solution:\r \n {0}" , exception ) ;
85
+ MessageBox . Show ( exception . Message , Resources . MBOX_ERROR , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
87
86
}
88
87
else
89
88
{
90
- solutionPackagerCaller . ManageSolution ( args . Value ) ;
89
+ solutionPackagerCaller . ManageSolution ( value ) ;
91
90
}
92
91
}
93
92
94
93
public void RefreshSolutionList ( )
95
94
{
96
- asyncWorkQueue . EnqueueWork (
97
- Resources . REFRESHING_SOLUTION_LIST ,
98
- RefreshSolutionListInner ,
99
- RefreshSolutionListCompleted
100
- ) ;
95
+ asyncWorkQueue . EnqueueBackgroundWork (
96
+ AlBackgroundWorkerFactory . NewWorker ( RefreshSolutionListInner , RefreshSolutionListCompleted )
97
+ . WithViewModel ( solutionPackagerControl . toolViewModel )
98
+ . WithMessage ( solutionPackagerControl , Resources . REFRESHING_SOLUTION_LIST ) ) ;
101
99
}
102
100
103
101
private object [ ] RefreshSolutionListInner ( )
@@ -111,18 +109,18 @@ private object[] RefreshSolutionListInner()
111
109
return solutionPackagerControl . Service . RetrieveMultiple ( query ) . Entities . Select ( solution => solution . ToEntity < Solution > ( ) ) . ToArray < object > ( ) ;
112
110
}
113
111
114
- private void RefreshSolutionListCompleted ( BackgroundWorkResult < object [ ] > args )
112
+ private void RefreshSolutionListCompleted ( object [ ] value , Exception exception )
115
113
{
116
- if ( args . Exception != null )
114
+ if ( exception != null )
117
115
{
118
- solutionPackagerControl . WriteErrorLog ( "The following error occurred while refreshing the solution list:\r \n {0}" , args . Exception ) ;
119
- MessageBox . Show ( args . Exception . Message , Resources . MBOX_ERROR , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
116
+ solutionPackagerControl . WriteErrorLog ( "The following error occurred while refreshing the solution list:\r \n {0}" , exception ) ;
117
+ MessageBox . Show ( exception . Message , Resources . MBOX_ERROR , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
120
118
}
121
119
else
122
120
{
123
121
cmbCrmSolutions . BeginUpdate ( ) ;
124
122
cmbCrmSolutions . Items . Clear ( ) ;
125
- cmbCrmSolutions . Items . AddRange ( args . Value ) ;
123
+ cmbCrmSolutions . Items . AddRange ( value ) ;
126
124
cmbCrmSolutions . EndUpdate ( ) ;
127
125
}
128
126
}
0 commit comments