Beispiel #1
0
        private void ValidateValueChangeType(ValueModificationType type)
        {
            switch (this.ModificationType)
            {
            case AttributeModificationType.Add:
                if (type != ValueModificationType.Add)
                {
                    throw new UnknownOrUnsupportedModificationTypeException(type);
                }

                break;

            case AttributeModificationType.Delete:
                throw new UnknownOrUnsupportedModificationTypeException(type);

            case AttributeModificationType.Replace:
                if (type != ValueModificationType.Add)
                {
                    throw new UnknownOrUnsupportedModificationTypeException(type);
                }

                break;

            case AttributeModificationType.Update:
                break;

            default:
            case AttributeModificationType.Unconfigured:
                throw new UnknownOrUnsupportedModificationTypeException(type);
            }
        }
 /// <summary>
 /// Create a ValueChange for the specified value based on the modification type specified by this object
 /// </summary>
 /// <param name="newValue">The value to create the value change for</param>
 /// <param name="modificationType">The type of modification to perform</param>
 /// <returns>A new ValueChange object</returns>
 protected ValueChange CreateValueChange(object newValue, ValueModificationType modificationType)
 {
     if (modificationType == ValueModificationType.Delete)
     {
         return(ValueChange.CreateValueDelete(newValue));
     }
     else
     {
         return(ValueChange.CreateValueAdd(newValue));
     }
 }
Beispiel #3
0
        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());
        }
        /// <summary>
        /// Gets the values present in the attribute change that match the specified ValueModificationType
        /// </summary>
        /// <typeparam name="T">The type of data in the attribute</typeparam>
        /// <param name="change">The attribute change</param>
        /// <param name="modificationType">The type of value modification to apply</param>
        /// <returns>A list values present in the attribute change, or an empty list if there were no value changes matching the specified type were present</returns>
        public static IList <T> GetValueChanges <T>(this AttributeChange change, ValueModificationType modificationType)
        {
            List <T> list = new List <T>();

            if (change.ValueChanges == null)
            {
                return(list);
            }

            IEnumerable <ValueChange> valueChanges = change.ValueChanges.Where(t => t.ModificationType == modificationType);

            foreach (ValueChange valueChange in valueChanges)
            {
                list.Add(TypeConverter.ConvertData <T>(valueChange.Value));
            }

            return(list);
        }
Beispiel #5
0
        private void AddValueChange(ValueModificationType type, object value)
        {
            switch (type)
            {
            case ValueModificationType.Add:
                this.ValueChanges.Add(ValueChange.CreateValueAdd(value));
                break;

            case ValueModificationType.Delete:
                this.ValidateValueChangeType(type);
                this.ValueChanges.Add(ValueChange.CreateValueDelete(value));

                break;

            case ValueModificationType.Unconfigured:
            default:
                throw new UnknownOrUnsupportedModificationTypeException(type);
            }
        }
        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);
            }
        }
        /// <summary>
        /// Converts an enumeration of values to a list of ValueChanges
        /// </summary>
        /// <typeparam name="T">The type of the data in the list</typeparam>
        /// <param name="list">The list of values to convert to ValueChanges</param>
        /// <param name="modificationType">The modification type to apply to the values in the ValueChange</param>
        /// <returns>A list of ValueChange objects</returns>
        public static IList <ValueChange> ToValueChange <T>(this IEnumerable <T> list, ValueModificationType modificationType)
        {
            List <ValueChange> changes = new List <ValueChange>();

            foreach (T value in list)
            {
                switch (modificationType)
                {
                case ValueModificationType.Add:
                    changes.Add(ValueChange.CreateValueAdd(value));
                    break;

                case ValueModificationType.Delete:
                    changes.Add(ValueChange.CreateValueDelete(value));
                    break;

                case ValueModificationType.Unconfigured:
                default:
                    throw new NotSupportedException("The modification type is unknown or unsupported");
                }
            }

            return(changes);
        }
        /// <summary>
        /// Gets the value changes from the specified attribute
        /// </summary>
        /// <typeparam name="T">The data type of the atttribute</typeparam>
        /// <param name="csentry">The CSEntryChange</param>
        /// <param name="attributeName">The name of the attribute</param>
        /// <param name="modificationType">The modification type of the values to get</param>
        /// <returns>A list of values from the attribute change if it was present. If the attribute change was not present, or contained no modifications matching the type specified by the <paramref name="modificationType"/> parameter, an empty list is returned</returns>
        public static IList <T> GetValueChanges <T>(this CSEntryChange csentry, string attributeName, ValueModificationType modificationType)
        {
            AttributeChange change = csentry.AttributeChanges.FirstOrDefault(t => t.Name == attributeName);

            if (change == null)
            {
                return(new List <T>());
            }

            return(change.GetValueChanges <T>(modificationType));
        }
Beispiel #9
0
 internal void SetObject(ValueChange change)
 {
     this.Value            = change.Value;
     this.ModificationType = change.ModificationType;
 }
Beispiel #10
0
        /// <summary>
        /// Retrieves the source attribute values from the specified attribute change
        /// </summary>
        /// <param name="attributeChange">The attribute change to enumerate the values from</param>
        /// <param name="reference">The declaration of the referenced attribute</param>
        /// <param name="modificationType">The value modification type to enumerate</param>
        /// <returns>An enumeration of expanded string values</returns>
        private IEnumerable <string> GetSourceAttributeValues(AttributeChange attributeChange, ReferencedAttribute reference, ValueModificationType modificationType)
        {
            IEnumerable <ValueChange> valueChanges = attributeChange.ValueChanges.Where(t => t.ModificationType == (modificationType == ValueModificationType.Unconfigured ? ValueModificationType.Add : modificationType));

            foreach (ValueChange valueChange in valueChanges)
            {
                if (attributeChange.DataType == AttributeType.Reference)
                {
                    yield return(reference.PreReferenceString + this.GetReferencedDNComponent(valueChange.Value.ToString(), reference) + reference.PostReferenceString);
                }
                else
                {
                    yield return(reference.PreReferenceString + valueChange.Value.ToString() + reference.PostReferenceString);
                }
            }

            yield break;
        }
Beispiel #11
0
        /// <summary>
        /// Gets an enumeration of expanded attribute value declarations for a multi-valued attribute
        /// </summary>
        /// <param name="csentry">The source object</param>
        /// <param name="multiValuedAttribute">The multi-valued attribute to expand</param>
        /// <param name="modificationType">Specifies which value modification types to expand during the enumeration</param>
        /// <returns>An enumeration of expanded declaration strings</returns>
        public IEnumerable <string> ExpandDeclarationWithMultiValued(CSEntryChange csentry, MASchemaAttribute multiValuedAttribute, ValueModificationType modificationType)
        {
            if (csentry == null)
            {
                yield return(this.DeclarationText);
            }

            string constructedValue = this.DeclarationText;

            foreach (ReferencedAttribute reference in this.AttributeReferences.Where(t => t.AttributeName != multiValuedAttribute.Name))
            {
                if (MASchema.GetAttributeType(reference.AttributeName) == AttributeType.Reference)
                {
                    constructedValue = constructedValue.Replace(reference.Declaration, this.GetReferencedDNComponent(csentry, reference));
                }
                else
                {
                    constructedValue = constructedValue.Replace(reference.Declaration, this.GetSourceAttributeValue(csentry, reference, false, false) ?? string.Empty);
                }
            }

            ReferencedAttribute mvattribute = this.AttributeReferences.FirstOrDefault(t => t.AttributeName == multiValuedAttribute.Name);

            if (mvattribute != null && csentry.AttributeChanges.Contains(multiValuedAttribute.Name))
            {
                AttributeChange change = csentry.AttributeChanges[multiValuedAttribute.Name];

                foreach (string value in this.GetSourceAttributeValues(change, mvattribute, modificationType))
                {
                    yield return(constructedValue.Replace(mvattribute.Declaration, value));
                }
            }
            else
            {
                yield return(constructedValue);
            }

            yield break;
        }
 /// <summary>
 /// Initializes a new instance of the UnknownOrUnsupportedModificationTypeException class
 /// </summary>
 /// <param name="modificationType">The modification type that was unknown or supported</param>
 public UnknownOrUnsupportedModificationTypeException(ValueModificationType modificationType)
     : base(string.Format("An unknown or unsupported value modification type was used: {0}", modificationType.ToSmartString()))
 {
 }
        /// <summary>
        /// Populates the object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute successCodes     = node.Attributes["success-codes"];
            XmlAttribute forEachAttribute = node.Attributes["for-each"];
            XmlAttribute valueModificationTypeAttribute = node.Attributes["value-modification"];
            XmlAttribute hasObjectsAttribute            = node.Attributes["result-has-objects"];

            if (hasObjectsAttribute != null && !string.IsNullOrWhiteSpace(hasObjectsAttribute.Value))
            {
                bool hasObjects = false;
                if (bool.TryParse(hasObjectsAttribute.Value, out hasObjects))
                {
                    this.HasObjects = hasObjects;
                }
                else
                {
                    throw new ArgumentException("The boolean value could not be parsed: " + hasObjectsAttribute.Value);
                }
            }

            if (forEachAttribute != null && !string.IsNullOrWhiteSpace(forEachAttribute.Value))
            {
                MASchema.ThrowOnMissingAttribute(forEachAttribute.Value);
                this.ForEachAttribute = MASchema.Attributes[forEachAttribute.Value];
            }

            if (successCodes != null)
            {
                string[] split = successCodes.Value.Split(',');
                foreach (string value in split)
                {
                    int result = 0;

                    if (int.TryParse(value, out result))
                    {
                        this.SuccessCodes.Add(result);
                    }
                    else
                    {
                        throw new ArgumentException("The specified success code value cannot be converted to an integer: " + value);
                    }
                }
            }

            if (this.SuccessCodes.Count == 0)
            {
                this.SuccessCodes.Add(0);
            }

            if (valueModificationTypeAttribute == null || string.IsNullOrWhiteSpace(valueModificationTypeAttribute.Value))
            {
                this.ForEachValueModificationType = ValueModificationType.Unconfigured;
            }
            else
            {
                ValueModificationType valueModificationType = ValueModificationType.Unconfigured;
                if (Enum.TryParse(valueModificationTypeAttribute.Value, true, out valueModificationType))
                {
                    this.ForEachValueModificationType = valueModificationType;
                }
                else
                {
                    throw new ArgumentException("The value modification type is unknown: " + valueModificationTypeAttribute.Value);
                }
            }

            this.Command = new ValueDeclaration(node);
        }