コード例 #1
0
ファイル: Connect.cs プロジェクト: zi-yu/midgard
        /// <summary>
        /// Called when Visio loads the add-in.
        /// </summary>
        /// <param name="application">Reference to the Visio Application object.</param>
        /// <param name="connectMode">Describes how the add-in is started.</param>
        /// <param name="addInInst">Reference to the add-in.</param>
        /// <param name="custom">Array of additional parameters for the add-in.</param>
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            try
            {
                if (_visioApplication == null)
                {
                    _visioApplication = (VisioApplication)application;

                    /*
                     * Check visio version.
                     */
                    int majorVersion = (int)Convert.ToDouble(_visioApplication.Version, CultureInfo.InvariantCulture);

                    if ((majorVersion == 0) ||
                        (majorVersion < VisioUtils.MinVisioVersion))
                    {
                        return;
                    }


                    /*
                     * Start listening to the desired events.
                     */
                    _eventSink = new EventSink(Application);
                    EventSink.AddAdvise();
                    EventSink.CreateCommandBar();
                    EventSink.Activate();
                }
            }
            catch (Exception ex)
            {
                ESIMessageBox.ShowError(ex);
            }
        }
コード例 #2
0
 public VisioShapes()
 {
     db = new AccesoDatos();
     Microsoft.Office.Interop.Visio.Application Application = new Microsoft.Office.Interop.Visio.Application();
     Application.Documents.Add("");
     Microsoft.Office.Interop.Visio.Documents visioDocs = Application.Documents;
     visioStencil = visioDocs.OpenEx("Basic Shapes.vss",
                                     (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
     visioPage = Application.ActivePage;
 }
コード例 #3
0
ファイル: ThisAddIn.Designer.cs プロジェクト: nikkw/W2C
 protected override void Initialize() {
     base.Initialize();
     this.Application = this.GetHostItem<Microsoft.Office.Interop.Visio.Application>(typeof(Microsoft.Office.Interop.Visio.Application), "Application");
     Globals.ThisAddIn = this;
     global::System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
コード例 #4
0
 public static form_AddinManager GetUniqueForm(Application VisioApp)
 {
     if (_uniqueForm == null)
     {
         _uniqueForm = new form_AddinManager();
     }
     //
     _VisioApplication = VisioApp;
     return(_uniqueForm);
 }
コード例 #5
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            VisioApp = Globals.ThisAddIn.Application;

            SharedApp.HostApp = Globals.ThisAddIn.Application;
            // Custom taskpanes not available in Visio
            // SharedApp.InitAppTaskPanes(ref this.CustomTaskPanes);
            // SharedApp.AppTaskPanes.CreateTaskpaneInstance();

            VisioApp.DocumentOpened += new Microsoft.Office.Interop.Visio.EApplication_DocumentOpenedEventHandler(Visio_DocOpened);
        }
コード例 #6
0
 void _VisioApplication_NoEventsPending(Microsoft.Office.Interop.Visio.Application app)
 {
     if (Common.DisplayChattyEvents)
     {
         DisplayInWatchWindow(countNoEventsPending++, System.Reflection.MethodInfo.GetCurrentMethod().Name);;
     }
     else
     {
         countNoEventsPending++;
     }
 }
コード例 #7
0
 protected override void Initialize()
 {
     base.Initialize();
     this.Application  = this.GetHostItem <Microsoft.Office.Interop.Visio.Application>(typeof(Microsoft.Office.Interop.Visio.Application), "Application");
     Globals.ThisAddIn = this;
     global::System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
コード例 #8
0
        public override void PostParse()
        {
            base.PostParse();

            Microsoft.Office.Interop.Visio.Application visio = visioTL.Value;
            if (visio != null)
            {
                visioTL.Value = null;

                visio.Quit();
                visio = null;
            }
        }
コード例 #9
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                System.Console.WriteLine("Syntax is: VisioExportPagesToDocs <filename.vsd> [<outptufolder>]");
                System.Environment.Exit(0);
            }

            string input_filename = args[0];

            input_filename = System.IO.Path.GetFullPath(input_filename);

            var visioapp = new Microsoft.Office.Interop.Visio.Application();
            var docs     = visioapp.Documents;

            Microsoft.Office.Interop.Visio.Document doc = null;
            try
            {
                doc = docs.Open(input_filename);

                var settings = new ExporterSettings();
                settings.InputDocument = doc;
                if (args.Length >= 2)
                {
                    settings.DestinationPath = args[1];
                }
                else
                {
                    settings.DestinationPath = System.IO.Path.GetDirectoryName(input_filename);
                }

                var exporter = new Exporter(settings);
                foreach (var rec in exporter.Run())
                {
                    Console.WriteLine();
                    Console.WriteLine("Page Index: {0}", rec.PageIndex);
                    Console.WriteLine("Page Name: {0}", rec.PageName);
                    Console.WriteLine("Output document: {0}", rec.OutputFilename);
                    Console.WriteLine("Output document already exists: {0}", rec.OutputFileAlreadyExists);
                    Console.WriteLine("Wrote output document: {0}", rec.OutputFileWritten);
                }
            }
            catch (System.Runtime.InteropServices.COMException comexc)
            {
                throw new System.ArgumentException(string.Format("Failed to open file: {0}", comexc.Message));
            }
        }
コード例 #10
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                System.Console.WriteLine("Syntax is: VisioExportPagesToDocs <filename.vsd> [<outptufolder>]");
                System.Environment.Exit(0);
            }

            string input_filename = args[0];
            input_filename = System.IO.Path.GetFullPath(input_filename);

            var visioapp = new Microsoft.Office.Interop.Visio.Application();
            var docs = visioapp.Documents;
            Microsoft.Office.Interop.Visio.Document doc = null;
            try
            {
                doc = docs.Open(input_filename);

                var settings = new ExporterSettings();
                settings.InputDocument = doc;
                if (args.Length >= 2)
                {
                    settings.DestinationPath = args[1];
                }
                else
                {
                    settings.DestinationPath = System.IO.Path.GetDirectoryName(input_filename);
                }

                var exporter = new Exporter(settings);
                foreach (var rec in exporter.Run())
                {
                    Console.WriteLine();
                    Console.WriteLine("Page Index : {0}", rec.PageIndex);
                    Console.WriteLine("Page Name : {0}", rec.PageName);
                    Console.WriteLine("Output Document : {0}", rec.OutputFilename);
                    Console.WriteLine("Output Document already existed : {0}", rec.OutputFileAlreadyExisted);
                    Console.WriteLine("Wrote output file: {0}", rec.OutputFileWritten);
                }

            }
            catch (System.Runtime.InteropServices.COMException comexc)
            {
                throw new System.ArgumentException(string.Format("Failed to open file: {0}", comexc.Message));
            }
        }
コード例 #11
0
        public static string GetXmlErrorLogFilename(Microsoft.Office.Interop.Visio.Application app)
        {
            // the location of the xml error log file is specific to the user
            // we need to retrieve it from the registry
            var hkcu = Microsoft.Win32.Registry.CurrentUser;

            // The reg path is specific to the version of visio being used

            string ver            = app.Version;
            string ver_normalized = ver.Replace(",", ".");

            string path = string.Format(@"Software\Microsoft\Office\{0}\Visio\Application", ver_normalized);

            string logfilename = null;

            using (var key_visio_application = hkcu.OpenSubKey(path))
            {
                if (key_visio_application == null)
                {
                    // key doesn't exist - can't continue
                    throw new VisioAutomation.Exceptions.InternalAssertionException("Could not find the key visio application key in hkcu");
                }

                var subkeynames = key_visio_application.GetValueNames();
                if (!subkeynames.Contains("XMLErrorLogName"))
                {
                    return(null);
                }

                logfilename = (string)key_visio_application.GetValue("XMLErrorLogName");
            }

            // the folder that contains the file is located in the users internet cache
            // C:\Users\<your alias>\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO\VisioLogFiles
            string internetcache = System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache);
            string folder        = System.IO.Path.Combine(internetcache, @"Content.MSO\VisioLogFiles");

            var s = System.IO.Path.Combine(folder, logfilename);

            System.Diagnostics.Debug.WriteLine("XmlErrorLogFilename: " + s);

            return(s);
        }
コード例 #12
0
 /// <summary> 构造函数 </summary>
 private frm_CurveParameter(Application vsoApp)
 {
     InitializeComponent();
     this.KeyPreview   = true;
     this.FormClosing += OnFormClosing;
     this.KeyDown     += OnKeyDown;
     //
     _vsoApp = vsoApp;
     //
     textBoxTolerance.Text         = @"0.01";
     textBoxTolerance.PositiveOnly = true;
     textBox_degree.Text           = @"2";
     textBox_degree.PositiveOnly   = true;
     textBox_degree.IntegerOnly    = true;
     //
     ConstructDatagridview(dataGridView1 as eZDataGridView);
     // 事件绑定
     radioButton_spline.CheckedChanged += RadioButtonSplineOnCheckedChanged;
 }
コード例 #13
0
ファイル: Converter.cs プロジェクト: sep/visio2img
        public void Convert(string visioFile,
                            Action<int> pageCount,
                            Func<string, string> getFilename,
                            Action<string, int> fileCreated)
        {
            var visio = new Microsoft.Office.Interop.Visio.Application();
            var document = visio.Documents.OpenEx(visioFile, VisioConstants.VisOpenRo + VisioConstants.VisOpenNoWorkspace + VisioConstants.VisOpenNoWorkspace + VisioConstants.VisOpenMinimized + VisioConstants.VisOpenMacrosDisabled + VisioConstants.VisOpenHidden);

            using (Disposer.Create(visio.Quit))
            using (Disposer.Create(document.Close))
            {
                pageCount(document.Pages.Count);
                Enumerable.Range(1, document.Pages.Count).ToList().ForEach(i =>
                {
                    var page = document.Pages[i];
                    var filename = getFilename(page.Name);

                    page.Export(filename);
                    fileCreated(filename, i);
                });
            }
        }
コード例 #14
0
        //选择新的Visio文档
        /// <summary>
        /// 选择新的Visio文档
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        public void BtnChooseVsoDoc_Click(object sender, EventArgs e)
        {
            string FilePath = "";

            this.OpenFileDialog1.Title       = "选择进行数据链接的Visio文档";
            this.OpenFileDialog1.Filter      = "Visio文件(*.vsd)|*.vsd";
            this.OpenFileDialog1.FilterIndex = 2;
            this.OpenFileDialog1.Multiselect = false;
            if (this.OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                FilePath = this.OpenFileDialog1.FileName;
            }
            else
            {
                return;
            }
            if (FilePath.Length > 0)
            {
                //
                this.txtbxVsoDoc.Text = FilePath;
                //
                if (this.F_vsoApplication == null)
                {
                    this.F_vsoApplication             = new Microsoft.Office.Interop.Visio.Application();
                    this.F_vsoApplication.BeforeQuit += this.F_vsoApplication_BeforeQuit;
                }
                //
                try
                {
                    this.vsoDoc = this.F_vsoApplication.Documents.Open(FilePath);
                }
                catch (Exception)
                {
                    MessageBox.Show("Visio文档打开出错,请检查后重新打开。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.F_vsoApplication.Visible = true;
            }
        }
コード例 #15
0
        public override bool Parse(FileInfo sourceFile, DirectoryInfo targetDir)
        {
            int index = 1;

            if (!IsTargetFileOutdated(sourceFile, BuildTargetFileName(sourceFile, targetDir, index)))
            {
                // if the first slide of a file is not invalid all other slides are still valid, too
                return(false);
            }
            Microsoft.Office.Interop.Visio.Application visio = visioTL.Value;
            if (visio == null)
            {
                visio         = new Microsoft.Office.Interop.Visio.Application();
                visio.Visible = false;

                visioTL.Value = visio;
            }
            Microsoft.Office.Interop.Visio.Document vsd = visioTL.Value.Documents.Open(sourceFile.FullName);
            try
            {
                foreach (Microsoft.Office.Interop.Visio.Page page in vsd.Pages)
                {
                    DoExport(sourceFile, targetDir, index, delegate(FileInfo targetFile)
                    {
                        page.Export(targetFile.FullName);
                    });
                    index++;
                }
                return(true);
            }
            finally
            {
                vsd.Saved = true;
                vsd.Close();
            }
        }
コード例 #16
0
 void _VisioApplication_BeforeSuspend(Microsoft.Office.Interop.Visio.Application app)
 {
     DisplayInWatchWindow(countBeforeSuspend++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #17
0
 public FrmBabylonScene(Microsoft.Office.Interop.Visio.Application visApp)
 {
     InitializeComponent();
     chkLight.Checked = true;
     webBrowserBabylon.ObjectForScripting = this;
 }
コード例 #18
0
 bool _VisioApplication_QueryCancelQuit(Microsoft.Office.Interop.Visio.Application app)
 {
     DisplayInWatchWindow(countQueryCancelQuit++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
     return(false);
 }
コード例 #19
0
ファイル: Connect.cs プロジェクト: zi-yu/midgard
        /// <summary>
        /// Called when Visio loads the add-in.
        /// </summary>
        /// <param name="application">Reference to the Visio Application object.</param>
        /// <param name="connectMode">Describes how the add-in is started.</param>
        /// <param name="addInInst">Reference to the add-in.</param>
        /// <param name="custom">Array of additional parameters for the add-in.</param>
        public void OnConnection( object application, ext_ConnectMode connectMode, object addInInst, ref Array custom )
        {
            try
            {
                if ( _visioApplication == null )
                {
                    _visioApplication = (VisioApplication) application;

                    /*
                     * Check visio version.
                     */
                    int majorVersion = (int) Convert.ToDouble( _visioApplication.Version, CultureInfo.InvariantCulture );

                    if (   ( majorVersion == 0 )
                        || ( majorVersion < VisioUtils.MinVisioVersion ) )
                    {
                        return;
                    }

                    /*
                     * Start listening to the desired events.
                     */
                    _eventSink = new EventSink( Application );
                    EventSink.AddAdvise();
                    EventSink.CreateCommandBar();
                    EventSink.Activate();
                }
            }
            catch ( Exception ex )
            {
                ESIMessageBox.ShowError( ex );
            }
        }
コード例 #20
0
 void _VisioApplication_MustFlushScopeBeginning(Microsoft.Office.Interop.Visio.Application app)
 {
     DisplayInWatchWindow(countMustFlushScopeBeginning++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #21
0
 /// <summary>
 /// Visio程序关闭
 /// </summary>
 /// <param name="app"></param>
 /// <remarks></remarks>
 private void F_vsoApplication_BeforeQuit(Microsoft.Office.Interop.Visio.Application app)
 {
     this.F_vsoApplication             = null;
     this.F_vsoApplication.BeforeQuit += this.F_vsoApplication_BeforeQuit;
 }
コード例 #22
0
        static void Main(string[] args)
        {
            /*
             *
             */
            CommandLine options = new CommandLine();

            if (options.Parse(args) == false)
            {
                Environment.Exit(1001);
                return;
            }

            if (options.Help == true)
            {
                options.HelpShow();
                Environment.Exit(1002);
                return;
            }

            _options = options;


            /*
             *
             */
            string[] files = Yttrium.Glob.Do(options.FilePatterns.ToArray());

            if (files == null || files.Length == 0)
            {
                Console.WriteLine("error: no matching files.");
                Environment.Exit(2);
            }


            /*
             *
             */
            Console.WriteLine("~ mode: '{0}'", _options.Mode);


            /*
             *
             */
            Microsoft.Office.Interop.Visio.Application visio = null;
            bool anyError = false;

            try
            {
                /*
                 *
                 */
                ModelExporter exporter = new ModelExporter();
                exporter.PageStart += new EventHandler <PageEventArgs>(OnPageStart);
                exporter.PageEnd   += new EventHandler <PageEventArgs>(OnPageEnd);
                exporter.StepStart += new EventHandler <PageStepEventArgs>(OnStepStart);
                exporter.StepEnd   += new EventHandler <PageStepEventArgs>(OnStepEnd);

                /*
                 *
                 */
                visio = new Microsoft.Office.Interop.Visio.Application();
                visio.AlertResponse = 1;
                visio.Visible       = false;

                foreach (string file in files)
                {
                    /*
                     *
                     */
                    Console.Write("+ opening '{0}'...", Path2.RelativePath(file));
                    FileInfo fileInfo = new FileInfo(file);

                    if (fileInfo.Exists == false)
                    {
                        ConsoleFail();
                        Console.WriteLine(" - file does not exist");

                        anyError = true;
                        continue;
                    }


                    /*
                     * Open the document: if the document is not a valid/compatible Visio
                     * document, this will fail.
                     */
                    Microsoft.Office.Interop.Visio.Document document;

                    try
                    {
                        document = visio.Documents.Open(fileInfo.FullName);
                        ConsoleOk();
                    }
                    catch (Exception ex)
                    {
                        ConsoleFail();

                        if (options.Verbose == true)
                        {
                            ConsoleDump(ex);
                        }

                        anyError = true;
                        continue;
                    }


                    /*
                     * Settings
                     */
                    ModelExportSettings exportSettings = new ModelExportSettings();
                    exportSettings.Program = "ModelExport";
                    exportSettings.Mode    = options.Mode;
                    exportSettings.Path    = options.OutputDirectory ?? fileInfo.DirectoryName;

                    exporter.Settings = exportSettings;


                    /*
                     * Export.
                     */
                    ModelCommandResult result = null;

                    ModelCommand command = new ModelCommand();
                    command.Document  = document;
                    command.Operation = ModelOperation.ExportAll;

                    if (options.ValidateOnly == true)
                    {
                        command.Operation = ModelOperation.ValidateAll;
                    }


                    try
                    {
                        result = exporter.Execute(command);
                    }
                    catch (Exception ex)
                    {
                        anyError = true;

                        if (options.Verbose == true)
                        {
                            ConsoleDump(ex);
                        }
                    }
                    finally
                    {
                        document.Close();
                    }

                    if (result == null)
                    {
                        continue;
                    }


                    /*
                     *
                     */
                    Console.WriteLine("");
                    Console.WriteLine("execution summary");
                    Console.WriteLine("-------------------------------------------------------------------------");

                    foreach (ModelCommandPageResult pageResult in result.Pages)
                    {
                        Console.Write(pageResult.Name);

                        if (pageResult.Success == true)
                        {
                            ConsoleOk();
                        }
                        else
                        {
                            ConsoleFail();
                        }

                        foreach (ModelResultItem item in pageResult.Items)
                        {
                            string marker;

                            switch (item.ItemType)
                            {
                            case ModelResultItemType.Error:
                                Console.ForegroundColor = ConsoleColor.DarkRed;
                                marker = "!";
                                break;

                            case ModelResultItemType.Warning:
                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                                marker = "W";
                                break;

                            default:
                                marker = " ";
                                break;
                            }

                            if (item.VisioShapeId == null)
                            {
                                Console.WriteLine("{0} [page] {1}#{2}: {3}", marker, item.Actor, item.Code, item.Description);
                            }
                            else
                            {
                                Console.WriteLine("{0} [{1}] {2}#{3}: {4}", marker, item.VisioShapeId, item.Actor, item.Code, item.Description);
                            }

                            Console.ResetColor();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleDump(ex);
            }
            finally
            {
                // This _needs_ to be performed here: in case an exception is caught,
                // make sure that Visio is closed or otherwise a zombie process will
                // be left running on the machine.
                if (visio != null)
                {
                    visio.Quit();
                }
            }


            /*
             *
             */
            if (anyError == true)
            {
                Environment.Exit(3);
            }
            else
            {
                Environment.Exit(0);
            }
        }
コード例 #23
0
 void _VisioApplication_AfterModal(Microsoft.Office.Interop.Visio.Application app)
 {
     DisplayInWatchWindow(countAfterModal++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #24
0
 void _VisioApplication_MarkerEvent(Microsoft.Office.Interop.Visio.Application app, int SequenceNum, string ContextString)
 {
     DisplayInWatchWindow(countMarkerEvent++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #25
0
 void _VisioApplication_EnterScope(Microsoft.Office.Interop.Visio.Application app, int nScopeID, string bstrDescription)
 {
     DisplayInWatchWindow(countEnterScope++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #26
0
 /// <summary> 全局唯一的一个窗口实例 </summary>
 /// <param name="vsoApp"></param>
 /// <returns></returns>
 public static frm_CurveParameter GetUniqueInstance(Application vsoApp)
 {
     _uniqueInstance = _uniqueInstance ?? new frm_CurveParameter(vsoApp);
     return(_uniqueInstance);
 }