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); }
public void SerializeObject(ISerializeWriter writer) { writer.AddWidget(_widget); }
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); }
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"); 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); IShape triangle = baseView.CreateWidget(WidgetType.Shape) as IShape; triangle.ShapeType = ShapeType.Triangle; triangle.Annotation.SetTextValue("CreatedTime", DateTime.Now.ToString()); triangle.WidgetStyle.Height = 100; triangle.WidgetStyle.Width = 100; triangle.WidgetStyle.X = 650; triangle.WidgetStyle.Y = 300; triangle.WidgetStyle.Z = 11; triangle.Name = "Triangle_Show_Hide"; triangle.Tooltip = "A Triangle to triger Show or Hide."; triangle.SetRichText("Triangle_Show_Hide"); IInteractionEvent iEvent = triangle.Events[EventType.OnClick]; IInteractionCase iCase = iEvent.CreateCase("clickCase"); IInteractionShowHideAction action = iCase.CreateAction(ActionType.ShowHideAction) as IInteractionShowHideAction; action.AddTargetObject(master.Guid); action.SetAllVisibilityType(VisibilityType.Toggle); action.SetAllAnimateType(ShowHideAnimateType.SlideRight); action.SetAllAnimateTime(500); ISerializeWriter writer = document.CreateSerializeWriter(document.AdaptiveViewSet.Base.Guid); writer.AddWidget(triangle); 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(); }