Пример #1
0
        public async Task <T> GetSubjectAsync <T>(KnowedgebaseSubjects subject, CancellationToken token) where T : class
        {
            try
            {
                using (var reader = await _source.GetKnowledgebaseXml(subject, token))
                {
                    var serialiser = new XmlSerializer(typeof(T));
                    return(serialiser.Deserialize(reader) as T);
                }
            }
            catch (KnowledgebaseException)
            {
                throw;
            }
            catch (AggregateException ae)
            {
                if (ae.InnerExceptions.Count == 1)
                {
                    throw ae.InnerExceptions[0];
                }

                throw;
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error when deserialising xml for {subject}", subject);
                throw new KnowledgebaseException($"Error when deserialising xml for {subject}");
            }
        }
Пример #2
0
 public async void GetXml(KnowedgebaseSubjects subject, string expectedRoot)
 {
     using (var reader =
                await _client.GetKnowledgebaseXml(subject, CancellationToken.None))
     {
         while (reader.Read())
         {
             if (reader.IsStartElement())
             {
                 Assert.Equal(expectedRoot, reader.Name);
                 break;
             }
         }
     }
 }