protected NativeStorePropertyDefinition CreatePropertyDefinition(TnefPropertyTag propertyTag, TnefNameId?namedProperty) { PropType tnefType = (PropType)propertyTag.TnefType; if (tnefType == PropType.Error || tnefType == PropType.Null || tnefType == PropType.ObjectArray || tnefType == PropType.Unspecified) { return(null); } if (tnefType == PropType.Object && propertyTag != TnefPropertyTag.AttachDataObj) { return(null); } if (namedProperty == null) { return(PropertyTagPropertyDefinition.InternalCreateCustom(string.Empty, (PropTag)propertyTag, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType)); } Guid propertySetGuid = namedProperty.Value.PropertySetGuid; if (namedProperty.Value.Kind == TnefNameIdKind.Id) { return(GuidIdPropertyDefinition.InternalCreateCustom(string.Empty, tnefType, propertySetGuid, namedProperty.Value.Id, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType, new PropertyDefinitionConstraint[0])); } string name = namedProperty.Value.Name; if (!GuidNamePropertyDefinition.IsValidName(propertySetGuid, name)) { return(null); } return(GuidNamePropertyDefinition.InternalCreateCustom(string.Empty, tnefType, propertySetGuid, name, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType, new PropertyDefinitionConstraint[0])); }
private TnefPropertyTag StartProperty(NativeStorePropertyDefinition property) { this.CheckStartTnefAttribute(); this.streamProperty = null; TnefPropertyTag tnefPropertyTag; switch (property.SpecifiedWith) { case PropertyTypeSpecifier.PropertyTag: tnefPropertyTag = ItemToTnefConverter.TnefContentWriter.GetTnefPropertyTag((PropertyTagPropertyDefinition)property); this.tnefWriter.StartProperty(tnefPropertyTag); break; case PropertyTypeSpecifier.GuidString: { GuidNamePropertyDefinition guidNamePropertyDefinition = (GuidNamePropertyDefinition)property; tnefPropertyTag = ItemToTnefConverter.TnefContentWriter.GetTnefPropertyTag(guidNamePropertyDefinition); this.tnefWriter.StartProperty(tnefPropertyTag, guidNamePropertyDefinition.Guid, guidNamePropertyDefinition.PropertyName); break; } case PropertyTypeSpecifier.GuidId: { GuidIdPropertyDefinition guidIdPropertyDefinition = (GuidIdPropertyDefinition)property; tnefPropertyTag = ItemToTnefConverter.TnefContentWriter.GetTnefPropertyTag(guidIdPropertyDefinition); this.tnefWriter.StartProperty(tnefPropertyTag, guidIdPropertyDefinition.Guid, guidIdPropertyDefinition.Id); break; } default: throw new InvalidOperationException(string.Format("Invalid native property specifier: {0}", property.SpecifiedWith)); } return(tnefPropertyTag); }
private void WriteProperty(NativeStorePropertyDefinition property, object value) { value = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(value); switch (property.SpecifiedWith) { case PropertyTypeSpecifier.PropertyTag: { PropertyTagPropertyDefinition propertyTagPropertyDefinition = (PropertyTagPropertyDefinition)property; TnefPropertyTag propertyTag = (int)propertyTagPropertyDefinition.PropertyTag; this.PropertyWriter.WriteProperty(propertyTag, value); return; } case PropertyTypeSpecifier.GuidString: { GuidNamePropertyDefinition guidNamePropertyDefinition = (GuidNamePropertyDefinition)property; TnefPropertyType propertyType = (TnefPropertyType)guidNamePropertyDefinition.MapiPropertyType; this.PropertyWriter.WriteProperty(guidNamePropertyDefinition.Guid, guidNamePropertyDefinition.PropertyName, propertyType, value); return; } case PropertyTypeSpecifier.GuidId: { GuidIdPropertyDefinition guidIdPropertyDefinition = (GuidIdPropertyDefinition)property; TnefPropertyType propertyType2 = (TnefPropertyType)guidIdPropertyDefinition.MapiPropertyType; this.PropertyWriter.WriteProperty(guidIdPropertyDefinition.Guid, guidIdPropertyDefinition.Id, propertyType2, value); return; } default: throw new InvalidOperationException(string.Format("Invalid native property specifier: {0}", property.SpecifiedWith)); } }
public override bool Equals(object obj) { if (object.ReferenceEquals(obj, this)) { return(true); } GuidIdPropertyDefinition guidIdPropertyDefinition = obj as GuidIdPropertyDefinition; return(guidIdPropertyDefinition != null && this.GetHashCode() == guidIdPropertyDefinition.GetHashCode() && this.Guid == guidIdPropertyDefinition.Guid && this.Id == guidIdPropertyDefinition.Id && base.MapiPropertyType == guidIdPropertyDefinition.MapiPropertyType); }
private void StreamProperty(NativeStorePropertyDefinition property, Stream propertyStream) { Stream stream = null; try { switch (property.SpecifiedWith) { case PropertyTypeSpecifier.PropertyTag: { PropertyTagPropertyDefinition propertyTagPropertyDefinition = (PropertyTagPropertyDefinition)property; TnefPropertyTag propertyTag = (int)propertyTagPropertyDefinition.PropertyTag; stream = this.PropertyWriter.OpenPropertyStream(propertyTag); break; } case PropertyTypeSpecifier.GuidString: { GuidNamePropertyDefinition guidNamePropertyDefinition = (GuidNamePropertyDefinition)property; TnefPropertyType propertyType = (TnefPropertyType)guidNamePropertyDefinition.MapiPropertyType; stream = this.PropertyWriter.OpenPropertyStream(guidNamePropertyDefinition.Guid, guidNamePropertyDefinition.PropertyName, propertyType); break; } case PropertyTypeSpecifier.GuidId: { GuidIdPropertyDefinition guidIdPropertyDefinition = (GuidIdPropertyDefinition)property; TnefPropertyType propertyType2 = (TnefPropertyType)guidIdPropertyDefinition.MapiPropertyType; stream = this.PropertyWriter.OpenPropertyStream(guidIdPropertyDefinition.Guid, guidIdPropertyDefinition.Id, propertyType2); break; } default: throw new InvalidOperationException(string.Format("Invalid native property specifier: {0}", property.SpecifiedWith)); } Util.StreamHandler.CopyStreamData(propertyStream, stream); } finally { if (stream != null) { stream.Close(); } } }
internal static GuidIdPropertyDefinition InternalCreate(string displayName, Type propertyType, PropType mapiPropType, Guid propertyGuid, int dispId, PropertyFlags flags, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, bool isCustom, params PropertyDefinitionConstraint[] constraints) { if (mapiPropType == PropType.AnsiString) { mapiPropType = PropType.String; propertyType = typeof(string); } else if (mapiPropType == PropType.AnsiStringArray) { mapiPropType = PropType.StringArray; propertyType = typeof(string[]); } NamedProp namedProp = new NamedProp(propertyGuid, dispId); NamedProp namedProp2 = WellKnownNamedProperties.Find(namedProp); if (namedProp2 != null) { namedProp = namedProp2; } else { namedProp = NamedPropertyDefinition.NamedPropertyKey.GetSingleton(namedProp); } GuidIdPropertyDefinition.GuidIdKey guidIdKey = new GuidIdPropertyDefinition.GuidIdKey(namedProp); bool flag; if (propertyGuid == WellKnownPropertySet.InternetHeaders) { NativeStorePropertyDefinition.OnFailedPropertyTypeCheck(guidIdKey, mapiPropType, typeCheckingFlag, out flag); return(null); } GuidIdPropertyDefinition result; if (GuidIdPropertyDefinition.TryFindEquivalentDefinition(guidIdKey, isCustom, mapiPropType, typeCheckingFlag, out result, out flag)) { return(result); } if (!flag) { return(null); } return(new GuidIdPropertyDefinition(displayName, propertyType, mapiPropType, guidIdKey, flags, isCustom, constraints)); }
private static NativeStorePropertyDefinition GetPropDefByMapiNamedProp(NamedProp prop, PropType type, NativeStorePropertyDefinition.TypeCheckingFlag propertyTypeCheckingFlag) { if (prop == null) { return(null); } switch (prop.Kind) { case NamedPropKind.Id: return(GuidIdPropertyDefinition.InternalCreateCustom(string.Empty, type, prop.Guid, prop.Id, PropertyFlags.None, propertyTypeCheckingFlag, new PropertyDefinitionConstraint[0])); case NamedPropKind.String: if (GuidNamePropertyDefinition.IsValidName(prop.Guid, prop.Name)) { return(GuidNamePropertyDefinition.InternalCreate(string.Empty, InternalSchema.ClrTypeFromPropTagType(type), type, prop.Guid, prop.Name, PropertyFlags.None, propertyTypeCheckingFlag, true, PropertyDefinitionConstraint.None)); } return(null); default: throw new ArgumentOutOfRangeException("prop.Kind"); } }
internal static void RecalculateNormalizedTimeProperty(PropertyBag.BasicPropertyStore propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty, ExTimeZone newTimeZone) { if (newTimeZone == null || newTimeZone == ExTimeZone.UtcTimeZone || newTimeZone == ExTimeZone.UnspecifiedTimeZone) { return; } ExDateTime?normalizedTime = StartTimeProperty.GetNormalizedTime(propertyBag, utcTimeProperty, legacyUtcTimeProperty); if (normalizedTime != null) { ExDateTime exDateTime = newTimeZone.ConvertDateTime(normalizedTime.Value); propertyBag.SetValueWithFixup(utcTimeProperty, exDateTime.ToUtc()); if (legacyUtcTimeProperty != null) { propertyBag.SetValueWithFixup(legacyUtcTimeProperty, exDateTime.ToUtc()); } } }
internal static GuidIdPropertyDefinition InternalCreateCustom(string displayName, PropType mapiPropType, Guid propertyGuid, int dispId, PropertyFlags flags, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, params PropertyDefinitionConstraint[] constraints) { Type propertyType = InternalSchema.ClrTypeFromPropTagType(mapiPropType); return(GuidIdPropertyDefinition.InternalCreate(displayName, propertyType, mapiPropType, propertyGuid, dispId, flags | PropertyFlags.Custom, typeCheckingFlag, true, constraints)); }
internal static object InternalTryGetDateTimeValue(PropertyBag.BasicPropertyStore propertyBag, StorePropertyDefinition property, GuidIdPropertyDefinition mapiUtcTimeProperty, PropertyTagPropertyDefinition mapiLegacyUtcTimeProperty) { ExDateTime?normalizedTime = StartTimeProperty.GetNormalizedTime(propertyBag, mapiUtcTimeProperty, mapiLegacyUtcTimeProperty); if (normalizedTime != null) { return(normalizedTime.Value); } return(new PropertyError(property, PropertyErrorCode.NotFound)); }
public static GuidIdPropertyDefinition CreateCustom(string displayName, ushort mapiPropertyType, Guid propertyGuid, int dispId, PropertyFlags flags) { return(GuidIdPropertyDefinition.CreateCustom(displayName, InternalSchema.ClrTypeFromPropTagType((PropType)mapiPropertyType), propertyGuid, dispId, flags, PropertyDefinitionConstraint.None)); }
public static GuidIdPropertyDefinition CreateCustom(string displayName, Type propertyType, Guid propertyGuid, int dispId, PropertyFlags flags) { return(GuidIdPropertyDefinition.CreateCustom(displayName, propertyType, propertyGuid, dispId, flags, PropertyDefinitionConstraint.None)); }
internal static ExDateTime?GetNormalizedTime(PropertyBag.BasicPropertyStore propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty) { ExDateTime?valueAsNullable = propertyBag.GetValueAsNullable <ExDateTime>(utcTimeProperty); if (valueAsNullable == null) { if (legacyUtcTimeProperty != null) { valueAsNullable = propertyBag.GetValueAsNullable <ExDateTime>(legacyUtcTimeProperty); } if (valueAsNullable == null) { return(null); } } ExDateTime exDateTime = ExTimeZone.UtcTimeZone.ConvertDateTime(valueAsNullable.Value); byte[] valueOrDefault = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneDefinitionStart); ExTimeZone legacyTimeZone; if (O12TimeZoneFormatter.TryParseTimeZoneBlob(valueOrDefault, string.Empty, out legacyTimeZone)) { exDateTime = TimeZoneHelper.NormalizeUtcTime(exDateTime, legacyTimeZone); } exDateTime = StartTimeProperty.DynamicAdjustForAllDayEvent(propertyBag, exDateTime, utcTimeProperty == InternalSchema.MapiEndTime); return(new ExDateTime?(propertyBag.TimeZone.ConvertDateTime(exDateTime))); }
internal static ExDateTime?GetNormalizedTime(PropertyBag propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty) { return(StartTimeProperty.GetNormalizedTime((PropertyBag.BasicPropertyStore)propertyBag, utcTimeProperty, legacyUtcTimeProperty)); }
internal static void DenormalizeTimeProperty(PropertyBag propertyBag, ExDateTime newTime, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty) { byte[] valueOrDefault = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneDefinitionStart); ExTimeZone legacyTimeZone; if (O12TimeZoneFormatter.TryParseTimeZoneBlob(valueOrDefault, string.Empty, out legacyTimeZone)) { ExDateTime exDateTime = TimeZoneHelper.DeNormalizeToUtcTime(newTime, legacyTimeZone); propertyBag.SetProperty(utcTimeProperty, exDateTime); if (legacyUtcTimeProperty != null) { propertyBag.SetProperty(legacyUtcTimeProperty, exDateTime); } } }
public static GuidIdPropertyDefinition CreateCustom(string displayName, Type propertyType, Guid propertyGuid, int dispId, PropertyFlags flags, params PropertyDefinitionConstraint[] constraints) { PropType mapiPropType = InternalSchema.PropTagTypeFromClrType(propertyType); return(GuidIdPropertyDefinition.InternalCreate(displayName, propertyType, mapiPropType, propertyGuid, dispId, flags | PropertyFlags.Custom, NativeStorePropertyDefinition.TypeCheckingFlag.ThrowOnInvalidType, true, constraints)); }
private static TnefPropertyTag GetTnefPropertyTag(GuidIdPropertyDefinition property) { return((int)((PropType)(-2147483648) | property.MapiPropertyType)); }
internal static bool TryFindEquivalentDefinition(GuidIdPropertyDefinition.GuidIdKey key, bool isCustom, PropType type, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, out GuidIdPropertyDefinition definition, out bool createNewDefinition) { createNewDefinition = true; if (!isCustom) { definition = null; return(false); } switch (NativeStorePropertyDefinitionDictionary.TryFindInstance(key, type, typeCheckingFlag == NativeStorePropertyDefinition.TypeCheckingFlag.AllowCompatibleType, out definition)) { case PropertyMatchResult.Found: createNewDefinition = false; return(true); case PropertyMatchResult.TypeMismatch: NativeStorePropertyDefinition.OnFailedPropertyTypeCheck(key, type, typeCheckingFlag, out createNewDefinition); break; } return(false); }
internal static ExDateTime?GetWallClockTime(PropertyBag.BasicPropertyStore propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty, NativeStorePropertyDefinition[] timeZoneBlobPropertyDefinitions) { ExDateTime?normalizedTime = StartTimeProperty.GetNormalizedTime(propertyBag, utcTimeProperty, legacyUtcTimeProperty); if (normalizedTime == null) { return(null); } byte[] array = null; foreach (NativeStorePropertyDefinition propertyDefinition in timeZoneBlobPropertyDefinitions) { array = propertyBag.GetValueOrDefault <byte[]>(propertyDefinition); if (array != null) { break; } } if (array == null) { ExTraceGlobals.StorageTracer.TraceWarning(0L, "Could not determine suitable time zone"); } ExTimeZone exTimeZone = StartWallClockProperty.FindBestMatchingTimeZone(array); if (exTimeZone != null) { return(new ExDateTime?(exTimeZone.ConvertDateTime(normalizedTime.Value))); } return(new ExDateTime?(normalizedTime.Value)); }
internal static void SetCalendarTime(PropertyBag.BasicPropertyStore propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty, GuidIdPropertyDefinition timeZoneDefinition, bool isEndTime, object value) { StoreObject storeObject = propertyBag.Context.StoreObject; CalendarItemBase calendarItemBase = storeObject as CalendarItemBase; if (calendarItemBase != null && calendarItemBase.PropertyBag.ExTimeZone != null && calendarItemBase.IsAllDayEventCache == null) { object obj = IsAllDayEventProperty.CalculateIsAllDayEvent(propertyBag); if (obj is bool) { calendarItemBase.IsAllDayEventCache = new bool?((bool)obj); } } propertyBag.SetValueWithFixup(utcTimeProperty, value); propertyBag.SetValueWithFixup(legacyUtcTimeProperty, value); ExTimeZone timeZone = propertyBag.TimeZone; if (value is ExDateTime && ((ExDateTime)value).TimeZone != null && ((ExDateTime)value).TimeZone != ExTimeZone.UnspecifiedTimeZone) { timeZone = ((ExDateTime)value).TimeZone; } if (timeZone == ExTimeZone.UtcTimeZone) { if (!(storeObject is CalendarItemOccurrence)) { propertyBag.Delete(timeZoneDefinition); } } else if (value is ExDateTime && timeZone != ExTimeZone.UnspecifiedTimeZone) { if (timeZoneDefinition == InternalSchema.TimeZoneDefinitionStart) { byte[] timeZoneBlob = O12TimeZoneFormatter.GetTimeZoneBlob(timeZone); StartTimeZoneProperty.RecalculateNormalizedTimeProperty(propertyBag, InternalSchema.MapiEndTime, InternalSchema.MapiPREndDate, timeZone); StartTimeZoneProperty.RecalculateNormalizedTimeProperty(propertyBag, InternalSchema.ReminderNextTime, null, timeZone); StartTimeZoneProperty.SyncRecurringTimeZoneProperties(propertyBag, timeZone, timeZoneBlob); propertyBag.SetValueWithFixup(timeZoneDefinition, timeZoneBlob); } else { byte[] timeZoneBlob2 = O12TimeZoneFormatter.GetTimeZoneBlob(timeZone, (ExDateTime)value); propertyBag.SetValueWithFixup(timeZoneDefinition, timeZoneBlob2); } } if (!isEndTime) { propertyBag.SetValueWithFixup(InternalSchema.ReminderDueByInternal, value); } if (storeObject != null) { Reminder.Adjust(storeObject); } }