Пример #1
0
        private static string?FindShowCode([NotNull] FileInfo file, string simpleIdCode, string uniqueIdCode)
        {
            try
            {
                using (System.IO.StreamReader? streamReader = file.OpenText())
                {
                    using (XmlReader reader = XmlReader.Create(streamReader))
                    {
                        while (reader.Read())
                        {
                            if (reader.Name == simpleIdCode && reader.IsStartElement())
                            {
                                string s = reader.ReadElementContentAsString();
                                if (s.HasValue())
                                {
                                    return(s);
                                }
                            }

                            if (reader.Name == "uniqueid" && reader.IsStartElement() &&
                                reader.GetAttribute("type") == uniqueIdCode)
                            {
                                string s = reader.ReadElementContentAsString();
                                if (s.HasValue())
                                {
                                    return(s);
                                }
                            }
                        }
                    }
                }
            }
            catch (XmlException xe)
            {
                Logger.Warn($"Could not parse {file.FullName} to try and see whether there is any Ids inside, got {xe.Message}");
            }
            catch (System.IO.IOException xe)
            {
                Logger.Warn($"Could not parse {file.FullName} to try and see whether there is any Ids inside, got {xe.Message}");
            }
            catch (UnauthorizedAccessException xe)
            {
                Logger.Warn($"Could not parse {file.FullName} to try and see whether there is any Ids inside, got {xe.Message}");
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Could not parse {file.FullName} to try and see whether there is any Ids inside.");
            }

            return(null);
        }
 public override StreamReader OpenText()
 {
     return(instance.OpenText());
 }