public IEnumerable <VisualHref> VisualHrefsOf(IStreamThing source) { source.DeCompress(); IEnumerable <VisualHref> result = new VisualHref[0]; var stream = source.Data; if (stream == null) { return(null); } try { stream.Position = 0; var graph = new VisualThingGraph() { Source = ThingGraph }; var serializer = new VisualThingXmlSerializer { VisualThingGraph = graph, Layout = this.Layout }; serializer.Read(stream); stream.Position = 0; result = serializer.VisualsCollection .Where(v => !(v is IVisualEdge)) .Select(v => HrefOfVisual(graph, v)) .ToArray(); } catch (Exception ex) { // TODO: stream-closed-error should never happen.Try to get reread the source Registry.Pooled <IExceptionHandler> ().Catch(ex, MessageType.OK); } finally { source.ClearRealSubject(); } return(result); }
public void ProveStream(Id id) { IStreamThing thing = Graph.GetById(id) as IStreamThing; thing.DeCompress(); Assert.AreEqual(thing.Data.Length, Stream.Length); thing.ClearRealSubject(); this.Close(); }
/// <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); }