Beispiel #1
0
        public void LoadDiagrams(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName))
            {
                return;
            }

            this.UnloadDiagrams();

            string fileExt = IoPath.GetExtension(fileName);

            Cursor curCursor = this.Cursor;

            this.Cursor = Cursors.Wait;
            try
            {
                object xamlObject = null;

                if (string.Equals(fileExt, ".xaml", StringComparison.OrdinalIgnoreCase))
                {
                    using (XmlReader xmlReader = XmlReader.Create(new StreamReader(fileName)))
                    {
                        xamlObject = XamlReader.Load(xmlReader);
                    }
                }
                else if (string.Equals(fileExt, ".zaml", StringComparison.OrdinalIgnoreCase))
                {
                    using (FileStream fileStream = File.OpenRead(fileName))
                    {
                        using (GZipStream zipStream =
                                   new GZipStream(fileStream, CompressionMode.Decompress))
                        {
                            xamlObject = XamlReader.Load(zipStream);
                        }
                    }
                }

                if (xamlObject is SvgImageNameScope)
                {
                    SvgImageNameScope imageDrawing = (SvgImageNameScope)xamlObject;
                    RenderDiagrams(imageDrawing);
                }
                else if (xamlObject is DrawingGroup)
                {
                    DrawingGroup groupDrawing = (DrawingGroup)xamlObject;
                    RenderDiagrams(groupDrawing);
                }
            }
            finally
            {
                this.Cursor = curCursor;
            }
        }
        public void RenderDiagrams(SvgImageNameScope image)
        {
            DrawingImage drawingImage = image.Source as DrawingImage;

            if (drawingImage == null)
            {
                return;
            }

            DrawingGroup renderedGroup = drawingImage.Drawing as DrawingGroup;

            if (renderedGroup != null)
            {
                this.RenderDiagrams(renderedGroup);
            }
        }