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


C# RuleContext类代码示例

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


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

示例1: DoesUserAgentMatchesTheRegularExpressionValueCondition

    public void DoesUserAgentMatchesTheRegularExpressionValueCondition(string userAgent, string regularExpressionValue, bool expectedResult, Db database)
    {


      SetupDb(database);


      RuleContext ruleContext = new RuleContext();

      PoorMansDeviceDetectorCondition<RuleContext> customUserAgentCondition = new PoorMansDeviceDetectorCondition<RuleContext>()
      {
        OperatorId = Constants.StringOperations.MatchesTheRegularExpression.ItemID.ToString(),
        Value = regularExpressionValue,
        UserAgent = userAgent
      };

      var ruleStack = new RuleStack();

      // act
      customUserAgentCondition.Evaluate(ruleContext, ruleStack);

      // assert
      ruleStack.Should().HaveCount(1);

      object value = ruleStack.Pop();

      value.Should().Be(expectedResult);

    }
开发者ID:GoranHalvarsson,项目名称:Habitat,代码行数:29,代码来源:PoorMansDeviceDetectorConditionTests.cs

示例2: 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

示例3: MinHourDifferenceIsAtLeastAnHour

        public void MinHourDifferenceIsAtLeastAnHour()
        {
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("endTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));


            var wsMock = new Mock<IWorkSchedule>();
            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014, 4, 1, 10, 0, 0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 10, 30, 0));

            var newRule = new MinHourDifferenceRule(startTimeProperty.Object, endTimeProperty.Object);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, { endTimeProperty.Object, wsMock.Object.EndTime } });
            var ruleInterface = (IBusinessRule)newRule;

            ruleInterface.Execute(ruleContext);


            Assert.IsTrue(ruleContext.Results.Count > 0);

            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014, 4, 1, 8, 0, 0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 9, 30, 0));
            ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, { endTimeProperty.Object, wsMock.Object.EndTime } });
            ruleInterface = (IBusinessRule)newRule;

            ruleInterface.Execute(ruleContext);
            Assert.IsTrue(ruleContext.Results.Count == 0);
        }
开发者ID:rbocobo,项目名称:MagenicMasters.Csla,代码行数:32,代码来源:MinHourDifferenceRuleTest.cs

示例4: OnItemAdded

        public void OnItemAdded(object sender, EventArgs args)
        {
            var addedItem = ExtractItem(args);

            if (addedItem == null)
            {
                return;
            }

            var rulesFolderId = ID.Parse(ItemAddedRulesConstants.ItemAddedRules.ItemId);
            var itemAddedRules = addedItem.Database.GetItem(rulesFolderId);

            if (itemAddedRules == null)
            {
                return;
            }

            var ruleContext = new RuleContext();
            ruleContext.Item = addedItem;

            RuleList<RuleContext> rules = RuleFactory.GetRules<RuleContext>(itemAddedRules, "Rule");

            if (rules.Count > 0)
            {
                rules.Run(ruleContext);
            }
        }
开发者ID:BDFurlong,项目名称:AddChildItemRule,代码行数:27,代码来源:ItemAddedRulesHandler.cs

示例5: Render

        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var contextChunks = context.CustomData as List<Item>;
            if (contextChunks != null)
            {
                var chunk = contextChunks[0];
                contextChunks.RemoveAt(0);
                var psButtons = chunk.Children;
                var contextItem = context.Items.Length > 0 ? context.Items[0] : null;

                var ruleContext = new RuleContext
                {
                    Item = contextItem
                };
                foreach (var parameter in context.Parameters.AllKeys)
                {
                    ruleContext.Parameters[parameter] = context.Parameters[parameter];
                }

                foreach (Item psButton in psButtons)
                {
                    if (!RulesUtils.EvaluateRules(psButton["ShowRule"], ruleContext))
                    {
                        continue;
                    }

                    RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
                        Translate.Text(psButton.DisplayName),
                        psButton["__Icon"], string.Empty,
                        $"ise:runplugin(scriptDb={psButton.Database.Name},scriptId={psButton.ID})",
                        context.Parameters["ScriptRunning"] == "0" && RulesUtils.EvaluateRules(psButton["EnableRule"], ruleContext),
                        false, context);
                }
            }
        }
开发者ID:GuitarRich,项目名称:Console,代码行数:35,代码来源:IsePluginPanel.cs

示例6: 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

示例7: Execute

 /// <summary>
 /// Calls inner rule if PrimaryProperty has value.
 /// </summary>
 /// <param name="context">Rule context object.</param>
 protected override void Execute(RuleContext context)
 {
   if (context.InputPropertyValues.ContainsKey(PrimaryProperty))
   {
     context.ExecuteRule(InnerRule);
   }
 }
开发者ID:Jaans,项目名称:csla,代码行数:11,代码来源:FieldExists.cs

示例8: Execute

 /// <summary>
 /// Business or validation rule implementation.
 /// </summary>
 /// <param name="context">Rule context object.</param>
 protected override void Execute(RuleContext context)
 {
     if (string.IsNullOrWhiteSpace((string)context.InputPropertyValues[PrimaryProperty]) && (((SummaryTypes)context.InputPropertyValues[InputProperties[2]]) != SummaryTypes.Count))
     {
         context.AddErrorResult(ProcessMetricEdit.MetricFieldSystemNameRuleHighlightProperty, LanguageService.Translate("Rule_MetricFieldIsRequired"));
     }
 }
开发者ID:mparsin,项目名称:Elements,代码行数:11,代码来源:MetricFieldIsRequiredRule.cs

示例9: Run

        /// <summary>
        /// Runs the specified context.
        /// </summary>
        /// <param name="context">The rule context.</param>
        public override void Run(RuleContext context)
        {
            context.Message = ErrorMessage;
            context.Success = true;

            if (!CanRun(context.TrackedObject))
                return;

            object value = GetPropertyValue(context.TrackedObject.Current);

            if (value is string && value != null)
            {
                context.Success = ((string)value).Trim().Length > 0;
            }
            else if (value is Guid)
            {
                context.Success = (Guid)value != Guid.Empty;
            }
            else if (value is DateTime)
            {
                context.Success = (DateTime)value > (DateTime)SqlDateTime.MinValue;
            }
            else
            {
                context.Success = value != null;
            }
        }
开发者ID:mattfrerichs,项目名称:Templates,代码行数:31,代码来源:RequiredRule.cs

示例10: 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

示例11: 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

示例12: Apply

		/// <summary>
		/// Applies the specified context.
		/// </summary>
		/// <param name="context">The context.</param>
		/// <returns></returns>
		public RuleFlagProcessorResponse Apply(RuleContext context)
		{
			Manager.SetServerVariable(context.HttpContext, Name, Value, Replace);

			Manager.LogIf(context.LogLevel >= 2, "Set Server Variable: " + Name, "Rewrite");
			return RuleFlagProcessorResponse.ContinueToNextFlag;
		}
开发者ID:jsakamoto,项目名称:managedfusion-rewriter,代码行数:12,代码来源:ServerVariableFlag.cs

示例13: Render

        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var typeName = context.Parameters["type"];
            var viewName = context.Parameters["viewName"];
            var ruleContext = new RuleContext
            {
                Item = context.CustomData as Item
            };
            ruleContext.Parameters["ViewName"] = viewName;

            if (!string.IsNullOrEmpty(typeName))
            {
                foreach (
                    Item scriptItem in
                        ModuleManager.GetFeatureRoots(IntegrationPoints.ListViewRibbonFeature)
                            .Select(parent => parent.Paths.GetSubItem(typeName))
                            .Where(scriptLibrary => scriptLibrary != null)
                            .SelectMany(scriptLibrary => scriptLibrary.Children,
                                (scriptLibrary, scriptItem) => new {scriptLibrary, scriptItem})
                            .Where(
                                @t => RulesUtils.EvaluateRules(@t.scriptItem["ShowRule"], ruleContext)
                                )
                            .Select(@t => @t.scriptItem))
                {
                    RenderSmallButton(output, ribbon, Control.GetUniqueID("export"),
                        Translate.Text(scriptItem.DisplayName),
                        scriptItem["__Icon"], string.Empty,
                        string.Format("listview:action(scriptDb={0},scriptID={1})", scriptItem.Database.Name,
                            scriptItem.ID),
                        RulesUtils.EvaluateRules(scriptItem["EnableRule"], ruleContext) &&
                        context.Parameters["ScriptRunning"] == "0",
                        false);
                }
            }
        }
开发者ID:ostat,项目名称:Console,代码行数:35,代码来源:RibbonActionScriptsPanel.cs

示例14: 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

示例15: Execute

        /// <summary>
        /// Rule implementation.
        /// </summary>
        /// <param name="context">Rule context.</param>
        protected override void Execute(RuleContext context)
        {
            var value = (string) context.InputPropertyValues[PrimaryProperty];

            if (MaxCharsPerLineProperty != null)
            {
                MaxCharsPerLine = (int) context.InputPropertyValues[MaxCharsPerLineProperty];
            }

            if (value != null)
            {
                string[] valueArray = value.Split(new string[1] {Environment.NewLine}, StringSplitOptions.None);

                bool maxExceeded = false;
                if (valueArray != null)
                {
                    foreach (string line in valueArray)
                    {
                        if (line.Length > MaxCharsPerLine)
                        {
                            maxExceeded = true;
                            break;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(value) && (maxExceeded))
                {
                    string message = string.Format(ResourcesValidation.StringMaxCharsPerLine,
                        PrimaryProperty.FriendlyName, MaxCharsPerLine.ToString());
                    context.Results.Add(new RuleResult(RuleName, PrimaryProperty, message) {Severity = Severity});
                }
            }
        }
开发者ID:nttung91,项目名称:PLSoft,代码行数:38,代码来源:StringMaxCharsPerLine.cs


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