Exemplo n.º 1
0
        /// <summary>
        /// 实体中的数据被修改后调用本方法更新实体的持久化状态
        /// </summary>
        public void Modify()
        {
            switch (this._status)
            {
            case PersistenceStatus.Temporary:
                throw new PersistenceEntityException("实体未加载数据,没有数据可修改.");

            case PersistenceStatus.Read:
                this._status = PersistenceStatus.Dirty;
                break;

            case PersistenceStatus.Dirty:
            case PersistenceStatus.New:
                break;

            case PersistenceStatus.Delete:
                throw new PersistenceEntityException("实体被删除,无法修改.");

            case PersistenceStatus.Destory:
                throw new PersistenceEntityException("实体被销毁,无法修改.");

            default:
                throw new PersistenceEntityException(string.Format("未知的实体持久化状态{0}.", this._status.ToString()));
            }
        }
Exemplo n.º 2
0
 private void SetStatus(IList <Entity> list, PersistenceStatus value)
 {
     for (int j = 0, jc = list.Count; j < jc; j++)
     {
         list[j].PersistenceStatus = value;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 设置整个聚合为指定的状态。
 /// </summary>
 /// <param name="status">The status.</param>
 void IDirtyAware.MarkAggregate(PersistenceStatus status)
 {
     for (int i = 0, c = this.Count; i < c; i++)
     {
         var child = this[i] as IDirtyAware;
         child.MarkAggregate(status);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 设置整个聚合为指定的状态。
 /// </summary>
 /// <param name="status">The status.</param>
 void IDirtyAware.MarkAggregate(PersistenceStatus status)
 {
     if (_nodes != null)
     {
         for (int i = 0, c = _nodes.Count; i < c; i++)
         {
             var child = _nodes[i];
             (child as IDirtyAware).MarkAggregate(status);
         }
     }
 }
Exemplo n.º 5
0
        void IDirtyAware.MarkAggregate(PersistenceStatus status)
        {
            this.PersistenceStatus = status;

            foreach (var child in this.GetLoadedChildren())
            {
                child.Value.MarkAggregate(status);
            }

            if (_treeChildren != null)
            {
                (_treeChildren as IDirtyAware).MarkAggregate(status);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更改实体的状态
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="persistenceStatus"></param>
        private void ChangeEntityPersistenceStatus(IList <Entity> entityList, PersistenceStatus persistenceStatus)
        {
            entityList.ForEach(item => item.PersistenceStatus = persistenceStatus);

            foreach (var entity in entityList)
            {
                foreach (var childField in entity.GetLoadedChildren())
                {
                    var children = childField.Value as EntityList;
                    if (children != null && children.Count > 0)
                    {
                        ChangeEntityPersistenceStatus(children, persistenceStatus);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 持久化实体后调用本方法更新实体的持久化状态
        /// </summary>
        public virtual void Save()
        {
            switch (this._status)
            {
            case PersistenceStatus.Temporary:
                throw new PersistenceEntityException("临时状态的实体无法持久化.");

            case PersistenceStatus.Read:
                break;

            case PersistenceStatus.Dirty:
            case PersistenceStatus.New:
                this._status = PersistenceStatus.Read;
                break;

            case PersistenceStatus.Destory:
                throw new PersistenceEntityException("销毁状态的实体无法持久化.");

            default:
                throw new PersistenceEntityException(string.Format("未知的实体持久化状态{0}.", this._status.ToString()));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 删除实体时调用本方法更新实体的持久化状态。
        /// </summary>
        public virtual void Delete()
        {
            switch (this._status)
            {
            case PersistenceStatus.Temporary:
                throw new PersistenceEntityException("实体未加载数据,无法删除.");

            case PersistenceStatus.Read:
            case PersistenceStatus.Dirty:
                this._status = PersistenceStatus.Delete;
                break;

            case PersistenceStatus.New:
                this._status = PersistenceStatus.Destory;
                break;

            case PersistenceStatus.Destory:
                break;

            default:
                throw new PersistenceEntityException(string.Format("未知的实体持久化状态{0}.", this._status.ToString()));
            }
        }
Exemplo n.º 9
0
        private void DeliveryReportCallbackImpl(IntPtr rk, IntPtr rkmessage, IntPtr opaque)
        {
            // Ensure registered handlers are never called as a side-effect of Dispose/Finalize (prevents deadlocks in common scenarios).
            if (ownedKafkaHandle.IsClosed)
            {
                return;
            }

            var msg = Util.Marshal.PtrToStructure <rd_kafka_message>(rkmessage);

            // the msg._private property has dual purpose. Here, it is an opaque pointer set
            // by Topic.Produce to be an IDeliveryHandler. When Consuming, it's for internal
            // use (hence the name).
            if (msg._private == IntPtr.Zero)
            {
                // Note: this can occur if the ProduceAsync overload that accepts a DeliveryHandler
                // was used and the delivery handler was set to null.
                return;
            }

            var gch             = GCHandle.FromIntPtr(msg._private);
            var deliveryHandler = (IDeliveryHandler)gch.Target;

            gch.Free();

            Headers headers = null;

            if (this.enableDeliveryReportHeaders)
            {
                headers = new Headers();
                Librdkafka.message_headers(rkmessage, out IntPtr hdrsPtr);
                if (hdrsPtr != IntPtr.Zero)
                {
                    for (var i = 0; ; ++i)
                    {
                        var err = Librdkafka.header_get_all(hdrsPtr, (IntPtr)i, out IntPtr namep, out IntPtr valuep, out IntPtr sizep);
                        if (err != ErrorCode.NoError)
                        {
                            break;
                        }
                        var    headerName  = Util.Marshal.PtrToStringUTF8(namep);
                        byte[] headerValue = null;
                        if (valuep != IntPtr.Zero)
                        {
                            headerValue = new byte[(int)sizep];
                            Marshal.Copy(valuep, headerValue, 0, (int)sizep);
                        }
                        headers.Add(headerName, headerValue);
                    }
                }
            }

            IntPtr timestampType = (IntPtr)TimestampType.NotAvailable;
            long   timestamp     = 0;

            if (enableDeliveryReportTimestamp)
            {
                timestamp = Librdkafka.message_timestamp(rkmessage, out timestampType);
            }

            PersistenceStatus messageStatus = PersistenceStatus.PossiblyPersisted;

            if (enableDeliveryReportPersistedStatus)
            {
                messageStatus = Librdkafka.message_status(rkmessage);
            }

            deliveryHandler.HandleDeliveryReport(
                new DeliveryReport <Null, Null>
            {
                // Topic is not set here in order to avoid the marshalling cost.
                // Instead, the delivery handler is expected to cache the topic string.
                Partition = msg.partition,
                Offset    = msg.offset,
                Error     = KafkaHandle.CreatePossiblyFatalError(msg.err, null),
                Status    = messageStatus,
                Message   = new Message <Null, Null> {
                    Timestamp = new Timestamp(timestamp, (TimestampType)timestampType), Headers = headers
                }
            }
                );
        }
Exemplo n.º 10
0
 private void PublishResults(PersistenceStatus status, Headers headers)
 {
     if (status == PersistenceStatus.Persisted)
     {
         if (headers.TryGetLastBytes(HeaderNames.MESSAGE_ID, out byte[] messageIdBytes))
Exemplo n.º 11
0
 private void SetStatus(IList<Entity> list, PersistenceStatus value)
 {
     for (int j = 0, jc = list.Count; j < jc; j++)
     {
         list[j].PersistenceStatus = value;
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// 在内存中创建新的实体实例时调用本方法更新实体的持久化状态。
 /// </summary>
 public virtual void New()
 {
     this._status = PersistenceStatus.New;
 }
Exemplo n.º 13
0
 /// <summary>
 /// 实体从DB中加载了数据后调用本方法更新实体的持久化状态
 /// </summary>
 public void Load()
 {
     this._status = PersistenceStatus.Read;
 }