public HttpResponseMessage MiniDump(int id, int dumpType = 0)
        {
            using (_tracer.Step("ProcessController.MiniDump"))
            {
                var process = GetProcessById(id);

                string dumpFile = Path.Combine(_environment.TempPath, "minidump.dmp");
                FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);

                try
                {
                    _tracer.Trace("MiniDump pid={0}, name={1}, file={2}", process.Id, process.ProcessName, dumpFile);
                    process.MiniDump(dumpFile, (MINIDUMP_TYPE)dumpType);
                    _tracer.Trace("MiniDump size={0}", new FileInfo(dumpFile).Length);
                }
                catch
                {
                    FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);
                    throw;
                }

                HttpResponseMessage response = Request.CreateResponse();
                response.Content = new StreamContent(MiniDumpStream.OpenRead(dumpFile, _fileSystem));
                response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("{0}-{1:MM-dd-H:mm:ss}.dmp", process.ProcessName, DateTime.UtcNow);
                return(response);
            }
        }
Пример #2
0
        public HttpResponseMessage MiniDump(int id, int dumpType = 0)
        {
            using (_tracer.Step("ProcessController.MiniDump"))
            {
                string sitePolicy = _settings.GetWebSitePolicy();
                if ((MINIDUMP_TYPE)dumpType == MINIDUMP_TYPE.WithFullMemory && sitePolicy.Equals(FreeSitePolicy, StringComparison.OrdinalIgnoreCase))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                                                       String.Format(CultureInfo.CurrentCulture, Resources.Error_FullMiniDumpNotSupported, sitePolicy)));
                }

                var process = GetProcessById(id);

                string dumpFile = Path.Combine(_environment.LogFilesPath, "minidump", "minidump.dmp");
                FileSystemHelpers.EnsureDirectory(Path.GetDirectoryName(dumpFile));
                FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);

                try
                {
                    _tracer.Trace("MiniDump pid={0}, name={1}, file={2}", process.Id, process.ProcessName, dumpFile);
                    process.MiniDump(dumpFile, (MINIDUMP_TYPE)dumpType);
                    _tracer.Trace("MiniDump size={0}", new FileInfo(dumpFile).Length);
                }
                catch (Exception ex)
                {
                    FileSystemHelpers.DeleteFileSafe(_fileSystem, dumpFile);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                HttpResponseMessage response = Request.CreateResponse();
                response.Content = new StreamContent(MiniDumpStream.OpenRead(dumpFile, _fileSystem));
                response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("{0}-{1:MM-dd-H:mm:ss}.dmp", process.ProcessName, DateTime.UtcNow);
                return(response);
            }
        }