protected internal virtual byte[] ReadSerializedValueFromFields(IValueFields valueFields) { if (valueFields.ByteArrayValue == null && !string.IsNullOrEmpty(valueFields.ByteArrayId)) { if (context.Impl.Context.CommandContext != null) { var bytearr = context.Impl.Context.CommandContext.ByteArrayManager.Get(valueFields.ByteArrayId); valueFields.ByteArrayValue = bytearr.Bytes; } else { using (IScope scope = ObjectContainer.BeginLifetimeScope()) { IByteArrayManager manager = scope.Resolve <IByteArrayManager>(); var bytearr = manager.Get(valueFields.ByteArrayId); valueFields.ByteArrayValue = bytearr.Bytes; } } } return(valueFields.ByteArrayValue); }
public virtual void SetByteArrayValue(byte[] bytes) { if (bytes != null) { if (byteArrayId != null && ResourceEntity != null) { byteArrayValue.Bytes = bytes; } else { DeleteByteArrayValue(); //TODO 每次新建ResourceEntity? if (Context.CommandContext != null) { byteArrayValue = new ResourceEntity(NameProvider.Name, bytes); Context.CommandContext.ByteArrayManager.Add(byteArrayValue); byteArrayId = byteArrayValue.Id; } else//TODO 不在cmd中 { using (IScope scope = ObjectContainer.BeginLifetimeScope()) { IByteArrayManager manager = scope.Resolve <IByteArrayManager>(); byteArrayValue = new ResourceEntity(NameProvider.Name, bytes); var bytearr = manager.Add(byteArrayValue); byteArrayId = byteArrayValue.Id; } //throw new System.NotImplementedException("CommandContext is null"); } } } else { DeleteByteArrayValue(); } }
public AttachmentManager(DbContext dbContex, ILoggerFactory loggerFactory, IByteArrayManager byteArrayManager, IDGenerator idGenerator) : base(dbContex, loggerFactory, idGenerator) { _byteArrayManager = byteArrayManager; }