/// <summary> /// Generate rule properties value. /// </summary> /// <param name="name">Rule name.</param> /// <returns>Rule properties</returns> public static RuleProperties GenerateRuleProperties(string name) { RuleProperties ruleProperties = new RuleProperties { UserFlag = Constants.PidTagRuleUserFlags1, Provider = Constants.PidTagRuleProvider, ProviderData = Constants.PidTagRuleProviderData, ConditionSubjectName = Constants.RuleConditionSubjectContainString, Name = name }; return(ruleProperties); }
/// <summary> /// Generate a sample valid RuleData structure. /// </summary> /// <param name="actionType">ActionType in a rule</param> /// <param name="ruleDataType">Rule data value.</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="ruleProperties">Rule properties structure.</param> /// <returns>A valid RuleData structure</returns> public static RuleData GenerateValidRuleData(ActionTypes actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties ruleProperties) { RuleData ruleData = new RuleData { RuleDataFlags = (byte)ruleDataType }; List <TaggedPropertyValue> propertyList = new List <TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleSequence, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag; pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence); propertyList.Add(pidTagRuleSequence); TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleLevel, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag; pidTagRuleLevel.Value = BitConverter.GetBytes(0); propertyList.Add(pidTagRuleLevel); TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue(); PropertyTag pidTagRuleStatePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleState, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag; pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState); propertyList.Add(pidTagRuleState); if (ruleProperties.Name.Length > 0) { TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue(); PropertyTag pidTagRuleNamePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleName, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag; pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Name + "\0"); propertyList.Add(pidTagRuleName); } if (ruleProperties.Provider.Length > 0) { TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProvider, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag; pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Provider + "\0"); propertyList.Add(pidTagRuleProvider); } if (ruleProperties.UserFlag.Length > 0) { TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue(); PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleUserFlags, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag; pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(ruleProperties.UserFlag)); propertyList.Add(pidTagRuleUserFlags); } if (ruleProperties.ProviderData.Length > 0) { TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProviderData, PropertyType = (ushort)PropertyTypeName.PtypBinary }; pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag; pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(ruleProperties.ProviderData); pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value); propertyList.Add(pidTagRuleProviderData); } if (ruleProperties.ConditionSubjectName.Length > 0) { AddRuleCondition(propertyList, ruleProperties.ConditionSubjectName); AddRuleAction(propertyList, actionType, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); } ruleData.PropertyValues = propertyList.ToArray(); ruleData.PropertyValueCount = (ushort)propertyList.Count; return(ruleData); }
/// <summary> /// Generate a sample valid RuleData structure. /// </summary> /// <param name="actionType">ActionType in a rule</param> /// <param name="ruleDataType">Rule data value.</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="ruleProperties">Rule properties structure.</param> /// <returns>A valid RuleData structure</returns> public static RuleData GenerateValidRuleData(ActionTypes actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties ruleProperties) { RuleData ruleData = new RuleData { RuleDataFlags = (byte)ruleDataType }; List<TaggedPropertyValue> propertyList = new List<TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleSequence, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag; pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence); propertyList.Add(pidTagRuleSequence); TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleLevel, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag; pidTagRuleLevel.Value = BitConverter.GetBytes(0); propertyList.Add(pidTagRuleLevel); TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue(); PropertyTag pidTagRuleStatePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleState, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag; pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState); propertyList.Add(pidTagRuleState); if (ruleProperties.Name.Length > 0) { TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue(); PropertyTag pidTagRuleNamePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleName, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag; pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Name + "\0"); propertyList.Add(pidTagRuleName); } if (ruleProperties.Provider.Length > 0) { TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProvider, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag; pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Provider + "\0"); propertyList.Add(pidTagRuleProvider); } if (ruleProperties.UserFlag.Length > 0) { TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue(); PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleUserFlags, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag; pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(ruleProperties.UserFlag)); propertyList.Add(pidTagRuleUserFlags); } if (ruleProperties.ProviderData.Length > 0) { TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProviderData, PropertyType = (ushort)PropertyTypeName.PtypBinary }; pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag; pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(ruleProperties.ProviderData); pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value); propertyList.Add(pidTagRuleProviderData); } if (ruleProperties.ConditionSubjectName.Length > 0) { AddRuleCondition(propertyList, ruleProperties.ConditionSubjectName); AddRuleAction(propertyList, actionType, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); } ruleData.PropertyValues = propertyList.ToArray(); ruleData.PropertyValueCount = (ushort)propertyList.Count; return ruleData; }
/// <summary> /// Generate rule properties value. /// </summary> /// <param name="name">Rule name.</param> /// <returns>Rule properties</returns> public static RuleProperties GenerateRuleProperties(string name) { RuleProperties ruleProperties = new RuleProperties { UserFlag = Constants.PidTagRuleUserFlags1, Provider = Constants.PidTagRuleProvider, ProviderData = Constants.PidTagRuleProviderData, ConditionSubjectName = Constants.RuleConditionSubjectContainString, Name = name }; return ruleProperties; }