public void AddLine(ConsoleId consoleId, ConsoleLine line)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }
            if (line.IsReference)
            {
                throw new ArgumentException("Cannot add reference directly", nameof(line));
            }

            using (var tran = _connection.CreateWriteTransaction())
            {
                // check if encoded message fits into Set's Value field

                string value;

                if (line.Message.Length > ValueFieldLimit - 36)
                {
                    // pretty sure it won't fit
                    // (36 is an upper bound for JSON formatting, TimeOffset and TextColor)
                    value = null;
                }
                else
                {
                    // try to encode and see if it fits
                    value = JobHelper.ToJson(line);

                    if (value.Length > ValueFieldLimit)
                    {
                        value = null;
                    }
                }

                if (value == null)
                {
                    var referenceKey = Guid.NewGuid().ToString("N");

                    tran.SetRangeInHash(consoleId.ToString(), new[] { new KeyValuePair <string, string>(referenceKey, line.Message) });

                    line.Message     = referenceKey;
                    line.IsReference = true;

                    value = JobHelper.ToJson(line);
                }

                tran.AddToSet(consoleId.ToString(), value);

                tran.Commit();
            }
        }
        public void Expire(ConsoleId consoleId, TimeSpan expireIn)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            using (var tran = (JobStorageTransaction)_connection.CreateWriteTransaction())
            {
                tran.ExpireSet(consoleId.ToString(), expireIn);
                tran.ExpireHash(consoleId.ToString(), expireIn);
                tran.Commit();
            }
        }
示例#3
0
        public void SerializesCorrectly()
        {
            var x = new ConsoleId("123", new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            var s = x.ToString();

            Assert.Equal("00cdb7af151123", s);
        }
示例#4
0
        public void Expire_ExpiresOldSetAndHashKeysEither_ForBackwardsCompatibility()
        {
            var storage = new ConsoleStorage(_connection.Object);

            storage.Expire(_consoleId, TimeSpan.FromHours(1));

            _transaction.Verify(x => x.ExpireSet(_consoleId.ToString(), It.IsAny <TimeSpan>()));
            _transaction.Verify(x => x.ExpireHash(_consoleId.ToString(), It.IsAny <TimeSpan>()));
        }
        public int GetLineCount(ConsoleId consoleId)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            return((int)_connection.GetSetCount(consoleId.ToString()));
        }
        public IEnumerable <ConsoleLine> GetLines(ConsoleId consoleId, int start, int end)
        {
            if (consoleId == null)
            {
                throw new ArgumentNullException(nameof(consoleId));
            }

            foreach (var item in _connection.GetRangeFromSet(consoleId.ToString(), start, end))
            {
                var line = JobHelper.FromJson <ConsoleLine>(item);

                if (line.IsReference)
                {
                    line.Message     = _connection.GetValueFromHash(consoleId.ToString(), line.Message);
                    line.IsReference = false;
                }

                yield return(line);
            }
        }
示例#7
0
 public static string GetOldConsoleKey(this ConsoleId consoleId) => consoleId.ToString();
示例#8
0
 public static string GetOldConsoleKey(this ConsoleId consoleId)
 {
     return(consoleId.ToString());
 }
 private string GetOldConsoleKey(ConsoleId consoleId)
 {
     return(consoleId.ToString());
 }