예제 #1
0
        public static int ApplyEnableHardQuotaFeature(int packageId)
        {
            if (SecurityContext.CheckAccount(DemandAccount.IsActive | DemandAccount.IsAdmin | DemandAccount.NotDemo) != 0)
            {
                throw new Exception("This method could be called by serveradmin only.");
            }

            // place log record
            TaskManager.StartTask("FILES", "APPLY_ENABLEHARDQUOTAFEATURE");

            try
            {
                // request OS service
                //int osId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);
                //if (osId == 0)
                //    return -1;

                //OS.OperatingSystem os = new OS.OperatingSystem();
                //ServiceProviderProxy.Init(os, osId);

                ////Get operating system settings
                // StringDictionary osSesstings = ServerController.GetServiceSettings(osId);
                //  bool diskQuotaEnabled = (osSesstings["EnableHardQuota"] != null) ? bool.Parse(osSesstings["EnableHardQuota"]) : false;
                //string driveName = osSesstings["LocationDrive"];

                //if (!diskQuotaEnabled)
                //    return -1;


                List <PackageInfo> allPackages = PackageController.GetPackagePackages(packageId, true);

                foreach (PackageInfo childPackage in allPackages)
                {
                    // request OS service
                    int osId = PackageController.GetPackageServiceId(childPackage.PackageId, ResourceGroups.Os);
                    if (osId == 0)
                    {
                        continue;
                    }

                    OS.OperatingSystem os = new OS.OperatingSystem();
                    ServiceProviderProxy.Init(os, osId);

                    //Get operating system settings
                    StringDictionary osSesstings = ServerController.GetServiceSettings(osId);
                    string           driveName   = osSesstings["LocationDrive"];

                    if (String.IsNullOrEmpty(driveName))
                    {
                        continue;
                    }

                    string homeFolder = FilesController.GetHomeFolder(childPackage.PackageId);
                    FilesController.SetFolderQuota(childPackage.PackageId, homeFolder, driveName, Quotas.OS_DISKSPACE);
                }
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }

            return(0);
        }