public static PdbSrcSrvSection Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
                return null;

            var result = new PdbSrcSrvSection();

            string ini = text.Remove(0, text.IndexOf(SrcSrvIni) + SrcSrvIni.Length);
            ini = ini.Remove(ini.IndexOf(SrcSrvVariables)).Trim();
            string variables = text.Remove(0, text.IndexOf(SrcSrvVariables) + SrcSrvVariables.Length);
            variables = variables.Remove(variables.IndexOf(SrcSrvSources)).Trim();
            string sources = text.Remove(0, text.IndexOf(SrcSrvSources) + SrcSrvSources.Length);
            sources = sources.Remove(sources.IndexOf(SrcSrvEnd)).Trim();

            foreach (string line in ini.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
                result.Ini.Add(line.Remove(line.IndexOf("=")), line.Substring(line.IndexOf("=") + 1));

            foreach (string line in variables.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
                result.Variables.Add(line.Remove(line.IndexOf("=")), line.Substring(line.IndexOf("=") + 1));

            foreach (string line in sources.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
                result.Sources.Add(new List<string>(line.Split('*')));

            return result;
        }
        public PdbSrcSrvSection ReadSrcSrv(string pdbFilePath)
        {
            using (var pdbstrProcess = processFactory.Create(PdbStrPath(), "-r", string.Format(@"-p:""{0}""", pdbFilePath), "-s:srcsrv"))
            {
                pdbstrProcess.StartInfo.RedirectStandardOutput = true;
                pdbstrProcess.Start();

                string result = pdbstrProcess.StandardOutput.ReadToEnd();
                pdbstrProcess.WaitForExit();
                return(PdbSrcSrvSection.Parse(result));
            }
        }
        public void WriteSrcSrv(string pdbFilePath, PdbSrcSrvSection srcSrvSection)
        {
            string tempFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempFile, srcSrvSection.ToString());

                using (var pdbstrProcess = processFactory.Create(PdbStrPath(), "-w", string.Format(@"-p:""{0}""", pdbFilePath), string.Format(@"-i:""{0}""", tempFile), "-s:srcsrv"))
                {
                    pdbstrProcess.Start();
                    pdbstrProcess.WaitForExit();
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
        public void WriteSrcSrv(string pdbFilePath, PdbSrcSrvSection srcSrvSection)
        {
            string tempFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempFile, srcSrvSection.ToString());

                using (var pdbstrProcess = processFactory.Create(PdbStrPath(), "-w", string.Format(@"-p:""{0}""", pdbFilePath), string.Format(@"-i:""{0}""", tempFile), "-s:srcsrv"))
                {
                    pdbstrProcess.Start();
                    pdbstrProcess.WaitForExit();
                }
            }
            finally
            {
                File.Delete(tempFile);
            }          
        }
        public static PdbSrcSrvSection Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            var result = new PdbSrcSrvSection();

            string ini = text.Remove(0, text.IndexOf(SrcSrvIni) + SrcSrvIni.Length);

            ini = ini.Remove(ini.IndexOf(SrcSrvVariables)).Trim();
            string variables = text.Remove(0, text.IndexOf(SrcSrvVariables) + SrcSrvVariables.Length);

            variables = variables.Remove(variables.IndexOf(SrcSrvSources)).Trim();
            string sources = text.Remove(0, text.IndexOf(SrcSrvSources) + SrcSrvSources.Length);

            sources = sources.Remove(sources.IndexOf(SrcSrvEnd)).Trim();

            foreach (string line in ini.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
            {
                result.Ini.Add(line.Remove(line.IndexOf("=")), line.Substring(line.IndexOf("=") + 1));
            }

            foreach (string line in variables.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
            {
                result.Variables.Add(line.Remove(line.IndexOf("=")), line.Substring(line.IndexOf("=") + 1));
            }

            foreach (string line in sources.Split('\n').Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
            {
                result.Sources.Add(new List <string>(line.Split('*')));
            }

            return(result);
        }
        private ActionResult PdbFile(IWinDbgBackend backend, ImageFile imageFile, string sourcePath)
        {
            var directoryPathTemp = Path.Combine(Path.GetTempPath(), "hss-temp-" + Path.GetRandomFileName());
            Directory.CreateDirectory(directoryPathTemp);

            var link = backend.GetSymbolFileLink(ref imageFile);
            var tempPath = Path.Combine(directoryPathTemp, imageFile.Name + ".pdb");
            var temp2Path = Path.Combine(directoryPathTemp, imageFile.Name + ".pd_");

            try
            {
                DownloadFile(link, tempPath);

                var pdbstr = new PdbSrcSrvSection();

                pdbstr.Ini.Add("VERSION", "2");
                pdbstr.Ini.Add("INDEXVERSION", "2");
                //TODO: jaka jest idea tych podmian, zamiast od razu wkleić %cośtam%?
                pdbstr.Variables.Add("SRCSRVTRG", sourcePath.Replace("XVAR2X", "%var2%").Replace("XCNX", "%CN%").Replace("XUNX", "%UN%"));
                pdbstr.Variables.Add("SRCSRVCMD", string.Empty);
                pdbstr.Variables.Add("UN", "%USERNAME%");
                pdbstr.Variables.Add("CN", "%COMPUTERNAME%");
                pdbstr.Variables.Add("SRCSRVVERCTRL", "http");
                pdbstr.Variables.Add("SRCSRVERRVAR", "var2");
                pdbstr.Ini.Add("VERCTRL", "http");

                var sources = backend.GetSourceFileList(ref imageFile);

                foreach (var source in sources)
                    pdbstr.Sources.Add(new[] { source.OriginalPath, source.Path, source.Hash });

                pdbStoreManager.WriteSrcSrv(tempPath, pdbstr);
                fileCompressor.Compress(tempPath, temp2Path);

                return File(System.IO.File.ReadAllBytes(temp2Path), "application/octet-stream");
            }
            finally
            {
                System.IO.File.Delete(tempPath);
                System.IO.File.Delete(temp2Path);
                Directory.Delete(directoryPathTemp);
            }
        }