コード例 #1
0
        protected Exceptional RemoveBackwardEdges(TypeUUID myTypeUUID, Dictionary<AttributeUUID, object> myUserdefinedAttributes, ObjectUUID myObjectUUIDReference, DBContext myDBContext)
        {
            #region get type that carries the attributes

            var aType = myDBContext.DBTypeManager.GetTypeByUUID(myTypeUUID);

            #endregion

            #region process attributes

            foreach (var aUserDefinedAttribute in myUserdefinedAttributes)
            {

                #region Data

                GraphDBType typeOFAttribute = null;
                TypeAttribute attributesOfType = null;

                #endregion

                #region get GraphType of Attribute

                attributesOfType = aType.Attributes[aUserDefinedAttribute.Key];

                typeOFAttribute = myDBContext.DBTypeManager.GetTypeByUUID(attributesOfType.DBTypeUUID);

                #endregion

                IEnumerable<Exceptional<DBObjectStream>> listOfObjects;

                if (aUserDefinedAttribute.Value is IReferenceEdge)
                {
                    listOfObjects = ((IReferenceEdge)aUserDefinedAttribute.Value).GetAllEdgeDestinations(myDBContext.DBObjectCache);
                }
                else
                {
                    listOfObjects = myDBContext.DBObjectCache.LoadListOfDBObjectStreams(typeOFAttribute, (HashSet<ObjectUUID>)aUserDefinedAttribute.Value);
                }

                foreach (var aDBObject in listOfObjects)
                {
                    if (aDBObject.Failed())
                    {
                        return new Exceptional(aDBObject);
                    }

                    var removeExcept = myDBContext.DBObjectManager.RemoveBackwardEdge(aDBObject.Value, myTypeUUID, aUserDefinedAttribute.Key, myObjectUUIDReference);

                    if (removeExcept.Failed())
                    {
                        return new Exceptional(removeExcept);
                    }
                }

            }

            #endregion

            return Exceptional.OK;
        }
コード例 #2
0
ファイル: EdgeTypeSetOfReferences.cs プロジェクト: ipbi/sones
 public override void Add(ObjectUUID myValue, TypeUUID typeOfDBObjects, params ADBBaseObject[] myParameters)
 {
     if (!_ObjectUUIDs.ContainsKey(myValue))
     {
         _ObjectUUIDs.Add(myValue, new Reference(myValue, typeOfDBObjects));
     }
 }
コード例 #3
0
ファイル: INode.cs プロジェクト: TheByte/sones
        /// <summary>
        /// This will create an (mostly) empty INode
        /// </summary>
        public INode()
        {
            // Members of AGraphStructure
            _StructureVersion             = actualStructureVersion;
            _IntegrityCheckValue          = null;
            _EncryptionParameters         = null;
            ObjectUUID                    = new ObjectUUID();
            _INodePositions               = new List<ExtendedPosition>();
            _ObjectLocatorReference       = null;

            // Common attributes
            _CreationTime                 = TimestampNonce.Ticks;
            _LastAccessTime               = _CreationTime;
            _LastModificationTime         = _CreationTime;
            _DeletionTime                 = UInt64.MinValue;

            // Object Safety and Security
            _IntegrityCheckAlgorithm      = IntegrityCheckTypes.NULLAlgorithm;
            _EncryptionAlgorithm          = SymmetricEncryptionTypes.NULLAlgorithm;

            // ObjectLocatorPositions
            _ObjectLocatorLength          = 0;
            _ObjectLocatorCopies          = FSConstants.ObjectLocatorsCopies;
            _ObjectLocatorPositions       = new List<ExtendedPosition>();

            // Mark INode dirty
            isDirty                       = true;
        }
コード例 #4
0
ファイル: PathViewer.cs プロジェクト: TheByte/sones
        /// <summary>
        /// Writes an DBObject into log
        /// </summary>
        /// <param name="myObjectUUID">The UUID of the Object</param>
        /// <param name="myTypeManager">The corresponding type manager</param>
        /// <param name="myTypeAttribute">The type attribute</param>
        public static void ShowDBObject(ObjectUUID myObjectUUID, DBTypeManager myTypeManager, TypeAttribute myTypeAttribute, DBObjectCache myObjectCache)
        {
            var currentDBObject = myObjectCache.LoadDBObjectStream(myTypeAttribute.GetRelatedType(myTypeManager), myObjectUUID);

            if (currentDBObject.Failed())
                throw new NotImplementedException();
        }
コード例 #5
0
ファイル: ExpressionLevel.cs プロジェクト: TheByte/sones
        public void AddBackwardEdgesToNode(LevelKey myPath, ObjectUUID myObjectUUID, EdgeKey backwardDestination, Dictionary<ObjectUUID, ADBBaseObject> validUUIDs)
        {
            lock (_Content)
            {
                if (_Content.ContainsKey(myPath))
                {
                    //the level exists
                    if (_Content[myPath].Nodes.ContainsKey(myObjectUUID))
                    {

                        //Node exists
                        _Content[myPath].Nodes[myObjectUUID].AddBackwardEdges(backwardDestination, validUUIDs);

                    }
                    else
                    {
                        //Node does not exist
                        throw new GraphDBException(new Error_ExpressionGraphInternal(new System.Diagnostics.StackTrace(true), "The node does not exist in this LevelKey."));
                    }
                }
                else
                {
                    //LevelKey does not exist
                    throw new GraphDBException(new Error_ExpressionGraphInternal(new System.Diagnostics.StackTrace(true), "The LevelKey does not exist in this ExpressionLevel."));
                }
            }
        }
コード例 #6
0
        public override List <byte[]> DoFragment(int max_frag_length)
        {
            int           header_length    = 8 + (ObjectUUID != Guid.Empty ? 16 : 0);
            List <byte[]> fragments        = new List <byte[]>();
            int           remaining_length = StubData.Length;
            int           curr_offset      = 0;

            while (remaining_length > 0)
            {
                int          data_length = Math.Min(max_frag_length - header_length, remaining_length);
                MemoryStream stm         = new MemoryStream();
                BinaryWriter writer      = new BinaryWriter(stm);
                writer.Write(AllocHint);
                writer.Write(ContextId);
                writer.Write(OpNum);
                if (ObjectUUID != Guid.Empty)
                {
                    writer.Write(ObjectUUID.ToByteArray());
                }
                writer.Write(StubData, curr_offset, data_length);
                curr_offset      += data_length;
                remaining_length -= data_length;
                fragments.Add(stm.ToArray());
            }
            return(fragments);
        }
コード例 #7
0
ファイル: EdgeTypeSingleReference.cs プロジェクト: ipbi/sones
 public EdgeTypeSingleReference(ObjectUUID dbos, TypeUUID myTypeOfDBObject)
 {
     Debug.Assert(myTypeOfDBObject != null);
     if (dbos != null)
     {
         _ObjectUUID = new Tuple<ObjectUUID, Reference>(dbos, new Reference(dbos, myTypeOfDBObject));
     }
 }
コード例 #8
0
ファイル: Node.cs プロジェクト: TheByte/sones
        public Node()
        {
            _Key = null;

            _Parents = new HashSet<Node>();

            _Children = new HashSet<Node>();

            _AlreadyInPath = false;
        }
コード例 #9
0
ファイル: DBObjectMR.cs プロジェクト: TheByte/sones
        public DBObjectMR(DBObjectStream myDBObject, GraphDBType myDBTypeStream, DBContext myTypeManager)
        {
            _ObjectUUID = myDBObject.ObjectUUID;
            _Attributes = new Dictionary<String, Object>();

            foreach (var _Attribute in myDBTypeStream.Attributes)
            {
                _Attributes.Add(_Attribute.Value.Name, myDBObject.GetAttribute(_Attribute.Key));
            }
        }
コード例 #10
0
ファイル: BulkInsertDBO.cs プロジェクト: TheByte/sones
        /// <summary>
        /// Adds a new BackwardEdge from the current DBObject to the destination attribute identified by <paramref name="myBackwardEdgeAttribute"/>.
        /// Do not forget to call Flush() after doing all changes!
        /// </summary>
        /// <param name="myBackwardEdgeAttribute">The destination type and attribute</param>
        /// <param name="myObjectReference">The destination DBObject</param>
        /// <returns></returns>
        public BulkInsertDBO AddBackwardEdge(EdgeKey myBackwardEdgeAttribute, ObjectUUID myObjectReference)
        {
            if (_BackwardEdge == null)
                _BackwardEdge = new BackwardEdgeStream(_DBObjectStream.ObjectLocation);
            _BackwardEdge.AddBackwardEdge(myBackwardEdgeAttribute, myObjectReference, _DBContext.DBObjectManager);

            BackwardEdgesCount++;

            return this;
        }
コード例 #11
0
ファイル: AFSObject.cs プロジェクト: TheByte/sones
        /// <summary>
        /// This will set all important variables within this AFSObject.
        /// This will especially create a new ObjectUUID and mark the
        /// AFSObject as "new" and "dirty".
        /// </summary>
        public AFSObject()
        {
            _ObjectStream       = null;
            _ObjectSize         = 0;
            _ObjectSizeOnDisc   = 0;

            // Generate a new ObjectUUID
            if (ObjectUUID.Length == 0)
                ObjectUUID = new ObjectUUID();
        }
コード例 #12
0
ファイル: AFSObject.cs プロジェクト: TheByte/sones
        /// <summary>
        /// This will set all important variables within this AFSObject.
        /// Additionally it sets the ObjectUUID to the given value and marks
        /// the AFSObject as "new" and "dirty".
        /// </summary>
        public AFSObject(ObjectUUID myObjectUUID)
        {
            _ObjectStream       = null;

            _ObjectSize         = 0;
            _ObjectSizeOnDisc   = 0;

            // Members of AGraphStructure
            ObjectUUID          = myObjectUUID;
        }
コード例 #13
0
ファイル: AFSStructure.cs プロジェクト: ipbi/sones
        /// <summary>
        /// This will set all important variables within this AFSStructure.
        /// This will especially create a new ObjectUUID and mark the
        /// AGraphStructure as "new" and "dirty".
        /// </summary>
        public AFSStructure()
        {
            // Members of AGraphStructure
            _isNew                   = true;
            _StructureVersion        = 1;
            _IntegrityCheckValue     = null;
            _EncryptionParameters    = null;
            ObjectUUID               = new ObjectUUID();
            _ObjectLocatorReference  = null;

            // Members of IFastSerialize
            isDirty                  = true;
        }
コード例 #14
0
        public override void Add(ObjectUUID myValue, TypeUUID typeOfDBObjects, params ADBBaseObject[] myParameters)
        {
            if (!_ObjectUUIDs.ContainsKey(myValue))
            {
                var aReference = new Reference(myValue, typeOfDBObjects);

                _estimatedSize += aReference.GetEstimatedSize() + EstimatedSizeConstants.CalcUUIDSize(myValue);

                _ObjectUUIDs.Add(myValue, aReference);
            }
        }
コード例 #15
0
ファイル: AFSObject.cs プロジェクト: TheByte/sones
        public Exceptional Deserialize(Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, Boolean myIgnoreIntegrityCheckFailures)
        {
            #region Data

            Byte[] IntegrityCheckValue;
            int IntegrityCheckValue_Length;
            Int64 IntegrityCheckValue_Position;
            Byte[] actualIntegrityCheckValue;

            Byte[] EncryptionParameters;
            int EncryptionParameters_Length;

            int DataPadding_Length;
            int AdditionalPadding_Length = 0;

            #endregion

            #region Check if data is larger than the minimum allowed size

            if (mySerializedData == null)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            if (mySerializedData.Length < 8)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            #endregion

            try
            {

                #region Init reader

                var _SerializationReader = new SerializationReader(mySerializedData);

                #endregion

                #region Read HeaderVersion

                var _NewHeaderVersion = _SerializationReader.ReadByte();

                #endregion

                #region Read Length of the Integrity Check Value

                // Multiply the value of the first byte with 8
                IntegrityCheckValue_Length = _SerializationReader.ReadByte() << 3;

                if (IntegrityCheckValue_Length > mySerializedData.Length - HeaderLength)
                    throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is invalid!");

                // HACK: Remeber that a IntegrityCheckValue of 0 will circumvent the whole integrity checking!
                if (myIntegrityCheckAlgorithm != null)
                    if ((IntegrityCheckValue_Length > 0) && (IntegrityCheckValue_Length != myIntegrityCheckAlgorithm.HashSize))
                        throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is " + IntegrityCheckValue_Length + ", but " + myIntegrityCheckAlgorithm.HashSize + " was expected!");

                #endregion

                #region Read Length of the Encryption Parameters

                // Multiply the value of the second byte with 8
                EncryptionParameters_Length = _SerializationReader.ReadByte() << 3;

                if (EncryptionParameters_Length > mySerializedData.Length - HeaderLength - IntegrityCheckValue_Length)
                    throw new GraphFSException_InvalidEncryptionParametersLengthField("The length of the encryption parameters is invalid!");

                #endregion

                #region Read Padding lengths

                DataPadding_Length = (Int32)_SerializationReader.ReadByte();
                AdditionalPadding_Length = (Int32)(256 * _SerializationReader.ReadByte() + _SerializationReader.ReadByte()) << 3;

                if ((HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length) >= mySerializedData.Length)
                    throw new GraphFSException_InvalidAdditionalPaddingLengthField("The length of the additional padding is invalid!");

                _SerializationReader.ReadBytesDirect(2);  // Read reserved bytes

                #endregion

                #region Read Integrity Check Value and Encryption Parameters

                IntegrityCheckValue_Position = _SerializationReader.BaseStream.Position;

                if (IntegrityCheckValue_Length > 0)
                    IntegrityCheckValue = _SerializationReader.ReadBytesDirect(IntegrityCheckValue_Length);

                if (EncryptionParameters_Length > 0)
                    EncryptionParameters = _SerializationReader.ReadBytesDirect(EncryptionParameters_Length);

                #endregion

                #region Verify the integrity of the data

                if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0)
                {

                    // Save the read IntegrityCheckValue
                    IntegrityCheckValue = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue, 0, IntegrityCheckValue_Length);

                    // Zero the IntegrityCheckValue within the serialized data
                    Byte[] AllZeros = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(AllZeros, 0, mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue_Length);

                    // Calculate the actual IntegrityCheckValue
                    actualIntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(mySerializedData);

                    // Compare read and actual IntegrityCheckValue
                    if (IntegrityCheckValue.CompareByteArray(actualIntegrityCheckValue) != 0 && myIgnoreIntegrityCheckFailures == false)
                        throw new GraphFSException_IntegrityCheckFailed(String.Concat("The IntegrityCheck failed as ", actualIntegrityCheckValue.ToHexString(), " is not equal to the expected ", IntegrityCheckValue.ToHexString()));

                }

                #endregion

                #region Decrypt the remaining data

                //EncryptedData_Length      = (UInt64) (mySerializedData.Length - (HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length));
                //EncryptedData             = new Byte[EncryptedData_Length];
                //Array.Copy(mySerializedData, HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length, EncryptedData, 0, (Int64) EncryptedData_Length);

                //#endregion

                //#region Decrypt Data

                // Decrypt Data, sooon...!

                //if ( (UInt64) DataPadding_Length >= EncryptedData_Length)
                //    throw new GraphFSException_InvalidDataPaddingLengthField("The length of the data padding is invalid!");

                //DecryptedData = new Byte[EncryptedData_Length - (UInt64) DataPadding_Length];
                //Array.Copy(EncryptedData, 0, DecryptedData, 0, (Int64) (EncryptedData_Length - (UInt64) DataPadding_Length));

                #endregion

                #region Deserialize Inner Object

                _StructureVersion = BitConverter.ToUInt16(_SerializationReader.ReadBytesDirect(2), 0);
                ObjectUUID = new ObjectUUID();
                ObjectUUID.Deserialize(ref _SerializationReader); // n or at least 16 Bytes

                Deserialize(ref _SerializationReader);

                #endregion

            }

            catch (GraphFSException_IntegrityCheckFailed e)
            {
                throw new GraphFSException_IntegrityCheckFailed("The AGraphStructure could not be deserialized as its integrity is corrupted!\n\n" + e);
            }

            catch (Exception e)
            {
                throw new GraphFSException_AGraphStructureCouldNotBeDeserialized("The AGraphStructure could not be deserialized!\n\n" + e);
            }

            _SerializedAGraphStructure = mySerializedData;

            return new Exceptional();
        }
コード例 #16
0
ファイル: DBTypeManager.cs プロジェクト: TheByte/sones
 public Exceptional<DirectoryObject> GetObjectsDirectory(GraphDBType myTypeOfDBObject, ObjectUUID uuid)
 {
     return _IGraphFSSession.GetFSObject<DirectoryObject>(new ObjectLocation(myTypeOfDBObject.ObjectLocation, DBConstants.DBObjectsLocation, ObjectManager.GetDBObjectStreamShard(myTypeOfDBObject, uuid)));
 }
コード例 #17
0
ファイル: DBTypeManager.cs プロジェクト: TheByte/sones
        private Exceptional<ResultType> AddAttributeToDBObject(GraphDBType myTypeOfDBObject, ObjectUUID myUUID, AttributeUUID myAttributeUUID, IObject myAttributeValue)
        {
            //myGraphType is needed due to correctness concerning the attribute name

            #region Input exceptions

            if ((myTypeOfDBObject == null) || (myUUID == null) || (myAttributeUUID == null) || (myAttributeValue == null))
            {
                throw new ArgumentNullException();
            }

            #endregion

            #region Check GraphType for new Attribute

            TypeAttribute typeAttribute = myTypeOfDBObject.GetTypeAttributeByUUID(myAttributeUUID);

            if (typeAttribute == null)
            {
                //Todo: add notification here (the user has to be informed about the detailed circumstances)

                GraphDBError aError = new Error_AttributeIsNotDefined(myTypeOfDBObject.Name, myAttributeUUID.ToString());

                return new Exceptional<ResultType>(aError);
            }

            #endregion

            #region Data

            var objectLocation = new ObjectLocation(myTypeOfDBObject.ObjectLocation, DBConstants.DBObjectsLocation, myUUID.ToString());
            Exceptional<DBObjectStream> aNewDBObject;
            Exceptional<ResultType> result = new Exceptional<ResultType>();

            #endregion

            #region add attribute

            aNewDBObject = _DBContext.DBObjectManager.LoadDBObject(myTypeOfDBObject, myUUID);

            if (aNewDBObject.Failed())
            {
                result.PushIError(new Error_LoadObject(aNewDBObject.Value.ObjectLocation));
                return result;
            }

            result = aNewDBObject.Value.AddAttribute(typeAttribute.UUID, myAttributeValue);

            if (result.Failed())
                return result;

            try
            {
                _DBContext.DBObjectManager.FlushDBObject(aNewDBObject.Value);
            }
            catch (Exception ex)
            {
                result.PushIError(new Error_FlushObject(aNewDBObject.Value.ObjectLocation, ex));
                aNewDBObject.Value.RemoveAttribute(typeAttribute.UUID);
            }

            #endregion

            return result;
        }
コード例 #18
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
        /// <summary>
        /// Loads a DBBackwardEdge from internal cache structure or GraphFS (if it is not present in cache)
        /// </summary>
        /// <param name="myType">The Type of the DBObjects as DBTypeStream.</param>
        /// <param name="myObjectUUID">The UUID of the corresponding DBObject.</param>
        /// <returns>A BackwardEdge</returns>
        public Exceptional<BackwardEdgeStream> LoadDBBackwardEdgeStream(GraphDBType myType, ObjectUUID myObjectUUID)
        {
            ConcurrentDictionary<ObjectUUID, WeakReference> items = null;
            lock (_cachedBackwardEdges)
            {
                if (!_cachedBackwardEdges.ContainsKey(myType.UUID))
                {
                    _cachedBackwardEdges.Add(myType.UUID, new ConcurrentDictionary<ObjectUUID, WeakReference>());
                }
                items = _cachedBackwardEdges[myType.UUID];
            }

            try
            {
                if (_currentElements > _maxElements)
                {
                    if (items.ContainsKey(myObjectUUID))
                    {
                        return GetBackwardEdgeStreamViaWeakReference(myObjectUUID, myType, items[myObjectUUID]);
                    }
                    else
                    {
                        //just load from fs
                        return LoadDBBackwardEdgeInternal(myType, myObjectUUID);
                    }
                }
                else
                {
                    var aWeakReference = items.GetOrAdd(myObjectUUID, (aObjectUUID) =>
                    {
                        //DBObject must be loaded from GraphFS
                        var tempResult = LoadDBBackwardEdgeInternal(myType, aObjectUUID);

                        if (tempResult.Failed())
                        {
                            throw new GraphDBException(tempResult.IErrors);
                        }

                        Interlocked.Increment(ref _currentElements);

                        return new WeakReference(tempResult);
                    });

                    return GetBackwardEdgeStreamViaWeakReference(myObjectUUID, myType, aWeakReference);
                }
            }
            catch (GraphDBException ex)
            {
                return new Exceptional<BackwardEdgeStream>(ex.GraphDBErrors);
            }
        }
コード例 #19
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
        /// <summary>
        /// Internal method for loading a DBObject from GraphFS.
        /// </summary>
        /// <param name="myType">The Type of the DBObjects as GraphType.</param>
        /// <param name="myObjectUUID">The UUID of the DBObject.</param>
        /// <returns>An DBObject</returns>
        private Exceptional<DBObjectStream> LoadDBObjectInternal(GraphDBType myType, ObjectUUID myObjectUUID)
        {
            var tempResult = _DBObjectManager.LoadDBObject(myType, myObjectUUID);

            #region Try all subTypes - as long as the Symlink alternativ does not work

            if (tempResult.Failed())
            {

                var exceptional = new Exceptional<DBObjectStream>(tempResult);

                #region Try sub types

                foreach (var type in _typeManager.GetAllSubtypes(myType, false))
                {
                    tempResult = LoadDBObjectInternal(type, myObjectUUID);
                    if (tempResult.Success())
                        break;
                    else
                        exceptional = new Exceptional<DBObjectStream>(tempResult);
                }

                #endregion

                if (tempResult.Failed())
                    return exceptional;
            }

            #endregion

            return tempResult;
        }
コード例 #20
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
 /// <summary>
 /// Internal method for loading a DBObject from GraphFS.
 /// </summary>
 /// <param name="myType">The Type of the DBObjects as TypeUUID.</param>
 /// <param name="myObjectUUID">The UUID of the DBObject.</param>
 /// <returns>An DBObject</returns>
 private Exceptional<DBObjectStream> LoadDBObjectInternal(TypeUUID myType, ObjectUUID myObjectUUID)
 {
     return LoadDBObjectInternal(_typeManager.GetTypeByUUID(myType), myObjectUUID);
 }
コード例 #21
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
 /// <summary>
 /// Internal method for loading a DBBackwardEdge from GraphFS. 
 /// </summary>
 /// <param name="myType">The Type of the DBObjects as GraphType.</param>
 /// <param name="myObjectUUID">The UUID of the corresponding DBObject.</param>
 /// <returns>A BackwardEdge</returns>
 private Exceptional<BackwardEdgeStream> LoadDBBackwardEdgeInternal(GraphDBType myType, ObjectUUID myObjectUUID)
 {
     return _DBObjectManager.LoadBackwardEdge(new ObjectLocation(myType.ObjectLocation, DBConstants.DBObjectsLocation, myObjectUUID.ToString()));
 }
コード例 #22
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
 /// <summary>
 /// Internal method for loading a DBBackwardEdge from GraphFS. 
 /// </summary>
 /// <param name="myType">The Type of the DBObjects as TypeUUID.</param>
 /// <param name="myObjectUUID">The UUID of the corresponding DBObject.</param>
 /// <returns>A BackwardEdge</returns>
 private Exceptional<BackwardEdgeStream> LoadDBBackwardEdgeInternal(TypeUUID myType, ObjectUUID myObjectUUID)
 {
     return LoadDBBackwardEdgeInternal(_typeManager.GetTypeByUUID(myType), myObjectUUID);
 }
コード例 #23
0
ファイル: DBObjectManager.cs プロジェクト: ipbi/sones
 public Exceptional<Boolean> AddBackwardEdge(DBObjectStream aDBObject, TypeUUID uUIDofType, AttributeUUID uUIDofAttribute, ObjectUUID reference)
 {
     return aDBObject.AddBackwardEdge(uUIDofType, uUIDofAttribute, reference, _DBContext.DBObjectManager);
 }
コード例 #24
0
ファイル: DBObjectManager.cs プロジェクト: ipbi/sones
 public Exceptional<DBObjectStream> LoadDBObject(GraphDBType myGraphDBType, ObjectUUID myObjectUUID, String myNameOfType)
 {
     return LoadDBObject(new ObjectLocation(myGraphDBType.ObjectLocation, DBConstants.DBObjectsLocation, myObjectUUID.ToString()));
 }
コード例 #25
0
 public override Boolean RemoveUUID(ObjectUUID myValue)
 {
     return _ObjectUUIDs.Remove(myValue);
 }
コード例 #26
0
ファイル: DBObjectManager.cs プロジェクト: ipbi/sones
        /// <summary>
        /// Loads a DBObject from filesystem.
        /// </summary>
        /// <param name="myGraphType">The GraphType of the DBObject (for path resolution).</param>
        /// <param name="myObjectUUID">The unique identifier of the DBObject</param>
        /// <returns>The requested DBObject or null.</returns>
        public Exceptional<DBObjectStream> LoadDBObject(GraphDBType myGraphDBType, ObjectUUID myObjectUUID)
        {
            if (myObjectUUID == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("ObjectUUID should not be null."));

            if(myGraphDBType == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("DBType should not be null."));

            return LoadDBObject(myGraphDBType, myObjectUUID, myGraphDBType.Name);
        }
コード例 #27
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
 /// <summary>
 /// Loads a DBObject from internal cache structure or GraphFS (if it is not present in cache)
 /// </summary>
 /// <param name="myType">The type of the DBObject as TypeUUID.</param>
 /// <param name="myObjectUUID">The UUID of the DBObject.</param>
 /// <returns>A DBObject.</returns>
 public Exceptional<DBObjectStream> LoadDBObjectStream(TypeUUID myType, ObjectUUID myObjectUUID)
 {
     return LoadDBObjectStream(_typeManager.GetTypeByUUID(myType), myObjectUUID);
 }
コード例 #28
0
ファイル: DBObjectManager.cs プロジェクト: ipbi/sones
        internal Exceptional AddBackwardEdge(ObjectUUID uuid, TypeUUID typeOfBESource, EdgeKey beEdgeKey, ObjectUUID reference)
        {
            //var beLocation = DBObjectStream.GetObjectLocation(_DBContext.DBTypeManager.GetTypeByUUID(typeOfBESource), uuid);
            var loadExcept = _DBContext.DBObjectCache.LoadDBBackwardEdgeStream(typeOfBESource, uuid); // LoadBackwardEdge(beLocation);

            if (loadExcept.Failed())
            {
                return new Exceptional(loadExcept);
            }

            //EdgeKey tempKey = new EdgeKey(typeUUID, attributeUUID);
            loadExcept.Value.AddBackwardEdge(beEdgeKey, reference, this);
            if (loadExcept.Value.isNew)
            {
                return _IGraphFSSession.StoreFSObject(loadExcept.Value, true);
            }
            else
            {
                return loadExcept.Value.Save();
            }
        }
コード例 #29
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
        private Exceptional<BackwardEdgeStream> GetBackwardEdgeStreamViaWeakReference(ObjectUUID myObjectUUID, GraphDBType myType, WeakReference weakReference)
        {
            var aBackwardEdge = weakReference.Target as Exceptional<BackwardEdgeStream>;
            if (aBackwardEdge == null)
            {
                // Object was reclaimed, so get it again
                aBackwardEdge = LoadDBBackwardEdgeInternal(myType, myObjectUUID);
            }

            return aBackwardEdge;
        }
コード例 #30
0
ファイル: DBObjectManager.cs プロジェクト: ipbi/sones
        /// <summary>
        /// Creates a new DBObject of a given GraphType inserts its UUID into all indices of the given GraphType.
        /// </summary>
        /// <param name="myGraphDBType">The GraphType of the DBObject to create</param>
        /// <param name="myDBObjectAttributes">A dictionary of attributes for the new DBObject</param>
        /// <param name="mySpecialTypeAttributes">Special values which should be set to a object</param>
        /// <param name="myCheckUniqueness">check for unique constraints</param> 
        /// <returns>The UUID of the new DBObject</returns>
        public Exceptional<DBObjectStream> CreateNewDBObjectStream(GraphDBType myGraphDBType, Dictionary<AttributeUUID, IObject> myDBObjectAttributes, Dictionary<String, IObject> myUndefAttributes, Dictionary<ASpecialTypeAttribute, Object> mySpecialTypeAttributes, SessionSettings mySessionSettings, Boolean myCheckUniqueness)
        {
            #region Input validation

            if (myGraphDBType == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("The parameter myGraphType must not be null!"));

            if (myDBObjectAttributes == null)
                return new Exceptional<DBObjectStream>(new Error_ArgumentNullOrEmpty("The parameter myDBObjectAttributes must not be null!"));

            #endregion

            #region Check uniqueness

            if (myCheckUniqueness)
            {

                var parentTypes = _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false);
                var CheckVal = _DBContext.DBIndexManager.CheckUniqueConstraint(myGraphDBType, parentTypes, myDBObjectAttributes);

                if (CheckVal.Failed())
                    return new Exceptional<DBObjectStream>(CheckVal);

            }

            #endregion

            #region Create a new DBObjectStream

            DBObjectStream        _NewDBObjectStream               = null;
            ObjectUUID            _NewObjectUUID                   = null;
            ASpecialTypeAttribute _SpecialTypeAttribute_UUID_Key   = new SpecialTypeAttribute_UUID();
            Object                _SpecialTypeAttribute_UUID_Value = null;

            #region Search for an user-defined ObjectUUID

            if (mySpecialTypeAttributes != null)
            {
                if (mySpecialTypeAttributes.TryGetValue(_SpecialTypeAttribute_UUID_Key, out _SpecialTypeAttribute_UUID_Value))
                {

                    // User-defined ObjectUUID of type UInt64
                    var _ValueAsUInt64 = _SpecialTypeAttribute_UUID_Value as UInt64?;
                    if (_ValueAsUInt64 != null)
                        _NewObjectUUID = new ObjectUUID(_ValueAsUInt64.Value);

                    // User-defined ObjectUUID of type String or anything else...
                    else
                    {

                        var _String = _SpecialTypeAttribute_UUID_Value.ToString();
                        if (_String == null || _String == "")
                            return new Exceptional<DBObjectStream>(new Error_InvalidAttributeValue(SpecialTypeAttribute_UUID.AttributeName, _String));

                        _NewObjectUUID = new ObjectUUID(_SpecialTypeAttribute_UUID_Value.ToString());

                    }

                    mySpecialTypeAttributes[_SpecialTypeAttribute_UUID_Key] = _NewObjectUUID;

                }
            }

            #endregion

            // If _NewObjectUUID == null a new one will be generated!
            _NewDBObjectStream                = new DBObjectStream(_NewObjectUUID, myGraphDBType, myDBObjectAttributes);
            _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

            #endregion

            #region Check for duplicate ObjectUUIDs... maybe resolve duplicates!

            var _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

            if (_DBObjectStreamAlreadyExistsResult.Failed())
                return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            while (_DBObjectStreamAlreadyExistsResult.Value == Trinary.TRUE)
            {

                if (_NewObjectUUID != null)
                    return new Exceptional<DBObjectStream>(new Error_DBObjectCollision(_NewDBObjectStream));

                _NewDBObjectStream                = new DBObjectStream(ObjectUUID.NewUUID, myGraphDBType, myDBObjectAttributes);
                _NewDBObjectStream.ObjectLocation = new ObjectLocation(_NewDBObjectStream.ObjectPath, _NewDBObjectStream.ObjectUUID.ToString());

                _DBObjectStreamAlreadyExistsResult = ObjectExistsOnFS(_NewDBObjectStream);

                if (_DBObjectStreamAlreadyExistsResult.Failed())
                    return new Exceptional<DBObjectStream>(_DBObjectStreamAlreadyExistsResult);

            }

            #endregion

            #region Check for ExtractSetting attributes unlike UUID

            if (mySpecialTypeAttributes != null && mySpecialTypeAttributes.Any())
            {
                foreach (var _SpecialAttribute in mySpecialTypeAttributes)
                {
                    // Skip SpecialTypeAttribute_UUID!
                    if (!(_SpecialAttribute.Key is SpecialTypeAttribute_UUID))
                    {
                        var result = _SpecialAttribute.Key.ApplyTo(_NewDBObjectStream, _SpecialAttribute.Value);
                        if (result.Failed())
                        {
                            return new Exceptional<DBObjectStream>(result);
                        }
                    }
                }
            }

            #endregion

            // Flush new DBObject
            var flushResult = FlushDBObject(_NewDBObjectStream);

            if (flushResult.Failed())
                return new Exceptional<DBObjectStream>(flushResult);

            #region Check for existing object - might be removed at some time

            //var exists = ObjectExistsOnFS(_NewDBObjectStream);

            //if (exists.Failed())
            //    return new Exceptional<DBObjectStream>(exists);

            //if (exists.Value != Trinary.TRUE)
            //{
            //    return new Exceptional<DBObjectStream>(new Error_UnknownDBError("DBObject with path " + _NewDBObjectStream.ObjectLocation + " does not exist."));
            //}

            #endregion

            #region Add UUID of the new DBObject to all indices of myGraphType

            foreach (var _GraphDBType in _DBContext.DBTypeManager.GetAllParentTypes(myGraphDBType, true, false))
            {
                foreach (var _AAttributeIndex in _GraphDBType.GetAllAttributeIndices(false))
                {
                    //Find out if the dbobject carries all necessary attributes
                    if (_NewDBObjectStream.HasAtLeastOneAttribute(_AAttributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs, _GraphDBType, mySessionSettings))
                    {
                        //valid dbo for idx
                        _AAttributeIndex.Insert(_NewDBObjectStream, _GraphDBType, _DBContext);
                    }
                }
            }

            #endregion

            #region add undefined attributes to the object

            if (!myUndefAttributes.IsNullOrEmpty())
            {
                foreach (var item in myUndefAttributes)
                {
                    var addExcept = _NewDBObjectStream.AddUndefinedAttribute(item.Key, item.Value, this);

                    if (addExcept.Failed())
                    {
                        return new Exceptional<DBObjectStream>(addExcept);
                    }
                }
            }

            #endregion

            return new Exceptional<DBObjectStream>(_NewDBObjectStream);
        }
コード例 #31
0
ファイル: DBObjectCache.cs プロジェクト: ipbi/sones
        private Exceptional<DBObjectStream> GetDBObjectStreamViaWeakReference(ObjectUUID uuidOfDBObject, GraphDBType typeOfDBObject, WeakReference wrDBObject)
        {
            var aDBO = wrDBObject.Target as Exceptional<DBObjectStream>;
            if (aDBO == null)
            {
                // Object was reclaimed, so get it again
                aDBO = LoadDBObjectInternal(typeOfDBObject, uuidOfDBObject);

                wrDBObject.Target = aDBO;
            }

            return aDBO;
        }