示例#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 IContentIo <Stream> SinkOf(string extension)
 {
     return(ContentIoPool.Where(sinkIo => sinkIo.Detector.ContentSpecs
                                .Any(info => info.Extension == extension)).FirstOrDefault());
 }