Ejemplo n.º 1
0
        public override void Validate()
        {
            var errors = new RulesException <VisualEditorPlugin>();

            base.Validate(errors);

            if (!string.IsNullOrEmpty(Url) && !UrlHelpers.IsValidWebFolderUrl(Url))
            {
                errors.ErrorFor(n => Url, VisualEditorStrings.UrlPrefixInvalidFormat);
            }

            var duplicateCurrentNames   = VeCommands.GroupBy(c => c.Name).Where(g => g.Count() > 1).Select(x => x.Key).ToArray();
            var duplicateCurrentAliases = VeCommands.GroupBy(c => c.Alias).Where(g => g.Count() > 1).Select(x => x.Key).ToArray();

            if (VeCommands.Count == 0)
            {
                errors.ErrorForModel(VisualEditorStrings.CommandsRequired);
            }
            else
            {
                var veCommandsArray = VeCommands.ToArray();
                for (var i = 0; i < veCommandsArray.Length; i++)
                {
                    ValidateVeCommand(veCommandsArray[i], errors, i + 1, duplicateCurrentNames, duplicateCurrentAliases);
                }
            }

            if (!errors.IsEmpty)
            {
                throw errors;
            }
        }
Ejemplo n.º 2
0
        public void DoCustomBinding(List <VisualEditorCommand> jsonCommands)
        {
            Dictionary <int, VisualEditorCommand> oldVeCommands = null;

            if (VeCommands != null)
            {
                oldVeCommands = VeCommands.ToDictionary(n => n.Id, m => m);
            }

            var rowOrder            = VisualEditorRepository.GetCommandMaxRowOrder();
            var toolbarInRowOrder   = BaseCommandOrder + Order;
            var commandInGroupOrder = 0;

            foreach (var command in jsonCommands)
            {
                command.RowOrder            = rowOrder;
                command.ToolbarInRowOrder   = toolbarInRowOrder;
                command.GroupInToolbarOrder = 0;
                command.CommandInGroupOrder = commandInGroupOrder;

                command.PluginId = Id;
                if (command.Id != 0 && oldVeCommands != null)
                {
                    var oldCommand = oldVeCommands[command.Id];
                    command.Created  = oldCommand.Created;
                    command.Modified = oldCommand.Modified;
                }

                commandInGroupOrder++;
            }

            VeCommands = jsonCommands;
        }