1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
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.
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.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Mike Lasky (mlasky@novell.com)
22
|***************************************************************************/
24
namespace Novell.iFolderWeb.Admin
29
using System.Resources;
31
using System.Web.UI.WebControls;
32
using System.Web.UI.HtmlControls;
35
/// Summary description for DiskSpaceQuota.
37
public class DiskSpaceQuota : System.Web.UI.UserControl
42
/// Default constants.
44
private const long DefaultDiskQuotaLimit = 100 * 1024 * 1024;
49
private ResourceManager rm;
53
/// Control that contains the title for the page.
55
protected Label Title;
58
/// Disk Quota policy controls.
60
protected CheckBox Enabled;
63
/// Control that contains the limit tag.
65
protected Label LimitTag;
68
/// Control that contains the limit value.
70
protected TextBox LimitValue;
73
/// Disk Quota policy controls.
75
protected Label UsedTag;
78
/// Disk Quota policy controls.
80
protected Label UsedValue;
83
/// Disk Quota policy controls.
85
protected Label UsedUnits;
88
/// Disk Quota policy controls.
90
protected Label AvailableTag;
93
/// Disk Quota policy controls.
95
protected Label AvailableValue;
98
/// Disk Quota policy controls.
100
protected Label AvailableUnits;
103
/// Disk Quota policy controls.
105
protected Label EffectiveTag;
108
/// Disk Quota policy controls.
110
protected Label EffectiveValue;
113
/// Disk Quota policy controls.
115
protected Label EffectiveUnits;
119
/// Event that notifies consumer that the disk quota limit has changed.
121
public event EventHandler LimitChanged = null;
128
/// Gets or sets the effective disk space.
130
private long EffectiveSpace
132
get { return ( long )ViewState[ "EffectiveSpace" ]; }
133
set { ViewState[ "EffectiveSpace" ] = value; }
138
#region Private Methods
143
/// <param name="sender"></param>
144
/// <param name="e"></param>
145
private void Page_Load(object sender, System.EventArgs e)
148
rm = Application[ "RM" ] as ResourceManager;
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" );
162
#region Protected Methods
165
/// Event handler that gets called when the disk space quota text is changed.
167
/// <param name="sender"></param>
168
/// <param name="e"></param>
169
protected void DiskSpaceQuotaChanged( Object sender, EventArgs e )
171
if ( LimitChanged != null )
173
LimitChanged( this, e );
178
/// Get a Localized String
180
/// <param name="key">Key to the localized string.</param>
181
/// <returns>Localized string.</returns>
182
protected string GetString( string key )
184
return rm.GetString( key );
188
/// Event handler that gets called when the quota enable checkbox is changed.
190
/// <param name="sender"></param>
191
/// <param name="e"></param>
192
protected void QuotaCheckChanged( Object sender, EventArgs e )
194
if ( Enabled.Checked )
196
long limit = ( EffectiveSpace == 0 ) ? DefaultDiskQuotaLimit : EffectiveSpace;
197
LimitValue.Text = Utils.ConvertToMBString( limit, false, rm );
201
LimitValue.Text = String.Empty;
204
LimitValue.Enabled = Enabled.Checked;
205
DiskSpaceQuotaChanged( sender, e );
210
#region Public Methods
213
/// Gets the disk quota policy for the current user.
215
/// <param name="policy">User policy object</param>
216
public void GetDiskSpacePolicy( UserPolicy policy )
218
EffectiveSpace = policy.SpaceLimitEffective;
220
Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimit > 0 );
222
UsedValue.Text = Utils.ConvertToMBString( policy.SpaceUsed, false, rm );
223
UsedUnits.Text = GetString( "MB" );
225
LimitValue.Text = Enabled.Checked ?
226
Utils.ConvertToMBString( policy.SpaceLimit, false, rm ) : String.Empty;
228
if ( ( policy.SpaceLimitEffective > 0 ) || ( policy.SpaceLimit > 0 ) )
230
AvailableValue.Text = Utils.ConvertToMBString( policy.SpaceAvailable, false, rm );
231
AvailableUnits.Text = GetString( "MB" );
235
AvailableValue.Text = GetString( "UNLIMITED" );
236
AvailableUnits.Text = String.Empty;
239
if ( Enabled.Checked )
241
EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = false;
245
EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = true;
246
if ( policy.SpaceLimitEffective > 0 )
248
EffectiveValue.Text = Utils.ConvertToMBString( policy.SpaceLimitEffective, false, rm );
249
EffectiveUnits.Text = GetString( "MB" );
253
EffectiveValue.Text = GetString( "UNLIMITED" );
254
EffectiveUnits.Text = String.Empty;
260
/// Gets the disk quota policy for the current ifolder.
262
/// <param name="policy">iFolder policy object</param>
263
public void GetDiskSpacePolicy( iFolderPolicy policy )
265
EffectiveSpace = policy.SpaceLimitEffective;
267
Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimit > 0 );
269
UsedValue.Text = Utils.ConvertToMBString( policy.SpaceUsed, false, rm );
270
UsedUnits.Text = GetString( "MB" );
272
LimitValue.Text = Enabled.Checked ?
273
Utils.ConvertToMBString( policy.SpaceLimit, false, rm ) : String.Empty;
275
if ( ( policy.SpaceLimitEffective > 0 ) || ( policy.SpaceLimit > 0 ) )
277
AvailableValue.Text = Utils.ConvertToMBString( policy.SpaceAvailable, false, rm );
278
AvailableUnits.Text = GetString( "MB" );
280
EffectiveValue.Text = Utils.ConvertToMBString( policy.SpaceLimitEffective, false, rm );
281
EffectiveUnits.Text = GetString( "MB" );
285
AvailableValue.Text = GetString( "UNLIMITED" );
286
AvailableUnits.Text = String.Empty;
288
EffectiveValue.Text = GetString( "UNLIMITED" );
289
EffectiveUnits.Text = String.Empty;
294
/// Gets the disk quota policy for the system.
296
/// <param name="policy">System policy object</param>
297
public void GetDiskSpacePolicy( SystemPolicy policy )
301
Enabled.Checked = LimitValue.Enabled = ( policy.SpaceLimitUser > 0 );
302
LimitValue.Text = Enabled.Checked ?
303
Utils.ConvertToMBString( policy.SpaceLimitUser, false, rm ) : String.Empty;
305
UsedTag.Visible = UsedValue.Visible = false;
306
AvailableTag.Visible = AvailableValue.Visible = false;
307
EffectiveTag.Visible = EffectiveValue.Visible = EffectiveUnits.Visible = false;
311
/// Sets the disk space policy for this user.
313
/// <param name="policy">User policy that the new disk space quota will be set.</param>
314
public void SetDiskSpacePolicy( UserPolicy policy )
316
// Verify that the disk space quota value is valid.
317
if ( Enabled.Checked )
319
string limitString = LimitValue.Text;
320
if ( ( limitString != null ) && ( limitString != String.Empty ) )
324
decimal limit = Convert.ToDecimal( limitString );
327
// Convert from megabytes back to bytes.
328
policy.SpaceLimit = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
332
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
335
catch ( FormatException )
337
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
339
catch ( OverflowException )
341
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
346
throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
351
policy.SpaceLimit = 0;
356
/// Sets the disk space policy for this ifolder.
358
/// <param name="policy">iFolder policy that the new disk space quota will be set.</param>
359
public void SetDiskSpacePolicy( iFolderPolicy policy )
361
// Verify that the disk space quota value is valid.
362
if ( Enabled.Checked )
364
string limitString = LimitValue.Text;
365
if ( ( limitString != null ) && ( limitString != String.Empty ) )
369
decimal limit = Convert.ToDecimal( limitString );
372
// Convert from megabytes back to bytes.
373
policy.SpaceLimit = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
377
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
380
catch ( FormatException )
382
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
384
catch ( OverflowException )
386
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
391
throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
396
policy.SpaceLimit = 0;
401
/// Sets the disk space policy for the system.
403
/// <param name="policy">System policy that the new disk space quota will be set.</param>
404
public void SetDiskSpacePolicy( SystemPolicy policy )
406
// Verify that the disk space quota value is valid.
407
if ( Enabled.Checked )
409
string limitString = LimitValue.Text;
410
if ( ( limitString != null ) && ( limitString != String.Empty ) )
414
decimal limit = Convert.ToDecimal( limitString );
417
// Convert from megabytes back to bytes.
418
policy.SpaceLimitUser = Convert.ToInt64( Decimal.Round( limit, 2 ) * 1048576 );
422
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
425
catch ( FormatException )
427
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
429
catch ( OverflowException )
431
throw new ArgumentException( GetString( "ERRORINVALIDQUOTA" ) );
436
throw new ArgumentException( GetString( "ERRORNOQUOTA" ) );
441
policy.SpaceLimitUser = 0;
447
#region Web Form Designer generated code
452
/// <param name="e"></param>
453
override protected void OnInit(EventArgs e)
456
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
458
InitializeComponent();
463
/// Required method for Designer support - do not modify
464
/// the contents of this method with the code editor.
466
private void InitializeComponent()
468
Enabled.CheckedChanged += new EventHandler( QuotaCheckChanged );
469
LimitValue.TextChanged += new EventHandler( DiskSpaceQuotaChanged );
471
this.Load += new System.EventHandler(this.Page_Load);