diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs | 25 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs | 7 |
2 files changed, 22 insertions, 10 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs index 7b4925d6de..0e7b6e5b61 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs @@ -41,8 +41,6 @@ using System.Globalization; namespace MonoDevelop.Projects.Policies { - - public static class PolicyService { const string TYPE_EXT_POINT = "/MonoDevelop/ProjectModel/PolicyTypes"; @@ -1122,6 +1120,13 @@ namespace MonoDevelop.Projects.Policies /// </param> public static void AddUserPolicySet (PolicySet pset) { + if (pset.Id != null) + throw new ArgumentException ("User policy cannot have ID"); + if (string.IsNullOrEmpty (pset.Name)) + throw new ArgumentException ("User policy cannot have null or empty name"); + if (sets.Any (ps => ps.Name == pset.Name)) + throw new ArgumentException ("There is already a policy with the name ' " + pset.Name + "'"); + userSets.Add (pset); sets.Add (pset); } @@ -1200,7 +1205,14 @@ namespace MonoDevelop.Projects.Policies if (Directory.Exists (PoliciesFolder)) { foreach (var file in Directory.GetFiles (PoliciesFolder, "*.mdpolicy.xml")) { - LoadPolicy (file); + try { + LoadPolicy (file); + } catch (Exception ex) { + LoggingService.LogError ( + string.Format ("Failed to load policy file '{0}'", Path.GetFileName (file)), + ex + ); + } } } @@ -1225,11 +1237,10 @@ namespace MonoDevelop.Projects.Policies while (xr.NodeType != XmlNodeType.EndElement) { PolicySet pset = new PolicySet (); pset.LoadFromXml (xr); - if (pset.Id == "Default") + if (pset.Id == "Default") { defaultPolicies = pset; - else { - userSets.Add (pset); - sets.Add (pset); + } else { + AddUserPolicySet (pset); } xr.MoveToContent (); } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs index abcead1ca2..d8b62e1387 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs @@ -156,7 +156,7 @@ namespace MonoDevelop.Projects.Policies internal void LoadFromFile (StreamReader reader) { - var xr = System.Xml.XmlReader.Create (reader); + var xr = XmlReader.Create (reader); LoadFromXml (xr); } @@ -180,8 +180,9 @@ namespace MonoDevelop.Projects.Policies foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml (reader)) { PolicyKey key = new PolicyKey (policyPair.PolicyType, policyPair.Scope); if (policies.ContainsKey (key)) - throw new InvalidOperationException ("Cannot add second policy of type '" + - key.ToString () + "' to policy set '" + Id + "'"); + throw new InvalidOperationException ( + "Cannot add second policy of type '" + key + "' to policy set '" + Id + "'" + ); policies[key] = policyPair.Policy; } } |