Exemple #1
0
        private bool SendNotification(ServicesGroupServiceClient groupClient, TaskScheduling task, List <Group> groups, int processedFailed, int processedSuccessFully, string clientID = "")
        {
            bool flag;

            if (this.NeedNotify(task, processedFailed, processedSuccessFully))
            {
                try
                {
                    List <Group> compressedList = Helper.PrepareCompressedData(groups);
                    Console.WriteLine(string.Concat(Environment.NewLine, "SENDING NOTIFICATION THROUGH GROUP CLIENT FOR CLIENT ", clientID, Environment.NewLine));
                    groupClient.SendUpdateNotification(task.get_IdentityStoreId(), compressedList, task.get_SendToSpecified(), task.get_SendToOwner(), task.get_SendOnUpdate(), clientID);
                    flag = true;
                }
                catch (Exception exception)
                {
                    this.logger.Error("Error occurred while sending smart group update notifications. ", exception);
                    flag = false;
                }
            }
            else
            {
                flag = true;
            }
            return(flag);
        }
        private List <IdentityStoreObject> EnsureChildGroups(int identityStoreId, ServicesGroupServiceClient groupClient, List <IdentityStoreObject> managedGroups)
        {
            Func <IdentityStoreObject, bool> func = null;
            List <IdentityStoreObject>       identityStoreObjects = new List <IdentityStoreObject>();

            foreach (IdentityStoreObject pair in managedGroups)
            {
                try
                {
                    List <IdentityStoreObject>       childGroups           = groupClient.GetAllLevelCurrentChildGroups(identityStoreId, pair.get_ObjectIdFromIdentityStore(), null, this.GetAttributesToLoad());
                    List <IdentityStoreObject>       identityStoreObjects1 = identityStoreObjects;
                    List <IdentityStoreObject>       identityStoreObjects2 = childGroups;
                    Func <IdentityStoreObject, bool> func1 = func;
                    if (func1 == null)
                    {
                        Func <IdentityStoreObject, bool> func2 = (IdentityStoreObject grp) => !identityStoreObjects.Any <IdentityStoreObject>((IdentityStoreObject obj1) => obj1.get_ObjectIdFromIdentityStore().Equals(grp.get_ObjectIdFromIdentityStore(), StringComparison.InvariantCultureIgnoreCase));
                        Func <IdentityStoreObject, bool> func3 = func2;
                        func  = func2;
                        func1 = func3;
                    }
                    identityStoreObjects1.AddRange(identityStoreObjects2.Where <IdentityStoreObject>(func1));
                }
                catch (Exception exception)
                {
                    Exception ex = exception;
                    GroupsProcessor.logger.Error(string.Concat("Error occurred in getting child groups after smart group update. ", ex.Message));
                    continue;
                }
            }
            return(identityStoreObjects);
        }
        private ActionResult SaveGroupUsage(List <IdentityStoreObject> providerResult, DateTime toDate)
        {
            providerResult.ForEach((IdentityStoreObject identityStoreObject) => {
                DateTime dateTime;
                identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection().Keys.ToList <string>().ForEach((string key) => {
                    if ((key.Equals("IMGFirstUsed", StringComparison.InvariantCultureIgnoreCase) || key.Equals("IMGLastUsed", StringComparison.InvariantCultureIgnoreCase) || key.Equals("IMGUsedCount", StringComparison.InvariantCultureIgnoreCase) ? false : !key.Equals("IMGLastProcessedDate", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection().Remove(key);
                    }
                    else if ((identityStoreObject.get_AttributesBusinessObject().HasValue(key) ? false : !key.Equals("IMGLastProcessedDate", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection().Remove(key);
                    }
                });
                if (identityStoreObject.get_AttributesBusinessObject().HasValue("IMGLastProcessedDate"))
                {
                    Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute item = identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection()["IMGLastProcessedDate"][0];
                    dateTime = Convert.ToDateTime(toDate);
                    item.set_Value(dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection()["IMGLastProcessedDate"][0].set_Action(3);
                }
                else if (!identityStoreObject.get_AttributesBusinessObject().IsIn("IMGLastProcessedDate"))
                {
                    Dictionary <string, List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> > attributesCollection = identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection();
                    List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> attributes = new List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute>();
                    Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute attribute         = new Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute();
                    attribute.set_Action(1);
                    dateTime = Convert.ToDateTime(toDate);
                    attribute.set_Value(dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    attributes.Add(attribute);
                    attributesCollection.Add("IMGLastProcessedDate", attributes);
                }
                else
                {
                    List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> item1 = identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection()["IMGLastProcessedDate"];
                    Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute attribute1   = new Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute();
                    attribute1.set_Action(1);
                    dateTime = Convert.ToDateTime(toDate);
                    attribute1.set_Value(dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    item1.Add(attribute1);
                }
                GroupsProcessor.logger.InfoFormat("Stamping {0} with last processed date {1} with action {2}", identityStoreObject.get_ObjectIdFromIdentityStore(), identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection()["IMGLastProcessedDate"][0].get_Value(), identityStoreObject.get_AttributesBusinessObject().get_AttributesCollection()["IMGLastProcessedDate"][0].get_Action().ToString());
            });
            ServicesGroupServiceClient searchGroupClient = new ServicesGroupServiceClient(false);
            string       cData        = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(providerResult);
            ActionResult actionResult = searchGroupClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), cData, typeof(IdentityStoreObject).FullName);

            return(actionResult);
        }
        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);
            }
        }
Exemple #5
0
 private Dictionary <string, Dictionary <string, IdentityStoreObject> > EnsureChildGroups(int identityStoreId, ServicesGroupServiceClient groupClient, Dictionary <string, Dictionary <string, IdentityStoreObject> > managedGroups)
 {
     foreach (KeyValuePair <string, Dictionary <string, IdentityStoreObject> > pair in managedGroups)
     {
         try
         {
             List <IdentityStoreObject> childGroups = groupClient.GetAllLevelCurrentChildGroups(identityStoreId, pair.Key, null, new List <string>()
             {
                 "IMSGManagedGroupType",
                 "IMSGObjectParentKey",
                 Helper.KnownProviderAttributes.get_DistinguishedName()
             });
             Dictionary <string, IdentityStoreObject> childDict = pair.Value;
             IdentityStoreObject[] array = childGroups.ToArray();
             for (int i = 0; i < (int)array.Length; i++)
             {
                 IdentityStoreObject g = array[i];
                 if (!childDict.ContainsKey(g.get_ObjectIdFromIdentityStore()))
                 {
                     childDict.Add(g.get_ObjectIdFromIdentityStore(), g);
                 }
             }
             ILookup <string, IdentityStoreObject>        childGroupsLookup = childGroups.ToLookup <IdentityStoreObject, string>((IdentityStoreObject c) => c.get_ObjectIdFromIdentityStore());
             KeyValuePair <string, IdentityStoreObject>[] keyValuePairArray = childDict.ToArray <KeyValuePair <string, IdentityStoreObject> >();
             for (int j = 0; j < (int)keyValuePairArray.Length; j++)
             {
                 KeyValuePair <string, IdentityStoreObject> childPair = keyValuePairArray[j];
                 if (!childGroupsLookup[childPair.Key].Any <IdentityStoreObject>())
                 {
                     childDict.Remove(childPair.Key);
                 }
             }
         }
         catch (Exception exception)
         {
             Exception ex = exception;
             this.logger.Error(string.Concat("Error occurred in getting child groups after smart group update. ", ex.Message));
             continue;
         }
     }
     return(managedGroups);
 }
        public void ProcessJob(TaskScheduling task)
        {
            List <User> ownerUsers = new List <User>();
            List <IdentityStoreObject> orphanGrps      = this.GetOrphanGroups(null);
            IStoreTypeHelper           storeHelper     = Helper.GetStoreTypeHelper(Helper.CurrentTask.get_IdentityStoreId());
            ILookup <string, User>     addOwnersLookup = null;
            List <string> supportedObjectTypes         = new List <string>();

            if (storeHelper != null)
            {
                supportedObjectTypes = storeHelper.GetSupportedObjectTypes(Helper.KnownProviderAttributes.get_Owner());
                if (supportedObjectTypes.Count > 0)
                {
                    List <string> strs1 = new List <string>();
                    orphanGrps.ForEach((IdentityStoreObject g) => {
                        List <string> strs = strs1;
                        List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> values = g.get_AttributesBusinessObject().GetValues("XAdditionalOwner");
                        Func <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute, string> u003cu003e9_12 = OrphanGroupProcessor.< > c.< > 9__1_2;
                        if (u003cu003e9_12 == null)
                        {
                            u003cu003e9_12 = (Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute o) => o.get_Value();
                            OrphanGroupProcessor.< > c.< > 9__1_2 = u003cu003e9_12;
                        }
                        strs.AddRange(values.Select <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute, string>(u003cu003e9_12));
                    });
                    ServicesUserServiceClient serviceUser = new ServicesUserServiceClient(false);
                    List <User> owners = serviceUser.Get(Helper.CurrentTask.get_IdentityStoreId(), strs1, new List <string>());
                    addOwnersLookup = owners.ToLookup <User, string>((User o) => o.get_ObjectIdFromIdentityStore(), StringComparer.OrdinalIgnoreCase);
                }
            }
            List <IdentityStoreObject> orphansList = new List <IdentityStoreObject>();

            foreach (IdentityStoreObject oGrp in orphanGrps)
            {
                if (oGrp.get_AttributesBusinessObject().IsIn(Helper.KnownProviderAttributes.get_Container()))
                {
                    oGrp.get_AttributesBusinessObject().Remove(Helper.KnownProviderAttributes.get_Container());
                }
                if (oGrp.get_AttributesBusinessObject().IsIn(Helper.KnownProviderAttributes.get_DisplayName()))
                {
                    oGrp.get_AttributesBusinessObject().Remove(Helper.KnownProviderAttributes.get_DisplayName());
                }
                if (oGrp.get_AttributesBusinessObject().IsIn(Helper.KnownProviderAttributes.get_DistinguishedName()))
                {
                    oGrp.get_AttributesBusinessObject().Remove(Helper.KnownProviderAttributes.get_DistinguishedName());
                }
                if (oGrp.get_AttributesBusinessObject().IsIn(Helper.KnownProviderAttributes.get_CommonName()))
                {
                    oGrp.get_AttributesBusinessObject().Remove(Helper.KnownProviderAttributes.get_CommonName());
                }
                Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute additionalOwner = this.GetAdditionalOwnerToPromote(oGrp.get_AttributesBusinessObject().GetValues("XAdditionalOwner"), addOwnersLookup, supportedObjectTypes);
                if (additionalOwner != null)
                {
                    ServicesUserServiceClient serviceUser = new ServicesUserServiceClient(false);
                    User additionaOwnerDN = serviceUser.Get(Helper.CurrentTask.get_IdentityStoreId(), additionalOwner.get_Value(), new List <string>()
                    {
                        Helper.KnownProviderAttributes.get_DistinguishedName(),
                        Helper.KnownProviderAttributes.get_EmailAddress(),
                        Helper.KnownProviderAttributes.get_DisplayName()
                    }, false);
                    if ((additionaOwnerDN == null ? false : additionaOwnerDN.get_AttributesBusinessObject().HasValue(Helper.KnownProviderAttributes.get_DistinguishedName())))
                    {
                        oGrp.set_ObjectName(additionalOwner.get_Value());
                        ownerUsers.Add(additionaOwnerDN);
                        additionaOwnerDN.set_ObjectIdFromIdentityStore(additionalOwner.get_Value());
                        additionalOwner.set_Action(2);
                        string dnValue = additionaOwnerDN.get_AttributesBusinessObject().get_AttributesCollection()[Helper.KnownProviderAttributes.get_DistinguishedName()][0].get_Value();
                        if (oGrp.get_AttributesBusinessObject().HasValue(Helper.KnownProviderAttributes.get_Owner()))
                        {
                            oGrp.get_AttributesBusinessObject().get_AttributesCollection()[Helper.KnownProviderAttributes.get_Owner()][0].set_Value(dnValue);
                            oGrp.get_AttributesBusinessObject().get_AttributesCollection()[Helper.KnownProviderAttributes.get_Owner()][0].set_Action(1);
                        }
                        else if (!oGrp.get_AttributesBusinessObject().IsIn(Helper.KnownProviderAttributes.get_Owner()))
                        {
                            Dictionary <string, List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> > attributesCollection = oGrp.get_AttributesBusinessObject().get_AttributesCollection();
                            string owner = Helper.KnownProviderAttributes.get_Owner();
                            List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> attributes = new List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute>();
                            Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute        attribute  = new Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute();
                            attribute.set_Action(1);
                            attribute.set_Value(dnValue);
                            attributes.Add(attribute);
                            attributesCollection.Add(owner, attributes);
                        }
                        else
                        {
                            Dictionary <string, List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> > attributesCollection1 = oGrp.get_AttributesBusinessObject().get_AttributesCollection();
                            string str = Helper.KnownProviderAttributes.get_Owner();
                            List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute> attributes1 = new List <Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute>();
                            Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute        attribute1  = new Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute();
                            attribute1.set_Action(1);
                            attribute1.set_Value(dnValue);
                            attributes1.Add(attribute1);
                            attributesCollection1[str] = attributes1;
                        }
                        orphansList.Add(oGrp);
                    }
                }
            }
            if (orphansList.Count > 0)
            {
                ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false);
                string cData = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(orphansList);
                if (groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), cData, typeof(IdentityStoreObject).FullName).get_Status() == 0)
                {
                    List <IdentityStoreObject> idObjectsList = Helper.PrepareCompressedData(orphansList);
                    groupServiceClient.SendOwnerUpdateNotification(Helper.CurrentTask.get_IdentityStoreId(), idObjectsList, ownerUsers);
                }
            }
        }
        public virtual void DeleteExpiredGroups(List <IdentityStoreObject> groups)
        {
            LogExtension.EnterMethod(GroupsProcessor.logger, MethodBase.GetCurrentMethod(), new object[0]);
            List <string> groupsToNotify = new List <string>();
            List <IdentityStoreObject> groupsToDelete = new List <IdentityStoreObject>();

            try
            {
                foreach (IdentityStoreObject group in groups)
                {
                    try
                    {
                        if (!this.IsGroup(group))
                        {
                            GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is not a group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                            continue;
                        }
                        else if (this.IsSystemGroup(group))
                        {
                            GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is a system group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                            continue;
                        }
                        else if (this.IsGroupInExcludedContainer(group))
                        {
                            GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is in excluded containers.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                            continue;
                        }
                        else if (this.ShouldExpireSecurityGroup(group))
                        {
                            string   expirationDateString = this.GetAttributeValue("XGroupExpirationDate", group.get_AttributesBusinessObject()).get_Value();
                            DateTime expirationDate       = Helper.ParseDateTime(expirationDateString);
                            if (expirationDate.Date == DateTime.MinValue.Date)
                            {
                                continue;
                            }
                            else if (DateTime.Now.Date.Subtract(expirationDate.Date).Days >= Helper.AppConfiguration.get_DeletionDaysAfterExpiry())
                            {
                                this.SetAttributeValue("IMGIsDeleted", "true", group.get_AttributesBusinessObject());
                                string updatedDisplayName = this.GetUpdatedDisplayName(group);
                                group.set_ObjectDisplayName(updatedDisplayName);
                                this.SetAttributeValue(Helper.KnownProviderAttributes.get_DisplayName(), updatedDisplayName, group.get_AttributesBusinessObject());
                                groupsToNotify.Add(group.get_ObjectIdFromIdentityStore());
                                groupsToDelete.Add(group);
                                GroupsProcessor.logger.InfoFormat("Group Deleted: {0}", group.get_ObjectDisplayName());
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is a security group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty);
                            continue;
                        }
                    }
                    catch (Exception exception)
                    {
                        Exception ex = exception;
                        GroupsProcessor.logger.Error(string.Format("An Error occured while performing deletion operation on group: {0} Reason: {1}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_DistinguishedName(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty, ex.Message), ex);
                    }
                }
                ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false);
                if (groupsToDelete.Count > 0)
                {
                    groupsToDelete.ForEach((IdentityStoreObject g) => this.SetAttributeValue("IMGLastSentExpireNotificationDate", DateTime.Now.Date.ToString("yyyy MMMM dd HH:mm:ss"), g.get_AttributesBusinessObject()));
                    groupsToDelete.ForEach((IdentityStoreObject g) => this.SetAttributeValue("IMGIsDeleted", "TRUE", g.get_AttributesBusinessObject()));
                    List <IdentityStoreObject> groupsToUpdate = this.CloneObjectsForUpdate(new List <string>()
                    {
                        "IMGLastSentExpireNotificationDate",
                        "IMGIsDeleted",
                        Helper.KnownProviderAttributes.get_DisplayName()
                    }, groupsToDelete, null);
                    string       compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate);
                    ActionResult result           = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName);
                    this.LogResults(result, "DeleteExpiredGroups");
                }
                if (groupsToNotify.Count > 0)
                {
                    ActionResult result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 29, groupsToNotify);
                    this.LogResults(result, "DeleteExpiredGroups-Notifications");
                }
                LogExtension.ExitMethod(GroupsProcessor.logger, MethodBase.GetCurrentMethod(), new object[0]);
            }
            catch (Exception exception1)
            {
                Exception Ex = exception1;
                LogExtension.LogException(GroupsProcessor.logger, string.Format("An error ocurred while deleting 30 days old expired 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");
            }
        }
        public virtual void NotifyTheExpiringGroups(List <IdentityStoreObject> expiringGroups)
        {
            List <string> groupsToNotifyOneDay              = new List <string>();
            List <string> groupsToNotifySevenDays           = new List <string>();
            List <string> groupsToNotifyThirtyDays          = new List <string>();
            List <IdentityStoreObject> groupsToNotifyUpdate = new List <IdentityStoreObject>();

            foreach (IdentityStoreObject group in expiringGroups)
            {
                if (group != null)
                {
                    if (this.IsGroup(group))
                    {
                        IdentityStoreObject parentGroup = this.GetParentGroup(expiringGroups, group);
                        if (parentGroup != null)
                        {
                            if (this.IsGroupInExcludedContainer(parentGroup))
                            {
                                continue;
                            }
                        }
                        else if (this.IsGroupInExcludedContainer(group))
                        {
                            continue;
                        }
                        if (this.ShouldExpireSecurityGroup(group))
                        {
                            if ((this.ExtendedGroups == null || this.ExtendedGroups.Count <= 0 ? true : !this.ExtendedGroups.Contains(group.get_ObjectIdFromIdentityStore())))
                            {
                                int dueDays = 0;
                                if (this.IsNotificationDueOneDay(group, out dueDays))
                                {
                                    groupsToNotifyOneDay.Add(group.get_ObjectIdFromIdentityStore());
                                    groupsToNotifyUpdate.Add(group);
                                }
                                dueDays = 0;
                                if (this.IsNotificationDueSevenDays(group, out dueDays))
                                {
                                    groupsToNotifySevenDays.Add(group.get_ObjectIdFromIdentityStore());
                                    groupsToNotifyUpdate.Add(group);
                                }
                                dueDays = 0;
                                if (this.IsNotificationDueThirtyDays(group, out dueDays))
                                {
                                    groupsToNotifyThirtyDays.Add(group.get_ObjectIdFromIdentityStore());
                                    groupsToNotifyUpdate.Add(group);
                                }
                            }
                        }
                    }
                }
            }
            if ((groupsToNotifyOneDay.Count > 0 || groupsToNotifySevenDays.Count > 0 ? true : groupsToNotifyThirtyDays.Count > 0))
            {
                ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false);
                ActionResult result = null;
                if (groupsToNotifyOneDay.Count > 0)
                {
                    result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 38, groupsToNotifyOneDay);
                    this.LogResults(result, "NotifyTheExpiringGroups-OneDay-Notifications");
                }
                if (groupsToNotifySevenDays.Count > 0)
                {
                    result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 39, groupsToNotifySevenDays);
                    this.LogResults(result, "NotifyTheExpiringGroups-SevenDays-Notifications");
                }
                if (groupsToNotifyThirtyDays.Count > 0)
                {
                    result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 40, groupsToNotifyThirtyDays);
                    this.LogResults(result, "NotifyTheExpiringGroups-ThirtyDays-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, "NotifyTheExpiringGroups-AfterNotificationsUpdate");
            }
        }