Beispiel #1
0
        private SPSiteModel ProcessSite(Web _web)
        {
            var hasListFound = false;
            var model        = new SPSiteModel();

            _web.EnsureProperties(wssp => wssp.Id,
                                  wspp => wspp.ServerRelativeUrl,
                                  wspp => wspp.Title,
                                  wssp => wssp.HasUniqueRoleAssignments,
                                  wssp => wssp.SiteUsers,
                                  wssp => wssp.Url,
                                  wssp => wssp.Lists,
                                  wssp => wssp.ContentTypes.Include(
                                      lcnt => lcnt.Id,
                                      lcnt => lcnt.Name,
                                      lcnt => lcnt.StringId,
                                      lcnt => lcnt.Description,
                                      lcnt => lcnt.DocumentTemplate,
                                      lcnt => lcnt.Group,
                                      lcnt => lcnt.Hidden,
                                      lcnt => lcnt.JSLink,
                                      lcnt => lcnt.SchemaXml,
                                      lcnt => lcnt.Scope,
                                      lcnt => lcnt.FieldLinks.Include(
                                          lcntlnk => lcntlnk.Id,
                                          lcntlnk => lcntlnk.Name,
                                          lcntlnk => lcntlnk.Hidden,
                                          lcntlnk => lcntlnk.Required
                                          ),
                                      lcnt => lcnt.Fields.Include(
                                          lcntfld => lcntfld.FieldTypeKind,
                                          lcntfld => lcntfld.InternalName,
                                          lcntfld => lcntfld.Id,
                                          lcntfld => lcntfld.Group,
                                          lcntfld => lcntfld.Title,
                                          lcntfld => lcntfld.Hidden,
                                          lcntfld => lcntfld.Description,
                                          lcntfld => lcntfld.JSLink,
                                          lcntfld => lcntfld.Indexed,
                                          lcntfld => lcntfld.Required,
                                          lcntfld => lcntfld.SchemaXml)),
                                  wssp => wssp.Fields.Include(
                                      lcntfld => lcntfld.FieldTypeKind,
                                      lcntfld => lcntfld.InternalName,
                                      lcntfld => lcntfld.Id,
                                      lcntfld => lcntfld.Group,
                                      lcntfld => lcntfld.Title,
                                      lcntfld => lcntfld.Hidden,
                                      lcntfld => lcntfld.Description,
                                      lcntfld => lcntfld.JSLink,
                                      lcntfld => lcntfld.Indexed,
                                      lcntfld => lcntfld.Required,
                                      lcntfld => lcntfld.SchemaXml));
            model.Url   = _web.Url;
            model.title = _web.Title;
            LogVerbose("Processing: {0}", _web.Url);


            /* Process Fields */
            try
            {
                foreach (var _fields in _web.Fields)
                {
                    if (string.IsNullOrEmpty(FieldColumnName) ||
                        _fields.Title.Equals(FieldColumnName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        hasListFound = true;

                        model.FieldDefinitions.Add(new SPFieldDefinitionModel()
                        {
                            FieldTypeKind = _fields.FieldTypeKind,
                            InternalName  = _fields.InternalName,
                            FieldGuid     = _fields.Id,
                            GroupName     = _fields.Group,
                            Title         = _fields.Title,
                            HiddenField   = _fields.Hidden,
                            Description   = _fields.Description,
                            JSLink        = _fields.JSLink,
                            FieldIndexed  = _fields.Indexed,
                            Required      = _fields.Required,
                            SchemaXml     = _fields.SchemaXml
                        });
                    }
                }
                ;
            }
            catch (Exception e)
            {
                LogError(e, "Failed to retrieve site owners {0}", _web.Url);
            }

            /* Process Content Type */
            try
            {
                foreach (var _ctypes in _web.ContentTypes)
                {
                    var cmodel = new SPContentTypeDefinition()
                    {
                        ContentTypeId    = _ctypes.StringId,
                        Name             = _ctypes.Name,
                        Description      = _ctypes.Description,
                        DocumentTemplate = _ctypes.DocumentTemplate,
                        ContentTypeGroup = _ctypes.Group,
                        Hidden           = _ctypes.Hidden,
                        JSLink           = _ctypes.JSLink,
                        Scope            = _ctypes.Scope
                    };

                    foreach (var _ctypeFields in _ctypes.FieldLinks)
                    {
                        if (string.IsNullOrEmpty(FieldColumnName) ||
                            _ctypeFields.Name.Equals(FieldColumnName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            cmodel.FieldLinks.Add(new SPFieldLinkDefinitionModel()
                            {
                                Name     = _ctypeFields.Name,
                                Id       = _ctypeFields.Id,
                                Hidden   = _ctypeFields.Hidden,
                                Required = _ctypeFields.Required
                            });
                        }
                    }

                    if (cmodel.FieldLinks.Any())
                    {
                        hasListFound = true;
                        model.ContentTypes.Add(cmodel);
                    }
                }
                ;
            }
            catch (Exception e)
            {
                LogError(e, "Failed to retrieve site owners {0}", _web.Url);
            }

            // ********** Process List
            try
            {
                var lists = ProcessList(_web);
                if (lists.Any())
                {
                    hasListFound = true;
                    model.Lists.AddRange(lists);
                }
            }
            catch (Exception e)
            {
                LogError(e, "Exception occurred in processSite");
            }

            if (hasListFound)
            {
                // setting ID to indicate to parent consumer that this entity has unique permissions in the TREE
                model.Id = _web.Id;
            }

            return(model);
        }
        private void ProcessSite(Web _web)
        {
            var site = new SPSiteModel();

            var admins = _web.GetAdministrators();


            _web.EnsureProperties(lssp => lssp.Id, wspp => wspp.ServerRelativeUrl,
                                  wspp => wspp.Title,
                                  spp => spp.HasUniqueRoleAssignments,
                                  spp => spp.Url,
                                  spp => spp.Lists);
            site.Url   = _web.Url;
            site.title = _web.Title;

            LogVerbose("Processing: {0}", _web.Url);

            /* Process Site Owner */
            try
            {
                admins.ForEach(owner =>
                {
                    site.Owners.Add(new SPPrincipalModel()
                    {
                        LoginName = owner.LoginName
                    });
                });
            }
            catch (Exception e)
            {
                LogError(e, "Failed to retrieve site owners {0}", _web.Url);
            }

            // ********** Process Site user
            try
            {
                _web.EnsureProperties(wspp => wspp.RoleAssignments,
                                      spp => spp.SiteUsers.Include(sppi => sppi.Id, sppi => sppi.Title, sppi => sppi.LoginName));

                foreach (User _user in _web.SiteUsers)
                {
                    if (IsEveryoneInPrincipal(_user))
                    {
                        if (!site.Users.Any(u => u.Id == _user.Id))
                        {
                            var roles = _web.RoleAssignments.Where(ra => ra.PrincipalId == _user.Id).ToList();

                            _user.EnsureProperties(
                                susp => susp.Id,
                                susp => susp.Title,
                                susp => susp.LoginName,
                                susp => susp.IsHiddenInUI,
                                susp => susp.PrincipalType,
                                susp => susp.IsSiteAdmin,
                                susp => susp.Groups);

                            site.Users.Add(new SPPrincipalModel()
                            {
                                Id            = _user.Id,
                                IsHiddenInUI  = _user.IsHiddenInUI,
                                Title         = _user.Title,
                                LoginName     = _user.LoginName,
                                PrincipalType = _user.PrincipalType
                            });
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e, "Failed processUsers enumerating site users");
            }

            // ********** Process Site groups
            try
            {
                GroupCollection _groups = _web.SiteGroups;
                _web.Context.Load(_groups, gspp => gspp.Include(ussp => ussp.Id, ussp => ussp.Title, ussp => ussp.LoginName, ussp => ussp.IsHiddenInUI, ussp => ussp.Users));
                _web.Context.ExecuteQueryRetry();

                foreach (Group _group in _groups)
                {
                    UserCollection _users = _group.Users;
                    _group.EnsureProperties(usp => usp.Users);

                    foreach (User _xUser in _users)
                    {
                        if (IsEveryoneInPrincipal(_xUser))
                        {
                            if (!site.Groups.Any(g => g.Id == _xUser.Id))
                            {
                                site.Groups.Add(new SPGroupPrincipalModel()
                                {
                                    GroupId       = _group.Id,
                                    GroupName     = _group.Title,
                                    GroupHidden   = _group.IsHiddenInUI,
                                    GroupLogin    = _group.LoginName,
                                    Id            = _xUser.Id,
                                    IsHiddenInUI  = _xUser.IsHiddenInUI,
                                    Title         = _xUser.Title,
                                    LoginName     = _xUser.LoginName,
                                    PrincipalType = _xUser.PrincipalType
                                });
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e, "Failed in process Groups");
            }

            Model.Add(site);
        }