public static void SetPolicyTagForDeleteOnFolder(PolicyTag policyTag, Folder folder)
        {
            folder[StoreObjectSchema.PolicyTag]       = policyTag.PolicyGuid.ToByteArray();
            folder[StoreObjectSchema.RetentionPeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
            object valueOrDefault = folder.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags);
            int    num            = 9;
            RetentionAndArchiveFlags retentionAndArchiveFlags;

            if (valueOrDefault != null && valueOrDefault is int)
            {
                retentionAndArchiveFlags = (RetentionAndArchiveFlags)((int)valueOrDefault | num);
            }
            else
            {
                retentionAndArchiveFlags = (RetentionAndArchiveFlags)num;
            }
            folder[StoreObjectSchema.RetentionFlags] = (int)retentionAndArchiveFlags;
            if (folder.GetValueOrDefault <object>(StoreObjectSchema.ExplicitPolicyTag) != null)
            {
                folder.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ExplicitPolicyTag
                });
            }
        }
        public static void SetPolicyTagForDeleteOnItem(PolicyTag policyTag, StoreObject item)
        {
            item[StoreObjectSchema.PolicyTag] = policyTag.PolicyGuid.ToByteArray();
            CompositeRetentionProperty compositeRetentionProperty = null;

            byte[] valueOrDefault = item.GetValueOrDefault <byte[]>(ItemSchema.StartDateEtc);
            if (valueOrDefault != null)
            {
                try
                {
                    compositeRetentionProperty = CompositeRetentionProperty.Parse(valueOrDefault, true);
                }
                catch (ArgumentException)
                {
                    compositeRetentionProperty = null;
                }
            }
            if (compositeRetentionProperty == null)
            {
                compositeRetentionProperty         = new CompositeRetentionProperty();
                compositeRetentionProperty.Integer = (int)policyTag.TimeSpanForRetention.TotalDays;
                object valueOrDefault2 = item.GetValueOrDefault <object>(InternalSchema.ReceivedTime);
                if (valueOrDefault2 == null)
                {
                    valueOrDefault2 = item.GetValueOrDefault <object>(StoreObjectSchema.CreationTime);
                }
                if (valueOrDefault2 == null)
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)ExDateTime.Now);
                }
                else
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)((ExDateTime)valueOrDefault2));
                }
                item[InternalSchema.StartDateEtc] = compositeRetentionProperty.GetBytes(true);
            }
            long fileTime = 0L;

            try
            {
                fileTime = compositeRetentionProperty.Date.Value.AddDays(policyTag.TimeSpanForRetention.TotalDays).ToFileTimeUtc();
            }
            catch (ArgumentOutOfRangeException)
            {
                fileTime = 0L;
            }
            item[InternalSchema.RetentionPeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
            DateTime dateTime = DateTime.FromFileTimeUtc(fileTime);

            item[InternalSchema.RetentionDate] = dateTime;
            if (item.GetValueOrDefault <object>(StoreObjectSchema.ExplicitPolicyTag) != null)
            {
                item.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ExplicitPolicyTag
                });
            }
        }
        public static void SetPolicyTagForDeleteOnNewItem(PolicyTag policyTag, StoreObject item)
        {
            item[StoreObjectSchema.PolicyTag]      = policyTag.PolicyGuid.ToByteArray();
            item[StoreObjectSchema.RetentionFlags] = 0;
            CompositeRetentionProperty setStartDateEtc = PolicyTagHelper.GetSetStartDateEtc(policyTag, item);

            if (policyTag.TimeSpanForRetention.TotalDays > 0.0)
            {
                item[InternalSchema.RetentionPeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
                item[InternalSchema.RetentionDate]   = PolicyTagHelper.CalculateExecutionDate(setStartDateEtc, policyTag.TimeSpanForRetention.TotalDays);
            }
        }
        public static void SetPolicyTagForArchiveOnNewFolder(PolicyTag policyTag, Folder folder)
        {
            folder[StoreObjectSchema.ArchiveTag]    = policyTag.PolicyGuid.ToByteArray();
            folder[StoreObjectSchema.ArchivePeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
            object valueOrDefault = folder.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags);
            RetentionAndArchiveFlags retentionAndArchiveFlags;

            if (valueOrDefault != null && valueOrDefault is int)
            {
                retentionAndArchiveFlags = (RetentionAndArchiveFlags)((int)valueOrDefault | 16);
            }
            else
            {
                retentionAndArchiveFlags = RetentionAndArchiveFlags.ExplictArchiveTag;
            }
            folder[StoreObjectSchema.RetentionFlags] = (int)retentionAndArchiveFlags;
        }
        private static CompositeRetentionProperty GetSetStartDateEtc(PolicyTag policyTag, StoreObject item)
        {
            CompositeRetentionProperty compositeRetentionProperty = null;

            byte[] array = null;
            try
            {
                array = item.GetValueOrDefault <byte[]>(InternalSchema.StartDateEtc);
            }
            catch (NotInBagPropertyErrorException)
            {
                array = null;
            }
            if (array != null)
            {
                try
                {
                    compositeRetentionProperty = CompositeRetentionProperty.Parse(array, true);
                }
                catch (ArgumentException)
                {
                    compositeRetentionProperty = null;
                }
            }
            if (compositeRetentionProperty == null)
            {
                compositeRetentionProperty         = new CompositeRetentionProperty();
                compositeRetentionProperty.Integer = (int)policyTag.TimeSpanForRetention.TotalDays;
                object valueOrDefault = item.GetValueOrDefault <object>(InternalSchema.ReceivedTime);
                if (valueOrDefault == null)
                {
                    valueOrDefault = item.GetValueOrDefault <object>(StoreObjectSchema.CreationTime);
                }
                if (valueOrDefault == null)
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)ExDateTime.Now);
                }
                else
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)((ExDateTime)valueOrDefault));
                }
                item[InternalSchema.StartDateEtc] = compositeRetentionProperty.GetBytes(true);
            }
            return(compositeRetentionProperty);
        }
Beispiel #6
0
 private GroupOperationResult SetRetentionPolicyInternal(StoreObjectId itemId, PolicyTag policyTag, bool isArchiveAction)
 {
     PropertyDefinition[] propsToReturn = isArchiveAction ? PolicyTagHelper.ArchiveProperties : PolicyTagHelper.RetentionProperties;
     using (Item item = Item.Bind(this.session, itemId, propsToReturn))
     {
         item.OpenAsReadWrite();
         if (isArchiveAction)
         {
             if (policyTag == null)
             {
                 PolicyTagHelper.ClearPolicyTagForArchiveOnItem(item);
             }
             else
             {
                 PolicyTagHelper.SetPolicyTagForArchiveOnItem(policyTag, item);
             }
         }
         else if (policyTag == null)
         {
             PolicyTagHelper.ClearPolicyTagForDeleteOnItem(item);
         }
         else
         {
             PolicyTagHelper.SetPolicyTagForDeleteOnItem(policyTag, item);
         }
         item.Save(SaveMode.ResolveConflicts);
     }
     return(new GroupOperationResult(OperationResult.Succeeded, new StoreObjectId[]
     {
         itemId
     }, null));
 }
Beispiel #7
0
        public AggregateOperationResult SetRetentionPolicy(StoreObjectId contextFolderId, DateTime?actionTime, PolicyTag policyTag, bool isArchiveAction)
        {
            StoreObjectId[]             array = this.GetFilteredItemIds(contextFolderId, actionTime, null).ToArray();
            List <GroupOperationResult> groupOperationResults = new List <GroupOperationResult>(array.Length);

            if (array != null)
            {
                StoreObjectId[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    StoreObjectId itemId = array2[i];
                    Folder.ExecuteGroupOperationAndAggregateResults(groupOperationResults, new StoreObjectId[]
                    {
                        itemId
                    }, () => this.SetRetentionPolicyInternal(itemId, policyTag, isArchiveAction));
                }
            }
            return(Folder.CreateAggregateOperationResult(groupOperationResults));
        }