public void SetPageOrientation(TargetPages targetpages, Models.PageOrientation orientation)
        {
            if (orientation != VisioScripting.Models.PageOrientation.Landscape && orientation != VisioScripting.Models.PageOrientation.Portrait)
            {
                throw new System.ArgumentOutOfRangeException(nameof(orientation), "must be either Portrait or Landscape");
            }

            targetpages = targetpages.Resolve(this._client);
            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageOrientation)))
            {
                foreach (var page in targetpages.Pages)
                {
                    var old_orientation = PageCommands._GetPageOrientation(page);

                    if (old_orientation == orientation)
                    {
                        // don't need to do anything
                        return;
                    }

                    var page_tp  = new VisioScripting.TargetPages(page);
                    var old_size = this.GetPageSize(page_tp);

                    double new_height = old_size.Width;
                    double new_width  = old_size.Height;

                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_height);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PrintPageOrientation, (int)orientation);

                    writer.Commit(page.PageSheet, VASS.CellValueType.Formula);
                }
            }
        }
        public void DeletePages(TargetPages targetpages, bool renumber)
        {
            targetpages = targetpages.Resolve(this._client);

            foreach (var page in targetpages.Pages)
            {
                page.Delete(renumber ? (short)1 : (short)0);
            }
        }
        public void LayoutPage(TargetPages targetpages, VisioAutomation.Models.LayoutStyles.LayoutStyleBase layout)
        {
            targetpages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageSize)))
            {
                foreach (var page in targetpages.Pages)
                {
                    layout.Apply(page);
                }
            }
        }
        public void ResizeToFitContents(TargetPages targetpages, VisioAutomation.Geometry.Size bordersize)
        {
            targetpages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(ResizeToFitContents)))
            {
                foreach (var page in targetpages.Pages)
                {
                    page.ResizeToFitContents(bordersize);
                }
            }
        }
        public void SetBackground(TargetPages targetpages, string background_page_name)
        {
            if (background_page_name == null)
            {
                throw new System.ArgumentNullException(nameof(background_page_name));
            }

            targetpages = targetpages.Resolve(this._client);

            if (targetpages.Pages.Count < 1)
            {
                return;
            }

            var page0     = targetpages.Pages[0];
            var doc       = page0.Document;
            var doc_pages = doc.Pages;

            var names = new HashSet <string>(doc_pages.GetNamesU());

            if (!names.Contains(background_page_name))
            {
                string msg = string.Format("Could not find page with name \"{0}\"", background_page_name);
                throw new VisioAutomation.Exceptions.VisioOperationException(msg);
            }

            var bgpage = doc_pages.ItemU[background_page_name];

            // Set the background page
            // Check that the intended background is indeed a background page
            if (bgpage.Background == 0)
            {
                string msg = string.Format("Page \"{0}\" is not a background page", bgpage.Name);
                throw new VisioAutomation.Exceptions.VisioOperationException(msg);
            }

            // don't allow the page to be set as a background to itself

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetBackground)))
            {
                foreach (var page in targetpages.Pages)
                {
                    if (page == bgpage)
                    {
                        string msg = "Cannot set page as its own background page";
                        throw new VisioAutomation.Exceptions.VisioOperationException(msg);
                    }

                    page.BackPage = bgpage;
                }
            }
        }
        public void SetPageFormatCells(TargetPages targetpages, VisioAutomation.Pages.PageFormatCells cells)
        {
            targetpages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageFormatCells)))
            {
                foreach (var page in targetpages.Pages)
                {
                    var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValues(cells);
                    writer.BlastGuards = true;
                    writer.Commit(page, VASS.CellValueType.Formula);
                }
            }
        }
        public void SetPageSize(TargetPages targetpages, VisioAutomation.Geometry.Size new_size)
        {
            targetpages = targetpages.Resolve(this._client);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetPageSize)))
            {
                foreach (var page in targetpages.Pages)
                {
                    var page_sheet = page.PageSheet;
                    var writer     = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, new_size.Width);
                    writer.SetValue(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, new_size.Height);
                    writer.Commit(page_sheet, VASS.CellValueType.Formula);
                }
            }
        }
        public VisioAutomation.Geometry.Size GetPageSize(TargetPages targetpages)
        {
            targetpages = targetpages.Resolve(this._client);

            if (targetpages.Pages.Count < 1)
            {
                throw new System.ArgumentException("No pages found");
            }

            var query      = new VisioAutomation.ShapeSheet.Query.CellQuery();
            var col_height = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageHeight));
            var col_width  = query.Columns.Add(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, nameof(VisioAutomation.ShapeSheet.SrcConstants.PageWidth));

            var    cellqueryresult = query.GetResults <double>(targetpages.Pages[0].PageSheet);
            var    row             = cellqueryresult[0];
            double height          = row[col_height];
            double width           = row[col_width];
            var    s = new VisioAutomation.Geometry.Size(width, height);

            return(s);
        }
 public Models.PageOrientation GetPageOrientation(TargetPages targetpages)
 {
     targetpages = targetpages.Resolve(this._client);
     return(PageCommands._GetPageOrientation(targetpages.Pages[0]));
 }