Exemple #1
0
        private void HttpDumpLoadAction(IDEContext r, int id = -1)
        {
            // get the dump file
            DumpFileInfo di = null;

            using (dumpFiles.EnterReadLock())
            {
                var index = dumpFiles.FindIndex(c => c.Id == id);
                if (index >= 0)
                {
                    di = dumpFiles[index];
                }
            }

            // send the file
            if (di == null)
            {
                throw new ArgumentException("dump id is wrong.");
            }
            var fi = new FileInfo(di.FileName);

            if (!fi.Exists)
            {
                throw new ArgumentException("dump id is invalid.");
            }

            r.SetAttachment(fi.Name)
            .WriteFile(fi.FullName, MimeTypes.Application.OctetStream + ";gzip");
        }         // HttpDumpLoadAction
Exemple #2
0
        private XElement HttpDumpAction(bool mini = false)
        {
            // check for the procdump.exe
            var procDump = Config.Element(xnServer)?.GetAttribute("procdump", String.Empty);

            if (String.IsNullOrEmpty(procDump) || !File.Exists(procDump))
            {
                throw new ArgumentException("procdump.exe is not available.");
            }

            // prepare arguments
            var sbArgs = new StringBuilder();

            if (!mini)
            {
                sbArgs.Append("-ma ");                                 // dump all
            }
            sbArgs.Append("-o ");                                      // overwrite existing dump
            sbArgs.Append("-accepteula ");                             // accept eula
            sbArgs.Append(Process.GetCurrentProcess().Id).Append(' '); // process id

            // create the dump in the temp directory
            DumpFileInfo fi;

            using (dumpFiles.EnterWriteLock())
            {
                var newId = ++lastDumpFileInfoId;
                dumpFiles.Add(fi = new DumpFileInfo(newId, Path.Combine(Path.GetTempPath(), $"DEServer_{newId:000}.dmp")));
            }

            sbArgs.Append(fi.FileName);

            // prepare calling procdump
            ProcessStartInfo psi = new ProcessStartInfo(procDump, sbArgs.ToString());

            psi.UseShellExecute        = false;
            psi.RedirectStandardOutput = true;
            using (var p = Process.Start(psi))
            {
                if (!p.WaitForExit(5 * 60 + 1000))
                {
                    p.Kill();
                }

                var outputText = p.StandardOutput.ReadToEnd();

                return(DEConfigItem.SetStatusAttributes(
                           new XElement("return",
                                        new XAttribute("id", fi.Id),
                                        new XAttribute("exitcode", p.ExitCode)
                                        ),
                           p.ExitCode > 0,
                           outputText
                           ));
            }
        }         // proc HttpDumpAction