Exemplo n.º 1
0
 public IObjectContainer DeSerializeData2Dom(Stream SrcStram)
 {
     if (_activeView == null)
     {
         return(null);
     }
     return(_activeView.AddObjects(SrcStram));
 }
Exemplo n.º 2
0
        protected override void RunInternal()
        {
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            IDocumentPage page1 = document.CreatePage("Page 1");
            ITreeNode     node1 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node1.AttachedObject = page1;

            page1.Open();

            // Get the page view for base adaptive view.
            IPageView baseView1 = page1.PageViews[document.AdaptiveViewSet.Base.Guid];

            IImage image = baseView1.CreateWidget(WidgetType.Image) as IImage;

            image.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            image.WidgetStyle.Height = 267;
            image.WidgetStyle.Width  = 116;
            image.Name    = "4.png";
            image.Tooltip = "A png image has 116 x 267 in size";

            // Creata a image widget.
            string imageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", "4.png");

            if (File.Exists(imageFile))
            {
                using (FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream imageStream = new MemoryStream();
                    fileStream.CopyTo(imageStream);
                    image.ImageStream = imageStream;
                }
            }

            // Create a flicking widget.
            IDynamicPanel dynamicPanel = baseView1.CreateWidget(WidgetType.DynamicPanel) as IDynamicPanel;

            dynamicPanel.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            dynamicPanel.WidgetStyle.Height = 198;
            dynamicPanel.WidgetStyle.Width  = 152;
            dynamicPanel.WidgetStyle.X      = 250;
            dynamicPanel.WidgetStyle.Y      = 250;
            dynamicPanel.WidgetStyle.Z      = 1;
            dynamicPanel.IsAutomatic        = true;

            // Set start panel page as the first created page.
            dynamicPanel.StartPanelStatePage = dynamicPanel.CreatePanelStatePage("Panel 1");
            dynamicPanel.CreatePanelStatePage("Panel 2");
            dynamicPanel.CreatePanelStatePage("Panel 3");

            int imageFileName = 1;

            foreach (IPage statePage in dynamicPanel.PanelStatePages)
            {
                statePage.Open(); // Open page to edit.

                // Get the base view of state page.
                IPageView stateBaseView = statePage.PageViews[document.AdaptiveViewSet.Base.Guid];

                IImage statePageImage = stateBaseView.CreateWidget(WidgetType.Image) as IImage;
                statePageImage.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
                statePageImage.WidgetStyle.Height = 198;
                statePageImage.WidgetStyle.Width  = 152;
                string statePageImageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", imageFileName + ".png");
                if (File.Exists(statePageImageFile))
                {
                    using (FileStream fileStream = new FileStream(statePageImageFile, FileMode.Open, FileAccess.Read))
                    {
                        MemoryStream imageStream = new MemoryStream();
                        fileStream.CopyTo(imageStream);
                        statePageImage.ImageStream = imageStream;
                    }
                }
                statePage.Close(); // Close Page to release resources.

                imageFileName++;
            }

            // Create a group
            List <Guid> widgetGuidList = new List <Guid>();

            widgetGuidList.Add(image.Guid);
            widgetGuidList.Add(dynamicPanel.Guid);
            IGroup group = page1.CreateGroup(widgetGuidList);

            // Create a serialize writer.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            // Add widgets and groups you want to copy to the writer.
            writer.AddGroup(group);

            // Serialize widgets and groups to a stream.
            Stream stream = writer.WriteToStream();

            // Paste stream back to page 1.
            IObjectContainer container = baseView1.AddObjects(stream);

            // Change the new widgets location.
            foreach (IWidget widget in container.WidgetList)
            {
                widget.WidgetStyle.X = widget.WidgetStyle.X + 50;
                widget.WidgetStyle.Y = widget.WidgetStyle.Y + 50;
            }

            page1.Close();

            // Paste stream to page 2.
            IDocumentPage page2 = document.CreatePage("Page 2");
            ITreeNode     node2 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node2.AttachedObject = page2;

            page2.Open();

            // Get the page view for base adaptive view.
            IPageView baseView2 = page2.PageViews[document.AdaptiveViewSet.Base.Guid];

            baseView2.AddObjects(stream); // Paste to page 2.

            page2.Close();

            // Save document.
            string fileName = Path.Combine(Program.WORKING_DIRECTORY, _caseName + ".pn");

            Program.Service.Save(fileName);
            Program.Service.Close();
        }
Exemplo n.º 3
0
        protected override void RunInternal()
        {
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            IMasterPage masterPage     = document.CreateMasterPage("Master 1");
            ITreeNode   masterPageNode = document.DocumentSettings.LayoutSetting.MasterPageTree.AddChild(TreeNodeType.MasterPage);

            masterPageNode.AttachedObject = masterPage;
            masterPage.Open();
            IPageView masterBaseView = masterPage.PageViews[document.AdaptiveViewSet.Base.Guid];

            IButton button = masterBaseView.CreateWidget(WidgetType.Button) as IButton;

            button.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());

            // Size
            button.WidgetStyle.Height = 30;
            button.WidgetStyle.Width  = 100;

            // Location
            button.WidgetStyle.X = 0;
            button.WidgetStyle.Y = 0;
            button.WidgetStyle.Z = 0;

            // Text things
            button.Name    = "Button 1";
            button.Text    = "Button";
            button.Tooltip = "Html button.";

            IImage image = masterBaseView.CreateWidget(WidgetType.Image) as IImage;

            image.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            image.WidgetStyle.Height = 267;
            image.WidgetStyle.Width  = 116;
            image.WidgetStyle.X      = 150;
            image.WidgetStyle.Y      = 100;
            image.WidgetStyle.Z      = 5;
            image.Name    = "4.png";
            image.Tooltip = "A png image has 116 x 267 in size";

            // It is a png image by default. Set image stream
            string imageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", "4.png");

            if (File.Exists(imageFile))
            {
                using (FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream imageStream = new MemoryStream();
                    fileStream.CopyTo(imageStream);
                    image.ImageStream = imageStream;
                }
            }

            IShape lable = masterBaseView.CreateWidget(WidgetType.Shape) as IShape;

            lable.ShapeType = ShapeType.Paragraph;
            lable.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            lable.WidgetStyle.Height = 100;
            lable.WidgetStyle.Width  = 200;
            lable.WidgetStyle.X      = 350;
            lable.WidgetStyle.Y      = 300;
            lable.WidgetStyle.Z      = 9;
            lable.Name    = "Label 1";
            lable.Tooltip = "A label.";
            lable.SetRichText("Label");
            lable.WidgetStyle.FillColor = new StyleColor(ColorFillType.Solid, -999);

            List <Guid> guidList = new List <Guid>();

            guidList.Add(image.Guid);
            guidList.Add(lable.Guid);
            masterBaseView.CreateGroup(guidList);

            IDocumentPage page     = document.CreatePage("Page 1");
            ITreeNode     pageNode = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode.AttachedObject = page;
            page.Open();
            IPageView baseView = page.PageViews[document.AdaptiveViewSet.Base.Guid];

            IMaster master = baseView.CreateMaster(masterPage.Guid);

            master.MasterStyle.X = 150;
            master.MasterStyle.Y = 50;

            // Copy master in the same page.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            writer.AddMaster(master);
            Stream stream = writer.WriteToStream();

            // Create another document
            DocumentService Service = new DocumentService();

            Service.NewDocument(DocumentType.Standard);
            IDocument document2 = Service.Document;

            IDocumentPage page2     = document2.CreatePage("Page 1");
            ITreeNode     pageNode2 = document2.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode2.AttachedObject = page2;
            page2.Open();
            IPageView baseView2 = page2.PageViews[document2.AdaptiveViewSet.Base.Guid];

            baseView2.AddObjects(stream);

            string target = Path.Combine(Program.WORKING_DIRECTORY, _caseName + "_Target.pn");

            Service.Save(target);
            Service.Close();

            string source = Path.Combine(Program.WORKING_DIRECTORY, _caseName + "_Source.pn");

            Program.Service.Save(source);
            Program.Service.Close();
        }
Exemplo n.º 4
0
        protected override void RunInternal()
        {
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            IDocumentPage page1 = document.CreatePage("Page 1");
            ITreeNode     node1 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node1.AttachedObject = page1;

            page1.Open();

            // Get the page view for base adaptive view.
            IPageView baseView1 = page1.PageViews[document.AdaptiveViewSet.Base.Guid];

            IImage image = baseView1.CreateWidget(WidgetType.Image) as IImage;

            image.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            image.WidgetStyle.Height = 267;
            image.WidgetStyle.Width  = 116;
            image.Name    = "4.png";
            image.Tooltip = "A png image has 116 x 267 in size";

            // Creata a image widget.
            string imageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", "4.png");

            if (File.Exists(imageFile))
            {
                using (FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream imageStream = new MemoryStream();
                    fileStream.CopyTo(imageStream);
                    image.ImageStream = imageStream;
                }
            }

            // Create a flicking widget.
            IDynamicPanel dynamicPanel = baseView1.CreateWidget(WidgetType.DynamicPanel) as IDynamicPanel;

            dynamicPanel.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            dynamicPanel.WidgetStyle.Height = 198;
            dynamicPanel.WidgetStyle.Width  = 152;
            dynamicPanel.WidgetStyle.X      = 250;
            dynamicPanel.WidgetStyle.Y      = 250;
            dynamicPanel.WidgetStyle.Z      = 1;
            dynamicPanel.IsAutomatic        = true;

            // Set start panel page as the first created page.
            dynamicPanel.StartPanelStatePage = dynamicPanel.CreatePanelStatePage("Panel 1");
            dynamicPanel.CreatePanelStatePage("Panel 2");
            dynamicPanel.CreatePanelStatePage("Panel 3");

            int imageFileName = 1;

            foreach (IPage statePage in dynamicPanel.PanelStatePages)
            {
                statePage.Open(); // Open page to edit.

                // Get the base view of state page.
                IPageView stateBaseView = statePage.PageViews[document.AdaptiveViewSet.Base.Guid];

                IImage statePageImage = stateBaseView.CreateWidget(WidgetType.Image) as IImage;
                statePageImage.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
                statePageImage.WidgetStyle.Height = 198;
                statePageImage.WidgetStyle.Width  = 152;
                string statePageImageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", imageFileName + ".png");
                if (File.Exists(statePageImageFile))
                {
                    using (FileStream fileStream = new FileStream(statePageImageFile, FileMode.Open, FileAccess.Read))
                    {
                        MemoryStream imageStream = new MemoryStream();
                        fileStream.CopyTo(imageStream);
                        statePageImage.ImageStream = imageStream;
                    }
                }
                statePage.Close(); // Close Page to release resources.

                imageFileName++;
            }

            // Create a group
            List <Guid> widgetGuidList = new List <Guid>();

            widgetGuidList.Add(image.Guid);
            widgetGuidList.Add(dynamicPanel.Guid);
            IGroup group = page1.CreateGroup(widgetGuidList);

            // Create a serialize writer.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            // Add widgets and groups you want to copy to the writer.
            writer.AddGroup(group);

            // Serialize widgets and groups to a stream.
            Stream stream = writer.WriteToStream();

            // DeflateStream Compress
            long         deflateCompressStart    = DateTime.Now.Ticks;
            MemoryStream deflateCompressedStream = new MemoryStream();

            using (DeflateStream deflateStream = new DeflateStream(deflateCompressedStream, CompressionMode.Compress, true))
            {
                stream.Position = 0;
                stream.CopyTo(deflateStream);
            }
            long   deflateCompressEnd  = DateTime.Now.Ticks;
            double deflateCompressRate = Math.Round((double)(stream.Length - deflateCompressedStream.Length) / (double)stream.Length * 100, 2);

            Console.WriteLine("DeflateStream compress length {0} to length {1}, compress rate: {2}%,  take ticks: {3}.",
                              stream.Length, deflateCompressedStream.Length, deflateCompressRate, deflateCompressEnd - deflateCompressStart);

            // GZipStream Compress
            long         gZipStreamCompressStart    = DateTime.Now.Ticks;
            MemoryStream gZipStreamCompressedStream = new MemoryStream();

            using (GZipStream gZipStream = new GZipStream(gZipStreamCompressedStream, CompressionMode.Compress, true))
            {
                stream.Position = 0;
                stream.CopyTo(gZipStream);
            }
            long   gZipStreamCompressEnd  = DateTime.Now.Ticks;
            double gZipStreamCompressRate = Math.Round((double)(stream.Length - gZipStreamCompressedStream.Length) / (double)stream.Length * 100, 2);

            Console.WriteLine("GZipStream compress length {0} to length {1}, compress rate: {2}%,  take ticks: {3}.",
                              stream.Length, gZipStreamCompressedStream.Length, gZipStreamCompressRate, gZipStreamCompressEnd - gZipStreamCompressStart);

            page1.Close();

            // Paste stream to page 2.
            IDocumentPage page2 = document.CreatePage("Page 2");
            ITreeNode     node2 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node2.AttachedObject = page2;
            page2.Open();

            // Get the page view for base adaptive view.
            IPageView baseView2 = page2.PageViews[document.AdaptiveViewSet.Base.Guid];

            IDocumentPage page3 = document.CreatePage("Page 3");
            ITreeNode     node3 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node3.AttachedObject = page3;
            page3.Open();

            // Get the page view for base adaptive view.
            IPageView baseView3 = page3.PageViews[document.AdaptiveViewSet.Base.Guid];

            // DeflateStream Decompress
            long deflateDecompressStart = DateTime.Now.Ticks;

            deflateCompressedStream.Position = 0;
            MemoryStream deflateDecompressedStream = new MemoryStream();

            using (DeflateStream deflateStream = new DeflateStream(deflateCompressedStream, CompressionMode.Decompress, true))
            {
                deflateStream.CopyTo(deflateDecompressedStream);
            }
            long deflateDecompressEnd = DateTime.Now.Ticks;

            Console.WriteLine("DeflateStream decompress take ticks: {0}.", deflateDecompressEnd - deflateDecompressStart);

            deflateDecompressedStream.Position = 0;
            baseView2.AddObjects(deflateDecompressedStream); // Paste to page 2.
            page2.Close();

            // GZipStream Decompress
            long gZipStreamDecompressStart = DateTime.Now.Ticks;

            gZipStreamCompressedStream.Position = 0;
            MemoryStream gZipStreamDecompressedStream = new MemoryStream();

            using (GZipStream gZipStream = new GZipStream(gZipStreamCompressedStream, CompressionMode.Decompress, true))
            {
                gZipStream.CopyTo(gZipStreamDecompressedStream);
            }
            long gZipStreamDecompressEnd = DateTime.Now.Ticks;

            Console.WriteLine("DeflateStream decompress take ticks: {0}.", gZipStreamDecompressEnd - gZipStreamDecompressStart);


            gZipStreamDecompressedStream.Position = 0;
            baseView3.AddObjects(gZipStreamDecompressedStream); // Paste to page 3.
            page3.Close();

            // Save the document to a pn file.
            string fileName = Path.Combine(Program.WORKING_DIRECTORY, _caseName + ".pn");

            Program.Service.Save(fileName);

            Program.Service.Close();
        }
Exemplo n.º 5
0
        protected override void RunInternal()
        {
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            IMasterPage masterPage     = document.CreateMasterPage("Master 1");
            ITreeNode   masterPageNode = document.DocumentSettings.LayoutSetting.MasterPageTree.AddChild(TreeNodeType.MasterPage);

            masterPageNode.AttachedObject = masterPage;
            masterPage.Open();
            IPageView masterBaseView = masterPage.PageViews[document.AdaptiveViewSet.Base.Guid];

            IButton button = masterBaseView.CreateWidget(WidgetType.Button) as IButton;

            button.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());

            // Size
            button.WidgetStyle.Height = 30;
            button.WidgetStyle.Width  = 100;

            // Location
            button.WidgetStyle.X = 0;
            button.WidgetStyle.Y = 0;
            button.WidgetStyle.Z = 0;

            // Text things
            button.Name    = "Button 1";
            button.Text    = "Button";
            button.Tooltip = "Html button.";

            IImage image = masterBaseView.CreateWidget(WidgetType.Image) as IImage;

            image.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            image.WidgetStyle.Height = 267;
            image.WidgetStyle.Width  = 116;
            image.WidgetStyle.X      = 150;
            image.WidgetStyle.Y      = 100;
            image.WidgetStyle.Z      = 5;
            image.Name    = "4.png";
            image.Tooltip = "A png image has 116 x 267 in size";

            // It is a png image by default. Set image stream
            string imageFile = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "HangGame", "4.png");

            if (File.Exists(imageFile))
            {
                using (FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read))
                {
                    MemoryStream imageStream = new MemoryStream();
                    fileStream.CopyTo(imageStream);
                    image.ImageStream = imageStream;
                }
            }

            IShape lable = masterBaseView.CreateWidget(WidgetType.Shape) as IShape;

            lable.ShapeType = ShapeType.Paragraph;
            lable.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            lable.WidgetStyle.Height = 100;
            lable.WidgetStyle.Width  = 200;
            lable.WidgetStyle.X      = 150;
            lable.WidgetStyle.Y      = 300;
            lable.WidgetStyle.Z      = 9;
            lable.Name    = "Label 1";
            lable.Tooltip = "A label.";
            lable.SetRichText("Label");
            lable.WidgetStyle.LineColor = new StyleColor(ColorFillType.Solid, -16777216);
            lable.WidgetStyle.LineWidth = 0;                                             // No border
            lable.WidgetStyle.FillColor = new StyleColor(ColorFillType.Solid, 16777215); // Transparent
            lable.WidgetStyle.HorzAlign = Alignment.Left;
            lable.WidgetStyle.VertAlign = Alignment.Top;

            IDocumentPage page     = document.CreatePage("Page 1");
            ITreeNode     pageNode = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode.AttachedObject = page;
            page.Open();
            IPageView baseView = page.PageViews[document.AdaptiveViewSet.Base.Guid];

            IMaster master = baseView.CreateMaster(masterPage.Guid);

            // Copy master in the same page.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            writer.AddMaster(master);
            baseView.AddObjects(writer.WriteToStream());

            // Copy master to different page.
            IDocumentPage page2     = document.CreatePage("Page 2");
            ITreeNode     pageNode2 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            pageNode2.AttachedObject = page2;
            page2.Open();
            IPageView baseView2 = page2.PageViews[document.AdaptiveViewSet.Base.Guid];

            baseView2.AddObjects(writer.WriteToStream());

            // Save the document to a pn file.
            string fileName = Path.Combine(Program.WORKING_DIRECTORY, _caseName + ".pn");

            Program.Service.Save(fileName);

            // Close this document when you don't work on it anymore.
            Program.Service.Close();
        }