예제 #1
0
        public void StateTests()
        {
            using (var db = new StateDbContext())
            {
                var e = db.Items.Add(new TestItem {
                    Description = "1"
                });
                db.SaveChanges();

                PreEntityEntry afterEntry = null;
                using (db.AfterEach.Subscribe(x => afterEntry = x))
                {
                    var e2 = db.Items.Find(e.Entity.Id);
                    e2.Description = "1";
                    db.SaveChanges();
                    afterEntry.OriginalValues["Description"].Should().Be(afterEntry.Entry.CurrentValues["Description"], "No change should have been detected");

                    var e3 = db.Items.Find(e.Entity.Id);
                    e3.Description = "2";
                    db.SaveChanges();

                    afterEntry.OriginalValues["Description"].Should().Be("1", "Original values in pre-entry did not clone");
                    afterEntry.Entry.OriginalValues["Description"].Should().Be("2", "Original values didn't change in standard entry");
                    afterEntry.Entry.CurrentValues["Description"].Should().Be("2", "Current values didn'tchange in standard entry");
                }
            }
        }
        /// <summary>
        ///     Get persistent state
        /// </summary>
        /// <param name="name">Name of state</param>
        public object?GetPersistentState(string name)
        {
            _ = ConnectionString ??
                throw new NullReferenceException("Connection string cannot be null, please set");

            using (var c = new StateDbContext(ConnectionString))
            {
                var prop = c.States.FirstOrDefault(n => n.PropName == name);

                if (prop is null)
                {
                    return(null);
                }

                if (prop.IntValue is not null)
                {
                    return(prop.IntValue);
                }
                else if (prop.DoubleValue is not null)
                {
                    return(prop.DoubleValue);
                }
                else if (prop.StringValue is not null)
                {
                    return(prop.StringValue);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #3
0
        static async Task Main(string[] args)
        {
            _stateDbContext = new StateDbContext();
            await _stateDbContext.Database.EnsureCreatedAsync();

            _subscriptionConnection = EventStoreConnectionFactory.Create(
                new EventStoreSingleNodeConfiguration(),
                new ConsoleLogger(),
                "admin", "changeit");
            _writeConnection = EventStoreConnectionFactory.Create(
                new EventStoreSingleNodeConfiguration(),
                new ConsoleLogger(),
                "admin", "changeit");

            await _subscriptionConnection.ConnectAsync();

            await _writeConnection.ConnectAsync();

            _eventStore = new Bank.Persistence.EventStore.EventStore(_writeConnection, new List <IEventSchema>
            {
                new InvoiceSchema()
            });
            _repository = new InvoiceRepository(_eventStore);

            //await StartMultipleSubscriptions();
            await StartCategoryGeneration();

            Console.ReadLine();
        }
예제 #4
0
        public ActionResult Map()
        {
            StateDbContext DC     = new StateDbContext();
            var            states = from s in DC.States select s;

            return(View(states));
        }
예제 #5
0
 public OidcLoginModel(
     ApplicationDbContext context,
     StateDbContext stateContext,
     ILogger <OidcLoginModel> logger)
 {
     _context      = context;
     _stateContext = stateContext;
     _logger       = logger;
 }
예제 #6
0
 public ToolModel(
     ApplicationDbContext context,
     StateDbContext stateContext,
     AccessTokenService accessTokenService,
     IHttpClientFactory httpClientFactory)
 {
     _context            = context;
     _stateContext       = stateContext;
     _accessTokenService = accessTokenService;
     _httpClientFactory  = httpClientFactory;
 }
        /// <summary>
        ///     Sets perssistant state
        /// </summary>
        /// <param name="name">Name of state</param>
        /// <param name="value">Value to set or null</param>
        public void SetPersistentState(string name, object?value)
        {
            _ = ConnectionString ??
                throw new NullReferenceException("Connection string cannot be null, please set");

            using (var c = new StateDbContext(ConnectionString))
            {
                var prop = c.States.FirstOrDefault(n => n.PropName == name);

                if (prop is null)
                {
                    if (value is null)
                    {
                        return; // No value allready
                    }
                    var state = new State()
                    {
                        PropName    = name,
                        IntValue    = (value is int) ? (int)value : null,
                        DoubleValue = (value is double) ? (double)value : null,
                        StringValue = (value is string) ? (string)value : null
                    };
                    c.Add(state);
                    c.SaveChanges();
                }
                else
                {
                    // update existing
                    if (value is null)
                    {
                        c.Remove <State>(prop);
                        c.SaveChanges();
                        return;
                    }

                    prop.IntValue    = (value is int) ? (int)value : null;
                    prop.DoubleValue = (value is double) ? (double)value : null;
                    prop.StringValue = (value is string) ? (string)value : null;
                    c.SaveChanges();
                }
            }
        }
예제 #8
0
        private static async Task RaiseStateEventWithSqlState <T>(MonthlyInvoiceStateMachine stateMachine, Event <T> stateEvent, T data) where T : AccountDomainEvent
        {
            using (var context = new StateDbContext())
            {
                var state = await context.MonthlyInvoiceStates.SingleOrDefaultAsync(s => s.AccountId == Guid.Parse(data.StreamId));

                if (state == null)
                {
                    state = new MonthlyInvoiceState();
                    await context.MonthlyInvoiceStates.AddAsync(state);
                }

                if (state.AccountStreamVersion > data.EventNumber)
                {
                    return;
                }

                state.AccountStreamVersion = data.EventNumber;

                await stateMachine.RaiseEvent(state, stateEvent, data);

                await context.SaveChangesAsync();
            }
        }