private static HttpMessageHandler CreateMessageHandler(ODataClientSettings settings)
        {
            if (settings.OnCreateMessageHandler != null)
            {
                return settings.OnCreateMessageHandler();
            }
            else
            {
                var clientHandler = new HttpClientHandler();

                // Perform this test to prevent failure to access Credentials/PreAuthenticate properties on SL5
                if (settings.Credentials != null)
                {
                    clientHandler.Credentials = settings.Credentials;
                    if (clientHandler.SupportsPreAuthenticate())
                        clientHandler.PreAuthenticate = true;
                }

                if (settings.OnApplyClientHandler != null)
                {
                    settings.OnApplyClientHandler(clientHandler);
                }

                return clientHandler;
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBase"/> class with a <paramref name="clientSettings"/>.
 /// </summary>
 /// <param name="clientSettings">The <see cref="Soc.ODataClientSettings"/>.</param>
 /// <remarks><i>Note:</i> Overrides the <see cref="Soc.ODataClientSettings.IgnoreResourceNotFoundException"/> to <c>true</c> by design.</remarks>
 protected ODataBase(Soc.ODataClientSettings clientSettings)
 {
     ClientSettings = Check.NotNull(clientSettings, nameof(clientSettings));
     ClientSettings.IgnoreResourceNotFoundException = true;
     ClientSettings.PreferredUpdateMethod           = Soc.ODataUpdateMethod.Patch;
     Client = new Soc.ODataClient(ClientSettings);
 }
Пример #3
0
        private static HttpMessageHandler CreateMessageHandler(ODataClientSettings settings)
        {
            if (settings.OnCreateMessageHandler != null)
            {
                return(settings.OnCreateMessageHandler());
            }
            else
            {
                var clientHandler = new HttpClientHandler();

                // Perform this test to prevent failure to access Credentials/PreAuthenticate properties on SL5
                if (settings.Credentials != null)
                {
                    clientHandler.Credentials = settings.Credentials;
                    if (Utils.IsDesktopPlatform() || clientHandler.SupportsPreAuthenticate())
                    {
                        clientHandler.PreAuthenticate = true;
                    }
                }

                if (settings.OnApplyClientHandler != null)
                {
                    settings.OnApplyClientHandler(clientHandler);
                }

                return(clientHandler);
            }
        }
        public ODataClient(ODataBatch batch)
        {
            _settings = batch.Settings;
            _schema = Client.Schema.Get(_settings.UrlBase, _settings.Credentials);

            _requestBuilder = batch.RequestBuilder;
            _requestRunner = batch.RequestRunner;
        }
 internal ODataClient(ODataClientSettings settings, bool isBatch)
     : this(settings)
 {
     if (isBatch)
     {
         _lazyBatchWriter = new Lazy <IBatchWriter>(() => _session.Adapter.GetBatchWriter());
     }
 }
Пример #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;
        }
Пример #7
0
 internal ODataClient(ODataClientSettings settings, ConcurrentDictionary <object, IDictionary <string, object> > batchEntries)
     : this(settings)
 {
     if (batchEntries != null)
     {
         _batchEntries    = batchEntries;
         _lazyBatchWriter = new Lazy <IBatchWriter>(() => _session.Adapter.GetBatchWriter(_batchEntries));
     }
 }
Пример #8
0
        public ODataBatch(ODataClientSettings settings)
        {
            this.Settings = settings;
            this.RequestBuilder = new BatchRequestBuilder(this.Settings.UrlBase, this.Settings.Credentials);
            this.RequestRunner = new BatchRequestRunner(this.RequestBuilder);

            this.RequestBuilder.BeginBatch();
            _active = true;
        }
Пример #9
0
        private Session(ODataClientSettings settings)
        {
            _adapterFactory = new AdapterFactory(this);
            _createAdapter  = () => _adapterFactory.ParseMetadata(this.MetadataCache.MetadataAsString);

            this.Settings      = settings;
            this.MetadataCache = MetadataCache.Instances.GetOrAdd(this.Settings.UrlBase, new MetadataCache());
            this.Pluralizer    = new SimplePluralizer();
        }
Пример #10
0
        protected override void OnSetup()
        {
            base.OnSetup();

            var odataFeed = new ODataFeed(this.Settings);
            _clientSettings = odataFeed.ClientSettings;
            _schema = Utils.ExecuteAndUnwrap(() => 
                ODataClient.GetSchemaAsync(_clientSettings.UrlBase, _clientSettings.Credentials));
        }
Пример #11
0
 private Session(Uri baseUri, string metadataString)
 {
     // Create a local setting with the correct uri and metadata
     Settings = new ODataClientSettings
     {
         BaseUri          = baseUri,
         MetadataDocument = metadataString
     };
 }
Пример #12
0
        public ODataClient(ODataClientSettings settings)
        {
            _settings = settings;
            _schema = Client.Schema.Get(_settings.UrlBase, _settings.Credentials);

            _requestBuilder = new CommandRequestBuilder(_settings.UrlBase, _settings.Credentials);
            _requestRunner = new CommandRequestRunner(_settings);
            _requestRunner.BeforeRequest = _settings.BeforeRequest;
            _requestRunner.AfterResponse = _settings.AfterResponse;
        }
Пример #13
0
 internal ODataClient(ODataClient client, ConcurrentDictionary <object, IDictionary <string, object> > batchEntries)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _requestRunner = client._requestRunner;
     if (batchEntries != null)
     {
         _batchEntries    = batchEntries;
         _lazyBatchWriter = new Lazy <IBatchWriter>(() => _session.Adapter.GetBatchWriter(_batchEntries));
     }
 }
Пример #14
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");

            _adapterFactory = new AdapterFactory(this);
            _createAdapter = () => _adapterFactory.ParseMetadata(this.MetadataCache.MetadataDocument);

            this.Settings = settings;
            this.MetadataCache = MetadataCache.Instances.GetOrAdd(this.Settings.BaseUri.AbsoluteUri, new MetadataCache());
            this.Pluralizer = new SimplePluralizer();
        }
Пример #15
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 = MetadataCache.GetOrAdd(this.Settings.BaseUri.AbsoluteUri, uri => new MetadataCache(uri, settings.MetadataDocument));
            }
        }
Пример #16
0
 private static HttpClient CreateHttpClient(ODataClientSettings settings, HttpMessageHandler messageHandler)
 {
     if (settings.RequestTimeout >= TimeSpan.FromMilliseconds(1))
     {
         return(new HttpClient(messageHandler)
         {
             Timeout = settings.RequestTimeout,
         });
     }
     else
     {
         return(new HttpClient(messageHandler));
     }
 }
Пример #17
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");
            }

            _adapterFactory = new AdapterFactory(this);
            _createAdapter  = () => _adapterFactory.ParseMetadata(this.MetadataCache.MetadataDocument);

            this.Settings      = settings;
            this.MetadataCache = MetadataCache.Instances.GetOrAdd(this.Settings.BaseUri.AbsoluteUri, new MetadataCache());
            this.Pluralizer    = new SimplePluralizer();
        }
 private static HttpClient CreateHttpClient(ODataClientSettings settings, HttpMessageHandler messageHandler)
 {
     if (settings.RequestTimeout >= TimeSpan.FromMilliseconds(1))
     {
         return new HttpClient(messageHandler)
         {
             Timeout = settings.RequestTimeout,
         };
     }
     else
     {
         return new HttpClient(messageHandler);
     }
 }
 public static ODataClientSettings ToSettings(this WebApiCredentials credentials)
 {
     var settings = new ODataClientSettings
     {
         Credentials = new NetworkCredential(credentials.UserName,
             credentials.Password),
         BeforeRequest = requestMessage => {
             requestMessage.Headers.Accept.Clear();
             requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
             requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
         }
     };
     return settings;
 }
Пример #20
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);
            }
        }
Пример #21
0
        private static HttpMessageHandler CreateMessageHandler(ODataClientSettings settings)
        {
            if (settings.OnCreateMessageHandler != null)
            {
                return(settings.OnCreateMessageHandler());
            }
            else
            {
                var clientHandler = new HttpClientHandler();

                if (settings.Credentials != null)
                {
                    clientHandler.Credentials     = settings.Credentials;
                    clientHandler.PreAuthenticate = true;
                }

                settings.OnApplyClientHandler?.Invoke(clientHandler);

                return(clientHandler);
            }
        }
Пример #22
0
        public ODataClient CreateODataClient()
        {
            var settings = new ODataClientSettings { UrlBase = ServiceUri + "odata" };


            if (Username != null)
                settings.Credentials = new NetworkCredential(Username, Password);

            return new ODataClient(settings);
        }
Пример #23
0
 internal ODataClient(ODataClient client, ODataResponse batchResponse)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _batchResponse = batchResponse;
 }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataClient"/> class.
 /// </summary>
 /// <param name="settings">The OData client settings.</param>
 public ODataClient(ODataClientSettings settings)
 {
     _settings      = settings;
     _session       = Session.FromSettings(_settings);
     _requestRunner = new RequestRunner(_session);
 }
 public HttpConnection(ODataClientSettings settings)
 {
     _messageHandler = CreateMessageHandler(settings);
     _httpClient = CreateHttpClient(settings, _messageHandler);
 }
 public CommandRequestRunner(ODataClientSettings settings)
 {
     _feedReader = new ODataFeedReader(settings.IncludeResourceTypeInEntryProperties);
     _ignoreResourceNotFoundException = settings.IgnoreResourceNotFoundException;
 }
Пример #27
0
 public HttpConnection(ODataClientSettings settings)
 {
     _messageHandler = CreateMessageHandler(settings);
     _httpClient     = CreateHttpClient(settings, _messageHandler);
 }
 public CommandRequestRunner(ISchema schema, ODataClientSettings settings)
 {
     _responseReader = new ResponseReader(schema, settings.IncludeResourceTypeInEntryProperties);
     _ignoreResourceNotFoundException = settings.IgnoreResourceNotFoundException;
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, true);
 }
Пример #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, _entryMap);
 }
Пример #31
0
 internal static Session FromSettings(ODataClientSettings settings)
 {
     return new Session(settings);
 }
Пример #32
0
		/// <summary>
		/// Creates and returns a new <see cref="ODataClient"/> which is configured to talk to <paramref name="testServer"/>.
		/// </summary>
		/// <param name="testServer"></param>
		/// <param name="odataBaseUrl"></param>
		/// <returns></returns>
		protected virtual ODataClient CreateODataClient(TestServer testServer, string odataBaseUrl = "/odata/")
		{
			var baseUrl = new Uri(new Uri("http://localhost/"), odataBaseUrl);
			ODataClientSettings oDataClientSettings = new ODataClientSettings(baseUrl)
			                                          {
				                                          OnCreateMessageHandler = () => testServer.Handler
			                                          };
			return new ODataClient(oDataClientSettings);
		}
 internal ODataClient(ODataClient client)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _requestRunner = client._requestRunner;
 }
Пример #34
0
 internal static Session FromSettings(ODataClientSettings settings)
 {
     return(new Session(settings));
 }
Пример #35
-1
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, _entryMap);
 }