コード例 #1
0
ファイル: ContentTypeTests.cs プロジェクト: jflepp/Epub
        public void GetMimeTypeForContentType_WithContentType_ReturnsMimeType(
            ContentType input, string expected)
        {
            var result = ContentTypeParser.GetMimeTypeContentType(input);

            Assert.AreEqual(expected, result);
        }
コード例 #2
0
ファイル: ContentTypeTests.cs プロジェクト: jflepp/Epub
        public void GetContentTypeFromMimeType_WithMimeType_ReturnsContentType(
            string input, ContentType expected)
        {
            var result = ContentTypeParser.GetContentTypeFromMimeType(input);

            Assert.AreEqual(expected, result);
        }
コード例 #3
0
ファイル: ManifestExtractor.cs プロジェクト: jflepp/Epub
 private static ManifestItem CreateFromXElement(XElement e)
 {
     return(new ManifestItem(
                e.GetAttributeValueOrNull(OpfXmlNames.IdAttributeName),
                e.GetAttributeValueOrNull(OpfXmlNames.HrefAttributeName),
                e.GetAttributeValueOrNull(OpfXmlNames.PropertiesAttributeName),
                ContentTypeParser.GetContentTypeFromMimeType(e.GetAttributeValueOrNull(OpfXmlNames.MediaTypeAttributeName))));
 }
コード例 #4
0
 public static File ToModel(this Api.ResponseObjects.Files.File @this)
 {
     return(new File
     {
         FileID = @this.id,
         Name = @this.name,
         ContentType = ContentTypeParser.ParseString(@this.content_type),
         Mp4Available = @this.is_mp4_available,
         ParentID = @this.parent_id,
         ScreenShot = @this.screenshot,
         Size = @this.size,
         CreatedDate = @this.created_at.ToDateTime()
     });
 }
コード例 #5
0
        private static void UnZip(CompressedProduct product, IEventPublisher ctx)
        {
            using (var zip = new ZipArchive(product.GetStream(), ZipArchiveMode.Read))
            {
                foreach (var file in zip.Entries)
                {
                    using (var fileStream = file.Open())
                    {
                        var fileName    = file.Name.ToUpperInvariant();
                        var contentType = ContentTypeParser.GetFileContentType(fileName);
                        switch (contentType)
                        {
                        case ContentFileType.Text:
                            using (var text = new StreamReader(fileStream))
                            {
                                var textProduct = TextProduct.Create(fileName, file.LastWriteTime, text.ReadToEnd(),
                                                                     product.ReceivedAt, product.Source);
                                ctx.SendMessage(textProduct);
                                ProcessorEventSource.Log.Info(nameof(ZipExtractor), textProduct.ToString());
                            }
                            break;

                        case ContentFileType.Image:
                            var imageProduct = ImageProduct.Create(
                                fileName, file.LastWriteTime, ReadAllBytes(fileStream), product.ReceivedAt, product.Source);
                            ctx.SendMessage(imageProduct);
                            ProcessorEventSource.Log.Info(nameof(ZipExtractor), imageProduct.ToString());
                            break;

                        // There are no zips within zips :-)

                        default:
                            ProcessorEventSource.Log.Warning(nameof(ZipExtractor),
                                                             "Unknown content file type: " + file.Name);
                            return;
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// This will be called every time a QuickBlockTransferSegment[] bundle is published through the event aggregator
        /// </summary>
        /// <param name="bundle">The bundle.</param>
        /// <param name="ctx">The CTX.</param>
        public void Handle(QuickBlockTransferSegment[] bundle, IEventAggregator ctx)
        {
            try
            {
                var contentType = ContentTypeParser.GetFileContentType(bundle[0].Filename);
                switch (contentType)
                {
                case ContentFileType.Text:
                    var textProduct = bundle.AsTextProduct();
                    ProcessorEventSource.Log.Verbose(nameof(ProductAssembler), textProduct.ToString());
                    ctx.SendMessage(textProduct);
                    break;

                case ContentFileType.Image:
                    var imageProduct = bundle.AsImageProduct();
                    ProcessorEventSource.Log.Verbose(nameof(ProductAssembler), imageProduct.ToString());
                    ctx.SendMessage(imageProduct);
                    break;

                case ContentFileType.Compressed:
                    var compressedProduct = bundle.AsCompressedProduct();
                    ProcessorEventSource.Log.Verbose(nameof(ProductAssembler), compressedProduct.ToString());
                    ctx.SendMessage(compressedProduct);
                    break;

                default:
                    ProcessorEventSource.Log.Warning(nameof(ProductAssembler),
                                                     "Unknown content file type: " + contentType);
                    return;
                }

                PerformanceCounters.ProductsCreatedTotal.Increment();
            }
            catch (Exception ex)
            {
                ProcessorEventSource.Log.Error(nameof(ProductAssembler), ex.ToString());
            }
        }