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


C# RuleContext.Complete方法代码示例

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


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

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

示例2: Execute

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

示例3: Execute

 /// <summary>
 /// Execute the business rule.
 /// </summary>
 /// <param name="context">
 /// The rule context.
 /// </param>
 protected override sealed async void Execute(RuleContext context)
 {
     try
     {
         await ExecuteAsync(context);
     }
     finally
     {
         if (IsAsync)
             context.Complete();
     }
 }
开发者ID:mparsin,项目名称:Elements,代码行数:18,代码来源:AsyncRule.cs

示例4: 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();
#elif SILVERLIGHT
        RoleList.GetList((o, e) =>
          {
            if (!e.Object.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:Jaans,项目名称:csla,代码行数:21,代码来源:ValidRole.cs

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

示例6: Execute

    /// <summary>
    /// The execute.
    /// </summary>
    /// <param name="context">
    /// The context.
    /// </param>
    protected override void Execute(RuleContext context)
    {
      var id = (int) context.InputPropertyValues[PrimaryProperty];

      // uses the async methods in DataPortal to perform data access on a background thread. 
      LookupCustomerCommand.BeginExecute(id, (o, e) =>
                                               {
                                                 if (e.Error != null)
                                                 {
                                                   context.AddErrorResult(e.Error.ToString());
                                                 }
                                                 else
                                                 {
                                                   context.AddOutValue(NameProperty, e.Object.Name);
                                                 }

                                                 context.Complete();
                                               });
    }
开发者ID:BiYiTuan,项目名称:csla,代码行数:25,代码来源:AsyncLookupCustomer.cs

示例7: RunRules

    /// <summary>
    /// Runs the enumerable list of rules.
    /// </summary>
    /// <param name="rules">The rules.</param>
    /// <param name="cascade">if set to <c>true</c> cascade.</param>
    /// <param name="executionContext">The execution context.</param>
    /// <returns></returns>
    private RunRulesResult RunRules(IEnumerable<IBusinessRule> rules, bool cascade, RuleContextModes executionContext)
    {
      var affectedProperties = new List<string>();
      var dirtyProperties = new List<string>();
      bool anyRuleBroken = false;
      foreach (var rule in rules)
      {
        // implicit short-circuiting
        if (anyRuleBroken && rule.Priority > ProcessThroughPriority)
          break;
        bool complete = false;
        // set up context
        var context = new RuleContext((r) =>
        {
          if (r.Rule.IsAsync)
          {
            lock (SyncRoot)
            {
              // update output values
              if (r.OutputPropertyValues != null)
                foreach (var item in r.OutputPropertyValues)
                {
                  // value is changed add to dirtyValues
                  if (((IManageProperties) _target).LoadPropertyMarkDirty(item.Key, item.Value))
                    r.AddDirtyProperty(item.Key);
                }
              // update broken rules list
              BrokenRules.SetBrokenRules(r.Results, r.OriginPropertyName);

              // run rules on affected properties for this async rule
              var affected = new List<string>();
              if (cascade)
                foreach (var item in r.Rule.AffectedProperties.Distinct())
                  if (!ReferenceEquals(r.Rule.PrimaryProperty, item))
                  {
                    var doCascade = false;
                    if (CascadeOnDirtyProperties && (r.DirtyProperties != null))
                       doCascade = r.DirtyProperties.Any(p => p.Name == item.Name);
                    affected.AddRange(CheckRulesForProperty(item, doCascade, r.ExecuteContext | RuleContextModes.AsAffectedPoperty));
                  }

              // mark each property as not busy
              foreach (var item in r.Rule.AffectedProperties)
              {
                BusyProperties.Remove(item);
                _isBusy = BusyProperties.Count > 0;
                if (!BusyProperties.Contains(item))
                  _target.RuleComplete(item);
              }

              foreach (var property in affected.Distinct())
              {
                // property is not in AffectedProperties (already signalled to UI)
                if (!r.Rule.AffectedProperties.Any(p => p.Name == property)) 
                  _target.RuleComplete(property);
              }

              if (!RunningRules && !RunningAsyncRules)
                _target.AllRulesComplete();
            }
          }
          else  // Rule is Sync 
          {
            // update output values
            if (r.OutputPropertyValues != null)
              foreach (var item in r.OutputPropertyValues)
              {
                // value is changed add to dirtyValues
                if (((IManageProperties)_target).LoadPropertyMarkDirty(item.Key, item.Value))
                  r.AddDirtyProperty(item.Key);
              }

            // update broken rules list
            if (r.Results != null)
            {
              BrokenRules.SetBrokenRules(r.Results, r.OriginPropertyName);

              // is any rules here broken with severity Error
              if (r.Results.Any(p => !p.Success && p.Severity == RuleSeverity.Error))
                anyRuleBroken = true;
            }

            complete = true;
          }
        });
        context.Rule = rule;
        if (rule.PrimaryProperty != null)
          context.OriginPropertyName = rule.PrimaryProperty.Name;
        context.ExecuteContext = executionContext;
        if (!rule.IsAsync || rule.ProvideTargetWhenAsync)
          context.Target = _target;

        // get input properties
//.........这里部分代码省略.........
开发者ID:Jaans,项目名称:csla,代码行数:101,代码来源:BusinessRules.cs

示例8: EndValidation

        /// <summary>
        /// Ends the validation.
        /// </summary>
        /// <param name="context">The context.</param>
        private void EndValidation(RuleContext context)
        {
            lock (_syncRoot)
            {
                if (context.Target == null)
                {
                    context.Complete();
                    return;
                }

                var validationContext = _validationContexts[context.Target];
                validationContext.CompletedValidations.Add(context);

                while (validationContext.ValidationsQueue.Count > 0
                       && validationContext.CompletedValidations.Contains(validationContext.ValidationsQueue.Peek()))
                {
                    var ruleContext = validationContext.ValidationsQueue.Dequeue();
                    validationContext.CompletedValidations.Remove(ruleContext);

                    ruleContext.Complete();
                }

                if (validationContext.ValidationsQueue.Count == 0)
                    _validationContexts.Remove(context.Target);
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:30,代码来源:AsyncBusinessRule.cs

示例9: 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;

            try
            {
                var checklist = ((IEditableBusinessObject)context.Target).GetParent<ChecklistEdit>();
                if (checklist == null) return;  //run only for answer process

                var result = (double?)context.InputPropertyValues[_resultProperty];
                if (!result.HasValue) return;

                var resultList = context.InputPropertyValues[_resultListProperty] as MobileObservableCollection<ChoiceInfo>;
                if (resultList == null) return;

                var selectedChoice = resultList.FirstOrDefault(x => x.Score == result.Value);
                if (selectedChoice == null) return;

                if (selectedChoice.IsNewItemRequired && selectedChoice.NewItemProcessId == 0)
                    context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.InvariantCulture, LanguageService.Translate("Error_NewItemProcessRequired"), selectedChoice.Choice));

                if (selectedChoice.IsCommentRequired)
                {
                    if (!string.IsNullOrEmpty(checklist.CommentsFieldSystemName))
                    {
                        var commentProperty = ((IDynamicObject)context.Target).GetPropertyByName(checklist.CommentsFieldSystemName);
                        var comment = commentProperty.GetValue(context.Target, null) as string;

                        if (string.IsNullOrEmpty(comment))
                        {
                            var display = (from d in commentProperty.GetCustomAttributes(typeof(DisplayAttribute), false) select d).FirstOrDefault() as DisplayAttribute;
                            var fieldName = display == null ? commentProperty.Name : display.GetName();
                            context.AddErrorResult(PrimaryProperty, string.Format(CultureInfo.InvariantCulture, LanguageService.Translate("Error_CommentRequiredForChoice"), fieldName, selectedChoice.Choice));
                        }
                    }
                }
            }
            finally
            {
                context.Complete();
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:46,代码来源:ResultFieldValidationRule.cs


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