Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 private Session(Uri baseUri, string metadataString)
 {
     this.Settings = new ODataClientSettings {
         BaseUri = baseUri
     };
     this.MetadataCache = EdmMetadataCache.GetOrAdd(baseUri.AbsoluteUri, uri => new EdmMetadataCache(uri, metadataString));
 }
Exemplo n.º 3
0
        public void ClearMetadataCache()
        {
            var metadataCache = _metadataCache;

            if (metadataCache != null)
            {
                EdmMetadataCache.Clear(metadataCache.Key);
                _metadataCache = null;
            }
        }
Exemplo n.º 4
0
 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);
     }));
 }
Exemplo n.º 5
0
        public async Task Initialize(CancellationToken cancellationToken)
        {
            if (_metadataCache == null)
            {
                _metadataCache = await InitializeMetadataCache(cancellationToken).ConfigureAwait(false);
            }

            if (_adapter == null)
            {
                _adapter = _metadataCache.GetODataAdapter(this);
            }
        }
Exemplo n.º 6
0
        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));
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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();
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Clears service metadata cache.
 /// </summary>
 public static void ClearMetadataCache()
 {
     EdmMetadataCache.Clear();
 }
Exemplo n.º 10
0
 private EdmMetadataCache InitializeStaticMetadata(string metadata)
 {
     return(EdmMetadataCache.GetOrAdd(
                Settings.BaseUri.AbsoluteUri,
                uri => CreateMdc(uri, metadata)));
 }