示例#1
0
        /// <summary>
        /// Loads fb2 file's content into Fb2Document model from stream.
        /// </summary>
        /// <param name="fileContent">Stream of file data, opened for read.</param>
        /// <param name="loadingOptions">Fb2Document stream loading options. This parameter is optional.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <remarks>Actual encoding of content will be determined automatically or <see cref="Encoding.Default"/> will be used.</remarks>
        public void Load([In] Stream fileContent, Fb2StreamLoadingOptions?loadingOptions = null)
        {
            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }

            if (!fileContent.CanRead)
            {
                throw new ArgumentException($"Can`t read {nameof(fileContent)}, {nameof(Stream.CanRead)} is {false}");
            }

            var options = loadingOptions ?? new Fb2StreamLoadingOptions();

            var xmlReaderSetting = DefaultXmlReaderSettings.Clone();

            xmlReaderSetting.CloseInput = options.CloseInputStream;

            LoadHandled(() =>
            {
                using (var reader = XmlReader.Create(fileContent, xmlReaderSetting))
                {
                    var document = XDocument.Load(reader);
                    Load(document.Root, options);
                }
            });
        }
示例#2
0
            public XmlReaderSettings Get(XmlReaderSettings parameter)
            {
                var result = parameter.Clone();

                result.CloseInput = true;
                return(result);
            }
示例#3
0
        public object Clone()
        {
            var c = this.MemberwiseClone() as ValidadorEstructura;

            c._settings = _settings.Clone();
            return(c);
        }
示例#4
0
        public object Clone()
        {
            var s = settings.Clone();
            var o = this.MemberwiseClone() as ValidadorEstructuraRetenciones;

            o.settings = s;
            return(o);
        }
示例#5
0
        private static XmlReaderSettings InitializeXmlReaderSettingsForDTD()
        {
            XmlReaderSettings xmlReaderSettings = XmlReaderSettingsForSchema.Clone();

            // CloseInput is false so that the DTD-validating reader does not close the underlying stream
            xmlReaderSettings.CloseInput     = false;
            xmlReaderSettings.ValidationType = ValidationType.DTD;
            return(xmlReaderSettings);
        }
示例#6
0
        private XmlReaderSettings GetXmlReaderSettings()
        {
            var settings = _xmlReaderSettings.Clone();

            settings.CloseInput  = true;
            settings.XmlResolver = _xmlResolver;

            return(settings);
        }
        protected XmlReaderSettings GetReaderSettings(XmlInput defaultDocument)
        {
            if (defaultDocument.Resolver is DefaultXmlResolver)
            {
                return(DefaultReaderSettings);
            }
            var settings = DefaultReaderSettings.Clone();

            settings.XmlResolver = defaultDocument.Resolver;
            return(settings);
        }
示例#8
0
 private XmlReaderSettings GetReaderSettings(XmlInput defaultDocument)
 {
     if (defaultDocument.resolver is DefaultXmlResolver)
     {
         return(DefaultReaderSettings);
     }
     else
     {
         XmlReaderSettings settings = DefaultReaderSettings.Clone();
         settings.XmlResolver = defaultDocument.resolver;
         return(settings);
     }
 }
示例#9
0
        public QueryReaderSettings(XmlReader reader)
        {
#pragma warning disable 618
            XmlValidatingReader valReader = reader as XmlValidatingReader;
#pragma warning restore 618
            if (valReader != null)
            {
                // Unwrap validation reader
                _validatingReader = true;
                reader            = valReader.Impl.Reader;
            }
            _xmlReaderSettings = reader.Settings;
            if (_xmlReaderSettings != null)
            {
                _xmlReaderSettings                    = _xmlReaderSettings.Clone();
                _xmlReaderSettings.NameTable          = reader.NameTable;
                _xmlReaderSettings.CloseInput         = true;
                _xmlReaderSettings.LineNumberOffset   = 0;
                _xmlReaderSettings.LinePositionOffset = 0;
                XmlTextReaderImpl impl = reader as XmlTextReaderImpl;
                if (impl != null)
                {
                    _xmlReaderSettings.XmlResolver = impl.GetResolver();
                }
            }
            else
            {
                _xmlNameTable = reader.NameTable;
                XmlTextReader xmlTextReader = reader as XmlTextReader;
                if (xmlTextReader != null)
                {
                    XmlTextReaderImpl impl = xmlTextReader.Impl;
                    _entityHandling     = impl.EntityHandling;
                    _namespaces         = impl.Namespaces;
                    _normalization      = impl.Normalization;
                    _prohibitDtd        = (impl.DtdProcessing == DtdProcessing.Prohibit);
                    _whitespaceHandling = impl.WhitespaceHandling;
                    _xmlResolver        = impl.GetResolver();
                }
                else
                {
                    _entityHandling     = EntityHandling.ExpandEntities;
                    _namespaces         = true;
                    _normalization      = true;
                    _prohibitDtd        = true;
                    _whitespaceHandling = WhitespaceHandling.All;
                    _xmlResolver        = null;
                }
            }
        }
示例#10
0
        private static XmlReader CreateOutline(int parts, XmlReaderSettings settings)
        {
            var builder = new StringBuilder(1024);

            builder.Append("<agg:Root xmlns:agg=\"http://schemas.microsoft.com/BizTalk/2003/aggschema\">");
            for (var i = 0; i < parts; i++)
            {
                builder.AppendFormat("<agg:InputMessagePart_{0}></agg:InputMessagePart_{0}>", i);
            }
            builder.Append("</agg:Root>");

            settings            = settings.Clone();
            settings.CloseInput = true;
            return(Create(new StringReader(builder.ToString()), settings));
        }
        private static XmlReader CreateOutline(int parts, XmlReaderSettings settings)
        {
            var builder = new StringBuilder(1024);

            builder.Append($"<agg:Root xmlns:agg=\"{XML_AGGREGATE_SCHEMA_TARGET_NAMESPACE}\">");
            for (var i = 0; i < parts; i++)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "<agg:InputMessagePart_{0}></agg:InputMessagePart_{0}>", i);
            }

            builder.Append("</agg:Root>");

            settings            = settings.Clone();
            settings.CloseInput = true;
            return(Create(new StringReader(builder.ToString()), settings));
        }
示例#12
0
        private static XmlReader CreateOutline(int parts, XmlReaderSettings settings)
        {
            var builder = new StringBuilder(1024);

            builder.Append($"<agg:Root xmlns:agg=\"{XmlSchemaNamespaces.BizTalkAggregate}\">");
            for (var i = 0; i < parts; i++)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "<agg:InputMessagePart_{0}></agg:InputMessagePart_{0}>", i);
            }

            builder.Append("</agg:Root>");

            settings            = settings.Clone();
            settings.CloseInput = true;
            return(Create(new StringReader(builder.ToString()), settings));
        }
示例#13
0
        public void AsyncPropagation()
        {
            var s = new XmlReaderSettings();

            s.Async = true;
            var r = XmlReader.Create(new StringReader("<root/>"), s);

            var c = s.Clone();

            Assert.IsTrue(c.Async);
            c.Reset();
            Assert.IsFalse(c.Async);

            var r2 = XmlReader.Create(r, c);

            Assert.IsTrue(r2.Settings.Async);
        }
示例#14
0
 public IServiceRepository Get(IServiceRepository parameter)
 => parameter.RegisterInstance(Encoding.UTF8)
 .RegisterInstance(_names)
 .RegisterInstance(_reader.Clone())
 .RegisterInstance(_writer.Clone())
 .RegisterInstance <IIdentifierFormatter>(IdentifierFormatter.Default)
 .RegisterInstance <IReaderFormatter>(ReaderFormatter.Default)
 .RegisterInstance <IFormattedContentSpecification>(FormattedContentSpecification.Default)
 .RegisterInstance <IListContentsSpecification>(
     new ListContentsSpecification(
         IsTypeSpecification <
             IListInnerContent>
         .Default
         .And(ElementSpecification
              .Default)))
 .Register <IInnerContentActivation, XmlInnerContentActivation>()
 .Register <IFormatReaderContexts, FormatReaderContexts>()
 .Register <IFormatWriters <System.Xml.XmlWriter>, FormatWriters>()
 .Register <IXmlReaderFactory, XmlReaderFactory>()
 .Register <IFormatReaders <System.Xml.XmlReader>, FormatReaders>()
 .Register <IExtendedXmlSerializer, ExtendedXmlSerializer>();
示例#15
0
        public static XmlReader CreateCharCheckingReader(CreateReaderParams createParams)
        {
            XmlReaderSettings settings      = GetSettings(createParams);
            XmlParserContext  parserContext = GetParserContext(createParams);
            XmlReader         r             = null;

            settings.CheckCharacters = false;
            XmlReaderSettings rs = settings.Clone();

            rs.CheckCharacters = true;
            switch (createParams.InputType)
            {
            case ReadOverload.String:
                r = Create(new StringReader((string)createParams.Input), settings, parserContext);
                return(Create(r, rs));

            case ReadOverload.URL:
                r = Create((string)createParams.Input, settings);
                return(Create(r, rs));

            case ReadOverload.Stream:
                r = Create((Stream)createParams.Input, settings, parserContext);
                return(Create(r, rs));

            case ReadOverload.TextReader:
                r = Create((TextReader)createParams.Input, settings, parserContext);
                return(Create(r, rs));

            case ReadOverload.XmlReader:
                r = Create((XmlReader)createParams.Input, settings);
                return(Create(r, rs));

            default:
                throw new CTestFailedException("Unknown ReadOverload");
            }
        }
示例#16
0
 public int v4()
 {
     XmlReaderSettings rs = new XmlReaderSettings();
     XmlReaderSettings crs = rs.Clone();
     CError.Compare(rs.CheckCharacters, crs.CheckCharacters, "CheckCharacters");
     CError.Compare(rs.CloseInput, crs.CloseInput, "CloseInput");
     CError.Compare(rs.DtdProcessing, crs.DtdProcessing, "ProhibitDtd");
     CError.Compare(rs.IgnoreComments, crs.IgnoreComments, "IgnoreComments");
     CError.Compare(rs.IgnoreProcessingInstructions, crs.IgnoreProcessingInstructions, "IgnorePI");
     CError.Compare(rs.IgnoreWhitespace, crs.IgnoreWhitespace, "IgnoreWhitespace");
     CError.Compare(rs.LineNumberOffset, crs.LineNumberOffset, "LineNumberOffset");
     CError.Compare(rs.LinePositionOffset, crs.LinePositionOffset, "LinePositionOffset");
     CError.Compare(rs.MaxCharactersInDocument, crs.MaxCharactersInDocument, "maxcharsindoc");
     CError.Compare(rs.NameTable, crs.NameTable, "NameTable");
     CError.Compare(rs.ConformanceLevel, crs.ConformanceLevel, "ConformanceLevel");
     CError.Compare(rs.GetType(), crs.GetType(), "GetType");
     return TEST_PASS;
 }
示例#17
0
        static async Task <bool> P_TryRecognizeStreamContentAsXmlAsync(Stream stream, XmlReaderSettings xmlReaderSettings)
        {
            stream.EnsureNotNull(nameof(stream));
            xmlReaderSettings.EnsureNotNull(nameof(xmlReaderSettings));
            //
            if (stream.CanSeek)
            {
                var xmlReader  = default(XmlReader);
                var textReader = default(TextReader);
                var initialInputStreamPosition = default(long?);
                var tryException = default(Exception);
                try {
                    Func <Stream, bool, TextReader> createTextReader =
                        (locInputStream, locLeaveInputStreamOpen)
                        =>
                        new StreamReader(
                            stream: locInputStream,
                            encoding: Encoding.UTF8,
                            detectEncodingFromByteOrderMarks: true,
                            bufferSize: TextReaderWriterUtilities.DefaultBufferSize,
                            leaveOpen: locLeaveInputStreamOpen);
                    //
                    initialInputStreamPosition = stream.Position;
                    textReader = createTextReader(stream, true);
                    var xmlReaderSettingsClone = xmlReaderSettings.Clone();
                    xmlReaderSettingsClone.DtdProcessing = DtdProcessing.Prohibit;
                    xmlReaderSettingsClone.CloseInput    = false;
                    xmlReaderSettingsClone.IgnoreComments
                              = xmlReaderSettingsClone.IgnoreProcessingInstructions
                              = xmlReaderSettingsClone.IgnoreWhitespace
                              = true;
                    xmlReader = XmlReader.Create(textReader, xmlReaderSettingsClone);
                    //
                    bool isXml;
                    try {
                        isXml =
                            await
                            xmlReader
                            .ReadAsync()
                            .ConfigureAwait(false);

                        isXml = isXml && xmlReader.NodeType == XmlNodeType.XmlDeclaration;
                        //
                        stream.Position            = initialInputStreamPosition.Value;
                        initialInputStreamPosition = null;
                    }
                    catch (XmlException) {
                        isXml = false;
                    }
                    //
                    textReader.Dispose();
                    (xmlReader as IDisposable)?.Dispose();
                    //
                    return(isXml);
                }
                catch (Exception firstException) {
                    tryException = firstException;
                    throw;
                }
                finally {
                    try {
                        if (initialInputStreamPosition.HasValue)
                        {
                            try { stream.Position = initialInputStreamPosition.Value; }
                            catch (ObjectDisposedException) { }
                        }
                        if (tryException != null)
                        {
                            textReader?.Dispose();
                            (xmlReader as IDisposable)?.Dispose();
                        }
                    }
                    catch (Exception firstException) {
                        if (tryException == null)
                        {
                            throw;
                        }
                        else
                        {
                            throw tryException.ToAggregateException(firstException);
                        }
                    }
                }
            }
            else
            {
                return(false);
            }
        }
示例#18
0
 public XmlFilterReader(XmlReader reader, XmlReaderSettings settings)
 {
     this.reader   = reader;
     this.settings = settings.Clone();
     this.lineInfo = (reader as IXmlLineInfo);
 }