Ejemplo n.º 1
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);
            }
        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]));
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(obj, this))
            {
                return(true);
            }
            GuidNamePropertyDefinition guidNamePropertyDefinition = obj as GuidNamePropertyDefinition;

            return(guidNamePropertyDefinition != null && this.GetHashCode() == guidNamePropertyDefinition.GetHashCode() && this.Guid == guidNamePropertyDefinition.Guid && this.PropertyName == guidNamePropertyDefinition.PropertyName && base.MapiPropertyType == guidNamePropertyDefinition.MapiPropertyType);
        }
Ejemplo n.º 5
0
        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();
                }
            }
        }
Ejemplo n.º 6
0
        internal static GuidNamePropertyDefinition InternalCreate(string displayName, Type propertyType, PropType mapiPropType, Guid propertyGuid, string propertyName, PropertyFlags flags, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, bool isCustom, params PropertyDefinitionConstraint[] constraints)
        {
            if (!GuidNamePropertyDefinition.IsValidName(propertyGuid, propertyName))
            {
                throw new ArgumentException("Invalid property name for property", "propertyName");
            }
            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, propertyName);
            NamedProp namedProp2 = WellKnownNamedProperties.Find(namedProp);

            if (namedProp2 != null)
            {
                namedProp = namedProp2;
            }
            else
            {
                namedProp = NamedPropertyDefinition.NamedPropertyKey.GetSingleton(namedProp);
            }
            GuidNamePropertyDefinition.GuidNameKey guidNameKey = new GuidNamePropertyDefinition.GuidNameKey(namedProp);
            GuidNamePropertyDefinition             result;
            bool flag;

            if (GuidNamePropertyDefinition.TryFindEquivalentDefinition(guidNameKey, isCustom, mapiPropType, typeCheckingFlag, out result, out flag))
            {
                return(result);
            }
            if (!flag)
            {
                return(null);
            }
            return(new GuidNamePropertyDefinition(displayName, propertyType, mapiPropType, guidNameKey, flags, isCustom, constraints));
        }
Ejemplo n.º 7
0
        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");
            }
        }
Ejemplo n.º 8
0
 private static TnefPropertyTag GetTnefPropertyTag(GuidNamePropertyDefinition property)
 {
     return((int)((PropType)(-2147483648) | property.MapiPropertyType));
 }
Ejemplo n.º 9
0
        private bool IsExtensionCustomProperty(NativeStorePropertyDefinition property)
        {
            GuidNamePropertyDefinition guidNamePropertyDefinition = property as GuidNamePropertyDefinition;

            return(guidNamePropertyDefinition != null && guidNamePropertyDefinition.Guid == WellKnownPropertySet.PublicStrings && guidNamePropertyDefinition.PropertyName.StartsWith("cecp-", StringComparison.Ordinal));
        }
Ejemplo n.º 10
0
        internal static bool TryFindEquivalentDefinition(GuidNamePropertyDefinition.GuidNameKey key, bool isCustom, PropType type, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, out GuidNamePropertyDefinition 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);
        }
Ejemplo n.º 11
0
        public static GuidNamePropertyDefinition CreateCustom(string displayName, Type propertyType, Guid propertyGuid, string propertyName, PropertyFlags flags, params PropertyDefinitionConstraint[] constraints)
        {
            PropType mapiPropType = InternalSchema.PropTagTypeFromClrType(propertyType);

            return(GuidNamePropertyDefinition.InternalCreate(displayName, propertyType, mapiPropType, propertyGuid, propertyName, flags | PropertyFlags.Custom, NativeStorePropertyDefinition.TypeCheckingFlag.ThrowOnInvalidType, true, constraints));
        }
Ejemplo n.º 12
0
 public static GuidNamePropertyDefinition CreateCustom(string displayName, Type propertyType, Guid propertyGuid, string propertyName, PropertyFlags flags)
 {
     return(GuidNamePropertyDefinition.CreateCustom(displayName, propertyType, propertyGuid, propertyName, flags, PropertyDefinitionConstraint.None));
 }
Ejemplo n.º 13
0
        internal static GuidNamePropertyDefinition InternalCreateCustom(string displayName, PropType mapiPropType, Guid propertyGuid, string propertyName, PropertyFlags flags, NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, params PropertyDefinitionConstraint[] constraints)
        {
            Type propertyType = InternalSchema.ClrTypeFromPropTagType(mapiPropType);

            return(GuidNamePropertyDefinition.InternalCreate(displayName, propertyType, mapiPropType, propertyGuid, propertyName, flags | PropertyFlags.Custom, typeCheckingFlag, true, constraints));
        }
Ejemplo n.º 14
0
 private GuidNamePropertyDefinition(string displayName, Type propertyType, PropType mapiPropertyType, GuidNamePropertyDefinition.GuidNameKey key, PropertyFlags flags, bool isCustom, PropertyDefinitionConstraint[] constraints) : base(PropertyTypeSpecifier.GuidString, displayName, propertyType, mapiPropertyType, GuidNamePropertyDefinition.CalculatePropertyTagPropertyFlags(key.PropertyName, key.PropertyGuid, flags, isCustom), constraints)
 {
     this.InternalKey = key;
     this.hashCode    = (this.Guid.GetHashCode() ^ this.PropertyName.GetHashCode() ^ (int)base.MapiPropertyType);
 }