1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Xml;
- using Masuit.Tools.Mime;
- namespace Masuit.Tools.Files.FileDetector.Detectors;
- [FormatCategory(FormatCategory.Document)]
- internal sealed class ConfigurationDetector : IDetector
- {
- public string Precondition => "txt";
- public string Extension => "config";
- public string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
- public List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
- public bool Detect(Stream stream)
- {
- try
- {
- var reader = XmlReader.Create(stream, new XmlReaderSettings()
- {
- });
- if (reader.Read() && reader.IsStartElement() && reader.Name == "configuration")
- {
- return true;
- }
- }
- catch
- {
- }
- return false;
- }
- public override string ToString() => "Microsoft .NET Configuration File Detector";
- }
|