Using system;
USING DISKQUOTATYPELIBRARY;
Namespace ex3cut3.libraries {/// ///// summary> public class quotaclass {private diskquotacontrolclass _diskquotacontrol;
// this path as to be in this format or // else is going to give an error of invalid path private const string filesharevolume = @ "// server / c $ /"; private const Int mbtobytes = 1048576;
public DiskQuotaControlClass DiskQuotaControl {get {if (this._diskQuotaControl == null) {this._diskQuotaControl = new DiskQuotaControlClass (); // Initializes the control to the specified path this._diskQuotaControl.Initialize (FILESHAREVOLUME, true);} return this._diskQuotaControl }}
Public quotaclass () {}
/// /// ads a user to the quota entries of the volume /// summary> /// The name of the user to add param> // / The domain what used Uses to logon param> /// The quota limit of this user param> public void add (String Username, String userDomain, int quotaLimit) {DIDiskQuotaUser dskuser = null; // In some cases if you use name resolution, // the application will give an error this.DiskQuotaControl.UserNameResolution = UserNameResolutionConstants.dqResolveNone;. // Here we had the user to the QUOTAS ENTRYS OF // THE VOLUME, We use user@domain.net the logon name of the user. // You can use the domain / user or just the user, // But in Like this works Faster dskuser = this.diskquotacontrol. AddUser (User.SAMACCOUNTNAME "@" User.d Omain); // Here We set the limited of the quota, this is // prepared to received MB SO i convert it to bytes dskuser.quotalimit = (int) quotalimit * mbtobytes; // Here is the set of the warning limited DSKUSER .Quotathrest / 1.2) * MbTobytes; dskuser = null;}
/// /// Removes the user form the quota entries list /// //// param> public void remove (String username) {// hERE We just use the the user, and infoke // the method this.diskquotacontrol.deleteuseuser (this.getuser (username));} /// /// a private function to return the user object // / summary> /// The user name param> /// a didiskquotause Object /// of the specified user returns> private didiskquotauser getUser {// invokes the method to find a user in a quota entry list return this.diskquotacontrol.finduser (username);
/// /// Gets the quota of the user /// summary> /// The user name param> /// a formated string of THE quota /// limited of the user returns> private string getquota (String Username) {// Here We return the text of the quota limit //0.0 bytes, 0.0 kb, 0.0 mb etc Return this.getuser (UserName) .Quotalimittext;
/// /// Gets the quota currently use by the user /// summary> /// The user name param> /// a formated string of the quota /// used by the user returns> private string GetQuotaUsed (string userName) {return this.GetUser (userName) .QuotaUsedText;} /// /// Change the quota of a specified user /// summary> /// The user name param> /// The new quota limit of the user param> Private vid ChangeQuota (string userName, int quotaLimit) {DIDiskQuotaUser dskuser = this.GetUser (userName); dskuser.QuotaLimit = quotaLimit * Support.Constants.CONVERTBTOMB; dskuser.QuotaThreshold = (quotaLimit / 1.2) * Support.Constants.CONVERTBTOMB;}}}