Exemplo n.º 1
0
        private void ImportStream(ZipPackage package, XmlTextReader reader)
        {
            reader.ReadStartElement();

            while (true)
            {
                try
                {
                    if (_context.IsAborting && !_context.ContinueOnError)
                    {
                        break;
                    }
                    else if (reader.IsStartElement("pages"))
                    {
                        ImportContents <TransferPageData>(reader);
                    }
                    else if (!reader.Read())
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    _context.Abort();
                    if (!_context.ContinueOnError)
                    {
                        throw;
                    }
                    //Importer.Log.Error("Exception: {0}[{1}]", e, e.Message, e.InnerException != null ? e.InnerException.Message : String.Empty);
                }
            }
        }
        public virtual void ParseElement(XmlReader reader)
        {
            reader.Read(); // Read away
            while (reader.IsStartElement(typeof(TransferPageData).Name) && (!_readerContext.IsAborting || _readerContext.ContinueOnError))
            {
                try
                {
                    var serializer = new XmlSerializer(typeof(TransferPageData));
                    var content    = serializer.Deserialize(reader) as ITransferContentData;
                    if (content.RawContentData == null)
                    {
                        continue;
                    }

                    foreach (var collector in _collectors)
                    {
                        collector.Collect(content);
                    }
                    //OnContentScanned(new ContentScanEventArgs(content, null /*_context.Importer*/));
                }
                catch (Exception ex)
                {
                    _readerContext.Abort();
                    if (!_readerContext.ContinueOnError)
                    {
                        throw;
                    }
                    Logger.Error(String.Format("Failed to Import Content. Reason is {0}", ex.Message), ex);
                }
            }

            reader.ReadEndElement(); // Contents
        }
        public virtual void ParseElement(XmlReader reader)
        {
            var pageTypes = Deserialize(reader);

            foreach (var pageType in pageTypes.Where(pt => !IgnoredPageTypes.Contains(pt.Name)))
            {
                if (_readerContext.IsAborting)
                {
                    break;
                }
                try
                {
                    var contentType = _mapper.Map(pageType);
                    _contentTypeWriter.Write(contentType);
                }
                catch (Exception ex)
                {
                    _readerContext.Abort();
                    if (!_readerContext.ContinueOnError)
                    {
                        throw;
                    }
                    Logger.Error("Failed to parse xml content.", ex);
                }
            }
        }
        public virtual void ReadPackage(Stream stream)
        {
            if (stream == null)
            {
                return;
            }

            try
            {
                using (var package = (ZipPackage)ZipPackage.Open(stream))
                {
                    ReadPartOfPackage(package, PackageContentName, ReadXmlStream);
                }
            }
            catch (Exception ex)
            {
                _readerContext.Abort();
                if (!_readerContext.ContinueOnError)
                {
                    throw;
                }
                Logger.Error(string.Format("Failed to read packet. Reason is {0}", ex.Message));
            }
        }
Exemplo n.º 5
0
        public void ReadPackage(Stream stream, IPackageReaderContext context)
        {
            if (context == null || stream == null)
            {
                return;
            }

            try
            {
                using (var package = (ZipPackage)ZipPackage.Open(stream))
                {
                    ImportPartOfPackage(package, PackageContentName);
                }
            }
            catch (Exception ex)
            {
                context.Abort();
                if (!context.ContinueOnError)
                {
                    throw;
                }
                //Importer.Log.Error(string.Format("Failed to scan packet. Reason is {0}", ex.Message), ex);
            }
        }