/// <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)
        {
            EwsUtilities.Assert(
                this.Results.Conversations != null,
                "FindConversationResponse.ReadElementsFromXml",
                "conversations is null.");

            EwsUtilities.Assert(
                this.Results.HighlightTerms != null,
                "FindConversationResponse.ReadElementsFromXml",
                "highlightTerms is null.");

            foreach (object conversationObject in responseObject.ReadAsArray(XmlElementNames.Conversations))
            {
                JsonObject jsonConversation = conversationObject as JsonObject;

                Conversation item = EwsUtilities.CreateEwsObjectFromXmlElementName <Conversation>(service, XmlElementNames.Conversation);

                if (item != null)
                {
                    item.LoadFromJson(
                        jsonConversation,
                        service,
                        true,
                        null,
                        false);

                    this.Conversations.Add(item);
                }
            }

            Object[] highlightTermObjects = responseObject.ReadAsArray(XmlElementNames.HighlightTerms);
            if (highlightTermObjects != null)
            {
                foreach (object highlightTermObject in highlightTermObjects)
                {
                    JsonObject    jsonHighlightTerm = highlightTermObject as JsonObject;
                    HighlightTerm term = new HighlightTerm();

                    term.LoadFromJson(jsonHighlightTerm, service);
                    this.Results.HighlightTerms.Add(term);
                }
            }

            if (responseObject.ContainsKey(XmlElementNames.TotalConversationsInView))
            {
                this.Results.TotalCount = responseObject.ReadAsInt(XmlElementNames.TotalConversationsInView);
            }

            if (responseObject.ContainsKey(XmlElementNames.IndexedOffset))
            {
                this.Results.IndexedOffset = responseObject.ReadAsInt(XmlElementNames.IndexedOffset);
            }
        }
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="eventsResponse">The events response.</param>
        /// <param name="service">The service.</param>
        internal void LoadFromJson(JsonObject eventsResponse, ExchangeService service)
        {
            foreach (string key in eventsResponse.Keys)
            {
                switch (key)
                {
                case XmlElementNames.SubscriptionId:
                    this.subscriptionId = eventsResponse.ReadAsString(key);
                    break;

                case XmlElementNames.PreviousWatermark:
                    this.previousWatermark = eventsResponse.ReadAsString(key);
                    break;

                case XmlElementNames.MoreEvents:
                    this.moreEventsAvailable = eventsResponse.ReadAsBool(key);
                    break;

                case JsonNames.Events:
                    this.LoadEventsFromJson(eventsResponse.ReadAsArray(key), service);
                    break;

                default:
                    break;
                }
            }
        }
Exemple #3
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)
        {
            object[] attachmentsArray;
            if (responseObject.ContainsKey(XmlElementNames.Attachments) &&
                (attachmentsArray = responseObject.ReadAsArray(XmlElementNames.Attachments)).Length > 0)
            {
                JsonObject attachmentArrayJsonObject = attachmentsArray[0] as JsonObject;

                if (this.attachment == null && attachmentArrayJsonObject != null)
                {
                    if (attachmentArrayJsonObject.ContainsKey(XmlElementNames.FileAttachment))
                    {
                        this.attachment = new FileAttachment(service);
                    }
                    else if (attachmentArrayJsonObject.ContainsKey(XmlElementNames.ItemAttachment))
                    {
                        this.attachment = new ItemAttachment(service);
                    }
                }

                if (this.attachment != null)
                {
                    this.attachment.LoadFromJson(attachmentArrayJsonObject, service);
                }
            }
        }
Exemple #4
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.UserOptions:
                    Object[] votingOptionObjects = jsonProperty.ReadAsArray(XmlElementNames.UserOptions);
                    if (votingOptionObjects != null)
                    {
                        foreach (object votingOptionObject in votingOptionObjects)
                        {
                            JsonObject       jsonObject = votingOptionObject as JsonObject;
                            VotingOptionData option     = new VotingOptionData();

                            option.LoadFromJson(jsonObject, service);
                            this.userOptions.Add(option);
                        }
                    }
                    break;

                case XmlElementNames.VotingResponse:
                    this.votingResponse = jsonProperty.ReadAsString(key);
                    break;

                default:
                    break;
                }
            }
        }
        /// <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;
                }
            }
        }
            /// <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)
            {
                object[] filterArray = jsonProperty.ReadAsArray(XmlElementNames.Item);

                foreach (object filter in filterArray)
                {
                    this.Add(SearchFilter.LoadSearchFilterFromJson(filter as JsonObject, service));
                }
            }
Exemple #7
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)
        {
            object[] attachmentArray = responseObject.ReadAsArray(XmlElementNames.Attachments);

            if (attachmentArray != null && attachmentArray.Length > 0)
            {
                this.attachment.LoadFromJson(attachmentArray[0] as JsonObject, service);
            }
        }
        /// <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)
        {
            object[] jsonFolderPermissions = jsonProperty.ReadAsArray(this.InnerCollectionXmlElementName);

            foreach (object jsonFolderPermission in jsonFolderPermissions)
            {
                FolderPermission permission = new FolderPermission();
                permission.LoadFromJson(jsonFolderPermission as JsonObject, service);
                this.InternalAdd(permission);
            }

            object[] jsonUnknownEntries = jsonProperty.ReadAsArray(XmlElementNames.UnknownEntries);

            foreach (object jsonUnknownEntry in jsonUnknownEntries)
            {
                this.unknownEntries.Add(jsonUnknownEntry as string);
            }
        }
        /// <summary>
        /// Gets the dictionary object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        private object GetDictionaryObject(JsonObject jsonObject, ExchangeService service)
        {
            if (jsonObject == null)
            {
                return(null);
            }

            UserConfigurationDictionaryObjectType type = GetObjectType(jsonObject.ReadAsString(XmlElementNames.Type));

            List <string> values = this.GetObjectValue(jsonObject.ReadAsArray(XmlElementNames.Value));

            return(this.ConstructObject(type, values, service));
        }
Exemple #10
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)
        {
            this.date    = DateTime.Parse(jsonProperty.ReadAsString(XmlElementNames.Date));
            this.quality = jsonProperty.ReadEnumValue <SuggestionQuality>(XmlElementNames.DayQuality);

            foreach (object jsonSuggestion in jsonProperty.ReadAsArray(XmlElementNames.SuggestionArray))
            {
                TimeSuggestion timeSuggestion = new TimeSuggestion();

                timeSuggestion.LoadFromJson(jsonSuggestion as JsonObject, service);

                this.timeSuggestions.Add(timeSuggestion);
            }
        }
        /// <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)
        {
            this.ConversationId = new ConversationId();
            this.ConversationId.LoadFromJson(jsonProperty.ReadAsJsonObject(XmlElementNames.ConversationId), service);

            if (jsonProperty.ContainsKey(XmlElementNames.SyncState))
            {
                this.SyncState = jsonProperty.ReadAsString(XmlElementNames.SyncState);
            }

            this.ConversationNodes = new ConversationNodeCollection(this.propertySet);
            ((IJsonCollectionDeserializer)this.ConversationNodes).CreateFromJsonCollection(
                jsonProperty.ReadAsArray(XmlElementNames.ConversationNodes),
                service);
        }
        /// <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.configurations.Clear();

            base.ReadElementsFromJson(responseObject, service);

            if (responseObject.ContainsKey(XmlElementNames.DiscoverySearchConfigurations))
            {
                foreach (object searchConfiguration in responseObject.ReadAsArray(XmlElementNames.DiscoverySearchConfigurations))
                {
                    JsonObject jsonSearchConfiguration = searchConfiguration as JsonObject;
                    this.configurations.Add(DiscoverySearchConfiguration.LoadFromJson(jsonSearchConfiguration));
                }
            }
        }
Exemple #13
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.searchableMailboxes.Clear();

            base.ReadElementsFromJson(responseObject, service);

            if (responseObject.ContainsKey(XmlElementNames.SearchMailboxes))
            {
                foreach (object searchableMailboxObject in responseObject.ReadAsArray(XmlElementNames.SearchableMailboxes))
                {
                    JsonObject jsonSearchableMailbox = searchableMailboxObject as JsonObject;
                    this.searchableMailboxes.Add(SearchableMailbox.LoadFromJson(jsonSearchableMailbox));
                }
            }
        }
        /// <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.retentionPolicyTags.Clear();

            base.ReadElementsFromJson(responseObject, service);

            if (responseObject.ContainsKey(XmlElementNames.RetentionPolicyTags))
            {
                foreach (object retentionPolicyTagObject in responseObject.ReadAsArray(XmlElementNames.RetentionPolicyTags))
                {
                    JsonObject jsonRetentionPolicyTag = retentionPolicyTagObject as JsonObject;
                    this.retentionPolicyTags.Add(RetentionPolicyTag.LoadFromJson(jsonRetentionPolicyTag));
                }
            }
        }
        /// <summary>
        /// Load from json
        /// </summary>
        /// <param name="jsonObject">The json object</param>
        /// <returns>Mailbox hold object</returns>
        internal static MailboxHoldResult LoadFromJson(JsonObject jsonObject)
        {
            List <MailboxHoldStatus> statuses   = new List <MailboxHoldStatus>();
            MailboxHoldResult        holdResult = new MailboxHoldResult();

            if (jsonObject.ContainsKey(XmlElementNames.HoldId))
            {
                holdResult.HoldId = jsonObject.ReadAsString(XmlElementNames.HoldId);
            }

            if (jsonObject.ContainsKey(XmlElementNames.Query))
            {
                holdResult.Query = jsonObject.ReadAsString(XmlElementNames.Query);
            }

            if (jsonObject.ContainsKey(XmlElementNames.Statuses))
            {
                foreach (object statusObject in jsonObject.ReadAsArray(XmlElementNames.Statuses))
                {
                    MailboxHoldStatus status     = new MailboxHoldStatus();
                    JsonObject        jsonStatus = statusObject as JsonObject;

                    if (jsonStatus.ContainsKey(XmlElementNames.Mailbox))
                    {
                        status.Mailbox = jsonStatus.ReadAsString(XmlElementNames.Mailbox);
                    }

                    if (jsonStatus.ContainsKey(XmlElementNames.Status))
                    {
                        status.Status = (HoldStatus)Enum.Parse(typeof(HoldStatus), jsonStatus.ReadAsString(XmlElementNames.Status));
                    }

                    if (jsonStatus.ContainsKey(XmlElementNames.AdditionalInfo))
                    {
                        status.AdditionalInfo = jsonStatus.ReadAsString(XmlElementNames.AdditionalInfo);
                    }

                    statuses.Add(status);
                }
            }

            holdResult.Statuses = statuses.Count == 0 ? null : statuses.ToArray();

            return(holdResult);
        }
        /// <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);
        }
Exemple #17
0
        /// <summary>
        /// Load from json
        /// </summary>
        /// <param name="jsonObject">The json object</param>
        /// <returns>Discovery search configuration object</returns>
        internal static DiscoverySearchConfiguration LoadFromJson(JsonObject jsonObject)
        {
            List <SearchableMailbox>     mailboxes     = new List <SearchableMailbox>();
            DiscoverySearchConfiguration configuration = new DiscoverySearchConfiguration();

            if (jsonObject.ContainsKey(XmlElementNames.SearchId))
            {
                configuration.SearchId = jsonObject.ReadAsString(XmlElementNames.SearchId);
            }

            if (jsonObject.ContainsKey(XmlElementNames.InPlaceHoldIdentity))
            {
                configuration.InPlaceHoldIdentity = jsonObject.ReadAsString(XmlElementNames.InPlaceHoldIdentity);
            }

            if (jsonObject.ContainsKey(XmlElementNames.ManagedByOrganization))
            {
                configuration.ManagedByOrganization = jsonObject.ReadAsString(XmlElementNames.ManagedByOrganization);
            }

            if (jsonObject.ContainsKey(XmlElementNames.SearchQuery))
            {
                configuration.SearchQuery = jsonObject.ReadAsString(XmlElementNames.SearchQuery);
            }

            if (jsonObject.ContainsKey(XmlElementNames.SearchableMailboxes))
            {
                foreach (object searchableMailboxObject in jsonObject.ReadAsArray(XmlElementNames.SearchableMailboxes))
                {
                    JsonObject jsonSearchableMailbox = searchableMailboxObject as JsonObject;

                    mailboxes.Add(SearchableMailbox.LoadFromJson(jsonSearchableMailbox));
                }
            }

            if (jsonObject.ContainsKey(XmlElementNames.Language))
            {
                configuration.Language = jsonObject.ReadAsString(XmlElementNames.Language);
            }

            configuration.SearchableMailboxes = mailboxes.Count == 0 ? null : mailboxes.ToArray();

            return(configuration);
        }
        /// <summary>
        /// Loads from json array.
        /// </summary>
        /// <param name="jsonProperty">The p.</param>
        /// <param name="service">The service.</param>
        internal void LoadFromJson(JsonObject jsonProperty, ExchangeService service)
        {
            int totalItemsInView;

            object[] resolutions;

            foreach (string key in jsonProperty.Keys)
            {
                switch (key)
                {
                case XmlAttributeNames.TotalItemsInView:
                    totalItemsInView = jsonProperty.ReadAsInt(key);
                    break;

                case XmlAttributeNames.IncludesLastItemInRange:
                    this.includesAllResolutions = jsonProperty.ReadAsBool(key);
                    break;

                // This label only exists for Json objects.  The XML doesn't have a "Resolutions"
                // element.
                // This was necessary becaue of the lack of attributes in JSON
                //
                case "Resolutions":
                    resolutions = jsonProperty.ReadAsArray(key);
                    foreach (object resolution in resolutions)
                    {
                        JsonObject resolutionProperty = resolution as JsonObject;
                        if (resolutionProperty != null)
                        {
                            NameResolution nameResolution = new NameResolution(this);
                            nameResolution.LoadFromJson(resolutionProperty, service);
                            this.items.Add(nameResolution);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemple #19
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);
        }
Exemple #20
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;
                }
            }
        }
        /// <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);
                }
            }
        }
Exemple #22
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)
        {
            base.ReadElementsFromJson(responseObject, service);

            JsonObject rootFolder         = responseObject.ReadAsJsonObject(XmlElementNames.RootFolder);
            int        totalItemsInView   = rootFolder.ReadAsInt(XmlAttributeNames.TotalItemsInView);
            bool       moreItemsAvailable = !rootFolder.ReadAsBool(XmlAttributeNames.IncludesLastItemInRange);

            // Ignore IndexedPagingOffset attribute if moreItemsAvailable is false.
            int?nextPageOffset = null;

            if (moreItemsAvailable)
            {
                if (rootFolder.ContainsKey(XmlAttributeNames.IndexedPagingOffset))
                {
                    nextPageOffset = rootFolder.ReadAsInt(XmlAttributeNames.IndexedPagingOffset);
                }
            }

            if (!this.isGrouped)
            {
                this.results                = new FindItemsResults <TItem>();
                this.results.TotalCount     = totalItemsInView;
                this.results.NextPageOffset = nextPageOffset;
                this.results.MoreAvailable  = moreItemsAvailable;
                this.InternalReadItemsFromJson(
                    rootFolder,
                    this.propertySet,
                    service,
                    this.results.Items);
            }
            else
            {
                this.groupedFindResults                = new GroupedFindItemsResults <TItem>();
                this.groupedFindResults.TotalCount     = totalItemsInView;
                this.groupedFindResults.NextPageOffset = nextPageOffset;
                this.groupedFindResults.MoreAvailable  = moreItemsAvailable;

                if (rootFolder.ContainsKey(XmlElementNames.Groups))
                {
                    object[] jsGroups = rootFolder.ReadAsArray(XmlElementNames.Groups);

                    foreach (JsonObject jsGroup in jsGroups.OfType <JsonObject>())
                    {
                        if (jsGroup.ContainsKey(XmlElementNames.GroupedItems))
                        {
                            JsonObject jsGroupedItems = jsGroup.ReadAsJsonObject(XmlElementNames.GroupedItems);

                            string groupIndex = jsGroupedItems.ReadAsString(XmlElementNames.GroupIndex);

                            List <TItem> itemList = new List <TItem>();
                            this.InternalReadItemsFromJson(
                                jsGroupedItems,
                                this.propertySet,
                                service,
                                itemList);

                            this.groupedFindResults.ItemGroups.Add(new ItemGroup <TItem>(groupIndex, itemList));
                        }
                    }
                }
            }

            Object[] highlightTermObjects = responseObject.ReadAsArray(XmlElementNames.HighlightTerms);
            if (highlightTermObjects != null)
            {
                foreach (object highlightTermObject in highlightTermObjects)
                {
                    JsonObject    jsonHighlightTerm = highlightTermObject as JsonObject;
                    HighlightTerm term = new HighlightTerm();

                    term.LoadFromJson(jsonHighlightTerm, service);
                    this.results.HighlightTerms.Add(term);
                }
            }
        }
        /// <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.TimeZone:
                    LegacyAvailabilityTimeZone legacyTimeZone = new LegacyAvailabilityTimeZone();
                    legacyTimeZone.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service);

                    this.timeZone = legacyTimeZone.ToTimeZoneInfo();

                    break;

                case XmlElementNames.WorkingPeriodArray:
                    List <WorkingPeriod> workingPeriods = new List <WorkingPeriod>();

                    object[] workingPeriodsArray = jsonProperty.ReadAsArray(key);

                    foreach (object workingPeriodEntry in workingPeriodsArray)
                    {
                        JsonObject jsonWorkingPeriodEntry = workingPeriodEntry as JsonObject;

                        if (jsonWorkingPeriodEntry != null)
                        {
                            WorkingPeriod workingPeriod = new WorkingPeriod();

                            workingPeriod.LoadFromJson(jsonWorkingPeriodEntry, service);

                            workingPeriods.Add(workingPeriod);
                        }
                    }

                    // Availability supports a structure that can technically represent different working
                    // times for each day of the week. This is apparently how the information is stored in
                    // Exchange. However, no client (Outlook, OWA) either will let you specify different
                    // working times for each day of the week, and Outlook won't either honor that complex
                    // structure if it happens to be in Exchange.
                    // So here we'll do what Outlook and OWA do: we'll use the start and end times of the
                    // first working period, but we'll use the week days of all the periods.
                    this.startTime = workingPeriods[0].StartTime;
                    this.endTime   = workingPeriods[0].EndTime;

                    foreach (WorkingPeriod workingPeriod in workingPeriods)
                    {
                        foreach (DayOfTheWeek dayOfWeek in workingPeriods[0].DaysOfWeek)
                        {
                            if (!this.daysOfTheWeek.Contains(dayOfWeek))
                            {
                                this.daysOfTheWeek.Add(dayOfWeek);
                            }
                        }
                    }

                    break;

                default:
                    break;
                }
            }
        }
        /// <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);
        }
        /// <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.ExtendedFieldURI:
                    this.propertyDefinition = new ExtendedPropertyDefinition();
                    this.propertyDefinition.LoadFromJson(jsonProperty.ReadAsJsonObject(key));
                    break;

                case XmlElementNames.Value:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    string stringValue = jsonProperty.ReadAsString(key);
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringValue);
                    break;

                case XmlElementNames.Values:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    StringList stringList = new StringList(XmlElementNames.Value);
                    ((IJsonCollectionDeserializer)stringList).CreateFromJsonCollection(jsonProperty.ReadAsArray(key), service);
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringList);
                    break;

                default:
                    break;
                }
            }
        }
Exemple #26
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)
        {
            if (jsonProperty.ContainsKey(XmlElementNames.OperationIndex))
            {
                this.operationIndex = jsonProperty.ReadAsInt(XmlElementNames.OperationIndex);
            }

            if (jsonProperty.ContainsKey(XmlElementNames.ValidationErrors))
            {
                this.ruleErrors = new RuleErrorCollection();
                (this.ruleErrors as IJsonCollectionDeserializer).CreateFromJsonCollection(jsonProperty.ReadAsArray(XmlElementNames.ValidationErrors), service);
            }
        }
        /// <summary>
        /// Loads from json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal void LoadFromJson(JsonObject responseObject, ExchangeService service)
        {
            foreach (string key in responseObject.Keys)
            {
                switch (key)
                {
                case XmlElementNames.UserConfigurationName:
                    JsonObject jsonUserConfigName = responseObject.ReadAsJsonObject(key);
                    string     responseName       = jsonUserConfigName.ReadAsString(XmlAttributeNames.Name);

                    EwsUtilities.Assert(
                        string.Compare(this.name, responseName, StringComparison.Ordinal) == 0,
                        "UserConfiguration.LoadFromJson",
                        "UserConfigurationName does not match: Expected: " + this.name + " Name in response: " + responseName);

                    break;

                case XmlElementNames.ItemId:
                    this.itemId = new ItemId();
                    this.itemId.LoadFromJson(responseObject.ReadAsJsonObject(key), service);
                    break;

                case XmlElementNames.Dictionary:
                    ((IJsonCollectionDeserializer)this.dictionary).CreateFromJsonCollection(responseObject.ReadAsArray(key), service);
                    break;

                case XmlElementNames.XmlData:
                    this.xmlData = Convert.FromBase64String(responseObject.ReadAsString(key));
                    break;

                case XmlElementNames.BinaryData:
                    this.binaryData = Convert.FromBase64String(responseObject.ReadAsString(key));
                    break;

                default:
                    break;
                }
            }
        }