public async Task <IODataAdapter> ResolveAdapterAsync(CancellationToken cancellationToken) { if (this.MetadataCache == null) { if (string.IsNullOrEmpty(Settings.MetadataDocument)) { this.MetadataCache = await EdmMetadataCache.GetOrAddAsync( this.Settings.BaseUri.AbsoluteUri, async uri => { var metadata = await ResolveMetadataAsync(cancellationToken).ConfigureAwait(false); return(new EdmMetadataCache(uri, metadata)); }); } else { this.MetadataCache = EdmMetadataCache.GetOrAdd( this.Settings.BaseUri.AbsoluteUri, uri => { var cache = new EdmMetadataCache(uri, Settings.MetadataDocument); return(cache); }); } } if (this.Settings.PayloadFormat == ODataPayloadFormat.Unspecified) { this.Settings.PayloadFormat = this.Adapter.DefaultPayloadFormat; } return(this.Adapter); }
private Session(Uri baseUri, string metadataString) { this.Settings = new ODataClientSettings { BaseUri = baseUri }; this.MetadataCache = EdmMetadataCache.GetOrAdd(baseUri.AbsoluteUri, uri => new EdmMetadataCache(uri, metadataString)); }
public void ClearMetadataCache() { var metadataCache = _metadataCache; if (metadataCache != null) { EdmMetadataCache.Clear(metadataCache.Key); _metadataCache = null; } }
private async Task <EdmMetadataCache> InitializeMetadataCache(CancellationToken cancellationToken) { return(await EdmMetadataCache.GetOrAddAsync( Settings.BaseUri.AbsoluteUri, async uri => { var metadata = await ResolveMetadataAsync(cancellationToken).ConfigureAwait(false); return CreateMdc(uri, metadata); })); }
public async Task Initialize(CancellationToken cancellationToken) { if (_metadataCache == null) { _metadataCache = await InitializeMetadataCache(cancellationToken).ConfigureAwait(false); } if (_adapter == null) { _adapter = _metadataCache.GetODataAdapter(this); } }
private Session(ODataClientSettings settings) { if (settings.BaseUri == null || string.IsNullOrEmpty(settings.BaseUri.AbsoluteUri)) { throw new InvalidOperationException("Unable to create client session with no URI specified."); } this.Settings = settings; if (!string.IsNullOrEmpty(settings.MetadataDocument)) { this.MetadataCache = EdmMetadataCache.GetOrAdd(this.Settings.BaseUri.AbsoluteUri, uri => new EdmMetadataCache(uri, settings.MetadataDocument)); } }
private Session(ODataClientSettings settings) { if (settings.BaseUri == null || string.IsNullOrEmpty(settings.BaseUri.AbsoluteUri)) { throw new InvalidOperationException("Unable to create client session with no URI specified."); } Settings = settings; if (!string.IsNullOrEmpty(Settings.MetadataDocument)) { // Create as early as possible as most unit tests require this and also makes it simpler when assigning a static document _metadataCache = InitializeStaticMetadata(Settings.MetadataDocument); } }
public async Task Initialize(CancellationToken cancellationToken) { // Just allow one schema request at a time, unlikely to be much contention but avoids multiple requests for same endpoint. await _initializeSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { if (_metadataCache == null) { _metadataCache = await InitializeMetadataCache(cancellationToken) .ConfigureAwait(false); } if (_adapter == null) { _adapter = _metadataCache.GetODataAdapter(this); } } finally { _initializeSemaphore.Release(); } }
/// <summary> /// Clears service metadata cache. /// </summary> public static void ClearMetadataCache() { EdmMetadataCache.Clear(); }
private EdmMetadataCache InitializeStaticMetadata(string metadata) { return(EdmMetadataCache.GetOrAdd( Settings.BaseUri.AbsoluteUri, uri => CreateMdc(uri, metadata))); }