Exemplo n.º 1
0
        internal static void ValidateExternalCss(ExternalCss externalCss, RulesException errors, int index, string[] duplicateUrls)
        {
            if (string.IsNullOrWhiteSpace(externalCss.Url))
            {
                errors.ErrorForModel(string.Format(VisualEditorStrings.ExternalCssUrlRequired, index));
                externalCss.Invalid = true;
            }
            else
            {
                if (duplicateUrls.Contains(externalCss.Url))
                {
                    errors.ErrorForModel(string.Format(VisualEditorStrings.ExternalCssUrlDuplicate, index));
                    externalCss.Invalid = true;
                }

                if (!UrlHelpers.IsValidWebFolderUrl(externalCss.Url))
                {
                    errors.ErrorForModel(string.Format(VisualEditorStrings.ExternalCssUrlNotValid, index));
                    externalCss.Invalid = true;
                }

                if (externalCss.Url.Length > 255)
                {
                    errors.ErrorForModel(string.Format(VisualEditorStrings.ExternalCssUrlMaxLengthExceeded, index));
                    externalCss.Invalid = true;
                }
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public override void Validate()
        {
            var errors = new RulesException <QpPlugin>();

            base.Validate(errors);

            if (!string.IsNullOrEmpty(LoadedContractInvalidMessage))
            {
                errors.ErrorFor(n => ServiceUrl, $"{QpPluginStrings.LoadedContractInvalidMessage}: {LoadedContractInvalidMessage}");
            }

            if (!string.IsNullOrEmpty(ParsedContractInvalidMessage))
            {
                errors.ErrorFor(n => Contract, $"{QpPluginStrings.ParsedContractInvalidMessage}: {ParsedContractInvalidMessage}");
            }

            if (!string.IsNullOrEmpty(ServiceUrl) && !UrlHelpers.IsValidWebFolderUrl(ServiceUrl))
            {
                errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ServiceUrlInvalidFormat);
            }

            if (ContractParsed)
            {
                if (string.IsNullOrEmpty(Contract))
                {
                    errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ContractNotEntered);
                }
                else
                {
                    if (string.IsNullOrEmpty(Code))
                    {
                        errors.ErrorFor(n => ServiceUrl, QpPluginStrings.CodeNotEntered);
                    }
                    else
                    {
                        if (QpPluginRepository.CodeExists(this))
                        {
                            errors.ErrorFor(n => Code, QpPluginStrings.CodeExists);
                        }
                    }
                    if (string.IsNullOrEmpty(Version))
                    {
                        errors.ErrorFor(n => ServiceUrl, QpPluginStrings.VersionNotEntered);
                    }
                    else
                    {
                        if (Version.Length > MaxVersionLength)
                        {
                            errors.ErrorFor(n => Version, String.Format(QpPluginStrings.VersionMaxLengthExceeded, null, MaxVersionLength));
                        }
                        else if (OldVersion == Version)
                        {
                            errors.ErrorFor(n => Version, QpPluginStrings.VersionEqual);
                        }
                    }

                    if (Fields.Any(n => String.IsNullOrEmpty(n.Name)))
                    {
                        errors.ErrorForModel(QpPluginStrings.FieldNameNotEntered);
                    }

                    if (Fields.Any(n => n.Name.Length > MaxFieldNameLength))
                    {
                        errors.ErrorForModel(String.Format(QpPluginStrings.FieldNameMaxLengthExceeded, null, MaxFieldNameLength));
                    }

                    if (Fields.GroupBy(n => n.Name.ToLower() + n.RelationType).Any(g => g.Count() > 1))
                    {
                        errors.ErrorForModel(QpPluginStrings.FieldNameDuplicate);
                    }
                }
            }

            if (!errors.IsEmpty)
            {
                throw errors;
            }
        }