Пример #1
0
        internal static object GetIdentity(Node node)
        {
            if (node == null)
                throw new ArgumentException("Identity not found");

            //TODO: domain
            string domain = null;
            var kind = node is User ? SnIdentityKind.User : node is Group ? SnIdentityKind.Group : SnIdentityKind.OrganizationalUnit;

            return new Dictionary<string, object>
            {
                { "id", node.Id },
                { "path", node.Path },
                { "name", node.Name },
                { "displayName", SNSR.GetString(node.DisplayName) },
                { "domain", domain },
                { "kind", kind.ToString().ToLower() },
                { "ValidationId", node["ValidationId"]}
            };
        }
Пример #2
0
        /// <summary>
        /// Returns the XML representation of the given URL list.
        /// For example:
        ///   &lt;Url authType="Forms"&gt;localhost:1315/&lt;/Url&gt;
        ///   &lt;Url authType="Windows"&gt;name.server.xy&lt;/Url&gt;
        /// </summary>
        /// <param name="urlList">A url-authenticationtype dictionary.</param>
        public static string UrlListToString(IDictionary <string, string> urlList)
        {
            if (urlList == null)
            {
                throw new ApplicationException(SNSR.GetString(SNSR.Exceptions.Site.UrlListCannotBeEmpty));
            }

            var sb = new StringBuilder();

            foreach (string key in urlList.Keys)
            {
                string auth = urlList[key];
                sb.Append("<Url");
                if (!String.IsNullOrEmpty(auth))
                {
                    sb.Append(" authType='").Append(auth).Append("'");
                }
                sb.Append(">");
                sb.Append(key);
                sb.Append("</Url>");
            }
            return(sb.ToString());
        }
Пример #3
0
        public static string GetMetadata(Content content)
        {
            // collects regular fields
            var types1 = new List <type>();
            var i      = 0;

            foreach (var contentType in ContentType.GetContentTypes())
            {
                if (contentType.Name.ToLower().Contains("fieldsetting"))
                {
                    continue;
                }

                var c  = "ct" + i;
                var ct = new type {
                    n = contentType.Name, d = SNSR.GetString(contentType.DisplayName), c = c
                };
                types1.Add(ct);
                var fields        = new List <field>();
                var fieldSettings = contentType.FieldSettings.Where(s => s.IndexingInfo.IsInIndex);
                foreach (var fieldSetting in fieldSettings)
                {
                    if (fieldSetting.Name == "FieldSettingContents" || fieldSetting.Name == "AllFieldSettingContents")
                    {
                        continue;
                    }

                    var displayName = String.IsNullOrEmpty(fieldSetting.DisplayName) ? fieldSetting.Name : SNSR.GetString(fieldSetting.DisplayName);
                    var fieldType   = fieldSetting.ShortName;
                    var choiceField = fieldSetting as ChoiceFieldSetting;
                    if (choiceField != null)
                    {
                        var opts = choiceField.Options.Select(o => new option {
                            n = o.Text, v = o.Value, e = o.Enabled, s = o.Selected
                        }).ToArray();
                        fields.Add(new field {
                            n = fieldSetting.Name, d = displayName, t = "choice", c = c, q = opts
                        });
                    }
                    else if (fieldType != "Binary")
                    {
                        fields.Add(new field {
                            n = fieldSetting.Name, d = displayName, t = fieldType, c = c
                        });
                    }
                }
                ct.f = fields.OrderBy(x => x.d).ToArray();
                i++;
            }

            types1 = types1.OrderBy(x => x.d).ToList();

            // collect aspect fields
            var types2  = new List <type>();
            var aspects = ContentQuery.Query("TypeIs:Aspect .AUTOFILTERS:OFF").Nodes;

            i = 0;

            foreach (Aspect aspect in aspects)
            {
                var c  = "a" + i;
                var at = new type {
                    n = aspect.Name, d = SNSR.GetString(aspect.DisplayName), c = c
                };
                types2.Add(at);
                var fields = new List <field>();
                foreach (var field in aspect.FieldSettings)
                {
                    if (field != null)
                    {
                        var displayName = String.IsNullOrEmpty(field.DisplayName) ? field.Name : SNSR.GetString(field.DisplayName);
                        var fieldType   = field.ShortName;
                        if (fieldType != "BinaryData")
                        {
                            fields.Add(new field {
                                n = field.Name, d = displayName, t = fieldType, c = c
                            });
                        }
                    }
                }
                at.f = fields.OrderBy(x => x.d).ToArray();
                i++;
            }

            types2 = types2.OrderBy(x => x.d).ToList();

            var sb       = new StringBuilder();
            var settings = new JsonSerializerSettings {
                Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore
            };
            var serializer = JsonSerializer.Create(settings);

            using (var writer = new StringWriter(sb))
                serializer.Serialize(writer, new[] { types1, types2 });

            return(sb.ToString());
        }