Exemplo n.º 1
0
 /// <summary>
 /// Adds the schema property names to dictionary.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="propertyNameDictionary">The property name dictionary.</param>
 private static void AddSchemaPropertyNamesToDictionary(Type type, Dictionary <PropertyDefinition, string> propertyNameDictionary)
 {
     ServiceObjectSchema.ForeachPublicStaticPropertyFieldInType(
         type,
         delegate(PropertyDefinition propertyDefinition, FieldInfo fieldInfo)
         { propertyNameDictionary.Add(propertyDefinition, fieldInfo.Name); });
 }
        /// <summary>
        /// Tries to load from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <returns>True if property was loaded.</returns>
        internal static bool TryLoadFromXml(EwsServiceXmlReader reader, ref PropertyDefinitionBase propertyDefinition)
        {
            switch (reader.LocalName)
            {
            case XmlElementNames.FieldURI:
                propertyDefinition = ServiceObjectSchema.FindPropertyDefinition(reader.ReadAttributeValue(XmlAttributeNames.FieldURI));
                reader.SkipCurrentElement();
                return(true);

            case XmlElementNames.IndexedFieldURI:
                propertyDefinition = new IndexedPropertyDefinition(
                    reader.ReadAttributeValue(XmlAttributeNames.FieldURI),
                    reader.ReadAttributeValue(XmlAttributeNames.FieldIndex));
                reader.SkipCurrentElement();
                return(true);

            case XmlElementNames.ExtendedFieldURI:
                propertyDefinition = new ExtendedPropertyDefinition();
                (propertyDefinition as ExtendedPropertyDefinition).LoadFromXml(reader);
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validate request.
        /// </summary>
        internal override void Validate()
        {
            base.Validate();

            if (this.SearchQueries == null || this.SearchQueries.Count == 0)
            {
                throw new ServiceValidationException(Strings.MailboxQueriesParameterIsNotSpecified);
            }

            foreach (MailboxQuery searchQuery in this.SearchQueries)
            {
                if (searchQuery.MailboxSearchScopes == null || searchQuery.MailboxSearchScopes.Length == 0)
                {
                    throw new ServiceValidationException(Strings.MailboxQueriesParameterIsNotSpecified);
                }
            }

            if (!string.IsNullOrEmpty(this.SortByProperty))
            {
                PropertyDefinitionBase prop = null;
                try
                {
                    prop = ServiceObjectSchema.FindPropertyDefinition(this.SortByProperty);
                }
                catch (KeyNotFoundException)
                {
                }

                if (prop == null)
                {
                    throw new ServiceValidationException(string.Format(Strings.InvalidSortByPropertyForMailboxSearch, this.SortByProperty));
                }
            }
        }
        /// <summary>
        /// Validate request.
        /// </summary>
        internal override void Validate()
        {
            base.Validate();

            if (this.SearchQueries == null || this.SearchQueries.Count == 0)
            {
                throw new ServiceValidationException(Strings.MailboxQueriesParameterIsNotSpecified);
            }

            foreach (MailboxQuery searchQuery in this.SearchQueries)
            {
                if (searchQuery.MailboxSearchScopes == null || searchQuery.MailboxSearchScopes.Length == 0)
                {
                    throw new ServiceValidationException(Strings.MailboxQueriesParameterIsNotSpecified);
                }

                foreach (MailboxSearchScope searchScope in searchQuery.MailboxSearchScopes)
                {
                    if (searchScope.ExtendedAttributes != null && searchScope.ExtendedAttributes.Count > 0 && !DiscoverySchemaChanges.SearchMailboxesExtendedData.IsCompatible(this))
                    {
                        throw new ServiceVersionException(
                                  string.Format(
                                      Strings.ClassIncompatibleWithRequestVersion,
                                      typeof(ExtendedAttribute).Name,
                                      DiscoverySchemaChanges.SearchMailboxesExtendedData.MinimumServerVersion));
                    }

                    if (searchScope.SearchScopeType != MailboxSearchScopeType.LegacyExchangeDN && (!DiscoverySchemaChanges.SearchMailboxesExtendedData.IsCompatible(this) || !DiscoverySchemaChanges.SearchMailboxesAdditionalSearchScopes.IsCompatible(this)))
                    {
                        throw new ServiceVersionException(
                                  string.Format(
                                      Strings.EnumValueIncompatibleWithRequestVersion,
                                      searchScope.SearchScopeType.ToString(),
                                      typeof(MailboxSearchScopeType).Name,
                                      DiscoverySchemaChanges.SearchMailboxesAdditionalSearchScopes.MinimumServerVersion));
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.SortByProperty))
            {
                PropertyDefinitionBase prop = null;
                try
                {
                    prop = ServiceObjectSchema.FindPropertyDefinition(this.SortByProperty);
                }
                catch (KeyNotFoundException)
                {
                }

                if (prop == null)
                {
                    throw new ServiceValidationException(string.Format(Strings.InvalidSortByPropertyForMailboxSearch, this.SortByProperty));
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initialize schema property names.
 /// </summary>
 internal static void InitializeSchemaPropertyNames()
 {
     lock (lockObject)
     {
         foreach (Type type in ServiceObjectSchema.allSchemaTypes.Member)
         {
             ServiceObjectSchema.ForeachPublicStaticPropertyFieldInType(
                 type,
                 delegate(PropertyDefinition propDef, FieldInfo fieldInfo) { propDef.Name = fieldInfo.Name; });
         }
     }
 }
        /// <summary>
        /// Tries to load from XML.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns>True if property was loaded.</returns>
        internal static PropertyDefinitionBase TryLoadFromJson(JsonObject jsonObject)
        {
            switch (jsonObject.ReadTypeString())
            {
            case JsonNames.PathToUnindexedFieldType:
                return(ServiceObjectSchema.FindPropertyDefinition(jsonObject.ReadAsString(XmlAttributeNames.FieldURI)));

            case JsonNames.PathToIndexedFieldType:
                return(new IndexedPropertyDefinition(
                           jsonObject.ReadAsString(XmlAttributeNames.FieldURI),
                           jsonObject.ReadAsString(XmlAttributeNames.FieldIndex)));

            case JsonNames.PathToExtendedFieldType:
                ExtendedPropertyDefinition propertyDefinition = new ExtendedPropertyDefinition();
                propertyDefinition.LoadFromJson(jsonObject);
                return(propertyDefinition);

            default:
                return(null);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parses the message XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void ParseMessageXml(EwsServiceXmlReader reader)
        {
            do
            {
                reader.Read();

                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                        case XmlElementNames.Value:
                            this.errorDetails.Add(reader.ReadAttributeValue(XmlAttributeNames.Name), reader.ReadElementValue());
                            break;

                        case XmlElementNames.FieldURI:
                            this.errorProperties.Add(ServiceObjectSchema.FindPropertyDefinition(reader.ReadAttributeValue(XmlAttributeNames.FieldURI)));
                            break;

                        case XmlElementNames.IndexedFieldURI:
                            this.errorProperties.Add(
                                new IndexedPropertyDefinition(
                                    reader.ReadAttributeValue(XmlAttributeNames.FieldURI),
                                    reader.ReadAttributeValue(XmlAttributeNames.FieldIndex)));
                            break;

                        case XmlElementNames.ExtendedFieldURI:
                            ExtendedPropertyDefinition extendedPropDef = new ExtendedPropertyDefinition();
                            extendedPropDef.LoadFromXml(reader);
                            this.errorProperties.Add(extendedPropDef);
                            break;

                        default:
                            break;
                    }
                }
            }
            while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.MessageXml));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Adds schema properties to dictionary.
        /// </summary>
        /// <param name="type">Schema type.</param>
        /// <param name="propDefDictionary">The property definition dictionary.</param>
        internal static void AddSchemaPropertiesToDictionary(
            Type type,
            Dictionary <string, PropertyDefinitionBase> propDefDictionary)
        {
            ServiceObjectSchema.ForeachPublicStaticPropertyFieldInType(
                type,
                delegate(PropertyDefinition propertyDefinition, FieldInfo fieldInfo)
            {
                // Some property definitions descend from ServiceObjectPropertyDefinition but don't have
                // a Uri, like ExtendedProperties. Ignore them.
                if (!string.IsNullOrEmpty(propertyDefinition.Uri))
                {
                    PropertyDefinitionBase existingPropertyDefinition;
                    if (propDefDictionary.TryGetValue(propertyDefinition.Uri, out existingPropertyDefinition))
                    {
                        EwsUtilities.Assert(
                            existingPropertyDefinition == propertyDefinition,
                            "Schema.allSchemaProperties.delegate",
                            string.Format("There are at least two distinct property definitions with the following URI: {0}", propertyDefinition.Uri));
                    }
                    else
                    {
                        propDefDictionary.Add(propertyDefinition.Uri, propertyDefinition);

                        // The following is a "generic hack" to register properties that are not public and
                        // thus not returned by the above GetFields call. It is currently solely used to register
                        // the MeetingTimeZone property.
                        List <PropertyDefinition> associatedInternalProperties = propertyDefinition.GetAssociatedInternalProperties();

                        foreach (PropertyDefinition associatedInternalProperty in associatedInternalProperties)
                        {
                            propDefDictionary.Add(associatedInternalProperty.Uri, associatedInternalProperty);
                        }
                    }
                }
            });
        }