/// <summary>
        ///     Internal Method for Evaluate
        /// </summary>
        protected override void EvaluateInternal()
        {
            // Initialized all rules. Instancing only takes place during execution, since otherwise the service scope has not yet been assigned
            Context.Rules = new RulesBundle(Context, this);
            Context.PostingAccountRepository  = ServiceProvider.GetService <IRepository <Olma.PostingAccount> >();
            Context.LoadCarrierRepository     = ServiceProvider.GetService <IRepository <Olma.LoadCarrier> >();
            Context.LmsAvail2deliRepository   = ServiceProvider.GetService <IRepository <LmsAvail2deli> >();
            Context.LmsQuali2palletRepository = ServiceProvider.GetService <IRepository <LmsQuali2pallet> >();
            Context.Mapper = ServiceProvider.GetService <IMapper>();

            // Initialized Evaluator
            var rulesEvaluator = RulesEvaluator.Create().StopEvaluateOnFirstInvalidRule();

            // Assign rules to the Evaluator
            // Not things to validate

            // Evaluate
            var ruleResult = rulesEvaluator.Evaluate();

            Context.ExpressCode = Context.ExpressCodeResult;

            if (Context.ExpressCode == null)
            {
                RuleState.Add(ResourceName,
                              new RuleState(Context.ExpressCode)
                {
                    RuleStateItems = { new DigitalCodeInvalid() }
                });
            }

            AddMessage(!ruleResult.IsSuccess, ResourceName, Message);
            MergeFromResult(ruleResult);
        }
Exemple #2
0
 internal static DlpPolicyState RuleStateToDlpState(RuleState state, RuleMode mode)
 {
     if (state == RuleState.Disabled && mode == RuleMode.Audit)
     {
         return(DlpPolicyState.Disabled_Audit);
     }
     if (state == RuleState.Disabled && mode == RuleMode.AuditAndNotify)
     {
         return(DlpPolicyState.Disabled_AuditAndNotify);
     }
     if (state == RuleState.Disabled && mode == RuleMode.Enforce)
     {
         return(DlpPolicyState.Disabled_Enforce);
     }
     if (state == RuleState.Enabled && mode == RuleMode.Audit)
     {
         return(DlpPolicyState.Enabled_Audit);
     }
     if (state == RuleState.Enabled && mode == RuleMode.AuditAndNotify)
     {
         return(DlpPolicyState.Enabled_AuditAndNotify);
     }
     if (state == RuleState.Enabled && mode == RuleMode.Enforce)
     {
         return(DlpPolicyState.Enabled_Enforce);
     }
     return(DlpPolicyState.Disabled_Audit);
 }
Exemple #3
0
        /// <summary>
        ///     Internal Method for Evaluate
        /// </summary>
        protected override void EvaluateInternal()
        {
            // Initialized all rules. Instancing only takes place during execution, since otherwise the service scope has not yet been assigned
            Context.Rules = new RulesBundle(Context, this);

            var mapper = ServiceProvider.GetService <IMapper>();

            var permissionResource = mapper.Map <TPermissionResource>(Context.Resource);

            if (permissionResource == null)
            {
                RuleState.AddMessage(ResourceName, Message);
                return;
            }

            try
            {
                var result = Check(permissionResource);
                AddMessage(!result.Result.Succeeded, ResourceName, Message);
            }
            catch (Exception exception)
            {
                RuleState.AddMessage(ResourceName, Message);
            }
        }
        public override void Evaluate()
        {
            if (Context == null)
            {
                return;
            }
            var contextType = Context.GetType();

            var properties = contextType.GetProperties();

            var requiredAttributes = properties.ToDictionary(
                p => p.Name,
                p => p.GetCustomAttributes(typeof(RequiredAttribute), false).OfType <RequiredAttribute>());

            var filter = requiredAttributes.Where(p => p.Value.Any());

            foreach (var(key, value) in filter)
            {
                var attr = value.FirstOrDefault();
                if (attr == null)
                {
                    continue;
                }

                RuleState.AddMessage(!attr.IsValid(Context), $"{contextType.Name}_{key}, " + "_", Message);
            }
        }
Exemple #5
0
        public ExpressionCallRule(LambdaExpression callSpecification)
        {
            Guard.IsNotNull(callSpecification, "callSpecification");

            this.Expression = callSpecification.Body;

            this.state = CreateRuleState(callSpecification);
        }
Exemple #6
0
 public void StopFinalize()
 {
     this.execState = null;
     if (string.IsNullOrEmpty(Word))
     {
         return;
     }
     strip = new Strip(Word, BlankMarker);
     //History.Clear();
 }
Exemple #7
0
 public PolicyNudgeRule(string etrXml, string id, DateTime version, RuleState state, DateTime?activationDate, DateTime?expiryDate)
 {
     this.etrXml         = etrXml;
     this.ID             = id;
     this.Version        = version;
     this.state          = state;
     this.activationDate = activationDate;
     this.expiryDate     = expiryDate;
     this.IsPnrXmlValid  = true;
 }
Exemple #8
0
        RuleState[] DefaultItems(char marker)
        {
            var defItems = new RuleState[_columns];

            for (int i = 0; i < _columns; i++)
            {
                defItems[i] = new RuleState(i, marker, DefaultState);
            }
            return(defItems);
        }
Exemple #9
0
 public void Restore(RuleState state)
 {
     if (state != null)
     {
         BackgroundColor = state.Background;
         BorderColor = state.Border;
         IsChecked = IsEnabled ? state.Checked : true; // If rule is disabled, it's always checked.
         TextColor = state.Text;
     }
 }
Exemple #10
0
 public void Restore(RuleState state)
 {
     if (state != null)
     {
         BackgroundColor = state.Background;
         BorderColor     = state.Border;
         IsChecked       = IsEnabled ? state.Checked : true; // If rule is disabled, it's always checked.
         TextColor       = state.Text;
     }
 }
Exemple #11
0
        /// <summary>
        /// Remove RuleState for key
        /// </summary>
        /// <param name="messageId">Search for</param>
        /// <param name="key">Remove RuleStateDictionary Key</param>
        private void CleanupRuleStateIfExists(string messageId, string key)
        {
            var drop = RuleState.Any(rs =>
                                     rs.Value.Any(item => item.MessageId == messageId));

            if (drop)
            {
                RuleState.Remove(key);
            }
        }
 protected override void EvaluateInternal()
 {
     if (Context.ExpressCode == null || Context.ExpressCode.IsCanceled)
     {
         RuleState.Add(ResourceName, new RuleState(Context.ExpressCode)
         {
             RuleStateItems = { Message }
         });
     }
 }
Exemple #13
0
 public void ForwardChain()
 {
     while (progress && !completed)
     {
         if (facts.Contains(result))
         {
             completed = true;
             Console.WriteLine("\t\tTikslas gautas.");
             Console.WriteLine();
             break;
         }
         progress = false;
         Console.WriteLine();
         Console.WriteLine("\t" + iteration + " ITERACIJA");
         foreach (var rule in rules)
         {
             if (rule.flag == Rule.Flag.flag1)
             {
                 state = RuleState.Flag1;
             }
             else if (rule.flag == Rule.Flag.flag2)
             {
                 state = RuleState.SkipRaiseFlag2;
             }
             else
             {
                 if (facts.Contains(rule.result))
                 {
                     state     = RuleState.Flag2;
                     rule.flag = Rule.Flag.flag2;
                 }
                 else
                 {
                     if (rule.requirements.All(element => facts.Contains(element)))
                     {
                         state = RuleState.UseRaiseFlag1;
                         facts.Add(rule.result);
                         newFacts.Add(rule.result);
                         usedRules.Add(rule);
                         rule.flag = Rule.Flag.flag1;
                         PrintExecution(rule);
                         progress = true;
                         break;
                     }
                     else
                     {
                         state = RuleState.SkipNoFact;
                     }
                 }
             }
             PrintExecution(rule);
         }
         iteration++;
     }
 }
 protected override void EvaluateInternal()
 {
     if (Context.Parent.OrderGroupsCreateRequest.QuantityType == OrderQuantityType.Load &&
         (Context.Parent.OrderGroupsCreateRequest.NumberOfLoads < MinNumberOfLoads ||
          Context.Parent.OrderGroupsCreateRequest.NumberOfLoads > MaxNumberOfLoads))
     {
         RuleState.Add(ResourceName, new RuleState {
             RuleStateItems = { Message }
         });
     }
 }
Exemple #15
0
        public override void Evaluate()
        {
            if (!_rules.Any())
            {
                return;
            }

            var valid = _rules.All(r => r.IsValid());

            RuleState.AddMessage(!valid, ResourceName, new NotAllowedByRule());
        }
Exemple #16
0
            public RuleOperation Call(IRuleRef rule, TokenStreamIndex index, out CoroutineResult <RuleResult> result)
            {
                var state = new RuleState <TNode>(rule, index, this, _parser._ruleStack.Peek());

                result = state.Result;

                return(() =>
                {
                    DebugHooks.OnBeforeCall(state, rule, index);
                    _parser._ruleStack.Push(state);
                });
            }
Exemple #17
0
        public override void Evaluate()
        {
            var invalidState = OrderGroup.Orders == null || OrderGroup.Orders.Count == 0;

            if (invalidState)
            {
                RuleState.Add("OrderGroup", new RuleState(OrderGroup)
                {
                    RuleStateItems = { new OrderGroupHasOrders() }
                });
            }
        }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the AlertsSuppressionRule class.
 /// </summary>
 /// <param name="alertType">Type of the alert to automatically
 /// suppress. For all alert types, use '*'</param>
 /// <param name="reason">The reason for dismissing the alert</param>
 /// <param name="state">Possible states of the rule. Possible values
 /// include: 'Enabled', 'Disabled', 'Expired'</param>
 /// <param name="id">Resource Id</param>
 /// <param name="name">Resource name</param>
 /// <param name="type">Resource type</param>
 /// <param name="lastModifiedUtc">The last time this rule was
 /// modified</param>
 /// <param name="expirationDateUtc">Expiration date of the rule, if
 /// value is not provided or provided as null this field will default
 /// to the maximum allowed expiration date.</param>
 /// <param name="comment">Any comment regarding the rule</param>
 /// <param name="suppressionAlertsScope">The suppression
 /// conditions</param>
 public AlertsSuppressionRule(string alertType, string reason, RuleState state, string id = default(string), string name = default(string), string type = default(string), System.DateTime?lastModifiedUtc = default(System.DateTime?), System.DateTime?expirationDateUtc = default(System.DateTime?), string comment = default(string), SuppressionAlertsScope suppressionAlertsScope = default(SuppressionAlertsScope))
     : base(id, name, type)
 {
     AlertType              = alertType;
     LastModifiedUtc        = lastModifiedUtc;
     ExpirationDateUtc      = expirationDateUtc;
     Reason                 = reason;
     State                  = state;
     Comment                = comment;
     SuppressionAlertsScope = suppressionAlertsScope;
     CustomInit();
 }
Exemple #19
0
 private void RemoveMixedMode()
 {
     if (mixedModeTuple != null)
     {
         if (RuleState.Contains(mixedModeTuple))
         {
             RuleState.Remove(mixedModeTuple);
             mixedModeTuple = null;
             base.RaisePropertyChanged("Index");
         }
     }
 }
Exemple #20
0
 private void AddMixedMode()
 {
     if (!RuleState.Contains(mixedModeTuple))
     {
         var image = PresentationResourceService.GetBitmapSource("Icons.16x16.ClosedFolderBitmap");
         mixedModeTuple = Tuple.Create <ImageSource, string>(image,
                                                             StringParser.Parse("${res:ICSharpCode.CodeAnalysis.ProjectOptions.WarningErrorMixed}"));
         RuleState.Add(mixedModeTuple);
         Index = RuleState.Count - 1;
         base.RaisePropertyChanged("Index");
     }
 }
Exemple #21
0
 private StateMachine.RuleStateEventArgs InitState()
 {
     try
     {
         return(new StateMachine.RuleStateEventArgs(execState = Table.Where(x =>
                                                                            x.Q == 0 && x.Marker == strip[SelectedCell]).First())
         {
             State = StateMachine.RuleStateEventArgs.OnState.NewState
         });
     }
     catch (InvalidOperationException) {
         throw;
     }
 }
        internal static string ToSerializedValue(this RuleState value)
        {
            switch (value)
            {
            case RuleState.Enabled:
                return("Enabled");

            case RuleState.Disabled:
                return("Disabled");

            case RuleState.Expired:
                return("Expired");
            }
            return(null);
        }
        protected override void EvaluateInternal()
        {
            if (Context.LoadCarrierId == 0)
            {
                RuleState.Add(ResourceName, new RuleState {
                    RuleStateItems = { new LoadCarrierRequired() }
                });
                return;
            }

            var loadCarrierRepository = ServiceProvider.GetService <IRepository <Olma.LoadCarrier> >();
            var loadCarrierExists     = loadCarrierRepository.FindAll().Any(lc => lc.Id == Context.LoadCarrierId);

            AddMessage(!loadCarrierExists, ResourceName, Message);
        }
Exemple #24
0
        private StateMachine.RuleStateEventArgs Undo(RuleState state)
        {
            var t = Table.Where(x =>
                                x.Q == state.Q &&
                                x.Marker == state.Marker).First();

            if (t.Previous != null)
            {
                t.ReferenceState = t.GetUndo();
            }
            return(new StateMachine.RuleStateEventArgs(t)
            {
                State = StateMachine.RuleStateEventArgs.OnState.Undo
            });
        }
        /// <summary>
        /// Internal Method for Evaluate
        /// </summary>
        protected override void EvaluateInternal()
        {
            // Initialized all rules. Instancing only takes place during execution, since otherwise the service scope has not yet been assigned
            Context.Rules    = new RulesBundle(Context, this);
            Context.AuthData = ServiceProvider.GetService <IAuthorizationDataService>();

            // Initialized Evaluator
            var rulesEvaluator = RulesEvaluator.Create().StopEvaluateOnFirstInvalidRule();

            // Assign rules to the Evaluator
            rulesEvaluator
            .Eval(Context.Rules.ExpressCodeAuthorizationRule);

            //Check issuer
            var customerIds = Context.AuthData.GetCustomerIds().ToList();
            var divisionIds = Context.AuthData.GetDivisionIds().ToList();

            if (customerIds.Count > 0 && Context.ExpressCode.IssuingCustomerId != null && !customerIds.Contains((int)Context.ExpressCode.IssuingCustomerId))
            {
                RuleState.Add(ResourceName, new RuleState(Context.ExpressCode)
                {
                    RuleStateItems = { new DigitalCodeIssuingCustomerDoesNotMatch() }
                });
            }

            if (divisionIds.Count > 0 && Context.ExpressCode.IssuingDivisionId != null && !divisionIds.Contains((int)Context.ExpressCode.IssuingDivisionId))
            {
                RuleState.Add(ResourceName, new RuleState(Context.ExpressCode)
                {
                    RuleStateItems = { new DigitalCodeIssuingDivisionDoesNotMatch() }
                });
            }

            if (Context.ExpressCode.ValidTo.HasValue && Context.ExpressCode.ValidTo < DateTime.Today)
            {
                RuleState.Add(ResourceName, new RuleState(Context.ExpressCode)
                {
                    RuleStateItems = { new DigitalCodeExpired() }
                });
            }
            //TODO: implement generic ExpiredRule

            // Evaluate
            var ruleResult = rulesEvaluator.Evaluate();

            AddMessage(!ruleResult.IsSuccess, ResourceName, Message);
            MergeFromResult(ruleResult);
        }
Exemple #26
0
        private void RuleInput_KeyUp(object sender, KeyEventArgs e)
        {
            var t = RuleInput.Text;

            try
            {
                var       bk = ((RuleState)GetValue(CurrentRuleStateProperty)).Clone();
                RuleState rs = (RuleState)GetValue(CurrentRuleStateProperty);

                rs.ReferenceState = State.ConvUserInputString(t);
                SetValue(CurrentRuleStateProperty, rs);
                RuleStateChange(this, new DependencyPropertyChangedEventArgs
                                    (CurrentRuleStateProperty, bk, rs));
            }
            catch (FormatException) { }
        }
        protected override void EvaluateInternal()
        {
            if (Context.PostingAccountId == 0)
            {
                RuleState.Add(ResourceName, new RuleState {
                    RuleStateItems = { new PostingAccountRequired() }
                });
                return;
            }

            var postingAccountRepository = ServiceProvider.GetService <IRepository <Olma.PostingAccount> >();
            var postingAccountExists     = postingAccountRepository.FindAll()
                                           .Any(pa => pa.Id == Context.PostingAccountId);

            AddMessage(!postingAccountExists, ResourceName, Message);
        }
        public static PSRuleState ConvertToPSType(this RuleState value)
        {
            switch (value)
            {
            case RuleState.Enabled:
                return(PSRuleState.Enabled);

            case RuleState.Disabled:
                return(PSRuleState.Disabled);

            case RuleState.Expired:
                return(PSRuleState.Expired);

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }
        }
Exemple #29
0
        protected void UpdateRules(RuleState state, RuleMode mode)
        {
            bool flag = this.taskObject.TargetItem.IsModified(ADObjectSchema.Name);
            ADRuleStorageManager adruleStorageManager;
            IEnumerable <TransportRuleHandle> transportRuleHandles = DlpUtils.GetTransportRuleHandles(base.DataSession, out adruleStorageManager);

            foreach (TransportRule transportRule in (from handle in transportRuleHandles
                                                     select handle.Rule).Where(new Func <TransportRule, bool>(this.RuleDlpPolicyIdMatches)))
            {
                transportRule.Enabled = state;
                transportRule.Mode    = mode;
                if (flag)
                {
                    transportRule.SetDlpPolicy(this.taskObject.TargetItem.ImmutableId, this.taskObject.TargetItem.Name);
                }
            }
            adruleStorageManager.UpdateRuleHandles(transportRuleHandles);
        }
Exemple #30
0
        internal void SelectCurrent(RuleState stateObject)
        {
            if (stateObject == null)
            {
                return;
            }
            CellControl rb = (CellControl)
                             ClearSelections().Where(x =>
            {
                var t = (((CellControl)x).CurrentRuleState);
                return(t.ReferenceState.Equals(stateObject.ReferenceState) &&
                       t.Marker == stateObject.Marker && t.Q == stateObject.Q);
            }).FirstOrDefault();

            if (rb != null)
            {
                rb.SetValue(BackgroundProperty, new SolidColorBrush(Colors.Green));
            }
        }
Exemple #31
0
        /// <summary>
        /// Internal Method for Evaluate
        /// </summary>
        protected override void EvaluateInternal()
        {
            // Initialized all rules. Instancing only takes place during execution, since otherwise the service scope has not yet been assigned
            Context.Rules = new RulesBundle(Context, this);
            var loadCarrierRepository = ServiceProvider.GetService <IRepository <Olma.LoadCarrier> >();

            Olma.LoadCarrier loadCarrier = loadCarrierRepository
                                           .FindByCondition(lc => lc.Id == Context.Request.LoadCarrierId)
                                           .Include(lct => lct.Type).ThenInclude(blc => blc.BaseLoadCarrierMappings).FirstOrDefault();
            if (loadCarrier == null)
            {
                return;
            }

            switch (loadCarrier.Type.BaseLoadCarrier)
            {
            case BaseLoadCarrierInfo.None when Context.Request.BaseLoadCarrierId != null:
                RuleState.Add(ResourceName, new RuleState {
                    RuleStateItems = { Message }
                });
                break;

            case BaseLoadCarrierInfo.Required when Context.Request.BaseLoadCarrierId == null:
                RuleState.Add(ResourceName, new RuleState {
                    RuleStateItems = { new BaseLoadCarrierRequired() }
                });
                break;

            default:
            {
                if (loadCarrier.Type.BaseLoadCarrier != BaseLoadCarrierInfo.None &&
                    Context.Request.BaseLoadCarrierId != null && loadCarrier.Type.BaseLoadCarrierMappings.All(blc =>
                                                                                                              blc.LoadCarrierId != Context.Request.BaseLoadCarrierId))
                {
                    RuleState.Add(ResourceName, new RuleState {
                            RuleStateItems = { new BaseLoadCarrierError() }
                        });
                }
                break;
            }
            }
        }
Exemple #32
0
 public RuleOverview(string name, RuleState state)
 {
     _name = name;
     _state = state;
 }
        /// <summary>
        /// Generate RuleData from ptf config base on different action Type.
        /// </summary>
        /// <param name="actionType">ActionType of each blocks, the sequence must be the same as the actionData array.</param>
        /// <param name="ruleSequence">Rule sequence in PidTagRuleSequence of the RuleData.</param>
        /// <param name="ruleState">Specifies value of PidTagRuleState of the RuleData.</param>
        /// <param name="actionData">The actionData array needed to construct the ActionBlock in RuleActions.</param>
        /// <param name="actionFlavor">The actionFlavor array of the rule ActionBlocks.</param>
        /// <param name="otherInfo">
        /// An array of Other needed information of Actions.
        /// Index may be from 0-4
        /// 0. Rule name
        /// 1. Rule provider
        /// 2. Rule user Flags
        /// 3. Rule provider data
        /// 4. Subject name of content restriction
        /// </param>
        /// <returns>A valid RuleData structure.</returns>
        public static RuleData GenerateValidRuleDataWithFlavor(ActionType[] actionType, int ruleSequence, RuleState ruleState, IActionData[] actionData, uint[] actionFlavor, RuleProperties otherInfo)
        {
            RuleData ruleData = new RuleData
            {
                RuleDataFlags = (byte)TestRuleDataType.ForAdd
            };

            List<TaggedPropertyValue> propertyList = new List<TaggedPropertyValue>();
            TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue();
            PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagRuleSequence,
                PropertyType = (ushort)PropertyType.PtypInteger32
            };
            pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag;
            pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence);
            propertyList.Add(pidTagRuleSequence);

            TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue();
            PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagRuleLevel,
                PropertyType = (ushort)PropertyType.PtypInteger32
            };
            pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag;
            pidTagRuleLevel.Value = BitConverter.GetBytes(Constants.RuleLevel);
            propertyList.Add(pidTagRuleLevel);

            TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue();
            PropertyTag pidTagRuleStatePropertyTag = new PropertyTag
            {
                PropertyId = (ushort)PropertyId.PidTagRuleState,
                PropertyType = (ushort)PropertyType.PtypInteger32
            };
            pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag;
            pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState);
            propertyList.Add(pidTagRuleState);

            if (otherInfo.Name.Length > 0)
            {
                TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue();
                PropertyTag pidTagRuleNamePropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleName,
                    PropertyType = (ushort)PropertyType.PtypString
                };
                pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag;
                pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)otherInfo.Name + "\0");
                propertyList.Add(pidTagRuleName);
            }

            if (otherInfo.Provider.Length > 0)
            {
                TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue();
                PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleProvider,
                    PropertyType = (ushort)PropertyType.PtypString
                };
                pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag;
                pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)otherInfo.Provider + "\0");
                propertyList.Add(pidTagRuleProvider);
            }

            if (otherInfo.UserFlag.Length > 0)
            {
                TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue();
                PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleUserFlags,
                    PropertyType = (ushort)PropertyType.PtypInteger32
                };
                pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag;
                pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(otherInfo.UserFlag));
                propertyList.Add(pidTagRuleUserFlags);
            }

            if (otherInfo.ProviderData.Length > 0)
            {
                TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue();
                PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleProviderData,
                    PropertyType = (ushort)PropertyType.PtypBinary
                };
                pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag;
                pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(otherInfo.ProviderData);
                pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value);
                propertyList.Add(pidTagRuleProviderData);
            }

            if (otherInfo.ConditionSubjectName.Length > 0)
            {
                AddRuleCondition(propertyList, otherInfo.ConditionSubjectName);

                uint[] defaultActionFlags = new uint[actionData.Length];
                for (int i = 0; i < actionData.Length; i++)
                {
                    defaultActionFlags[i] = Constants.RuleActionFlags;
                }

                AddRuleAction(propertyList, actionType, actionData, actionFlavor, defaultActionFlags);
            }

            ruleData.PropertyValues = propertyList.ToArray();
            ruleData.PropertyValueCount = (ushort)propertyList.Count;
            return ruleData;
        }
        /// <summary>
        /// Generate RuleData from ptf config base on different action Type.
        /// </summary>
        /// <param name="actionType">ActionType in a rule.</param>
        /// <param name="ruleDataType">The type of the rule data.</param>
        /// <param name="ruleSequence">Rule sequence in PidTagRuleSequence of the RuleData.</param>
        /// <param name="ruleState">Specifies value of PidTagRuleState of the RuleData.</param>
        /// <param name="actionData">The actionData needed to construct the RuleData.</param>
        /// <param name="otherInfo">
        /// An array of Other needed information of Actions.
        /// Index may be from 0-4
        /// 0. Rule name
        /// 1. Rule provider
        /// 2. Rule user Flags
        /// 3. Rule provider data
        /// 4. Subject name of content restriction
        /// </param>
        /// <param name="ruleId">A 64-bit unsigned integer represents the rule.</param>
        /// <returns>A valid RuleData structure.</returns>
        public static RuleData GenerateValidRuleData(ActionType actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties otherInfo, ulong? ruleId)
        {
            RuleData ruleData = new RuleData
            {
                RuleDataFlags = (byte)ruleDataType
            };

            List<TaggedPropertyValue> propertyList = new List<TaggedPropertyValue>();
            if (ruleDataType == TestRuleDataType.ForModify || ruleDataType == TestRuleDataType.ForRemove)
            {
                TaggedPropertyValue pidTagRuleId = new TaggedPropertyValue();
                PropertyTag pidTagRuleIdPropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleId,
                    PropertyType = (ushort)PropertyType.PtypInteger64
                };
                pidTagRuleId.PropertyTag = pidTagRuleIdPropertyTag;
                pidTagRuleId.Value = BitConverter.GetBytes((ulong)ruleId);
                propertyList.Add(pidTagRuleId);
            }

            if (ruleDataType != TestRuleDataType.ForRemove)
            {
                TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue();
                PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleSequence,
                    PropertyType = (ushort)PropertyType.PtypInteger32
                };
                pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag;
                pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence);
                propertyList.Add(pidTagRuleSequence);

                TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue();
                PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleLevel,
                    PropertyType = (ushort)PropertyType.PtypInteger32
                };
                pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag;
                pidTagRuleLevel.Value = BitConverter.GetBytes(0);
                propertyList.Add(pidTagRuleLevel);

                TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue();
                PropertyTag pidTagRuleStatePropertyTag = new PropertyTag
                {
                    PropertyId = (ushort)PropertyId.PidTagRuleState,
                    PropertyType = (ushort)PropertyType.PtypInteger32
                };
                pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag;
                pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState);
                propertyList.Add(pidTagRuleState);

                if (otherInfo.Name.Length > 0)
                {
                    TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue();
                    PropertyTag pidTagRuleNamePropertyTag = new PropertyTag
                    {
                        PropertyId = (ushort)PropertyId.PidTagRuleName,
                        PropertyType = (ushort)PropertyType.PtypString
                    };
                    pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag;
                    pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)otherInfo.Name + "\0");
                    propertyList.Add(pidTagRuleName);
                }

                if (otherInfo.Provider.Length > 0)
                {
                    TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue();
                    PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag
                    {
                        PropertyId = (ushort)PropertyId.PidTagRuleProvider,
                        PropertyType = (ushort)PropertyType.PtypString
                    };
                    pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag;
                    pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)otherInfo.Provider + "\0");
                    propertyList.Add(pidTagRuleProvider);
                }

                if (otherInfo.UserFlag.Length > 0)
                {
                    TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue();
                    PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag
                    {
                        PropertyId = (ushort)PropertyId.PidTagRuleUserFlags,
                        PropertyType = (ushort)PropertyType.PtypInteger32
                    };
                    pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag;
                    pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(otherInfo.UserFlag));
                    propertyList.Add(pidTagRuleUserFlags);
                }

                if (otherInfo.ProviderData.Length > 0)
                {
                    TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue();
                    PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag
                    {
                        PropertyId = (ushort)PropertyId.PidTagRuleProviderData,
                        PropertyType = (ushort)PropertyType.PtypBinary
                    };
                    pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag;
                    pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(otherInfo.ProviderData);
                    pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value);
                    propertyList.Add(pidTagRuleProviderData);
                }

                if (otherInfo.ConditionSubjectName.Length > 0)
                {
                    AddRuleCondition(propertyList, otherInfo.ConditionSubjectName);
                    AddRuleAction(propertyList, actionType, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags);
                }
            }

            ruleData.PropertyValues = propertyList.ToArray();
            ruleData.PropertyValueCount = (ushort)propertyList.Count;
            return ruleData;
        }