public void GetMessages(int accountId, string propertyHref, CampaignsPostGetMessagesRequest campaigns, Action <string> onSuccessAction, Action <Exception> onErrorAction, int environment, int millisTimeout) { msTimeout = millisTimeout; instance.client.Timeout = TimeSpan.FromMilliseconds(millisTimeout); string idfaStatus = "unknown"; var dict = new Dictionary <string, string> { { "type", "RecordString" } }; var includeData = new IncludeDataPostGetMessagesRequest() { localState = dict, messageMetaData = dict, TCData = dict }; var requestBody = new PostGetMessagesRequest(accountId, propertyHref, idfaStatus, GUID.Value, campaigns, SaveContext.GetLocalState(), // new LocalState(), // TODO: remove & uncomment line above includeData); Task.Factory.StartNew(async delegate { await PostGetMessages(requestBody, environment, onSuccessAction, onErrorAction); }); }
async Task PostGetMessages(PostGetMessagesRequest body, int environment, Action <string> onSuccessAction, Action <Exception> onErrorAction) { try { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var options = new JsonSerializerOptions { IgnoreNullValues = true }; string json = JsonSerializer.Serialize(body, options); var data = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(GetGetMessagesUriWithQueryParams(environment), data); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); dispatcher.Enqueue(delegate { onSuccessAction?.Invoke(responseBody); }); } catch (Exception ex) { dispatcher.Enqueue(delegate { onErrorAction?.Invoke(ex); }); } }