Ejemplo n.º 1
0
        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        *
        * Shared
        *
        * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

        /// <summary>
        /// Increments a named sequence, keeping the current sequence value in the
        /// page shape-sheet. If the sequence does not exist, will create the
        /// necessary properties in the shape-sheet.
        /// </summary>
        /// <param name="shape">Visio shape.</param>
        /// <param name="sequence">Sequence which will be incremented.</param>
        /// <returns>Sequence number.</returns>
        private int PageIncrementSequence(Visio.IVShape shape, string sequence)
        {
            #region Validations

            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (sequence == null)
            {
                throw new ArgumentNullException(nameof(sequence));
            }

            #endregion

            /*
             *
             */
            Visio.Page page = (Visio.Page)shape.Parent;

            string cellFull = string.Concat("User.ModelSequence_", sequence, ".Value");
            string cellPart = string.Concat("ModelSequence_", sequence);


            /*
             *
             */
            int value = 0;

            lock (this)
            {
                Visio.Cell cell;

                if (page.PageSheet.get_CellExists(cellFull, 1) != 0)
                {
                    cell  = page.PageSheet.get_Cells(cellFull);
                    value = int.Parse(VU.FormulaToString(cell.Formula), CultureInfo.InvariantCulture);
                }
                else
                {
                    page.PageSheet.AddNamedRow((short)Visio.VisSectionIndices.visSectionUser, cellPart, 0);
                    cell = page.PageSheet.get_Cells(cellFull);
                }

                cell.Formula = (++value).ToString(CultureInfo.InvariantCulture);
            }

            return(value);
        }
Ejemplo n.º 2
0
        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        *
        * Workers
        *
        * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */


        /// <summary>
        /// Executes a document/page command.
        /// </summary>
        /// <param name="command">Which command to execute.</param>
        /// <param name="mode">Which validation mode to use.</param>
        private static void CommandExecute(ModelCommand command, ValidationMode mode)
        {
            #region Validations

            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            #endregion


            /*
             * #0. Settings!
             */
            ModelExportSettings exportSettings = new ModelExportSettings();
            exportSettings.Program = "VisioAddIn";
            exportSettings.Mode    = mode;

            if (string.IsNullOrEmpty(command.Document.Path) == false)
            {
                exportSettings.Path = System.IO.Path.GetDirectoryName(command.Document.Path);
            }


            /*
             * #1. Run the exporter
             */
            ProgressForm pform = new ProgressForm();
            pform.Command  = command;
            pform.Settings = exportSettings;
            pform.ShowDialog();


            /*
             * #2. Repaint everything to show that it's ok.
             *     Paint all objects which have errors to red.
             *
             * TODO: This should probably be done in an undo unit, so that
             * the repainting of all of the shapes can be done atomically.
             */
            foreach (ModelCommandPageResult pageResult in pform.CommandResult.Pages)
            {
                if (pageResult.Processed == false)
                {
                    continue;
                }


                /*
                 * Paint all black.
                 */
                Visio.IVPage page = command.Document.Pages[pageResult.Name];

                if (page == null)
                {
                    continue;
                }

                foreach (Visio.IVShape shape in page.Shapes)
                {
                    Visio.VisDefaultColors orig = VU.ShapeColorGet(shape);

                    if (orig != Visio.VisDefaultColors.visBlack)
                    {
                        VU.ShapeColorSet(shape, Visio.VisDefaultColors.visBlack);
                    }
                }

                if (pageResult.Success == true)
                {
                    continue;
                }


                /*
                 * Paint red, only shapes with errors.
                 */
                foreach (ModelResultItem item in pageResult.Items)
                {
                    if (item.ItemType != ModelResultItemType.Error)
                    {
                        continue;
                    }

                    if (item.VisioShapeId == null)
                    {
                        continue;
                    }

                    Visio.IVShape shape = page.Shapes[item.VisioShapeId];

                    if (shape == null)
                    {
                        continue;
                    }

                    VU.ShapeColorSet(shape, Visio.VisDefaultColors.visRed);
                }
            }


            /*
             * #3.
             */
            ResultForm rform = new ResultForm();
            rform.CommandResult = pform.CommandResult;
            rform.ShowDialog();
        }