Beispiel #1
0
 public void ProcessRequest(Stream requestStream, Stream responseStream, Action <Enum, string> logDetail)
 {
     if (this.permanentException != null)
     {
         throw new CobaltStore.OrphanedCobaltStoreException(string.Format("The attachment is no longer available for CobaltStore {0}.", this.correlationId), this.permanentException);
     }
     try
     {
         Stopwatch stopwatch = new Stopwatch();
         stopwatch.Start();
         if (!Monitor.TryEnter(this.synchronizationObject, TimeSpan.FromSeconds(15.0)))
         {
             throw new Exception("Unable to acquire CobaltStore lock.");
         }
         stopwatch.Stop();
         logDetail(WacRequestHandlerMetadata.LockWaitTime, stopwatch.ElapsedMilliseconds.ToString());
         using (DisposalEscrow disposalEscrow = new DisposalEscrow("CobaltStore.ProcessRequest"))
         {
             using (Stream stream = new MemoryStream(65536))
             {
                 requestStream.CopyTo(stream, 65536);
                 stream.Position = 0L;
                 logDetail(WacRequestHandlerMetadata.CobaltRequestLength, stream.Length.ToString());
                 CobaltFile cobaltFile = this.CreateCobaltFile(disposalEscrow, false);
                 this.SaveDiagnosticDocument(cobaltFile, "BeforeRoundTrip.bin");
                 this.SaveDiagnosticStream(requestStream, "Request.xml");
                 using (DisposableAtomFromStream disposableAtomFromStream = new DisposableAtomFromStream(stream))
                 {
                     Roundtrip roundtrip       = cobaltFile.CobaltEndpoint.CreateRoundtrip();
                     bool      exceptionThrown = false;
                     Atom      atom            = null;
                     Stopwatch stopwatch2      = new Stopwatch();
                     stopwatch2.Start();
                     try
                     {
                         object          obj;
                         ProtocolVersion protocolVersion;
                         roundtrip.DeserializeInputFromProtocol(disposableAtomFromStream, ref obj, ref protocolVersion);
                         roundtrip.Execute();
                         cobaltFile.CommitChanges();
                         atom = roundtrip.SerializeOutputToProtocol(1, obj, null);
                     }
                     catch (Exception)
                     {
                         exceptionThrown = true;
                         throw;
                     }
                     finally
                     {
                         stopwatch2.Stop();
                         logDetail(WacRequestHandlerMetadata.CobaltTime, stopwatch2.ElapsedMilliseconds.ToString());
                         this.LogBlobStoreMetrics(logDetail, cobaltFile);
                         this.LogRequestDetails(logDetail, roundtrip, exceptionThrown);
                     }
                     this.UpdateEditorCount(roundtrip.RequestBatch);
                     this.SaveDiagnosticDocument(cobaltFile, "AfterRoundTrip.bin");
                     atom.CopyTo(responseStream);
                     logDetail(WacRequestHandlerMetadata.CobaltResponseLength, atom.Length.ToString());
                     if (this.diagnosticsEnabled)
                     {
                         using (MemoryStream memoryStream = new MemoryStream())
                         {
                             atom.CopyTo(memoryStream);
                             this.SaveDiagnosticStream(memoryStream, "Response.xml");
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         if (Monitor.IsEntered(this.synchronizationObject))
         {
             Monitor.Exit(this.synchronizationObject);
         }
     }
 }