Microsoft.Protocols.TestSuites.MS_OXORULE.AdapterHelper.GenerateValidRuleData C# (CSharp) Method

GenerateValidRuleData() public static method

Generate RuleData from ptf config base on different action Type.
public static GenerateValidRuleData ( ActionType actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties otherInfo, ulong ruleId ) : RuleData
actionType ActionType ActionType in a rule.
ruleDataType TestRuleDataType The type of the rule data.
ruleSequence int Rule sequence in PidTagRuleSequence of the RuleData.
ruleState RuleState Specifies value of PidTagRuleState of the RuleData.
actionData IActionData The actionData needed to construct the RuleData.
otherInfo RuleProperties /// 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 ///
ruleId ulong A 64-bit unsigned integer represents the rule.
return Microsoft.Protocols.TestSuites.Common.RuleData
        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;
        }