Пример #1
0
        private static string SerializeJson(MovieEntity entity)
        {
            string json;
            var    js = new DataContractJsonSerializer(typeof(MovieEntity));

            using (var msObj = new MemoryStream())
            {
                js.WriteObject(msObj, entity);
                msObj.Position = 0;
                var sr = new StreamReader(msObj);

                json = sr.ReadToEnd();
            }

            return(json);
        }
Пример #2
0
        public async Task PostMovieAsync(string server, string apiKey, MovieEntity entity)
        {
            Log.Information("Adding movie {movieName} ({movieYear}) to server.", entity.title, entity.year);

            using (var client = CreateClient())
            {
                var url = $"http://{server}/api/movie?apikey={apiKey}";

                var json    = SerializeJson(entity);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                var result = await client.PostAsync(url, content);

                if (!result.IsSuccessStatusCode)
                {
                    throw new Exception("Error posting to Radarr: " + result.Content.ReadAsStringAsync().Result);
                }
            }
        }