Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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.º 3
0
        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();
        }
Exemplo n.º 4
0
 /// <summary>
 /// assigns the the content to the thing
 /// </summary>
 /// <param name="thing"></param>
 /// <param name="content"></param>
 public void AssignContent(IStreamThing thing, Content <Stream> content)
 {
     if (thing == null || thing.ContentContainer == null || content == null || content.Data == null)
     {
         return;
     }
     thing.Data        = content.Data;
     thing.Compression = content.Compression;
     thing.StreamType  = content.ContentType;
     thing.Compress();
     thing.Flush();
     thing.ClearRealSubject();
 }
Exemplo n.º 5
0
        protected IGraphScene <IVisual, IVisualEdge> LoadFromThing(IStreamThing sourceThing, IGraph <IVisual, IVisualEdge> sourceGraph, IGraphSceneLayout <IVisual, IVisualEdge> layout)
        {
            var result  = default(IGraphScene <IVisual, IVisualEdge>);
            var content = sourceGraph.ThingGraph().ContentOf(sourceThing);

            try {
                content.Source = sourceThing.Id;
                result         = LoadFromContent(content, sourceGraph, layout);
            } finally {
                sourceThing.ClearRealSubject();
            }
            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// assigns the the content to the thing
        /// if thing is null, a new StreamThing is created
        /// </summary>
        /// <param name="thing"></param>
        /// <param name="content"></param>
        public IStreamThing AssignContent(IThingGraph graph, IStreamThing thing, Content <Stream> content)
        {
            if (thing != null)
            {
                thing.ContentContainer = graph.ContentContainer;
                AssignContent(thing, content);
                AssignContentDescription(thing, content, graph);
            }
            else
            {
                thing = CreateAndAdd(graph, content);
                AssignContentDescription(thing, content, graph);
            }

            return(thing);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        protected void LoadStreamThing(ContentStreamViewer viewer, IThingGraph graph, IStreamThing thing)
        {
            try {
                viewer.IsStreamOwner = IsStreamOwner;
                if (viewer.ContentId != thing.Id)
                {
                    SaveStream(graph, viewer);

                    var content = graph.ContentOf(thing);
                    if (viewer is SheetViewer)
                    {
                        content.Source = thing.Id;
                    }

                    if (viewer is HtmlContentViewer)
                    {
                        var htmlViewr = (HtmlContentViewer)viewer;
                        htmlViewr.ContentThing = thing;
                        htmlViewr.ThingGraph   = graph;
                    }


                    viewer.SetContent(content);
                    viewer.ContentId = thing.Id;
                }
            } catch (Exception ex) {
                ExceptionHandler.Catch(ex, MessageType.OK);
            } finally {
                thing.ClearRealSubject(!IsStreamOwner);
            }
        }