Beispiel #1
0
        private void LoadCookieIfNeeded(IJobExecutionContext context)
        {
            if (cookie == null)
            {
                cookie = (List <byte>)context.JobDetail.JobDataMap[JOB_DATA_COOKIE];

                if (cookie == null)
                {
                    cookie = new List <byte>();
                    context.JobDetail.JobDataMap.Put(JOB_DATA_COOKIE, cookie);
                }
            }

            if (cookie.Count != 0) // Cookie is already set, no need to load it
            {
                return;
            }
            else if (IsCookieInDB())
            {
                string b64cookie = RecordDao.FindByKey(DIR_SYNC_COOKIE_KEY).Value;
                SetCookie(Convert.FromBase64String(b64cookie));
                directorySearcher.DirectorySynchronization.ResetDirectorySynchronizationCookie(Convert.FromBase64String(b64cookie));

                log.Info("Loaded DirSyncCookie from the database.");
            }
            else
            {
                log.Info("No DirSyncCookie, performing a full sync!");
            }
        }
Beispiel #2
0
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                LoadState(context);

                // perform a sync, fetching latest changes
                using (SearchResultCollection searchResults = directorySearcher.FindAll())
                {
                    int i = 0, failures = 0, ou_updates = 0, ou_deletes = 0, user_updates = 0, user_deletes = 0;

                    foreach (SearchResult searchResult in searchResults)
                    {
                        i++;
                        if (i % 250 == 0)
                        {
                            log.Info("Synchronization from Active Diretory in progress - processed " + i + " modifications");
                        }

                        try
                        {
                            switch (eventListenerProcessor.Process(searchResult))
                            {
                            case EventListenerProcessor.ProcessingResult.FAILURE:
                                failures++;
                                break;

                            case EventListenerProcessor.ProcessingResult.OU_DELETE:
                                ou_deletes++;
                                break;

                            case EventListenerProcessor.ProcessingResult.OU_UPDATE:
                                log.Debug("OU retrieved from AD for update/create: " + searchResult.Path);
                                ou_updates++;
                                break;

                            case EventListenerProcessor.ProcessingResult.USER_DELETE:
                                user_deletes++;
                                break;

                            case EventListenerProcessor.ProcessingResult.USER_UPDATE:
                                user_updates++;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Warn("Failed to parse object from AD with path: " + searchResult.Path + " and error: " + ex.Message, ex);
                        }
                    }

                    if (i > 0)
                    {
                        log.Info("Read " + i + " modifications from Active Directory (" + ou_updates + " ou-updates, " + ou_deletes + " ou-deletes, " + user_updates + " user-updates, " + user_deletes + " user-deletes and " + failures + " unknown records)");
                    }

                    // store the updated cookie
                    SetCookie(directorySearcher.DirectorySynchronization.GetDirectorySynchronizationCookie());

                    RecordDao.Save(DIR_SYNC_COOKIE_KEY, Convert.ToBase64String((directorySearcher.DirectorySynchronization.GetDirectorySynchronizationCookie())));
                }
            }
            catch (Exception ex)
            {
                log.Error("Directory Synchronization Failed.", ex);
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
 private static bool IsCookieInDB()
 {
     return(RecordDao.FindByKey(DIR_SYNC_COOKIE_KEY) == null ? false : true);
 }