예제 #1
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonCollection">The json collection.</param>
        /// <param name="service">The service.</param>
        void IJsonCollectionDeserializer.CreateFromJsonCollection(object[] jsonCollection, ExchangeService service)
        {
            foreach (object jsonObject in jsonCollection)
            {
                JsonObject jsonProperty = jsonObject as JsonObject;

                if (jsonProperty != null)
                {
                    TComplexProperty complexProperty = null;

                    // If type property is present, use it. Otherwise create default property instance.
                    // Note: polymorphic collections (such as Attachments) need a type property so
                    // the CreateDefaultComplexProperty call will fail.
                    if (jsonProperty.HasTypeProperty())
                    {
                        complexProperty = this.CreateComplexProperty(jsonProperty.ReadTypeString());
                    }
                    else
                    {
                        complexProperty = this.CreateDefaultComplexProperty();
                    }

                    if (complexProperty != null)
                    {
                        complexProperty.LoadFromJson(jsonProperty, service);
                        this.InternalAdd(complexProperty, true);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            string alternateIdClass = responseObject.ReadTypeString();

            switch (alternateIdClass)
            {
            case AlternateId.SchemaTypeName:
                this.convertedId = new AlternateId();
                break;

            case AlternatePublicFolderId.SchemaTypeName:
                this.convertedId = new AlternatePublicFolderId();
                break;

            case AlternatePublicFolderItemId.SchemaTypeName:
                this.convertedId = new AlternatePublicFolderItemId();
                break;

            default:
                EwsUtilities.Assert(
                    false,
                    "ConvertIdResponse.ReadElementsFromXml",
                    string.Format("Unknown alternate Id class: {0}", alternateIdClass));
                break;
            }

            this.convertedId.LoadAttributesFromJson(responseObject);
        }
        /// <summary>
        /// Reads the service objects collection from JSON.
        /// </summary>
        /// <typeparam name="TServiceObject">The type of the service object.</typeparam>
        /// <param name="jsonResponse">The json response.</param>
        /// <param name="collectionJsonElementName">Name of the collection XML element.</param>
        /// <param name="getObjectInstanceDelegate">The get object instance delegate.</param>
        /// <param name="clearPropertyBag">if set to <c>true</c> [clear property bag].</param>
        /// <param name="requestedPropertySet">The requested property set.</param>
        /// <param name="summaryPropertiesOnly">if set to <c>true</c> [summary properties only].</param>
        /// <returns>List of service objects.</returns>
        internal List <TServiceObject> ReadServiceObjectsCollectionFromJson <TServiceObject>(
            JsonObject jsonResponse,
            string collectionJsonElementName,
            GetObjectInstanceDelegate <TServiceObject> getObjectInstanceDelegate,
            bool clearPropertyBag,
            PropertySet requestedPropertySet,
            bool summaryPropertiesOnly) where TServiceObject : ServiceObject
        {
            List <TServiceObject> serviceObjects = new List <TServiceObject>();
            TServiceObject        serviceObject  = null;

            object[] jsonServiceObjects = jsonResponse.ReadAsArray(collectionJsonElementName);
            foreach (object arrayEntry in jsonServiceObjects)
            {
                JsonObject jsonServiceObject = arrayEntry as JsonObject;

                if (jsonServiceObject != null)
                {
                    serviceObject = getObjectInstanceDelegate(this.Service, jsonServiceObject.ReadTypeString());

                    if (serviceObject != null)
                    {
                        if (string.Compare(jsonServiceObject.ReadTypeString(), serviceObject.GetXmlElementName(), StringComparison.Ordinal) != 0)
                        {
                            throw new ServiceLocalException(
                                      string.Format(
                                          "The type of the object in the store ({0}) does not match that of the local object ({1}).",
                                          jsonServiceObject.ReadTypeString(),
                                          serviceObject.GetXmlElementName()));
                        }

                        serviceObject.LoadFromJson(
                            jsonServiceObject,
                            this.Service,
                            clearPropertyBag,
                            requestedPropertySet,
                            summaryPropertiesOnly);

                        serviceObjects.Add(serviceObject);
                    }
                }
            }

            return(serviceObjects);
        }
예제 #4
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        internal static SearchFilter LoadSearchFilterFromJson(JsonObject jsonObject, ExchangeService service)
        {
            SearchFilter searchFilter = GetSearchFilterInstance(jsonObject.ReadTypeString());

            if (searchFilter != null)
            {
                searchFilter.LoadFromJson(jsonObject, service);
            }

            return(searchFilter);
        }
예제 #5
0
        /// <summary>
        /// Loads from json collection.
        /// </summary>
        /// <param name="jsonCollection">The json collection.</param>
        /// <param name="service">The service.</param>
        void IJsonCollectionDeserializer.CreateFromJsonCollection(object[] jsonCollection, ExchangeService service)
        {
            foreach (object entry in jsonCollection)
            {
                JsonObject jsonServiceObject = entry as JsonObject;

                TItem item = EwsUtilities.CreateEwsObjectFromXmlElementName <Item>(
                    service,
                    jsonServiceObject.ReadTypeString()) as TItem;

                item.LoadFromJson(jsonServiceObject, service, true);

                this.items.Add(item);
            }
        }
            /// <summary>
            /// Loads from json.
            /// </summary>
            /// <param name="jsonProperty">The json property.</param>
            /// <param name="service">The service.</param>
            internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
            {
                base.LoadFromJson(jsonProperty, service);

                JsonObject jsonFieldUriOrConstant = jsonProperty.ReadAsJsonObject(XmlElementNames.FieldURIOrConstant).ReadAsJsonObject(XmlElementNames.Item);

                if (jsonFieldUriOrConstant.ReadTypeString() == XmlElementNames.Constant)
                {
                    this.value = jsonFieldUriOrConstant[XmlElementNames.Value];
                }
                else
                {
                    this.otherPropertyDefinition = PropertyDefinitionBase.TryLoadFromJson(jsonProperty);
                }
            }
        /// <summary>
        /// Loads the property value from json.
        /// </summary>
        /// <param name="value">The JSON value.  Can be a JsonObject, string, number, bool, array, or null.</param>
        /// <param name="service">The service.</param>
        /// <param name="propertyBag">The property bag.</param>
        internal override void LoadPropertyValueFromJson(object value, ExchangeService service, PropertyBag propertyBag)
        {
            JsonObject jsonRecurrence = value as JsonObject;

            JsonObject jsonPattern = jsonRecurrence.ReadAsJsonObject(JsonNames.RecurrencePattern);
            Recurrence recurrence  = GetRecurrenceFromString(jsonPattern.ReadTypeString());

            recurrence.LoadFromJson(jsonPattern, service);

            JsonObject      jsonRange = jsonRecurrence.ReadAsJsonObject(JsonNames.RecurrenceRange);
            RecurrenceRange range     = GetRecurrenceRange(jsonRange.ReadTypeString());

            range.LoadFromJson(jsonRange, service);

            range.SetupRecurrence(recurrence);

            propertyBag[this] = recurrence;
        }
예제 #8
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service"></param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            base.LoadFromJson(jsonProperty, service);

            if (jsonProperty.ContainsKey(XmlElementNames.Item))
            {
                JsonObject jsonItem = jsonProperty.ReadAsJsonObject(XmlElementNames.Item);

                // skip this - "Item" : null
                if (jsonItem != null)
                {
                    this.item = EwsUtilities.CreateItemFromXmlElementName(this, jsonItem.ReadTypeString());

                    if (this.item != null)
                    {
                        this.item.LoadFromJson(jsonItem, service, true /* clearPropertyBag */);
                    }
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Loads from json to update existing property.
        /// </summary>
        /// <param name="jsonCollection">The json collection.</param>
        /// <param name="service">The service.</param>
        void IJsonCollectionDeserializer.UpdateFromJsonCollection(object[] jsonCollection, ExchangeService service)
        {
            if (this.Count != jsonCollection.Length)
            {
                throw new ServiceLocalException(Strings.PropertyCollectionSizeMismatch);
            }

            int index = 0;

            foreach (object jsonObject in jsonCollection)
            {
                JsonObject jsonProperty = jsonObject as JsonObject;

                if (jsonProperty != null)
                {
                    TComplexProperty expectedComplexProperty = null;

                    if (jsonProperty.HasTypeProperty())
                    {
                        expectedComplexProperty = this.CreateComplexProperty(jsonProperty.ReadTypeString());
                    }
                    else
                    {
                        expectedComplexProperty = this.CreateDefaultComplexProperty();
                    }

                    TComplexProperty actualComplexProperty = this[index++];

                    if (expectedComplexProperty == null || !expectedComplexProperty.GetType().IsInstanceOfType(actualComplexProperty))
                    {
                        throw new ServiceLocalException(Strings.PropertyTypeIncompatibleWhenUpdatingCollection);
                    }

                    actualComplexProperty.LoadFromJson(jsonProperty, service);
                }
                else
                {
                    throw new ServiceLocalException();
                }
            }
        }
        /// <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);
            }
        }
예제 #11
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlElementNames.MeetingTime:
                    this.meetingTime = EwsUtilities.ParseAsUnbiasedDatetimescopedToServicetimeZone(jsonProperty.ReadAsString(key), service);
                    break;

                case XmlElementNames.IsWorkTime:
                    this.isWorkTime = jsonProperty.ReadAsBool(key);
                    break;

                case XmlElementNames.SuggestionQuality:
                    this.quality = jsonProperty.ReadEnumValue <SuggestionQuality>(key);
                    break;

                case XmlElementNames.AttendeeConflictDataArray:
                    object[] jsonConflictArray = jsonProperty.ReadAsArray(key);
                    foreach (object conflictObject in jsonConflictArray)
                    {
                        JsonObject jsonConflict = conflictObject as JsonObject;
                        if (jsonConflict != null)
                        {
                            Conflict conflict = null;

                            switch (jsonConflict.ReadTypeString())
                            {
                            case XmlElementNames.UnknownAttendeeConflictData:
                                conflict = new Conflict(ConflictType.UnknownAttendeeConflict);
                                break;

                            case XmlElementNames.TooBigGroupAttendeeConflictData:
                                conflict = new Conflict(ConflictType.GroupTooBigConflict);
                                break;

                            case XmlElementNames.IndividualAttendeeConflictData:
                                conflict = new Conflict(ConflictType.IndividualAttendeeConflict);
                                break;

                            case XmlElementNames.GroupAttendeeConflictData:
                                conflict = new Conflict(ConflictType.GroupConflict);
                                break;

                            default:
                                EwsUtilities.Assert(
                                    false,
                                    "TimeSuggestion.TryReadElementFromJson",
                                    string.Format("The {0} element name does not map to any AttendeeConflict descendant.", jsonConflict.ReadTypeString()));

                                // The following line to please the compiler
                                break;
                            }

                            conflict.LoadFromJson(jsonConflict, service);

                            this.conflicts.Add(conflict);
                        }
                    }

                    break;

                default:
                    break;
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            this.Changes.SyncState            = responseObject.ReadAsString(XmlElementNames.SyncState);
            this.Changes.MoreChangesAvailable = !responseObject.ReadAsBool(this.GetIncludesLastInRangeXmlElementName());

            JsonObject changesElement = responseObject.ReadAsJsonObject(XmlElementNames.Changes);

            foreach (object changeElement in changesElement.ReadAsArray(XmlElementNames.Changes))
            {
                JsonObject jsonChange = changeElement as JsonObject;

                TChange change = this.CreateChangeInstance();

                string changeType = jsonChange.ReadAsString(XmlElementNames.ChangeType);

                switch (changeType)
                {
                case XmlElementNames.Create:
                    change.ChangeType = ChangeType.Create;
                    break;

                case XmlElementNames.Update:
                    change.ChangeType = ChangeType.Update;
                    break;

                case XmlElementNames.Delete:
                    change.ChangeType = ChangeType.Delete;
                    break;

                case XmlElementNames.ReadFlagChange:
                    change.ChangeType = ChangeType.ReadFlagChange;
                    break;

                default:
                    break;
                }

                if (change != null)
                {
                    switch (change.ChangeType)
                    {
                    case ChangeType.Delete:
                    case ChangeType.ReadFlagChange:
                        change.Id = change.CreateId();
                        JsonObject jsonChangeId = jsonChange.ReadAsJsonObject(this.GetChangeIdElementName());
                        change.Id.LoadFromJson(jsonChangeId, service);

                        if (change.ChangeType == ChangeType.ReadFlagChange)
                        {
                            ItemChange itemChange = change as ItemChange;

                            EwsUtilities.Assert(
                                itemChange != null,
                                "SyncResponse.ReadElementsFromJson",
                                "ReadFlagChange is only valid on ItemChange");

                            itemChange.IsRead = jsonChange.ReadAsBool(XmlElementNames.IsRead);
                        }

                        break;

                    default:
                        JsonObject jsonServiceObject = jsonChange.ReadAsJsonObject(this.GetChangeElementName());
                        change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>(service, jsonServiceObject.ReadTypeString());

                        change.ServiceObject.LoadFromJson(
                            jsonServiceObject,
                            service,
                            true,                         /* clearPropertyBag */
                            this.propertySet,
                            this.SummaryPropertiesOnly);
                        break;
                    }

                    this.changes.Add(change);
                }
            }
        }
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            base.LoadFromJson(jsonProperty, service);

            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlAttributeNames.Id:
                    this.id = jsonProperty.ReadAsString(key);
                    break;

                case XmlElementNames.Transition:

                    foreach (object uncastJsonTransition in jsonProperty.ReadAsArray(key))
                    {
                        JsonObject         jsonTransition = uncastJsonTransition as JsonObject;
                        TimeZoneTransition transition     = TimeZoneTransition.Create(this.timeZoneDefinition, jsonTransition.ReadTypeString());

                        transition.LoadFromJson(jsonTransition, service);

                        this.transitions.Add(transition);
                    }
                    break;
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            base.LoadFromJson(jsonProperty, service);

            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlAttributeNames.Name:
                    this.name = jsonProperty.ReadAsString(key);
                    break;

                case XmlAttributeNames.Id:
                    this.id = jsonProperty.ReadAsString(key);
                    break;

                case XmlElementNames.Periods:
                    foreach (object jsonPeriod in jsonProperty.ReadAsArray(key))
                    {
                        TimeZonePeriod period = new TimeZonePeriod();
                        period.LoadFromJson(jsonPeriod as JsonObject, service);

                        this.periods.Add(period.Id, period);
                    }

                    break;

                case XmlElementNames.TransitionsGroups:
                    foreach (object arrayOfTransitionsTypeInstance in jsonProperty.ReadAsArray(key))
                    {
                        TimeZoneTransitionGroup transitionGroup = new TimeZoneTransitionGroup(this);
                        transitionGroup.LoadFromJson(arrayOfTransitionsTypeInstance as JsonObject, service);

                        this.transitionGroups.Add(transitionGroup.Id, transitionGroup);
                    }

                    break;

                case XmlElementNames.Transitions:
                    JsonObject arrayOfTransitionsType = jsonProperty.ReadAsJsonObject(key);

                    foreach (object uncastJsonTransition in arrayOfTransitionsType.ReadAsArray(XmlElementNames.Transition))
                    {
                        JsonObject         jsonTransition = uncastJsonTransition as JsonObject;
                        TimeZoneTransition transition     = TimeZoneTransition.Create(this, jsonTransition.ReadTypeString());

                        transition.LoadFromJson(jsonTransition, service);

                        this.transitions.Add(transition);
                    }

                    break;

                default:
                    break;
                }
            }

            // EWS can return a TimeZone definition with no Id. Generate a new Id in this case.
            if (string.IsNullOrEmpty(this.id))
            {
                string nameValue = string.IsNullOrEmpty(this.Name) ? string.Empty : this.Name;
                this.Id = NoIdPrefix + Math.Abs(nameValue.GetHashCode()).ToString();
            }

            this.transitions.Sort(this.CompareTransitions);
        }
예제 #15
0
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="jsonProperty">The json property.</param>
        /// <param name="service">The service.</param>
        internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            base.LoadFromJson(jsonProperty, service);

            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlAttributeNames.Name:
                    this.name = jsonProperty.ReadAsString(key);
                    break;

                case XmlAttributeNames.Id:
                    this.id = jsonProperty.ReadAsString(key);
                    break;

                case XmlElementNames.Periods:
                    foreach (object jsonPeriod in jsonProperty.ReadAsArray(key))
                    {
                        TimeZonePeriod period = new TimeZonePeriod();
                        period.LoadFromJson(jsonPeriod as JsonObject, service);

                        // OM:1648848 Bad timezone data from clients can include duplicate rules
                        // for one year, with duplicate ID. In that case, let the first one win.
                        if (!this.periods.ContainsKey(period.Id))
                        {
                            this.periods.Add(period.Id, period);
                        }
                        else
                        {
                            service.TraceMessage(
                                TraceFlags.EwsTimeZones,
                                string.Format(
                                    "An entry with the same key (Id) '{0}' already exists in Periods. Cannot add another one. Existing entry: [Name='{1}', Bias='{2}']. Entry to skip: [Name='{3}', Bias='{4}'].",
                                    period.Id,
                                    this.Periods[period.Id].Name,
                                    this.Periods[period.Id].Bias,
                                    period.Name,
                                    period.Bias));
                        }
                    }

                    break;

                case XmlElementNames.TransitionsGroups:
                    foreach (object arrayOfTransitionsTypeInstance in jsonProperty.ReadAsArray(key))
                    {
                        TimeZoneTransitionGroup transitionGroup = new TimeZoneTransitionGroup(this);
                        transitionGroup.LoadFromJson(arrayOfTransitionsTypeInstance as JsonObject, service);

                        this.transitionGroups.Add(transitionGroup.Id, transitionGroup);
                    }

                    break;

                case XmlElementNames.Transitions:
                    JsonObject arrayOfTransitionsType = jsonProperty.ReadAsJsonObject(key);

                    foreach (object uncastJsonTransition in arrayOfTransitionsType.ReadAsArray(XmlElementNames.Transition))
                    {
                        JsonObject         jsonTransition = uncastJsonTransition as JsonObject;
                        TimeZoneTransition transition     = TimeZoneTransition.Create(this, jsonTransition.ReadTypeString());

                        transition.LoadFromJson(jsonTransition, service);

                        this.transitions.Add(transition);
                    }

                    break;

                default:
                    break;
                }
            }

            // EWS can return a TimeZone definition with no Id. Generate a new Id in this case.
            if (string.IsNullOrEmpty(this.id))
            {
                string nameValue = string.IsNullOrEmpty(this.Name) ? string.Empty : this.Name;
                this.Id = NoIdPrefix + Math.Abs(nameValue.GetHashCode()).ToString();
            }

            this.transitions.Sort(this.CompareTransitions);
        }