コード例 #1
0
        // Token: 0x0600184D RID: 6221 RVA: 0x0008E8B4 File Offset: 0x0008CAB4
        private static bool ParseSupportedTags(int version, List <TagNode> tags, StoreObjectType type)
        {
            if (tags.Count == 0 || version < 21)
            {
                return(true);
            }
            Dictionary <string, bool> dictionary = new Dictionary <string, bool>(tags.Count);

            foreach (TagNode tagNode in tags)
            {
                if (tagNode.NameSpace == 2)
                {
                    tagNode.NameSpace = 1;
                }
                else
                {
                    if (tagNode.NameSpace != 3)
                    {
                        return(false);
                    }
                    tagNode.NameSpace = 4;
                }
                int    tag  = (int)tagNode.NameSpace << 8 | (int)(tagNode.Tag + 4);
                string name = TiSyncUpgrade.wbxmlSchema.GetName(tag);
                dictionary.Add(name, false);
            }
            IAirSyncVersionFactory airSyncVersionFactory = AirSyncProtocolVersionParserBuilder.FromVersion(version);
            AirSyncSchemaState     airSyncSchemaState;

            switch (type)
            {
            case StoreObjectType.Folder:
                airSyncSchemaState = airSyncVersionFactory.CreateEmailSchema(null);
                break;

            case StoreObjectType.CalendarFolder:
                airSyncSchemaState = airSyncVersionFactory.CreateCalendarSchema();
                break;

            case StoreObjectType.ContactsFolder:
                airSyncSchemaState = airSyncVersionFactory.CreateContactsSchema();
                break;

            case StoreObjectType.TasksFolder:
                airSyncSchemaState = airSyncVersionFactory.CreateTasksSchema();
                break;

            default:
                return(false);
            }
            AirSyncSetToDefaultStrategy airSyncSetToDefaultStrategy = new AirSyncSetToDefaultStrategy(dictionary);
            AirSyncDataObject           airSyncDataObject           = airSyncSchemaState.GetAirSyncDataObject(new Hashtable(), airSyncSetToDefaultStrategy);

            try
            {
                airSyncSetToDefaultStrategy.Validate(airSyncDataObject);
            }
            catch (ConversionException)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        // Token: 0x06000C40 RID: 3136 RVA: 0x000404C0 File Offset: 0x0003E6C0
        public void BuildResponse(XmlNode responseNode)
        {
            XmlNode xmlNode  = responseNode.OwnerDocument.CreateElement("Fetch", "ItemOperations:");
            XmlNode xmlNode2 = responseNode.OwnerDocument.CreateElement("Status", "ItemOperations:");
            XmlNode xmlNode3 = responseNode.OwnerDocument.CreateElement("Class", "AirSync:");
            XmlNode xmlNode4 = responseNode.OwnerDocument.CreateElement("Properties", "ItemOperations:");
            XmlNode xmlNode5 = responseNode.OwnerDocument.CreateElement("ServerId", "AirSync:");
            XmlNode xmlNode6 = responseNode.OwnerDocument.CreateElement("CollectionId", "AirSync:");
            XmlNode xmlNode7 = responseNode.OwnerDocument.CreateElement("LongId", "Search:");
            FlexibleSchemaStrategy missingPropertyStrategy = new FlexibleSchemaStrategy(this.schemaTags);

            this.schemaConverterOptions["BodyPreference"]     = this.bodyPreferences;
            this.schemaConverterOptions["BodyPartPreference"] = this.bodyPartPreferences;
            this.schemaConverterOptions["MIMESupport"]        = this.mimeSupport;
            bool flag = false;

            try
            {
                using (Item item = Item.Bind(this.mailboxSession, this.storeObjectId))
                {
                    if (this.removeRightsManagementProtection)
                    {
                        this.IrmRemoveRestriction(item);
                    }
                    if (this.bodyPartPreferences != null && this.bodyPartPreferences.Count > 0)
                    {
                        ConversationId valueOrDefault = item.GetValueOrDefault <ConversationId>(ItemSchema.ConversationId, null);
                        if (valueOrDefault != null)
                        {
                            Conversation conversation;
                            Command.CurrentCommand.GetOrCreateConversation(valueOrDefault, true, out conversation);
                            conversation.LoadItemParts(new List <StoreObjectId>
                            {
                                item.StoreObjectId
                            });
                        }
                    }
                    foreach (KeyValuePair <string, AirSyncSchemaState> keyValuePair in this.schemaStates)
                    {
                        AirSyncSchemaState       value = keyValuePair.Value;
                        AirSyncXsoSchemaState    airSyncXsoSchemaState    = value as AirSyncXsoSchemaState;
                        AirSyncEntitySchemaState airSyncEntitySchemaState = value as AirSyncEntitySchemaState;
                        IServerDataObject        serverDataObject;
                        if (airSyncXsoSchemaState != null)
                        {
                            serverDataObject = airSyncXsoSchemaState.GetXsoDataObject();
                        }
                        else
                        {
                            if (airSyncEntitySchemaState == null)
                            {
                                throw new NotImplementedException(string.Format("Schema state for \"{0}\" is not implemented yet.", keyValuePair.Key));
                            }
                            serverDataObject = airSyncEntitySchemaState.GetEntityDataObject();
                        }
                        if (serverDataObject.CanConvertItemClassUsingCurrentSchema(item.ClassName))
                        {
                            AirSyncDataObject airSyncDataObject = value.GetAirSyncDataObject(this.schemaConverterOptions, missingPropertyStrategy);
                            if (this.rightsManagementSupport)
                            {
                                Command.CurrentCommand.DecodeIrmMessage(item, true);
                            }
                            item.Load(serverDataObject.GetPrefetchProperties());
                            try
                            {
                                serverDataObject.Bind(item);
                                airSyncDataObject.Bind(xmlNode4);
                                airSyncDataObject.CopyFrom(serverDataObject);
                            }
                            finally
                            {
                                airSyncDataObject.Unbind();
                                serverDataObject.Unbind();
                            }
                            if (this.rightsManagementSupport)
                            {
                                Command.CurrentCommand.SaveLicense(item);
                            }
                            xmlNode3.InnerText = keyValuePair.Key;
                            flag = true;
                            break;
                        }
                    }
                }
            }
            catch (ObjectNotFoundException innerException)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException, false)
                      {
                          ErrorStringForProtocolLogger = "NotFoundInMbxFetch"
                      };
            }
            catch (AirSyncPermanentException)
            {
                throw;
            }
            catch (Exception ex)
            {
                if (!SyncCommand.IsItemSyncTolerableException(ex))
                {
                    throw;
                }
                AirSyncDiagnostics.TraceError <Exception>(ExTraceGlobals.ConversionTracer, this, "Sync-tolerable Item conversion Exception was thrown. Location BuildResponse(). {0}", ex);
            }
            if (!flag)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidWaitTime, false)
                      {
                          ErrorStringForProtocolLogger = "ConvertErrorInMbxFetch"
                      };
            }
            xmlNode2.InnerText = 1.ToString(CultureInfo.InvariantCulture);
            xmlNode.AppendChild(xmlNode2);
            if (this.longId != null)
            {
                xmlNode7.InnerText = this.longId;
                xmlNode.AppendChild(xmlNode7);
            }
            else
            {
                xmlNode6.InnerText = this.collectionId;
                xmlNode.AppendChild(xmlNode6);
                xmlNode5.InnerText = this.serverId;
                xmlNode.AppendChild(xmlNode5);
            }
            xmlNode.AppendChild(xmlNode3);
            xmlNode.AppendChild(xmlNode4);
            if (this.multiPartResponse)
            {
                XmlNode xmlNode8 = xmlNode4["Body"];
                if (xmlNode8 != null)
                {
                    XmlNode            xmlNode9           = xmlNode8["Data"];
                    AirSyncBlobXmlNode airSyncBlobXmlNode = xmlNode9 as AirSyncBlobXmlNode;
                    if (xmlNode9 != null && (!string.IsNullOrEmpty(xmlNode9.InnerText) || (airSyncBlobXmlNode != null && airSyncBlobXmlNode.Stream != null)))
                    {
                        XmlNode xmlNode10 = responseNode.OwnerDocument.CreateElement("Part", "ItemOperations:");
                        xmlNode10.InnerText = this.partNumber.ToString(CultureInfo.InvariantCulture);
                        xmlNode8.ReplaceChild(xmlNode10, xmlNode9);
                        if (airSyncBlobXmlNode != null && airSyncBlobXmlNode.Stream != null)
                        {
                            this.outStream = airSyncBlobXmlNode.Stream;
                            if (airSyncBlobXmlNode.Stream is AirSyncStream)
                            {
                                this.delayStreamDispose = true;
                            }
                            AirSyncDiagnostics.TraceError <Type>(ExTraceGlobals.ConversionTracer, this, "blobNode.Stream is of {0} type.", airSyncBlobXmlNode.Stream.GetType());
                        }
                        else
                        {
                            UTF8Encoding utf8Encoding = new UTF8Encoding();
                            this.outStream = new MemoryStream(utf8Encoding.GetBytes(xmlNode9.InnerText));
                        }
                    }
                }
            }
            responseNode.AppendChild(xmlNode);
        }
コード例 #3
0
        public void BuildResponse(XmlElement responseNode)
        {
            MailboxSearchProvider.BuildResponseState buildResponseState = MailboxSearchProvider.BuildResponseState.Seeking;
            int  num  = -1;
            bool flag = false;

            this.totalRowCount   = 0;
            this.numberResponses = 0;
            XmlNode xmlNode = responseNode.OwnerDocument.CreateElement("Status", "Search:");

            responseNode.AppendChild(xmlNode);
            xmlNode.InnerText = 1.ToString(CultureInfo.InvariantCulture);
            foreach (MailboxSearchCriteriaBuilder.SchemaCacheItem schemaCacheItem in this.schemaCache.Values)
            {
                schemaCacheItem.SchemaState.Options.Clear();
                this.mailboxSchemaOptions.PopulateOptionsCollection(this.context.Request.DeviceIdentity.DeviceType, schemaCacheItem.SchemaState.Options);
            }
            bool flag2 = false;
            int  num2  = 0;
            bool hasBodyPartPreferences = this.mailboxSchemaOptions.HasBodyPartPreferences;

            if (this.queryFilter != null)
            {
                using (QueryResult queryResult = this.searchFolder.ItemQuery(ItemQueryType.None, null, this.defaultSortBy, MailboxSearchProvider.queryColumns))
                {
                    this.uncappedResultCount = queryResult.EstimatedRowCount;
                    num2 = this.uncappedResultCount;
                    while (!flag2 && num <= this.maxRange)
                    {
                        object[][] rows = queryResult.GetRows(this.maxRange + 1);
                        flag2 = (rows.Length == 0);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            StoreObjectId objectId       = (rows[i][0] as VersionedId).ObjectId;
                            string        itemClass      = rows[i][1] as string;
                            StoreObjectId parentFolderId = rows[i][2] as StoreObjectId;
                            string        innerText      = null;
                            try
                            {
                                AirSyncDataObject airSyncDataObject = null;
                                IServerDataObject serverDataObject  = null;
                                foreach (string text in this.schemaCache.Keys)
                                {
                                    MailboxSearchCriteriaBuilder.SchemaCacheItem schemaCacheItem2 = this.schemaCache[text];
                                    if (schemaCacheItem2.MailboxDataObject.CanConvertItemClassUsingCurrentSchema(itemClass))
                                    {
                                        innerText         = text;
                                        airSyncDataObject = schemaCacheItem2.AirSyncDataObject;
                                        serverDataObject  = schemaCacheItem2.MailboxDataObject;
                                        break;
                                    }
                                }
                                if (airSyncDataObject != null)
                                {
                                    if (this.searchCriteriaBuilder.DoesMatchCriteria(parentFolderId, objectId))
                                    {
                                        num++;
                                        if (MailboxSearchProvider.BuildResponseState.BuildingResponse == buildResponseState || (buildResponseState == MailboxSearchProvider.BuildResponseState.Seeking && num >= this.minRange))
                                        {
                                            buildResponseState = MailboxSearchProvider.BuildResponseState.BuildingResponse;
                                            buildResponseState = MailboxSearchProvider.BuildResponseState.BuildingResponse;
                                            Item item = null;
                                            try
                                            {
                                                item = this.BindToItemWithItemClass(objectId, itemClass, serverDataObject.GetPrefetchProperties());
                                                if (this.searchCriteriaBuilder.ExcludedFolders.Contains(item.ParentId))
                                                {
                                                    num--;
                                                }
                                                else
                                                {
                                                    XmlNode xmlNode2 = responseNode.OwnerDocument.CreateElement("Result", "Search:");
                                                    XmlNode xmlNode3 = responseNode.OwnerDocument.CreateElement("Properties", "Search:");
                                                    XmlNode xmlNode4 = responseNode.OwnerDocument.CreateElement("Class", "AirSync:");
                                                    xmlNode4.InnerText = innerText;
                                                    XmlNode xmlNode5 = responseNode.OwnerDocument.CreateElement("LongId", "Search:");
                                                    XmlNode xmlNode6 = responseNode.OwnerDocument.CreateElement("CollectionId", "AirSync:");
                                                    xmlNode5.InnerText = HttpUtility.UrlEncode(item.Id.ObjectId.ToBase64String());
                                                    if (hasBodyPartPreferences)
                                                    {
                                                        if (this.searchCriteriaBuilder.Conversation == null)
                                                        {
                                                            throw new InvalidOperationException("Conversation object should not be null here when body part is requested!");
                                                        }
                                                        this.searchCriteriaBuilder.Conversation.LoadItemParts(new List <StoreObjectId>
                                                        {
                                                            item.StoreObjectId
                                                        });
                                                    }
                                                    if (this.mailboxSchemaOptions.RightsManagementSupport)
                                                    {
                                                        Command.CurrentCommand.DecodeIrmMessage(item, false);
                                                    }
                                                    try
                                                    {
                                                        serverDataObject.Bind(item);
                                                        airSyncDataObject.Bind(xmlNode3);
                                                        airSyncDataObject.CopyFrom(serverDataObject);
                                                    }
                                                    finally
                                                    {
                                                        airSyncDataObject.Unbind();
                                                        serverDataObject.Unbind();
                                                    }
                                                    if (this.mailboxSchemaOptions.RightsManagementSupport)
                                                    {
                                                        Command.CurrentCommand.SaveLicense(item);
                                                    }
                                                    xmlNode2.AppendChild(xmlNode4);
                                                    xmlNode2.AppendChild(xmlNode5);
                                                    if (this.FolderIdMappingSyncState == null)
                                                    {
                                                        throw new SearchNeedToFolderSyncException();
                                                    }
                                                    string text2 = ((FolderIdMapping)this.FolderIdMappingSyncState[CustomStateDatumType.IdMapping])[MailboxSyncItemId.CreateForNewItem(item.ParentId)];
                                                    if (text2 == null)
                                                    {
                                                        throw new SearchNeedToFolderSyncException();
                                                    }
                                                    xmlNode6.InnerText = text2;
                                                    xmlNode2.AppendChild(xmlNode6);
                                                    xmlNode2.AppendChild(xmlNode3);
                                                    responseNode.AppendChild(xmlNode2);
                                                    this.numberResponses++;
                                                    if (this.minRange + this.numberResponses > this.maxRange)
                                                    {
                                                        flag = true;
                                                        buildResponseState = MailboxSearchProvider.BuildResponseState.CountingTotal;
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                num--;
                                                throw;
                                            }
                                            finally
                                            {
                                                if (item != null)
                                                {
                                                    item.Dispose();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex is SearchNeedToFolderSyncException)
                                {
                                    throw;
                                }
                                if (!SyncCommand.IsItemSyncTolerableException(ex) && !SyncCommand.IsObjectNotFound(ex))
                                {
                                    throw;
                                }
                            }
                        }
                    }
                    if (!flag && this.uncappedResultCount > queryResult.EstimatedRowCount)
                    {
                        this.haveUnretrievableResults = true;
                    }
                }
            }
            if (this.numberResponses == 0)
            {
                XmlNode newChild = responseNode.OwnerDocument.CreateElement("Result", "Search:");
                responseNode.AppendChild(newChild);
                if (this.minRange >= GlobalSettings.MaxMailboxSearchResults)
                {
                    xmlNode.InnerText = 12.ToString(CultureInfo.InvariantCulture);
                    return;
                }
            }
            else if (this.rangeSpecified)
            {
                XmlNode xmlNode7 = responseNode.OwnerDocument.CreateElement("Range", "Search:");
                XmlNode xmlNode8 = responseNode.OwnerDocument.CreateElement("Total", "Search:");
                xmlNode7.InnerText = this.minRange.ToString(CultureInfo.InvariantCulture) + "-" + (this.minRange + this.numberResponses - 1).ToString(CultureInfo.InvariantCulture);
                responseNode.AppendChild(xmlNode7);
                if (this.haveUnretrievableResults)
                {
                    this.totalRowCount = this.uncappedResultCount;
                    xmlNode.InnerText  = 12.ToString(CultureInfo.InvariantCulture);
                }
                else if (this.uncappedResultCount > num2 || !flag2)
                {
                    this.totalRowCount = this.uncappedResultCount;
                }
                else
                {
                    this.totalRowCount = num + 1;
                    if (this.minRange + this.numberResponses == GlobalSettings.MaxMailboxSearchResults)
                    {
                        xmlNode.InnerText = 12.ToString(CultureInfo.InvariantCulture);
                    }
                }
                xmlNode8.InnerText = this.totalRowCount.ToString(CultureInfo.InvariantCulture);
                responseNode.AppendChild(xmlNode8);
            }
        }