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 }); } }
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); }