From 5e89401b2a4734b7f5c22d6f472e6d56a408fe27 Mon Sep 17 00:00:00 2001 From: Alex K Date: Thu, 3 Jan 2019 17:22:50 +0200 Subject: [PATCH 1/2] Updated Thread Safety handling for synchronous execution --- src/Plivo/Client/SystemHttpClient.cs | 4 +- .../Resource/Account/AccountInterface.cs | 4 +- .../Resource/Address/AddressInterface.cs | 10 ++--- .../Application/ApplicationInterface.cs | 10 ++--- src/Plivo/Resource/Call/CallInterface.cs | 40 +++++++++--------- .../Conference/ConferenceInterface.cs | 42 +++++++++---------- .../Resource/Endpoint/EndpointInterface.cs | 10 ++--- .../Resource/Identity/IdentityInterface.cs | 10 ++--- .../Resource/Message/MessageInterface.cs | 6 +-- .../PhoneNumber/PhoneNumberInterface.cs | 6 +-- .../Resource/Pricing/PricingInterface.cs | 4 +- .../Resource/Recording/RecordingInterface.cs | 6 +-- .../RentedNumber/RentedNumberInterface.cs | 12 +++--- .../Subaccount/SubaccountInterface.cs | 10 ++--- 14 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/Plivo/Client/SystemHttpClient.cs b/src/Plivo/Client/SystemHttpClient.cs index 365c3175..027e1bb0 100644 --- a/src/Plivo/Client/SystemHttpClient.cs +++ b/src/Plivo/Client/SystemHttpClient.cs @@ -206,9 +206,9 @@ public async Task> SendRequest(string method, string uri, Di method + " not supported"); } - response = await _client.SendAsync(request); + response = await _client.SendAsync(request).ConfigureAwait(false); - var responseContent = await response.Content.ReadAsStringAsync(); + var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); // create Plivo response object along with the deserialized object PlivoResponse plivoResponse; diff --git a/src/Plivo/Resource/Account/AccountInterface.cs b/src/Plivo/Resource/Account/AccountInterface.cs index 8ba87f90..841d9ae9 100644 --- a/src/Plivo/Resource/Account/AccountInterface.cs +++ b/src/Plivo/Resource/Account/AccountInterface.cs @@ -27,7 +27,7 @@ public AccountInterface(HttpClient client) : base(client) /// The get. public Account Get() { - var account = GetResource("").Result; + var account = Task.Run(async () => await GetResource("").ConfigureAwait(false)).Result; account.Interface = this; return account; } @@ -55,7 +55,7 @@ public UpdateResponse Update(string name = null, string city = null, s var mandatoryParams = new List {"name"}; var data = CreateData( mandatoryParams, new {name, city, address}); - var result = Client.Update>(Uri, data).Result; + var result = Task.Run(async () => await Client.Update>(Uri, data).ConfigureAwait(false)).Result; return result.Object; } /// diff --git a/src/Plivo/Resource/Address/AddressInterface.cs b/src/Plivo/Resource/Address/AddressInterface.cs index 93eac0cd..44dca759 100644 --- a/src/Plivo/Resource/Address/AddressInterface.cs +++ b/src/Plivo/Resource/Address/AddressInterface.cs @@ -211,7 +211,7 @@ public AddressCreateResponse Create( filesToUpload.Add("file", fileToUpload); } - var result = Client.Update(Uri, data, filesToUpload).Result; + var result = Task.Run(async () => await Client.Update(Uri, data, filesToUpload).ConfigureAwait(false)).Result; return result.Object; } @@ -280,7 +280,7 @@ public UpdateResponse
Update( filesToUpload.Add("file", fileToUpload); } - var result = Client.Update>(Uri + addressId + "/", data, filesToUpload).Result; + var result = Task.Run(async () => await Client.Update>(Uri + addressId + "/", data, filesToUpload).ConfigureAwait(false)).Result; return result.Object; } @@ -359,7 +359,7 @@ public async Task> UpdateAsync( /// Identifier. public Address Get(string id) { - var address = GetResource
(id).Result; + var address = Task.Run(async () => await GetResource
(id).ConfigureAwait(false)).Result; address.Interface = this; return address; } @@ -408,7 +408,7 @@ public ListResponse
List( limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -472,7 +472,7 @@ public async Task> DeleteAsync(string id) /// Identifier. public DeleteResponse
Delete(string id) { - return DeleteResource>(id).Result; + return Task.Run(async () => await DeleteResource>(id).ConfigureAwait(false)).Result; } #endregion } diff --git a/src/Plivo/Resource/Application/ApplicationInterface.cs b/src/Plivo/Resource/Application/ApplicationInterface.cs index 05307083..9a7ae111 100644 --- a/src/Plivo/Resource/Application/ApplicationInterface.cs +++ b/src/Plivo/Resource/Application/ApplicationInterface.cs @@ -73,7 +73,7 @@ public ApplicationCreateResponse Create( logIncomingMessages }); - var result = Client.Update(Uri, data).Result; + var result = Task.Run(async () => await Client.Update(Uri, data).ConfigureAwait(false)).Result; return result.Object; } @@ -139,7 +139,7 @@ public async Task CreateAsync( /// App identifier. public Application Get(string appId) { - var application = GetResource(appId).Result; + var application = Task.Run(async () => await GetResource(appId).ConfigureAwait(false)).Result; application.Interface = this; return application; } @@ -171,7 +171,7 @@ public ListResponse List( var data = CreateData( mandatoryParams, new { subaccount, limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -209,7 +209,7 @@ public async Task> ListAsync( /// App identifier. public DeleteResponse Delete(string appId) { - return DeleteResource>(appId).Result; + return Task.Run(async () => await DeleteResource>(appId).ConfigureAwait(false)).Result; } /// /// Asynchronously delete Application with the specified appId. @@ -268,7 +268,7 @@ public UpdateResponse Update( logIncomingMessages }); - var result = Client.Update>(Uri + appId + "/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + appId + "/", data).ConfigureAwait(false)).Result; return result.Object; } /// diff --git a/src/Plivo/Resource/Call/CallInterface.cs b/src/Plivo/Resource/Call/CallInterface.cs index 4d0fabe6..a9a36dc8 100644 --- a/src/Plivo/Resource/Call/CallInterface.cs +++ b/src/Plivo/Resource/Call/CallInterface.cs @@ -97,7 +97,7 @@ public CallCreateResponse Create( parentCallUuid, errorIfrentNotFound }); - var result = Client.Update(Uri, data).Result; + var result = Task.Run(async () => await Client.Update(Uri, data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -252,7 +252,7 @@ public ListResponse List( limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -349,7 +349,7 @@ public async Task> ListAsync( /// Call UUID. public Call Get(string callUuid) { - var call = GetResource(callUuid).Result; + var call = Task.Run(async () => await GetResource(callUuid).ConfigureAwait(false)).Result; call.Interface = this; return call; } @@ -389,7 +389,7 @@ public LiveCallListResponse ListLive(string callDirection = null, toNumber }); - return ListResources(data).Result; + return Task.Run(async () => await ListResources(data).ConfigureAwait(false)).Result; } /// /// Lists the live. @@ -425,8 +425,8 @@ public async Task ListLiveAsync(string callDirection = nul /// Live call UUID. public LiveCall GetLive(string liveCallUuid) { - var liveCall = GetResource( - liveCallUuid, new Dictionary() { { "status", "live" } }).Result; + var liveCall = Task.Run(async () => await GetResource( + liveCallUuid, new Dictionary() { { "status", "live" } }).ConfigureAwait(false)).Result; liveCall.Interface = this; return liveCall; } @@ -452,8 +452,8 @@ public async Task GetLiveAsync(string liveCallUuid) /// Call UUID. public QueuedCall GetQueued(string callUuid) { - var queuedCall = GetResource( - callUuid, new Dictionary() { { "status", "queued" } }).Result; + var queuedCall = Task.Run(async () => await GetResource( + callUuid, new Dictionary() { { "status", "queued" } }).ConfigureAwait(false)).Result; queuedCall.Interface = this; return queuedCall; } @@ -478,8 +478,8 @@ public async Task GetQueuedAsync(string callUuid) /// queued calls list public QueuedCallListResponse ListQueued() { - return ListResources( - new Dictionary() { { "status", "queued" } }).Result; + return Task.Run(async () => await ListResources( + new Dictionary() { { "status", "queued" } }).ConfigureAwait(false)).Result; } /// /// Lists the queued calls. @@ -501,7 +501,7 @@ await ListResources( /// Call UUID. public DeleteResponse Delete(string callUuid) { - return DeleteResource>(callUuid).Result; + return Task.Run(async () => await DeleteResource>(callUuid).ConfigureAwait(false)).Result; } /// /// Asynchronously delete Call with the specified callUuid. @@ -541,7 +541,7 @@ public UpdateResponse Transfer( blegUrl, blegMethod }); - var result = Client.Update>(Uri + callUuid + "/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + callUuid + "/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -602,7 +602,7 @@ public UpdateResponse StartPlaying( loop, mix }); - var result = Client.Update>(Uri + callUuid + "/Play/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + callUuid + "/Play/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -644,7 +644,7 @@ public async Task> StartPlayingAsync( /// Call UUID. public DeleteResponse StopPlaying(string callUuid) { - var result = Client.Delete>(Uri + callUuid + "/Play/").Result; + var result = Task.Run(async () => await Client.Delete>(Uri + callUuid + "/Play/").ConfigureAwait(false)).Result; return result.Object; } /// @@ -691,7 +691,7 @@ public RecordCreateResponse StartRecording( callbackUrl, callbackMethod }); - var result = Client.Update>(Uri + callUuid + "/Record/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + callUuid + "/Record/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -742,7 +742,7 @@ public DeleteResponse StopRecording(string callUuid, string URL = null) var mandatoryParams = new List { "" }; var data = CreateData( mandatoryParams, new { URL }); - var result = Client.Delete>(Uri + callUuid + "/Record/", data).Result; + var result = Task.Run(async () => await Client.Delete>(Uri + callUuid + "/Record/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -790,7 +790,7 @@ public UpdateResponse StartSpeaking( loop, mix }); - var result = Client.Update>(Uri + callUuid + "/Speak/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + callUuid + "/Speak/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -835,7 +835,7 @@ public async Task> StartSpeakingAsync( /// Call UUID. public DeleteResponse StopSpeaking(string callUuid) { - var result = Client.Delete>(Uri + callUuid + "/Speak/").Result; + var result = Task.Run(async () => await Client.Delete>(Uri + callUuid + "/Speak/").ConfigureAwait(false)).Result; return result.Object; } /// @@ -869,7 +869,7 @@ public UpdateResponse SendDigits( digits, leg }); - var result = Client.Update>(Uri + callUuid + "/DTMF/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + callUuid + "/DTMF/", data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -903,7 +903,7 @@ public async Task> SendDigitsAsync( /// Request UUID. public DeleteResponse CancelCall(string requestUuid) { - var result = Client.Delete>("Account/" + Client.GetAuthId() + "/Request/" + requestUuid + "/", null).Result; + var result = Task.Run(async () => await Client.Delete>("Account/" + Client.GetAuthId() + "/Request/" + requestUuid + "/", null).ConfigureAwait(false)).Result; return result.Object; } /// diff --git a/src/Plivo/Resource/Conference/ConferenceInterface.cs b/src/Plivo/Resource/Conference/ConferenceInterface.cs index 3e4d7532..b98a8940 100644 --- a/src/Plivo/Resource/Conference/ConferenceInterface.cs +++ b/src/Plivo/Resource/Conference/ConferenceInterface.cs @@ -29,7 +29,7 @@ public ConferenceInterface(HttpClient client) : base(client) /// Name. public Conference Get(string conferenceName) { - var conference = GetResource(conferenceName).Result; + var conference = Task.Run(async () => await GetResource(conferenceName).ConfigureAwait(false)).Result; conference.Interface = this; return conference; } @@ -53,7 +53,7 @@ public async Task GetAsync(string conferenceName) /// The list. public ConferenceListResponse List() { - return ListResources().Result; + return Task.Run(async () => await ListResources().ConfigureAwait(false)).Result; } /// /// List Conferences. @@ -72,7 +72,7 @@ public async Task ListAsync() /// The all. public DeleteResponse DeleteAll() { - var result = Client.Delete>(Uri).Result; + var result = Task.Run(async () => await Client.Delete>(Uri).ConfigureAwait(false)).Result; return result.Object; } /// @@ -94,7 +94,7 @@ public async Task> DeleteAllAsync() /// Name. public DeleteResponse Delete(string name) { - return DeleteResource>(name).Result; + return Task.Run(async () => await DeleteResource>(name).ConfigureAwait(false)).Result; } /// /// Asynchronously delete with the specified name. @@ -117,7 +117,7 @@ public async Task> DeleteAsync(string name) public ConferenceMemberActionResponse HangupMember( string conferenceName, string memberId) { - var result = Client.Delete(Uri + conferenceName + "/Member/" + memberId + "/").Result; + var result = Task.Run(async () => await Client.Delete(Uri + conferenceName + "/Member/" + memberId + "/").ConfigureAwait(false)).Result; return result.Object; } /// @@ -144,7 +144,7 @@ public async Task HangupMemberAsync( public ConferenceMemberActionResponse KickMember( string conferenceName, string memberId) { - var result = Client.Update(Uri + conferenceName + "/Member/" + memberId + "/Kick/").Result; + var result = Task.Run(async () => await Client.Update(Uri + conferenceName + "/Member/" + memberId + "/Kick/").ConfigureAwait(false)).Result; return result.Object; } @@ -172,7 +172,7 @@ public async Task KickMemberAsync( public ConferenceMemberActionResponse MuteMember( string conferenceName, List memberId) { - var result = Client.Update(Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Mute/").Result; + var result = Task.Run(async () => await Client.Update(Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Mute/").ConfigureAwait(false)).Result; return result.Object; } /// @@ -225,14 +225,14 @@ await Client.Delete( public ConferenceMemberActionResponse PlayMember( string conferenceName, List memberId, string url) { - var result = Client.Update( + var result = Task.Run(async () => await Client.Update( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Play/", new Dictionary() { { "url", url } } - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } /// @@ -267,14 +267,14 @@ public async Task PlayMemberAsync( public ConferenceMemberActionResponse StopPlayMember( string conferenceName, List memberId) { - var result = + var result = Task.Run(async () => await Client.Delete( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Play/" - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } /// @@ -321,14 +321,14 @@ public ConferenceMemberActionResponse SpeakMember( voice, language }); - var result = Client.Update( + var result = Task.Run(async () => await Client.Update( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Speak/", data - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } /// @@ -375,12 +375,12 @@ public async Task SpeakMemberAsync( public ConferenceMemberActionResponse StopSpeakMember( string conferenceName, List memberId) { - var result = Client.Delete( + var result = Task.Run(async () => await Client.Delete( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + - "/Speak/") + "/Speak/").ConfigureAwait(false)) .Result; return result.Object; @@ -416,13 +416,13 @@ public async Task StopSpeakMemberAsync( public ConferenceMemberActionResponse DeafMember( string conferenceName, List memberId) { - var result = Client.Update( + var result = Task.Run(async () => await Client.Update( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Deaf/" - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } /// @@ -454,13 +454,13 @@ public async Task DeafMemberAsync( public ConferenceMemberActionResponse UnDeafMember( string conferenceName, List memberId) { - var result = Client.Delete( + var result = Task.Run(async () => await Client.Delete( Uri + conferenceName + "/Member/" + string.Join(",", memberId) + "/Deaf/" - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } public async Task UnDeafMemberAsync( @@ -507,10 +507,10 @@ public RecordCreateResponse StartRecording( callbackMethod }); - var result = Client.Update>( + var result = Task.Run(async () => await Client.Update>( Uri + conferenceName + "/Record/", data - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } diff --git a/src/Plivo/Resource/Endpoint/EndpointInterface.cs b/src/Plivo/Resource/Endpoint/EndpointInterface.cs index 4b97daee..3ab9271f 100644 --- a/src/Plivo/Resource/Endpoint/EndpointInterface.cs +++ b/src/Plivo/Resource/Endpoint/EndpointInterface.cs @@ -43,7 +43,7 @@ public EndpointCreateResponse Create( alias, appId }); - var result = Client.Update(Uri, data).Result; + var result = Task.Run(async () => await Client.Update(Uri, data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -80,7 +80,7 @@ public async Task CreateAsync( /// App identifier. public Endpoint Get(string endpointId) { - var endpoint = GetResource(endpointId).Result; + var endpoint = Task.Run(async () => await GetResource(endpointId).ConfigureAwait(false)).Result; endpoint.Interface = this; return endpoint; } @@ -112,7 +112,7 @@ public ListResponse List( var mandatoryParams = new List {""}; var data = CreateData( mandatoryParams, new {subaccount, limit, offset}); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this @@ -151,7 +151,7 @@ public async Task> ListAsync( /// Endpoint identifier. public DeleteResponse Delete(string endpointId) { - return DeleteResource>(endpointId).Result; + return Task.Run(async () => await DeleteResource>(endpointId).ConfigureAwait(false)).Result; } /// /// Asynchronously delete Endpoint with the specified endpointId. @@ -186,7 +186,7 @@ public UpdateResponse Update( alias, appId }); - var result = Client.Update>(Uri + endpointId + "/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + endpointId + "/", data).ConfigureAwait(false)).Result; return result.Object; } /// diff --git a/src/Plivo/Resource/Identity/IdentityInterface.cs b/src/Plivo/Resource/Identity/IdentityInterface.cs index 094f80ea..c04515d8 100644 --- a/src/Plivo/Resource/Identity/IdentityInterface.cs +++ b/src/Plivo/Resource/Identity/IdentityInterface.cs @@ -27,7 +27,7 @@ public IdentityInterface(HttpClient client) : base(client) /// Identifier. public Identity Get(string id) { - var identity = GetResource(id).Result; + var identity = Task.Run(async () => await GetResource(id).ConfigureAwait(false)).Result; identity.Interface = this; return identity; } @@ -74,7 +74,7 @@ public ListResponse List( offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -127,7 +127,7 @@ public async Task> ListAsync( /// Identifier. public DeleteResponse Delete(string id) { - return DeleteResource>(id).Result; + return Task.Run(async () => await DeleteResource>(id).ConfigureAwait(false)).Result; } /// /// Asynchronously delete Identity with the specified id. @@ -256,7 +256,7 @@ public IdentityCreateResponse Create( filesToUpload.Add("file", fileToUpload); } - var result = Client.Update(Uri, data, filesToUpload).Result; + var result = Task.Run(async () => await Client.Update(Uri, data, filesToUpload).ConfigureAwait(false)).Result; return result.Object; } /// @@ -476,7 +476,7 @@ public UpdateResponse Update( { filesToUpload.Add("file", fileToUpload); } - var result = Client.Update>(Uri + identityId + "/", data, filesToUpload).Result; + var result = Task.Run(async () => await Client.Update>(Uri + identityId + "/", data, filesToUpload).ConfigureAwait(false)).Result; return result.Object; } /// diff --git a/src/Plivo/Resource/Message/MessageInterface.cs b/src/Plivo/Resource/Message/MessageInterface.cs index 8ea96d71..92b10ca3 100644 --- a/src/Plivo/Resource/Message/MessageInterface.cs +++ b/src/Plivo/Resource/Message/MessageInterface.cs @@ -80,7 +80,7 @@ public MessageCreateResponse Create( return getResponseValidation("Specify either powerpack_uuid or src in request params to send a message."); } - var result = Client.Update(Uri, data).Result; + var result = Task.Run(async () => await Client.Update(Uri, data).ConfigureAwait(false)).Result; return result.Object; } @@ -178,7 +178,7 @@ private MessageCreateResponse getResponseValidation(string errorMessageText){ /// Message UUID. public Message Get(string messageUuid) { - var message = GetResource(messageUuid).Result; + var message = Task.Run(async () => await GetResource(messageUuid).ConfigureAwait(false)).Result; message.Interface = this; return message; } @@ -245,7 +245,7 @@ public ListResponse List( _message_time, error_code }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this diff --git a/src/Plivo/Resource/PhoneNumber/PhoneNumberInterface.cs b/src/Plivo/Resource/PhoneNumber/PhoneNumberInterface.cs index 2ecf668a..c39a970f 100644 --- a/src/Plivo/Resource/PhoneNumber/PhoneNumberInterface.cs +++ b/src/Plivo/Resource/PhoneNumber/PhoneNumberInterface.cs @@ -57,7 +57,7 @@ public ListResponse List( limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this @@ -126,10 +126,10 @@ public PhoneNumberBuyResponse Buy(string number, string appId = null, var mandatoryParams = new List {""}; var data = CreateData( mandatoryParams, new {appId, verificationInfo}); - var result = Client.Update( + var result = Task.Run(async () => await Client.Update( Uri + number + "/", data - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } diff --git a/src/Plivo/Resource/Pricing/PricingInterface.cs b/src/Plivo/Resource/Pricing/PricingInterface.cs index 39bdbcf7..d07833a7 100644 --- a/src/Plivo/Resource/Pricing/PricingInterface.cs +++ b/src/Plivo/Resource/Pricing/PricingInterface.cs @@ -27,10 +27,10 @@ public PricingInterface(HttpClient client) : base(client) /// Country iso. public Pricing Get(string countryIso) { - return GetResource("", new Dictionary() + return Task.Run(async() => await GetResource("", new Dictionary() { {"country_iso", countryIso} - }).Result; + }).ConfigureAwait(false)).Result; } /// /// Asynchronously get Procing for countryIso. diff --git a/src/Plivo/Resource/Recording/RecordingInterface.cs b/src/Plivo/Resource/Recording/RecordingInterface.cs index 07f93ec3..110af476 100644 --- a/src/Plivo/Resource/Recording/RecordingInterface.cs +++ b/src/Plivo/Resource/Recording/RecordingInterface.cs @@ -29,7 +29,7 @@ public RecordingInterface(HttpClient client) : base(client) /// Recording identifier. public Recording Get(string recordingId) { - var recording = GetResource(recordingId).Result; + var recording = Task.Run(async () => await GetResource(recordingId).ConfigureAwait(false)).Result; recording.Interface = this; return recording; } @@ -89,7 +89,7 @@ public ListResponse List( limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -155,7 +155,7 @@ public async Task> ListAsync( /// Recording identifier. public DeleteResponse Delete(string recordingId) { - return DeleteResource>(recordingId).Result; + return Task.Run(async () => await DeleteResource>(recordingId).ConfigureAwait(false)).Result; } /// diff --git a/src/Plivo/Resource/RentedNumber/RentedNumberInterface.cs b/src/Plivo/Resource/RentedNumber/RentedNumberInterface.cs index 3096b9c9..e2c6e965 100644 --- a/src/Plivo/Resource/RentedNumber/RentedNumberInterface.cs +++ b/src/Plivo/Resource/RentedNumber/RentedNumberInterface.cs @@ -30,7 +30,7 @@ public RentedNumberInterface(HttpClient client) : base(client) /// Number. public RentedNumber Get(string number) { - var rentedNumber = GetResource(number).Result; + var rentedNumber = Task.Run(async () => await GetResource(number).ConfigureAwait(false)).Result; rentedNumber.Interface = this; return rentedNumber; } @@ -78,7 +78,7 @@ public ListResponse List( limit, offset }); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -152,7 +152,7 @@ public UpdateResponse AddNumber( appId, subaccount }); - var result = Client.Update>(Uri, data).Result; + var result = Task.Run(async () => await Client.Update>(Uri, data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -213,10 +213,10 @@ public UpdateResponse Update( verificationInfo }); if (appId == "null") data["app_id"] = null; - var result = Client.Update>( + var result = Task.Run(async () => await Client.Update>( Uri + number + "/", data - ).Result; + ).ConfigureAwait(false)).Result; return result.Object; } @@ -261,7 +261,7 @@ public async Task> UpdateAsync( /// Number. public DeleteResponse Delete(string number) { - return DeleteResource>(number).Result; + return Task.Run(async () => await DeleteResource>(number).ConfigureAwait(false)).Result; } /// /// Asynchronously unrent RentedNumber with the specified number. diff --git a/src/Plivo/Resource/Subaccount/SubaccountInterface.cs b/src/Plivo/Resource/Subaccount/SubaccountInterface.cs index 35e2ba4c..e316c062 100644 --- a/src/Plivo/Resource/Subaccount/SubaccountInterface.cs +++ b/src/Plivo/Resource/Subaccount/SubaccountInterface.cs @@ -28,7 +28,7 @@ public SubaccountCreateResponse Create(string name, bool? enabled = null) { var mandatoryParams = new List {"name"}; var data = CreateData(mandatoryParams, new {name, enabled}); - var result = Client.Update(Uri, data).Result; + var result = Task.Run(async () => await Client.Update(Uri, data).ConfigureAwait(false)).Result; return result.Object; } /// @@ -55,7 +55,7 @@ public async Task CreateAsync(string name, bool? enabl /// Identifier. public Subaccount Get(string id) { - var subaccount = GetResource(id).Result; + var subaccount = Task.Run(async () => await GetResource(id).ConfigureAwait(false)).Result; subaccount.Interface = this; return subaccount; } @@ -83,7 +83,7 @@ public ListResponse List(uint? limit = null, uint? offset = null) { var mandatoryParams = new List { }; var data = CreateData(mandatoryParams, new {limit, offset}); - var resources = ListResources>(data).Result; + var resources = Task.Run(async () => await ListResources>(data).ConfigureAwait(false)).Result; resources.Objects.ForEach( (obj) => obj.Interface = this ); @@ -123,7 +123,7 @@ public DeleteResponse Delete(string id, bool? cascade = null) { data = CreateData(new List {}, new {cascade}); } - return DeleteResource>(id, data).Result; + return Task.Run(async () => await DeleteResource>(id, data).ConfigureAwait(false)).Result; } /// /// Asynchronously delete Subaccount with the specified id. @@ -155,7 +155,7 @@ public UpdateResponse Update(string id, string name, bool? enabled = var mandatoryParams = new List {"id", "name"}; var data = CreateData( mandatoryParams, new {name, enabled}); - var result = Client.Update>(Uri + id + "/", data).Result; + var result = Task.Run(async () => await Client.Update>(Uri + id + "/", data).ConfigureAwait(false)).Result; return result.Object; } /// From 536979d5a12cf911424ed0ecd17a8e1c3c10b324 Mon Sep 17 00:00:00 2001 From: suresach Date: Fri, 4 Jan 2019 17:17:39 +0530 Subject: [PATCH 2/2] bump version to 4.2.3 --- CHANGELOG.md | 3 +++ src/Plivo/Plivo.csproj | 2 +- src/Plivo/Plivo.nuspec | 3 ++- src/Plivo/Version.cs | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 019a346a..c9810265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log +## [v4.2.3](https://github.com/plivo/plivo-dotnet/tree/v4.2.3) (2019-01-04) +- Update Thread Safety handling for synchronous execution. + ## [v4.2.2](https://github.com/plivo/plivo-dotnet/tree/v4.2.2) (2018-12-27) - Fix dynamic object usage with async/await statement. diff --git a/src/Plivo/Plivo.csproj b/src/Plivo/Plivo.csproj index 0059e546..dd59569c 100644 --- a/src/Plivo/Plivo.csproj +++ b/src/Plivo/Plivo.csproj @@ -2,7 +2,7 @@ netstandard2.0;netstandard1.3 - 4.2.2 + 4.2.3 Plivo SDKs Team Plivo Inc. diff --git a/src/Plivo/Plivo.nuspec b/src/Plivo/Plivo.nuspec index 501bcf0c..c5e640bd 100644 --- a/src/Plivo/Plivo.nuspec +++ b/src/Plivo/Plivo.nuspec @@ -4,7 +4,7 @@ A .NET SDK to make voice calls & send SMS using Plivo and to generate Plivo XML A .NET SDK to make voice calls & send SMS using Plivo and to generate Plivo XML Plivo - 4.2.2 + 4.2.3 Plivo Plivo SDKs Team Plivo, Inc. @@ -12,6 +12,7 @@ http://github.com/plivo/plivo-dotnet false + * 4.2.3 Update Thread Safety handling for synchronous execution. * 4.2.2 Fix dynamic object usage with async/await statement. * 4.2.1 Fix Web Proxy support. * 4.2.0 Changed base reference to .NET Standard 2.0 to support System.Web.Proxy. Added Strong Naming instructions diff --git a/src/Plivo/Version.cs b/src/Plivo/Version.cs index 3fd85cce..f2b96d9f 100644 --- a/src/Plivo/Version.cs +++ b/src/Plivo/Version.cs @@ -10,7 +10,7 @@ public class Version /// /// DotNet SDK version /// - public const string SdkVersion = "4.2.2"; + public const string SdkVersion = "4.2.3"; /// /// Plivo API version