private static void InformAffectedObjects(List <DependencyInfo> dependenciesInfo, string dependentTypeInfo) { if (dependenciesInfo == null || dependenciesInfo.Count == 0) { // Nothing to do. return; } foreach (var dependencyInfo in dependenciesInfo) { ObjectDto principalObj = OdCepManager.Versioning.GetHeadVersion(dependencyInfo.PrincipalObjectType, dependencyInfo.PrincipalObjectUuid); ObjectDto dependentObj = OdCepManager.Versioning.GetHeadVersion(dependencyInfo.DependentObjectType, dependencyInfo.DependentObjectUuid); dependentObj.VersionIndex++; dependentObj.SuspendNotifications = true; #if USE_ASYNC_FOR_DISPATCH Task <ObjectDto> task = DispatchToObject(dependentObj.OnPrincipalObjectUpdated, principalObj, dependencyInfo.OptionalArg); ObjectDto newDependentObj = task.Result; #else ObjectDto newDependentObj = dependentObj.OnPrincipalObjectUpdated(principalObj, effectInfo.OptionalArg); #endif dependentObj.SuspendNotifications = false; string c = string.Format(LocalConst.AUTO_SAVE_COMMENT_PRINCIPAL_MODF_TEMPLATE, dependentTypeInfo); ObjectStore.AutoSaveExistingObject(newDependentObj, c); } foreach (var dependencyInfo in dependenciesInfo) { ObjectDto objectDto = (ObjectDto)Activator.CreateInstance(dependencyInfo.PrincipalObjectType); InformAllDependents(dependencyInfo.DependentObjectUuid, objectDto.WhoAmI()); } }
public static bool AddObjectDependency(string principalObjUuid, string principalType, string dependentObjUuid, string dependentType, string optionalArg) { bool success = _persistentObj.AddObjectDependency(principalObjUuid, dependentObjUuid, principalType, dependentType, optionalArg); ObjectDto principalObj = OdCepManager.Versioning.GetHeadVersion(Type.GetType(principalType), principalObjUuid, out string comment); ObjectDto dependentObj = OdCepManager.Versioning.GetHeadVersion(Type.GetType(dependentType), dependentObjUuid, out comment); ObjectDto updatedObj = dependentObj.OnPrincipalObjectUpdated(principalObj, optionalArg); updatedObj.VersionIndex++; string c = string.Format(LocalConst.AUTO_SAVE_COMMENT_PRINCIPAL_MODF_TEMPLATE, principalObj.WhoAmI()); ObjectStore.AutoSaveExistingObject(updatedObj, c); return(success); }
public static bool SaveExistingObject(ObjectDto persistObj, string comment, out string result) { string objUuid = persistObj.Uuid; if (!_persistentObj.ObjectExists(objUuid)) { result = LocalConst.ERR_NON_EXISTENT_OBJ; return(false); } // Here we need to check the current unique index value for this object and compare it to the // passed, modified object. There can be any one of two possible outcomes: // a. Both values are the same; or // b. Both values are different. // Case (b) first. If it's case (b), we will need to check if it isn't clashing with any other // object's index value. If it is, we fail and inform the caller as much, else we go ahead. // In case (a), we will again need to figure out one of the two sub-possibilities: // Both values are the same because: // i. Another property of the object is being changed; or // ii. The object is being passed as is. // In case (i), we will check the JSON of the existing object to figure out if the two objects // are the same or different. If they are different, we save, else we merely return a true, // without adding a record. // In the latter case (ii), we save because indeed some value seems to have been changed. Type objectType = persistObj.GetType(); string currentJson = Jsonizer.Serialize(persistObj); string existingJson = _persistentObj.RetrieveObjectJsonHeadVersion(persistObj.Uuid, out string existingComment); ObjectDto existingPersistObject = Jsonizer.Deserialize(existingJson, objectType); existingPersistObject.VersionIndex++; // At this point, we have the existing object. var props = objectType.GetProperties().Where( prop => Attribute.IsDefined(prop, typeof(UniqueAttribute))); PropertyInfo propertyToBeIndexed = null; foreach (var p in props) { propertyToBeIndexed = p; // There is only one unique property allowed per class. // So we can safely break: break; } string propertyValueToBeIndexed = (string)propertyToBeIndexed.GetValue(persistObj); string propertyValueCurrentlyIndexed = (string)propertyToBeIndexed.GetValue(existingPersistObject); // At this point, we have the two values: the unique index value for this object that needs to be indexed, // and the same property value that is currently indexed. // Question: Are both values the same? if (propertyValueToBeIndexed.Equals(propertyValueCurrentlyIndexed)) { // Answer: Both are the same, so we check for sub-possibilities (i) and (ii): if (JsonUtil.AreObjectsIdentical(currentJson, existingJson)) { // No change in the object, so we return true: result = LocalConst.INFO_NO_MODF; return(true); } else { // Another property within the object has been changed, so we go ahead. // Do nothing here. } } else { // Answer: Both values are *not* the same. So we do a regular check: if (ObjectIndexer.UniquePropertyValueExists(persistObj)) { result = LocalConst.ERR_DUPLICATE_VALUE; return(false); } else { // No clash of unique index value with that of any other object. // Do nothing here. } } // Version numbers are *always* zero-indexed! long versionNumber = _persistentObj.GetObjectLastVersionNumber(objUuid) + 1; persistObj.WhenAdded = DateTime.Now; string json = Jsonizer.Serialize(persistObj); // Save the versioned object: _persistentObj.PersistObjectAsVersion(objUuid, json, versionNumber, comment); // Closing tasks: ObjectIndexer.IndexObject(persistObj); ObjectDependencyStore.InformAllDependents(objUuid, persistObj.WhoAmI()); result = LocalConst.ERR_SUCCESS; return(true); }