Esempio n. 1
0
        /// <summary>
        /// Gets all messages that are due at this instant
        /// </summary>
        public async Task <DueMessagesResult> GetDueMessages()
        {
            var lockItem   = new FileSystemExclusiveLock(_lockFile, _log);
            var prefix     = _rebusTime.Now.UtcDateTime.Ticks.ToString(TickFormat);
            var enumerable = Directory.EnumerateFiles(_basePath, "*.json")
                             .Where(x => string.CompareOrdinal(prefix, 0, Path.GetFileNameWithoutExtension(x), 0, TickFormat.Length) >= 0)
                             .ToList();

            var items = enumerable
                        .Select(f => new
            {
                Timeout = JsonConvert.DeserializeObject <Timeout>(File.ReadAllText(f)),
                File    = f
            })
                        .Select(a => new DueMessage(a.Timeout.Headers, a.Timeout.Body, async() =>
            {
                if (File.Exists(a.File))
                {
                    File.Delete(a.File);
                }
            }))
                        .ToList();

            return(new DueMessagesResult(items, async() => { lockItem.Dispose(); }));
        }
        /// <summary>
        /// Gets all messages that are due at this instant
        /// </summary>
        public async Task<DueMessagesResult> GetDueMessages()
        {
            var lockItem = new FileSystemExclusiveLock(_lockFile, _log);
            var prefix = RebusTime.Now.UtcDateTime.Ticks.ToString(TickFormat);
            var enumerable = Directory.EnumerateFiles(_basePath, "*.json")
                .Where(x => string.CompareOrdinal(prefix, 0, Path.GetFileNameWithoutExtension(x), 0, TickFormat.Length) >= 0)
                .ToList();

            var items = enumerable
                .Select(f => new
                {
                    Timeout = JsonConvert.DeserializeObject<Timeout>(File.ReadAllText(f)),
                    File = f
                })
                .Select(a => new DueMessage(a.Timeout.Headers, a.Timeout.Body, async () =>
                {
                    if (File.Exists(a.File))
                    {
                        File.Delete(a.File);
                    }
                }))
                .ToList();

            return new DueMessagesResult(items, async () => { lockItem.Dispose(); });
        }