Exemplo n.º 1
0
        public void AddToLibrary(ICustomLibrary customLibrary)
        {
            try
            {
                string           objectName = CommonDefine.Untitled;
                ISerializeWriter writer     = GetSerializeWriter(ref objectName);
                if (writer == null)
                {
                    return;
                }

                IDocumentService DocService = ServiceLocator.Current.GetInstance <IDocumentService>();
                ILibrary         library    = DocService.LibraryManager.GetLibrary(customLibrary.LibraryGID, customLibrary.FileName);
                if (library != null)
                {
                    ICustomObject newObject = library.AddCustomObject(writer, objectName, CreateIconImage(false), null);
                    if (newObject != null)
                    {
                        customLibrary.AddCustomObject(newObject.Guid);
                    }
                }
                else
                {
                    // If we cannot get the specific library, there is something wrong about this custom library.
                    // Refresh this custom library
                    customLibrary.Refresh();
                }
            }
            catch (Exception ex)
            {
                NLogger.Warn("Add to library failed. ex:{0}", ex.ToString());

                MessageBox.Show(GlobalData.FindResource("Error_Create_Library") + ex.Message);
            }
        }
Exemplo n.º 2
0
 public virtual void Serialize(ISerializeWriter writer)
 {
     foreach (var child in Children)
     {
         Serialize(child, writer);
     }
 }
Exemplo n.º 3
0
        public IMasterPage CreateMasterPage(ISerializeWriter writer, string pageName, Stream thumbnail)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            CheckOpen();

            IMasterPage newMasterPage = CreateMasterPage(pageName);

            newMasterPage.Open();

            PageView         baseView  = newMasterPage.PageViews[AdaptiveViewSet.Base.Guid] as PageView;
            IObjectContainer container = baseView.AddObjects(writer.WriteToStream());

            // Adjust widgets position from coordinate (0,0);
            baseView.PageViewStyle.X = 0;
            baseView.PageViewStyle.Y = 0;

            if (thumbnail != null)
            {
                newMasterPage.Thumbnail = thumbnail;
            }

            newMasterPage.Close();

            return(newMasterPage);
        }
Exemplo n.º 4
0
        public void ExportToLibrary()
        {
            try
            {
                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Filter   = CommonDefine.LibraryFilter;
                saveFile.FileName = CommonDefine.Untitled;
                if (saveFile.ShowDialog() == true)
                {
                    string           objectName = CommonDefine.Untitled;
                    ISerializeWriter writer     = GetSerializeWriter(ref objectName);
                    if (writer == null)
                    {
                        return;
                    }

                    //Create a new Library. Thumbnail is empty now, and waiting for a improvement
                    IDocumentService DocService = ServiceLocator.Current.GetInstance <IDocumentService>();
                    ILibrary         newLibrary =
                        DocService.LibraryManager.CreateLibrary(writer, objectName, CreateIconImage(false), null);
                    if (newLibrary != null)
                    {
                        newLibrary.SaveCopyTo(saveFile.FileName);
                        DocService.LibraryManager.DeleteLibrary(newLibrary.Guid);
                    }
                }
            }
            catch (Exception ex)
            {
                NLogger.Warn("Export to Library failed. ex:{0}", ex.ToString());

                MessageBox.Show(GlobalData.FindResource("Error_Create_Library") + ex.Message);
            }
        }
Exemplo n.º 5
0
        public ILibrary CreateLibrary(ISerializeWriter writer, string objectName, Stream icon, Stream thumbnail)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            Document newLibrary = new Document(DocumentType.Library);

            CreateCustomObject(newLibrary, writer, objectName, icon, thumbnail);

            lock (this)
            {
                if (_createdLibraries.Count >= MAX_CACHE_COUNT)
                {
                    // If list is over the max limitaion, remove the LRU library.
                    Guid LRUGuid = _createdLibraries.Aggregate((l, r) => l.Value.LastAccessTime < r.Value.LastAccessTime ? l : r).Key;
                    DeleteLibrary(LRUGuid);
                }

                // Add to created libraries collection.
                _createdLibraries.Add(newLibrary.Guid, newLibrary);
            }

            return(newLibrary);
        }
Exemplo n.º 6
0
 public virtual void Serialize(ISerializeWriter writer)
 {
     writer.WriteAttribute("Width", Width);
     writer.WriteAttribute("Height", Height);
     writer.Write(Cache, "Cache", true);
     writer.Write(dock, dock.Name, true);
 }
Exemplo n.º 7
0
        private ISerializeWriter GetSerializeWriter(ref string name)
        {
            if (_selectionService.WidgetNumber <= 0)
            {
                return(null);
            }
            ISerializeWriter serializeWriter = _document.CreateSerializeWriter(CurAdaptiveViewGID);

            foreach (WidgetViewModBase wdgItem in _selectionService.GetSelectedWidgets())
            {
                //use widget's name if one widget, else "untitled"
                if (_selectionService.WidgetNumber == 1 && !string.IsNullOrEmpty(wdgItem.Name))
                {
                    name = wdgItem.Name;
                }

                if (wdgItem is GroupViewModel)
                {
                    IGroup group = (wdgItem as GroupViewModel).ExternalGroup;
                    if (group != null)
                    {
                        serializeWriter.AddGroup(group);
                    }
                }
                else if (wdgItem.WidgetModel != null)
                {
                    if (wdgItem.WidgetModel != null)
                    {
                        wdgItem.WidgetModel.SerializeObject(serializeWriter);
                    }
                }
            }
            return(serializeWriter);
        }
Exemplo n.º 8
0
        public ILibrary NewLibrary(ISerializeWriter writer, string objectName, Stream icon, Stream thumbnail)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            Document newLibrary = new Document(DocumentType.Library);

            CreateCustomObject(newLibrary, writer, objectName, icon, thumbnail);
            return(newLibrary);
        }
Exemplo n.º 9
0
        public ICustomObject AddCustomObject(ISerializeWriter writer, string objectName, Stream icon, Stream thumbnail)
        {
            CheckOpen();

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (_documentData.DocumentType == DocumentType.Library)
            {
                return(LibraryManager.CreateCustomObject(this, writer, objectName, icon, thumbnail));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        public override void Serialize(ISerializeWriter writer)
        {
            if (FileSerialize)
            {
                if (DocumentType != null)
                {
                    var fileName = GetFileName();
                    writer.WriteAttribute("FileName", fileName);
                    writer.WriteAttribute("DocumentId", Document?.Id);

                    XmlSerialize(fileName);
                }
            }
            else
            {
                base.Serialize(writer);
            }
        }
Exemplo n.º 11
0
        internal void CopyWidget(WidgetViewModBase wdgItem, bool bIsCut)
        {
            //implement copy operation
            ISerializeWriter serializeWriter = _document.CreateSerializeWriter(_curAdaptiveViewGID);

            wdgItem.WidgetModel.SerializeObject(serializeWriter);

            Stream stream = serializeWriter.WriteToStream();

            if (stream == null)
            {
                return;
            }

            //Clipboard operation
            try
            {
                var data = new DataObject();
                _copyTime = 0;
                _copyGID  = Guid.NewGuid();
                data.SetData(@"ProtoNowCopyID", _copyGID);
                data.SetData(@"ProtoNowAdaptiveID", _curAdaptiveViewGID);
                data.SetData(@"ProtoNowWidgets", stream);

                //Copy to Clipboard
                Clipboard.Clear();
                Clipboard.SetDataObject(data);
                //Clipboard.SetDataObject(data, true);

                //Reset Copy ID
                if (bIsCut == true)
                {
                    _copyGID = Guid.Empty;
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return;
            }
        }
Exemplo n.º 12
0
        public void CreateLibrary()
        {
            try
            {
                RenameWindow win = new RenameWindow();
                win.NewName = CommonDefine.Untitled;
                win.Owner   = Application.Current.MainWindow;
                win.ShowDialog();

                if (win.Result.HasValue && win.Result.Value)
                {
                    string libraryName = win.NewName;

                    string           objectName = CommonDefine.Untitled;
                    ISerializeWriter writer     = GetSerializeWriter(ref objectName);
                    if (writer == null)
                    {
                        return;
                    }

                    //Create a new Library. Thumbnail is empty now, and waiting for a improvement
                    IDocumentService DocService = ServiceLocator.Current.GetInstance <IDocumentService>();
                    ILibrary         newLibrary =
                        DocService.LibraryManager.CreateLibrary(writer, objectName, CreateIconImage(false), null);
                    if (newLibrary != null)
                    {
                        ICustomLibraryService customLibraryService = ServiceLocator.Current.GetInstance <ICustomLibraryService>();
                        customLibraryService.GetMyLibrary().CreateCustomLibrary(newLibrary.Guid, libraryName);
                    }
                }
            }
            catch (Exception ex)
            {
                NLogger.Warn("Add Library failed. ex:{0}", ex.ToString());

                MessageBox.Show(GlobalData.FindResource("Error_Create_Library") + ex.Message);
            }
        }
Exemplo n.º 13
0
        internal static CustomObjectPage CreateCustomObject(Document document, ISerializeWriter writer,
                                                            string objectName, Stream icon, Stream thumbnail)
        {
            CustomObjectPage objectPage = document.CreatePage(objectName) as CustomObjectPage;

            // Create a new node in the page tree.
            ITreeNode node = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node.AttachedObject = objectPage;

            objectPage.Open();

            // Add to base view.
            PageView         baseView  = objectPage.PageViews[document.AdaptiveViewSet.Base.Guid] as PageView;
            IObjectContainer container = baseView.AddObjects(writer.WriteToStream());

            // Adjust widgets position from coordinate (0,0);
            baseView.PageViewStyle.X = 0;
            baseView.PageViewStyle.Y = 0;

            if (icon != null)
            {
                objectPage.Icon = icon;
            }

            if (thumbnail != null)
            {
                objectPage.Thumbnail = thumbnail;
            }

            // Page must be closed after setting icon and thumbnail, so that they can be saved into the file.
            // Document.save() only call save() on opened pages.
            objectPage.Close();

            document.UpdateLastAccessTime();

            return(objectPage);
        }
Exemplo n.º 14
0
 public virtual void Serialize(Widget widget, ISerializeWriter writer)
 {
     if (widget == null)
     {
         return;
     }
     if (widget is ISerializableElement && !string.IsNullOrEmpty(widget.Name))
     {
         writer.Write(widget, widget.Name, true);
     }
     else if (widget is Box)
     {
         foreach (var swidget in ((Box)widget).Children)
         {
             Serialize(swidget, writer);
         }
     }
     else if (widget is Paned)
     {
         Serialize(((Paned)widget).Panel1.Content, writer);
         Serialize(((Paned)widget).Panel2.Content, writer);
     }
 }
Exemplo n.º 15
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.º 16
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.º 17
0
 public void Serialize(ISerializeWriter writer)
 {
     writer.Write(items);
 }
Exemplo n.º 18
0
        protected override void RunInternal()
        {
            // Create a new document.
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            // Create a new page 1.
            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];

            // Create a image.
            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";

            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 hamburger menu.
            IHamburgerMenu hamburgerMenu = baseView1.CreateWidget(WidgetType.HamburgerMenu) as IHamburgerMenu;

            hamburgerMenu.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            hamburgerMenu.WidgetStyle.Height = 280;
            hamburgerMenu.WidgetStyle.Width  = 150;
            hamburgerMenu.WidgetStyle.X      = 200;
            hamburgerMenu.WidgetStyle.Y      = 200;
            hamburgerMenu.WidgetStyle.Z      = 1;
            hamburgerMenu.Name    = "HamburgerMenu 1";
            hamburgerMenu.Tooltip = "A hamburger menu.";

            // Menu botton
            hamburgerMenu.MenuButton.WidgetStyle.Height = 50;
            hamburgerMenu.MenuButton.WidgetStyle.Width  = 50;
            hamburgerMenu.MenuButton.WidgetStyle.X      = 200;
            hamburgerMenu.MenuButton.WidgetStyle.Y      = 200;
            hamburgerMenu.MenuButton.WidgetStyle.Z      = 0;

            // Menu page,  add a shape
            IPage menuPage = hamburgerMenu.MenuPage;

            menuPage.Open(); // Open page to edit.

            // Get the base view of menu page.
            IPageView menuBaseView = menuPage.PageViews[document.AdaptiveViewSet.Base.Guid];

            IShape diamond = menuBaseView.CreateWidget(WidgetType.Shape) as IShape;

            diamond.ShapeType = ShapeType.Diamond;
            diamond.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString());
            diamond.WidgetStyle.Height = 100;
            diamond.WidgetStyle.Width  = 100;
            diamond.Name    = "Diamond 1";
            diamond.Tooltip = "A Diamond.";
            diamond.SetRichText("Diamond");
            menuPage.Close(); // Close Page to release resources.

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

            // Add the new page 1 to the writer.
            writer.AddPage(page1);

            // Serialize page 1 to a stream.
            Stream stream = writer.WriteToStream();

            // The data of page is already in stream, so close the page will not change anything in stream.
            page1.Close();

            // Add pages in stream.
            IObjectContainer container = document.AddPages(stream);

            stream.Close();

            foreach (IStandardPage page in container.StandardPageList)
            {
                ITreeNode node22 = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);
                node22.AttachedObject = page;
            }

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

            Program.Service.Save(fileName);

            // Close document.
            Program.Service.Close();
        }
        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];

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

            diamond.ShapeType          = ShapeType.Diamond;
            diamond.WidgetStyle.Height = 200;
            diamond.WidgetStyle.Width  = 200;
            diamond.WidgetStyle.X      = 0;
            diamond.WidgetStyle.Y      = 0;
            diamond.WidgetStyle.Z      = 0;
            diamond.Name = "Z_0_In_MasterPage";
            diamond.SetRichText("Z_0_In_MasterPage");

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

            ellipse.ShapeType          = ShapeType.Ellipse;
            ellipse.WidgetStyle.Height = 200;
            ellipse.WidgetStyle.Width  = 200;
            ellipse.WidgetStyle.X      = 50;
            ellipse.WidgetStyle.Y      = 50;
            ellipse.WidgetStyle.Z      = 1;
            ellipse.Name = "Z_1_In_MasterPage";
            ellipse.SetRichText("Z_1_In_MasterPage");

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

            rectangle.ShapeType          = ShapeType.Rectangle;
            rectangle.WidgetStyle.Height = 200;
            rectangle.WidgetStyle.Width  = 200;
            rectangle.WidgetStyle.X      = 100;
            rectangle.WidgetStyle.Y      = 100;
            rectangle.WidgetStyle.Z      = 2;
            rectangle.Name = "Z_2_In_MasterPage";
            rectangle.SetRichText("Z_2_In_MasterPage");

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

            guidList.Add(ellipse.Guid);
            guidList.Add(rectangle.Guid);
            IGroup groupInMaster = masterBaseView.CreateGroup(guidList);

            groupInMaster.Name = "Group_In_MasterPage";

            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];

            IShape round = baseView.CreateWidget(WidgetType.Shape) as IShape;

            round.ShapeType          = ShapeType.RoundedRectangle;
            round.WidgetStyle.Height = 200;
            round.WidgetStyle.Width  = 200;
            round.WidgetStyle.X      = 0;
            round.WidgetStyle.Y      = 0;
            round.WidgetStyle.Z      = 0;
            round.Name = "Z_0_In_Page";
            round.SetRichText("Z_0_In_Page");

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

            master1.MasterStyle.X = 250;
            master1.MasterStyle.Y = 250;
            master1.MasterStyle.Z = 1;

            IShape triangle = baseView.CreateWidget(WidgetType.Shape) as IShape;

            triangle.ShapeType          = ShapeType.Triangle;
            triangle.WidgetStyle.Height = 200;
            triangle.WidgetStyle.Width  = 200;
            triangle.WidgetStyle.X      = 100;
            triangle.WidgetStyle.Y      = 100;
            triangle.WidgetStyle.Z      = 2;
            triangle.Name = "Z_2_In_Page";
            triangle.SetRichText("Z_2_In_Page");
            triangle.WidgetStyle.FillColor = new StyleColor(ColorFillType.Solid, -22550);

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

            master2.MasterStyle.X = 500;
            master2.MasterStyle.Y = 500;
            master2.MasterStyle.Z = 3;

            IShape triangle1 = baseView.CreateWidget(WidgetType.Shape) as IShape;

            triangle1.ShapeType          = ShapeType.Triangle;
            triangle1.WidgetStyle.Height = 200;
            triangle1.WidgetStyle.Width  = 200;
            triangle1.WidgetStyle.X      = 100;
            triangle1.WidgetStyle.Y      = 100;
            triangle1.WidgetStyle.Z      = 4;
            triangle1.Name = "Z_4_In_Page";
            triangle1.SetRichText("Z_4_In_Page");
            triangle1.WidgetStyle.FillColor = new StyleColor(ColorFillType.Solid, -22550);

            ISerializeWriter writer = document.CreateSerializeWriter(Guid.Empty);

            writer.AddPage(page);
            Stream stream = writer.WriteToStream();

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

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

            IObjectContainer container = document2.AddPages(stream);

            stream.Close();

            foreach (IStandardPage newPage in container.StandardPageList)
            {
                ITreeNode node22 = document2.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);
                node22.AttachedObject = newPage;
            }

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

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

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

            Program.Service.Save(source);
            Program.Service.Close();
        }
Exemplo n.º 20
0
 public void Serialize(ISerializeWriter writer)
 {
     writer.Write(ToSerialize);
 }
Exemplo n.º 21
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.º 22
0
 public void SerializeObject(ISerializeWriter writer)
 {
     writer.AddMaster(_master);
 }
Exemplo n.º 23
0
 public void SerializeObject(ISerializeWriter writer)
 {
     writer.AddWidget(_widget);
 }
Exemplo n.º 24
0
        protected override void RunInternal()
        {
            // Load a library file
            string   libraryFileName = Path.Combine(Program.WORKING_DIRECTORY, "Test_CreateLibraryDocument.libpn");
            ILibrary libraryLoad     = Program.Service.LibraryManager.LoadLibrary(libraryFileName);

            // Cache the library guid.
            Guid libraryGuid = libraryLoad.Guid;

            // Create a new document.
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            // Create a page.
            IDocumentPage page = document.CreatePage("Home");

            // Create the page node in page tree.
            ITreeNode node = document.DocumentSettings.LayoutSetting.PageTree.AddChild(TreeNodeType.Page);

            node.AttachedObject = page;

            // Must open the page before you read and modify it.
            page.Open();

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

            // Create widgets on the base view in this page.
            IButton button = baseView.CreateWidget(WidgetType.Button) as IButton;

            button.WidgetStyle.Height = 30;
            button.WidgetStyle.Width  = 100;
            button.Name    = "Button 1";
            button.Text    = "Button";
            button.Tooltip = "Html button.";

            // Get the loaded library with the cached guid.
            ILibrary libraryGet = Program.Service.LibraryManager.GetLibrary(libraryGuid);

            // Put the button in a writer.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            writer.AddWidget(button);

            // Create a new custom object which contains the button and add to the loaded library.
            libraryGet.AddCustomObject(writer, "New_Custom_Object_Which_Contains_Button", null, null);

            // Save changes to file
            libraryGet.Save(libraryGet.Name);

            page.Close();

            // 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();

            // Delete loaded libraries
            Program.Service.LibraryManager.DeleteLibrary(libraryGuid);
        }
Exemplo n.º 25
0
        protected override void RunInternal()
        {
            // Create a document.
            Program.Service.NewDocument(DocumentType.Standard);
            IDocument document = Program.Service.Document;

            // Create a new page.
            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];

            // Create a image widget in the new page.
            IImage image = baseView1.CreateWidget(WidgetType.Image) as IImage;

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

            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 serialize writer first.
            ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid);

            // Add selected widgets in the writer.
            writer.AddWidget(image);

            MemoryStream iconStream = new MemoryStream();
            string       iconFile   = Path.Combine(Program.WORKING_IMAGES_DIRECTORY, "icon", "3.png");

            if (File.Exists(iconFile))
            {
                using (FileStream fileStream = new FileStream(iconFile, FileMode.Open, FileAccess.Read))
                {
                    fileStream.CopyTo(iconStream);
                }
            }

            // Create a custom object which name is "CustomObjectName", the custom object is contains the widgets
            // you added in ISerializeWriter.
            // The new custom object is added to a new library document and the new library is managed by DocumentService.
            ILibrary library = Program.Service.LibraryManager.CreateLibrary(writer, "CustomObjectName", iconStream, null);

            iconStream.Dispose();

            // Save the new library to a library file .libpn, the file extension is .libpn!!!!!!!
            string libraryFileName = Path.Combine(Program.WORKING_DIRECTORY, _caseName + ".libpn");

            library.Save(libraryFileName);

            // Close the page.
            page1.Close();

            // Close the document.
            Program.Service.Close();

            // Delete the new library from DocumentService.
            Program.Service.LibraryManager.DeleteLibrary(library.Guid);
        }
Exemplo n.º 26
0
        private void ConvertToMasterCommandHandler(object parameter)
        {
            try
            {
                MasterNameWindow win = new MasterNameWindow();
                win.NewName = MasterListViewModel.GetNextDataName();
                win.Owner   = Application.Current.MainWindow;
                win.ShowDialog();

                if (win.Result.HasValue && win.Result.Value)
                {
                    string masterName = win.NewName;

                    string           objectName = string.Empty;
                    ISerializeWriter writer     = GetSerializeWriter(ref objectName);
                    if (writer == null)
                    {
                        return;
                    }

                    var page = _document.CreateMasterPage(writer, masterName, CreateIconImage(false));
                    if (page != null)
                    {
                        //Add converted master to master list
                        _ListEventAggregator.GetEvent <AddConvertedMasterEvent>().Publish(page);
                        //keep widgets status when library editing mode
                        if (_document.DocumentType == DocumentType.Library)
                        {
                            return;
                        }

                        double minLeft = double.MaxValue;
                        double minTop  = double.MaxValue;
                        foreach (WidgetViewModBase wdgItem in _selectionService.GetSelectedWidgets())
                        {
                            if (minLeft > wdgItem.Left)
                            {
                                minLeft = wdgItem.Left;
                            }
                            if (minTop > wdgItem.Top)
                            {
                                minTop = wdgItem.Top;
                            }
                        }

                        //remove selected widgets
                        UndoCompositeCommand cmds = new UndoCompositeCommand();
                        RemoveSelectedWidget(cmds);

                        //add converted master to current page.
                        AddMasterItem(page.Guid, minLeft, minTop, cmds);

                        _undoManager.Push(cmds);

                        this.EditorCanvas.Focus();
                    }
                }
                else
                {
                    MasterListViewModel.RollBackDataName();
                }
            }
            catch (Exception ex)
            {
                NLogger.Debug("Convert Master failed: " + ex.Message);
            }
        }
Exemplo n.º 27
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();
        }