@@ -44,7 +44,7 @@ namespace XenAdmin.Controls
4444{
4545 public partial class MultipleDvdIsoList : UserControl
4646 {
47- bool inRefresh = false ;
47+ private bool _inRefresh ;
4848
4949 public MultipleDvdIsoList ( )
5050 {
@@ -61,7 +61,7 @@ public VM VM
6161 cdChanger1 . VM = value ;
6262 if ( value != null )
6363 cdChanger1 . VM . PropertyChanged += vm_PropertyChanged ;
64- refreshDrives ( ) ;
64+ RefreshDrives ( ) ;
6565 }
6666 get => cdChanger1 . VM ;
6767 }
@@ -72,24 +72,24 @@ public VM VM
7272 [ Category ( "Appearance" ) ]
7373 public Color LabelSingleDvdForeColor
7474 {
75- get { return labelSingleDvd . ForeColor ; }
76- set { labelSingleDvd . ForeColor = value ; }
75+ get => labelSingleDvd . ForeColor ;
76+ set => labelSingleDvd . ForeColor = value ;
7777 }
7878
7979 [ Browsable ( true ) ]
8080 [ Category ( "Appearance" ) ]
8181 public Color LabelNewCdForeColor
8282 {
83- get { return newCDLabel . ForeColor ; }
84- set { newCDLabel . ForeColor = value ; }
83+ get => newCDLabel . ForeColor ;
84+ set => newCDLabel . ForeColor = value ;
8585 }
8686
8787 [ Browsable ( true ) ]
8888 [ Category ( "Appearance" ) ]
8989 public Color LinkLabelLinkColor
9090 {
91- get { return linkLabel1 . LinkColor ; }
92- set { linkLabel1 . LinkColor = value ; }
91+ get => linkLabel1 . LinkColor ;
92+ set => linkLabel1 . LinkColor = value ;
9393 }
9494
9595 #endregion
@@ -115,24 +115,25 @@ internal virtual void DeregisterEvents()
115115 cdChanger1 . DeregisterEvents ( ) ;
116116 }
117117
118- void vm_PropertyChanged ( object sender , PropertyChangedEventArgs e )
118+ private void vm_PropertyChanged ( object sender , PropertyChangedEventArgs e )
119119 {
120120 if ( e . PropertyName == "VBDs" )
121- refreshDrives ( ) ;
121+ RefreshDrives ( ) ;
122122 }
123123
124- private void refreshDrives ( )
124+ private void RefreshDrives ( )
125125 {
126126 VbdCombiItem prevSelection = comboBoxDrive . SelectedItem as VbdCombiItem ;
127- inRefresh = true ;
127+ _inRefresh = true ;
128128
129129 foreach ( object o in comboBoxDrive . Items )
130130 {
131- VbdCombiItem v = o as VbdCombiItem ;
132- v . vbd . PropertyChanged -= new PropertyChangedEventHandler ( vbd_PropertyChanged ) ;
131+ if ( o is VbdCombiItem v )
132+ v . Vbd . PropertyChanged -= vbd_PropertyChanged ;
133133 }
134134
135135 comboBoxDrive . Items . Clear ( ) ;
136+
136137 if ( VM != null && ! VM . is_control_domain )
137138 {
138139 List < VBD > vbds = VM . Connection . ResolveAll ( VM . VBDs ) ;
@@ -142,31 +143,32 @@ private void refreshDrives()
142143 VM . Connection . CachePopulated += CachePopulatedMethod ;
143144 return ;
144145 }
146+
145147 vbds . RemoveAll ( vbd => ! vbd . IsCDROM ( ) && ! vbd . IsFloppyDrive ( ) ) ;
146148 vbds . Sort ( ) ;
149+
147150 int dvdCount = 0 ;
148151 int floppyCount = 0 ;
152+
149153 foreach ( VBD vbd in vbds )
150154 {
151- vbd . PropertyChanged += new PropertyChangedEventHandler ( vbd_PropertyChanged ) ;
155+ vbd . PropertyChanged += vbd_PropertyChanged ;
156+ VbdCombiItem item ;
157+
152158 if ( vbd . IsCDROM ( ) )
153159 {
154160 dvdCount ++ ;
155- VbdCombiItem i = new VbdCombiItem ( ) ;
156- i . name = string . Format ( Messages . DVD_DRIVE_LABEL_NUMBERED , dvdCount ) ;
157- i . vbd = vbd ;
158- comboBoxDrive . Items . Add ( i ) ;
161+ item = new VbdCombiItem ( string . Format ( Messages . DVD_DRIVE_LABEL_NUMBERED , dvdCount ) , vbd ) ;
159162 }
160163 else
161164 {
162165 floppyCount ++ ;
163- VbdCombiItem i = new VbdCombiItem ( ) ;
164- i . name = string . Format ( Messages . FLOPPY_DRIVE_LABEL_NUMBERED , floppyCount ) ;
165- i . vbd = vbd ;
166- comboBoxDrive . Items . Add ( i ) ;
167- }
166+ item = new VbdCombiItem ( string . Format ( Messages . FLOPPY_DRIVE_LABEL_NUMBERED , floppyCount ) , vbd ) ;
167+ }
168+ comboBoxDrive . Items . Add ( item ) ;
168169 }
169170 }
171+
170172 if ( comboBoxDrive . Items . Count == 0 )
171173 {
172174 comboBoxDrive . Visible = false ;
@@ -197,54 +199,59 @@ private void refreshDrives()
197199 newCDLabel . Visible = false ;
198200 linkLabel1 . Visible = true ;
199201 }
200- inRefresh = false ;
202+
203+ _inRefresh = false ;
204+
201205 // Restore prev selection or select the top item by default
202206 if ( prevSelection != null )
203207 {
204208 foreach ( object o in comboBoxDrive . Items )
205209 {
206- VbdCombiItem v = o as VbdCombiItem ;
207- if ( v . vbd . uuid == prevSelection . vbd . uuid )
210+ if ( o is VbdCombiItem v && v . Vbd . uuid == prevSelection . Vbd . uuid )
208211 {
209212 comboBoxDrive . SelectedItem = o ;
210213 return ;
211214 }
212215 }
213216 }
214- if ( comboBoxDrive . Items . Count == 0 )
215- comboBoxDrive . SelectedItem = null ;
216- else
217- comboBoxDrive . SelectedItem = comboBoxDrive . Items [ 0 ] ;
217+
218+ comboBoxDrive . SelectedItem = comboBoxDrive . Items . Count == 0 ? null : comboBoxDrive . Items [ 0 ] ;
218219 }
219220
220- void vbd_PropertyChanged ( object sender , PropertyChangedEventArgs e )
221+ private void vbd_PropertyChanged ( object sender , PropertyChangedEventArgs e )
221222 {
222- refreshDrives ( ) ;
223+ RefreshDrives ( ) ;
223224 }
224225
225226 private void CachePopulatedMethod ( IXenConnection conn )
226227 {
227228 VM . Connection . CachePopulated -= CachePopulatedMethod ;
228- refreshDrives ( ) ;
229+ RefreshDrives ( ) ;
229230 }
230231
231- internal class VbdCombiItem
232+ private class VbdCombiItem
232233 {
233- public string name ;
234- public VBD vbd ;
234+ public string Name { get ; }
235+ public VBD Vbd { get ; }
236+
237+ public VbdCombiItem ( string name , VBD vbd )
238+ {
239+ Name = name ;
240+ Vbd = vbd ;
241+ }
235242
236243 public override string ToString ( )
237244 {
238- return name ;
245+ return Name ;
239246 }
240247 }
241248
242249 private void comboBoxDrive_SelectedIndexChanged ( object sender , EventArgs e )
243250 {
244- if ( inRefresh )
251+ if ( _inRefresh )
245252 return ;
246253
247- cdChanger1 . Drive = ( comboBoxDrive . SelectedItem as VbdCombiItem ) ? . vbd ;
254+ cdChanger1 . Drive = ( comboBoxDrive . SelectedItem as VbdCombiItem ) ? . Vbd ;
248255 }
249256
250257
0 commit comments