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());
            }
        }
示例#2
0
        public static bool SaveNewObject(ObjectDto persistObj, string comment, out string result)
        {
            string objUuid = persistObj.Uuid;

            if (_persistentObj.ObjectExists(objUuid))
            {
                result = LocalConst.ERR_EXISTENT_OBJ;
                return(false);
            }

            if (ObjectIndexer.UniquePropertyValueExists(persistObj))
            {
                result = LocalConst.ERR_DUPLICATE_VALUE;
                return(false);
            }

            persistObj.WhenAdded = DateTime.Now;
            string json = Jsonizer.Serialize(persistObj);

            // First time this object is being persisted.
            _persistentObj.AddObjectFirstRecord(objUuid);

            // Version numbers are *always* zero-indexed!
            long versionNumber = 0;

            _persistentObj.PersistObjectAsVersion(objUuid, json, versionNumber, comment ?? string.Empty);

            // Closing tasks:
            ObjectIndexer.IndexObject(persistObj);

            result = LocalConst.ERR_SUCCESS;
            return(true);
        }
示例#3
0
        public bool DeletePrincipalDependency(ObjectDto principal)
        {
            if (!ObjectStore.ObjectExists(principal.Uuid) || !ObjectStore.ObjectExists(Uuid))
            {
                return(false);
            }

            return(ObjectDependencyStore.RemoveObjectDependency(principal.Uuid, Uuid));
        }
示例#4
0
        public bool AddPrincipalDependency(ObjectDto principal, string optionalArg = null)
        {
            if (!ObjectStore.ObjectExists(principal.Uuid) || !ObjectStore.ObjectExists(Uuid))
            {
                return(false);
            }

            return(ObjectDependencyStore.AddObjectDependency(
                       principal.Uuid, principal.GetType().AssemblyQualifiedName,
                       Uuid, GetType().AssemblyQualifiedName, optionalArg
                       ));
        }
        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);
        }
示例#6
0
        public static void IndexObject(ObjectDto persistObj)
        {
            var t = persistObj.GetType();

            var props = t.GetProperties().Where(
                prop => Attribute.IsDefined(prop, typeof(UniqueAttribute)));

            PropertyInfo propertyToBeUniquelyIndexed = null;

            foreach (var p in props)
            {
                propertyToBeUniquelyIndexed = p;
                // There is only one unique property allowed per class.
                // So we can safely break:
                break;
            }

            object propertyValueToBeIndexed = propertyToBeUniquelyIndexed.GetValue(persistObj);

            _persistentObj.DeletePreviousIndex(persistObj.Uuid);
            _persistentObj.IndexObject(persistObj.GetType().AssemblyQualifiedName, persistObj.Uuid, propertyValueToBeIndexed.ToString());
        }
示例#7
0
        public static bool UniquePropertyValueExists(ObjectDto persistObj)
        {
            Type objectType = persistObj.GetType();

            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;
            }

            if (propertyToBeIndexed == null)
            {
                return(false);
            }

            object propertyValueToBeIndexed = propertyToBeIndexed.GetValue(persistObj);

            string val = null;

            if (propertyValueToBeIndexed.GetType() == typeof(ObjectDto))
            {
                val = (propertyValueToBeIndexed as ObjectDto).WhoAmI();
            }
            else
            {
                val = ((object)propertyValueToBeIndexed).ToString();
            }

            return(_persistentObj.UniquePropertyValueExists(objectType.AssemblyQualifiedName, val));
        }
        static async Task <ObjectDto> DispatchToObject(OnPrincipalObjectUpdated onPrincipalObjectUpdated, ObjectDto dependentObj, string optionalArg)
        {
            Task <ObjectDto> task = Task <ObjectDto> .Factory.StartNew(() => {
                return(onPrincipalObjectUpdated(dependentObj, optionalArg));
            });

            return(await task);
        }
 public static string Serialize(ObjectDto objectDto)
 {
     return(JsonConvert.SerializeObject(objectDto));
 }
示例#10
0
        internal static bool AutoSaveExistingObject(ObjectDto persistObj, string comment)
        {
            string objUuid = persistObj.Uuid;

            // We can skip this check: if the object did not already exist, we wouldn't have been here, anyway.

            /*if (!_persistentObj.ObjectExists (objUuid)) {
             *  return false;
             * }*/

            // We will save the object afresh for maintaining the object's history, even if it remains unmodified,
            // especially when it is getting auto-modified and auto-saved.

            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 are 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))
                {
                    // We *do* save the new object even if it is identical to the last one (for the reason cited above),
                    //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))
                {
                    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);

            return(true);
        }
示例#11
0
        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);
        }
示例#12
0
#pragma warning restore 0168

        public abstract ObjectDto OnPrincipalObjectUpdated(ObjectDto updatedPrincipalObj, string optionalArg);
示例#13
0
 public bool PrincipalDependencyExists(ObjectDto principal)
 {
     return(ObjectDependencyStore.ObjectDependencyExists(principal.Uuid, Uuid));
 }
示例#14
0
 public NotifierList(ObjectDto dtoObject, IEnumerable <T> items) : base(items)
 {
     _dtoObject = dtoObject;
 }
示例#15
0
 public NotifierList(ObjectDto dtoObject, int capacity) : base(capacity)
 {
     _dtoObject = dtoObject;
 }
示例#16
0
 public NotifierList(ObjectDto dtoObject) : base()
 {
     _dtoObject = dtoObject;
 }