Exemplo n.º 1
0
        protected override void StartOnSchedule()
        {
            const string containerName       = TemporaryBlobName <object> .DefaultContainerName;
            var          executionExpiration = DateTimeOffset.UtcNow.Add(MaxExecutionTime);

            // lazy enumeration over the overflowing messages
            foreach (var blobName in Blobs.ListBlobNames(containerName))
            {
                // HACK: targeted object is irrelevant
                var parsedName = UntypedBlobName.Parse <TemporaryBlobName <object> >(blobName);

                if (DateTimeOffset.UtcNow <= parsedName.Expiration)
                {
                    // overflowing messages are iterated in date-increasing order
                    // as soon a non-expired overflowing message is encountered
                    // just stop the process.
                    break;
                }

                // if the overflowing message is expired, delete it
                Blobs.DeleteBlobIfExist(containerName, blobName);

                // don't freeze the worker with this service
                if (DateTimeOffset.UtcNow > executionExpiration)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public void PartialPrint_Manage_Enum()
 {
     Assert.AreEqual("abc/A", UntypedBlobName.Print(new PatternK {
         Id = "abc", K = EnumK.A
     }));
     Assert.AreEqual("abc/B", UntypedBlobName.Print(new PatternK {
         Id = "abc", K = EnumK.B
     }));
 }
Exemplo n.º 3
0
 public void PartialPrint_Manage_EnumNullable()
 {
     Assert.AreEqual("abc/A", UntypedBlobName.Print(new PatternKN {
         Id = "abc", K = EnumK.A
     }));
     Assert.AreEqual("abc/", UntypedBlobName.Print(new PatternKN {
         Id = "abc", K = null
     }));
 }
Exemplo n.º 4
0
        public void Wrong_type_is_detected()
        {
            try
            {
                var original = new PatternB(Guid.NewGuid(), 1000);
                var name     = UntypedBlobName.Print(original);
                UntypedBlobName.Parse <PatternA>(name);

                Assert.Fail("#A00");
            }
            catch (ArgumentException) {}
        }
Exemplo n.º 5
0
        public void Conversion_round_trip_EnumNullable()
        {
            var original = new PatternKN {
                Id = "abc", K = EnumK.B
            };
            var name   = UntypedBlobName.Print(original);
            var parsed = UntypedBlobName.Parse <PatternKN>(name);

            Assert.AreNotSame(original, parsed);
            Assert.AreEqual(original.Id, parsed.Id);
            Assert.AreEqual(original.K, parsed.K);
        }
Exemplo n.º 6
0
        public void SpecializedTemporaryBlobNamesCanBeParsedAsBaseClass()
        {
            var now = DateTimeOffset.UtcNow;

            // round to seconds, our time resolution in blob names
            now = new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Offset);

            var testRef = new TestTemporaryBlobName(now, "test", Guid.NewGuid());
            var printed = UntypedBlobName.Print(testRef);

            var parsedRef = UntypedBlobName.Parse <TemporaryBlobName <object> >(printed);

            Assert.AreEqual(now, parsedRef.Expiration);
            Assert.AreEqual("test", parsedRef.Suffix);
        }
Exemplo n.º 7
0
 public void PartialPrint_Manage_Nullable()
 {
     Assert.AreEqual("10/20", UntypedBlobName.Print(new PatternH {
         LongId = 10, IntId = 20
     }));
     Assert.AreEqual("10/", UntypedBlobName.Print(new PatternH {
         LongId = 10, IntId = null
     }));
     Assert.AreEqual(string.Empty, UntypedBlobName.Print(new PatternH {
         LongId = null, IntId = null
     }));
     Assert.AreEqual(string.Empty, UntypedBlobName.Print(new PatternH {
         LongId = null, IntId = 20
     }));
 }
Exemplo n.º 8
0
        public void Time_zone_safe_when_using_DateTimeOffset()
        {
            var localOffset = TimeSpan.FromHours(-2);
            var now         = DateTimeOffset.Now;

            // round to seconds, our time resolution in blob names
            now = new DateTimeOffset(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Offset);
            var unsafeNow = now.DateTime;

            var utcNow         = now.ToUniversalTime();
            var localNow       = now.ToOffset(localOffset);
            var unsafeUtcNow   = utcNow.UtcDateTime;
            var unsafeLocalNow = localNow.DateTime;

            // 'dummy' argument set as 'null'
            var localString = UntypedBlobName.Print(new PatternE(unsafeLocalNow, localNow, null));
            var localName   = UntypedBlobName.Parse <PatternE>(localString);

            Assert.AreEqual(now, localName.AbsoluteTime, "DateTimeOffset-local");
            Assert.AreEqual(utcNow, localName.AbsoluteTime, "DateTimeOffset-local-utc");
            Assert.AreEqual(localNow, localName.AbsoluteTime, "DateTimeOffset-local-local");

            Assert.AreNotEqual(unsafeNow, localName.UserTime, "DateTime-local");
            Assert.AreNotEqual(unsafeUtcNow, localName.UserTime, "DateTime-local-utc");
            Assert.AreEqual(unsafeLocalNow, localName.UserTime, "DateTime-local-local");

            Assert.AreNotEqual(unsafeUtcNow, localName.UserTime, "DateTime-local");

            // 'dummy' argument set as 'null'
            var utcString = UntypedBlobName.Print(new PatternE(unsafeUtcNow, utcNow, null));
            var utcName   = UntypedBlobName.Parse <PatternE>(utcString);

            Assert.AreEqual(now, utcName.AbsoluteTime, "DateTimeOffset-utc");
            Assert.AreEqual(utcNow, utcName.AbsoluteTime, "DateTimeOffset-local-utc");
            Assert.AreEqual(localNow, utcName.AbsoluteTime, "DateTimeOffset-local-local");

            if (unsafeNow != unsafeUtcNow)
            {
                // in case current machine runs NOT at UTC time
                Assert.AreNotEqual(unsafeNow, utcName.UserTime, "DateTime-utc");
            }
            Assert.AreEqual(unsafeUtcNow, utcName.UserTime, "DateTime-utc-utc");
            if (unsafeNow != unsafeLocalNow)
            {
                // in case current machine runs NOT at UTC-2 time
                Assert.AreNotEqual(unsafeLocalNow, utcName.UserTime, "DateTime-utc-local");
            }
        }
Exemplo n.º 9
0
        public void Conversion_round_trip()
        {
            var date     = new DateTime(2009, 1, 1, 3, 4, 5);
            var original = new PatternA(date, 12000, Guid.NewGuid(), 120);

            var name = UntypedBlobName.Print(original);

            //Console.WriteLine(name);

            var parsed = UntypedBlobName.Parse <PatternA>(name);

            Assert.AreNotSame(original, parsed);
            Assert.AreEqual(original.Timestamp, parsed.Timestamp);
            Assert.AreEqual(original.AccountHRID, parsed.AccountHRID);
            Assert.AreEqual(original.ChunkID, parsed.ChunkID);
            Assert.AreEqual(original.ChunkSize, parsed.ChunkSize);
        }
Exemplo n.º 10
0
        public void Conversion_round_trip_Nullable()
        {
            var original1 = new PatternH {
                LongId = 0, IntId = 0
            };
            var name1   = UntypedBlobName.Print(original1);
            var parsed1 = UntypedBlobName.Parse <PatternH>(name1);

            Assert.AreNotSame(original1, parsed1);
            Assert.AreEqual(original1.LongId, parsed1.LongId);
            Assert.AreEqual(original1.IntId, parsed1.IntId);

            var original2 = new PatternH {
                LongId = 10, IntId = 20
            };
            var name2   = UntypedBlobName.Print(original2);
            var parsed2 = UntypedBlobName.Parse <PatternH>(name2);

            Assert.AreNotSame(original2, parsed2);
            Assert.AreEqual(original2.LongId, parsed2.LongId);
            Assert.AreEqual(original2.IntId, parsed2.IntId);
        }