コード例 #1
0
        public void SetPolicies(PolicyContainer pset)
        {
            if (pset == null)
            {
                store.Clear();
                HasPolicies = false;
                return;
            }

            var content = new Dictionary <string, List <string> > ();

            foreach (var p in pset.DirectGetAll())
            {
                string        name = PolicyService.GetPolicyTypeDescription(p.PolicyType);
                List <string> scopes;
                if (!content.TryGetValue(name, out scopes))
                {
                    scopes = content [name] = new List <string> ();
                }
                scopes.Add(p.Scope ?? "");
            }

            var sorted = content.ToList();

            sorted.Sort((x, y) => x.Key.CompareTo(y.Key));

            store.Clear();

            var sb = new StringBuilder();

            foreach (var pol in sorted)
            {
                sb.Append(pol.Key);
                if (pol.Value.Count != 1 || pol.Value[0].Length != 0)
                {
                    sb.Append(" (");
                    bool first = true;
                    if (pol.Value.Remove(""))
                    {
                        sb.Append(GettextCatalog.GetString("default settings"));
                        first = false;
                    }
                    foreach (var s in pol.Value)
                    {
                        if (!first)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(s);
                        first = false;
                    }
                    sb.Append(")");
                }
                store.AppendValues(sb.ToString());
                sb.Length = 0;
            }

            HasPolicies = sorted.Count > 0;
        }
コード例 #2
0
        public static string GetPoliciesDescription(PolicyContainer pset)
        {
            Dictionary <string, List <string> > content = new Dictionary <string, List <string> > ();

            foreach (var p in pset.DirectGetAll())
            {
                string        name = PolicyService.GetPolicyTypeDescription(p.PolicyType);
                List <string> scopes;
                if (!content.TryGetValue(name, out scopes))
                {
                    scopes = content [name] = new List <string> ();
                }
                scopes.Add(p.Scope ?? "");
            }

            var sorted = content.ToList();

            sorted.Sort((x, y) => x.Key.CompareTo(y.Key));
            StringBuilder sb = StringBuilderCache.Allocate();

            foreach (var pol in sorted)
            {
                if (sb.Length > 0)
                {
                    sb.Append('\n');
                }
                sb.Append(pol.Key);
                if (pol.Value.Count != 1 || pol.Value[0].Length != 0)
                {
                    sb.Append(" (");
                    bool first = true;
                    if (pol.Value.Remove(""))
                    {
                        sb.Append(GettextCatalog.GetString("default settings"));
                        first = false;
                    }
                    foreach (var s in pol.Value)
                    {
                        if (!first)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(s);
                        first = false;
                    }
                    sb.Append(")");
                }
            }
            return(StringBuilderCache.ReturnAndFree(sb));
        }
コード例 #3
0
		public void SetPolicies (PolicyContainer pset)
		{
			if (pset == null) {
				store.Clear ();
				HasPolicies = false;
				return;
			}
			
			var content = new Dictionary<string, List<string>> ();
			foreach (var p in pset.DirectGetAll ()) {
				string name = PolicyService.GetPolicyTypeDescription (p.PolicyType);
				List<string> scopes;
				if (!content.TryGetValue (name, out scopes))
					scopes = content [name] = new List<string> ();
				scopes.Add (p.Scope ?? "");
			}
			
			var sorted = content.ToList ();
			sorted.Sort ((x, y) => x.Key.CompareTo(y.Key));
			
			store.Clear ();
			
			var sb = new StringBuilder ();
			foreach (var pol in sorted) {
				sb.Append (pol.Key);
				if (pol.Value.Count != 1 || pol.Value[0].Length != 0) {
					sb.Append (" (");
					bool first = true;
					if (pol.Value.Remove ("")) {
						sb.Append (GettextCatalog.GetString ("default settings"));
						first = false;
					}
					foreach (var s in pol.Value) {
						if (!first)
							sb.Append (", ");
						sb.Append (s);
						first = false;
					}
					sb.Append (")");
				}
				store.AppendValues (sb.ToString ());
				sb.Length = 0;
			}
			
			HasPolicies = sorted.Count > 0;
		}