~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/admin/.svn/text-base/DiskSpaceQuota.ascx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 | Author: Mike Lasky (mlasky@novell.com)
22
 
 |***************************************************************************/
23
 
 
24
 
namespace Novell.iFolderWeb.Admin
25
 
{
26
 
        using System;
27
 
        using System.Data;
28
 
        using System.Drawing;
29
 
        using System.Resources;
30
 
        using System.Web;
31
 
        using System.Web.UI.WebControls;
32
 
        using System.Web.UI.HtmlControls;
33
 
 
34
 
        /// <summary>
35
 
        ///             Summary description for DiskSpaceQuota.
36
 
        /// </summary>
37
 
        public class DiskSpaceQuota : System.Web.UI.UserControl
38
 
        {
39
 
                #region Class Members
40
 
 
41
 
                /// <summary>
42
 
                /// Default constants.
43
 
                /// </summary>
44
 
                private const long DefaultDiskQuotaLimit = 100 * 1024 * 1024;
45
 
 
46
 
                /// <summary>
47
 
                /// Resource Manager
48
 
                /// </summary>
49
 
                private ResourceManager rm;
50
 
 
51
 
 
52
 
                /// <summary>
53
 
                /// Control that contains the title for the page.
54
 
                /// </summary>
55
 
                protected Label Title;
56
 
 
57
 
                /// <summary>
58
 
                /// Disk Quota policy controls.
59
 
                /// </summary>
60
 
                protected CheckBox Enabled;
61
 
 
62
 
                /// <summary>
63
 
                /// Control that contains the limit tag.
64
 
                /// </summary>
65
 
                protected Label LimitTag;
66
 
 
67
 
                /// <summary>
68
 
                /// Control that contains the limit value.
69
 
                /// </summary>
70
 
                protected TextBox LimitValue;
71
 
 
72
 
                /// <summary>
73
 
                /// Disk Quota policy controls.
74
 
                /// </summary>
75
 
                protected Label UsedTag;
76
 
 
77
 
                /// <summary>
78
 
                /// Disk Quota policy controls.
79
 
                /// </summary>
80
 
                protected Label UsedValue;
81
 
 
82
 
                /// <summary>
83
 
                /// Disk Quota policy controls.
84
 
                /// </summary>
85
 
                protected Label UsedUnits;
86
 
 
87
 
                /// <summary>
88
 
                /// Disk Quota policy controls.
89
 
                /// </summary>
90
 
                protected Label AvailableTag;
91
 
 
92
 
                /// <summary>
93
 
                /// Disk Quota policy controls.
94
 
                /// </summary>
95
 
                protected Label AvailableValue;
96
 
 
97
 
                /// <summary>
98
 
                /// Disk Quota policy controls.
99
 
                /// </summary>
100
 
                protected Label AvailableUnits;
101
 
 
102
 
                /// <summary>
103
 
                /// Disk Quota policy controls.
104
 
                /// </summary>
105
 
                protected Label EffectiveTag;
106
 
 
107
 
                /// <summary>
108
 
                /// Disk Quota policy controls.
109
 
                /// </summary>
110
 
                protected Label EffectiveValue;
111
 
 
112
 
                /// <summary>
113
 
                /// Disk Quota policy controls.
114
 
                /// </summary>
115
 
                protected Label EffectiveUnits;
116
 
 
117
 
 
118
 
                /// <summary>
119
 
                /// Event that notifies consumer that the disk quota limit has changed.
120
 
                /// </summary>
121
 
                public event EventHandler LimitChanged = null;
122
 
 
123
 
                #endregion
124
 
 
125
 
                #region Properties
126
 
 
127
 
                /// <summary>
128
 
                /// Gets or sets the effective disk space.
129
 
                /// </summary>
130
 
                private long EffectiveSpace
131
 
                {
132
 
                        get { return ( long )ViewState[ "EffectiveSpace" ]; }
133
 
                        set { ViewState[ "EffectiveSpace" ] = value; }
134
 
                }
135
 
 
136
 
                #endregion
137
 
 
138
 
                #region Private Methods
139
 
 
140
 
                /// <summary>
141
 
                /// Page_Load
142
 
                /// </summary>
143
 
                /// <param name="sender"></param>
144
 
                /// <param name="e"></param>
145
 
                private void Page_Load(object sender, System.EventArgs e)
146
 
                {
147
 
                        // localization
148
 
                        rm = Application[ "RM" ] as ResourceManager;
149
 
 
150
 
                        if ( !IsPostBack )
151
 
                        {
152
 
                                Title.Text = GetString( "DISKQUOTA" );
153
 
                                LimitTag.Text = GetString( "LIMITTAG" );
154
 
                                UsedTag.Text = GetString ( "USEDTAG" );
155
 
                                AvailableTag.Text = GetString( "AVAILABLETAG" );
156
 
                                EffectiveTag.Text = GetString( "EFFECTIVETAG" );
157
 
                        }
158
 
                }
159
 
 
160
 
                #endregion
161
 
 
162
 
                #region Protected Methods
163
 
 
164
 
                /// <summary>
165
 
                /// Event handler that gets called when the disk space quota text is changed.
166
 
                /// </summary>
167
 
                /// <param name="sender"></param>
168
 
                /// <param name="e"></param>
169
 
                protected void DiskSpaceQuotaChanged( Object sender, EventArgs e )
170
 
                {
171
 
                        if ( LimitChanged != null )
172
 
                        {
173
 
                                LimitChanged( this, e );
174
 
                        }
175
 
                }
176
 
 
177
 
                /// <summary>
178
 
                /// Get a Localized String
179
 
                /// </summary>
180
 
                /// <param name="key">Key to the localized string.</param>
181
 
                /// <returns>Localized string.</returns>
182
 
                protected string GetString( string key )
183
 
                {
184
 
                        return rm.GetString( key );
185
 
                }
186
 
 
187
 
                /// <summary>
188
 
                /// Event handler that gets called when the quota enable checkbox is changed.
189
 
                /// </summary>
190
 
                /// <param name="sender"></param>
191
 
                /// <param name="e"></param>
192
 
                protected void QuotaCheckChanged( Object sender, EventArgs e )
193
 
                {
194
 
                        if ( Enabled.Checked )
195
 
                        {
196
 
                                long limit = ( EffectiveSpace == 0 ) ? DefaultDiskQuotaLimit : EffectiveSpace;
197
 
                                LimitValue.Text = Utils.ConvertToMBString( limit, false, rm );
198
 
                        }
199
 
                        else
200
 
                        {
201
 
                                LimitValue.Text = String.Empty;
202
 
                        }
203
 
 
204
 
                        LimitValue.Enabled = Enabled.Checked;
205
 
                        DiskSpaceQuotaChanged( sender, e );
206
 
                }
207
 
 
208
 
                #endregion
209
 
 
210
 
                #region Public Methods
211
 
 
212
 
                /// <summary>
213
 
                /// Gets the disk quota policy for the current user.
214
 
                /// </summary>
215
 
                /// <param name="policy">User policy object</param>
216
 
                public void GetDiskSpacePolicy( UserPolicy policy )
217
 
                {
218
 
                        EffectiveSpace = policy.SpaceLimitEffective;
219
 
 
220
 
                        Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimit > 0 );
221
 
 
222
 
                        UsedValue.Text = Utils.ConvertToMBString( policy.SpaceUsed, false, rm );
223
 
                        UsedUnits.Text = GetString( "MB" );
224
 
 
225
 
                        LimitValue.Text = Enabled.Checked ? 
226
 
                                Utils.ConvertToMBString( policy.SpaceLimit, false, rm ) : String.Empty;
227
 
 
228
 
                        if ( ( policy.SpaceLimitEffective > 0 ) || ( policy.SpaceLimit > 0 ) )
229
 
                        {
230
 
                                AvailableValue.Text = Utils.ConvertToMBString( policy.SpaceAvailable, false, rm );
231
 
                                AvailableUnits.Text = GetString( "MB" );
232
 
                        }
233
 
                        else
234
 
                        {
235
 
                                AvailableValue.Text = GetString( "UNLIMITED" );
236
 
                                AvailableUnits.Text = String.Empty;
237
 
                        }
238
 
 
239
 
                        if ( Enabled.Checked )
240
 
                        {
241
 
                                EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = false;
242
 
                        }
243
 
                        else
244
 
                        {
245
 
                                EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = true;
246
 
                                if ( policy.SpaceLimitEffective > 0 )
247
 
                                {
248
 
                                        EffectiveValue.Text = Utils.ConvertToMBString( policy.SpaceLimitEffective, false, rm );
249
 
                                        EffectiveUnits.Text = GetString( "MB" );
250
 
                                }
251
 
                                else
252
 
                                {
253
 
                                        EffectiveValue.Text = GetString( "UNLIMITED" );
254
 
                                        EffectiveUnits.Text = String.Empty;
255
 
                                }
256
 
                        }
257
 
                }
258
 
 
259
 
                /// <summary>
260
 
                /// Gets the disk quota policy for the current ifolder.
261
 
                /// </summary>
262
 
                /// <param name="policy">iFolder policy object</param>
263
 
                public void GetDiskSpacePolicy( iFolderPolicy policy )
264
 
                {
265
 
                        EffectiveSpace = policy.SpaceLimitEffective;
266
 
 
267
 
                        Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimit > 0 );
268
 
 
269
 
                        UsedValue.Text = Utils.ConvertToMBString( policy.SpaceUsed, false, rm );
270
 
                        UsedUnits.Text = GetString( "MB" );
271
 
 
272
 
                        LimitValue.Text = Enabled.Checked ? 
273
 
                                Utils.ConvertToMBString( policy.SpaceLimit, false, rm ) : String.Empty;
274
 
 
275
 
                        if ( ( policy.SpaceLimitEffective > 0 ) || ( policy.SpaceLimit > 0 ) )
276
 
                        {
277
 
                                AvailableValue.Text = Utils.ConvertToMBString( policy.SpaceAvailable, false, rm );
278
 
                                AvailableUnits.Text = GetString( "MB" );
279
 
 
280
 
                                EffectiveValue.Text = Utils.ConvertToMBString( policy.SpaceLimitEffective, false, rm );
281
 
                                EffectiveUnits.Text = GetString( "MB" );
282
 
                        }
283
 
                        else
284
 
                        {
285
 
                                AvailableValue.Text = GetString( "UNLIMITED" );
286
 
                                AvailableUnits.Text = String.Empty;
287
 
 
288
 
                                EffectiveValue.Text = GetString( "UNLIMITED" );
289
 
                                EffectiveUnits.Text = String.Empty;
290
 
                        }
291
 
                }
292
 
 
293
 
                /// <summary>
294
 
                /// Gets the disk quota policy for the system.
295
 
                /// </summary>
296
 
                /// <param name="policy">System policy object</param>
297
 
                public void GetDiskSpacePolicy( SystemPolicy policy )
298
 
                {
299
 
                        EffectiveSpace = 0;
300
 
 
301
 
                        Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimitUser > 0 );
302
 
                        LimitValue.Text = Enabled.Checked ? 
303
 
                                Utils.ConvertToMBString( policy.SpaceLimitUser, false, rm ) : String.Empty;
304
 
 
305
 
                        UsedTag.Visible = UsedValue.Visible = false;
306
 
                        AvailableTag.Visible = AvailableValue.Visible = false;
307
 
                        EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = false;
308
 
                }
309
 
 
310
 
                /// <summary>
311
 
                /// Sets the disk space policy for this user.
312
 
                /// </summary>
313
 
                /// <param name="policy">User policy that the new disk space quota will be set.</param>
314
 
                public void SetDiskSpacePolicy( UserPolicy policy )
315
 
                {
316
 
                        // Verify that the disk space quota value is valid.
317
 
                        if ( Enabled.Checked )
318
 
                        {
319
 
                                string limitString = LimitValue.Text;
320
 
                                if ( ( limitString != null ) && ( limitString != String.Empty ) )
321
 
                                {
322
 
                                        try
323
 
                                        {
324
 
                                                decimal limit = Convert.ToDecimal( limitString );
325
 
                                                if ( limit >= 1 )
326
 
                                                {
327
 
                                                        // Convert from megabytes back to bytes.
328
 
                                                        policy.SpaceLimit = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
329
 
                                                }
330
 
                                                else
331
 
                                                {
332
 
                                                        throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
333
 
                                                }
334
 
                                        }
335
 
                                        catch ( FormatException )
336
 
                                        {
337
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
338
 
                                        }
339
 
                                        catch ( OverflowException )
340
 
                                        {
341
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
342
 
                                        }
343
 
                                }
344
 
                                else
345
 
                                {
346
 
                                        throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
347
 
                                }
348
 
                        }
349
 
                        else
350
 
                        {
351
 
                                policy.SpaceLimit = 0;
352
 
                        }
353
 
                }
354
 
 
355
 
                /// <summary>
356
 
                /// Sets the disk space policy for this ifolder.
357
 
                /// </summary>
358
 
                /// <param name="policy">iFolder policy that the new disk space quota will be set.</param>
359
 
                public void SetDiskSpacePolicy( iFolderPolicy policy )
360
 
                {
361
 
                        // Verify that the disk space quota value is valid.
362
 
                        if ( Enabled.Checked )
363
 
                        {
364
 
                                string limitString = LimitValue.Text;
365
 
                                if ( ( limitString != null ) && ( limitString != String.Empty ) )
366
 
                                {
367
 
                                        try
368
 
                                        {
369
 
                                                decimal limit = Convert.ToDecimal( limitString );
370
 
                                                if ( limit >= 1 )
371
 
                                                {
372
 
                                                        // Convert from megabytes back to bytes.
373
 
                                                        policy.SpaceLimit = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
374
 
                                                }
375
 
                                                else
376
 
                                                {
377
 
                                                        throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
378
 
                                                }
379
 
                                        }
380
 
                                        catch ( FormatException )
381
 
                                        {
382
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
383
 
                                        }
384
 
                                        catch ( OverflowException )
385
 
                                        {
386
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
387
 
                                        }
388
 
                                }
389
 
                                else
390
 
                                {
391
 
                                        throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
392
 
                                }
393
 
                        }
394
 
                        else
395
 
                        {
396
 
                                policy.SpaceLimit = 0;
397
 
                        }
398
 
                }
399
 
 
400
 
                /// <summary>
401
 
                /// Sets the disk space policy for the system.
402
 
                /// </summary>
403
 
                /// <param name="policy">System policy that the new disk space quota will be set.</param>
404
 
                public void SetDiskSpacePolicy( SystemPolicy policy )
405
 
                {
406
 
                        // Verify that the disk space quota value is valid.
407
 
                        if ( Enabled.Checked )
408
 
                        {
409
 
                                string limitString = LimitValue.Text;
410
 
                                if ( ( limitString != null ) && ( limitString != String.Empty ) )
411
 
                                {
412
 
                                        try
413
 
                                        {
414
 
                                                decimal limit = Convert.ToDecimal( limitString );
415
 
                                                if ( limit >= 1 )
416
 
                                                {
417
 
                                                        // Convert from megabytes back to bytes.
418
 
                                                        policy.SpaceLimitUser = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
419
 
                                                }
420
 
                                                else
421
 
                                                {
422
 
                                                        throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
423
 
                                                }
424
 
                                        }
425
 
                                        catch ( FormatException )
426
 
                                        {
427
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
428
 
                                        }
429
 
                                        catch ( OverflowException )
430
 
                                        {
431
 
                                                throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
432
 
                                        }
433
 
                                }
434
 
                                else
435
 
                                {
436
 
                                        throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
437
 
                                }
438
 
                        }
439
 
                        else
440
 
                        {
441
 
                                policy.SpaceLimitUser = 0;
442
 
                        }
443
 
                }
444
 
 
445
 
                #endregion
446
 
 
447
 
                #region Web Form Designer generated code
448
 
 
449
 
                /// <summary>
450
 
                /// OnInit
451
 
                /// </summary>
452
 
                /// <param name="e"></param>
453
 
                override protected void OnInit(EventArgs e)
454
 
                {
455
 
                        //
456
 
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
457
 
                        //
458
 
                        InitializeComponent();
459
 
                        base.OnInit(e);
460
 
                }
461
 
                
462
 
                /// <summary>
463
 
                ///             Required method for Designer support - do not modify
464
 
                ///             the contents of this method with the code editor.
465
 
                /// </summary>
466
 
                private void InitializeComponent()
467
 
                {
468
 
                        Enabled.CheckedChanged += new EventHandler( QuotaCheckChanged );
469
 
                        LimitValue.TextChanged += new EventHandler( DiskSpaceQuotaChanged );
470
 
 
471
 
                        this.Load += new System.EventHandler(this.Page_Load);
472
 
                }
473
 
                #endregion
474
 
        }
475
 
}