Exemple #1
0
        internal static CompositeRetentionProperty Parse(byte[] propertyBytes, bool useFileTime)
        {
            if (propertyBytes.Length != 12)
            {
                throw new ArgumentException("The length of the composite property must be 12. It is: " + propertyBytes.Length);
            }
            CompositeRetentionProperty compositeRetentionProperty = new CompositeRetentionProperty();

            compositeRetentionProperty.integer = BitConverter.ToInt32(propertyBytes, 0);
            if (useFileTime)
            {
                long num = BitConverter.ToInt64(propertyBytes, 4);
                if (num == 0L)
                {
                    compositeRetentionProperty.date = new DateTime?(DateTime.MinValue);
                }
                else
                {
                    compositeRetentionProperty.date = new DateTime?(DateTime.FromFileTimeUtc(num));
                }
            }
            else
            {
                compositeRetentionProperty.date = new DateTime?(DateTime.FromBinary(BitConverter.ToInt64(propertyBytes, 4)));
            }
            return(compositeRetentionProperty);
        }
        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);
            }
        }
        private static DateTime CalculateExecutionDate(CompositeRetentionProperty startDateEtc, double policyDays)
        {
            long fileTime = 0L;

            if (startDateEtc != null && startDateEtc.Date != null)
            {
                try
                {
                    fileTime = startDateEtc.Date.Value.AddDays(policyDays).ToFileTimeUtc();
                }
                catch (ArgumentOutOfRangeException)
                {
                    fileTime = 0L;
                }
            }
            return(DateTime.FromFileTimeUtc(fileTime));
        }
        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);
        }
Exemple #6
0
 internal static CompositeRetentionProperty Parse(byte[] propertyBytes)
 {
     return(CompositeRetentionProperty.Parse(propertyBytes, false));
 }