1414using Contentstack . Management . Core . Abstractions ;
1515using Contentstack . Management . Core . Runtime . Contexts ;
1616using Contentstack . Management . Core . Runtime . Pipeline ;
17- using Contentstack . Management . Core . Http ;
1817using Contentstack . Management . Core . Services . User ;
1918using Contentstack . Management . Core . Queryable ;
2019using Environment = System . Environment ;
@@ -26,7 +25,7 @@ namespace Contentstack.Management.Core
2625 /// <summary>
2726 /// Contentstack Client for interacting with Contentstack Management API.
2827 /// </summary>
29- public class ContentstackClient : IContentstackClient
28+ public class ContentstackClient : IContentstackClient
3029 {
3130 internal ContentstackRuntimePipeline ContentstackPipeline { get ; set ; }
3231 internal ContentstackClientOptions contentstackOptions ;
@@ -36,8 +35,8 @@ public class ContentstackClient: IContentstackClient
3635 private HttpClient _httpClient ;
3736 private bool _disposed = false ;
3837
39- private string Version => "0.1.1 " ;
40- private string xUserAgent { get => $ "contentstack-management-dotnet/{ Version } "; }
38+ private string Version => "0.1.2 " ;
39+ private string xUserAgent => $ "contentstack-management-dotnet/{ Version } ";
4140 #endregion
4241
4342
@@ -74,7 +73,8 @@ public ContentstackClient(IOptions<ContentstackClientOptions> contentstackOption
7473 }
7574
7675 public ContentstackClient ( ContentstackClientOptions contentstackOptions ) :
77- this ( new OptionsWrapper < ContentstackClientOptions > ( contentstackOptions ) ) { }
76+ this ( new OptionsWrapper < ContentstackClientOptions > ( contentstackOptions ) )
77+ { }
7878
7979 /// <summary>
8080 /// Initializes new instance of the <see cref="ContentstackClient"/> class.
@@ -96,7 +96,7 @@ public ContentstackClient(ContentstackClientOptions contentstackOptions) :
9696 /// </code></pre>
9797 /// </example>
9898 public ContentstackClient (
99- string authtoken = null ,
99+ string authtoken = null ,
100100 string host = "api.contentstack.io" ,
101101 int port = 443 ,
102102 string version = "v3" ,
@@ -122,14 +122,16 @@ public ContentstackClient(
122122 ProxyPort = proxyPort ,
123123 ProxyCredentials = proxyCredentials
124124 }
125- ) ) { }
125+ ) )
126+ { }
126127 #endregion
127128
128129 protected void Initialize ( )
129130 {
130- var httpClientHandler = new HttpClientHandler ( ) ;
131-
132- httpClientHandler . Proxy = contentstackOptions . GetWebProxy ( ) ;
131+ HttpClientHandler httpClientHandler = new HttpClientHandler
132+ {
133+ Proxy = contentstackOptions . GetWebProxy ( )
134+ } ;
133135
134136 _httpClient = new HttpClient ( httpClientHandler ) ;
135137
@@ -145,20 +147,13 @@ protected void Initialize()
145147 {
146148 _httpClient . Timeout = contentstackOptions . Timeout ;
147149 _httpClient . MaxResponseContentBufferSize = contentstackOptions . MaxResponseContentBufferSize ;
148- if ( contentstackOptions . DisableLogging )
149- {
150- LogManager = LogManager . EmptyLogger ;
151- }
152- else
153- {
154- LogManager = LogManager . GetLogManager ( this . GetType ( ) ) ;
155- }
150+ LogManager = contentstackOptions . DisableLogging ? LogManager . EmptyLogger : LogManager . GetLogManager ( GetType ( ) ) ;
156151 }
157152
158- this . SerializerSettings . DateParseHandling = DateParseHandling . None ;
159- this . SerializerSettings . DateFormatHandling = DateFormatHandling . IsoDateFormat ;
160- this . SerializerSettings . DateTimeZoneHandling = DateTimeZoneHandling . Utc ;
161- this . SerializerSettings . NullValueHandling = NullValueHandling . Ignore ;
153+ SerializerSettings . DateParseHandling = DateParseHandling . None ;
154+ SerializerSettings . DateFormatHandling = DateFormatHandling . IsoDateFormat ;
155+ SerializerSettings . DateTimeZoneHandling = DateTimeZoneHandling . Utc ;
156+ SerializerSettings . NullValueHandling = NullValueHandling . Ignore ;
162157
163158 foreach ( Type t in CsmJsonConverterAttribute . GetCustomAttribute ( typeof ( CsmJsonConverterAttribute ) ) )
164159 {
@@ -170,8 +165,8 @@ protected void BuildPipeline()
170165 {
171166 HttpHandler httpClientHandler = new HttpHandler ( _httpClient ) ;
172167
173- var retryPolicy = contentstackOptions . RetryPolicy ?? new DefaultRetryPolicy ( contentstackOptions . RetryLimit , contentstackOptions . RetryDelay ) ;
174- this . ContentstackPipeline = new ContentstackRuntimePipeline ( new List < IPipelineHandler > ( )
168+ RetryPolicy retryPolicy = contentstackOptions . RetryPolicy ?? new DefaultRetryPolicy ( contentstackOptions . RetryLimit , contentstackOptions . RetryDelay ) ;
169+ ContentstackPipeline = new ContentstackRuntimePipeline ( new List < IPipelineHandler > ( )
175170 {
176171 httpClientHandler ,
177172 new RetryHandler ( retryPolicy )
@@ -182,15 +177,15 @@ internal ContentstackResponse InvokeSync<TRequest>(TRequest request) where TRequ
182177 {
183178 ThrowIfDisposed ( ) ;
184179
185- var context = new ExecutionContext (
180+ ExecutionContext context = new ExecutionContext (
186181 new RequestContext ( )
187182 {
188- config = this . contentstackOptions ,
183+ config = contentstackOptions ,
189184 service = request
190185 } ,
191186 new ResponseContext ( ) ) ;
192187
193- return ( ContentstackResponse ) this . ContentstackPipeline . InvokeSync ( context ) . httpResponse ;
188+ return ( ContentstackResponse ) ContentstackPipeline . InvokeSync ( context ) . httpResponse ;
194189 }
195190
196191 internal Task < TResponse > InvokeAsync < TRequest , TResponse > ( TRequest request )
@@ -199,14 +194,14 @@ internal Task<TResponse> InvokeAsync<TRequest, TResponse>(TRequest request)
199194 {
200195 ThrowIfDisposed ( ) ;
201196
202- var context = new ExecutionContext (
197+ ExecutionContext context = new ExecutionContext (
203198 new RequestContext ( )
204199 {
205- config = this . contentstackOptions ,
200+ config = contentstackOptions ,
206201 service = request
207202 } ,
208203 new ResponseContext ( ) ) ;
209- return this . ContentstackPipeline . InvokeAsync < TResponse > ( context ) ;
204+ return ContentstackPipeline . InvokeAsync < TResponse > ( context ) ;
210205 }
211206
212207 #region Dispose methods
@@ -222,14 +217,15 @@ public void Dispose()
222217 protected virtual void Dispose ( bool disposing )
223218 {
224219 if ( _disposed )
220+ {
225221 return ;
222+ }
226223
227224 if ( disposing )
228225 {
229226 _httpClient . Dispose ( ) ;
230227 }
231- if ( ContentstackPipeline != null )
232- ContentstackPipeline . Dispose ( ) ;
228+ ContentstackPipeline ? . Dispose ( ) ;
233229
234230 _disposed = true ;
235231
@@ -238,8 +234,10 @@ protected virtual void Dispose(bool disposing)
238234 private void ThrowIfDisposed ( )
239235 {
240236 //_httpClient.SendAsync
241- if ( this . _disposed )
237+ if ( _disposed )
238+ {
242239 throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
240+ }
243241 }
244242 #endregion
245243
@@ -310,9 +308,9 @@ public Stack Stack(string apiKey = null, string managementToken = null, string b
310308 public ContentstackResponse Login ( ICredentials credentials , string token = null )
311309 {
312310 ThrowIfAlreadyLoggedIn ( ) ;
313- var Login = new LoginService ( this . serializer , credentials , token ) ;
311+ LoginService Login = new LoginService ( serializer , credentials , token ) ;
314312
315- return this . InvokeSync ( Login ) ;
313+ return InvokeSync ( Login ) ;
316314 }
317315
318316 /// <summary>
@@ -331,25 +329,25 @@ public ContentstackResponse Login(ICredentials credentials, string token = null)
331329 public Task < ContentstackResponse > LoginAsync ( ICredentials credentials , string token = null )
332330 {
333331 ThrowIfAlreadyLoggedIn ( ) ;
334- var Login = new LoginService ( this . serializer , credentials , token ) ;
332+ LoginService Login = new LoginService ( serializer , credentials , token ) ;
335333
336- return this . InvokeAsync < LoginService , ContentstackResponse > ( Login ) ;
334+ return InvokeAsync < LoginService , ContentstackResponse > ( Login ) ;
337335 }
338336 #endregion
339337
340338 #region Throw Error
341339
342340 internal void ThrowIfAlreadyLoggedIn ( )
343341 {
344- if ( ! string . IsNullOrEmpty ( this . contentstackOptions . Authtoken ) )
342+ if ( ! string . IsNullOrEmpty ( contentstackOptions . Authtoken ) )
345343 {
346344 throw new InvalidOperationException ( CSConstants . YouAreLoggedIn ) ;
347345 }
348346 }
349347
350348 internal void ThrowIfNotLoggedIn ( )
351349 {
352- if ( string . IsNullOrEmpty ( this . contentstackOptions . Authtoken ) )
350+ if ( string . IsNullOrEmpty ( contentstackOptions . Authtoken ) )
353351 {
354352 throw new InvalidOperationException ( CSConstants . YouAreNotLoggedIn ) ;
355353 }
@@ -370,10 +368,10 @@ internal void ThrowIfNotLoggedIn()
370368 /// <returns>The <see cref="ContentstackResponse" /></returns>
371369 public ContentstackResponse Logout ( string authtoken = null )
372370 {
373- var token = authtoken ?? this . contentstackOptions . Authtoken ;
374- var logout = new LogoutService ( this . serializer , token ) ;
371+ string token = authtoken ?? contentstackOptions . Authtoken ;
372+ LogoutService logout = new LogoutService ( serializer , token ) ;
375373
376- return this . InvokeSync ( logout ) ;
374+ return InvokeSync ( logout ) ;
377375 }
378376 /// <summary>
379377 ///
@@ -388,10 +386,10 @@ public ContentstackResponse Logout(string authtoken = null)
388386 /// <returns>The Task.</returns>
389387 public Task < ContentstackResponse > LogoutAsync ( string authtoken = null )
390388 {
391- var token = authtoken ?? this . contentstackOptions . Authtoken ;
392- var logout = new LogoutService ( this . serializer , token ) ;
389+ string token = authtoken ?? contentstackOptions . Authtoken ;
390+ LogoutService logout = new LogoutService ( serializer , token ) ;
393391
394- return this . InvokeAsync < LogoutService , ContentstackResponse > ( logout ) ;
392+ return InvokeAsync < LogoutService , ContentstackResponse > ( logout ) ;
395393 }
396394 #endregion
397395
@@ -409,9 +407,9 @@ public ContentstackResponse GetUser(ParameterCollection collection = null)
409407 {
410408 ThrowIfNotLoggedIn ( ) ;
411409
412- var getUser = new GetLoggedInUserService ( this . serializer , collection ) ;
410+ GetLoggedInUserService getUser = new GetLoggedInUserService ( serializer , collection ) ;
413411
414- return this . InvokeSync ( getUser ) ;
412+ return InvokeSync ( getUser ) ;
415413 }
416414
417415 /// <summary>
@@ -428,9 +426,9 @@ public Task<ContentstackResponse> GetUserAsync(ParameterCollection collection =
428426 {
429427 ThrowIfNotLoggedIn ( ) ;
430428
431- var getUser = new GetLoggedInUserService ( this . serializer , collection ) ;
429+ GetLoggedInUserService getUser = new GetLoggedInUserService ( serializer , collection ) ;
432430
433- return this . InvokeAsync < GetLoggedInUserService , ContentstackResponse > ( getUser ) ;
431+ return InvokeAsync < GetLoggedInUserService , ContentstackResponse > ( getUser ) ;
434432 }
435433 }
436434}
0 commit comments