Exemplo n.º 1
0
        public StreamContent StreamContent(IStreamThing thing)
        {
            if (thing == null)
            {
                return(null);
            }

            var result = new StreamContent(thing.ContentOf());

            result.Source = thing.Id.ToString("X16");

            SetMimeType(result);

            if (result.ContentType == ContentTypes.TIF)
            {
                var sinkType  = ContentTypes.PNG;
                var converter = Registry.Pooled <ConverterPool <Stream> >()
                                .Find(ContentTypes.TIF, sinkType);

                if (converter != null)
                {
                    var conv = converter.Use(result, sinkType);
                    result.Data.Dispose();
                    result.Data        = conv.Data;
                    result.ContentType = conv.ContentType;

                    SetMimeType(result);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// gives back a content
        /// where data is a html-string
        /// null if not supported
        /// </summary>
        /// <param name="thing"></param>
        /// <returns></returns>
        public virtual HtmlContent HtmlContent(IStreamThing thing)
        {
            if (!IsConvertibleToHtml(thing))
            {
                return(null);
            }

            var result = new HtmlContent {
                Data        = thing.Id.ToString("X16"), // dummy value
                Description = ThingToDisplay(ThingGraph, thing).ToString(),
                ContentType = ContentTypes.HTML,
                Source      = thing.Id.ToString("X16"),
            };

            try {
                if (thing.StreamType == ContentTypes.HTML)
                {
                    thing.DeCompress();
                    var reader = new StreamReader(thing.Data);
                    result.Data = reader.ReadToEnd();
                    thing.ClearRealSubject();
                }
                else
                {
                    var sinkType  = ContentTypes.HTML;
                    var converter = Registry.Pooled <ConverterPool <Stream> > ()
                                    .Find(thing.StreamType, sinkType);
                    if (converter != null)
                    {
                        var source = thing.ContentOf();
                        using (var reader = new StreamReader(converter.Use(source, sinkType).Data))
                            result.Data = reader.ReadToEnd();
                        source.Data.Dispose();
                    }
                }
            } catch (Exception ex) {
#if DEBUG
                result.Data = "Error:" + ex.Message + "<br>" + ex.StackTrace;
#else
                result.Data = "Server überlastet. Bitte später nochmal probieren...";
#endif
                result.ContentType = ContentTypes.Unknown;
            }
            return(result);
        }