Пример #1
0
        public virtual IEnumerable <Tuple <TransferDataType, IContentIo <Stream> > > SinksOf(IEnumerable <TransferDataType> sources)
        {
            var result   = new List <Tuple <TransferDataType, IContentIo <Stream> > > ();
            var prefered = MimeFingerPrints.Prefer(sources.Select(s => s.Id))
                           .ToArray();

            sources = sources.Where(s => prefered.Contains(MimeFingerPrints.Synonym(s.Id).ToLower()));
            foreach (var source in sources)
            {
                var  sourceId    = MimeFingerPrints.Synonym(source.Id.ToLower());
                long contentType = 0;
                Func <IContentIo <Stream>, bool> lookUp = null;
                if (TransferContentTypes.TryGetValue(sourceId.ToLower(), out contentType))
                {
                    lookUp = sinkIo => sinkIo.Detector.ContentSpecs
                             .Any(info => info.ContentType == contentType);
                }
                else
                {
                    lookUp = sinkIo => sinkIo.Detector.ContentSpecs
                             .Any(info => info.MimeType == sourceId);
                }
                var done = new Set <long>();

                foreach (var sinkIo in ContentIoPool.Where(lookUp)
                         .Where(io => !io.Detector.ContentSpecs.Any(info => done.Contains(info.ContentType))))
                {
                    result.Add(Tuple.Create(source, sinkIo));
                }
            }
            return(result.OrderBy(r => ContentIoPool.Priority(r.Item2)));
        }
Пример #2
0
        public virtual IEnumerable <ContentInfo> InfoOf(IContentIo <Stream> io, IEnumerable <TransferDataType> sources)
        {
            var result = new List <ContentInfo> ();

            foreach (var source in sources)
            {
                var  sourceId    = MimeFingerPrints.Synonym(source.Id);
                long contentType = 0;
                Func <IContentIo <Stream>, IEnumerable <ContentInfo> > lookUp = null;

                if (TransferContentTypes.TryGetValue(sourceId.ToLower(), out contentType))
                {
                    lookUp = sinkIo => sinkIo.Detector.ContentSpecs
                             .Where(info => info.ContentType == contentType);
                }
                else
                {
                    lookUp = sinkIo => sinkIo.Detector.ContentSpecs
                             .Where(info => info.MimeType == sourceId);
                }
                result.AddRange(lookUp(io));
            }

            return(result);
        }