private void Create(NewAttributeWindow window, bool close = true) { try { this.attributesVM.CreateAttribute(this.Name, this.Type, this.IsMultivalued, this.Operation, this.IsIndexable, this.IsIndexed); if (close) { window.Close(); } else { this.Name = null; this.Type = ExtendedAttributeType.String; this.IsIndexed = false; this.IsIndexable = true; this.IsMultivalued = false; window.AttributeName.Focus(); } } catch (Exception ex) { MessageBox.Show("Could not create the attribute\n\n" + ex.Message); } }
/// <summary> /// Gets the value operators that are allowed to be used with the specified ExtendedAttributeType /// </summary> /// <param name="type">The type of attribute to obtain the allowed operators for</param> /// <returns>An enumeration of ValueOperators</returns> public static IEnumerable <ValueOperator> GetAllowedValueOperators(ExtendedAttributeType type) { switch (type) { case ExtendedAttributeType.Binary: return(ComparisonEngine.AllowedBinaryOperators); case ExtendedAttributeType.Boolean: return(ComparisonEngine.AllowedBooleanOperators); case ExtendedAttributeType.Integer: return(ComparisonEngine.AllowedIntegerOperators); case ExtendedAttributeType.DateTime: return(ComparisonEngine.AllowedDateTimeOperators); case ExtendedAttributeType.Reference: return(ComparisonEngine.AllowedReferenceOperators); case ExtendedAttributeType.String: return(ComparisonEngine.AllowedStringOperators); case ExtendedAttributeType.Undefined: default: throw new UnknownOrUnsupportedDataTypeException(); } }
private IEnumerable <EnumExtension.EnumMember> GetAllowedValueOperators(ExtendedAttributeType type) { if (AdvancedComparisonRuleViewModel.valueOperatorValues.Count == 0) { var enumValues = Enum.GetValues(typeof(ValueOperator)); EnumExtension.EnumMember enumMember; foreach (var value in enumValues) { enumMember = new EnumExtension.EnumMember(); enumMember.Value = value; enumMember.Description = ((Enum)value).GetEnumDescription(); valueOperatorValues.Add(enumMember); } enumMember = new EnumExtension.EnumMember(); enumMember.Value = ValueOperator.IsPresent; enumMember.Description = ((Enum)enumMember.Value).GetEnumDescription(); valueOperatorValues.Add(enumMember); enumMember = new EnumExtension.EnumMember(); enumMember.Value = ValueOperator.NotPresent; enumMember.Description = ((Enum)enumMember.Value).GetEnumDescription(); valueOperatorValues.Add(enumMember); } foreach (var value in ComparisonEngine.GetAllowedValueOperators(type)) { yield return(valueOperatorValues.FirstOrDefault(t => (int)t.Value == ((int)value))); } yield return(valueOperatorValues.FirstOrDefault(t => (ValueOperator)t.Value == ValueOperator.IsPresent)); yield return(valueOperatorValues.FirstOrDefault(t => (ValueOperator)t.Value == ValueOperator.NotPresent)); }
/// <summary> /// Executes the transformation against the specified value /// </summary> /// <param name="inputType">The type of data supplied as the input value</param> /// <param name="inputValue">The incoming value to transform</param> /// <returns>The transformed value</returns> public IList <object> TransformValue(object inputValue) { if (inputValue != null) { ExtendedAttributeType inputType = TypeConverter.GetDataTypeExtended(inputValue); this.ValidateInputType(inputType); } object returnValue = this.TransformSingleValue(inputValue); IList <object> returnValues = returnValue as IList <object>; if (returnValues == null) { if (returnValue == null) { returnValues = new List <object>(); } else { returnValues = new List <object>() { returnValue }; } } //Logger.WriteLine("Transform {0}: {1} -> {2}", LogLevel.Debug, this.ID, inputValue.ToSmartStringOrNull(), returnValues.Where(t => t != null).Select(u => u.ToSmartStringOrNull()).ToCommaSeparatedString()); return(returnValues); }
/// <summary> /// Converts an ExtendedAttributeType value to its equivalent MetadirectoryServices AttributeType /// </summary> /// <param name="type">The ExtendedAttributeType value</param> /// <returns>An equivalent AttributeType value</returns> public static AttributeType ToAttributeType(this ExtendedAttributeType type) { switch (type) { case ExtendedAttributeType.String: return(AttributeType.String); case ExtendedAttributeType.Integer: return(AttributeType.Integer); case ExtendedAttributeType.Reference: return(AttributeType.Reference); case ExtendedAttributeType.Binary: return(AttributeType.Binary); case ExtendedAttributeType.Boolean: return(AttributeType.Boolean); case ExtendedAttributeType.Undefined: return(AttributeType.Undefined); case ExtendedAttributeType.DateTime: return(AttributeType.String); default: throw new UnknownOrUnsupportedDataTypeException(); } }
/// <summary> /// Converts the object to the specified attribute type /// </summary> /// <param name="obj">The object to convert</param> /// <param name="type">The data type to convert the object to</param> /// <returns>The converted value</returns> public static object ConvertData(object obj, ExtendedAttributeType type) { switch (type) { case ExtendedAttributeType.Binary: return(TypeConverter.ConvertToBinary(obj)); case ExtendedAttributeType.Boolean: return(TypeConverter.ConvertToBoolean(obj)); case ExtendedAttributeType.Integer: return(TypeConverter.ConvertToLong(obj)); case ExtendedAttributeType.Reference: return(TypeConverter.ConvertToGuid(obj)); case ExtendedAttributeType.String: return(TypeConverter.ConvertToString(obj)); case ExtendedAttributeType.DateTime: return(TypeConverter.ConvertToDateTime(obj)); case ExtendedAttributeType.Undefined: default: throw new UnknownOrUnsupportedDataTypeException(); } }
private AttributeChange AvpToAttributeChange(KeyValuePair <string, IList <string> > kvp, AttributeModificationType modificationType) { ExtendedAttributeType type = ActiveConfig.DB.GetAttribute(kvp.Key).Type; switch (modificationType) { case AttributeModificationType.Replace: if (kvp.Value == null) { return(AttributeChangeDetached.CreateAttributeDelete(kvp.Key)); } else { return(AttributeChangeDetached.CreateAttributeReplace(kvp.Key, kvp.Value.Select(t => TypeConverter.ConvertData(t, type)).ToList <object>())); } case AttributeModificationType.Add: return(AttributeChangeDetached.CreateAttributeAdd(kvp.Key, kvp.Value.Select(t => TypeConverter.ConvertData(t, type)).ToList <object>())); case AttributeModificationType.Delete: return(AttributeChangeDetached.CreateAttributeDelete(kvp.Key)); default: case AttributeModificationType.Update: case AttributeModificationType.Unconfigured: throw new InvalidOperationException(); } }
/// <summary> /// Gets a value indicating if the specified ValueOperator is compatible with the specified ExtendedAttributeType /// </summary> /// <param name="op">The ValueOperator to compare</param> /// <param name="type">The ExtendedAttributeType to compare</param> /// <returns>True if the specified ValueOperator is usable with the specified ExtendedAttributeType, otherwise false is returned</returns> public static bool IsAllowedOperator(ValueOperator op, ExtendedAttributeType type) { switch (type) { case ExtendedAttributeType.Binary: return(ComparisonEngine.AllowedBinaryOperators.Any(t => t == op)); case ExtendedAttributeType.Boolean: return(ComparisonEngine.AllowedBooleanOperators.Any(t => t == op)); case ExtendedAttributeType.Integer: return(ComparisonEngine.AllowedIntegerOperators.Any(t => t == op)); case ExtendedAttributeType.DateTime: return(ComparisonEngine.AllowedDateTimeOperators.Any(t => t == op)); case ExtendedAttributeType.Reference: return(ComparisonEngine.AllowedReferenceOperators.Any(t => t == op)); case ExtendedAttributeType.String: return(ComparisonEngine.AllowedStringOperators.Any(t => t == op)); case ExtendedAttributeType.Undefined: default: throw new UnknownOrUnsupportedDataTypeException(); } }
protected void ValidateInputType(ExtendedAttributeType inputType) { if (!this.AllowedInputTypes.Any(t => t == inputType)) { throw new InvalidCastException(string.Format( "The input type {0} for the transform {1} ({2}) was not one of the following valid input types: {3}", inputType.ToString(), this.ID, this.GetType().Name, this.AllowedInputTypes.Select(t => t.ToSmartStringOrNull()).ToCommaSeparatedString())); } }
/// <summary> /// Tries to convert the object to the specified attribute type /// </summary> /// <param name="obj">The object to convert</param> /// <param name="type">The data type to convert the object to</param> /// <param name="value">The converted value</param> /// <returns>A value indicating if the conversion was successful</returns> public static bool TryConvertData(object obj, ExtendedAttributeType type, out object value) { try { value = TypeConverter.ConvertData(obj, type); return(true); } catch { value = null; return(false); } }
private static List <ValueChange> GetValueChanges(XElement element, ExtendedAttributeType attributeType) { List <ValueChange> valueChanges = new List <ValueChange>(); foreach (var child in element.Elements().Where(t => t.Name.LocalName == "value-change")) { ValueChange change = CSEntryChangeXmlImport.GetValueChange(child, attributeType); if (change != null) { valueChanges.Add(change); } } return(valueChanges); }
/// <summary> /// Executes the transformation against the specified value /// </summary> /// <param name="inputType">The type of data supplied as the input value</param> /// <param name="inputValue">The incoming value to transform</param> /// <returns>The transformed value</returns> public IList <object> TransformValuesWithLoopback(IList <object> inputValues, IList <object> targetValues) { if (inputValues.Any(t => t == null)) { throw new ArgumentNullException("One or more values passed to the transform were null"); } ExtendedAttributeType inputType = TypeConverter.GetDataTypeExtended(inputValues.First()); this.ValidateInputType(inputType); IList <object> returnValue = this.TransformMultiValuesWithLoopback(inputValues, targetValues); //Logger.WriteLine("Transform {0}: {1} -> {2}", LogLevel.Debug, this.ID, inputValues.Select(t => t.ToSmartStringOrNull()).ToCommaSeparatedString(), returnValue.Select(t => t.ToSmartStringOrNull()).ToCommaSeparatedString()); return(returnValue); }
internal void CreateAttribute(string name, ExtendedAttributeType type, bool isMultivalued, AcmaAttributeOperation operation, bool isIndexable, bool isIndexed) { AcmaSchemaAttribute attribute; try { attribute = ActiveConfig.DB.CreateAttribute(name, type, isMultivalued, operation, isIndexable, isIndexed); this.Add(attribute); } catch (Exception ex) { MessageBox.Show("Could not create the attribute\n\n" + ex.Message); } }
public NewValueChangeViewModel( Window window, IEnumerable <UnitTestStepObjectCreation> allowedReferenceObjects, ExtendedAttributeType dataType, ValueModificationType modificationType, ValueChangeViewModel existingValueChange = null) : base() { this.IgnoreOwnPropertyChanges = true; this.AllowedObjects = allowedReferenceObjects; this.existingValueChange = existingValueChange; this.ModificationType = modificationType; this.Type = dataType; if (this.existingValueChange != null) { this.ModificationType = this.existingValueChange.ModificationType; if (this.Type == ExtendedAttributeType.Reference) { if (!string.IsNullOrEmpty(this.existingValueChange.Value)) { object modelValue = this.existingValueChange.ModelValue; Guid modelValueGuid = Lithnet.MetadirectoryServices.TypeConverter.ConvertData <Guid>(modelValue); this.ReferenceValue = modelValueGuid; } else { this.ReferenceValue = Guid.Empty; } } else { this.Value = this.existingValueChange.Value; } } else { if (this.type == ExtendedAttributeType.Reference) { if (this.AllowedObjects.Any()) { this.ReferenceValue = this.AllowedObjects.First().ObjectId; } } } this.Commands.AddItem("Create", t => this.Create(window), t => this.CanCreate()); }
private static ValueChange GetValueChange(XElement element, ExtendedAttributeType attributeType) { ValueModificationType modificationType = ValueModificationType.Unconfigured; string value = null; foreach (var child in element.Elements()) { if (child.Name.LocalName == "modification-type") { string modificationTypeString = (string)child; if (!Enum.TryParse <ValueModificationType>(modificationTypeString, out modificationType)) { throw new InvalidCastException(string.Format("Cannot convert '{0}' to type {1}", modificationTypeString, typeof(ValueModificationType).Name)); } } else if (child.Name.LocalName == "value") { value = (string)child; } } if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentException("The value-change value was blank"); } switch (modificationType) { case ValueModificationType.Add: return(ValueChange.CreateValueAdd(TypeConverter.ConvertData(value, attributeType))); case ValueModificationType.Delete: return(ValueChange.CreateValueDelete(TypeConverter.ConvertData(value, attributeType))); case ValueModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(modificationType); } }
private void ExecuteLoopbackTransform() { List <object> inputValues; string targetValue; if (this.IsMultivalueSupported) { inputValues = new List <object>(); if (!string.IsNullOrWhiteSpace(this.InputValue1)) { inputValues.Add(TypeConverter.ConvertData(this.InputValue1, this.AttributeType)); } if (!string.IsNullOrWhiteSpace(this.InputValue2)) { inputValues.Add(TypeConverter.ConvertData(this.InputValue2, this.AttributeType)); } targetValue = this.InputValue3; } else { inputValues = new List <object>() { TypeConverter.ConvertData(this.InputValue1, this.AttributeType) }; targetValue = this.InputValue2; } ExtendedAttributeType returnType = this.model.PossibleReturnTypes.First(); IList <object> output = this.model.TransformValuesWithLoopback( inputValues.Where(t => t != null).ToList(), new List <object>() { TypeConverter.ConvertData(targetValue, returnType) }); this.OutputValue = output.Select(t => t.ToSmartStringOrNull()).ToCommaSeparatedString(); }
private static void XmlReadAttributeChangeNode(XElement element, CSEntryChange csentry, bool throwOnMissingAttribute) { string name = null; AttributeModificationType modificationType = AttributeModificationType.Unconfigured; ExtendedAttributeType dataType = ExtendedAttributeType.Undefined; List <ValueChange> valueChanges = null; AttributeChange attributeChange = null; foreach (var child in element.Elements()) { if (child.Name.LocalName == "name") { name = (string)child; } else if (child.Name.LocalName == "modification-type") { string modificationTypeString = (string)child; if (!Enum.TryParse <AttributeModificationType>(modificationTypeString, out modificationType)) { throw new InvalidCastException(string.Format("Cannot convert '{0}' to type {1}", modificationTypeString, typeof(AttributeModificationType).Name)); } } else if (child.Name.LocalName == "data-type") { string dataTypeString = (string)child; if (!Enum.TryParse <ExtendedAttributeType>(dataTypeString, out dataType)) { throw new InvalidCastException(string.Format("Cannot convert '{0}' to type '{1}'", dataTypeString, typeof(ExtendedAttributeType).Name)); } } else if (child.Name.LocalName == "value-changes") { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The attribute name must appear first in the list of <attribute-change> elements"); } if (dataType == ExtendedAttributeType.Undefined) { if (ActiveConfig.DB == null) { throw new NotConnectedException("The CSEntryChange did not specify a data type in the attribute change, and there was no active connection to the database to resolve it internally"); } else { AcmaSchemaAttribute attribute = null; try { attribute = ActiveConfig.DB.GetAttribute(name); dataType = attribute.Type; } catch (NoSuchAttributeException) { if (throwOnMissingAttribute) { throw; } else { continue; } } } } valueChanges = CSEntryChangeXmlImport.GetValueChanges(child, dataType); } } switch (modificationType) { case AttributeModificationType.Add: if (valueChanges.Count == 0) { // discard attribute change with no values return; } attributeChange = AttributeChange.CreateAttributeAdd(name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()); break; case AttributeModificationType.Replace: if (valueChanges.Count == 0) { // discard attribute change with no values return; //throw new ArgumentException("The attribute replace in the CSEntry provided no values"); } attributeChange = AttributeChange.CreateAttributeReplace(name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()); break; case AttributeModificationType.Delete: attributeChange = AttributeChange.CreateAttributeDelete(name); break; case AttributeModificationType.Update: if (valueChanges.Count == 0) { // discard attribute change with no values return; //throw new ArgumentException("The attribute update in the CSEntry provided no values"); } attributeChange = AttributeChange.CreateAttributeUpdate(name, valueChanges); break; case AttributeModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(modificationType); } csentry.AttributeChanges.Add(attributeChange); }
/// <summary> /// Compares two values of the specified ExtendedAttributeType /// </summary> /// <param name="actualValue">The value to test</param> /// <param name="expectedValue">The expected value</param> /// <param name="valueOperator">The operator to use</param> /// <param name="type">The data type of the values to compare</param> /// <returns>True if the values are the same</returns> public static bool Compare(object actualValue, object expectedValue, ValueOperator valueOperator, ExtendedAttributeType type) { switch (type) { case ExtendedAttributeType.Binary: return(CompareBinary(TypeConverter.ConvertData <byte[]>(actualValue), TypeConverter.ConvertData <byte[]>(expectedValue), valueOperator)); case ExtendedAttributeType.Boolean: return(CompareBoolean(TypeConverter.ConvertData <bool>(actualValue), TypeConverter.ConvertData <bool>(expectedValue), valueOperator)); case ExtendedAttributeType.Integer: return(CompareLong(TypeConverter.ConvertData <long>(actualValue), TypeConverter.ConvertData <long>(expectedValue), valueOperator)); case ExtendedAttributeType.DateTime: return(CompareDateTime(TypeConverter.ConvertData <DateTime>(actualValue), TypeConverter.ConvertData <DateTime>(expectedValue), valueOperator)); case ExtendedAttributeType.Reference: return(CompareString(TypeConverter.ConvertData <Guid>(actualValue).ToString(), TypeConverter.ConvertData <Guid>(expectedValue).ToString(), valueOperator)); case ExtendedAttributeType.String: return(CompareString(TypeConverter.ConvertData <string>(actualValue), TypeConverter.ConvertData <string>(expectedValue), valueOperator)); default: case ExtendedAttributeType.Undefined: throw new UnknownOrUnsupportedDataTypeException(); } }