コード例 #1
0
ファイル: ObjectDto.cs プロジェクト: najeeb1010/ObjectStore
        public bool DeletePrincipalDependency(ObjectDto principal)
        {
            if (!ObjectStore.ObjectExists(principal.Uuid) || !ObjectStore.ObjectExists(Uuid))
            {
                return(false);
            }

            return(ObjectDependencyStore.RemoveObjectDependency(principal.Uuid, Uuid));
        }
コード例 #2
0
ファイル: ObjectDto.cs プロジェクト: najeeb1010/ObjectStore
        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
                       ));
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: ObjectDto.cs プロジェクト: najeeb1010/ObjectStore
 public bool PrincipalDependencyExists(ObjectDto principal)
 {
     return(ObjectDependencyStore.ObjectDependencyExists(principal.Uuid, Uuid));
 }