public async Task <string> CreateLiveEventAsync(LiveEventForRest liveEventSettings, bool startLiveEventNow)
        {
            string URL = GenerateApiUrl(liveEventSettings.Name) + string.Format("&autoStart={0}", startLiveEventNow.ToString());

            string token = _amsClient.accessToken != null ? _amsClient.accessToken.AccessToken :
                           TokenCache.DefaultShared.ReadItems()
                           .Where(t => t.ClientId == _amsClient.credentialsEntry.ADSPClientId)
                           .OrderByDescending(t => t.ExpiresOn)
                           .First().AccessToken;

            var client = _amsClient.AMSclient.HttpClient;

            client.DefaultRequestHeaders.Remove("Authorization");
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            var _requestContent = liveEventSettings.ToJson(); // Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(liveEvent, serializationSettings);
            var httpContent     = new StringContent(_requestContent, System.Text.Encoding.UTF8);

            httpContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

            HttpResponseMessage amsRequestResult = await client.PutAsync(URL, httpContent).ConfigureAwait(false);

            string responseContent = await amsRequestResult.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (!amsRequestResult.IsSuccessStatusCode)
            {
                dynamic error = JsonConvert.DeserializeObject(responseContent);
                throw new Exception((string)error?.error?.message);
            }

            return(responseContent);
        }
        public async Task <LiveEventForRest> GetLiveEventAsync(string liveEventName)
        {
            string URL = GenerateApiUrl(liveEventName);

            string token = _amsClient.accessToken != null ? _amsClient.accessToken.AccessToken :
                           TokenCache.DefaultShared.ReadItems()
                           .Where(t => t.ClientId == _amsClient.credentialsEntry.ADSPClientId)
                           .OrderByDescending(t => t.ExpiresOn)
                           .First().AccessToken;

            var client = _amsClient.AMSclient.HttpClient;

            client.DefaultRequestHeaders.Remove("Authorization");
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            HttpResponseMessage amsRequestResult = await client.GetAsync(URL).ConfigureAwait(false);

            string responseContent = await amsRequestResult.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (!amsRequestResult.IsSuccessStatusCode)
            {
                dynamic error = JsonConvert.DeserializeObject(responseContent);
                throw new Exception((string)error?.error?.message);
            }

            return(LiveEventForRest.FromJson(responseContent));
        }
 public static string ToJson(this LiveEventForRest self) => JsonConvert.SerializeObject(self, AMSExplorer.ConverterLE.Settings);