Ejemplo n.º 1
0
        public int Increment(string key)
        {
            ValidateKeyVal(key);
            var command = new IncrementCommand(1, key);

            return(command.Execute());
        }
Ejemplo n.º 2
0
        public int IncrementBy(string key, int count)
        {
            ValidateKeyVal(key);
            var command = new IncrementCommand(count, key);

            return(command.Execute());
        }
Ejemplo n.º 3
0
        private static void Stream_DataRow(object sender, EventStreamRow e)
        {
            if (e.Kind != EventStreamRow.RowKind.Event)
            {
                return;                                         // We don't parse state events
            }
            if (!EmojiEventParser.CanParse(e.EventType))
            {
                return;
            }

            EventJson ev;

            using (var db = new SynapseDbContext(_config.GetConnectionString("synapse")))
            {
                ev = db.EventsJson.FirstOrDefault(e2 => e2.RoomId == e.RoomId && e2.EventId == e.EventId);
                if (ev == null)
                {
                    return;
                }
            }

            var emoji = EmojiEventParser.CountEmoji(e.EventType, ev).Where(c => c.Value > 0);

            foreach (var pair in emoji)
            {
                log.Information("Found {0} instances of {1} emoji in type {2}", pair.Value, pair.Key, e.EventType);
                _redis.GetSubscriber().PublishAsync(EmojiChannel.IncrementCommands, IncrementCommand.Make(pair.Key, pair.Value, e.EventType));
                _redisDb.StringIncrementAsync(pair.Key, pair.Value, CommandFlags.FireAndForget);
            }
        }
Ejemplo n.º 4
0
        private static void HandleIncrement(RedisChannel channelName, RedisValue rawJson)
        {
            var cmd = IncrementCommand.Parse(rawJson);

            log.Information("Received increment command for {0} (amount = {1}) sourced by {2}", cmd.Emoji, cmd.Amount,
                            cmd.SourceType);
            IncrementQueue.Add(cmd);
        }
Ejemplo n.º 5
0
            void SendIncrementCommand(ISmartCardReader smartCardReader, string description, int value, byte blockNumber)
            {
                var    incrementCommand = new IncrementCommand();
                string input            = incrementCommand.GetApdu(blockNumber, value);
                string output           = ReaderHelper.SendCommand(smartCardReader, input);

                ConsoleWriter.Instance.PrintCommand(description + blockNumber.ToString("X2"), input, output);
            }
Ejemplo n.º 6
0
            void SendIncrementCommand(ISmartCardReader smartCardReader, int value, byte blockNumber)
            {
                var    incrementCommand = new IncrementCommand();
                string input            = incrementCommand.GetApdu(blockNumber, value);
                string output           = ReaderHelper.SendCommand(smartCardReader, input);

                Console.WriteLine("Input ", input, "Output: ", output);
            }
Ejemplo n.º 7
0
 protected override void OnBuyCommandExecute()
 {
     if (Quantity == default(float))
     {
         base.OnBuyCommandExecute();
     }
     else if (IncrementCommand != null && IncrementCommand.CanExecute())
     {
         IncrementCommand.Execute();
     }
 }
        public CanExecuteChangedAsObservableViewModel()
        {
            IncrementCommand = new[] { IsChecked1, IsChecked2 }
            .CombineLatestValuesAreAllTrue()
            .ToReactiveCommand()
            .WithSubscribe(() => Counter.Increment(), CompositeDisposable.Add);

            CanExecuteIncrementCommand = IncrementCommand.CanExecuteChangedAsObservable()
                                         .Select(_ => IncrementCommand.CanExecute())
                                         .ToReadOnlyReactiveProperty()
                                         .AddTo(CompositeDisposable);
        }
Ejemplo n.º 9
0
        public static void Begin(string host, int port)
        {
            _redis = ConnectionMultiplexer.Connect($"{host}:{port}");
            _redis.GetSubscriber().Subscribe(EmojiChannel.IncrementCommands, (chan, rawJson) =>
            {
                var command = IncrementCommand.Parse(rawJson);
                EmojiCache.HandleIncrement(command);
            });

            // Populate the cache with all known emoji
            var db = _redis.GetDatabase();

            foreach (var emoji in EmojiData.KnownSymbols)
            {
                var  countStr = db.StringGet(emoji);
                long count    = string.IsNullOrWhiteSpace(countStr) ? 0 : long.Parse(countStr);
                EmojiCache.SetValue(emoji, count);
            }
        }
Ejemplo n.º 10
0
 public static void HandleIncrement(IncrementCommand command)
 {
     CountCache.AddOrUpdate(command.Emoji, command.Amount, (key, existing) => existing + command.Amount);
     Updates.AddOrUpdate(command.Emoji, command.Amount, (key, existing) => existing + command.Amount);
 }
        public void TestVerb()
        {
            var command = new IncrementCommand();

            Assert.AreEqual("incr", command.Verb);
        }