Ejemplo n.º 1
0
        /// <summary>
        ///     Open queue and all its files.
        /// </summary>
        /// <returns>Task when completed.</returns>
        public async Task Open()
        {
            var fileNames = Directory.GetFiles(_queueDirectory, _queueName + "_*.data")
                            .OrderBy(x => x);

            foreach (var fileName in fileNames)
            {
                var file = new QueueFile(_queueDirectory, fileName);
                await file.Open();

                _files.AddLast(file);
            }

            if (_files.Count == 0)
            {
                var newFile = await CreateNewFile();

                _files.AddLast(newFile);
            }

            var count = _files.Sum(x => x.RecordCount);

            if (count > 0)
            {
                _newMessageNotification.Release(count);
            }
        }
Ejemplo n.º 2
0
        private async Task <QueueFile> CreateNewFile()
        {
            var counter  = 0;
            var fileName = $"{_queueName}_{DateTime.UtcNow:MMddHHmmss}-{counter:00}.data";

            //guard against many files being creating at the same second.
            while (File.Exists(Path.Combine(_queueDirectory, fileName)))
            {
                counter++;
                fileName = $"{_queueName}_{DateTime.UtcNow:MMddHHmmss}-{counter:00}.data";
            }

            var file = new QueueFile(_queueDirectory, fileName);
            await file.Open();

            return(file);
        }