Exemplo n.º 1
0
        public static int SetFolderQuota(int packageId, string path, string driveName, string quotas)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "SET_QUOTA_ON_FOLDER", path, packageId);

            try
            {
                // disk space quota
                // This gets all the disk space allocated for a specific customer
                // It includes the package Add Ons * Quatity + Hosting Plan System disk space value. //Quotas.OS_DISKSPACE
                QuotaValueInfo diskSpaceQuota = PackageController.GetPackageQuota(packageId, quotas);


                #region figure Quota Unit

                // Quota Unit
                string unit = String.Empty;
                if (diskSpaceQuota.QuotaDescription.ToLower().Contains("gb"))
                {
                    unit = "GB";
                }
                else if (diskSpaceQuota.QuotaDescription.ToLower().Contains("mb"))
                {
                    unit = "MB";
                }
                else
                {
                    unit = "KB";
                }

                #endregion

                OS.OperatingSystem os = GetOS(packageId);

                os.SetQuotaLimitOnFolder(path, driveName, QuotaType.Hard, diskSpaceQuota.QuotaAllocatedValue.ToString() + unit, 0, String.Empty, String.Empty);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }