public static string ToIdString(SupplierProductId id)
        {
            var formatter = (new ValueObjectTextFormatter <SupplierProductId>());
            var idStr     = formatter.ToString(id);

            return(idStr);
        }
        public override EventStream LoadEventStream(Type eventType, IEventStoreAggregateId eventStoreAggregateId, long version)
        {
            Type supportedEventType = typeof(SupplierProductEventBase);

            if (!eventType.IsAssignableFrom(supportedEventType))
            {
                throw new NotSupportedException();
            }
            SupplierProductId idObj = (SupplierProductId)(eventStoreAggregateId as EventStoreAggregateId).Id;
            var criteria            = CurrentSession.CreateCriteria <SupplierProductEventBase>();

            criteria.Add(Restrictions.Eq("SupplierProductEventId.SupplierProductIdProductId", idObj.ProductId));
            criteria.Add(Restrictions.Eq("SupplierProductEventId.SupplierProductIdPartyId", idObj.PartyId));
            criteria.Add(Restrictions.Eq("SupplierProductEventId.SupplierProductIdCurrencyUomId", idObj.CurrencyUomId));
            criteria.Add(Restrictions.Eq("SupplierProductEventId.SupplierProductIdMinimumOrderQuantity", idObj.MinimumOrderQuantity));
            criteria.Add(Restrictions.Le("SupplierProductEventId.Version", version));
            criteria.AddOrder(global::NHibernate.Criterion.Order.Asc("SupplierProductEventId.Version"));
            var es = criteria.List <IEvent>();

            foreach (SupplierProductEventBase e in es)
            {
                e.EventReadOnly = true;
            }
            return(new EventStream()
            {
                SteamVersion = es.Count > 0 ? ((SupplierProductEventBase)es.Last()).SupplierProductEventId.Version : default(long),
                Events = es
            });
        }
예제 #3
0
        public ISupplierProductState Get(SupplierProductId id)
        {
            ISupplierProductState state = CurrentSession.Get <SupplierProductState>(id);

            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <ISupplierProductState>(state, new Type[] {  }, _readOnlyPropertyNames));
            }
            return(state);
        }
        public async Task <ISupplierProductState> GetHistoryStateAsync(SupplierProductId supplierProductId, long version)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductHistoryStateUriParameters();

            uriParameters.Id      = idObj;
            uriParameters.Version = version.ToString();

            var req  = new SupplierProductHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.SupplierProductHistoryState.Get(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToSupplierProductState());
        }
        public async Task <ISupplierProductEvent> GetStateEventAsync(SupplierProductId supplierProductId, long version)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductStateEventUriParameters();

            uriParameters.Id      = idObj;
            uriParameters.Version = version.ToString();

            var req  = new SupplierProductStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.SupplierProductStateEvent.Get(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
예제 #6
0
        public ISupplierProductState Get(SupplierProductId id, bool nullAllowed)
        {
            ISupplierProductState state = CurrentSession.Get <SupplierProductState> (id);

            if (!nullAllowed && state == null)
            {
                state = new SupplierProductState();
                (state as SupplierProductState).SupplierProductId = id;
            }
            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <ISupplierProductState>(state, new Type[] {  }, _readOnlyPropertyNames));
            }
            return(state);
        }
        public async Task <ISupplierProductState> GetAsync(SupplierProductId supplierProductId)
        {
            ISupplierProductState state = null;
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductUriParameters();

            uriParameters.Id = idObj;

            var req = new SupplierProductGetRequest(uriParameters);

            var resp = await _ramlClient.SupplierProduct.Get(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            state = (resp.Content == null) ? null : resp.Content.ToSupplierProductState();
            return(state);
        }
 public override IEventStoreAggregateId ToEventStoreAggregateId(SupplierProductId aggregateId)
 {
     return(new EventStoreAggregateId(aggregateId));
 }
 public virtual ISupplierProductState GetHistoryState(SupplierProductId supplierProductId, long version)
 {
     return(GetHistoryStateAsync(supplierProductId, version).GetAwaiter().GetResult());
 }
 public ISupplierProductEvent GetEvent(SupplierProductId supplierProductId, long version)
 {
     return(GetStateEventAsync(supplierProductId, version).GetAwaiter().GetResult());
 }
 public ISupplierProductState Get(SupplierProductId supplierProductId)
 {
     return(GetAsync(supplierProductId).GetAwaiter().GetResult());
 }