Пример #1
0
        //Takes organizationId and msgId and returns the a specific DifiMessage based on msgId for that organization
        public async Task <DifiMessage> GetDifiMessageAsync(string organizationId, string msgId)
        {
            //Passes the orgId to the dictionary in order to retrive information about the Organization's API's etc
            var orgConfig = await _configService.GetConfigAsync(organizationId);

            //Variable request does the api query and puts json response in variable response
            var request = new HttpRequestMessage(HttpMethod.Get, $"{orgConfig.IntegrationPoint}/api/conversations?messageId={msgId}");

            request.Headers.Add("Accept", "application/json");
            var response = await Client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                //Read the response as stream and deserialize it into the variable difiMessages(a list) - return the first and only entry in the list, a single DifiMessage
                using var responseStream = await response.Content.ReadAsStreamAsync();

                var difiMessages = await JsonSerializer.DeserializeAsync <DifiMessageContent>(responseStream);

                if (difiMessages.content.Count() != 0)
                {
                    return(_messagesService.AddLatestStatusOnSingle(difiMessages.content.ToList().First()));
                }
                else
                {
                    return(null);
                }
            }
            else if (response.StatusCode.Equals(500))
            {
                throw new ServiceUnavailableException("Difi integrationpoint is unavailable");
            }
            else
            {
                var ex = response.StatusCode.ToString();
                throw new DifiException(ex);
            }
        }