/// <summary> /// States whether or not this rule should apply the predefined value to the predefined property /// The caller will handle aggregation if multiple rules /// /// *Note /// this need not be implemented if not supporting yes no classifiers /// </summary> /// <param name="property">The name of the property that this rule can modify</param> /// <param name="Value">The value to set that will be applied to the property if applyValue is true</param> /// <param name="applyValue">True if the caller should set Value to property, False if the caller should not set Value to property</param> /// <param name="idRule">The id of the rule to process</param> /// <param name="idPropDef">The id of the property definition that this rule can modify</param> public void DoesPropertyValueApply( string property, string Value, out bool applyValue, Guid idRule, Guid idPropDef ) { PowerShellRuleHoster rule = m_dictAllRules[idRule]; // run the powershell pipeline for this value rule.StepPipeline(m_propertyBag); // if the rule doesn't apply force the value to false if (rule.RuleNoApply) { applyValue = false; } else { try { applyValue = (bool)rule.PropertyValue; } catch (Exception ex) { //Assuming this error is due to casting String message = String.Format(CultureInfo.InvariantCulture, "PowerShell Classifier for rule [{0}] and file [{1}], failed to convert the property recieved from powershell of type [{2}] and value [{3}] into the a boolean value for yes/no classification, with error [{4}]", rule.RuleName, m_propertyBag.VolumeName + m_propertyBag.RelativePath + "\\" + m_propertyBag.Name, rule.PropertyValue.GetType().ToString(), rule.PropertyValue.ToString(), ex.Message); m_propertyBag.AddMessage(message); throw new COMException(message, ex.InnerException); } } }
/// <summary> /// Gets the value for the property and rule to apply /// The caller will handle aggregating multiple values for a single property /// /// *Note /// This function need not be implemented if only supporting yes no classifiers /// </summary> /// <param name="property">The name of the property that this rule can modify</param> /// <param name="Value">The value to set the property to</param> /// <param name="idRule">The id of the rule to process</param> /// <param name="idPropDef">The id of the definition that this rule can modify</param> public void GetPropertyValueToApply( string property, out string Value, Guid idRule, Guid idPropDef ) { PowerShellRuleHoster rule = m_dictAllRules[idRule]; // run the powershell script over the propertyBag rule.StepPipeline(m_propertyBag); // If the rule does not modify the property value throw an error that specifies this // You must specify the HR that is being specified below if you wish to not modify the rule's value if (rule.RuleNoApply) { throw new COMException("Value does not apply", FSRM_E_NO_PROPERTY_VALUE); //, FSRM_E_NO_PROPERTY_VALUE); } //convert the powershell value into the approrpiate value try { IFsrmPropertyDefinition propertyDefinition = m_dictAllProperties[idPropDef]; if (propertyDefinition.Type == _FsrmPropertyDefinitionType.FsrmPropertyDefinitionType_Bool) { //convert from true/false to "1","0" Value = (bool)rule.PropertyValue ? "1" : "0"; } else if (propertyDefinition.Type == _FsrmPropertyDefinitionType.FsrmPropertyDefinitionType_Date) { // convert from datetime to str DateTime time = (DateTime)rule.PropertyValue; long filetime = time.ToFileTimeUtc(); Value = filetime.ToString(CultureInfo.InvariantCulture); } else if (propertyDefinition.Type == _FsrmPropertyDefinitionType.FsrmPropertyDefinitionType_Int) { Value = rule.PropertyValue.ToString(); } else { Value = (string)rule.PropertyValue; } } catch (Exception ex) { String message = ""; if (rule.PropertyValue == null) { message = String.Format(CultureInfo.InvariantCulture, "PowerShell Classifier for rule [{0}] and file [{1}], received null value from powershell, with error [{2}]", rule.RuleName, m_propertyBag.VolumeName + m_propertyBag.RelativePath + "\\" + m_propertyBag.Name, ex.Message); } else { //Assuming this error is due to casting message = String.Format(CultureInfo.InvariantCulture, "PowerShell Classifier for rule [{0}] and file [{1}], failed to convert the property recieved from powershell of type [{2}] and value [{3}] into the property [{4}], with error [{5}]", rule.RuleName, m_propertyBag.VolumeName + m_propertyBag.RelativePath + "\\" + m_propertyBag.Name, rule.PropertyValue.GetType().ToString(), rule.PropertyValue.ToString(), property, ex.Message); } m_propertyBag.AddMessage(message); throw new COMException(message, ex.InnerException); } }