Esempio n. 1
0
        public override void Execute(Guid targetInstanceId)
        {
            LoggingEx.CreateReportStorage();

            try
            {
                var farm            = SPFarm.Local;
                var ignoredUsers    = FoundationSyncSettings.Local.IgnoredUsers;
                var service         = farm.Services.GetValue <SPWebService>();
                var userAccounts    = new HashSet <SPUser>();
                var groupAccounts   = new HashSet <SPUser>();
                var webApplications = FoundationSyncSettings.Local.WebApplicationCollection.Count < 1
                    ? (IEnumerable <SPWebApplication>)service.WebApplications
                    : FoundationSyncSettings.Local.WebApplicationCollection;

                foreach (SPWebApplication webApplication in webApplications)
                {
                    var siteCollections = FoundationSyncSettings.Local.SPSiteCollection.Count < 1
                        ? (IEnumerable <SPSite>)webApplication.Sites
                        : FoundationSyncSettings.Local.SPSiteCollection;

                    foreach (SPSite site in siteCollections)
                    {
                        foreach (SPUser userPrincipal in from SPUser userPrincipal in site.RootWeb.SiteUsers
                                 let invalidUser = ignoredUsers.Any(word => userPrincipal.LoginName.Contains(word))
                                                   where !invalidUser
                                                   where !userPrincipal.IsDomainGroup
                                                   where userPrincipal.LoginName.Contains(@"\")
                                                   select userPrincipal)
                        {
                            userAccounts.Add(userPrincipal);
                        }

                        if (_loggingEx)
                        {
                            LoggingExData(string.Format("{0} user principals in site {1}",
                                                        userAccounts.Count, site.Url), LoggingEx.LoggingExType.UsersFoundCount);
                        }

                        FoudationSync.LogMessage(100, FoudationSync.LogCategories.FoundationSync, TraceSeverity.Verbose,
                                                 string.Format("{0} user principals in site {1}", userAccounts.Count, site.Url), null);

                        PrincipalHandler.SearchPrincipals(userAccounts, webApplication, site, false, j, u);

                        userAccounts.Clear();

                        foreach (SPUser groupPrincipal in from SPUser groupPrincipal in site.RootWeb.SiteUsers
                                 let invalidGroup = ignoredUsers.Any(word => groupPrincipal.LoginName.Contains(word))
                                                    where !invalidGroup
                                                    where groupPrincipal.IsDomainGroup
                                                    select groupPrincipal)
                        {
                            groupAccounts.Add(groupPrincipal);
                        }

                        if (_loggingEx)
                        {
                            LoggingExData(string.Format("{0} group principals in site {1}",
                                                        groupAccounts.Count, site.Url), LoggingEx.LoggingExType.UsersFoundCount);
                        }

                        FoudationSync.LogMessage(101, FoudationSync.LogCategories.FoundationSync, TraceSeverity.Verbose,
                                                 string.Format("{0} group principals in site {1}", groupAccounts.Count, site.Url), null);

                        PrincipalHandler.SearchPrincipals(groupAccounts, webApplication, site, true, j, u);
                        groupAccounts.Clear();

                        site.Dispose();
                    }
                }

                if (_loggingEx)
                {
                    LoggingExData(string.Format("{0} user principals deleted",
                                                j), LoggingEx.LoggingExType.UsersDeletedCount);
                }

                if (_loggingEx)
                {
                    LoggingExData(string.Format("{0} users and groups updated",
                                                u), LoggingEx.LoggingExType.UsersUpdatedCount);
                }

                LoggingEx.SaveReport();
            }
            catch (IndexOutOfRangeException)
            {
                FoudationSync.LogMessage(102, FoudationSync.LogCategories.FoundationSync, TraceSeverity.Medium,
                                         string.Format("Index was out of range."), null);
            }
        }
Esempio n. 2
0
 internal static void LoggingExData(string logMessage, LoggingEx.LoggingExType logType)
 {
     LoggingEx.BuildReport(logMessage, logType);
 }