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;
            }
        }
Beispiel #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);
 }
Beispiel #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());
     }
 }
Beispiel #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;
        }
Beispiel #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));
     }
 }
        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;
        }
Beispiel #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();
        }
Beispiel #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));
        }
 private Session(Uri baseUri, string metadataString)
 {
     // Create a local setting with the correct uri and metadata
     Settings = new ODataClientSettings
     {
         BaseUri          = baseUri,
         MetadataDocument = metadataString
     };
 }
        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;
        }
Beispiel #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));
     }
 }
        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();
        }
Beispiel #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));
            }
        }
 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));
     }
 }
Beispiel #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;
 }
Beispiel #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);
            }
        }
        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);
            }
        }
Beispiel #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);
        }
Beispiel #23
0
 internal ODataClient(ODataClient client, ODataResponse batchResponse)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _batchResponse = batchResponse;
 }
Beispiel #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;
 }
 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;
 }
Beispiel #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);
 }
Beispiel #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);
 }
 internal static Session FromSettings(ODataClientSettings settings)
 {
     return new Session(settings);
 }
		/// <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;
 }
Beispiel #34
0
 internal static Session FromSettings(ODataClientSettings settings)
 {
     return(new Session(settings));
 }
 /// <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);
 }