Exemple #1
0
        /// <summary>
        /// Asynchronously receive the next message from the queue.
        /// </summary>
        public async Task <RsmqMessage> ReceiveMessageAsync(ReceiveMessageOptions options)
        {
            Validate(options, "QueueName");
            var q = await this.GetQueue(options.QueueName);

            options.VisibilityTimer = options.VisibilityTimer.HasValue ? options.VisibilityTimer.Value : q.VisibilityTimer;
            Validate(options);

            var res = await _receiveMessage.EvaluateAsync(
                this.RedisClient,
                new
            {
                key              = (RedisKey)$"{this._options.Namespace}:{options.QueueName}",
                timestamp        = q.Timestamp,
                timestampTimeout = q.Timestamp + options.VisibilityTimer * 1000
            }
                );

            var vals = (string[])res;

            if (vals.Length != 4)
            {
                return(null);
            }

            return(new RsmqMessage
            {
                Id = vals[0],
                Message = vals[1],
                ReceivedCount = int.Parse(vals[2]),
                FirstReceived = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(vals[3])).UtcDateTime,
                Sent = DateTimeOffset.FromUnixTimeMilliseconds(Base36.Decode(vals[0].Substring(0, 10)) / 1000).UtcDateTime
            });
        }
Exemple #2
0
    /// <summary>
    /// Insert new URL in NOSQL DB
    /// </summary>
    /// <param name="strUrlIn"></param>
    /// <returns>Base36 string ID</returns>
    public static string putUrl(string strUrlIn)
    {
        try
        {
            // Open database (or create if not exits)
            using (var db = new LiteDatabase(HttpContext.Current.Server.MapPath("~/") + @"Minify.db"))
            {
                // Get Minify Rec collection
                var col = db.GetCollection <MinifyRec>("MinifyRec");

                // Create your new Minify Rec instance
                var MinifyRecIn = new MinifyRec
                {
                    Url    = strUrlIn,
                    Visits = 0
                };

                // Insert new customer document (Id will be auto-incremented)
                col.Insert(MinifyRecIn);
                return(Base36.Encode(MinifyRecIn.Id));
            }
        }
        catch
        {
            return("");
        }
    }
Exemple #3
0
        public void PositiveAndNegativeComparison()
        {
            Assert.AreEqual(1, Base36.Compare("-A", "10"));
            Assert.AreEqual(1, Base36.Compare("-RS", "100"));
            Assert.AreEqual(1, Base36.Compare("-7PS", "1000"));
            Assert.AreEqual(1, Base36.Compare("-LFLS", "10000"));
            Assert.AreEqual(1, Base36.Compare("-5YC1S", "100000"));
            Assert.AreEqual(1, Base36.Compare("-GJDGXS", "1000000"));
            Assert.AreEqual(1, Base36.Compare("-4LDQPDS", "10000000"));
            Assert.AreEqual(1, Base36.Compare("-CRE66I9S", "100000000"));
            Assert.AreEqual(1, Base36.Compare("-ZG3D62R5S", "1000000000"));
            Assert.AreEqual(1, Base36.Compare("-9UGXNORJLS", "10000000000"));
            Assert.AreEqual(1, Base36.Compare("-RCN1HSSIGHS", "100000000000"));

            Assert.AreEqual(1, Base36.Compare("-10", "A"));
            Assert.AreEqual(1, Base36.Compare("-100", "RS"));
            Assert.AreEqual(1, Base36.Compare("-1000", "7PS"));
            Assert.AreEqual(1, Base36.Compare("-10000", "LFLS"));
            Assert.AreEqual(1, Base36.Compare("-100000", "5YC1S"));
            Assert.AreEqual(1, Base36.Compare("-1000000", "GJDGXS"));
            Assert.AreEqual(1, Base36.Compare("-10000000", "4LDQPDS"));
            Assert.AreEqual(1, Base36.Compare("-100000000", "CRE66I9S"));
            Assert.AreEqual(1, Base36.Compare("-1000000000", "ZG3D62R5S"));
            Assert.AreEqual(1, Base36.Compare("-10000000000", "9UGXNORJLS"));
            Assert.AreEqual(1, Base36.Compare("-100000000000", "RCN1HSSIGHS"));
        }
Exemple #4
0
        public void PositiveComparison()
        {
            Assert.AreEqual(1, Base36.Compare("A", "10"));
            Assert.AreEqual(1, Base36.Compare("RS", "100"));
            Assert.AreEqual(1, Base36.Compare("7PS", "1000"));
            Assert.AreEqual(1, Base36.Compare("LFLS", "10000"));
            Assert.AreEqual(1, Base36.Compare("5YC1S", "100000"));
            Assert.AreEqual(1, Base36.Compare("GJDGXS", "1000000"));
            Assert.AreEqual(1, Base36.Compare("4LDQPDS", "10000000"));
            Assert.AreEqual(1, Base36.Compare("CRE66I9S", "100000000"));
            Assert.AreEqual(1, Base36.Compare("ZG3D62R5S", "1000000000"));
            Assert.AreEqual(1, Base36.Compare("9UGXNORJLS", "10000000000"));
            Assert.AreEqual(1, Base36.Compare("RCN1HSSIGHS", "100000000000"));

            Assert.AreEqual(-1, Base36.Compare("10", "A"));
            Assert.AreEqual(-1, Base36.Compare("100", "RS"));
            Assert.AreEqual(-1, Base36.Compare("1000", "7PS"));
            Assert.AreEqual(-1, Base36.Compare("10000", "LFLS"));
            Assert.AreEqual(-1, Base36.Compare("100000", "5YC1S"));
            Assert.AreEqual(-1, Base36.Compare("1000000", "GJDGXS"));
            Assert.AreEqual(-1, Base36.Compare("10000000", "4LDQPDS"));
            Assert.AreEqual(-1, Base36.Compare("100000000", "CRE66I9S"));
            Assert.AreEqual(-1, Base36.Compare("1000000000", "ZG3D62R5S"));
            Assert.AreEqual(-1, Base36.Compare("10000000000", "9UGXNORJLS"));
            Assert.AreEqual(-1, Base36.Compare("100000000000", "RCN1HSSIGHS"));
        }
Exemple #5
0
        private static bool ParseSummary(string command2, string strParam1, string strParam2, HashSet <int> channels, out int combos)
        {
            int verse;

            if (!int.TryParse(command2, out verse))
            {
                combos = 0;
                return(false);
            }
            int channel = GetChannelNumberById(strParam2);

            if ((channel > 10 && channel < 30) || (channel > 50 && channel < 70))
            {
                channels.Add(channel);
                int lCombos = 0;
                for (int i = 0, length = strParam1.Length / 2; i < length; i++)
                {
                    int value = Base36.Decode(strParam1.Substring(i * 2, 2));
                    if (value > 0)
                    {
                        lCombos++;
                    }
                }
                combos = lCombos;
                return(true);
            }
            combos = 0;
            return(false);
        }
Exemple #6
0
        public void Decode_100000000_2821109907456()
        {
            const string input  = "100000000";
            long         result = Base36.Decode(input);

            Assert.AreEqual(2821109907456L, result);
        }
Exemple #7
0
        public void Decode_0H_17()
        {
            const string input  = "0H";
            long         result = Base36.Decode(input);

            Assert.AreEqual(17L, result);
        }
Exemple #8
0
        public void Decode_CRE66I9S_1000000000000()
        {
            const string input  = "CRE66I9S";
            long         result = Base36.Decode(input);

            Assert.AreEqual(1000000000000L, result);
        }
Exemple #9
0
        public void Encode_100000_255S()
        {
            const long input  = 100000L;
            string     result = Base36.Encode(input);

            Assert.AreEqual("255S", result, true);
        }
Exemple #10
0
        public static string ToFriendlyId(this Guid guid)
        {
            if (guid == Guid.Empty)
            {
                return("No GUID supplied for friendly ID");
            }

            string str = Base36.Encode(BitConverter.ToUInt64(guid.ToByteArray(), 8));

            if (string.IsNullOrEmpty(str))
            {
                return("Problem getting friendly name from GUID");
            }
            string part3 = str.Length > 8
                ? str.Substring(8, str.Length - 8).PadRight(4, '0')
                : 0.ToString().PadRight(4, '0');

            string part2 = str.Length > 4
                ? str.Length < 8
                    ? str.Substring(4, str.Length - 4).PadRight(4, '0')
                    : str.Substring(4, 4)
                : 0.ToString().PadRight(4, '0');

            string part1 = str.Length < 4
                ? str.Substring(0, str.Length).PadRight(4, '0')
                : str.Substring(0, 4);

            string resultID = string.Format("{0}-{1}-{2}", part1, part2, part3);

            return(resultID);
        }
Exemple #11
0
        /// <summary>
        /// Asynchronously receive the next message from the queue and delete it.
        ///
        /// Important: This method deletes the message it receives right away. There is no way to receive the message again if something goes wrong while working on the message.
        ///
        /// returns null if no message is there
        /// </summary>
        public async Task <RsmqMessage> PopMessageAsync(PopMessageOptions options)
        {
            // todo: validate (qname)
            var key = $"{this._options.Namespace}:{options.QueueName}";
            var q   = await this.GetQueue(options.QueueName);

            var res = await _popMessage.EvaluateAsync(
                this.RedisClient,
                new
            {
                key       = key,
                timestamp = q.Timestamp
            }
                );

            var vals = (string[])res;

            if (vals.Length != 4)
            {
                return(null);
            }

            return(new RsmqMessage
            {
                Id = vals[0],
                Message = vals[1],
                ReceivedCount = int.Parse(vals[2]),
                FirstReceived = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(vals[3])).UtcDateTime,
                Sent = DateTimeOffset.FromUnixTimeMilliseconds(Base36.Decode(vals[0].Substring(0, 10)) / 1000).UtcDateTime
            });
        }
Exemple #12
0
        public void EncodesAndDecodes(long expected)
        {
            var code   = Base36.Encode(expected);
            var actual = Base36.Decode(code);

            Assert.Equal(expected, actual);
        }
Exemple #13
0
        public async Task SetShortUrlToProduct(int productId)
        {
            var productForAddShortUrl = await GetProductById(productId);

            productForAddShortUrl.ShortUrl = Base36.Encode(productId);
            await UpdateNormal(productForAddShortUrl);
            await SaveChangeAsync();
        }
Exemple #14
0
        public async Task SetShortUrlToPost(int postId)
        {
            var postForAddShortUrl = await GetPostById(postId);

            postForAddShortUrl.ShortUrl = Base36.Encode(postId);
            await UpdateNormal(postForAddShortUrl);
            await SaveChangeAsync();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            Sector sector = new Sector(
                (uint)Base36.Decode("368"), (uint)Base36.Decode("4V5"));


            Console.ReadLine();
        }
        public void Decode_A_Returns10()
        {
            long expected = 10;

            long actual = Base36.Decode("a");

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Decode_Z_Returns35()
        {
            long expected = 35;

            long actual = Base36.Decode("z");

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Encode_35_ReturnsZ()
        {
            string expected = "z";

            string actual = Base36.Encode(35);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Encode_10000_Returns7ps()
        {
            string expected = "7ps";

            string actual = Base36.Encode(10000);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Reverse_54321_Returns12345()
        {
            string expected = "12345";

            string actual = Base36.Reverse("54321");

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Encode_1_Returns1()
        {
            string expected = "1";

            string actual = Base36.Encode(1);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Encode_0_ReturnsZero()
        {
            string expected = "0";

            string actual = Base36.Encode(0);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Reverse_EmptyString_ReturnsEmptyString()
        {
            string expected = string.Empty;

            string actual = Base36.Reverse(string.Empty);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemple #24
0
        public void Static_Decoding_IsCorrect()
        {
            const ulong  output = 292_756_934_830;
            const string input  = "3QHNX4MM";

            var result = Base36.Decode(input);

            Assert.Equal(output, result);
        }
Exemple #25
0
        public override string ContentsOf(Cell cell)
        {
            if (Distances != null && Distances.ContainsKey(cell))
            {
                return(Base36.Encode(Distances[cell]));
            }

            return(" ");
        }
Exemple #26
0
 public void Wouldnt()
 {
     Assert.IsFalse(Base36.WouldOverflow("0"));
     Assert.IsFalse(Base36.WouldOverflow("A"));
     Assert.IsFalse(Base36.WouldOverflow("ABC"));
     Assert.IsFalse(Base36.WouldOverflow("SHORTSTRING"));
     Assert.IsFalse(Base36.WouldOverflow("1Y2P0IJ32E8E7"));
     Assert.IsFalse(Base36.WouldOverflow("-1Y2P0IJ32E8E8"));
 }
Exemple #27
0
        public async Task SetShortUrlToPost(int postId)
        {
            var postForAddShortUrl = await GetPageById(postId);

            postForAddShortUrl.PageShortUrl = Base36.Encode(postId);
            await UpdatePage(postForAddShortUrl);

            await _context.SaveChangesAsync();
        }
Exemple #28
0
        public void Encode_minus12345678_ArgumentOutOfRangeException()
        {
            // Arrange
            int data = -12345678;

            // Act

            // Assert
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Base36.Encode(data));
        }
Exemple #29
0
        public void Decode_7CLZzI_FormatException()
        {
            // Arrange
            string data = "7CLZzI";

            // Act

            // Assert
            Assert.ThrowsException <FormatException>(() => Base36.Decode(data));
        }
Exemple #30
0
        public void Decode_null_ArgumentNullException()
        {
            // Arrange
            string data = default;

            // Act

            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => Base36.Decode(data));
        }