Ejemplo n.º 1
0
        public void Apply(LogEntry entry, Command cmd)
        {
            var betCmd = cmd as BetOnPonyCommand;
            if (betCmd != null)
            {
                var odd = OddsReference.AvailableOdds.FirstOrDefault(o => o.OddId == betCmd.OddId);
                if (odd != null)
                {
                    this.Bets.Add(new Bet() { Odd = odd, UserId = betCmd.UserId, AmountOfMoney = betCmd.AmountOfMoney });
                    cmd.CommandResult = new { Result = "Success" };
                }
                else
                {
                    // TODO: figure out what to do if the odd is invalid
                }
            }

            var getCmd = cmd as GetAllBetsCommand;
            if (getCmd != null)
            {
                cmd.CommandResult = this.Bets;
            }

            this.LastAppliedIndex = cmd.AssignedIndex;
        }
Ejemplo n.º 2
0
		public void Apply(LogEntry entry, Command cmd)
		{
			if (LastAppliedIndex >= entry.Index)
				throw new InvalidOperationException("Already applied " + entry.Index);
			
			LastAppliedIndex = entry.Index;
			
			var dicCommand = cmd as DictionaryCommand;
			
			if (dicCommand != null) 
				dicCommand.Apply(Data);
		}
Ejemplo n.º 3
0
		public void Apply(LogEntry entry, Command cmd)
		{
			var batch = cmd as OperationBatchCommand;
		    if (batch != null)
		    {
		        Apply(batch.Batch, cmd.AssignedIndex);
		        return;
		    }
		    var get = cmd as GetCommand;
		    if (get != null)
		    {
		        cmd.CommandResult = Read(get.Key);
		    }
            // have to apply even get command so we'll keep track of the last applied index
		    Apply(Enumerable.Empty<KeyValueOperation>(), cmd.AssignedIndex);
		}
Ejemplo n.º 4
0
		internal virtual void OnEntriesAppended(LogEntry[] logEntries)
		{
			var handler = EntriesAppended;
			if (handler != null)
			{
				try
				{
					handler(logEntries);
				}
				catch (Exception e)
				{
					_log.Error("Error on raising EntriesAppended event", e);
				}
			}
		}
Ejemplo n.º 5
0
		protected void CommitEntries(LogEntry[] entries, long lastIndex)
		{
			var oldCommitIndex = Engine.CommitIndex + 1;
			Engine.ApplyCommits(oldCommitIndex, lastIndex);			
			Engine.OnEntriesAppended(entries);
		}
Ejemplo n.º 6
0
			public EntriesContent(LogEntry[] entries)
			{
				_entries = entries;
			}