Exemplo n.º 1
0
        public static IList <Tuple <ObjectInfo, Event> > GetEventBatch(this IObjectStorage storage, string queueName, IJsonSerializer serializer, int batchSize = 50, DateTime?maxCreatedDate = null)
        {
            var events = new List <Tuple <ObjectInfo, Event> >();

            lock (_lockObject) {
                foreach (var file in storage.GetQueueFiles(queueName, batchSize * 5, maxCreatedDate))
                {
                    if (!storage.LockFile(file))
                    {
                        continue;
                    }

                    try {
                        storage.IncrementAttempts(file);
                    } catch {}

                    try {
                        var ev = storage.GetObject <Event>(file.Path);
                        events.Add(Tuple.Create(file, ev));
                        if (events.Count == batchSize)
                        {
                            break;
                        }
                    } catch {}
                }

                return(events);
            }
        }
Exemplo n.º 2
0
        public void CanManageFiles()
        {
            Reset();

            IObjectStorage storage = GetStorage();

            storage.SaveObject("test.txt", "test");
            Assert.Equal(1, storage.GetObjectList("test.txt").Count());
            Assert.Equal(1, storage.GetObjectList().Count());
            var file = storage.GetObjectList().FirstOrDefault();

            Assert.NotNull(file);
            Assert.Equal("test.txt", file.Path);
            string content = storage.GetObject <string>("test.txt");

            Assert.Equal("test", content);
            storage.RenameObject("test.txt", "new.txt");
            Assert.True(storage.GetObjectList().Any(f => f.Path == "new.txt"));
            storage.DeleteObject("new.txt");
            Assert.Equal(0, storage.GetObjectList().Count());
            storage.SaveObject("test\\q\\" + Guid.NewGuid().ToString("N") + ".txt", "test");
            Assert.Equal(1, storage.GetObjectList("test\\q\\*.txt").Count());
            Assert.Equal(1, storage.GetObjectList("*", null, DateTime.Now).Count());
            List <ObjectInfo> files = storage.GetObjectList("*", null, DateTime.Now.Subtract(TimeSpan.FromMinutes(5))).ToList();

            Debug.WriteLine(String.Join(",", files.Select(f => f.Path + " " + f.Created)));
            Assert.Equal(0, files.Count);
        }