Example #1
0
        public byte[] GetComplexObjectBytes(object obj, bool returnOnlyOID_TID)
        {
            ComplexObjectEventArgs args = new ComplexObjectEventArgs(obj, returnOnlyOID_TID);

            this.OnNeedSaveComplexObject(args);
            byte[] by         = new byte[MetaExtractor.GetAbsoluteSizeOfField(MetaExtractor.complexID)];
            byte[] complexOID = ByteConverter.IntToByteArray(args.SavedOID);
            byte[] complexTID = ByteConverter.IntToByteArray(args.TID);
            Array.Copy(complexOID, 0, by, 0, complexOID.Length);
            Array.Copy(complexTID, 0, by, 4, complexTID.Length);
            return(by);
        }
Example #2
0
        protected async Task OnNeedSaveComplexObjectAsync(ComplexObjectEventArgs args)
        {
            ComplexObjectEventHandler handler;

            lock (_syncRoot)
            {
                handler = needSaveComplexObjectAsync;
            }
            if (handler != null)
            {
                await handler(this, args).ConfigureAwait(false);
            }
        }
Example #3
0
        protected void OnNeedSaveComplexObject(ComplexObjectEventArgs args)
        {
            EventHandler <ComplexObjectEventArgs> handler;

            lock (_syncRoot)
            {
                handler = needSaveComplexObject;
            }
            if (handler != null)
            {
                handler(this, args);
            }
        }
Example #4
0
        public async Task <byte[]> GetComplexObjectBytesAsync(object obj, bool returnOnlyOID_TID)
        {
            ComplexObjectEventArgs args = new ComplexObjectEventArgs(obj, returnOnlyOID_TID);

            await this.OnNeedSaveComplexObjectAsync(args).ConfigureAwait(false);

            byte[] by         = new byte[MetaExtractor.GetAbsoluteSizeOfField(MetaExtractor.complexID)];
            byte[] complexOID = ByteConverter.IntToByteArray(args.SavedOID);
            byte[] complexTID = ByteConverter.IntToByteArray(args.TID);
            Array.Copy(complexOID, 0, by, 0, complexOID.Length);
            Array.Copy(complexTID, 0, by, 4, complexTID.Length);
            return(by);
        }
        public object ReadComplexObject(byte[] field, Type parentType, string fieldName)
        {
            byte[] oidOfComplexObjBuff = GetFieldBytes(field, 0, 4);
            int    oidOfComplexObj     = ByteConverter.ByteArrayToInt(oidOfComplexObjBuff);

            byte[] tidOfComplexObjBuff  = GetFieldBytes(field, 4, 4);
            int    tidOfComplexObj      = ByteConverter.ByteArrayToInt(tidOfComplexObjBuff);
            ComplexObjectEventArgs args = new ComplexObjectEventArgs(oidOfComplexObj, tidOfComplexObj);

            args.ParentType = parentType;
            args.FieldName  = fieldName;
            this.OnNeedReadComplexObject(args);
            return(args.ComplexObject);
        }
        public async Task <object> ReadComplexObjectAsync(byte[] field, Type parentType, string fieldName)
        {
            byte[] oidOfComplexObjBuff = GetFieldBytes(field, 0, 4);
            int    oidOfComplexObj     = ByteConverter.ByteArrayToInt(oidOfComplexObjBuff);

            byte[] tidOfComplexObjBuff  = GetFieldBytes(field, 4, 4);
            int    tidOfComplexObj      = ByteConverter.ByteArrayToInt(tidOfComplexObjBuff);
            ComplexObjectEventArgs args = new ComplexObjectEventArgs(oidOfComplexObj, tidOfComplexObj);

            args.ParentType = parentType;
            args.FieldName  = fieldName;
            await this.OnNeedReadComplexObjectAsync(args).ConfigureAwait(false);

            return(args.ComplexObject);
        }
Example #7
0
        internal async Task <byte[]> GetObjectBytesAsync(ObjectInfo oi, RawdataSerializer rawSerializer)
        {
            byte[] oidBuff = ByteConverter.IntToByteArray(oi.Oid);
            byte[] buffer  = new byte[oi.SqoTypeInfo.Header.lengthOfRecord];

            int curentIndex = 0;

            Array.Copy(oidBuff, 0, buffer, curentIndex, oidBuff.Length);
            curentIndex += oidBuff.Length;

            bool oidToParentSet = false;

            foreach (FieldSqoInfo ai in oi.AtInfo.Keys)
            {
                byte[] by = null;
                if (ai.AttributeTypeId == MetaExtractor.complexID || ai.AttributeTypeId == (MetaExtractor.ArrayTypeIDExtra + MetaExtractor.complexID) || ai.AttributeTypeId == MetaExtractor.documentID)
                {
                    //to be able to cache for circular reference, we need to asign OID to it
                    if (!oidToParentSet)
                    {
                        //just set OID to parentObject, do not save anything
                        ComplexObjectEventArgs args = new ComplexObjectEventArgs(true, oi);
                        await this.OnNeedSaveComplexObjectAsync(args).ConfigureAwait(false);

                        oidToParentSet = true;
                    }
                }
                int parentOID = -1;
                if (!oi.Inserted)
                {
                    parentOID = oi.Oid;
                }
                IByteTransformer byteTransformer = ByteTransformerFactory.GetByteTransformer(this, rawSerializer, ai, oi.SqoTypeInfo, parentOID);

                by = await byteTransformer.GetBytesAsync(oi.AtInfo[ai]).ConfigureAwait(false);

                Array.Copy(by, 0, buffer, curentIndex, by.Length);
                curentIndex += by.Length;
            }
            return(buffer);
        }