示例#1
0
        public void Dom_VerifyThatUnknownMastersAreDetected()
        {
            var doc           = this.GetNewDoc();
            var page_node     = new VADOM.Page();
            var master_node_0 = page_node.Shapes.Drop("XXX", this.node_stencil_name, 3, 3);

            IVisio.Page page   = null;
            bool        caught = false;

            try
            {
                page = page_node.Render(doc);
            }
            catch (System.ArgumentException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page != null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
示例#2
0
        public void Dom_VerifyThatUnknownStencilsAreDetected()
        {
            string non_existent_stencil = "foobar.vss";

            var doc           = this.GetNewDoc();
            var page_node     = new VADOM.Page();
            var master_node_0 = page_node.Shapes.Drop(this.node_master_name, non_existent_stencil, 3, 3);

            IVisio.Page page   = null;
            bool        caught = false;

            try
            {
                page = page_node.Render(doc);
            }
            catch (AutomationException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page != null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
示例#3
0
        private void ProcessCommand_Page_Delete(XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                // TODO(crhodes):
                // Need to pass in doc so this can work for any document

                Visio.Application app = Globals.ThisAddIn.Application;

                Visio.Document doc = app.ActiveDocument;

                string pageName = pageElement.Attribute("Name").Value;

                Visio.Page deletePage = doc.Pages[pageName];

                if (deletePage != null)
                {
                    deletePage.Delete(0);
                }
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
示例#4
0
        public static Visio.Page CreateTOCPage()
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodBase.GetCurrentMethod().Name));

            Visio.Page page = null;

            int undoScope = Globals.ThisAddIn.Application.BeginUndoScope("GenerateTOCPage");

            try
            {
                page = Globals.ThisAddIn.Application.ActiveDocument.Pages["Table of Contents"];
                // We found a page, delete it.  Not much luck iterating across shapes and clearing page - See ClearPage()

                page.Delete(0);
                //ClearPage(page);
                // Need to delete all the stuff.
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.LOG_CATEGORY);
            }

            page = Globals.ThisAddIn.Application.ActiveDocument.Pages.Add();

            page.NameU      = "Table of Contents";
            page.Background = 0;
            page.Index      = 1;

            Globals.ThisAddIn.Application.EndUndoScope(undoScope, true);

            return(page);
        }
示例#5
0
        private void ProcessCommand_Page_Delete(Visio.Document doc, XElement pageElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            try
            {
                string pageName = pageElement.Attribute("Name") != null?pageElement.Attribute("Name").Value : "";

                if (pageName != "")
                {
                    Visio.Page deletePage = doc.Pages[pageName];

                    if (deletePage != null)
                    {
                        deletePage.Delete(0);
                    }
                    else
                    {
                        VisioHlp.DisplayInWatchWindow(string.Format("Page ({0}) not found", pageName));
                    }
                }
                else
                {
                    VisioHlp.DisplayInWatchWindow("Missing \"Name\" attribute");
                }
            }
            catch (Exception ex)
            {
                VisioHlp.DisplayInWatchWindow(ex.ToString());
            }
        }
示例#6
0
        public void Container_PerformLayoutBeforeRender()
        {
            // Purpose: Verify that if PerformLayout is NOT called before Render()
            // is called then an exception will be thrown

            bool caught = false;
            var  layout = new CONMODEL.ContainerLayout();
            var  doc    = this.GetNewDoc();

            try
            {
                var c1 = layout.AddContainer("A");
                var i1 = c1.Add("A1");
                // layout.PerformLayout();
                IVisio.Page page = layout.Render(doc);
                page.Delete(0);
            }
            catch (VA.AutomationException)
            {
                caught = true;
            }

            doc.Close(true);

            if (caught == false)
            {
                Assert.Fail("Did not catch expected exception");
            }
        }
示例#7
0
        public void DOM_VerifyThatUnknownStencilsAreDetected()
        {
            var doc           = this.GetNewDoc();
            var page_node     = new VA.DOM.Page();
            var master_node_0 = page_node.Shapes.Drop("Rectangle", "basic_uXXX.vss", 3, 3);

            IVisio.Page page   = null;
            bool        caught = false;

            try
            {
                page = page_node.Render(doc);
            }
            catch (VA.AutomationException)
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Expected an AutomationException");
            }

            if (page != null)
            {
                page.Delete(0);
            }
            doc.Close(true);
        }
        private static Visio.Page CreateTOCPage()
        {
            Visio.Page page = null;

            int undoScope = Globals.ThisAddIn.Application.BeginUndoScope("GenerateTOCPage");

            try
            {
                page = Globals.ThisAddIn.Application.ActiveDocument.Pages["Table of Contents"];
                // We found a page, delete it.  Not much luck iterating across shapes and clearing page - See ClearPage()

                page.Delete(0);
                //ClearPage(page);
                // Need to delete all the stuff.
            }
            catch (Exception ex)
            {
            }

            page = Globals.ThisAddIn.Application.ActiveDocument.Pages.Add();

            page.Name       = "Table of Contents";
            page.Background = 0;
            page.Index      = 1;

            Globals.ThisAddIn.Application.EndUndoScope(undoScope, true);

            return(page);
        }
示例#9
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid number of arguments.");
                Usage();
                return(3);
            }

            FileInfo sourceFileInfo = new FileInfo(args[0]);

            if (!sourceFileInfo.Exists)
            {
                Console.Error.WriteLine("Source file \"{0}\"doesn't exist.", sourceFileInfo.FullName);
                Usage();
                return(3);
            }

            string[] validExtensions = new string[] { ".vst", ".vsd" };
            if (!validExtensions.Contains(sourceFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Source file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }

            string referencePageNames = args[1];

            FileInfo targetFileInfo = new FileInfo(args[2]);

            if (targetFileInfo.Exists && targetFileInfo.IsReadOnly)
            {
                Console.Error.WriteLine("Target file exists and is readonly.");
                Usage();
                return(3);
            }
            if (!targetFileInfo.Directory.Exists)
            {
                Console.Error.WriteLine("Target file directory doesn't exist.");
                Usage();
                return(3);
            }
            if (!validExtensions.Contains(targetFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Target file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }
            if (String.Compare(sourceFileInfo.FullName, targetFileInfo.FullName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                Console.Error.WriteLine("Source and targer file are identical.");
                Usage();
                return(3);
            }

            string targetFile = targetFileInfo.FullName;

            File.Copy(sourceFileInfo.FullName, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);
            //Visio.Application visioApp = new Visio.Application(); // Visible Application
            Visio.InvisibleApp visioApp            = new Visio.InvisibleApp();
            Visio.Document     visioTargetDocument = visioApp.Documents.OpenEx(targetFile, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visAddMacrosDisabled);

            Array pageNameArray;

            visioTargetDocument.Pages.GetNames(out pageNameArray);
            IList <string> pageNames = pageNameArray.Cast <string>().ToList();

            foreach (string referencePageName in referencePageNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                bool referencePageContained = pageNames.Remove(referencePageName);
                if (!referencePageContained)
                {
                    visioApp.Quit();
                    File.Delete(targetFile);
                    Console.Error.WriteLine(String.Format("ReferencePageName \"{0}\" not found in \"{1}\".", referencePageName, sourceFileInfo.FullName));
                    Usage();
                    return(3);
                }
            }

            foreach (string pageName in pageNames)
            {
                Visio.Page page = visioTargetDocument.Pages[pageName];
                page.Delete(1);
            }

            visioTargetDocument.Save();

            if (referencePageNames != "Template")
            {
                foreach (Visio.Page page in visioTargetDocument.Pages)
                {
                    foreach (Visio.Shape shape in page.Shapes)
                    {
                        if (shape.get_CellExists("User.StateChartType", (short)0) != 0)
                        {
                            string stateChartType = shape.Cells["User.StateChartType"].FormulaU;
                            if (stateChartType == "GUARD(0)")
                            {
                                Console.WriteLine("Name={0} NameID={1} NameU={2}", shape.Name, shape.NameID, shape.NameU);

                                shape.get_Cells("Prop.TargetFile").FormulaU = "";

                                Console.WriteLine("Prop.TargetFile Formula={0} Value={1}", shape.get_Cells("Prop.TargetFile").FormulaU, shape.get_Cells("Prop.TargetFile").get_ResultStrU((short)Visio.VisToParts.visNone));
                            }
                        }
                    }
                }
            }

            visioTargetDocument.Save();

            visioTargetDocument.Close();

            visioApp.Quit();

            Console.WriteLine(String.Format("File written to \"{0}\"", targetFileInfo.FullName));

            return(0);
        }