/// <summary> /// Copies property values from <see cref="cloneFrom"/>, removing items that exist in /// <see cref="PropertiesToRemove"/> /// </summary> /// <param name="cloneFrom">The collection of properties to clone.</param> /// <returns>The cloned set of properties, with the requested properties removed.</returns> private PropertyValues GetNewObjectPropertyValues(PropertyValues cloneFrom) { // Sanity. if (null == cloneFrom) { throw new ArgumentNullException(nameof(cloneFrom)); } // Get a basic copy. var propertyValues = cloneFrom.Clone(); // Remove the properties we don't want. foreach (var propertyId in this.PropertiesToRemove) { // If the property is not in the collection then skip. int index = propertyValues.IndexOf(propertyId); if (-1 == index) { continue; } // Remove it. propertyValues.Remove(index); } // Return. return(propertyValues); }
private object MergeNewAndOldValues(PropertyValues original, PropertyValues current, PropertyValues database) { PropertyValues result = original.Clone(); foreach (var propertyName in original.Properties.Select(p => p.Name)) { if (original[propertyName] is PropertyValues) { object mergedComplexValues = MergeNewAndOldValues((PropertyValues)original[propertyName], (PropertyValues)current[propertyName], (PropertyValues)database[propertyName]); ((PropertyValues)result[propertyName]).SetValues(mergedComplexValues); } else { if (!object.Equals(current[propertyName], original[propertyName])) { result[propertyName] = current[propertyName]; } else if (!object.Equals(database[propertyName], original[propertyName])) { result[propertyName] = database[propertyName]; } } } return(result); }
public ObjectVersionAndProperties SetAllProperties(ObjVer objVer, bool allowModifyingCheckedInObject, PropertyValues propertyValues) { vault.MetricGatherer.MethodCalled(); // TODO: error checking foreach (PropertyValue propertyValue in propertyValues) { if (vault.propertyDefs.SingleOrDefault(prop => prop.PropertyDef.ID == propertyValue.PropertyDef) == null) { throw new Exception(string.Format("Property does not exist. ({0})", propertyValue.PropertyDef)); } } List <TestObjectVersionAndProperties> thisObj = vault.ovaps.Where(obj => obj.ObjVer.ID == objVer.ID && obj.ObjVer.Type == objVer.Type).ToList(); if (thisObj.Count == 0) { throw new Exception("Object not found"); } int maxVersion = thisObj.Max(obj => obj.ObjVer.Version); if (objVer.Version != -1 && objVer.Version != maxVersion) { throw new Exception("Invalid version"); } TestObjectVersionAndProperties current = thisObj.Single(obj => obj.ObjVer.Version == maxVersion); if (!current.VersionData.ObjectCheckedOut) { if (!allowModifyingCheckedInObject) { throw new Exception("Modifying Checked In Object not allowed."); } current = ( TestObjectVersionAndProperties )current.Clone(); current.ObjVer.Version += 1; vault.ovaps.Add(current); } current.Properties = propertyValues.Clone(); return(current); }