Ejemplo n.º 1
0
        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         * ~
         * ~ Settings validation
         * ~
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

        private static ModelCommandResult ValidateSettings(ModelCommand command, ModelExportSettings settings)
        {
            #region Validations

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

            #endregion

            string pageName = PageName(command);

            if (settings == null)
            {
                return(BuildResult(pageName, "SettingsRequired"));
            }

            if (command.Operation == ModelOperation.ExportAll || command.Operation == ModelOperation.ValidateAll)
            {
                if (command.Document == null)
                {
                    return(BuildResult(pageName, "SettingsPathDocumentNull"));
                }
            }

            if (command.Operation == ModelOperation.ExportCurrent || command.Operation == ModelOperation.ValidateCurrent)
            {
                if (command.Page == null)
                {
                    return(BuildResult(pageName, "SettingsPathPageNull"));
                }
            }

            if (command.Operation == ModelOperation.ExportAll || command.Operation == ModelOperation.ExportCurrent)
            {
                if (string.IsNullOrEmpty(settings.Path) == true)
                {
                    if (settings.Program == "VisioAddIn")
                    {
                        return(BuildResult(pageName, "SettingsPathRequiredAddIn"));
                    }
                    else
                    {
                        return(BuildResult(pageName, "SettingsPathRequiredElse"));
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static string PageName(ModelCommand command)
        {
            #region Validations

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

            #endregion

            if (command.Page != null)
            {
                return(command.Page.Name);
            }
            else
            {
                return(command.Document.Pages[1].Name);
            }
        }
Ejemplo n.º 3
0
        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         * ~
         * ~ Public methods
         * ~
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

        /// <summary>
        /// Executes an export command.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        public ModelCommandResult Execute(ModelCommand command)
        {
            #region Validations

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

            #endregion

            ModelCommandResult result = ValidateSettings(command, this.Settings);

            if (result != null)
            {
                return(result);
            }

            switch (command.Operation)
            {
            case ModelOperation.ExportAll:
                result = ExportAll(command.Document);
                break;

            case ModelOperation.ExportCurrent:
                result = ExportPage(command.Page);
                break;

            case ModelOperation.ValidateAll:
                result = ValidateAll(command.Document);
                break;

            case ModelOperation.ValidateCurrent:
                result = ValidatePage(command.Page);
                break;
            }

            return(result);
        }