Пример #1
0
        public async Task AddPeople(string path)
        {
            var settings = new XmlReaderSettings
            {
                IgnoreWhitespace = true
            };

            try
            {
                using (var reader = XmlReader.Create(path, settings))
                {
                    reader.ReadToFollowing("People");
                    while (reader.Name == "People")
                    {
                        var people = new People();
                        people.ReadXml(reader);
                        if (!await HelperConnect.FindEmail(people.Email))
                        {
                            people.Birthday = HelperWorkWithData.TransformDate(people.Birthday);
                            await HelperConnect.AddPeople(people);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Wrong format XML:" + e.Message);
            }
        }
Пример #2
0
 public async Task AddPeople(string path)
 {
     try
     {
         var text = "";
         using (var sr = new StreamReader(path, Encoding.Default))
         {
             string line;
             while ((line = sr.ReadLine()) != null)
             {
                 text += line;
             }
         }
         var peoples = JsonConvert.DeserializeObject <List <People> >(text);
         foreach (var people in peoples)
         {
             if (!await HelperConnect.FindEmail(people.Email))
             {
                 people.Birthday = HelperWorkWithData.TransformDate(people.Birthday);
                 await HelperConnect.AddPeople(people);
             }
         }
     }catch (Exception e)
     {
         logger.Error("Wrong JSON format: " + e.Message);
     }
 }