Example #1
0
        /// <summary>
        /// Creates a file size filter policy for the current user on the current machine.
        /// </summary>
        /// <param name="limit">Size of file in bytes that all users in the domain will be limited to.</param>
        static public void Create(long limit)
        {
            // Need a policy manager.
            PolicyManager pm = new PolicyManager();

            // See if the policy already exists.
            Policy policy = pm.GetPolicy(FileSizeFilterPolicyID);

            if (limit > 0)
            {
                if (policy == null)
                {
                    // The policy does not exist, create a new one and add the rules.
                    policy = new Policy(FileSizeFilterPolicyID, FileSizeFilterShortDescription);
                }
                else
                {
                    // The policy already exists, delete the old rules.
                    policy.DeleteRule(FileSizeFilter.GetRule(policy));
                }

                // Add the new rules and save the policy.
                policy.AddRule(new Rule(limit, Rule.Operation.Greater, Rule.Result.Deny));
                pm.CommitLocalMachinePolicy(policy);
            }
            else if (policy != null)
            {
                // Setting the limit to zero is the same as deleting the policy.
                pm.DeletePolicy(policy);
            }
        }
Example #2
0
 static public FileSizeFilter Get(Member member, Collection collection)
 {
     return(FileSizeFilter.Get(collection));
 }