public virtual void ExtendEligibleGroupsLife()
        {
            ServicesSearchServiceClient searchServiceClient = new ServicesSearchServiceClient(false);
            FilterCriteria            filterCriteria        = this.GetEligibleGroupsFilter();
            int                       totalFound            = 0;
            Dictionary <string, bool> containers            = null;

            if ((Helper.CurrentTask.get_Targets() == null ? false : Helper.CurrentTask.get_Targets().Count > 0))
            {
                containers = Helper.CurrentTask.get_Targets().ToDictionary <SchedulingTarget, string, bool>((SchedulingTarget target) => target.get_Target(), (SchedulingTarget target) => false);
            }
            SearchFilter searchFilter1 = new SearchFilter();

            searchFilter1.set_ExtensionDataCriteria(filterCriteria);
            searchFilter1.set_ProviderCriteria(new FilterCriteria());
            SearchFilter searchFilter = searchFilter1;
            List <IdentityStoreObject> groupsToExtend = searchServiceClient.SearchEx(Helper.CurrentTask.get_IdentityStoreId(), 2, ref totalFound, searchFilter, containers, string.Empty, 1, -1, 20000, this.GetAttributesToLoad(), false);

            try
            {
                List <IdentityStoreObject> groupsOld          = DeepCopyExtensionMethods.DeepCopy <List <IdentityStoreObject> >(groupsToExtend);
                List <string> reducedGroupsToNotify           = new List <string>();
                List <IdentityStoreObject> groupsToUpdate     = this.PrepareGroupsForExtensions(groupsToExtend, ref reducedGroupsToNotify);
                ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false);
                List <IdentityStoreObject> groupsToUpdate1    = this.CloneObjectsForUpdate(new List <string>()
                {
                    "XGroupExpirationPolicy",
                    "XGroupExpirationDate"
                }, groupsToUpdate, groupsOld);
                if ((groupsToUpdate1 == null ? false : groupsToUpdate1.Any <IdentityStoreObject>()))
                {
                    string       compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate1);
                    ActionResult result           = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName);
                    this.LogResults(result, "ExtendEligibleGroupsLife");
                }
                if (reducedGroupsToNotify.Count > 0)
                {
                    groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 37, reducedGroupsToNotify);
                }
            }
            catch (Exception exception)
            {
                Exception Ex = exception;
                LogExtension.LogException(GroupsProcessor.logger, string.Format("An error ocurred while expiring groups: {0}", Ex.Message), Ex);
            }
        }
        public virtual void ExpireTheGroups(List <IdentityStoreObject> groups)
        {
            List <IdentityStoreObject> groupsForExtension = new List <IdentityStoreObject>();
            List <string> strs = new List <string>();
            List <string> groupsToNotifyForExtension        = new List <string>();
            List <IdentityStoreObject> groupsToNotifyUpdate = new List <IdentityStoreObject>();
            List <IdentityStoreObject> groupsOld            = DeepCopyExtensionMethods.DeepCopy <List <IdentityStoreObject> >(groups);

            foreach (IdentityStoreObject group in groups)
            {
                if (!this.IsGroup(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Object {0} is not a group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                }
                else if (this.IsSystemGroup(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Object {0} is a system group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                }
                else if (this.IsGroupInExcludedContainer(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Object {0} is in excluded containers.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                }
                else if (!this.ShouldExpireSecurityGroup(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Object {0} is a security group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                }
                else if (this.ExtendLifeForGUS(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Extending life of object {0}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()));
                    groupsForExtension.Add(group);
                    groupsToNotifyForExtension.Add(group.get_ObjectIdFromIdentityStore());
                }
                else if (this.PrepareGroupForLifeExtension(group))
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Extending life of object {0}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()));
                    groupsForExtension.Add(group);
                }
                else if (!this.HasReceivedNotificationInLast7Days(group))
                {
                    strs.Add(group.get_ObjectIdFromIdentityStore());
                    groupsToNotifyUpdate.Add(group);
                }
                else
                {
                    GroupsProcessor.logger.DebugFormat("ExpireTheGroups. Object {0} has received notification within last 7 days. Not expiring.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                }
            }
            ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false);

            if (groupsForExtension.Count > 0)
            {
                List <IdentityStoreObject> groupsToUpdate = this.CloneObjectsForUpdate(new List <string>()
                {
                    "XGroupExpirationDate"
                }, groupsForExtension, groupsOld);
                string       compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate);
                ActionResult result           = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName);
                this.LogResults(result, "ExtendGroupsLife");
            }
            if (strs.Count > 0)
            {
                ActionResult result = groupServiceClient.Expire(Helper.CurrentTask.get_IdentityStoreId(), strs);
                this.LogResults(result, "ExpireGroups");
                this.GetExcludedNestedGroups((
                                                 from grp in groups
                                                 where strs.Contains(grp.get_ObjectIdFromIdentityStore())
                                                 select grp).ToList <IdentityStoreObject>(), strs);
                result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 28, strs);
                this.LogResults(result, "ExpireGroups-Notifications");
                groupsToNotifyUpdate.ForEach((IdentityStoreObject g) => this.SetAttributeValue("IMGLastSentExpireNotificationDate", DateTime.Now.Date.ToString("yyyy MMMM dd HH:mm:ss"), g.get_AttributesBusinessObject()));
                List <IdentityStoreObject> groupsToUpdate = this.CloneObjectsForUpdate(new List <string>()
                {
                    "IMGLastSentExpireNotificationDate"
                }, groupsToNotifyUpdate, null);
                groupsToUpdate.ForEach((IdentityStoreObject g) => g.set_StopNotification(true));
                string compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate);
                result = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName);
                this.LogResults(result, "UpdateExpireGroupsNotificationData");
            }
            if (groupsToNotifyForExtension.Count > 0)
            {
                ActionResult result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 35, groupsToNotifyForExtension);
                this.LogResults(result, "ExtendedGroups-Notifications");
            }
        }