当前位置: 首页>>代码示例>>C#>>正文


C# RuleContext.AddErrorResult方法代码示例

本文整理汇总了C#中RuleContext.AddErrorResult方法的典型用法代码示例。如果您正苦于以下问题:C# RuleContext.AddErrorResult方法的具体用法?C# RuleContext.AddErrorResult怎么用?C# RuleContext.AddErrorResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RuleContext的用法示例。


在下文中一共展示了RuleContext.AddErrorResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            if (context == null)
                return;

            var selectedFrequency = (int?)context.InputPropertyValues[PrimaryProperty];
            var frequencyTypeString = (string)context.InputPropertyValues[_frequencyTypeProperty];

            var frequencyName = (string)context.InputPropertyValues[_frequencyName];

            FrequencyEventEnum frequencyType;

            if (string.IsNullOrEmpty(frequencyTypeString))
                frequencyTypeString = FrequencyEventEnum.Time.ToString();

            if (!Enum.TryParse(frequencyTypeString, true, out frequencyType))
                return;

            if (frequencyType == FrequencyEventEnum.Event)
            {
                if (!selectedFrequency.HasValue || selectedFrequency.Value == 0)
                {
                    context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.InvariantCulture, "Frequency event for field \"{0}\" is required.", _frequencyFieldName));
                }

                if (string.IsNullOrEmpty(frequencyName))
                {
                    context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.InvariantCulture, "Frequency event for field \"{0}\" is required.", _frequencyFieldName));
                }
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:35,代码来源:FrequencyEventIsRequiredRule.cs

示例2: Execute

        protected override void Execute(RuleContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("Context cannot be null");
            }

            var imageArray = (byte[])context.InputPropertyValues[this.ImageProptery];
            if (imageArray != null && imageArray.Length > 0)
            {
                try
                {
                    using (var ms = new MemoryStream(imageArray))
                    {
                        var image = System.Drawing.Image.FromStream(ms);
                        if (image.Height != ImageConstants.AllowedHeight || image.Width != ImageConstants.AllowedWidth)
                        {
                            context.AddErrorResult(string.Format(CultureInfo.CurrentCulture, "The supplied image must have a height of {0} px and a width of {1} px.", ImageConstants.AllowedHeight, ImageConstants.AllowedWidth));
                        }
                    }
                }
                catch (ArgumentException)
                {
                    context.AddErrorResult("Image must be set with a valid image type.");
                }
            }
        }
开发者ID:Bowman74,项目名称:Badge-Application,代码行数:27,代码来源:ImageProperSize.cs

示例3: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            var sections = (ProcessSections)context.InputPropertyValues[ProcessEdit.SectionListProperty];
            if (sections == null || sections.Count == 0)
                return;

            if ((bool)context.InputPropertyValues[ProcessEdit.IsSystemProperty])
                return;

            var layoutList = (IProcessLayoutList)context.InputPropertyValues[PrimaryProperty];

            var defaultLayout = layoutList.GetDefaultLayout();
            if (defaultLayout == null)
                context.AddErrorResult(LanguageService.Translate("Rule_ProcessDefaultLayout"));

            foreach (var layout in layoutList)
            {
                if (string.IsNullOrEmpty(layout.Name))
                    context.AddErrorResult(PrimaryProperty, LanguageService.Translate("Rule_ProcessLayoutName"));
                if (string.IsNullOrEmpty(layout.LayoutInfo))
                    context.AddErrorResult(PrimaryProperty, LanguageService.Translate("Rule_ProcessSearchMustHaveAtLeastOneField"));
            }

            context.Complete();
        }
开发者ID:mparsin,项目名称:Elements,代码行数:29,代码来源:ProcessSearchMustHaveAtLeastOneFieldRule.cs

示例4: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            var process = context.Target as ProcessEdit;

            if (process == null)
                return;

            var commands = (ProcessCommandEditList)context.InputPropertyValues[PrimaryProperty];
            var states = process.StateList;

            if (commands == null)
                return;

            if (states != null)
                foreach (var command in commands)
                {
                    if (command.SecurityConfigurationList == null || command.SecurityConfigurationList.Count <= 0)
                        continue;

                    var configurationList = command.SecurityConfigurationList.Where(c => c.StateGuid != Constants.AllStatesGuid);
                    var depricatedConfigurationList = configurationList.Where(c => states.Count(s => s.Guid == c.StateGuid) == 0);

                    foreach (var depricatedItem in depricatedConfigurationList)
                        context.AddErrorResult(PrimaryProperty, string.Format(LanguageService.Translate("Rule_CommandSecurityConfigurationsState"), command.CommandName, depricatedItem));
                }
            else
                foreach (var command in commands)
                {
                    if (command.SecurityConfigurationList == null || command.SecurityConfigurationList.Count <= 0)
                        continue;

                    foreach (var depricatedItem in command.SecurityConfigurationList)
                        context.AddErrorResult(PrimaryProperty, string.Format(LanguageService.Translate("Rule_CommandSecurityConfigurationsState"), command.CommandName, depricatedItem));
                }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:39,代码来源:StatesShouldContainCommandSecurityConfigurationsState.cs

示例5: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            var sections = (ProcessSections)context.InputPropertyValues[PrimaryProperty];

            if (sections == null || sections.Count == 0)
                return;

            //ignore parent
            var localSections = sections.Where(s => !s.IsBase).ToList();

            //duplicate section name check
            var duplicateSections = localSections.Where(x => localSections.Count(y => y.Name == x.Name) > 1);
            foreach (var section in duplicateSections)
                context.AddErrorResult(string.Format(LanguageService.Translate("Rule_UniqueSectionName"), section.Name));

            //duplicate field's system name check
            var fields = new Dictionary<string, string>();
            foreach (var section in sections.Where(s => s.FieldList != null))
                foreach (var field in section.FieldList.Where(f => !string.IsNullOrEmpty(f.SystemName)))
                    if (fields.Keys.Any(key => key.ToUpperInvariant().Equals(field.SystemName.ToUpperInvariant())))
                    {
                        var duplicate = fields.First(f => f.Key.Equals(field.SystemName, StringComparison.OrdinalIgnoreCase));
                        context.AddErrorResult(string.Format(LanguageService.Translate("Rule_UniqueFieldSystemNames"), field.SystemName, section.Name, duplicate.Value));
                    }
                    else
                        fields.Add(field.SystemName, section.Name);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:31,代码来源:FieldSystemNamesAreUniqueRule.cs

示例6: Execute

        protected override void Execute(RuleContext context)
        {

            DateTime startTime = (DateTime) context.InputPropertyValues[startPropertyInfo];
            DateTime endTime = (DateTime)context.InputPropertyValues[endPropertyInfo];

            if (DateTime.Compare(startTime, endTime) >= 0)
            {
                context.AddErrorResult(ValidationMessages.InvalidTimeRange);
            }
            else if ((endTime - startTime).Hours <= 0)
            {
                context.AddErrorResult(ValidationMessages.MinHourInvalid);
            }
            else
            {
                var chainedContext1 = context.GetChainedContext(InnerTopOfHourStartRule);
                InnerTopOfHourStartRule.Execute(chainedContext1);

                var chainedContext2 = context.GetChainedContext(InnerTopOfHourEndRule);
                InnerTopOfHourEndRule.Execute(chainedContext2);
            }

            
        }
开发者ID:rbocobo,项目名称:MagenicMasters.Csla,代码行数:25,代码来源:TimeRangeRule.cs

示例7: Execute

        /// <summary>
        /// Executes the rule.
        /// </summary>
        /// <param name="context">The rule context.</param>
        protected override void Execute(RuleContext context)
        {
            try
            {
                var process = (ProcessEdit)context.Target;
                var allFields = GetProcessFields(process);

                foreach (var field in process.GetAllFields())
                {
                    var crossRefStep = field.StepList.OfType<CrossRefOptionsStepEdit>().FirstOrDefault();

                    if (crossRefStep != null)
                    {
                        if (!IsFilterValid(crossRefStep.FilterDefinition, allFields))
                            context.AddErrorResult(
                                string.Format(LanguageService.Translate("Rule_FilterReferencesInvalidFields"), field.Name ?? string.Empty));
                        continue;
                    }

                    var checklistStep = field.StepList.OfType<ChecklistSettingsStepEdit>().FirstOrDefault();

                    if (checklistStep != null)
                    {
                        if (!IsFilterValid(checklistStep.FilterDefinition, allFields))
                            context.AddErrorResult(
                                string.Format(LanguageService.Translate("Rule_FilterReferencesInvalidFields"), field.Name ?? string.Empty));
                    }
                }
            }
            catch (Exception ex)
            {
                context.AddErrorResult(PrimaryProperty, ex.Message);
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:38,代码来源:FilterParametersShouldReferenceValidFieldsRule.cs

示例8: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            var uri = context.InputPropertyValues[PrimaryProperty] as string;

            System.Diagnostics.Debug.WriteLine(uri);

            if (!string.IsNullOrWhiteSpace(uri) && !SystemPath.IsRelative(uri) && !Uri.IsWellFormedUriString(uri, UriKind.Absolute))
                context.AddErrorResult(PrimaryProperty, "Invalid URI");
            else if (SystemPath.IsRelative(uri) && !Uri.IsWellFormedUriString(uri, UriKind.Relative))
                context.AddErrorResult(PrimaryProperty, "Invalid URI");
        }
开发者ID:mparsin,项目名称:Elements,代码行数:15,代码来源:URIValidationRule.cs

示例9: Execute

    protected override void Execute(RuleContext context)
#endif
    {
        int role = (int)context.InputPropertyValues[PrimaryProperty];
#if __ANDROID__
        var roles = await RoleList.GetListAsync();
        if (!(await RoleList.GetListAsync()).ContainsKey(role))
            context.AddErrorResult("Role must be in RoleList");
        context.Complete();
#else
      if (!RoleList.GetList().ContainsKey(role))
        context.AddErrorResult("Role must be in RoleList");
#endif
    }
开发者ID:ruanbl,项目名称:csla,代码行数:14,代码来源:ValidRole.cs

示例10: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            if (context == null)
                return;

            var value = context.InputPropertyValues[InputProperties[0]];

            if (value == null)
            {
                return;
            }

            var s = value as string;
            if (s != null && string.IsNullOrEmpty(s))
                return;

            if (value is int)
            {
                return;
            }

            if (value is decimal)
            {
                if ((decimal)value < int.MaxValue && (decimal)value > int.MinValue)
                    return;
            }

            context.AddErrorResult("Value must be between -2 147 483 648 and +2 147 483 647");
        }
开发者ID:mparsin,项目名称:Elements,代码行数:33,代码来源:AqlForciblyRule.cs

示例11: Execute

        /// <summary>
        /// Business or validation rule implementation.
        /// </summary>
        /// <param name="context">Rule context object.</param>
        protected override void Execute(RuleContext context)
        {
            var commands = (ProcessCommandEditList)context.InputPropertyValues[PrimaryProperty];

            if (commands == null) return;

            foreach (var command in commands)
            {
                var foundConfigurations = new HashSet<ProcessCommandSecurityConfigurationEdit>();

                var command1 = command;
                foreach (var configuration in command.SecurityConfigurationList.Where(configuration => !foundConfigurations.Any(f => f.RoleId == configuration.RoleId &&
                                                                                                                                     f.StateGuid == configuration.StateGuid &&
                                                                                                                                     f.BusinessUnitId == configuration.BusinessUnitId &&
                                                                                                                                     f.PersonFieldSystemName == configuration.PersonFieldSystemName)
                                                                                                       && command1.SecurityConfigurationList.Any(x => !x.Equals(configuration) &&
                                                                                                                                                      x.RoleId == configuration.RoleId &&
                                                                                                                                                      x.StateGuid == configuration.StateGuid &&
                                                                                                                                                      x.BusinessUnitId == configuration.BusinessUnitId &&
                                                                                                                                                      x.PersonFieldSystemName == configuration.PersonFieldSystemName))
                    )
                {
                    foundConfigurations.Add(configuration);

                    context.AddErrorResult(PrimaryProperty, string.Format(LanguageService.Translate("Rule_UniqueSecurityConfiguration"), command.CommandName));
                }
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:32,代码来源:ProcessCommandSecurityConfigurationShouldByUniqueRule.cs

示例12: Execute

        protected override void Execute(RuleContext context)
        {
            var activityIdValue = (int)context.InputPropertyValues[PrimaryProperty];
            var activityStatusProperty = this.InputProperties.Single(p => p.Name == this.StatusName);
            var activtyStatusValue = (ActivitySubmissionStatus)context.InputPropertyValues[activityStatusProperty];
            var approvedByIdProperty = this.InputProperties.Single(p => p.Name == this.ApprovedByIdName);
            var approvedByIdValue = (ActivitySubmissionStatus)context.InputPropertyValues[approvedByIdProperty];

            if (approvedByIdValue == 0
                && (activtyStatusValue == ActivitySubmissionStatus.Unset
                || activtyStatusValue == ActivitySubmissionStatus.AwaitingApproval
                || activtyStatusValue == ActivitySubmissionStatus.Approved))
            {
                try
                {
                    var activityTask = Task.Run(() => IoC.Container.Resolve<IObjectFactory<IActivityEdit>>().FetchAsync(activityIdValue));
                    var activity = activityTask.Result;
                    context.AddOutValue(activityStatusProperty,
                        activity.RequiresApproval
                            ? ActivitySubmissionStatus.AwaitingApproval
                            : ActivitySubmissionStatus.Approved);
                }
                catch (Exception)
                {
                    context.AddErrorResult(PrimaryProperty,
                        string.Format(CultureInfo.CurrentCulture, "Activity id {0} was not able to be retrieved.", activityIdValue));
                }
            }
        }
开发者ID:Bowman74,项目名称:Badge-Application,代码行数:29,代码来源:DefaultActivityStatus.cs

示例13: Execute

    protected override void Execute(RuleContext context)
    {
#if SILVERLIGHT
        int role = (int)context.InputPropertyValues[PrimaryProperty];
        RoleList.GetList((o, e) =>
          {
            if (!e.Object.ContainsKey(role))
              context.AddErrorResult("Role must be in RoleList");
            context.Complete();
          });
#else
      int role = (int)context.InputPropertyValues[PrimaryProperty];
      if (!RoleList.GetList().ContainsKey(role))
        context.AddErrorResult("Role must be in RoleList");
#endif
    }
开发者ID:GavinHwa,项目名称:csla,代码行数:16,代码来源:ValidRole.cs

示例14: Execute

 /// <summary>
 /// Business or validation rule implementation.
 /// </summary>
 /// <param name="context">Rule context object.</param>
 protected override void Execute(RuleContext context)
 {
     if ((int)context.InputPropertyValues[ProcessScheduleEdit.ScheduleFrequencyPatternIdProperty] == 0)
     {
         context.AddErrorResult(PrimaryProperty, LanguageService.Translate("Rule_ScheduleFrequencyPattern"));
     }
 }
开发者ID:mparsin,项目名称:Elements,代码行数:11,代码来源:ScheduleFrequencyPatternRule.cs

示例15: Execute

 /// <summary>
 /// Business or validation rule implementation.
 /// </summary>
 /// <param name="context">Rule context object.</param>
 protected override void Execute(RuleContext context)
 {
     if (string.IsNullOrEmpty((string)context.InputPropertyValues[ProcessScheduleEdit.ScheduleDisplayDateFieldProperty]))
     {
         context.AddErrorResult(PrimaryProperty, LanguageService.Translate("Rule_ScheduleDate"));
     }
 }
开发者ID:mparsin,项目名称:Elements,代码行数:11,代码来源:ScheduleDateRule.cs


注:本文中的RuleContext.AddErrorResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。