Esempio n. 1
0
        /// <summary>
        /// Background worker: this code, and all of the callbacks, are
        /// running in a different thread than the UI thread: as such, they
        /// *must* not interact at all with any of the UI elements. All
        /// interaction must occur via .ReportProgress.
        /// </summary>
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            ModelExporter export = new ModelExporter();

            export.Settings   = this.Settings;
            export.PageStart += new EventHandler <PageEventArgs>(export_PageStart);
            export.PageEnd   += new EventHandler <PageEventArgs>(export_PageEnd);
            export.StepStart += new EventHandler <PageStepEventArgs>(export_StepStart);
            export.StepEnd   += new EventHandler <PageStepEventArgs>(export_StepEnd);

            e.Result = export.Execute(this.Command);
        }
Esempio n. 2
0
 static void Main(string[] args) => ModelExporter.Execute(args);
Esempio n. 3
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);
            }
        }