private Stream LoadUNCDocument(bool isLoadingStream)
        {
            if (!DocumentLibraryUtilities.IsNavigationToUNCAllowed(this.owaContext.UserContext))
            {
                throw new OwaSegmentationException("Access to Unc documents is disabled");
            }
            DocumentLibraryObjectId documentLibraryObjectId = DocumentLibraryUtilities.CreateDocumentLibraryObjectId(this.owaContext);
            UncSession  session     = this.owaContext.UserContext.LogonIdentity.CreateUncSession(documentLibraryObjectId);
            UncDocument uncDocument = UncDocument.Read(session, documentLibraryObjectId);

            this.mimeType     = (uncDocument[UncDocumentSchema.FileType] as string);
            this.fileName     = Path.GetFileName(uncDocument.Uri.ToString());
            this.fileSize     = uncDocument.Size;
            this.documentPath = uncDocument.Uri.ToString();
            string queryStringParameter = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "URL");

            this.openLink = string.Concat(new string[]
            {
                "ev.owa?ns=UncDocument&ev=GetDoc&allowLevel2=1&URL=",
                Utilities.UrlEncode(queryStringParameter),
                "&id=",
                Utilities.UrlEncode(documentLibraryObjectId.ToBase64String()),
                Utilities.GetCanaryRequestParameter()
            });
            this.documentIdStringBuilder.Append(documentLibraryObjectId.ToBase64String());
            this.documentIdStringBuilder.Append("-");
            object obj = uncDocument.TryGetProperty(UncItemSchema.LastModifiedDate);

            if (obj is DateTime)
            {
                this.documentIdStringBuilder.Append(((DateTime)obj).Ticks);
            }
            if (!isLoadingStream)
            {
                return(null);
            }
            return(uncDocument.GetDocument());
        }
Example #2
0
        // Token: 0x0600303B RID: 12347 RVA: 0x0011AD14 File Offset: 0x00118F14
        internal static IDocument LoadDocumentLibraryItem(DocumentLibraryObjectId objectId, UserContext userContext)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            IDocument result = null;

            if ((objectId.UriFlags & UriFlags.SharepointDocument) == UriFlags.SharepointDocument)
            {
                SharepointSession session = userContext.LogonIdentity.CreateSharepointSession(objectId);
                result = SharepointDocument.Read(session, objectId);
            }
            else if ((objectId.UriFlags & UriFlags.UncDocument) == UriFlags.UncDocument)
            {
                UncSession session2 = userContext.LogonIdentity.CreateUncSession(objectId);
                result = UncDocument.Read(session2, objectId);
            }
            return(result);
        }
Example #3
0
        public void SendByEmail()
        {
            ExTraceGlobals.DocumentsCallTracer.TraceDebug((long)this.GetHashCode(), "DocumentLibraryEventHandler.SendByEmail");
            MessageItem messageItem = null;

            string[] array  = (string[])base.GetParameter("uri");
            Stream   stream = null;
            bool     flag   = DocumentLibraryUtilities.IsNavigationToWSSAllowed(base.UserContext);
            bool     flag2  = DocumentLibraryUtilities.IsNavigationToUNCAllowed(base.UserContext);

            try
            {
                for (int i = 0; i < array.Length; i++)
                {
                    ClassifyResult documentLibraryObjectId = DocumentLibraryUtilities.GetDocumentLibraryObjectId(array[i], base.UserContext);
                    if (documentLibraryObjectId == null)
                    {
                        ExTraceGlobals.DocumentsTracer.TraceDebug(0L, "Could not classify link: " + array[i]);
                        throw new OwaEventHandlerException("Could not add attachment to email", LocalizedStrings.GetNonEncoded(1948229493), OwaEventHandlerErrorCode.SendByEmailError);
                    }
                    DocumentLibraryObjectId objectId = documentLibraryObjectId.ObjectId;
                    if (objectId == null)
                    {
                        ExTraceGlobals.DocumentsTracer.TraceDebug(0L, "ObjectId could not be created from URI parameter: " + array[i]);
                        throw new OwaEventHandlerException("Could not add attachment to email", LocalizedStrings.GetNonEncoded(1948229493), OwaEventHandlerErrorCode.SendByEmailError);
                    }
                    UriFlags uriFlags = objectId.UriFlags;
                    try
                    {
                        string text;
                        switch (uriFlags)
                        {
                        case UriFlags.SharepointDocument:
                        {
                            if (!flag)
                            {
                                throw new OwaSegmentationException("Access to Sharepoint documents is disabled");
                            }
                            SharepointSession  session            = base.UserContext.LogonIdentity.CreateSharepointSession(objectId);
                            SharepointDocument sharepointDocument = SharepointDocument.Read(session, objectId);
                            stream = sharepointDocument.GetDocument();
                            text   = (string.IsNullOrEmpty(sharepointDocument.DisplayName) ? LocalizedStrings.GetNonEncoded(1797976510) : sharepointDocument.DisplayName);
                            break;
                        }

                        case UriFlags.UncDocument:
                        {
                            if (!flag2)
                            {
                                throw new OwaSegmentationException("Access to Unc documents is disabled");
                            }
                            UncSession  session2    = base.UserContext.LogonIdentity.CreateUncSession(objectId);
                            UncDocument uncDocument = UncDocument.Read(session2, objectId);
                            stream = uncDocument.GetDocument();
                            text   = Path.GetFileName(uncDocument.Uri.ToString());
                            if (!string.IsNullOrEmpty(text))
                            {
                                text = HttpUtility.UrlDecode(text);
                            }
                            break;
                        }

                        default:
                            throw new OwaNotSupportedException("Unhandled document library type");
                        }
                        if (messageItem == null)
                        {
                            messageItem = MessageItem.Create(base.UserContext.MailboxSession, base.UserContext.DraftsFolderId);
                            messageItem[ItemSchema.ConversationIndexTracking] = true;
                        }
                        int num;
                        AttachmentAddResult attachmentAddResult = AttachmentUtility.AddAttachmentFromStream(messageItem, text, null, stream, base.UserContext, out num);
                        if (Globals.ArePerfCountersEnabled)
                        {
                            if (uriFlags == UriFlags.UncDocument)
                            {
                                OwaSingleCounters.UncRequests.Increment();
                                OwaSingleCounters.UncBytes.IncrementBy((long)num);
                            }
                            else
                            {
                                OwaSingleCounters.WssRequests.Increment();
                                OwaSingleCounters.WssBytes.IncrementBy((long)num);
                            }
                        }
                        if (attachmentAddResult.ResultCode != AttachmentAddResultCode.NoError)
                        {
                            throw new OwaEventHandlerException("Could not add attachment to email. " + attachmentAddResult.Message, LocalizedStrings.GetNonEncoded(1948229493), OwaEventHandlerErrorCode.SendByEmailError);
                        }
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Close();
                            stream = null;
                        }
                    }
                }
                messageItem.Save(SaveMode.ResolveConflicts);
                messageItem.Load();
                this.Writer.Write(messageItem.Id.ObjectId.ToBase64String());
            }
            finally
            {
                if (messageItem != null)
                {
                    messageItem.Dispose();
                    messageItem = null;
                }
            }
        }
        // Token: 0x0600074D RID: 1869 RVA: 0x00027EFC File Offset: 0x000260FC
        public void Execute()
        {
            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrary Fetch command received. Processing request...");
            Uri uri = null;

            try
            {
                uri = new Uri(this.linkId);
            }
            catch (UriFormatException innerException)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Bad document Uri {0} was specified!", new object[]
                {
                    this.linkId
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException, false);
            }
            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Processing Fetch command with Uri {0}.", uri.AbsoluteUri);
            if (!DocumentLibraryUtility.IsTrustedProtocol(uri.Scheme))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: untrusted protocol: {0}!", new object[]
                {
                    uri.Scheme
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadProtocolInDocFetch");
                throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
            }
            if (!DocumentLibraryUtility.IsInternalUri(uri))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Uri must be internal: {0}!", new object[]
                {
                    uri.Host
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternalProtocolInDocFetch");
                throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
            }
            AuthenticationContext authenticationContext = new AuthenticationContext();

            try
            {
                IPrincipal principal;
                if (this.userPassword == null)
                {
                    principal = this.user.WindowsPrincipal;
                    if (principal == null)
                    {
                        if (GlobalSettings.EnableCredentialRequest && this.user.Context.Request.Version >= 121)
                        {
                            this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedPromptForCredsToProxy2");
                            throw new AirSyncPermanentException(StatusCode.ItemOperations_CredentialsRequired, false);
                        }
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedCredsToProxy2");
                        throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false);
                    }
                }
                else
                {
                    SecurityStatus securityStatus = authenticationContext.LogonUser(this.userName, this.userPassword);
                    this.userPassword.Dispose();
                    this.userPassword = null;
                    if (securityStatus != SecurityStatus.OK)
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Authentication failed with status {0}.", new object[]
                        {
                            securityStatus
                        }));
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, string.Format(CultureInfo.InvariantCulture, "AuthenticationErrorStatus{0}", new object[]
                        {
                            securityStatus
                        }));
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);
                    }
                    principal = new WindowsPrincipal(authenticationContext.Identity);
                }
                ClassifyResult classifyResult = LinkClassifier.ClassifyLinks(principal, new Uri[]
                {
                    uri
                })[0];
                if (classifyResult.Error != ClassificationError.None)
                {
                    AirSyncDiagnostics.TraceDebug <string, ClassificationError>(ExTraceGlobals.RequestsTracer, this, "The LinkClassifier failed to classify the link {0}, returned {1}", this.linkId, classifyResult.Error);
                    switch (classifyResult.Error)
                    {
                    case ClassificationError.ConnectionFailed:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassConnFailedInDocFetch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_Conflict, null, false);

                    case ClassificationError.AccessDenied:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassDeniedInDocFetch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);

                    case ClassificationError.ObjectNotFound:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassNotFoundInDocFetch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ClientServerConversion, null, false);

                    case ClassificationError.UriTypeNotSupported:
                    case ClassificationError.InvalidUri:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassBadUriInDocFetch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ProtocolError, null, false);
                    }
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassFailureInDocFetch");
                    throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false);
                }
                IDocument         document          = null;
                UncSession        uncSession        = null;
                SharepointSession sharepointSession = null;
                if ((classifyResult.UriFlags & UriFlags.UncDocument) == UriFlags.UncDocument)
                {
                    if (!DocumentLibraryUtility.IsUncAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch");
                        throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch");
                        throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
                    }
                    uncSession = UncSession.Open(classifyResult.ObjectId, principal);
                }
                else
                {
                    if ((classifyResult.UriFlags & UriFlags.SharepointDocument) != UriFlags.SharepointDocument)
                    {
                        AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Fetch", this.linkId, classifyResult.UriFlags);
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false);
                    }
                    if (!DocumentLibraryUtility.IsWssAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "WssDeniedInDocFetch");
                        throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_Retry, false);
                    }
                    this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs);
                    sharepointSession = SharepointSession.Open(classifyResult.ObjectId, principal);
                }
                try
                {
                    if (uncSession != null)
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading UNC document...");
                        document = UncDocument.Read(uncSession, classifyResult.ObjectId);
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading Sharepoint document...");
                        AirSyncDiagnostics.Assert(sharepointSession != null);
                        document = SharepointDocument.Read(sharepointSession, classifyResult.ObjectId);
                    }
                }
                catch (ObjectNotFoundException innerException2)
                {
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch");
                    throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException2, false);
                }
                catch (AccessDeniedException innerException3)
                {
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch2");
                    throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException3, false);
                }
                this.documentSize = (int)document.Size;
                if (this.documentSize == 0)
                {
                    AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "The file {0} was found to be empty!", this.linkId);
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "EmptyDocInDocFetch");
                    throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_NotificationGUID, null, false);
                }
                object obj = document.TryGetProperty(DocumentLibraryItemSchema.LastModifiedDate);
                if (obj is PropertyError)
                {
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch");
                    throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false);
                }
                ExDateTime exDateTime;
                if (obj is DateTime)
                {
                    exDateTime = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)obj);
                }
                else
                {
                    exDateTime = (ExDateTime)obj;
                }
                this.version = exDateTime.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture);
                if (this.rangeSpecified && this.minRange >= this.documentSize)
                {
                    AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, this, "The minimum range specified {0} is greater than the document size {1}", this.minRange, this.documentSize);
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadMinSizeInDocFetch");
                    throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ObjectNotFound, null, false);
                }
                using (Stream document2 = document.GetDocument())
                {
                    int num;
                    if (this.rangeSpecified)
                    {
                        num = this.maxRange - this.minRange + 1;
                    }
                    else
                    {
                        num = this.documentSize;
                    }
                    if (uncSession != null)
                    {
                        this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.UNCFiles);
                        this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.UNCBytes, num);
                    }
                    if (sharepointSession != null)
                    {
                        this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs);
                        this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.SharePointBytes, num);
                    }
                    this.outStream = new MemoryStream(num);
                    if (num > GlobalSettings.MaxDocumentDataSize)
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DocTooBigInDocFetch");
                        throw new AirSyncPermanentException(StatusCode.Sync_NotificationsNotProvisioned, false);
                    }
                    try
                    {
                        StreamHelper.CopyStream(document2, this.outStream, this.minRange, num);
                    }
                    catch (IOException innerException4)
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch");
                        throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException4, false);
                    }
                }
            }
            catch (UnknownErrorException innerException5)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch2");
                throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException5, false);
            }
            catch (DocumentModifiedException innerException6)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch3");
                throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException6, false);
            }
            catch (DocumentStreamAccessDeniedException innerException7)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch3");
                throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException7, false);
            }
            catch (ObjectMovedOrDeletedException innerException8)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch2");
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException8, false);
            }
            catch (DocumentLibraryException innerException9)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch2");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException9, false);
            }
            finally
            {
                if (authenticationContext != null)
                {
                    authenticationContext.Dispose();
                    authenticationContext = null;
                }
            }
        }
Example #5
0
        // Token: 0x06000741 RID: 1857 RVA: 0x00026D8C File Offset: 0x00024F8C
        public void Execute()
        {
            Uri uri = null;

            try
            {
                uri = new Uri(this.linkId);
            }
            catch (UriFormatException innerException)
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "DocumentLibrarySearchProvider: Bad Uri {0} was specified!", new object[]
                {
                    this.linkId
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException, false);
            }
            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Processing Search command with Uri {0}.", uri.AbsoluteUri);
            if (!DocumentLibraryUtility.IsTrustedProtocol(uri.Scheme))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: untrusted protocol: {0}!", new object[]
                {
                    uri.Scheme
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadProtocolInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
            }
            if (!DocumentLibraryUtility.IsInternalUri(uri))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Uri must be internal: {0}!", new object[]
                {
                    uri.Host
                }));
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternalProtocolInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
            }
            AuthenticationContext authenticationContext = new AuthenticationContext();

            try
            {
                IPrincipal principal;
                if (this.userPassword == null)
                {
                    principal = this.user.WindowsPrincipal;
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrarySearchProvider: Created IPrincipal object from IAirSyncUser .");
                    if (principal == null)
                    {
                        if (GlobalSettings.EnableCredentialRequest && this.user.Context.Request.Version >= 121)
                        {
                            this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedPromptForCredsToProxy2");
                            throw new AirSyncPermanentException(StatusCode.Sync_InvalidWaitTime, false);
                        }
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedCredsToProxy2");
                        throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false);
                    }
                }
                else
                {
                    SecurityStatus securityStatus = authenticationContext.LogonUser(this.userName, this.userPassword);
                    this.userPassword.Dispose();
                    this.userPassword = null;
                    if (securityStatus != SecurityStatus.OK)
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "DocumentLibrarySearchProvider: Authentication failed with status {0}.", new object[]
                        {
                            securityStatus
                        }));
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, string.Format(CultureInfo.InvariantCulture, "AuthenticationErrorStatus{0}", new object[]
                        {
                            securityStatus
                        }));
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);
                    }
                    principal = new WindowsPrincipal(authenticationContext.Identity);
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrarySearchProvider: Created IPrincipal using AuthenticationContext LogonUser method.");
                }
                ClassifyResult classifyResult = LinkClassifier.ClassifyLinks(principal, new Uri[]
                {
                    uri
                })[0];
                if (classifyResult.Error != ClassificationError.None)
                {
                    AirSyncDiagnostics.TraceDebug <string, ClassificationError>(ExTraceGlobals.RequestsTracer, this, "The LinkClassifier failed to classify the link {0}, returned {1}", this.linkId, classifyResult.Error);
                    switch (classifyResult.Error)
                    {
                    case ClassificationError.ConnectionFailed:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassConnFailedInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_Conflict, null, false);

                    case ClassificationError.AccessDenied:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassDeniedInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false);

                    case ClassificationError.ObjectNotFound:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassNotFoundInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ClientServerConversion, null, false);

                    case ClassificationError.UriTypeNotSupported:
                    case ClassificationError.InvalidUri:
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassBadUriInDocSearch");
                        throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ProtocolError, null, false);
                    }
                    this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassFailureInDocSearch");
                    throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false);
                }
                AirSyncDiagnostics.TraceDebug <UriFlags>(ExTraceGlobals.RequestsTracer, this, "Search command document type is {0}.", classifyResult.UriFlags);
                SharepointSession      sharepointSession     = null;
                UncSession             uncSession            = null;
                IDocumentLibraryItem   documentLibraryItem   = null;
                IDocumentLibrary       documentLibrary       = null;
                IDocumentLibraryFolder documentLibraryFolder = null;
                if ((classifyResult.UriFlags & UriFlags.Unc) == UriFlags.Unc)
                {
                    if (!DocumentLibraryUtility.IsUncAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    uncSession = UncSession.Open(classifyResult.ObjectId, principal);
                }
                else
                {
                    if ((classifyResult.UriFlags & UriFlags.Sharepoint) != UriFlags.Sharepoint)
                    {
                        AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Search", this.linkId, classifyResult.UriFlags);
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false);
                    }
                    if (!DocumentLibraryUtility.IsWssAccessEnabled(this.user))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "WssDeniedInDocSearch");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    if (DocumentLibraryUtility.IsBlockedHostName(uri.Host))
                    {
                        this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocSearch2");
                        throw new AirSyncPermanentException(StatusCode.Sync_InvalidParameters, false);
                    }
                    sharepointSession = SharepointSession.Open(classifyResult.ObjectId, principal);
                }
                UriFlags uriFlags = classifyResult.UriFlags;
                switch (uriFlags)
                {
                case UriFlags.Sharepoint:
                case UriFlags.Unc:
                    goto IL_645;

                case UriFlags.Sharepoint | UriFlags.Unc:
                case UriFlags.DocumentLibrary:
                    break;

                case UriFlags.SharepointDocumentLibrary:
                    documentLibrary = SharepointDocumentLibrary.Read(sharepointSession, classifyResult.ObjectId);
                    goto IL_645;

                case UriFlags.UncDocumentLibrary:
                    documentLibrary = UncDocumentLibrary.Read(uncSession, classifyResult.ObjectId);
                    goto IL_645;

                default:
                    switch (uriFlags)
                    {
                    case UriFlags.SharepointDocument:
                        documentLibraryItem = SharepointDocument.Read(sharepointSession, classifyResult.ObjectId);
                        goto IL_645;

                    case UriFlags.UncDocument:
                        documentLibraryItem = UncDocument.Read(uncSession, classifyResult.ObjectId);
                        goto IL_645;

                    default:
                        switch (uriFlags)
                        {
                        case UriFlags.SharepointFolder:
                            documentLibraryFolder = SharepointDocumentLibraryFolder.Read(sharepointSession, classifyResult.ObjectId);
                            goto IL_645;

                        case UriFlags.UncFolder:
                            documentLibraryFolder = UncDocumentLibraryFolder.Read(uncSession, classifyResult.ObjectId);
                            goto IL_645;
                        }
                        break;
                    }
                    break;
                }
                AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Search", this.linkId, classifyResult.UriFlags);
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch3");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false);
IL_645:
                if (documentLibrary != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() for document library...");
                    this.tableView = documentLibrary.GetView(null, DocumentLibrarySearchProvider.sortBy, DocumentLibraryQueryOptions.FoldersAndFiles, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps = documentLibrary.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (documentLibraryFolder != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() for document folder...");
                    this.tableView = documentLibraryFolder.GetView(null, DocumentLibrarySearchProvider.sortBy, DocumentLibraryQueryOptions.FoldersAndFiles, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps = documentLibraryFolder.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (documentLibraryItem != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Getting properties for the document item...");
                    this.rootProps = documentLibraryItem.GetProperties(DocumentLibrarySearchProvider.documentLibraryProps);
                }
                else if (sharepointSession != null)
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() on Sharepoint session...");
                    this.tableView    = sharepointSession.GetView(ListBaseType.DocumentLibrary, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps    = new object[DocumentLibrarySearchProvider.airSyncProps.GetLength(0)];
                    this.rootProps[0] = sharepointSession.Uri;
                    this.rootProps[1] = sharepointSession.DisplayName;
                    this.rootProps[2] = true;
                }
                else
                {
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling GetView() on UNC session...");
                    this.tableView    = uncSession.GetView(null, null, DocumentLibrarySearchProvider.documentLibraryProps);
                    this.rootProps    = new object[DocumentLibrarySearchProvider.airSyncProps.GetLength(0)];
                    this.rootProps[0] = uncSession.Uri;
                    this.rootProps[1] = uncSession.Title;
                    this.rootProps[2] = true;
                }
            }
            catch (UnknownErrorException innerException2)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocSearch4");
                throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException2, false);
            }
            catch (AccessDeniedException innerException3)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocSearch2");
                throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException3, false);
            }
            catch (ConnectionException innerException4)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ConnFailedInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_Conflict, innerException4, false);
            }
            catch (ObjectNotFoundException innerException5)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException5, false);
            }
            catch (DocumentLibraryException innerException6)
            {
                this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FailureInDocSearch");
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException6, false);
            }
            finally
            {
                if (authenticationContext != null)
                {
                    authenticationContext.Dispose();
                    authenticationContext = null;
                }
            }
        }