Esempio n. 1
0
        /// <summary>
        /// Fetches a file from the server 'serverPath' weith pdb signature path 'pdbSigPath' and places it in its
        /// correct location in 'symbolCacheDir'  Will return the path of the cached copy if it succeeds, null otherwise.  
        /// 
        /// You should probably be using GetFileFromServer
        /// </summary>
        /// <param name="serverPath">path to server (eg. \\symbols\symbols or http://symweb) </param>
        /// <param name="pdbIndexPath">pdb path with signature (e.g clr.pdb/1E18F3E494DC464B943EA90F23E256432/clr.pdb)</param>
        /// <param name="symbolCacheDir">path to the symbol cache where files are fetched (e.g. %TEMP%\symbols) </param>
        /// <param name="notification">A callback to provide progress updates.</param>
        private string GetPhysicalFileFromServer(string serverPath, string pdbIndexPath, string symbolCacheDir, ISymbolNotification notification)
        {
            if (string.IsNullOrEmpty(serverPath))
                return null;

            var fullDestPath = Path.Combine(symbolCacheDir, pdbIndexPath);
            if (!File.Exists(fullDestPath))
            {
                if (serverPath.StartsWith("http:"))
                {
                    var fullUri = serverPath + "/" + pdbIndexPath.Replace('\\', '/');
                    try
                    {
                        var req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(fullUri);
                        req.UserAgent = "Microsoft-Symbol-Server/6.13.0009.1140";
                        var responce = req.GetResponse();
                        var fromStream = responce.GetResponseStream();
                        var dirName = Path.GetDirectoryName(fullDestPath);

                        notification.FoundSymbolOnPath(fullUri);
                        CopyStreamToFile(fromStream, fullUri, fullDestPath, notification);
                    }
                    catch (Exception e)
                    {
                        notification.ProbeFailed(fullUri);
                        _log.WriteLine("Probe of {0} failed: {1}", fullUri, e.Message);
                        return null;
                    }
                }
                else
                {
                    var fullSrcPath = Path.Combine(serverPath, pdbIndexPath);
                    if (!File.Exists(fullSrcPath))
                        return null;

                    Directory.CreateDirectory(Path.GetDirectoryName(fullDestPath));
                    File.Copy(fullSrcPath, fullDestPath);
                    notification.FoundSymbolInCache(fullDestPath);
                }
            }
            else
            {
                notification.FoundSymbolInCache(fullDestPath);
            }
            return fullDestPath;
        }