Пример #1
0
 private void BackEndWriteContent(IAsyncResult asynchronousResult)
 {
     lock (this)
     {
         if (this.requestWasTimedOut)
         {
             AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndWriteContent() Request was timed out while waiting for lock!");
             return;
         }
     }
     try
     {
         AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndWriteContent called for serverName: {0}, user {1}", this.remoteUri, this.userName);
         this.UnregisterTimeoutWaitHandle();
         this.backEndRequestStream.EndWrite(asynchronousResult);
         this.pendingAsyncOperation = ProxyHandler.PendingOperationState.FrontEndReadContentFromClient;
         IAsyncResult asyncResult = this.clientRequestStream.BeginRead(this.asyncBuffer, 0, this.asyncBuffer.Length, new AsyncCallback(this.FrontEndReadContentFromClient), null);
         if (!asyncResult.CompletedSynchronously)
         {
             this.RegisterTimeoutWaitHandle(asyncResult, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
         }
     }
     catch (Exception ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndWriteContent caught an exception\r\n{0}", arg);
         if (this.backEndWebRequest != null)
         {
             this.backEndWebRequest.Abort();
             this.backEndWebRequest = null;
         }
         this.HandleException(ex);
     }
 }
Пример #2
0
 private void ProxyLoginGetStreamCompleteCallback(IAsyncResult iar)
 {
     AirSyncDiagnostics.TraceFunction <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyLoginRequestCompleteCallback: {0}, {1}.", this.remoteUri, this.userName);
     lock (this)
     {
         if (this.requestWasTimedOut)
         {
             AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.ProxyLoginGetStreamCompleteCallback() Request was timed out while waiting for lock!");
             return;
         }
     }
     try
     {
         this.UnregisterTimeoutWaitHandle();
         this.backEndRequestStream  = this.backEndWebRequest.EndGetRequestStream(iar);
         this.pendingAsyncOperation = ProxyHandler.PendingOperationState.ProxyLoginWritingCsc;
         IAsyncResult asyncResult = this.backEndRequestStream.BeginWrite(this.proxyInfo.CscBuffer, 0, this.proxyInfo.CscBuffer.Length, new AsyncCallback(this.ProxyLoginWriteCompleteCallback), null);
         if (!asyncResult.CompletedSynchronously)
         {
             this.RegisterTimeoutWaitHandle(asyncResult, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
         }
     }
     catch (Exception ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyLoginRequestCompleteCallback caught an exception\r\n{0}", arg);
         if (this.backEndWebRequest != null)
         {
             this.backEndWebRequest.Abort();
             this.backEndWebRequest = null;
         }
         this.HandleException(ex);
     }
     AirSyncDiagnostics.TraceFunction <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyLoginRequestCompleteCallback: completed {0}, {1}.", this.remoteUri, this.userName);
 }
Пример #3
0
 private void FrontEndReadContentFromClient(IAsyncResult asynchronousResult)
 {
     lock (this)
     {
         if (this.requestWasTimedOut)
         {
             AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.FrontEndReadContentFromClient() Request was timed out while waiting for lock!");
             return;
         }
     }
     try
     {
         AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.FrontEndReadContentFromClient called for serverName: {0}, user {1}", this.remoteUri, this.userName);
         this.UnregisterTimeoutWaitHandle();
         if (this.proxyLoginAttempts == 0 && this.cachedRequestBody == null)
         {
             this.cachedRequestBody = new MemoryStream(this.frontEndHttpContext.Request.ContentLength);
         }
         int num = this.clientRequestStream.EndRead(asynchronousResult);
         if (num > 0)
         {
             if (this.proxyLoginAttempts == 0)
             {
                 this.cachedRequestBody.Write(this.asyncBuffer, 0, num);
             }
             lock (this)
             {
                 this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndWriteContent;
                 IAsyncResult asyncResult = this.backEndRequestStream.BeginWrite(this.asyncBuffer, 0, num, new AsyncCallback(this.BackEndWriteContent), null);
                 if (!asyncResult.CompletedSynchronously)
                 {
                     this.RegisterTimeoutWaitHandle(asyncResult, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
                 }
                 goto IL_16D;
             }
         }
         this.backEndRequestStream.Flush();
         this.backEndRequestStream.Dispose();
         this.backEndRequestStream  = null;
         this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndGetResponse;
         IAsyncResult asyncResult2 = this.backEndWebRequest.BeginGetResponse(new AsyncCallback(this.BackEndGetResponse), null);
         if (!asyncResult2.CompletedSynchronously)
         {
             this.RegisterTimeoutWaitHandle(asyncResult2, (int)GlobalSettings.ProxyHandlerLongTimeout.TotalMilliseconds);
         }
         IL_16D :;
     }
     catch (Exception ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.FrontEndReadContentFromClient caught an exception\r\n{0}", arg);
         if (this.backEndWebRequest != null)
         {
             this.backEndWebRequest.Abort();
             this.backEndWebRequest = null;
         }
         this.HandleException(ex);
     }
 }
Пример #4
0
 internal override Command.ExecutionState ExecuteCommand()
 {
     try
     {
         this.ParseXmlRequest();
         this.provider = this.CreateProvider(this.reqStoreName);
         if (this.provider == null)
         {
             AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "Unknown search provider specified!");
             base.XmlResponse = this.GetValidationErrorXml();
             return(Command.ExecutionState.Complete);
         }
         XmlDocument xmlResponse = this.BuildXmlResponse();
         this.provider.ParseOptions(this.reqOptionsNode);
         this.provider.ParseQueryNode(this.reqQueryNode);
         MailboxSearchProvider mailboxSearchProvider = this.provider as MailboxSearchProvider;
         if (mailboxSearchProvider != null)
         {
             base.ProtocolLogger.SetValue(ProtocolLoggerData.TotalFolders, mailboxSearchProvider.Folders);
             if (mailboxSearchProvider.DeepTraversal)
             {
                 base.ProtocolLogger.SetValue(ProtocolLoggerData.SearchDeep, 1);
             }
         }
         this.provider.Execute();
         this.provider.BuildResponse(this.respStoreNode);
         base.ProtocolLogger.IncrementValueBy("S", PerFolderProtocolLoggerData.ServerAdds, this.provider.NumberResponses);
         base.XmlResponse = xmlResponse;
     }
     catch (AirSyncPermanentException ex)
     {
         if (ex.HttpStatusCode != HttpStatusCode.OK)
         {
             throw;
         }
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.ProtocolTracer, this, "AirSyncPermanentException was thrown. Location Execute.\r\n{0}", arg);
         base.ProtocolLogger.IncrementValue(ProtocolLoggerData.NumErrors);
         base.ProtocolLogger.AppendValue(ProtocolLoggerData.Error, ex.ErrorStringForProtocolLogger);
         if (base.MailboxLogger != null)
         {
             base.MailboxLogger.SetData(MailboxLogDataName.SearchCommand_Execute_Exception, ex);
         }
         base.XmlResponse    = this.GetProviderErrorXml(ex.AirSyncStatusCodeInInt);
         base.PartialFailure = true;
     }
     finally
     {
         if (this.provider is IDisposable)
         {
             ((IDisposable)this.provider).Dispose();
         }
         this.provider = null;
     }
     return(Command.ExecutionState.Complete);
 }
Пример #5
0
        private void HandleException(Exception ex)
        {
            AirSyncDiagnostics.TraceError <Exception>(ExTraceGlobals.RequestsTracer, this, "HandleException() is swallowing exception and returning HTTP 500 - {0}", ex);
            WebException ex2 = ex as WebException;

            if (ex2 != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(ex2.Status);
                if (ex2.Response != null)
                {
                    stringBuilder.Append(".");
                    stringBuilder.Append(((HttpWebResponse)ex2.Response).StatusCode);
                }
                this.protocolLogger.SetValue(ProtocolLoggerData.Error, stringBuilder.ToString());
            }
            else if (ex is SocketException || ex is IOException)
            {
                StringBuilder stringBuilder2 = new StringBuilder();
                stringBuilder2.Append("SocketIOException: ");
                stringBuilder2.Append(ex.Message);
                this.protocolLogger.SetValue(ProtocolLoggerData.Error, stringBuilder2.ToString());
            }
            else
            {
                if (!(ex is AirSyncPermanentException))
                {
                    throw ex;
                }
                StringBuilder stringBuilder3 = new StringBuilder();
                stringBuilder3.Append("AirSyncPermanentException: ");
                stringBuilder3.Append(ex.Message);
                this.protocolLogger.SetValue(ProtocolLoggerData.Error, stringBuilder3.ToString());
            }
            try
            {
                this.TryUnregisterTimeoutWaitHandle();
                this.frontEndHttpContext.Response.Clear();
                this.frontEndHttpContext.Response.StatusCode = 500;
                this.frontEndResult.InvokeCallback();
            }
            catch (HttpException ex3)
            {
                AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex3);
                AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "HttpException was thrown while setting the StatusCode.\r\n{0}", arg);
            }
            finally
            {
                this.ReleaseResources();
            }
        }
Пример #6
0
 private void BackEndReadContent(IAsyncResult asynchronousResult)
 {
     lock (this)
     {
         if (this.requestWasTimedOut)
         {
             AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndReadContent() Request was timed out while waiting for lock!");
             string text = this.remoteUri.Host.ToString();
             AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_ProxyResultTimedOut, text, new string[]
             {
                 text
             });
             return;
         }
     }
     try
     {
         AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndReadContent called for serverName: {0}, user {1}", this.remoteUri, this.userName);
         this.UnregisterTimeoutWaitHandle();
         int num = this.backEndResponseStream.EndRead(asynchronousResult);
         if (num > 0)
         {
             this.frontEndHttpContext.Response.OutputStream.Write(this.asyncBuffer, 0, num);
             this.backEndResponseStream = this.httpWebResponse.GetResponseStream();
             this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndReadContent;
             IAsyncResult asyncResult = this.backEndResponseStream.BeginRead(this.asyncBuffer, 0, this.asyncBuffer.Length, new AsyncCallback(this.BackEndReadContent), null);
             if (!asyncResult.CompletedSynchronously)
             {
                 this.RegisterTimeoutWaitHandle(asyncResult, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
             }
         }
         else
         {
             this.UnregisterTimeoutWaitHandle();
             this.frontEndResult.InvokeCallback();
             this.ReleaseResources();
         }
     }
     catch (Exception ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndReadContent caught an exception\r\n{0}", arg);
         if (this.backEndWebRequest != null)
         {
             this.backEndWebRequest.Abort();
             this.backEndWebRequest = null;
         }
         this.HandleException(ex);
     }
 }
 private AirSyncPermanentException(LocalizedString message, Exception innerException, HttpStatusCode httpStatusCode, XmlDocument xmlResponse, StatusCode airSyncStatusCode, bool logEvent)
 {
     this.httpStatusCode          = HttpStatusCode.InternalServerError;
     this.logStackTraceToEventLog = true;
     base..ctor(message, innerException);
     this.httpStatusCode    = httpStatusCode;
     this.xmlResponse       = xmlResponse;
     this.airSyncStatusCode = airSyncStatusCode;
     if (message.IsEmpty)
     {
         this.logExceptionToEventLog = false;
     }
     else
     {
         this.logExceptionToEventLog = logEvent;
     }
     AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(this);
     AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "AirSyncPermanentException: {0}", arg);
 }
Пример #8
0
        public override bool HasSchemaPropertyChanged(ISyncItem syncItem, int?[] oldChangeTrackingInformation, XmlDocument xmlResponse, MailboxLogger mailboxLogger)
        {
            bool    flag        = false;
            XmlNode xmlItemRoot = xmlResponse.CreateElement("ApplicationData", "AirSync:");

            try
            {
                this.EntityDataObject.Bind(syncItem.NativeItem);
                base.AirSyncDataObject.Bind(xmlItemRoot);
                base.AirSyncDataObject.CopyFrom(this.EntityDataObject);
            }
            catch (Exception ex)
            {
                if (!SyncCommand.IsItemSyncTolerableException(ex))
                {
                    throw;
                }
                if (mailboxLogger != null)
                {
                    mailboxLogger.SetData(MailboxLogDataName.MailboxSyncCommand_HasSchemaPropertyChanged_Exception, ex);
                }
                AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
                AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "Sync-tolerable Entity conversion Exception was thrown. HasSchemaPropertyChanged() {0}", arg);
                flag = true;
            }
            finally
            {
                this.EntityDataObject.Unbind();
                base.AirSyncDataObject.Unbind();
            }
            if (!flag)
            {
                int?[] array = base.ChangeTrackFilter.UpdateChangeTrackingInformation(xmlItemRoot, oldChangeTrackingInformation);
                AirSyncDiagnostics.TraceDebug <int?[], int?[]>(ExTraceGlobals.RequestsTracer, this, "HasSchemaPropertyChanged oldCCI {0} newCCI {1}", oldChangeTrackingInformation, array);
                flag = !ChangeTrackingFilter.IsEqual(array, oldChangeTrackingInformation);
            }
            return(flag);
        }
 // Token: 0x06000886 RID: 2182 RVA: 0x00032504 File Offset: 0x00030704
 internal override Command.ExecutionState ExecuteCommand()
 {
     try
     {
         FolderCommand.FolderRequest folderRequest = this.ParseRequest();
         XmlDocument xmlDocument = new SafeXmlDocument();
         XmlNode     newChild    = xmlDocument.CreateElement(base.XmlRequest.LocalName, base.XmlRequest.NamespaceURI);
         xmlDocument.AppendChild(newChild);
         try
         {
             base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.ClientSyncKey, folderRequest.SyncKey);
             this.LoadSyncState(folderRequest.SyncKey);
             this.ConvertSyncIdsToXsoIds(folderRequest);
             this.folderHierarchySync = this.folderHierarchySyncState.GetFolderHierarchySync(new ChangeTrackingDelegate(FolderCommand.ComputeChangeTrackingHash));
             if (folderRequest.SyncKey != 0)
             {
                 if (!this.folderHierarchySyncState.Contains(CustomStateDatumType.SyncKey))
                 {
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "I");
                     base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "RecoveryNotAllowed");
                     throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
                 }
                 int data  = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.SyncKey, -1);
                 int data2 = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.RecoverySyncKey, -1);
                 if (folderRequest.SyncKey != data && (!this.allowRecovery || folderRequest.SyncKey != data2))
                 {
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "I");
                     base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidSyncKey");
                     throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), null, false);
                 }
                 FolderIdMapping folderIdMapping = (FolderIdMapping)this.folderIdMappingSyncState[CustomStateDatumType.IdMapping];
                 if (folderRequest.SyncKey == data)
                 {
                     AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Committing folderIdMapping.");
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "S");
                     folderIdMapping.CommitChanges();
                     this.folderHierarchySync.AcknowledgeServerOperations();
                 }
                 else
                 {
                     AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Clearing changes on folderIdMapping.");
                     base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "R");
                     folderIdMapping.ClearChanges();
                     this.folderIdMappingSyncState[CustomStateDatumType.FullFolderTree] = this.folderIdMappingSyncState[CustomStateDatumType.RecoveryFullFolderTree];
                 }
             }
             else
             {
                 base.ProtocolLogger.SetValue("F", PerFolderProtocolLoggerData.SyncType, "F");
                 base.SendServerUpgradeHeader = true;
             }
             this.ProcessCommand(folderRequest, xmlDocument);
             if (this.folderHierarchySyncState != null)
             {
                 int data3 = this.folderHierarchySyncState.GetData <Int32Data, int>(CustomStateDatumType.AirSyncProtocolVersion, -1);
                 if (base.Version > data3)
                 {
                     AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, this, "Changing sync state protocol version from {0} to {1}.", data3, base.Version);
                     this.folderHierarchySyncState[CustomStateDatumType.AirSyncProtocolVersion] = new Int32Data(base.Version);
                     this.syncStateChanged = true;
                 }
             }
             if (this.syncStateChanged)
             {
                 if (this.folderHierarchySyncState != null)
                 {
                     this.folderHierarchySyncState.CustomVersion = new int?(5);
                     this.folderHierarchySyncState.Commit();
                 }
                 if (this.folderIdMappingSyncState != null)
                 {
                     FolderIdMapping folderIdMapping2 = this.folderIdMappingSyncState[CustomStateDatumType.IdMapping] as FolderIdMapping;
                     FolderTree      folderTree       = this.folderIdMappingSyncState[CustomStateDatumType.FullFolderTree] as FolderTree;
                     if (folderIdMapping2.IsDirty || folderTree.IsDirty)
                     {
                         this.folderIdMappingSyncState.Commit();
                     }
                 }
             }
         }
         finally
         {
             if (this.folderIdMappingSyncState != null)
             {
                 this.folderIdMappingSyncState.Dispose();
             }
             if (this.folderHierarchySyncState != null)
             {
                 this.folderHierarchySyncState.Dispose();
             }
         }
         base.XmlResponse = xmlDocument;
     }
     catch (ObjectNotFoundException innerException)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FolderNotFound");
         throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, this.ConstructErrorXml(StatusCode.Sync_ProtocolError), innerException, false);
     }
     catch (CorruptDataException ex)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "CorruptData");
         AirSyncDiagnostics.TraceDebug <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "Corrupted data found, replacing error with wrongsynckey error to force client to refresh.\r\n{0}", arg);
         throw new AirSyncPermanentException(StatusCode.Sync_OutOfDisk, this.ConstructErrorXml(StatusCode.Sync_OutOfDisk), ex, false);
     }
     catch (QuotaExceededException)
     {
         throw;
     }
     catch (StoragePermanentException ex2)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, ex2.GetType().ToString());
         throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, this.ConstructErrorXml(StatusCode.Sync_ClientServerConversion), ex2, false);
     }
     catch (ArgumentException innerException2)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ArgumentException");
         throw new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, this.ConstructErrorXml(StatusCode.Sync_NotificationGUID), innerException2, false);
     }
     catch (FormatException innerException3)
     {
         base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "FormatException");
         throw new AirSyncPermanentException(StatusCode.Sync_NotificationGUID, this.ConstructErrorXml(StatusCode.Sync_NotificationGUID), innerException3, false);
     }
     return(Command.ExecutionState.Complete);
 }
Пример #10
0
        // Token: 0x06000C29 RID: 3113 RVA: 0x0003F778 File Offset: 0x0003D978
        internal override Command.ExecutionState ExecuteCommand()
        {
            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ItemOperationsCommand received. Processing the command...");
            try
            {
                XmlDocument xmlDocument = null;
                XmlNode     xmlRequest  = base.XmlRequest;
                if (xmlRequest.ChildNodes.Count > GlobalSettings.MaxRetrievedItems)
                {
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "CapReached");
                    string message = string.Format("ItemOperations cap is reached, Cap = {0}, ChildNode = {1}", GlobalSettings.MaxRetrievedItems, xmlRequest.ChildNodes.Count);
                    AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, message);
                    xmlDocument = this.BuildXmlResponse(11.ToString(CultureInfo.InvariantCulture));
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.StatusCode, 11);
                }
                else
                {
                    xmlDocument = this.BuildXmlResponse(1.ToString(CultureInfo.InvariantCulture));
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.StatusCode, 1);
                    int i = 0;
                    while (i < xmlRequest.ChildNodes.Count)
                    {
                        XmlNode xmlNode = xmlRequest.ChildNodes[i];
                        string  localName;
                        if ((localName = xmlNode.LocalName) == null)
                        {
                            goto IL_278;
                        }
                        if (localName == "EmptyFolderContents")
                        {
                            this.currentProvider = this.EmptyFolderContentsProvider;
                            base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOEmptyFolderContents);
                            goto IL_27E;
                        }
                        if (!(localName == "Fetch"))
                        {
                            if (!(localName == "Move"))
                            {
                                goto IL_278;
                            }
                            this.currentProvider = this.MoveProvider;
                            base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOMoves);
                            goto IL_27E;
                        }
                        else
                        {
                            XmlNode xmlNode2 = xmlNode["Store", "ItemOperations:"];
                            string  a;
                            if ((a = xmlNode2.InnerText.ToLower(CultureInfo.InvariantCulture)) != null)
                            {
                                if (a == "documentlibrary")
                                {
                                    this.currentProvider = this.DocumentFetchProvider;
                                    base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOFetchDocs);
                                    goto IL_27E;
                                }
                                if (a == "mailbox")
                                {
                                    XmlNode xmlNode3 = xmlNode["FileReference", "AirSyncBase:"];
                                    if (xmlNode3 == null)
                                    {
                                        this.currentProvider = this.ItemFetchProvider;
                                        base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOFetchItems);
                                        goto IL_27E;
                                    }
                                    if (base.Version >= 160 && xmlNode3.InnerText != null && xmlNode3.InnerText.IndexOf("%3a") > 16)
                                    {
                                        this.currentProvider = this.EntityAttachmentFetchProvider;
                                        base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOFetchEntAtts);
                                        goto IL_27E;
                                    }
                                    this.currentProvider = this.AttachmentFetchProvider;
                                    base.ProtocolLogger.IncrementValue(ProtocolLoggerData.IOFetchAtts);
                                    goto IL_27E;
                                }
                            }
                            this.AppendFetchErrorXml(xmlDocument, 9.ToString(CultureInfo.InvariantCulture));
                            base.ProtocolLogger.SetValue(ProtocolLoggerData.StatusCode, 9);
                        }
IL_3C0:
                        i++;
                        continue;
Block_15:
                        try
                        {
IL_27E:
                            this.currentProvider.ParseRequest(xmlNode);
                            this.currentProvider.Execute();
                            if (base.Request.AcceptMultiPartResponse && this.currentProvider is IMultipartResponse)
                            {
                                IMultipartResponse multipartResponse = this.currentProvider as IMultipartResponse;
                                multipartResponse.BuildResponse(this.responseNode, this.multipartStreams.Count + 1);
                                Stream responseStream = multipartResponse.GetResponseStream();
                                if (responseStream != null)
                                {
                                    this.multipartStreams.Add(responseStream);
                                }
                            }
                            else
                            {
                                this.currentProvider.BuildResponse(this.responseNode);
                            }
                            this.currentProvider.Reset();
                        }
                        catch (AirSyncPermanentException ex)
                        {
                            base.ProtocolLogger.SetValue(ProtocolLoggerData.StatusCode, (int)ex.AirSyncStatusCode);
                            if (ex.HttpStatusCode != HttpStatusCode.OK)
                            {
                                throw;
                            }
                            base.ProtocolLogger.SetValueIfNotSet(ProtocolLoggerData.Error, ex.ErrorStringForProtocolLogger);
                            AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
                            AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.ProtocolTracer, this, "AirSyncPermanentException was thrown. Location Execute.\r\n{0}", arg);
                            if (base.MailboxLogger != null)
                            {
                                base.MailboxLogger.SetData(MailboxLogDataName.ItemOperationsCommand_Execute_Fetch_Exception, ex);
                            }
                            this.currentProvider.BuildErrorResponse(ex.AirSyncStatusCodeInInt.ToString(CultureInfo.InvariantCulture), this.responseNode, base.ProtocolLogger);
                            this.currentProvider.Reset();
                            base.PartialFailure = true;
                        }
                        goto IL_3C0;
IL_278:
                        AirSyncDiagnostics.Assert(false);
                        goto Block_15;
                    }
                }
                if (base.Request.AcceptMultiPartResponse)
                {
                    this.BuildMultiPartResponse(xmlDocument);
                }
                else
                {
                    base.XmlResponse = xmlDocument;
                }
            }
            finally
            {
                this.DisposeResources();
            }
            return(Command.ExecutionState.Complete);
        }
        public void UpdateFilterState(SyncOperation syncOperation)
        {
            if (syncOperation == null)
            {
                throw new ArgumentNullException("syncOperation");
            }
            if (this.prepopulate)
            {
                return;
            }
            if (this.CustomFilterState == null)
            {
                this.CustomFilterState = new Dictionary <ISyncItemId, DateTimeCustomSyncFilter.FilterState>();
            }
            switch (syncOperation.ChangeType)
            {
            case ChangeType.Add:
            case ChangeType.Change:
            case ChangeType.ReadFlagChange:
            {
                CalendarItem calendarItem = null;
                try
                {
                    calendarItem = (syncOperation.GetItem(new PropertyDefinition[0]).NativeItem as CalendarItem);
                    if (calendarItem == null)
                    {
                        this.UpdateFilterStateWithAddOrChange(syncOperation.Id, false, false, ExDateTime.MinValue);
                    }
                    else if (calendarItem.Recurrence == null)
                    {
                        this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, false, calendarItem.EndTime);
                    }
                    else if (calendarItem.Recurrence.Range is NoEndRecurrenceRange)
                    {
                        this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, true, ExDateTime.MinValue);
                    }
                    else
                    {
                        this.UpdateFilterStateWithAddOrChange(syncOperation.Id, true, true, calendarItem.Recurrence.GetLastOccurrence().EndTime);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ObjectNotFoundException)
                    {
                        if (this.CustomFilterState.ContainsKey(syncOperation.Id))
                        {
                            this.CustomFilterState.Remove(syncOperation.Id);
                        }
                    }
                    else
                    {
                        if (!SyncCommand.IsItemSyncTolerableException(ex))
                        {
                            throw;
                        }
                        StoreId    storeId    = null;
                        string     text       = "Unknown";
                        ExDateTime exDateTime = ExDateTime.MinValue;
                        try
                        {
                            if (calendarItem != null)
                            {
                                storeId    = calendarItem.Id;
                                text       = calendarItem.Subject;
                                exDateTime = calendarItem.StartTime;
                            }
                        }
                        catch
                        {
                        }
                        AirSyncUtility.ExceptionToStringHelper exceptionToStringHelper = new AirSyncUtility.ExceptionToStringHelper(ex);
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Exception was caught in UpdateFilterState. Item id=\"{0}\", subject=\"{1}\", meetingTime={2}\r\n{3}\r\nIgnoring exception and proceeding to next item.", new object[]
                            {
                                (storeId != null) ? storeId : "null",
                                text,
                                exDateTime,
                                exceptionToStringHelper
                            });
                    }
                }
                break;
            }

            case (ChangeType)3:
                break;

            case ChangeType.Delete:
                this.CustomFilterState.Remove(syncOperation.Id);
                return;

            default:
                return;
            }
        }
 internal void Prepopulate(Folder folder)
 {
     if (folder == null)
     {
         throw new ArgumentNullException("folder");
     }
     this.prepopulate = true;
     if (this.CustomFilterState == null)
     {
         this.CustomFilterState = new Dictionary <ISyncItemId, DateTimeCustomSyncFilter.FilterState>();
     }
     using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, null, new PropertyDefinition[]
     {
         ItemSchema.Id,
         CalendarItemInstanceSchema.EndTime,
         CalendarItemBaseSchema.CalendarItemType,
         StoreObjectSchema.ItemClass,
         ItemSchema.Subject,
         CalendarItemInstanceSchema.StartTime
     }))
     {
         bool flag = false;
         while (!flag)
         {
             object[][] rows = queryResult.GetRows(10000);
             flag = (rows.Length == 0);
             for (int i = 0; i < rows.Length; i++)
             {
                 StoreObjectId storeObjectId = null;
                 DateTimeCustomSyncFilter.FilterState filterState = null;
                 ISyncItemId key = null;
                 try
                 {
                     storeObjectId = ((VersionedId)rows[i][0]).ObjectId;
                     string itemClass = rows[i][3] as string;
                     key = MailboxSyncItemId.CreateForNewItem(storeObjectId);
                     if (!this.CustomFilterState.ContainsKey(key))
                     {
                         filterState = new DateTimeCustomSyncFilter.FilterState();
                         this.CustomFilterState[key] = filterState;
                     }
                     else
                     {
                         filterState = this.CustomFilterState[key];
                     }
                     if (!ObjectClass.IsCalendarItem(itemClass))
                     {
                         filterState.IsCalendarItem = false;
                     }
                     else
                     {
                         filterState.IsCalendarItem = true;
                         if (!(rows[i][2] is CalendarItemType))
                         {
                             filterState.IsCalendarItem = false;
                         }
                         else
                         {
                             filterState.IsRecurring = (CalendarItemType.RecurringMaster == (CalendarItemType)rows[i][2]);
                             if (filterState.IsRecurring)
                             {
                                 using (CalendarItem calendarItem = CalendarItem.Bind(folder.Session, storeObjectId))
                                 {
                                     if (calendarItem.Recurrence != null)
                                     {
                                         if (calendarItem.Recurrence.Range is NoEndRecurrenceRange)
                                         {
                                             filterState.DoesRecurrenceEnd = false;
                                         }
                                         else
                                         {
                                             filterState.DoesRecurrenceEnd = true;
                                             OccurrenceInfo lastOccurrence = calendarItem.Recurrence.GetLastOccurrence();
                                             filterState.EndTime = lastOccurrence.EndTime;
                                         }
                                     }
                                     else
                                     {
                                         filterState.IsCalendarItem = false;
                                     }
                                     goto IL_1E6;
                                 }
                             }
                             if (!(rows[i][1] is ExDateTime))
                             {
                                 filterState.IsCalendarItem = false;
                             }
                             else
                             {
                                 filterState.EndTime = (ExDateTime)rows[i][1];
                             }
                             IL_1E6 :;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     if (ex is ObjectNotFoundException)
                     {
                         this.CustomFilterState.Remove(key);
                     }
                     else
                     {
                         if (!SyncCommand.IsItemSyncTolerableException(ex))
                         {
                             throw;
                         }
                         string     text       = "Unknown";
                         ExDateTime exDateTime = ExDateTime.MinValue;
                         try
                         {
                             text       = (rows[i][4] as string);
                             exDateTime = (ExDateTime)rows[i][5];
                         }
                         catch
                         {
                         }
                         AirSyncUtility.ExceptionToStringHelper exceptionToStringHelper = new AirSyncUtility.ExceptionToStringHelper(ex);
                         AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Exception was caught in Prepopulate. Item id=\"{0}\", subject=\"{1}\", meetingTime={2}\r\n{3}\r\nIgnoring exception and proceeding to next item.", new object[]
                         {
                             (storeObjectId != null) ? storeObjectId : "null",
                             text,
                             exDateTime,
                             exceptionToStringHelper
                         });
                         if (filterState != null)
                         {
                             filterState.IsCalendarItem = false;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #13
0
        public IAsyncResult BeginProcessRequest(HttpContext context, IAsyncResult asyncResult, ProxyHandler.ProxiedRequestInfo proxyinfo)
        {
            LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)asyncResult;

            this.proxyInfo = proxyinfo;
            this.remoteUri = this.proxyInfo.RemoteUri;
            this.userName  = this.proxyInfo.User;
            try
            {
                AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest called for serverName: {0}, user {1}", this.remoteUri, this.userName);
                if (!string.Equals(context.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) && !string.Equals(context.Request.HttpMethod, "OPTIONS", StringComparison.OrdinalIgnoreCase))
                {
                    context.Response.StatusCode = 405;
                    lazyAsyncResult.InvokeCallback();
                    return(lazyAsyncResult);
                }
                UriBuilder uriBuilder = new UriBuilder(this.proxyInfo.RemoteUri);
                if (!string.IsNullOrEmpty(context.Request.Url.Query))
                {
                    if (!string.IsNullOrEmpty(context.Request.Url.Fragment))
                    {
                        string str = context.Request.Url.Fragment.Remove(0, 1);
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1) + "%23" + str;
                    }
                    else
                    {
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1);
                    }
                }
                this.cachedUri = uriBuilder.Uri;
                HttpWebRequest httpWebRequest = this.CopyClientRequest(context.Request, this.cachedUri);
                WindowsImpersonationContext windowsImpersonationContext = null;
                IAsyncResult asyncResult2 = null;
                try
                {
                    if (this.proxyInfo.RequiresImpersonation)
                    {
                        windowsImpersonationContext = ((WindowsIdentity)context.User.Identity).Impersonate();
                    }
                    else
                    {
                        NetworkServiceImpersonator.Initialize();
                        windowsImpersonationContext = NetworkServiceImpersonator.Impersonate();
                        httpWebRequest.Credentials  = CredentialCache.DefaultCredentials;
                    }
                    this.backEndWebRequest   = httpWebRequest;
                    this.frontEndResult      = lazyAsyncResult;
                    this.frontEndHttpContext = context;
                    try
                    {
                        this.clientRequestStream = this.frontEndHttpContext.Request.InputStream;
                    }
                    catch (COMException innerException)
                    {
                        this.protocolLogger.SetValue(ProtocolLoggerData.Error, "InputStreamUnavailable");
                        throw new AirSyncPermanentException(HttpStatusCode.ServiceUnavailable, StatusCode.ServerErrorRetryLater, innerException, false);
                    }
                    this.issueTime             = ExDateTime.Now;
                    this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndGetRequestStream;
                    asyncResult2 = this.backEndWebRequest.BeginGetRequestStream(new AsyncCallback(this.BackEndGetRequestStream), null);
                }
                finally
                {
                    if (windowsImpersonationContext != null)
                    {
                        windowsImpersonationContext.Undo();
                        windowsImpersonationContext.Dispose();
                    }
                }
                if (asyncResult2 != null && !asyncResult2.CompletedSynchronously)
                {
                    this.RegisterTimeoutWaitHandle(asyncResult2, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
                AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest caught an exception\r\n{0}", arg);
                if (this.backEndWebRequest != null)
                {
                    this.backEndWebRequest.Abort();
                    this.backEndWebRequest = null;
                }
                if (ex is WebException)
                {
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest swallowing exception and returning HTTP 500");
                    try
                    {
                        this.TryUnregisterTimeoutWaitHandle();
                        this.frontEndHttpContext.Response.StatusCode = 500;
                        this.frontEndResult.InvokeCallback();
                        goto IL_2F0;
                    }
                    catch (HttpException ex2)
                    {
                        AirSyncUtility.ExceptionToStringHelper arg2 = new AirSyncUtility.ExceptionToStringHelper(ex2);
                        AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "HttpException was thrown while setting the StatusCode.\r\n{0}", arg2);
                        goto IL_2F0;
                    }
                    goto IL_2EE;
IL_2F0:
                    return(lazyAsyncResult);
                }
IL_2EE:
                throw;
            }
            return(lazyAsyncResult);
        }
Пример #14
0
 private void BackEndGetResponse(IAsyncResult asynchronousResult)
 {
     lock (this)
     {
         if (this.requestWasTimedOut)
         {
             AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndGetResponse() Request was timed out while waiting for lock!");
             string text = this.remoteUri.Host.ToString();
             AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_ProxyResultTimedOut, text, new string[]
             {
                 text
             });
             return;
         }
     }
     try
     {
         AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndGetResponse called for serverName: {0}, user {1}", this.remoteUri, this.userName);
         this.UnregisterTimeoutWaitHandle();
         try
         {
             this.httpWebResponse = (HttpWebResponse)this.backEndWebRequest.EndGetResponse(asynchronousResult);
         }
         catch (WebException ex)
         {
             if (ex.Status == WebExceptionStatus.ProtocolError)
             {
                 HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
                 if (httpWebResponse == null)
                 {
                     this.HandleException(ex);
                     return;
                 }
                 if (httpWebResponse.StatusCode == (HttpStatusCode)441)
                 {
                     httpWebResponse.Close();
                     if (!this.proxyInfo.AttemptProxyLogin)
                     {
                         AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "BackEndGetResponse(): authentication failure for {0}.", this.userName);
                         this.TryUnregisterTimeoutWaitHandle();
                         this.frontEndHttpContext.Response.StatusCode = 403;
                         this.frontEndResult.InvokeCallback();
                         return;
                     }
                     AirSyncDiagnostics.Assert(!this.proxyInfo.RequiresImpersonation && this.proxyInfo.AdditionalHeaders != null);
                     AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "BackEndGetResponse(): proxy login required for {0}.", this.userName);
                     if (this.proxyLoginAttempts > 0)
                     {
                         AirSyncDiagnostics.TraceFunction(ExTraceGlobals.RequestsTracer, this, "BackEndGetResponse(): too many login attempts.");
                         this.protocolLogger.SetValue(ProtocolLoggerData.Error, "TooManyProxyLoginAttempts");
                         this.TryUnregisterTimeoutWaitHandle();
                         this.frontEndHttpContext.Response.StatusCode = 403;
                         this.frontEndResult.InvokeCallback();
                         return;
                     }
                     this.proxyLoginAttempts++;
                     this.IssueProxyLoginRequest();
                     return;
                 }
                 else
                 {
                     if (httpWebResponse.Headers != null)
                     {
                         WebHeaderCollection headers = httpWebResponse.Headers;
                         string text2 = headers["WWW-Authenticate"];
                         if (text2 != null && text2.IndexOf("Negotiate ") == -1)
                         {
                             if (this.HasBeenProxiedByMServ)
                             {
                                 this.protocolLogger.SetValue(ProtocolLoggerData.Error, "Datacenter Config issue upon MServ proxy");
                             }
                             else
                             {
                                 this.protocolLogger.SetValue(ProtocolLoggerData.Error, "NTLM not on the destination CAS");
                                 string text3 = this.proxyInfo.RemoteUri.Host.ToString();
                                 AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_SecondCasFailureNTLM, text3, new string[]
                                 {
                                     text3
                                 });
                             }
                         }
                     }
                     this.httpWebResponse = httpWebResponse;
                 }
             }
             else
             {
                 if (ex.Status == WebExceptionStatus.TrustFailure)
                 {
                     AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "SSL Certification failed for {0}.", this.proxyInfo.RemoteUri.Host);
                     this.protocolLogger.SetValue(ProtocolLoggerData.Error, "SSL Certification Failed.");
                     string text4 = this.proxyInfo.RemoteUri.Host.ToString();
                     AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_SecondCasFailureSSL, text4, new string[]
                     {
                         text4
                     });
                     this.HandleException(ex);
                     return;
                 }
                 this.HandleException(ex);
                 return;
             }
         }
         if (GlobalSettings.ProxyHeaders != null && GlobalSettings.ProxyHeaders.Length > 0)
         {
             this.frontEndHttpContext.Response.ContentType = string.Empty;
             for (int i = 0; i < this.httpWebResponse.Headers.Count; i++)
             {
                 string text5 = this.httpWebResponse.Headers.Keys[i];
                 for (int j = 0; j < GlobalSettings.ProxyHeaders.Length; j++)
                 {
                     if (string.Equals(text5, GlobalSettings.ProxyHeaders[j], StringComparison.OrdinalIgnoreCase))
                     {
                         this.frontEndHttpContext.Response.AppendHeader(text5, this.httpWebResponse.Headers[text5]);
                     }
                 }
             }
         }
         this.backEndResponseStream = this.httpWebResponse.GetResponseStream();
         this.frontEndHttpContext.Response.StatusCode        = (int)this.httpWebResponse.StatusCode;
         this.frontEndHttpContext.Response.StatusDescription = this.httpWebResponse.StatusDescription;
         this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndReadContent;
         IAsyncResult asyncResult = this.backEndResponseStream.BeginRead(this.asyncBuffer, 0, this.asyncBuffer.Length, new AsyncCallback(this.BackEndReadContent), null);
         if (!asyncResult.CompletedSynchronously)
         {
             this.RegisterTimeoutWaitHandle(asyncResult, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
         }
     }
     catch (Exception ex2)
     {
         AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex2);
         AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BackEndGetResponse caught an exception\r\n{0}", arg);
         if (this.backEndWebRequest != null)
         {
             this.backEndWebRequest.Abort();
             this.backEndWebRequest = null;
         }
         this.HandleException(ex2);
     }
 }