Exemplo n.º 1
0
        public static BudgetModel Load(Guid deviceId, IBudgetStore budgetStore)
        {
            BudgetModel model = new BudgetModel(deviceId, budgetStore, false);

            VectorClock eventVector    = budgetStore.EventStore.GetMaxVectorClock();
            VectorClock snapshotVector = budgetStore.SnapshotStore.GetLastVectorClock();

            if (eventVector.CompareTo(snapshotVector) != 0)
            {
                using (model.StartUpdateBatch(false))
                {
                    foreach (var evt in model.EventStore.GetEvents())
                    {
                        model.InternalMessageBus.PublishEvent(evt.EntityType, evt);
                    }
                }
                model.CurrencyDecimalPlaces = (int)model.GetBudget().CurrencyDecimals;
                model.BudgetViewCache.RecalculateCache();
            }
            else
            {
                model.CurrencyDecimalPlaces = (int)model.GetBudget().CurrencyDecimals;
            }

            return(model);
        }
Exemplo n.º 2
0
        public static BudgetModel CreateNew(Guid deviceId, IBudgetStore budgetStore, Budget initialBudget)
        {
            if (initialBudget == null)
            {
                throw new ArgumentNullException(nameof(initialBudget));
            }

            return(new BudgetModel(deviceId, budgetStore, initialBudget));
        }
Exemplo n.º 3
0
        protected BudgetModel(Guid deviceId, IBudgetStore budgetStore, Budget initialBudget) : this(deviceId, budgetStore, false)
        {
            if (initialBudget == null)
            {
                throw new ArgumentNullException(nameof(initialBudget));
            }

            RegisterHasChanges(initialBudget);
            this.SaveChanges();
        }
Exemplo n.º 4
0
        protected BudgetModel(Guid deviceId, IBudgetStore budgetStore, bool createBudget)
        {
            DeviceID           = deviceId;
            BudgetStore        = budgetStore;
            EventStore         = BudgetStore.EventStore;
            InternalMessageBus = new BudgetMessageBus();
            MessageBus         = new BudgetMessageBus();
            _unitOfWork        = new UnitOfWork(this);

            InitializeInternals();

            if (createBudget)
            {
                var newBudget = new Budget();
                RegisterHasChanges(newBudget);
                this.SaveChanges();
            }

            InitializeBudgetViewCache();
        }
Exemplo n.º 5
0
 public BudgetViewCalculator(BudgetModel budgetModel, IBudgetStore budgetStore)
 {
     _model         = budgetModel ?? throw new ArgumentNullException(nameof(budgetModel));
     _budgetStore   = budgetStore ?? throw new ArgumentNullException(nameof(budgetStore));
     _snapshotStore = _budgetStore.SnapshotStore;
 }
Exemplo n.º 6
0
 public static BudgetModel CreateNew(Guid deviceId, IBudgetStore budgetStore)
 {
     return(new BudgetModel(deviceId, budgetStore));
 }
Exemplo n.º 7
0
        public static BudgetModel OpenExistingOnNewDevice(Guid deviceId, ISynchronizationService syncService, IBudgetStore budgetStore)
        {
            //var budgetId = events.Single(e => e.EntityType == "Budget" && e is EntityCreatedEvent).EntityID;
            BudgetModel model = new BudgetModel(deviceId, budgetStore, false);

            model.SetSynchronizationService(syncService);
            model.Sync();

            //model.Budget = (Budget)model.BudgetGenerator.GetAll().Single();
            //model.Budget.AttachToModel(model);
            return(model);
        }
Exemplo n.º 8
0
 protected BudgetModel(Guid deviceId, IBudgetStore budgetStore) : this(deviceId, budgetStore, true)
 {
 }
Exemplo n.º 9
0
 public BudgetController(IBudgetStore budgetStore)
 {
     _budgetStore = budgetStore;
 }