Exemple #1
0
 internal HttpResponseMessage TearDown(HttpResponseMessage message)
 {
     if (Tracer.IsDisposed)
     {
         return(message);
     }
     Tracer.Dispose();
     AddSupportCode(message);
     Runtime.TearDown(Request.RequestUri.AbsoluteUri);
     AppendHeaders(message);
     return(message);
 }
 public virtual void TearDown()
 {
     if (IsEnded)
     {
         return;
     }
     IsEnded = true;
     if (!Tracer.IsDisposed)
     {
         Tracer.Dispose();
         Runtime.TearDown("");
     }
 }
 internal void TearDown()
 {
     if (Tracer.IsDisposed)
     {
         return;
     }
     Tracer.Dispose();
     AddSupportCode();
     Runtime.TearDown("");
     if (Runtime.Context.GetEnvironmentConfiguration().GetConfigParameter("AddPerformanceInfo") != "false")
     {
         Response.Headers.Add(BaseApiController.PerfHeaderName, Runtime.CallStack.ExecutionTime.ToString());
     }
 }
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         GC.SuppressFinalize(this);
     }
     Container.Dispose();
     Container = null;
     Tracer.Dispose();
     Tracer = null;
 }
        private Result OnGetFileStream(
            ulong commandId,
            string relativePath,
            byte[] providerId,
            byte[] contentId,
            int triggeringProcessId,
            string triggeringProcessName,
            IntPtr fileHandle)
        {
            try
            {
                if (contentId == null)
                {
                    this.Context.Tracer.RelatedError($"{nameof(this.OnGetFileStream)} called with null contentId, path: " + relativePath);
                    return(Result.EInvalidOperation);
                }

                if (providerId == null)
                {
                    this.Context.Tracer.RelatedError($"{nameof(this.OnGetFileStream)} called with null epochId, path: " + relativePath);
                    return(Result.EInvalidOperation);
                }

                string sha = GetShaFromContentId(contentId);
                byte   placeholderVersion = GetPlaceholderVersionFromProviderId(providerId);

                EventMetadata metadata = this.CreateEventMetadata(relativePath);
                metadata.Add(nameof(triggeringProcessId), triggeringProcessId);
                metadata.Add(nameof(triggeringProcessName), triggeringProcessName);
                metadata.Add(nameof(sha), sha);
                metadata.Add(nameof(placeholderVersion), placeholderVersion);
                metadata.Add(nameof(commandId), commandId);
                ITracer activity = this.Context.Tracer.StartActivity("GetFileStream", EventLevel.Verbose, Keywords.Telemetry, metadata);

                if (!this.FileSystemCallbacks.IsMounted)
                {
                    metadata.Add(TracingConstants.MessageKey.InfoMessage, $"{nameof(this.OnGetFileStream)} failed, mount has not yet completed");
                    activity.RelatedEvent(EventLevel.Informational, $"{nameof(this.OnGetFileStream)}_MountNotComplete", metadata);
                    activity.Dispose();

                    // TODO: Is this the correct Result to return?
                    return(Result.EIOError);
                }

                if (placeholderVersion != FileSystemVirtualizer.PlaceholderVersion)
                {
                    activity.RelatedError(metadata, nameof(this.OnGetFileStream) + ": Unexpected placeholder version");
                    activity.Dispose();

                    // TODO: Is this the correct Result to return?
                    return(Result.EIOError);
                }

                try
                {
                    if (!this.GitObjects.TryCopyBlobContentStream(
                            sha,
                            CancellationToken.None,
                            GVFSGitObjects.RequestSource.FileStreamCallback,
                            (stream, blobLength) =>
                    {
                        // TODO(Mac): Find a better solution than reading from the stream one byte at at time
                        byte[] buffer = new byte[4096];
                        uint bufferIndex = 0;
                        int nextByte = stream.ReadByte();
                        while (nextByte != -1)
                        {
                            while (bufferIndex < buffer.Length && nextByte != -1)
                            {
                                buffer[bufferIndex] = (byte)nextByte;
                                nextByte = stream.ReadByte();
                                ++bufferIndex;
                            }

                            Result result = this.virtualizationInstance.WriteFileContents(
                                fileHandle,
                                buffer,
                                bufferIndex);
                            if (result != Result.Success)
                            {
                                activity.RelatedError(metadata, $"{nameof(this.virtualizationInstance.WriteFileContents)} failed, error: " + result.ToString("X") + "(" + result.ToString("G") + ")");
                                throw new GetFileStreamException(result);
                            }

                            if (bufferIndex == buffer.Length)
                            {
                                bufferIndex = 0;
                            }
                        }
                    }))
                    {
                        activity.RelatedError(metadata, $"{nameof(this.OnGetFileStream)}: TryCopyBlobContentStream failed");

                        // TODO: Is this the correct Result to return?
                        return(Result.EFileNotFound);
                    }
                }
                catch (GetFileStreamException e)
                {
                    return(e.Result);
                }

                return(Result.Success);
            }
            catch (Exception e)
            {
                EventMetadata metadata = this.CreateEventMetadata(relativePath, e);
                metadata.Add(nameof(triggeringProcessId), triggeringProcessId);
                metadata.Add(nameof(triggeringProcessName), triggeringProcessName);
                metadata.Add(nameof(commandId), commandId);
                this.LogUnhandledExceptionAndExit(nameof(this.OnGetFileStream), metadata);
            }

            return(Result.EIOError);
        }
        private Result OnGetFileStream(
            ulong commandId,
            string relativePath,
            byte[] providerId,
            byte[] contentId,
            int triggeringProcessId,
            string triggeringProcessName,
            IntPtr fileHandle)
        {
            try
            {
                if (contentId == null)
                {
                    this.Context.Tracer.RelatedError($"{nameof(this.OnGetFileStream)} called with null contentId, path: " + relativePath);
                    return(Result.EInvalidOperation);
                }

                if (providerId == null)
                {
                    this.Context.Tracer.RelatedError($"{nameof(this.OnGetFileStream)} called with null epochId, path: " + relativePath);
                    return(Result.EInvalidOperation);
                }

                string sha = GetShaFromContentId(contentId);
                byte   placeholderVersion = GetPlaceholderVersionFromProviderId(providerId);

                EventMetadata metadata = this.CreateEventMetadata(relativePath);
                metadata.Add(nameof(triggeringProcessId), triggeringProcessId);
                metadata.Add(nameof(triggeringProcessName), triggeringProcessName);
                metadata.Add(nameof(sha), sha);
                metadata.Add(nameof(placeholderVersion), placeholderVersion);
                metadata.Add(nameof(commandId), commandId);
                ITracer activity = this.Context.Tracer.StartActivity("GetFileStream", EventLevel.Verbose, Keywords.Telemetry, metadata);

                if (placeholderVersion != FileSystemVirtualizer.PlaceholderVersion)
                {
                    activity.RelatedError(metadata, nameof(this.OnGetFileStream) + ": Unexpected placeholder version");
                    activity.Dispose();

                    // TODO(#1362): Is this the correct Result to return?
                    return(Result.EIOError);
                }

                try
                {
                    if (!this.GitObjects.TryCopyBlobContentStream(
                            sha,
                            CancellationToken.None,
                            GVFSGitObjects.RequestSource.FileStreamCallback,
                            (stream, blobLength) =>
                    {
                        // TODO(#1361): Find a better solution than reading from the stream one byte at at time
                        byte[] buffer = new byte[4096];
                        uint bufferIndex = 0;
                        int nextByte = stream.ReadByte();
                        int bytesWritten = 0;
                        while (nextByte != -1)
                        {
                            while (bufferIndex < buffer.Length && nextByte != -1)
                            {
                                buffer[bufferIndex] = (byte)nextByte;
                                nextByte = stream.ReadByte();
                                ++bufferIndex;
                            }

                            Result result = this.virtualizationInstance.WriteFileContents(
                                fileHandle,
                                buffer,
                                bufferIndex);
                            if (result != Result.Success)
                            {
                                activity.RelatedError(metadata, $"{nameof(this.virtualizationInstance.WriteFileContents)} failed, error: " + result.ToString("X") + "(" + result.ToString("G") + ")");
                                throw new GetFileStreamException(result);
                            }

                            if (bufferIndex == buffer.Length)
                            {
                                bufferIndex = 0;
                                bytesWritten += buffer.Length;
                            }
                        }
                        bytesWritten += Convert.ToInt32(bufferIndex);

                        if (bytesWritten != blobLength)
                        {
                            // If the read size does not match the expected size print an error and add the file to ModifiedPaths.dat
                            // This allows the user to see that something went wrong with file hydration
                            // Unfortunitely we must do this check *after* the file is hydrated since the header isn't corrupt for trunctated objects on mac
                            this.Context.Tracer.RelatedError($"Read {relativePath} to {bytesWritten}, not expected size of {blobLength}");
                            this.FileSystemCallbacks.OnFailedFileHydration(relativePath);
                        }
                    }))
                    {
                        activity.RelatedError(metadata, $"{nameof(this.OnGetFileStream)}: TryCopyBlobContentStream failed");

                        // TODO(#1362): Is this the correct Result to return?
                        return(Result.EFileNotFound);
                    }
                }
                catch (GetFileStreamException e)
                {
                    return(e.Result);
                }

                this.FileSystemCallbacks.OnPlaceholderFileHydrated(triggeringProcessName);
                return(Result.Success);
            }
            catch (Exception e)
            {
                EventMetadata metadata = this.CreateEventMetadata(relativePath, e);
                metadata.Add(nameof(triggeringProcessId), triggeringProcessId);
                metadata.Add(nameof(triggeringProcessName), triggeringProcessName);
                metadata.Add(nameof(commandId), commandId);
                this.LogUnhandledExceptionAndExit(nameof(this.OnGetFileStream), metadata);
            }

            return(Result.EIOError);
        }
Exemple #7
0
 protected virtual void TearDown()
 {
     Tracer.Dispose();
 }