/// <summary> /// Create an instance of a http symbol store /// </summary> /// <param name="backingStore">next symbol store or null</param> /// <param name="symbolServerUri">symbol server url</param> /// <param name="personalAccessToken">optional PAT or null if no authentication</param> public HttpSymbolStore(ITracer tracer, SymbolStore backingStore, Uri symbolServerUri, string personalAccessToken = null) : base(tracer, backingStore) { Uri = symbolServerUri ?? throw new ArgumentNullException(nameof(symbolServerUri)); if (!symbolServerUri.IsAbsoluteUri || symbolServerUri.IsFile) { throw new ArgumentException(nameof(symbolServerUri)); } // Normal unauthenticated client _client = new HttpClient { Timeout = TimeSpan.FromMinutes(4) }; // If PAT, create authenticated client if (!string.IsNullOrEmpty(personalAccessToken)) { var handler = new HttpClientHandler() { AllowAutoRedirect = false }; var client = new HttpClient(handler) { Timeout = TimeSpan.FromMinutes(4) }; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken)))); _authenticatedClient = client; } }
/// <summary> /// Sets a new store store head. /// </summary> /// <param name="store">symbol store (server, cache, directory, etc.)</param> private void SetSymbolStore(Microsoft.SymbolStore.SymbolStores.SymbolStore store) { if (store != _symbolStore) { OnChangeEvent.Fire(); _symbolStore = store; } }
/// <summary> /// Displays the symbol server and cache configuration /// </summary> public override string ToString() { StringBuilder sb = new StringBuilder(); Microsoft.SymbolStore.SymbolStores.SymbolStore symbolStore = _symbolStore; while (symbolStore != null) { sb.AppendLine(symbolStore.ToString()); symbolStore = symbolStore.BackingStore; } return(sb.ToString()); }
protected void ForEachSymbolStore <T>(Action <T> callback) where T : Microsoft.SymbolStore.SymbolStores.SymbolStore { Microsoft.SymbolStore.SymbolStores.SymbolStore symbolStore = _symbolStore; while (symbolStore != null) { if (symbolStore is T store) { callback(store); } symbolStore = symbolStore.BackingStore; } }
/// <summary> /// Add directory path to symbol search path /// </summary> /// <param name="symbolDirectoryPath">symbol directory path to search (optional)</param> public void AddDirectoryPath(string symbolDirectoryPath) { if (symbolDirectoryPath == null) { throw new ArgumentNullException(nameof(symbolDirectoryPath)); } Microsoft.SymbolStore.SymbolStores.SymbolStore store = _symbolStore; symbolDirectoryPath = Path.GetFullPath(symbolDirectoryPath); if (!IsDuplicateSymbolStore <DirectorySymbolStore>(store, (directorySymbolStore) => IsPathEqual(symbolDirectoryPath, directorySymbolStore.Directory))) { SetSymbolStore(new DirectorySymbolStore(Tracer.Instance, store, symbolDirectoryPath)); } }
private bool IsDuplicateSymbolStore <T>(Microsoft.SymbolStore.SymbolStores.SymbolStore symbolStore, Func <T, bool> match) where T : Microsoft.SymbolStore.SymbolStores.SymbolStore { while (symbolStore != null) { if (symbolStore is T store) { // TODO: replace this by adding an Equal override to the symbol stores if (match(store)) { return(true); } } symbolStore = symbolStore.BackingStore; } return(false); }
/// <summary> /// Add cache path to symbol search path /// </summary> /// <param name="symbolCachePath">symbol cache directory path (optional)</param> public void AddCachePath(string symbolCachePath) { if (symbolCachePath == null) { throw new ArgumentNullException(nameof(symbolCachePath)); } Microsoft.SymbolStore.SymbolStores.SymbolStore store = _symbolStore; symbolCachePath = Path.GetFullPath(symbolCachePath); // Check only the first symbol store for duplication. The same cache directory can be // added more than once but just not more than once in a row. if (!(store is CacheSymbolStore cacheSymbolStore && IsPathEqual(symbolCachePath, cacheSymbolStore.CacheDirectory))) { SetSymbolStore(new CacheSymbolStore(Tracer.Instance, store, symbolCachePath)); } }
/// <summary> /// Create an instance of a http symbol store /// </summary> /// <param name="tracer">trace source for logging</param> /// <param name="backingStore">next symbol store or null</param> /// <param name="symbolServerUri">symbol server url</param> /// <param name="personalAccessToken">PAT or null if no authentication</param> public SymwebHttpSymbolStore(ITracer tracer, SymbolStore backingStore, Uri symbolServerUri, string personalAccessToken = null) : base(tracer, backingStore, symbolServerUri, personalAccessToken) { }
public CacheSymbolStore(ITracer tracer, SymbolStore backingStore, string cacheDirectory) : base(tracer, backingStore) { CacheDirectory = cacheDirectory ?? throw new ArgumentNullException(nameof(cacheDirectory)); }
/// <summary> /// Add symbol server to search path. /// </summary> /// <param name="msdl">if true, use the public Microsoft server</param> /// <param name="symweb">if true, use symweb internal server and protocol (file.ptr)</param> /// <param name="symbolServerPath">symbol server url (optional)</param> /// <param name="authToken"></param> /// <param name="timeoutInMinutes">symbol server timeout in minutes (optional)</param> /// <returns>if false, failure</returns> public bool AddSymbolServer( bool msdl, bool symweb, string symbolServerPath, string authToken, int timeoutInMinutes) { bool internalServer = false; // Add symbol server URL if exists if (symbolServerPath == null) { if (msdl) { symbolServerPath = MsdlSymbolServer; } else if (symweb) { symbolServerPath = SymwebSymbolServer; internalServer = true; } } else { // Use the internal symbol store for symweb internalServer = symbolServerPath.Contains("symweb"); } // Return error if symbol server path is null and msdl and symweb are false. if (symbolServerPath == null) { return(false); } // Validate symbol server path if (!Uri.TryCreate(symbolServerPath.TrimEnd('/') + '/', UriKind.Absolute, out Uri uri)) { return(false); } // Add a cache symbol store if file or UNC path if (uri.IsFile || uri.IsUnc) { AddCachePath(symbolServerPath); } else { Microsoft.SymbolStore.SymbolStores.SymbolStore store = _symbolStore; if (!IsDuplicateSymbolStore <HttpSymbolStore>(store, (httpSymbolStore) => uri.Equals(httpSymbolStore.Uri))) { // Create http symbol server store HttpSymbolStore httpSymbolStore; if (internalServer) { httpSymbolStore = new SymwebHttpSymbolStore(Tracer.Instance, store, uri); } else { httpSymbolStore = new HttpSymbolStore(Tracer.Instance, store, uri, personalAccessToken: authToken); } if (timeoutInMinutes != 0) { httpSymbolStore.Timeout = TimeSpan.FromMinutes(timeoutInMinutes); } SetSymbolStore(httpSymbolStore); } } return(true); }
public SymbolStore(ITracer tracer, SymbolStore backingStore) : this(tracer) { BackingStore = backingStore; }